<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Wed, Jul 29, 2015 at 5:35 PM, Richard Smith <span dir="ltr"><<a href="mailto:richard@metafoo.co.uk" target="_blank">richard@metafoo.co.uk</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"><div class="gmail_extra"><div class="gmail_quote"><span class="">On Wed, Jul 29, 2015 at 10:43 AM, Sean Callanan <span dir="ltr"><<a href="mailto:scallanan@apple.com" target="_blank">scallanan@apple.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word">LLDB’s module support (implemented here: <a href="https://urldefense.proofpoint.com/v2/url?u=http-3A__llvm.org_svn_llvm-2Dproject_lldb_trunk_source_Expression_ClangModulesDeclVendor.cpp&d=AwMFaQ&c=8hUWFZcy2Z-Za5rBPlktOQ&r=CnzuN65ENJ1H9py9XLiRvC_UQz6u3oG6GUNn7_wosSM&m=qJ7PzNcXqcUiCKOoFs9S4BDpb3TOf64WitZDB3JoLdM&s=WSvUUkZckMbgeN5UAaJKYWcqxxQzarzUBnC0_xfDRZ4&e=" target="_blank">http://llvm.org/svn/llvm-project/lldb/trunk/source/Expression/ClangModulesDeclVendor.cpp</a>) sets up its own CompilerInstance and then loads modules into it.<div><br></div><div>The way we import macros from modules into expressions is by textual inclusion – we iterate across the macros like this:</div><div><br></div><div>–</div><div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"><div style="color:rgb(49,89,93);margin:0px;line-height:normal"><span style="color:#bb2ca2">if</span><span style="color:#000000"> (</span><span style="color:#4f8187">m_compiler_instance</span><span style="color:#000000">-></span>getPreprocessor<span style="color:#000000">().</span>getExternalSource<span style="color:#000000">())</span></div><div style="color:rgb(79,129,135);margin:0px;line-height:normal"><span style="color:rgb(0,0,0)">{</span></div><div style="margin:0px;line-height:normal">  <span style="color:rgb(79,129,135)">m_compiler_instance</span><span style="color:rgb(0,0,0)">-></span><font color="#31595d">getPreprocessor</font><span style="color:rgb(0,0,0)">().</span><font color="#31595d">getExternalSource</font><span style="color:rgb(0,0,0)">()-></span><font color="#31595d">ReadDefinedMacros</font><span style="color:rgb(0,0,0)">();</span></div></div></div></div></blockquote></span></div></div></div></blockquote><div><br></div><div>FYI, this is redundant; macro_begin does this for you.</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><span class=""><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word"><div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"><div style="color:rgb(79,129,135);margin:0px;line-height:normal"><span style="color:rgb(0,0,0)">}</span></div><div style="color:rgb(79,129,135)"><br></div></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(79,129,135)"><span style="color:#bb2ca2"><br></span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(79,129,135)"><span style="color:#bb2ca2">for</span><span style="color:#000000"> (</span>clang<span style="color:#000000">::</span>Preprocessor<span style="color:#000000">::</span>macro_iterator<span style="color:#000000"> mi = </span>m_compiler_instance<span style="color:#000000">-></span><span style="color:#31595d">getPreprocessor</span><span style="color:#000000">().</span><span style="color:#31595d">macro_begin</span><span style="color:#000000">(),</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo">                                         me = <span style="color:#4f8187">m_compiler_instance</span>-><span style="color:#31595d">getPreprocessor</span>().<span style="color:#31595d">macro_end</span>();</div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo">     mi != me; ++mi)</div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(79,129,135)"><span style="color:rgb(0,0,0)">{</span></div></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"><span style="color:rgb(79,129,135)">  </span><span style="color:rgb(0,132,0)">// ...</span></div><div><span style="font-family:Menlo;font-size:11px">  </span><span style="font-family:Menlo;font-size:11px;color:rgb(79,129,135)">clang</span><span style="font-family:Menlo;font-size:11px">::</span><span style="font-family:Menlo;font-size:11px;color:rgb(79,129,135)">MacroInfo</span><span style="font-family:Menlo;font-size:11px"> *macro_info = </span><span style="font-family:Menlo;font-size:11px;color:rgb(187,44,162)">nullptr</span><span style="font-family:Menlo;font-size:11px">;</span></div><p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;min-height:13px">        <br></p><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo">  <span style="color:#bb2ca2">for</span> (<span style="color:#4f8187">clang</span>::<span style="color:#4f8187">ModuleMacro</span> *module_macro : <span style="color:#4f8187">m_compiler_instance</span>-><span style="color:#31595d">getPreprocessor</span>().<span style="color:#31595d">getLeafModuleMacros</span>(ii))</div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo">  {</div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo">    <span style="color:rgb(0,132,0)">// pick the macro_info from the module we care most about; that might be NULL</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo">  }</div><p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;min-height:13px">        <br></p><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo">  <span style="color:#bb2ca2">if</span> (macro_info)</div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo">  {</div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo">    <span style="color:rgb(0,132,0)">// make a string from the macro</span></div><div><span style="font-family:Menlo;font-size:11px">  }</span></div><div><font face="Menlo"><span style="font-size:11px">}</span></font></div><div>–</div><div><br></div><div>What Im noticing is that a macro (say, “MAX”) doesn’t appear in the <span style="font-family:Menlo;font-size:11px;color:rgb(49,89,93)">macro_begin</span><span style="font-family:Menlo;font-size:11px">()</span> list at all.  Only later, after I’ve done a name lookup for “MAX" (on the assumption that it might be a variable, see <span style="color:rgb(79,129,135);font-family:Menlo;font-size:11px">ClangModulesDeclVendorImpl</span><span style="font-family:Menlo;font-size:11px">::FindDecls</span><span style="font-family:Menlo;font-size:11px">()</span>), does it appear in the list.</div><div><br></div><div>Is there something else I need to tickle here, or is this a bug in the API?</div></div></blockquote><div><br></div></span><div>Does this help:</div><div><br></div><div><div>Index: lib/Serialization/ASTReader.cpp</div><div>===================================================================</div><div>--- lib/Serialization/ASTReader.cpp     (revision 243368)</div><div>+++ lib/Serialization/ASTReader.cpp     (working copy)</div><div>@@ -1623,7 +1623,7 @@</div><div><br></div><div>         case PP_MACRO_OBJECT_LIKE:</div><div>         case PP_MACRO_FUNCTION_LIKE:</div><div>-          getLocalIdentifier(**I, Record[0]);</div><div>+          updateOutOfDateIdentifier(*getLocalIdentifier(**I, Record[0]));</div><div>           break;</div><div><br></div><div>         case PP_TOKEN:</div></div><div><br></div></div></div></div>
</blockquote></div><br></div></div>