Developer forums (C::B DEVELOPMENT STRICTLY!) > Plugins development

(Minor) improvement of CodeCompletion?

(1/5) > >>

MortenMacFly:
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;

--- End code ---
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;

--- End code ---
...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;

--- End code ---
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.

MortenMacFly:
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();
}

--- End code ---
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.

mandrav:

--- Quote ---within the file parserthread.cpp it seems that typedefs are handled in a way that they are simply skipped
--- End quote ---

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


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

OK. Let's go by examples. Say you have this piece of code:

--- Code: ---struct { ... } myStruct;
typedef struct myStruct myStruct;

--- End code ---

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*);

--- End code ---

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?
--- End quote ---
Me.

MortenMacFly:

--- 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"?

--- End quote ---
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.

--- End quote ---
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.

mandrav:

--- 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.
--- End quote ---

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;
}

--- End code ---

(Edit: fixed an error)

Navigation

[0] Message Index

[#] Next page

Go to full version