Author Topic: typedef parse problem(branch version )  (Read 9615 times)

Offline blueshake

  • Regular
  • ***
  • Posts: 459
typedef parse problem(branch version )
« 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]
Keep low and hear the sadness of little dog.
I fall in love with a girl,but I don't dare to tell her.What should I do?

Offline ollydbg

  • Developer
  • Lives here!
  • *****
  • Posts: 5915
  • OpenCV and Robotics
    • Chinese OpenCV forum moderator
Re: typedef parse problem(branch version )
« Reply #1 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).
If some piece of memory should be reused, turn them to variables (or const variables).
If some piece of operations should be reused, turn them to functions.
If they happened together, then turn them to classes.

Offline ollydbg

  • Developer
  • Lives here!
  • *****
  • Posts: 5915
  • OpenCV and Robotics
    • Chinese OpenCV forum moderator
Re: typedef parse problem(branch version )
« Reply #2 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

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".



If some piece of memory should be reused, turn them to variables (or const variables).
If some piece of operations should be reused, turn them to functions.
If they happened together, then turn them to classes.

Offline MortenMacFly

  • Administrator
  • Lives here!
  • *****
  • Posts: 9694
Re: typedef parse problem(branch version )
« Reply #3 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.
Compiler logging: Settings->Compiler & Debugger->tab "Other"->Compiler logging="Full command line"
C::B Manual: https://www.codeblocks.org/docs/main_codeblocks_en.html
C::B FAQ: https://wiki.codeblocks.org/index.php?title=FAQ

Offline ollydbg

  • Developer
  • Lives here!
  • *****
  • Posts: 5915
  • OpenCV and Robotics
    • Chinese OpenCV forum moderator
Re: typedef parse problem(branch version )
« Reply #4 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.
If some piece of memory should be reused, turn them to variables (or const variables).
If some piece of operations should be reused, turn them to functions.
If they happened together, then turn them to classes.

Offline Loaden

  • Lives here!
  • ****
  • Posts: 1014
Re: typedef parse problem(branch version )
« Reply #5 on: August 12, 2009, 08:10:30 am »
Where is "--- parserthread.cpp   (revision 5696)"?

Offline blueshake

  • Regular
  • ***
  • Posts: 459
Re: typedef parse problem(branch version )
« Reply #6 on: August 12, 2009, 08:52:04 am »
Where is "--- parserthread.cpp   (revision 5696)"?
pardon?
Keep low and hear the sadness of little dog.
I fall in love with a girl,but I don't dare to tell her.What should I do?