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

Prashant Purohit Prashant.Purohit at kpit.com
Wed Dec 25 21:17:52 PST 2013


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

From: Daniel Marjamäki [mailto:Daniel.Marjamaki at evidente.se]
Sent: 25 December 2013 14:06
To: Prashant Purohit
Cc: cfe-dev at cs.uiuc.edu
Subject: Re: [cfe-dev] [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<mailto:Daniel.Marjamaki at evidente.se>@evidente.se<mailto:Daniel.Marjamaki at evidente.se>

www.evidente.se<http://www.evidente.se>
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/20131226/d3905efa/attachment.html>


More information about the cfe-dev mailing list