User forums > Using Code::Blocks
X Macro
photon3108:
Does the autocomplete of CodeBlocks support X Macro?
ollydbg:
What does "X Macro" means?
photon3108:
http://en.wikipedia.org/wiki/X_Macro
It's a C marco skill. Some people use it to generate the code of enum and array in compile-time.
Because they generate enumerator in compile-time, I can't use autocomplete to select it.
ollydbg:
OK, I see.
The reason is that our parser(preprocessor) don't do a semantic check on every identifier, CB has macro expansion method, but it does not expand macro usage always.
For example, when the parser see a identifier like token:
--- Code: ---LIST_OF_VARIABLES
--- End code ---
It just see it as a simple type name or a variable name.
But what a compiler(gcc) do is to check every identifier to see whether it is a macro usage, and if it is true, then expand the macro.
I think we can enable it, but it will let the parser a bit slower, as you can think, checking of every identifier token takes much time, right?
Here is a test (cctest) file that we can test your request:
--- Code: ---/* x macro
* https://en.wikipedia.org/wiki/X_Macro
*/
#define LIST_OF_VARIABLES \
X(value1) \
X(value2) \
X(value3)
#define X(name) int name;
LIST_OF_VARIABLES
#undef X
// val //value1,value2,value3
--- End code ---
Currently, it get failed, but if we try to expand the LIST_OF_VARIABLES, I think it should be OK.
Also, for some enum definition:
--- Code: ---// test parsing of enumerator assignments
#define SHIFT(_x) (1 << (_x))
enum PowerEnum
{
powFirst = SHIFT(1),
powSecond = SHIFT(2),
powThird = SHIFT(3),
powFourth = SHIFT(4),
powFifth = SHIFT(5)
};
--- End code ---
the value is calculated, because we enable the macro expansion on enumerator definition. So you will see such tip: (image shot below)
You see, the tip show a value 32, which is calculated "1<<5".
Maybe, we can trigger macro expansion on a token which is totally capital characters?
Huki:
--- Quote from: ollydbg on March 05, 2014, 04:11:13 am ---I think we can enable it, but it will let the parser a bit slower, as you can think, checking of every identifier token takes much time, right?
Here is a test (cctest) file that we can test your request:
--- Code: ---/* x macro
* https://en.wikipedia.org/wiki/X_Macro
*/
#define LIST_OF_VARIABLES \
X(value1) \
X(value2) \
X(value3)
#define X(name) int name;
LIST_OF_VARIABLES
#undef X
// val //value1,value2,value3
--- End code ---
Currently, it get failed, but if we try to expand the LIST_OF_VARIABLES, I think it should be OK.
--- End quote ---
This feature is present in my cc_parser_general.patch (checks each identifier for preprocessor token if the m_Options.parseComplexMacros is on). It's a rather long patch with several other features, I'm trying to get the small ones (and bug fixes) in first. :)
Navigation
[0] Message Index
[#] Next page
Go to full version