Author Topic: (solved) Code completion plugin won't complete local variables  (Read 7298 times)

Offline Acce

  • Single posting newcomer
  • *
  • Posts: 2
I'm using windows, (c::b build SVN 8150) and can't seem to get local variables to be completed.
I'm quite new to c::b, (moved from eclipse), so I might be doing something wrong, but everything I saw in the code completion plugin settings said nothing about local (automatic) variables.

For example,

Code
wakeup interrupt (USCIAB0RX_VECTOR) process_RX (void)
{
     int receive_buffer = 0;

     recei //hitting ctrl+space here doesn't bring up the variable name.

}

I'm using c::b to program msp430 microcontrollers using mspgcc, and this probably has something to do with that "weird" function declaration (declares an interrupt handler) which the code completion plugin can't parse correctly, because the function doesn't show up in code completion toolbar's function list either.

btw, without macros function call looks like this:
Code
__attribute__((wakeup)) void __attribute__((interrupt (x))) process_RX(void)
if that makes some difference..

Thanks in advance!


« Last Edit: August 23, 2012, 02:07:07 pm by Acce »

stefanos_

  • Guest
Re: Code completion plugin won't complete local variables
« Reply #1 on: August 22, 2012, 09:24:36 am »
Acce, on my system (Debian wheezy 32-bit) I have a similar issue and in order to solve it, I have to first save my changes, and then right-click on the project to re-parse it. It usually works, but when it does not I use Ctrl-SPACE and gives me the options I am looking for after re-parsing process.

Another awkward situation is when you hover on a macro, function or class, it shows you the information you are looking for, but with a right-click option to find its implementation or declaration, it does not take you to it.

It must be an issue with the parser I guess.

Offline ollydbg

  • Developer
  • Lives here!
  • *****
  • Posts: 5910
  • OpenCV and Robotics
    • Chinese OpenCV forum moderator
Re: Code completion plugin won't complete local variables
« Reply #2 on: August 22, 2012, 10:16:34 am »
I'm using windows, (c::b build SVN 8150) and can't seem to get local variables to be completed.
I'm quite new to c::b, (moved from eclipse), so I might be doing something wrong,
Welcome!!!
Quote
but everything I saw in the code completion plugin settings said nothing about local (automatic) variables.
Yes, there is no options for local(automatic variables).

Quote
For example,

Code
wakeup interrupt (USCIAB0RX_VECTOR) process_RX (void)
{
     int receive_buffer = 0;

     recei //hitting ctrl+space here doesn't bring up the variable name.

}

I'm using c::b to program msp430 microcontrollers using mspgcc, and this probably has something to do with that "weird" function declaration (declares an interrupt handler) which the code completion plugin can't parse correctly, because the function doesn't show up in code completion toolbar's function list either.

Yes, you are right. The code:
Code
wakeup interrupt (USCIAB0RX_VECTOR) process_RX (void)
is not a valid function definition. So, CB does not recognize it.


Quote
btw, without macros function call looks like this:
Code
__attribute__((wakeup)) void __attribute__((interrupt (x))) process_RX(void)
if that makes some difference.
I think you can add some custom string replacement rules for this kind of parsing, you can see this page for some details.
http://wiki.codeblocks.org/index.php?title=Code_Completion_Design#replacement_rules
You can basically strip the strings like "__attribute__((wakeup))" and "__attribute__((interrupt (x)))", so the parser see these code like below:
Code
void  process_RX(void)
This should be a valid function declaration/definition, because it have some string mode like "AAAA BBBBB(CCCC)". :)
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 Acce

  • Single posting newcomer
  • *
  • Posts: 2
Re: Code completion plugin won't complete local variables
« Reply #3 on: August 22, 2012, 11:50:48 am »
Awesome, sounds very promising! Thanks a lot!

because the "x" in interrupt(x) changes, can i do something like strip all strings starting with "__attribute__"?

As for the * rule, it is able to strip parentheses and such, but can it also strip what is inside the ()?

or is it possible to see to the parser output somehow so I can try different rules?

EDIT:
One more question..
Does the parser read the code "as is", or does it run the preprocessor first?


EDIT 2:

I managed to achieve wanted result by adding rules
"wakeup -> "
and
"interrupt -> void"

because the token created from interrupt(USCIAB0RX_VECTOR) is apparently only "interrupt", it got replaced nicely!

Thanks for your help!
« Last Edit: August 23, 2012, 02:06:02 pm by Acce »

Offline ollydbg

  • Developer
  • Lives here!
  • *****
  • Posts: 5910
  • OpenCV and Robotics
    • Chinese OpenCV forum moderator
Re: Code completion plugin won't complete local variables
« Reply #4 on: August 23, 2012, 05:07:57 pm »
Awesome, sounds very promising! Thanks a lot!

because the "x" in interrupt(x) changes, can i do something like strip all strings starting with "__attribute__"?

As for the * rule, it is able to strip parentheses and such, but can it also strip what is inside the ()?

Hi, those rules were added years ago, it was mainly in the code completion's source code:
void Tokenizer::MacroReplace(wxString& str)
Which is under:
svn.berlios.de/svnroot/repos/codeblocks/trunk/src/plugins/codecompletion/parser/tokenizer.cpp
So, if you need any improvement, patches were welcome. :)
In-fact, I would like to implement these rules just like we define a real macro, such as:
Code
#define _GLIBCXX_BEGIN_NESTED_NAMESPACE(a,b) namespace a {
So, it will be more clean then the currently way:
Current replace rule

Quote
or is it possible to see to the parser output somehow so I can try different rules?
If you can build c::b yourself, there is a cc_test project(cbp), then you can enable the TRACE, and see what the parser do when parsing the file.

Quote
EDIT:
One more question..
Does the parser read the code "as is", or does it run the preprocessor first?
There is no "preprocessor" stage in our parser, this takes a lot of time, we even don't expand the #include directive, the parser only parse each file(header file or source file) once, and it did some macro replacement in its tokenizer, also it guess whether it hit some macros in some heuristic way. Also, our parser is only a very simple c++ parser, we don't use semantic check or other complex things.




Quote
EDIT 2:

I managed to achieve wanted result by adding rules
"wakeup -> "
and
"interrupt -> void"

because the token created from interrupt(USCIAB0RX_VECTOR) is apparently only "interrupt", it got replaced nicely!

Thanks for your help!
Grad to see you solved the problem. :)
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: 5910
  • OpenCV and Robotics
    • Chinese OpenCV forum moderator
Re: Code completion plugin won't complete local variables
« Reply #5 on: August 23, 2012, 05:13:08 pm »
I have to first save my changes, and then right-click on the project to re-parse it.
Why, the parser should start the re-parsing of the saved file. But when you "re-parse" the project, the whole files were re-parsed.


Quote
It usually works, but when it does not I use Ctrl-SPACE and gives me the options I am looking for after re-parsing process.
I can't understand this.

Quote
Another awkward situation is when you hover on a macro, function or class, it shows you the information you are looking for, but with a right-click option to find its implementation or declaration, it does not take you to it.
It must be a bug, can you give us some sample code to reproduce?
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.