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

Prashant Purohit Prashant.Purohit at kpit.com
Tue Dec 24 01:55:27 PST 2013

Hi all,

I am trying to write a check where I need name of the macro used in the source code.

E:g - (Sample source code)
#define SLEEP 20
#define WAKE 10

int g_var = 10;

U1 U1_Function()
  If(g_var == 20) {
          return (SLEEP); // I need to get the macro name in string format as 'SLEEP'

return WAKE; // I need to get the macro name in string format as 'WAKE'.

I am able to check if particular statement contains macro or not using 'containsMacro' function.
But I am not getting the actual macro name, though I tried using 'getMacroNameOrSpelling'.
When I used 'getMacroNameOrSpelling', I either get 'return' or '(' in the string but not the actual macro name.

Kindly suggest me a way to get macro name in a Stmt.
Thanks in advance.

Prashant S. Purohit
This message contains information that may be privileged or confidential and is the property of the KPIT Technologies Ltd. It is intended only for the person to whom it is addressed. If you are not the intended recipient, you are not authorized to read, print, retain copy, disseminate, distribute, or use this message or any part thereof. If you receive this message in error, please notify the sender immediately and delete all copies of this message. KPIT Technologies Ltd. does not accept any liability for virus infected mails.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20131224/4f3d8e54/attachment.html>

More information about the cfe-dev mailing list