Code::Blocks Forums

Developer forums (C::B DEVELOPMENT STRICTLY!) => Development => CodeCompletion redesign => Topic started by: blueshake on July 24, 2009, 03:57:13 am

Title: typedef parse problem(branch version )
Post by: blueshake on July 24, 2009, 03:57:13 am
codes like this can not be parsed .SubCls1,SubCls2 can not be recognized .
Code
#include <iostream>
#include <map>
using namespace std;
typedef class MyClass
{
    int x;
    int y;
}SubCls1,SubCls2;

int main()
{
   
    SubCls1 cls;
    cout << "Hello world!" << endl;
    return 0;
}

here is the patch.
Code
Index: parserthread.cpp
===================================================================
--- parserthread.cpp (revision 5696)
+++ parserthread.cpp (working copy)
@@ -1256,12 +1256,19 @@
                 // no vars are defined on a typedef, only types
                 // In the former example, aa is not part of the typedef.
                 if (m_ParsingTypedef)
+                {
+                    m_Str.Clear();
+                    ReadClsNames(newToken->m_Name);
+//                    m_ParsingTypedef = false;
                     break;
-
-                m_Str = newToken->m_Name;
-                ReadVarNames();
-                m_Str.Clear();
-                break;
+                }
+                else
+                {
+                    m_Str = newToken->m_Name;
+                    ReadVarNames();
+                    m_Str.Clear();
+                    break;
+                }
             }
             else if (next==ParserConsts::opbrace)
             {
@@ -1295,12 +1302,19 @@
                 // no vars are defined on a typedef, only types
                 // In the former example, aa is not part of the typedef.
                 if (m_ParsingTypedef)
+                {
+                    m_Str.Clear();
+                    ReadClsNames(newToken->m_Name);
+//                    m_ParsingTypedef = false;
                     break;
-
-                m_Str = newToken->m_Name;
-                ReadVarNames();
-                m_Str.Clear();
-                break;
+                }
+                else
+                {
+                    m_Str = newToken->m_Name;
+                    ReadVarNames();
+                    m_Str.Clear();
+                    break;
+                }
             }
             else if (next==ParserConsts::semicolon) // forward decl; we don't care
                 break;
@@ -1719,3 +1735,36 @@
             tdef->m_ActualType = ancestor + args;
     }
 }
+void ParserThread::ReadClsNames(wxString& ancestor)
+{
+    while (1)
+    {
+        wxString current = m_Tokenizer.GetToken();
+
+        if (current.IsEmpty())
+            break;
+        if (current==ParserConsts::comma)
+            continue;
+        else if (current==ParserConsts::semicolon)
+            {
+                m_Tokenizer.UngetToken();
+                break;
+            }
+        else if (wxIsalpha(current.GetChar(0)))
+        {
+//            if ( m_Filename == _T("F:\\fortest\\main.cpp"))
+//            Manager::Get()->GetLogManager()->DebugLog(F(_T("Adding variable '%s' as '%s' to '%s'"), current.c_str(), m_Str.c_str(), (m_pLastParent?m_pLastParent->m_Name.c_str():_T("<no-parent>"))));
+            Token* newToken = DoAddToken(tkClass, current, m_Tokenizer.GetLineNumber());
+            if (!newToken)
+                break;
+            else
+            {
+                wxString tempAncestor = ancestor;
+                newToken->m_AncestorsString = tempAncestor;
+            }
+           
+        }
+        else // unexpected
+            break;
+    }
+}
Index: parserthread.h
===================================================================
--- parserthread.h (revision 5696)
+++ parserthread.h (working copy)
@@ -89,6 +89,7 @@
         void HandlePreprocessorBlocks(const wxString& preproc);
         void HandleNamespace();
         void ReadVarNames();
+        void ReadClsNames(wxString& ancestor);
         void HandleClass(EClassType ct);
         void HandleFunction(const wxString& name, bool isOperator = false);
         void HandleEnum();


by the way ,Ihave not test it completely .welcome to test and report bugs .

[attachment deleted by admin]
Title: Re: typedef parse problem(branch version )
Post by: ollydbg on July 29, 2009, 04:28:56 pm
I tested this patch, and it works great!!!

By the way, I need to manually patch in my local copy.

Thanks to the "Block select mode in editor", I can delete many "+" at a once. :D  (use ALT + mouse drag).
Title: Re: typedef parse problem(branch version )
Post by: ollydbg on July 31, 2009, 04:31:10 am
Any dev can test this patch?

I have write the description of this patch in wiki page, see here:

Handing class and typdef (http://wiki.codeblocks.org/index.php?title=Talk:Code_Completion_Design#Handling_class_example)

Thanks.

By the way, I'm considering enrich the multiply match dialog. I think we should add another column about FileList, Or, we can do it like "threadSearch result tree".

(http://i683.photobucket.com/albums/vv194/ollydbg_cb/multimatch.png)

Title: Re: typedef parse problem(branch version )
Post by: MortenMacFly on July 31, 2009, 08:16:12 am
Any dev can test this patch?
I am already on it... don't worry. Looks good so far.
Title: Re: typedef parse problem(branch version )
Post by: ollydbg on July 31, 2009, 08:18:50 am
Any dev can test this patch?
I am already on it... don't worry. Looks good so far.
Nice to hear! Thanks.
Title: Re: typedef parse problem(branch version )
Post by: Loaden on August 12, 2009, 08:10:30 am
Where is "--- parserthread.cpp   (revision 5696)"?
Title: Re: typedef parse problem(branch version )
Post by: blueshake on August 12, 2009, 08:52:04 am
Where is "--- parserthread.cpp   (revision 5696)"?
pardon?