Author Topic: (Minor) improvement of CodeCompletion?  (Read 30484 times)

Offline MortenMacFly

  • Administrator
  • Lives here!
  • *****
  • Posts: 9694
(Minor) improvement of CodeCompletion?
« on: October 25, 2005, 11:23:09 am »
Dear community,

it seems that the CodeCompletion plugin does not realise typedefs, right?

If I declare a struct as:
Code
struct MyStruct
{
  int  iMyInt;
  long lMyLong;
};

MyStruct ms;
CodeCompletion works well. However - as far as I know this is a C++ specific extension. The correct declaration in C (not C++) should be:
Code
struct MyStruct ms;
...where it doesn't work.

To solve the problem from above in C one normally uses typedefs. However, for:
Code
typedef struct
{
  int  iMyInt;
  long lMyLong;
}MyStruct;

MyStruct ms;
CodeCompletion doesn't seem to work eighter. Is this by design? It would be very nice if this were working since such typedefs are quite common in standard C.

With regards,

Morten.
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 MortenMacFly

  • Administrator
  • Lives here!
  • *****
  • Posts: 9694
Re: (Minor) improvement of CodeCompletion?
« Reply #1 on: October 26, 2005, 12:04:15 pm »
I have thought of this issue again and had a look into the code of the CodeCompletion plugin. I am thinking of trying to implement what I have proposed. But before I try I'd like to ask a question:

within the file parserthread.cpp it seems that typedefs are handled in a way that they are simply skipped:
Code
else if (token.Matches(_T("typedef")) ||
  token.Matches(_T(":")))
{
  SkipToOneOfChars(_T(";}"), true);
  m_Str.Clear();
}
Am I right on this assumption? I wonder whether there is a reason for that?! I would like to know that reason before I might run into troubles I haven't thought of. Who is actually the author of this plugin?

With kind regards,

Morten.
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 mandrav

  • Project Leader
  • Administrator
  • Lives here!
  • *****
  • Posts: 4315
    • Code::Blocks IDE
Re: (Minor) improvement of CodeCompletion?
« Reply #2 on: October 26, 2005, 12:16:51 pm »
Quote
within the file parserthread.cpp it seems that typedefs are handled in a way that they are simply skipped

That's true. Typedefs are not supported...

Quote
I wonder whether there is a reason for that?!

OK. Let's go by examples. Say you have this piece of code:
Code
struct { ... } myStruct;
typedef struct myStruct myStruct;

With a little effort, we can make the plugin recognize it.
Now say you have this piece of code:
Code
typedef ATemplatedClass<ClassType1, int, float>(AContainerClass::*WithAMemberFunction)(int,int);
// or
typedef BOOL (WINAPI *PFN_CERT_CHAIN_FIND_BY_ISSUER_CALLBACK)(PCCERT_CONTEXT,void*);

Well, without having access to the compiler's internals, how would the plugin find and identify correctly "WithAMemberFunction" or "PFN_CERT_CHAIN_FIND_BY_ISSUER_CALLBACK"?

I 'm open to suggestions.

Quote
Who is actually the author of this plugin?
Me.
Be patient!
This bug will be fixed soon...

Offline MortenMacFly

  • Administrator
  • Lives here!
  • *****
  • Posts: 9694
Re: (Minor) improvement of CodeCompletion?
« Reply #3 on: October 26, 2005, 12:40:36 pm »
Well, without having access to the compiler's internals, how would the plugin find and identify correctly "WithAMemberFunction" or "PFN_CERT_CHAIN_FIND_BY_ISSUER_CALLBACK"?
I see and understand the difficulty. It was good to have asked.

I 'm open to suggestions.
Here are some - they are maybe not a good ones, but may still help C developers:

Isn't it possible to ask for the nature of the project (C/C++)? In a C project the first problem of the examples is solved, it's simply not possible and would be ignored. For the second problem the way enums handled came into my mind: Here an enum can be named or unnamed. What if a typdef member's type can be known by unknown (because cannot be resolved)?

Another way would be to ignore "complex" or unresolveble typedefs. This is not very nice but still: C developers would be happy with this interim-solution since it makes coding easier.

I wonder if (and how) VC6 handles such complex typedefs? I currently haven't a valid code-snippet to test this... I'll try to find one.

Morten.
« Last Edit: October 26, 2005, 12:42:34 pm by MortenMacFly »
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 mandrav

  • Project Leader
  • Administrator
  • Lives here!
  • *****
  • Posts: 4315
    • Code::Blocks IDE
Re: (Minor) improvement of CodeCompletion?
« Reply #4 on: October 26, 2005, 01:09:58 pm »
Quote
I wonder if (and how) VC6 handles such complex typedefs? I currently haven't a valid code-snippet to test this... I'll try to find one.

Here's a simple one:

Code
#include <iostream>

typedef void(*func)();

void AFunction()
{
    std::cout << "In AFunction()" << std::endl;
    return;
}

int main(int argc, char** argv)
{
    func f = AFunction;
    f();
    return 0;
}

(Edit: fixed an error)
« Last Edit: October 26, 2005, 01:12:04 pm by mandrav »
Be patient!
This bug will be fixed soon...

Offline MortenMacFly

  • Administrator
  • Lives here!
  • *****
  • Posts: 9694
