Bug 69471 - completion not working with typedefs
Summary: completion not working with typedefs
Status: RESOLVED FIXED
Alias: None
Product: kdevelop
Classification: Applications
Component: Code completion (show other bugs)
Version: git master
Platform: Mandrake RPMs Linux
: NOR normal
Target Milestone: ---
Assignee: KDevelop Developers
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2003-12-01 21:27 UTC by Konrad Klimaszewski
Modified: 2005-03-09 05:04 UTC (History)
1 user (show)

See Also:
Latest Commit:
Version Fixed In:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Konrad Klimaszewski 2003-12-01 21:27:38 UTC
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
Comment 1 Amilcar do Carmo Lucas 2003-12-01 22:27:22 UTC
This is related to bug 68929
Comment 2 Florian 2004-04-20 11:36:43 UTC
The same not only for C++ but for C! I've got version 3.0.1 of kdevelop.
Comment 3 Nir 2004-06-20 20:23:46 UTC
and also related to bug 74347
Comment 4 Adam Treat 2005-03-09 05:04:37 UTC
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 


Comment 5 Adam Treat 2005-03-09 05:04:40 UTC
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