Author Topic: About the Code Completion  (Read 7970 times)

Offline pingf

  • Multiple posting newcomer
  • *
  • Posts: 12
About the Code Completion
« on: March 14, 2009, 02:18:06 am »
Hi,
I felt a little disappointed about the C::B's code completion,
e.g.
typedef struct tagABC
{
      int a;
      int b;
} ABC;
and the completion won't find the ABC's members!
so does the OPENFILENAME ,PAINTSTRUCT.......
however,
e.g.
struct M
{
     int a;
     int b;
};
M m;
it finds the m's members immediately!

Offline ollydbg

  • Developer
  • Lives here!
  • *****
  • Posts: 5216
  • OpenCV and Robotics
    • Chinese OpenCV forum moderator
Re: About the Code Completion
« Reply #1 on: March 14, 2009, 03:40:33 am »
See this thread.

http://forums.codeblocks.org/index.php/topic,9225.msg65886.html#msg65886

I found this patch haven't applied.

Edit:
I investigate the source code in void ParserThread::HandleTypedef(), in parserthread.cpp. This file needs to be modified to parse C type typedef and struct correctly :D.
« Last Edit: March 14, 2009, 07:45:54 am by 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.

Offline ollydbg

  • Developer
  • Lives here!
  • *****
  • Posts: 5216
  • OpenCV and Robotics
    • Chinese OpenCV forum moderator
Re: About the Code Completion
« Reply #2 on: March 14, 2009, 08:47:46 am »
In the beginning, it has these comments.
Code: [Select]
void ParserThread::HandleTypedef()
{
    // typedefs are handled as tkClass and we put the typedef'd type as the class's
    // ancestor. this way, it will work through inheritance.

The typedef's type as the class's ancestor.

Here is my test code:
Code: [Select]
class Ancestor{
    public:
    int m_aaaa;
    int m_bbbb;
};
class Child:public Ancestor {
    public:
    int m_cccc;
    int m_dddd;

};

int main()
{
    Child obj;
    obj. // works ok! all the four members will be shown.

    return 0;
}
See the screen shot below.

But the code below can't work.
Code: [Select]

typedef class Ancestor{
    public:
    int m_aaaa;
    int m_bbbb;
} Parent;

//typedef class Ancestor Parent;


int main()
{
    Parent obj;
    obj. //Show nothing! works badly.

    return 0;
}
If the Parent was treated as Ancestor's parents(said by the comments), I think the public member of Ancestor should be shown. So, it can't work though it's inheritance.



[attachment deleted by admin]
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 pingf

  • Multiple posting newcomer
  • *
  • Posts: 12
Re: About the Code Completion
« Reply #3 on: March 14, 2009, 02:02:56 pm »
See this thread.

http://forums.codeblocks.org/index.php/topic,9225.msg65886.html#msg65886

I found this patch haven't applied.

Edit:
I investigate the source code in void ParserThread::HandleTypedef(), in parserthread.cpp. This file needs to be modified to parse C type typedef and struct correctly :D.

THX a lot!
but,How to use the patch? [or install ,compile...whatever]
I'm just a beginner on C::B.

Offline ollydbg

  • Developer
  • Lives here!
  • *****
  • Posts: 5216
  • OpenCV and Robotics
    • Chinese OpenCV forum moderator
Re: About the Code Completion
« Reply #4 on: March 14, 2009, 02:17:40 pm »
I'm examining the code.

In the parsethread.cpp line 1570, I enable the output to report a typedef token information.
Code: [Select]
Manager::Get()->GetLogManager()->DebugLog(F(_("Adding typedef: name '%s', ancestor: '%s'"), components.front().c_str(), ancestor.c_str()));

It seems that when I parse the code like this:
Code: [Select]
typedef class Ancestor{
    public:
    int m_aaaa;
    int m_bbbb;
} Parent;

Then the output is like this:
Code: [Select]
Adding typedef: name 'Parent', ancestor: ''
Note that the ancestor is an empty string. This is the reason that code completion can't give the correct tooltips.

If the ancestor is string named "Ancestor", I think the code completion will work ok!
Edit: This has been confirmed, I just tested by assigning the ancestor = _T("Ancestor") , in the line 1564 of parsethread.cpp.

Code: [Select]
    ancestor << typ;
    ancestor = _T("Ancestor");
then, the tips can show correctly.


I'm trying to solve it, but all the codes are hard to understand(currently no document were supplied), so, it will take times, also, I will enrich  the wiki page if I find the solution.

There is another issue: If I try to parse this code
Code: [Select]
class Ancestor{
    public:
    int m_aaaa;
    int m_bbbb;
};
typedef class Ancestor Parent;
Then no typedef token was recognized. :(
« Last Edit: March 15, 2009, 10:48:50 am by 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.

Offline ollydbg

  • Developer
  • Lives here!
  • *****
  • Posts: 5216
  • OpenCV and Robotics
    • Chinese OpenCV forum moderator
Re: About the Code Completion
« Reply #5 on: March 14, 2009, 02:20:31 pm »
See this thread.

http://forums.codeblocks.org/index.php/topic,9225.msg65886.html#msg65886

I found this patch haven't applied.

Edit:
I investigate the source code in void ParserThread::HandleTypedef(), in parserthread.cpp. This file needs to be modified to parse C type typedef and struct correctly :D.

THX a lot!
but,How to use the patch? [or install ,compile...whatever]
I'm just a beginner on C::B.
Apply a patch is something like you will build the code::blocks from it's source.
You can follow the wiki page
http://wiki.codeblocks.org/index.php?title=Installing_Code::Blocks_from_source_on_Windows#Code::Blocks_sources

also, I have wrote a page in

http://wiki.codeblocks.org/index.php?title=Code_Completion_Design

« Last Edit: March 14, 2009, 05:19:23 pm by 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.

Offline pingf

  • Multiple posting newcomer
  • *
  • Posts: 12
Re: About the Code Completion
« Reply #6 on: March 14, 2009, 03:16:44 pm »
See this thread.

http://forums.codeblocks.org/index.php/topic,9225.msg65886.html#msg65886

I found this patch haven't applied.

Edit:
I investigate the source code in void ParserThread::HandleTypedef(), in parserthread.cpp. This file needs to be modified to parse C type typedef and struct correctly :D.

THX a lot!
but,How to use the patch? [or install ,compile...whatever]
I'm just a beginner on C::B.
Apply a path is something like you will build the code::blocks from it's source.
You can follow the wiki page
http://wiki.codeblocks.org/index.php?title=Installing_Code::Blocks_from_source_on_Windows#Code::Blocks_sources

also, I have write a page in

http://wiki.codeblocks.org/index.php?title=Code_Completion_Design


WOW!
It seems a little tough for me now!
if I had enough time, I will try.

Offline ollydbg

  • Developer
  • Lives here!
  • *****
  • Posts: 5216
  • OpenCV and Robotics
    • Chinese OpenCV forum moderator
Re: About the Code Completion
« Reply #7 on: March 16, 2009, 10:02:32 am »
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.