[
Date Prev][
Date Next][
Thread Prev][
Thread Next][
Date Index][
Thread Index]
[
List Home]
[cdt-dev] RE: [Bug 306819] CPPASTVisitor does not visit ASTNames contained in IASTPreprocessorStatements
|
Hi Lukas,
There is no IASTName for 'AB' on line 3 in your example. This is
because the right hand side of a macro definition is just a list of
tokens with no semantic meaning up to the point where the macro is
expanded.
To further illustrate that consider:
#define DIRECT_CALL(arg) AB(arg)
#define STRINGIFY(x) #x
#define EVAL_AND_STRINGIFY(x) STRINGIFY(x)
With the 3 macro definitions the in the following expansion, AB becomes
part of a string literal.
EVAL_AND_STRINGIFY(DIRECT_CALL(1)) // yields "AB(1)"
To find references of macro definitions you can use the following code:
IASTTranslationUnit tu;
IASTPreprocessorMacroDefinition macroDef;
IBinding macroBinding= macroDef.getName().resolveBinding();
IASTName[] refs= tu.getReferences(macroBinding);
Markus.
> -----Original Message-----
> From: Lukas Felber [mailto:lfelber@xxxxxx]
> Sent: Wednesday, March 24, 2010 8:58 PM
> To: Schorn, Markus
> Subject: Re: [Bug 306819] CPPASTVisitor does not visit
> ASTNames contained in IASTPreprocessorStatements
>
> Hi
>
> Thanks for your answer!
> Well I can understand your argumentation that the marco names
> are not visited. My problem is then how can I find the names
> contained in those nodes.
> Consider the following example:
>
> "
> 1. #define AB(arg) arg
> 2. #define CONCAT_CALL(first,second,arg) first##second(arg)
> 3. #define DIRECT_CALL(arg) AB(arg) 4.
> 5 .#if CONCAT_CALL(A,B,1) || defined(X)
> 6. #elif DIRECT_CALL(1)
> 7. #endif
> 8.
> 9. int main() {
> 10. int i = CONCAT_CALL(A,B,5);
> 11. int i2 = DIRECT_CALL(6);
> 12. }
> "
>
> 1. How can I find the name AB on line 3? (I already got the
> IASTPreprocessorFunctionStyleMacroDefinition, and also the name
> DIRECT_CALL)
> 2. How can I find both CONCAT_CALL and X on line 5 (Also here
> I have the IASTPreprocessorIfStatement). Actually CONCAT_CALL
> should also yield the name AB.
> 3. Line 5 should yield the names DIRECT_CALL and AB.
> 3. On line 10, I would like to find the names CONCAT_CALL and
> AB again.
> (I have the IASTPreprocessorMacroExpansion node)
>
> I am grateful for ever hint you can give me!
>
>
> Lukas
>
>