Bug #18411 2011-11-10 11:37
alatar_
CC can`t add register variable
If variable defined as
register uint8_t MyVarName asm("r2");
(for example this syntax used by avr-gcc) it don`t add to compelion symbols list. In the symbol->Global variables it is listed as
asm : register uint8_t MyVarName
- Category
- Plugin::CodeCompletion
- Group
- Status
- Open
- Close date
- Assigned to
- ollydbg
History
what does asm("r2") means?
This means that variable MyVarName will be always stored in the register r2.
http://www.nongnu.org/avr-libc/user-manual/FAQ.html#faq_regbind
Hi, the code has the format:
AAA BBB CCC ();
And it will recognized as a global function. Not sure why it became a global variable. I just start a thread:
http://forums.codeblocks.org/index.php/topic,15930.msg107310.html#msg107310
Regard to your bug report, I think the best way is to define a custom replacement rule(like a macro definition)
The replacement rule should be:
asm( ) ---> NONE
So, that you code can looks like:
register uint8_t MyVarName;
And this string has the format
AAA BBB CCC;
Now, the CCC part will be recognized as a global variable.
The pity is currently we don't have such replacement rule, but it is put in my TODO list.
Luckily, you can use a replacement rule:
asm ----> NONE
This will change your code in the parser internally like (strip the "asm"):
register uint8_t MyVarName ("r2");
And now, it works OK as you expect.
Thanks for idea but I don`t understand why this string should be interpreted as a variable definition, not function definition?
Because to the function definition can`t be passed string instead of argument?
Answer1: In-fact, as in c/c++, a syntax parser can't disambiguate the variable definition and function declaration. It need a more semantic analysis.
http://en.wikipedia.org/wiki/Semantic_analysis_%28compilers%29#Front_end
But as you know, parser in CC is quite limited, and we only have some kind of syntax analysis, because writing a full semantic parser is a too complex. (you can take gcc's source code for example).
Answer2: Function declaration should not have a single string in the parentheses, This is true. So from a syntax point of view:
AAA BBB CCC("ddd");
should not be a function declaration. So, we can further add this check, but Note: This is still not sufficient enough, because there are many special case like this.
Update, When we have such code:
AAA BBB CCC("xxxx");
It should be recognized as a variable, because the arguments "xxxx" can not be used in a function declaration.
See:
http://forums.codeblocks.org/index.php/topic,15930.msg107334.html#msg107334