Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
RE: [cdt-dev] How to differenciate a call toafunctionfromareferencingits address?

> The approach I had used does not work. All the nested macro 
> are using the same file location.
> I still cannot figure out how to verify that nested macro is 
> a second parameter.
> Nested macro's getNodeLocations() does not return any 
> ASTMacroExpansionLocation, it returns ASTFileLocation, so I 
> cannot even use the ASTMacroExpansionLocation of secondParam.
> I'm wondering why nested macro's getNodeLocations() is not a 
> ASTMacroExpansionLocation?

Within the location model used by CDT the location of a nested macro
cannot be 
expressed. This is a conscious decision, the attempt to model the
locations in
full complexity was a failure. See bug
https://bugs.eclipse.org/bugs/show_bug.cgi?id=202459

Because nested macro references do return a location array, I should
document what you
can expect in this case (the file location of the enclosing macro
expansion is returned).

As written before, to figure out the role of a nested macro expansion
you can look at
its ImageLocation.

I am not sure that the problem you are trying to solve makes sense in
the general
case of macro expansions. There is no strict hierarchy for nested macro
expansions, 
basically because expansions can nest in two ways:
(a) arguments of macros in most cases are expanded before substitution.
(b) after substitution the result is rescanned and further expansions
    may be performed. 
(*) To make things more complicated you need to consider additional
tokens from the
    input when rescanning the expansion.

Example (1)
#define add operator+
#define apply(f, x, y) f(x,y)
apply(add, 1, 2)  // expands to operator+(1,2), 'add' expanded before
'apply'

Example (2)
#define add(x,y) x+y
#define apply(f, x, y) f(x,y)
apply(add, 1, 2)  // expands to 1+2, 'add' expanded after 'apply'

Example (*):
#define open a(
#define a(x) x+1
open y)   // expands to y+1
 
> 
> Another question is what are the meaning of 
> ASTMacroExpansionLocation's offset and length? How can I use 
> those values?

They are documented in the public interfaces, which you should be using.

Markus.


Back to the top