Re: (Minor) improvement of CodeCompletion?
« Reply #5 on: October 26, 2005, 01:32:06 pm »
Here's a simple one:
Thanks! :D

Alright, I've had a look into VC6. I've used the following code:
Code
#include "stdafx.h"
#include <iostream>

typedef struct
{
  int  iMyInt;
  long lMyLong;
}MyStruct;

typedef void(*func)();

void AFunction()
{
    std::cout << "In AFunction()" << std::endl;
    return;
}

int main(int argc, char** argv)
{
    func f = AFunction;
    f();
    return 0;
}

The result:

MyStruct and it's members is shown as a class in the class browser. Also codecompletion works for an instance ("ms"). The function typedef is ignored and not shown in the class browser. Is this handled as I proposed...?! MS seems to be is as lazy as I am. :lol:

So what to do from here? Is it worth giving a try? What do you (mandrav) think?

With regards,

Morten.

Edit: Did a mistake with quotes...
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 MortenMacFly

  • Administrator
  • Lives here!
  • *****
  • Posts: 9694
Re: (Minor) improvement of CodeCompletion?
« Reply #6 on: October 26, 2005, 02:14:52 pm »
The result:

I just gave a try to the same example using VS.NET from another student. There it is different. MyStruct is presented as "unnamed" struct (not "MyStruct"!) and "MyStruct" as well as "func" are shown with a typedef symbol without any members. Hence if I move the cursor over "func" (where the function is defined in main) the hint shows the complete typedef. If I move the cursor over an instance of "MyStruct" within main the hint shows "__unnamed_[address] MyStruct" and codecompletion works.

Now I am struggeling with my "construct". The inner part is intepreted as unnamed struct (which would then be right) and the outer part is therefore a typedef without members. I thought that this a right way do declare a new type (I've done it a lot and seen it a lot) but it seems not to be. It's suddenly becoming quite strange (at least for me that is)...

Now I am confused. :?

I think I should just shut up and stop wasting your time.

Morten.
« Last Edit: October 26, 2005, 02:29:23 pm by MortenMacFly »
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 mandrav

  • Project Leader
  • Administrator
  • Lives here!
  • *****
  • Posts: 4315
    • Code::Blocks IDE
Re: (Minor) improvement of CodeCompletion?
« Reply #7 on: October 26, 2005, 02:40:57 pm »
Quote
MyStruct is presented as "unnamed" struct (not "MyStruct"!)

This is correct. MyStruct is not a type itself but a typedef for the anonymous struct behind it. After being typedef'd it is a type, of course ;)
Be patient!
This bug will be fixed soon...

Offline MortenMacFly

  • Administrator
  • Lives here!
  • *****
  • Posts: 9694
Re: (Minor) improvement of CodeCompletion?
« Reply #8 on: October 26, 2005, 03:20:52 pm »
...I know, I said I shut up... but... :D

This is correct. MyStruct is not a type itself but a typedef for the anonymous struct behind it. After being typedef'd it is a type, of course ;)
Does that mean that
Code
typedef struct {...} MyStruct;
is actually lazy syntax because it should better be:
Code
typedef struct MyStruct {...} MyTypedef;
...and is just accepted by the generosity of the compiler?! I mean:
Code
struct {...};
itself without a name generates a compiler error (of course).

Seems I am learning something I had never thought of...

Morten.
« Last Edit: October 26, 2005, 03:23:07 pm by MortenMacFly »
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

anonuser

  • Guest
Re: (Minor) improvement of CodeCompletion?
« Reply #9 on: November 17, 2005, 01:33:46 am »
Does the Codecompletion plugin take scope into consideration?

takeshimiya

  • Guest
Re: (Minor) improvement of CodeCompletion?
« Reply #10 on: November 17, 2005, 02:24:47 am »
CodeCompletion needs a full real C++ parser. :)

anonuser

  • Guest
Re: (Minor) improvement of CodeCompletion?
« Reply #11 on: November 18, 2005, 11:41:57 pm »
Is C-Tags used?

Offline rickg22

  • Lives here!
  • ****
  • Posts: 2283
Re: (Minor) improvement of CodeCompletion?
« Reply #12 on: November 19, 2005, 12:55:41 am »
no, it doesn't.  All the parsing is hardwired. Frankly i'd vote to use an alternative engine, and use only the integrated parser only c++ projects.

Also, i understand that the Code::Bocks parser has to be "fault tolerant", but is this really necessary? I mean, if the code doesn't appear in the class browser, it means it won't compile anyway, so that "minus" would be really a "plus". What do you think guys?

(note: Of course this wouldn't change before 1.0 is released)

anonuser

  • Guest
Re: (Minor) improvement of CodeCompletion?
« Reply #13 on: November 19, 2005, 01:03:43 am »
Wouldn't it make sense to use exctags tp generate tag files and use their library which is public domain if I remember correctly. It handles all sorts of things. In fact I believe it'll even give you class::member if you generate with extra stuff in it.

Offline MortenMacFly

  • Administrator
  • Lives here!
  • *****
  • Posts: 9694
Re: (Minor) improvement of CodeCompletion?
« Reply #14 on: November 19, 2005, 01:18:36 am »
Does the Codecompletion plugin take scope into consideration?
Yes, it does if you enable it (or better: do not disable "SmartSense").

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