[prev in list] [next in list] [prev in thread] [next in thread] 

List:       cfe-dev
Subject:    Re: [cfe-dev] macro_begin()/macro_end()
From:       Sean Callanan <scallanan () apple ! com>
Date:       2015-07-30 16:31:50
Message-ID: 648205C8-2A76-4643-8E01-495EC23224A6 () apple ! com
[Download RAW message or body]

[Attachment #2 (multipart/alternative)]


Richard,

thanks for getting back to me!  The fix you proposed resolved the bug for me – and \
removing the code you said was redundant also worked fine.

Sean

> On Jul 29, 2015, at 5:36 PM, Richard Smith <richard@metafoo.co.uk> wrote:
> 
> On Wed, Jul 29, 2015 at 5:35 PM, Richard Smith <richard@metafoo.co.uk \
> <mailto:richard@metafoo.co.uk>> wrote: On Wed, Jul 29, 2015 at 10:43 AM, Sean \
> Callanan <scallanan@apple.com <mailto:scallanan@apple.com>> wrote: LLDB's module \
> support (implemented here: \
> http://llvm.org/svn/llvm-project/lldb/trunk/source/Expression/ClangModulesDeclVendor.cpp \
> <https://urldefense.proofpoint.com/v2/url?u=http-3A__llvm.org_svn_llvm-2Dproject_lld \
> b_trunk_source_Expression_ClangModulesDeclVendor.cpp&d=AwMFaQ&c=8hUWFZcy2Z-Za5rBPlkt \
> OQ&r=CnzuN65ENJ1H9py9XLiRvC_UQz6u3oG6GUNn7_wosSM&m=qJ7PzNcXqcUiCKOoFs9S4BDpb3TOf64WitZDB3JoLdM&s=WSvUUkZckMbgeN5UAaJKYWcqxxQzarzUBnC0_xfDRZ4&e=>) \
> sets up its own CompilerInstance and then loads modules into it. 
> The way we import macros from modules into expressions is by textual inclusion – \
> we iterate across the macros like this: 
> –
> if (m_compiler_instance->getPreprocessor().getExternalSource())
> {
> m_compiler_instance->getPreprocessor().getExternalSource()->ReadDefinedMacros();
> 
> FYI, this is redundant; macro_begin does this for you.
> 
> }
> 
> 
> for (clang::Preprocessor::macro_iterator mi = \
> m_compiler_instance->getPreprocessor().macro_begin(), me = \
> m_compiler_instance->getPreprocessor().macro_end(); mi != me; ++mi)
> {
> // ...
> clang::MacroInfo *macro_info = nullptr;
> 
> for (clang::ModuleMacro *module_macro : \
> m_compiler_instance->getPreprocessor().getLeafModuleMacros(ii)) {
> // pick the macro_info from the module we care most about; that might be NULL
> }
> 
> if (macro_info)
> {
> // make a string from the macro
> }
> }
> –
> 
> What Im noticing is that a macro (say, "MAX") doesn't appear in the macro_begin() \
> list at all.  Only later, after I've done a name lookup for "MAX" (on the \
> assumption that it might be a variable, see \
> ClangModulesDeclVendorImpl::FindDecls()), does it appear in the list. 
> Is there something else I need to tickle here, or is this a bug in the API?
> 
> Does this help:
> 
> Index: lib/Serialization/ASTReader.cpp
> ===================================================================
> --- lib/Serialization/ASTReader.cpp     (revision 243368)
> +++ lib/Serialization/ASTReader.cpp     (working copy)
> @@ -1623,7 +1623,7 @@
> 
> case PP_MACRO_OBJECT_LIKE:
> case PP_MACRO_FUNCTION_LIKE:
> -          getLocalIdentifier(**I, Record[0]);
> +          updateOutOfDateIdentifier(*getLocalIdentifier(**I, Record[0]));
> break;
> 
> case PP_TOKEN:
> 
> 


[Attachment #5 (unknown)]

<html><head><meta http-equiv="Content-Type" content="text/html \
charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; \
-webkit-line-break: after-white-space;" class="">Richard,<div class=""><br \
class=""></div><div class="">thanks for getting back to me! &nbsp;The fix you \
proposed resolved the bug for me – and removing the code you said was redundant \
also worked fine.</div><div class=""><br class=""></div><div class="">Sean</div><div \
class=""><br class=""></div><div class=""><div><blockquote type="cite" class=""><div \
class="">On Jul 29, 2015, at 5:36 PM, Richard Smith &lt;<a \
href="mailto:richard@metafoo.co.uk" class="">richard@metafoo.co.uk</a>&gt; \
wrote:</div><br class="Apple-interchange-newline"><div class=""><div dir="ltr" \
class=""><div class="gmail_extra"><div class="gmail_quote">On Wed, Jul 29, 2015 at \
5:35 PM, Richard Smith <span dir="ltr" class="">&lt;<a \
href="mailto:richard@metafoo.co.uk" target="_blank" \
class="">richard@metafoo.co.uk</a>&gt;</span> wrote:<br class=""><blockquote \
class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc \
solid;padding-left:1ex"><div dir="ltr" class=""><div class="gmail_extra"><div \
class="gmail_quote"><span class="">On Wed, Jul 29, 2015 at 10:43 AM, Sean Callanan \
<span dir="ltr" class="">&lt;<a href="mailto:scallanan@apple.com" target="_blank" \
class="">scallanan@apple.com</a>&gt;</span> wrote:<br 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" class="">LLDB's module \
support (implemented here:&nbsp;<a \
href="https://urldefense.proofpoint.com/v2/url?u=http-3A__llvm.org_svn_llvm-2Dproject_ \
lldb_trunk_source_Expression_ClangModulesDeclVendor.cpp&amp;d=AwMFaQ&amp;c=8hUWFZcy2Z- \
Za5rBPlktOQ&amp;r=CnzuN65ENJ1H9py9XLiRvC_UQz6u3oG6GUNn7_wosSM&amp;m=qJ7PzNcXqcUiCKOoFs \
9S4BDpb3TOf64WitZDB3JoLdM&amp;s=WSvUUkZckMbgeN5UAaJKYWcqxxQzarzUBnC0_xfDRZ4&amp;e=" \
target="_blank" class="">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 class=""><br \
class=""></div><div class="">The way we import macros from modules into expressions \
is by textual inclusion – we iterate across the macros like this:</div><div \
class=""><br class=""></div><div class="">–</div><div class=""><div \
style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo" class=""><div \
style="color:rgb(49,89,93);margin:0px;line-height:normal" class=""><span \
style="color:#bb2ca2" class="">if</span><span style="" class=""> (</span><span \
style="color:#4f8187" class="">m_compiler_instance</span><span style="" \
class="">-&gt;</span>getPreprocessor<span style="" \
class="">().</span>getExternalSource<span style="" class="">())</span></div><div \
style="color:rgb(79,129,135);margin:0px;line-height:normal" class=""><span style="" \
class="">{</span></div><div style="margin:0px;line-height:normal" \
class="">&nbsp;&nbsp;<span style="color:rgb(79,129,135)" \
class="">m_compiler_instance</span><span style="" class="">-&gt;</span><font \
color="#31595d" class="">getPreprocessor</font><span style="" \
class="">().</span><font color="#31595d" class="">getExternalSource</font><span \
style="" class="">()-&gt;</span><font color="#31595d" \
class="">ReadDefinedMacros</font><span style="" \
class="">();</span></div></div></div></div></blockquote></span></div></div></div></blockquote><div \
class=""><br class=""></div><div class="">FYI, this is redundant; macro_begin does \
this for you.</div><div class="">&nbsp;</div><blockquote class="gmail_quote" \
style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr" \
class=""><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" class=""><div class=""><div \
style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo" class=""><div \
style="color:rgb(79,129,135);margin:0px;line-height:normal" class=""><span style="" \
class="">}</span></div><div style="color:rgb(79,129,135)" class=""><br \
class=""></div></div><div \
style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(79,129,135)" \
class=""><span style="color:#bb2ca2" class=""><br class=""></span></div><div \
style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(79,129,135)" \
class=""><span style="color:#bb2ca2" class="">for</span><span style="" class=""> \
(</span>clang<span style="" class="">::</span>Preprocessor<span style="" \
class="">::</span>macro_iterator<span style="" class=""> mi = \
</span>m_compiler_instance<span style="" class="">-&gt;</span><span \
style="color:#31595d" class="">getPreprocessor</span><span style="" \
class="">().</span><span style="color:#31595d" class="">macro_begin</span><span \
style="" class="">(),</span></div><div \
style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo" \
class="">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; \
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;me = <span \
style="color:#4f8187" class="">m_compiler_instance</span>-&gt;<span \
style="color:#31595d" class="">getPreprocessor</span>().<span style="color:#31595d" \
class="">macro_end</span>();</div><div \
style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo" \
class="">&nbsp; &nbsp; &nbsp;mi != me; ++mi)</div><div \
style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(79,129,135)" \
class=""><span style="" class="">{</span></div></div><div \
style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo" class=""><span \
style="color:rgb(79,129,135)" class="">&nbsp;&nbsp;</span><span \
style="color:rgb(0,132,0)" class="">// ...</span></div><div class=""><span \
style="font-family:Menlo;font-size:11px" class="">&nbsp;&nbsp;</span><span \
style="font-family:Menlo;font-size:11px;color:rgb(79,129,135)" \
class="">clang</span><span style="font-family:Menlo;font-size:11px" \
class="">::</span><span \
style="font-family:Menlo;font-size:11px;color:rgb(79,129,135)" \
class="">MacroInfo</span><span style="font-family:Menlo;font-size:11px" class=""> \
*macro_info = </span><span \
style="font-family:Menlo;font-size:11px;color:rgb(187,44,162)" \
class="">nullptr</span><span style="font-family:Menlo;font-size:11px" \
class="">;</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; \
font-family: Menlo; min-height: 13px;" class="">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;<br \
class=""></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo" \
class="">&nbsp;&nbsp;<span style="color:#bb2ca2" class="">for</span> (<span \
style="color:#4f8187" class="">clang</span>::<span style="color:#4f8187" \
class="">ModuleMacro</span> *module_macro : <span style="color:#4f8187" \
class="">m_compiler_instance</span>-&gt;<span style="color:#31595d" \
class="">getPreprocessor</span>().<span style="color:#31595d" \
class="">getLeafModuleMacros</span>(ii))</div><div \
style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo" \
class="">&nbsp; {</div><div \
style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo" \
class="">&nbsp; &nbsp;&nbsp;<span style="color:rgb(0,132,0)" class="">// 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" \
class="">&nbsp; }</div><div style="margin: 0px; font-size: 11px; line-height: normal; \
font-family: Menlo; min-height: 13px;" class="">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;<br \
class=""></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo" \
class="">&nbsp;&nbsp;<span style="color:#bb2ca2" class="">if</span> \
(macro_info)</div><div \
style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo" \
class="">&nbsp; {</div><div \
style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo" \
class="">&nbsp; &nbsp;&nbsp;<span style="color:rgb(0,132,0)" class="">// make a \
string from the macro</span></div><div class=""><span \
style="font-family:Menlo;font-size:11px" class="">&nbsp; }</span></div><div \
class=""><font face="Menlo" class=""><span style="font-size:11px" \
class="">}</span></font></div><div class="">–</div><div class=""><br \
class=""></div><div class="">What Im noticing is that a macro (say, "MAX") doesn't \
appear in the&nbsp;<span style="font-family:Menlo;font-size:11px;color:rgb(49,89,93)" \
class="">macro_begin</span><span style="font-family:Menlo;font-size:11px" \
class="">()</span>&nbsp;list at all.&nbsp; Only later, after I've done a name lookup \
for "MAX" (on the assumption that it might be a variable, see&nbsp;<span \
style="color:rgb(79,129,135);font-family:Menlo;font-size:11px" \
class="">ClangModulesDeclVendorImpl</span><span \
style="font-family:Menlo;font-size:11px" class="">::FindDecls</span><span \
style="font-family:Menlo;font-size:11px" class="">()</span>), does it appear in the \
list.</div><div class=""><br class=""></div><div class="">Is there something else I \
need to tickle here, or is this a bug in the API?</div></div></blockquote><div \
class=""><br class=""></div></span><div class="">Does this help:</div><div \
class=""><br class=""></div><div class=""><div class="">Index: \
lib/Serialization/ASTReader.cpp</div><div \
class="">===================================================================</div><div \
class="">--- lib/Serialization/ASTReader.cpp &nbsp; &nbsp; (revision \
243368)</div><div class="">+++ lib/Serialization/ASTReader.cpp &nbsp; &nbsp; (working \
copy)</div><div class="">@@ -1623,7 +1623,7 @@</div><div class=""><br \
class=""></div><div class="">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;case \
PP_MACRO_OBJECT_LIKE:</div><div class="">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;case \
PP_MACRO_FUNCTION_LIKE:</div><div class="">- &nbsp; &nbsp; &nbsp; &nbsp; \
&nbsp;getLocalIdentifier(**I, Record[0]);</div><div class="">+ &nbsp; &nbsp; &nbsp; \
&nbsp; &nbsp;updateOutOfDateIdentifier(*getLocalIdentifier(**I, \
Record[0]));</div><div class="">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; \
&nbsp;break;</div><div class=""><br class=""></div><div class="">&nbsp; &nbsp; &nbsp; \
&nbsp; &nbsp;case PP_TOKEN:</div></div><div class=""><br \
class=""></div></div></div></div> </blockquote></div><br class=""></div></div>
</div></blockquote></div><br class=""></div></body></html>



_______________________________________________
cfe-dev mailing list
cfe-dev@cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic