[Clang Static Analyzer]: How to get name of Macro in Static Analyzer.

Hello!

I can’t give you much info about this.

I don’t think you can get the macro name directly. A couple of months ago I wanted to see if a AST element was inside a assert macro or not… but was told that there is no direct way to find this out.

I believe you could do it in some “hacky” way though. For instance by looking at the data that is used to output raw source code in error messages. Maybe there is a better way.

Best regards,
Daniel Marjamäki

Daniel Marjamäki Senior Engineer

Evidente ES East AB Warfvinges väg 34 SE-112 51 Stockholm Sweden

Mobile: +46 (0)709 12 42 62

E-mail: Daniel.Marjamaki@evidente.se

www.evidente.se

Hi,

I am able to get the macro name for cases where parenthesis is not there using ‘getMacroNameOrSpelling’ function.

But when a parenthesis is there, it is not giving the correct output.

Kindly suggest me a way to get the macro name when parenthesis is present.

I have tried using ‘IgnoreParens’ of Expr class but failed to get the macro name.

Below is an example code for the same:

#define SLEEP 20

#define WAKE 10

int g_var = 10;

U1 U1_Function()

{

If(g_var == 20) {

return (SLEEP); // I am not able to get the macro name when parenthesis is present in it.

}

return WAKE; // I am able to get the macro name in this case using ‘getMacroNameOrSpelling’

}

Thanks,

Prashant S. Purohit