News:

Accounts with zero posts and zero activity during the last months will be deleted periodically to fight SPAM!

Main Menu

typedef parse problem(branch version )

Started by blueshake, July 24, 2009, 03:57:13 AM

Previous topic - Next topic

blueshake

codes like this can not be parsed .SubCls1,SubCls2 can not be recognized .
#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.
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?

ollydbg

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.

ollydbg

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.

MortenMacFly

Quote from: ollydbg on July 31, 2009, 04:31:10 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: [url="https://www.codeblocks.org/docs/main_codeblocks_en.html"]https://www.codeblocks.org/docs/main_codeblocks_en.html[/url]
C::B FAQ: [url="https://wiki.codeblocks.org/index.php?title=FAQ"]https://wiki.codeblocks.org/index.php?title=FAQ[/url]

ollydbg

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.

Loaden

Where is "--- parserthread.cpp   (revision 5696)"?

blueshake

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?