<div dir="ltr">Found a way. For anyone interested:<div><div><br></div><div>MacroInfo* RegisterMacro(Preprocessor &PP, const char *Name){</div><div>  // Get the identifier.</div><div>  IdentifierInfo *Id = PP.getIdentifierInfo(Name);</div>
<div><br></div><div>  // Mark it as being a macro that is builtin.</div><div>  MacroInfo *MI = PP.AllocateMacroInfo(SourceLocation());</div><div>  MI->setIsBuiltinMacro();</div><div>  PP.setMacroInfo(Id, MI);</div><div>
<br></div><div>  return MI;</div><div>}</div><div><br></div><div>...</div><div><br></div><div>RegisterMacro(preprocessor, "FOO");</div><div><br></div><div><br></div><div>If you need replacement strings, manipulate the returned MacroInfo as follows:</div>
<div><br></div><div><div>        Token t;</div><div><span class="Apple-tab-span" style="white-space:pre">   </span>t.startToken();</div><div><span class="Apple-tab-span" style="white-space:pre">      </span>auto& i = preprocessor.getIdentifierTable().get("Replacement_String", tok::TokenKind::identifier);</div>
<div><span class="Apple-tab-span" style="white-space:pre">      </span>t.setIdentifierInfo(&i);</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>macroInfo->AddTokenToBody(t);</div></div><br><div class="gmail_quote">
On Sat, Apr 7, 2012 at 9:45 PM, Yaakov Davis <span dir="ltr"><<a href="mailto:yaakov.davis@gmail.com">yaakov.davis@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div dir="ltr">I'm not using the command line, but the lib through code. How do I achieve the desired effect <i>programatically</i>?<div><div class="h5"><br><br><div class="gmail_quote">On Sat, Apr 7, 2012 at 9:42 PM, Matthieu Monrocq <span dir="ltr"><<a href="mailto:matthieu.monrocq@gmail.com" target="_blank">matthieu.monrocq@gmail.com</a>></span> wrote:<br>

<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><br><br><div class="gmail_quote">Le 7 avril 2012 20:17, Yaakov Davis <span dir="ltr"><<a href="mailto:yaakov.davis@gmail.com" target="_blank">yaakov.davis@gmail.com</a>></span> a écrit :<br>

<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div>
<div dir="ltr"><span>I want to programatically define a symbol, e.g. FOO, such that the code "#if defined(FOO)" will evaluate to true during pre-processing. </span><div>How do I that?<div><br></div></div>
<div>I tried addMacroDef("FOO"), and other methods, but to no avail.</div></div>
<br></div>_______________________________________________<br>
cfe-dev mailing list<br>
<a href="mailto:cfe-dev@cs.uiuc.edu" target="_blank">cfe-dev@cs.uiuc.edu</a><br>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev</a><br>
<br></blockquote><div> </div></div>Either:<br><br>#define FOO<br><br>in the code or<br><br>-DFOO<br><br>on the command line during the compilation (for gcc and clang at least)<span><font color="#888888"><br>
<br>-- Matthieu<br>
</font></span></blockquote></div><br></div></div></div>
</blockquote></div><br></div></div>