[Bug 69471] completion not working with typedefs
Adam Treat
manyoso at yahoo.com
Wed Mar 9 05:06:05 UTC 2005
------- You are receiving this mail because: -------
You are the assignee for the bug, or are watching the assignee.
http://bugs.kde.org/show_bug.cgi?id=69471
manyoso yahoo com changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|NEW |RESOLVED
Resolution| |FIXED
------- Additional Comments From manyoso yahoo com 2005-03-09 05:04 -------
CVS commit by treat:
BUGS:69471
CCBUGS:69471
Resolve typedefs in the local codemodel and make sure to flatten them before
computing the types completion entry list. Templates in typedefs are not handled
yet.
M +10 -1 cppcodecompletion.cpp 1.154
M +63 -0 cppsupport_utils.cpp 1.5
M +2 -0 cppsupport_utils.h 1.5
--- kdevelop/languages/cpp/cppcodecompletion.cpp #1.153:1.154
@ -651,4 +651,13 @ QStringList CppCodeCompletion::evaluateE
QStringList type = evaluateExpressionInternal( exprList, QStringList(), ctx );
+ QMap<QString, QString> typedefs = typedefMap( m_pSupport->codeModel() );
+
+ QStringList::iterator it = type.begin();
+ for ( ; it != type.end(); ++it )
+ {
+ if ( typedefs.contains( ( *it ) ) )
+ ( *it ) = typedefs[ ( *it ) ];
+ }
+
m_pSupport->mainWindow() ->statusBar() ->message( i18n( "Type of %1 is %2" ).arg( expr ).arg( type.join( "::" ) ), 1000 );
--- kdevelop/languages/cpp/cppsupport_utils.cpp #1.4:1.5
@ -4,4 +4,6 @
#include <qdir.h>
+#include <kdebug.h>
+
static void typeNameList( QStringList& path, QStringList & lst, const CodeModel * model );
static void typeNameList( QStringList& path, QStringList & lst, NamespaceDom ns );
@ -49,6 +51,67 @ static void typeNameList( QStringList &
for( ClassList::ConstIterator it=classList.begin(); it!=classList.end(); ++it )
typeNameList( path, lst, *it );
+
path.pop_back();
}
+static void typedefMap( QMap<QString, QString> & map, const CodeModel * model );
+static void typedefMap( QMap<QString, QString> & map, NamespaceDom ns );
+static void typedefMap( QMap<QString, QString> & map, ClassDom klass );
+
+QMap<QString, QString> typedefMap( const CodeModel* model )
+{
+ QMap<QString, QString> map;
+ typedefMap( map, model );
+
+ /*We need to flatten the typedefs to avoid circular aliases.
+ Example:
+ map["Foo"] = "int";
+ map["Bar"] = "Foo";
+ map["Baz"] = "Bar";*/
+
+ QMap<QString, QString>::iterator it = map.begin();
+ for ( ; it != map.end(); ++it )
+ {
+ while ( map.contains( map[ it.key() ] ) )
+ {
+ map[ it.key() ] = map[ map[ it.key() ] ];
+ }
+ }
+
+ return map;
+}
+
+static void typedefMap( QMap<QString, QString> & map, const CodeModel * model )
+{
+ const FileList fileList = model->fileList();
+ for( FileList::ConstIterator it=fileList.begin(); it!=fileList.end(); ++it )
+ typedefMap( map, model_cast<NamespaceDom>(*it) );
+}
+
+static void typedefMap( QMap<QString, QString> & map, NamespaceDom ns )
+{
+ const TypeAliasList aliasList = ns->typeAliasList();
+ for( TypeAliasList::ConstIterator it=aliasList.begin(); it!=aliasList.end(); ++it )
+ map[ ( *it )->name() ] = ( *it )->type();
+
+ const NamespaceList namespaceList = ns->namespaceList();
+ for( NamespaceList::ConstIterator it=namespaceList.begin(); it!=namespaceList.end(); ++it )
+ typedefMap( map, *it );
+
+ const ClassList classList = ns->classList();
+ for( ClassList::ConstIterator it=classList.begin(); it!=classList.end(); ++it )
+ typedefMap( map, *it );
+}
+
+static void typedefMap( QMap<QString, QString> & map, ClassDom klass )
+{
+ const TypeAliasList aliasList = klass->typeAliasList();
+ for( TypeAliasList::ConstIterator it=aliasList.begin(); it!=aliasList.end(); ++it )
+ map[ ( *it )->name() ] = ( *it )->type();
+
+ const ClassList classList = klass->classList();
+ for( ClassList::ConstIterator it=classList.begin(); it!=classList.end(); ++it )
+ typedefMap( map, *it );
+}
+
//kate: indent-mode csands; tab-width 4; space-indent off;
--- kdevelop/languages/cpp/cppsupport_utils.h #1.4:1.5
@ -13,4 +13,5 @
#define __cppsupport_utils_h
+#include <qmap.h>
#include <qstringlist.h>
@ -18,4 +19,5 @ class CodeModel;
QStringList typeNameList( const CodeModel* model );
+QMap<QString, QString> typedefMap( const CodeModel* model );
#endif // __cppsupport_utils_h
------- Additional Comments From manyoso yahoo com 2005-03-09 05:04 -------
CVS commit by treat:
BUGS:69471
CCBUGS:69471
Resolve typedefs in the local codemodel and make sure to flatten them before
computing the types completion entry list. Templates in typedefs are not handled
yet.
M +10 -1 cppcodecompletion.cpp 1.154
M +63 -0 cppsupport_utils.cpp 1.5
M +2 -0 cppsupport_utils.h 1.5
--- kdevelop/languages/cpp/cppcodecompletion.cpp #1.153:1.154
@ -651,4 +651,13 @ QStringList CppCodeCompletion::evaluateE
QStringList type = evaluateExpressionInternal( exprList, QStringList(), ctx );
+ QMap<QString, QString> typedefs = typedefMap( m_pSupport->codeModel() );
+
+ QStringList::iterator it = type.begin();
+ for ( ; it != type.end(); ++it )
+ {
+ if ( typedefs.contains( ( *it ) ) )
+ ( *it ) = typedefs[ ( *it ) ];
+ }
+
m_pSupport->mainWindow() ->statusBar() ->message( i18n( "Type of %1 is %2" ).arg( expr ).arg( type.join( "::" ) ), 1000 );
--- kdevelop/languages/cpp/cppsupport_utils.cpp #1.4:1.5
@ -4,4 +4,6 @
#include <qdir.h>
+#include <kdebug.h>
+
static void typeNameList( QStringList& path, QStringList & lst, const CodeModel * model );
static void typeNameList( QStringList& path, QStringList & lst, NamespaceDom ns );
@ -49,6 +51,67 @ static void typeNameList( QStringList &
for( ClassList::ConstIterator it=classList.begin(); it!=classList.end(); ++it )
typeNameList( path, lst, *it );
+
path.pop_back();
}
+static void typedefMap( QMap<QString, QString> & map, const CodeModel * model );
+static void typedefMap( QMap<QString, QString> & map, NamespaceDom ns );
+static void typedefMap( QMap<QString, QString> & map, ClassDom klass );
+
+QMap<QString, QString> typedefMap( const CodeModel* model )
+{
+ QMap<QString, QString> map;
+ typedefMap( map, model );
+
+ /*We need to flatten the typedefs to avoid circular aliases.
+ Example:
+ map["Foo"] = "int";
+ map["Bar"] = "Foo";
+ map["Baz"] = "Bar";*/
+
+ QMap<QString, QString>::iterator it = map.begin();
+ for ( ; it != map.end(); ++it )
+ {
+ while ( map.contains( map[ it.key() ] ) )
+ {
+ map[ it.key() ] = map[ map[ it.key() ] ];
+ }
+ }
+
+ return map;
+}
+
+static void typedefMap( QMap<QString, QString> & map, const CodeModel * model )
+{
+ const FileList fileList = model->fileList();
+ for( FileList::ConstIterator it=fileList.begin(); it!=fileList.end(); ++it )
+ typedefMap( map, model_cast<NamespaceDom>(*it) );
+}
+
+static void typedefMap( QMap<QString, QString> & map, NamespaceDom ns )
+{
+ const TypeAliasList aliasList = ns->typeAliasList();
+ for( TypeAliasList::ConstIterator it=aliasList.begin(); it!=aliasList.end(); ++it )
+ map[ ( *it )->name() ] = ( *it )->type();
+
+ const NamespaceList namespaceList = ns->namespaceList();
+ for( NamespaceList::ConstIterator it=namespaceList.begin(); it!=namespaceList.end(); ++it )
+ typedefMap( map, *it );
+
+ const ClassList classList = ns->classList();
+ for( ClassList::ConstIterator it=classList.begin(); it!=classList.end(); ++it )
+ typedefMap( map, *it );
+}
+
+static void typedefMap( QMap<QString, QString> & map, ClassDom klass )
+{
+ const TypeAliasList aliasList = klass->typeAliasList();
+ for( TypeAliasList::ConstIterator it=aliasList.begin(); it!=aliasList.end(); ++it )
+ map[ ( *it )->name() ] = ( *it )->type();
+
+ const ClassList classList = klass->classList();
+ for( ClassList::ConstIterator it=classList.begin(); it!=classList.end(); ++it )
+ typedefMap( map, *it );
+}
+
//kate: indent-mode csands; tab-width 4; space-indent off;
--- kdevelop/languages/cpp/cppsupport_utils.h #1.4:1.5
@ -13,4 +13,5 @
#define __cppsupport_utils_h
+#include <qmap.h>
#include <qstringlist.h>
@ -18,4 +19,5 @ class CodeModel;
QStringList typeNameList( const CodeModel* model );
+QMap<QString, QString> typedefMap( const CodeModel* model );
#endif // __cppsupport_utils_h
More information about the KDevelop-devel
mailing list