CodeQL library for C/C++
Search

Member predicate MacroAccess::getParentInvocation

Gets the parent macro invocation, if any. For example:

1:  #define C 0
2:  #define P C
3:  static int x = P;

The invocation of P on line 3 also invokes C. The invocation of P is the parent of the invocation of C.

A macro invocation occurring in a macro argument often also establishes a parent relationship. This is due to the “call-by-name” evaluation order of C macros, where macro arguments are first substituted textually into the macro body before macro expansion is again performed on the body, invoking the macros present in the original macro argument. For example:

1:  #define C 0
2:  #define P(c)  c + c
3:  static int x = P(C);

In this case, P(C) first expands to C + C, which triggers an invocation of C whose parent is the invocation of P. Had c not occurred in the body of P, there would have been no invocation of C. There is only a single invocation even though c occurs twice; this is an optimization for efficiency.

MacroInvocation getParentInvocation()