News:

Accounts with zero posts and zero activity during the last months will be deleted periodically to fight SPAM!

Main Menu

Code Completion fails at extern declared functions

Started by christobal, December 01, 2009, 11:29:00 AM

Previous topic - Next topic

christobal

Hi,

The Code Completion fails if a function (and probably variables as well, but I haven't checked) is declared with the extern keyword.

The reason is IMHO the check for 'extern "C"' in src/plugins/codecompletion/parser/parserthread.cpp at line 479 (Rev. 5874) where the Token is read, but don't given back if it's not ParserConsts::kw_C.

I have patched the code, so that the Token will be "unget" in case the extern "C" - check fails.


        }
        else if (token==ParserConsts::kw_extern)
        {
            // check for "C"
            m_Str = m_Tokenizer.GetToken();
            if (m_Str==ParserConsts::kw_C)
            {
                m_Tokenizer.GetToken(); // "eat" {
                DoParse(); // time for recursion ;)
            }
            else
            {
                // do nothing, just skip keyword "extern", otherwise uncomment:
                //SkipToOneOfChars(ParserConsts::semicolon); // skip externs
               m_Tokenizer.UngetToken();
            }
            m_Str.Clear();
        }


can anyone confirm this?

MortenMacFly

Quote from: christobal on December 01, 2009, 11:29:00 AM
The Code Completion fails
What do you mean with "fails"? Is it not visible? Because this works fine here...?!
Compiler logging: Settings->Compiler & Debugger->tab "Other"->Compiler logging="Full command line"
C::B Manual: [url="https://www.codeblocks.org/docs/main_codeblocks_en.html"]https://www.codeblocks.org/docs/main_codeblocks_en.html[/url]
C::B FAQ: [url="https://wiki.codeblocks.org/index.php?title=FAQ"]https://wiki.codeblocks.org/index.php?title=FAQ[/url]

christobal

Sorry, I think I was not very clear about this  :oops:. The Code Completion doesn't work if you have only the declaration. I use a library which has all functions defined as extern in it's header file.

As long as the implementation is part of the project, the codecompletion works (but not the "Find declaration of: ..." from the Right Mouse Button menue).

You can repoduce it if you open an empty project and add these lines:

int foobar_test(void);
extern int foobar_blah(void);


int main (void)
{

}


If you now type foobar within main, you will only get codecompletion for foobar_test. foobar_blah has not been recognized (as you can see as well in the Symbol Browser).

BTW: I use Code::Blocks SVN Rev. 5895

blueshake

#3
confirm it.but since it is declared outside.it will be parsed correctly if the file exists where it is declared.


Edit:

thanks for your patch.
Keep low and hear the sadness of little dog.
I fall in love with a girl,but I don't dare to tell her.What should I do?

christobal

Quoteconfirm it.but since it is declared outside.it will be parsed correctly if the file exists where it is declared.

I guess you mean that it will be parsed correctly if the file exists where it is implemented? That is right, but if a library is used, the implementation is not part of the project. Therefore we need to parse the declaration correctly.

MortenMacFly

Quote from: christobal on December 01, 2009, 02:22:15 PM
That is right, but if a library is used, the implementation is not part of the project.
It's pretty weird to declare a declaration for a library function as "extern" in the interface, isn't it?!
However, yes - it's reproducible.
Compiler logging: Settings->Compiler & Debugger->tab "Other"->Compiler logging="Full command line"
C::B Manual: [url="https://www.codeblocks.org/docs/main_codeblocks_en.html"]https://www.codeblocks.org/docs/main_codeblocks_en.html[/url]
C::B FAQ: [url="https://wiki.codeblocks.org/index.php?title=FAQ"]https://wiki.codeblocks.org/index.php?title=FAQ[/url]

christobal

QuoteIt's pretty weird to declare a declaration for a library function as "extern" in the interface, isn't it?!

I have to admit that it has no effect on function declarations, but it is necessary for declarations of variables. Could you confirm that the patch above works correctly? I don't have a clue about the codecompletion plugin and so it's just a wild guess... :)

ivan1979

Hi,

i'm very interesting  in a libcodecompletion.so that implements extern resolution also, can anyone help me?
where can i found it?
Actually i include in mu C::B C parser a gcc arm toolchain and very many functions are declarated as extern so codecompletion cannot resolve those  :(
Thanks

ollydbg

Quote from: ivan1979 on March 12, 2010, 03:49:19 PM
Hi,

i'm very interesting  in a libcodecompletion.so that implements extern resolution also, can anyone help me?
where can i found it?
Actually i include in mu C::B C parser a gcc arm toolchain and very many functions are declarated as extern so codecompletion cannot resolve those  :(
Thanks
Sorry If I can't get your idea.
You want to get the function declaration from a "shared library"?
@christobal
I'm confused about your discussion, can you give a simple test case? or where is the patch?

By the way, this thread should be moved to the CodeCompletion redesign subforum.
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.

ivan1979

Sorry,
i think plugin is implemented by a library (libcodecompletion.so) o no???

christobal

#10
Quote from: ollydbg on March 12, 2010, 04:06:02 PM
@christobal
I'm confused about your discussion, can you give a simple test case? or where is the patch?

The Patch is the code snippet from my fist post and the test case is the code snippet from my second post.

The problem is, that every token after the "extern" keyword get "swallowed" by the tokenizer without evaluation, and so the extern declared symbol won't appear in the codecompletion unless the implementation of this symbol can be found elsewhere in the project. In most cases, you will have the implementation in the same project and so the codecompletion will work. But if you use a library in your project and just have the headers, you won't see any symbols that have been declared with the extern keyword.

I hope I made this clear   :)

By the way, this is just a bugfix and has IMHO nothing to do with the CodeCompletion redesign.

ollydbg

@christobal
Ok, I see. If you have both a declaration and a function declaration in your project, how can CC locate the true location of a function declaration?

For example, you have A.h, and it contains:
extern void f();

And in B.h, you have :
void f();

Then, both A.h and B.h was in your project, so, the parser must have two "f" declarations if your not skip extern statement.

Technically, it is really easy to handle "extern" statement, but we need some comments from CB's developers. :D
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.

ivan1979

Hi,
that's my problem!
I include many arm-linux toolchain headers (pthread.h, sys/time.h, ...) but i can't see functions tooltips help because they are all declarated as extern functions...

ivan1979

Hi,

i have just recompiled codeblocks and modify the parserthread.cpp on according christobal patch, so i replaced the libcodecomplete.so with the new owe...it works!!!

Thanks
Ivan