<div><br></div><div><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div>How are a preprocessor defines inserted (or removed) from a clang::Preprocessor object?<span class=""><font color="#888888"><br>
</font></span></div><span class=""><font color="#888888"><br></font></span></blockquote></div></div><div><br></div>Answering my own question, by hunting down the compiler driver handling of these:<br><br>tools/clang/lib/Frontend/InitPreprocessor.cpp:<div>
<br><div>void clang::InitializePreprocessor(Preprocessor &PP,</div><div> ...</div><div> ) {</div><div> const LangOptions &LangOpts = PP.getLangOpts();</div><div> std::string PredefineBuffer;</div>
<div> PredefineBuffer.reserve(4080);</div><div> llvm::raw_string_ostream Predefines(PredefineBuffer);</div><div> MacroBuilder Builder(Predefines);</div><div><br></div><div> ...</div><div><br></div><div> // Process #define's and #undef's in the order they are given.</div>
<div> for (unsigned i = 0, e = InitOpts.Macros.size(); i != e; ++i) {</div><div> if (InitOpts.Macros[i].second) // isUndef</div><div> Builder.undefineMacro(InitOpts.Macros[i].first);</div><div> else</div><div>
DefineBuiltinMacro(Builder, InitOpts.Macros[i].first,</div><div> PP.getDiagnostics());</div><div> }</div><div><br></div><div> // If -imacros are specified, include them now. These are processed before</div>
<div> // any -include directives.</div><div> for (unsigned i = 0, e = InitOpts.MacroIncludes.size(); i != e; ++i)</div><div> AddImplicitIncludeMacros(Builder, InitOpts.MacroIncludes[i],</div><div> PP.getFileManager());</div>
<div><br></div><div> ...</div><div> // Exit the command line and go back to <built-in> (2 is LC_LEAVE).</div><div> if (!PP.getLangOpts().AsmPreprocessor)</div><div> Builder.append("# 1 \"<built-in>\" 2");</div>
<div><br></div><div> // Copy PredefinedBuffer into the Preprocessor.</div><div> PP.setPredefines(Predefines.str());</div><div>...</div><div>}</div><div><br></div><div class="gmail_extra">-- <br>Peeter<br>
</div></div>