Code::Blocks Forums

Developer forums (C::B DEVELOPMENT STRICTLY!) => Development => CodeCompletion redesign => Topic started by: blueshake on August 12, 2009, 02:56:11 AM

Title: typedef to class?
Post by: blueshake on August 12, 2009, 02:56:11 AM
hello:
     in this thread ,http://forums.next.codeblocks.org/index.php/topic,10641.0.html (http://forums.next.codeblocks.org/index.php/topic,10641.0.html)
the typedef problem can not be solved.
codes like this:
#include <iostream>

using namespace std;

class Pt
{
public:
   int x;
   int y;
};
typedef Pt subpt;
typedef subpt sub;
int main()
{
   sub pp;
   pp. // not work here.
   cout << "Hello world!" << endl;
   return 0;
}


pp get nothing.
I think can use this patch.
but I not sure it is right or not to do this.

here is the patch.

Index: parserthread.cpp
===================================================================
--- parserthread.cpp (revision 5730)
+++ parserthread.cpp (working copy)


@@ -1707,15 +1737,60 @@
#if PARSER_DEBUG_OUTPUT
    Manager::Get()->GetLogManager()->DebugLog(F(_("Adding typedef: name='%s', ancestor='%s'"), components.front().c_str(), ancestor.c_str()));
#endif
-    Token* tdef = DoAddToken(tkTypedef, components.front(), lineNr, 0, 0, args);

+    Token* tdef = DoAddToken(tkClass, components.front(), lineNr, 0, 0, args);


and pp has the tip now.see the attachment.

any comment???
Title: Re: typedef to class?
Post by: ollydbg on August 12, 2009, 03:39:54 AM
Your attachment is 0kb? :(
Title: Re: typedef to class?
Post by: blueshake on August 12, 2009, 06:21:18 AM
sorry.I just upload the pic,see the attachment.

[attachment deleted by admin]
Title: Re: typedef to class?
Post by: MortenMacFly on August 12, 2009, 10:46:48 AM
Quote from: blueshake on August 12, 2009, 02:56:11 AM
any comment???
..does it still work if you make a type out of a struct using a typedef?
Meaning: Does the struct and the typedef still code-complete?
Title: Re: typedef to class?
Post by: blueshake on August 12, 2009, 12:07:55 PM
yes,i think so.
here is the test codes.
typedef unsigned int unlong;
typedef class cls
{
    int xx;
    int yy;
}clssub;
int main()
{
    sub pp;
    unlon
    cout << "Hello world!" << endl;
    return 0;
}


the unlong can be recognized correctly.
see the attachment.
my confuse is if use this ,it seems that the tkTypedef  will have no use any more.

[attachment deleted by admin]
Title: Re: typedef to class?
Post by: MortenMacFly on August 12, 2009, 12:13:52 PM
Quote from: blueshake on August 12, 2009, 12:07:55 PM
yes,i think so.
What I meant was something like this, actually:

struct tStruct
{
 SomeClass* some_class;
 int some_int;
 void* some_void;
};
typedef struct tStruct tStruct;

...or even:

struct sStruct
{
  SomeClass* some_class;
  int some_int;
  void* some_void;
};
typedef struct sStruct tStruct;

(Notice the different name of the struct).
Title: Re: typedef to class?
Post by: blueshake on August 12, 2009, 12:43:26 PM
I test the codes in cc-branch version without applying the patch.
class sStruct
{
  SomeClass* some_class;
  int some_int;
  void* some_void;
};
typedef class sStruct tStruct;

int main()
{

    cout << "Hello world!" << endl;
    return 0;
}

it seems that the codes can not be parsed correctly.

here tStruct is recognized as a variable.
and the main is a typedef. :(
does it exist or something .
if I apply the patch , seems nothing changed :(
i will check it if i am free

[attachment deleted by admin]
Title: Re: typedef to class?
Post by: MortenMacFly on August 12, 2009, 01:12:37 PM
Quote from: blueshake on August 12, 2009, 12:43:26 PM
I test the codes in cc-branch version without applying the patch.
it seems that the codes can not be parsed correctly.
Oops - that makes me wonder. Because the used to work...?!
Title: Re: typedef to class?
Post by: ollydbg on August 12, 2009, 01:24:52 PM
I'm not quite understand you guys are taking about.
For me, I think blueshake's comment is right:

Quote
my confuse is if use this ,it seems that the tkTypedef  will have no use any more.

We can just regard the "typedef" as a public derived class of the original type.
Something like this:

class sStruct
{
 SomeClass* some_class;
 int some_int;
 void* some_void;
};
typedef class sStruct tStruct;

int main()
{

   cout << "Hello world!" << endl;
   return 0;
}



We can consider tStruct is a derived class from "sStruct".
That's all my want to say.


Title: Re: typedef to class?
Post by: blueshake on August 12, 2009, 02:10:20 PM
QuoteOops - that makes me wonder. Because the used to work...?!
sorry! I don't know it doesn't work before.

@ollydbg
what we are talking about is codes like these can not be parsed correctly.
typedef class sStruct tStruct;

even i use the patch .nothing changed.

by the way . what does it mean of "Oops".
Title: Re: typedef to class?
Post by: MortenMacFly on August 12, 2009, 05:27:44 PM
Quote from: blueshake on August 12, 2009, 02:10:20 PM
QuoteOops - that makes me wonder. Because the used to work...?!
sorry! I don't know it doesn't work before.
What I meant is that we did several modifications to CC that such constructs were parsed correctly (~1 year back). And in fact it worked! som something we applied in the meantime broke this feature (again).

[/quote]
Quote from: blueshake on August 12, 2009, 02:10:20 PM
by the way . what does it mean of "Oops".
Nothing, really. It's a word you shout out if something happens you don't expect.
Title: Re: typedef to class?
Post by: blueshake on August 15, 2009, 03:10:21 PM
@MortenMacFly

i think the cc can use the followed patch to make codes below parsed correctly.
typedef class sStruct tStruct;

Index: parserthread.cpp
===================================================================
--- parserthread.cpp (revision 5731)
+++ parserthread.cpp (working copy)
@@ -1249,6 +1337,63 @@              
               
               struct HiddenStruct yy;
              */
+                if (m_ParsingTypedef)
+                {
+         m_Tokenizer.UngetToken();
+                     break;
+                }
               if (TokenExists(current, m_pLastParent, tkClass))
              {
                   if (!TokenExists(next, m_pLastParent, tkVariable) )

+    Token* tdef = DoAddToken(tkClass, components.front(), lineNr, 0, 0, args);
-       //Token* tdef = DoAddToken(tkTypedef, components.front(), lineNr, 0, 0, args);
Title: Re: typedef to class?
Post by: blueshake on August 15, 2009, 03:15:59 PM
see the attachment,

[attachment deleted by admin]