Dear community,
it seems that the CodeCompletion plugin does not realise typedefs, right?
If I declare a struct as:
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:
struct MyStruct ms;
...where it doesn't work.
To solve the problem from above in C one normally uses typedefs. However, for:
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.
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:
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.
Quotewithin 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...
QuoteI wonder whether there is a reason for that?!
OK. Let's go by examples. Say you have this piece of 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:
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.
QuoteWho is actually the author of this plugin?
Me.
Quote from: mandrav on October 26, 2005, 12:16:51 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.
Quote from: mandrav on October 26, 2005, 12:16:51 PM
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.
QuoteI 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:
#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)
Quote from: mandrav on October 26, 2005, 01:09:58 PM
Here's a simple one:
Thanks! :D
Alright, I've had a look into VC6. I've used the following 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...
Quote from: MortenMacFly on October 26, 2005, 01:32:06 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.
QuoteMyStruct 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 ;)
...I know, I said I shut up... but... :D
Quote from: mandrav on October 26, 2005, 02:40:57 PM
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
typedef struct {...} MyStruct;is actually lazy syntax because it should better be:
typedef struct MyStruct {...} MyTypedef;...and is just accepted by the generosity of the compiler?! I mean:
struct {...}; itself without a name generates a compiler error (of course).
Seems I am learning something I had never thought of...
Morten.
Does the Codecompletion plugin take scope into consideration?
CodeCompletion needs a full real C++ parser. :)
Is C-Tags used?
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)
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.
Quote from: anonuser on November 17, 2005, 01:33:46 AM
Does the Codecompletion plugin take scope into consideration?
Yes, it does if you enable it (or better: do not disable "SmartSense").
Morten.
I researched the other day for heavy full real open source C++ parsers and found more or less this:
Synopsis (http://synopsis.fresco.org/docs/DevGuide/cxx.html)
Developed for the Synopsis autodoc generation app.
Elsa (http://www.cs.berkeley.edu/~smcpeak/elkhound/)
Elsa can parse most C++ "in the wild". It has been tested with some notable large programs, including Mozilla, Qt, ACE, and itself.
ANTLR C++/CodeStore (http://vcfbuilder.org/?q=node/139)
Modified a little this open-source multi-platform IDE: VCFBuilder.
ANTLR is one of the most popular and well know parser generators out there.
Assist++ (http://upp.sourceforge.net/app$ide$Assist$en-us.html)
Developed for this another open-source cross-platform IDE: Ultimate++.
And these C/C++ pre-processor parsers:
ucpp (http://pornin.nerim.net/ucpp/)
Wave (http://spirit.sourceforge.net/)
All of the parsers mentioned uses Abstact Syntax Trees.
The best ones seems to be ANTLR and Elsa.
Ctags is not a C++ parser, and doesn't have the same functionality, so it would belong to another plugin.
Gotcha, but nice work, now do you know how hard it would be to make a plugin that would take advantage of those engines?
I don't think it would be really hard, all those parsers are written in good C++.
I compiled ANTLR (CodeStore) importing a MSVC workspace in C::B and it compiled almost out-of-the-box. Didn't tried the others yet.
I would like to know what do you guys think about what's best path:
-Modify the actual CodeCompletion plugin to use one of these parsers.
-Try to improve the current C::B parser.
-Create a new CodeCompletion plugin for one of these parsers, thus having two CodeCompletion plugins in the meantime.
I'd think rip out the current code completion plugin and rewrite using one of thses parsers.
Add in some cool features like
argument highlighting.
A major improvment would to make sure the the popup for code completion has no window border.
Pressing tab to complete would also rock.
Quote from: anonuser on November 19, 2005, 03:07:47 AM
Pressing tab to complete would also rock.
Try CTRL+Space!
Morten.
After you ctrl+space you need to press enter to complete. Why not tab?
But CTRL+Space had to be using another purpose in non-english ctiy.
pardon?
I'm talking about confirming auto-completion with tab as well as enter that way you can ctrl+space then press tab to confirm. Its just something I've picked up in other development platforms (codeforge, eclipse +CDT, Visual Studio)