Version: cvs snapshot 031129 (using KDE KDE 3.1) Installed from: Mandrake RPMs Compiler: gcc version 3.2.2 (Mandrake Linux 9.1 3.2.2-3mdk) OS: Linux Code completion doesn't work with typedefs even though I enabled: Project->Project Options->C++ specific->Code completion->Code completion options->Include Typedefs example: class test { public: test(); ~test(); void method(void); }; typedef test tmp; int main(int argc, char *argv[]) { tmp object; object.[CTRL]+[SPACE] Doesn't work :( But using: test object2; object2.[CTRL]+[SPACE] Works
This is related to bug 68929
The same not only for C++ but for C! I've got version 3.0.1 of kdevelop.
and also related to bug 74347
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