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

List:       cfe-dev
Subject:    [cfe-dev] macro_begin()/macro_end()
From:       Sean Callanan <scallanan () apple ! com>
Date:       2015-07-29 17:43:29
Message-ID: 46EA3E9E-AAFF-4216-B95B-AEAA172C3B42 () apple ! com
[Download RAW message or body]

[Attachment #2 (multipart/alternative)]


LLDB's module support (implemented here: \
http://llvm.org/svn/llvm-project/lldb/trunk/source/Expression/ClangModulesDeclVendor.cpp) \
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();
}


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?

Sean


[Attachment #5 (text/html)]

<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="">LLDB's module support (implemented \
here:&nbsp;<a href="https://urldefense.proofpoint.com/v2/url?u=http-3A__llvm.org_svn_l \
lvm-2Dproject_lldb_trunk_source_Expression_ClangModulesDeclVendor.cpp&d=AwMFaQ&c=8hUWF \
Zcy2Z-Za5rBPlktOQ&r=CnzuN65ENJ1H9py9XLiRvC_UQz6u3oG6GUNn7_wosSM&m=qJ7PzNcXqcUiCKOoFs9S4BDpb3TOf64WitZDB3JoLdM&s=WSvUUkZckMbgeN5UAaJKYWcqxxQzarzUBnC0_xfDRZ4&e=" \
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="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" \
class="">if</span><span style="font-variant-ligatures: no-common-ligatures; color: \
#000000" class=""> (</span><span style="font-variant-ligatures: no-common-ligatures; \
color: #4f8187" class="">m_compiler_instance</span><span \
style="font-variant-ligatures: no-common-ligatures; color: #000000" \
class="">-&gt;</span>getPreprocessor<span style="font-variant-ligatures: \
no-common-ligatures; color: #000000" class="">().</span>getExternalSource<span \
style="font-variant-ligatures: no-common-ligatures; color: #000000" \
class="">())</span></div><div style="color: rgb(79, 129, 135); margin: 0px; \
line-height: normal;" class=""><span style="color: rgb(0, 0, 0);" \
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="color: rgb(0, 0, 0);" \
class="">-&gt;</span><font color="#31595d" class="">getPreprocessor</font><span \
style="color: rgb(0, 0, 0);" class="">().</span><font color="#31595d" \
class="">getExternalSource</font><span style="color: rgb(0, 0, 0);" \
class="">()-&gt;</span><font color="#31595d" class="">ReadDefinedMacros</font><span \
style="color: rgb(0, 0, 0);" class="">();</span></div><div style="color: rgb(79, 129, \
135); margin: 0px; line-height: normal;" class=""><span style="color: rgb(0, 0, 0);" \
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="font-variant-ligatures: no-common-ligatures; 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="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" \
class="">for</span><span style="font-variant-ligatures: no-common-ligatures; color: \
#000000" class=""> (</span>clang<span style="font-variant-ligatures: \
no-common-ligatures; color: #000000" class="">::</span>Preprocessor<span \
style="font-variant-ligatures: no-common-ligatures; color: #000000" \
class="">::</span>macro_iterator<span style="font-variant-ligatures: \
no-common-ligatures; color: #000000" class=""> mi = </span>m_compiler_instance<span \
style="font-variant-ligatures: no-common-ligatures; color: #000000" \
class="">-&gt;</span><span style="font-variant-ligatures: no-common-ligatures; color: \
#31595d" class="">getPreprocessor</span><span style="font-variant-ligatures: \
no-common-ligatures; color: #000000" class="">().</span><span \
style="font-variant-ligatures: no-common-ligatures; color: #31595d" \
class="">macro_begin</span><span style="font-variant-ligatures: no-common-ligatures; \
color: #000000" 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="font-variant-ligatures: \
no-common-ligatures; color: #4f8187" class="">m_compiler_instance</span>-&gt;<span \
style="font-variant-ligatures: no-common-ligatures; color: #31595d" \
class="">getPreprocessor</span>().<span style="font-variant-ligatures: \
no-common-ligatures; 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="color: rgb(0, 0, 0);" 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><p style="margin: 0px; font-size: \
11px; line-height: normal; font-family: Menlo; min-height: 13px;" \
class="">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;<br \
class="webkit-block-placeholder"></p><div style="margin: 0px; font-size: 11px; \
line-height: normal; font-family: Menlo;" class="">&nbsp;&nbsp;<span \
style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" \
class="">for</span> (<span style="font-variant-ligatures: no-common-ligatures; color: \
#4f8187" class="">clang</span>::<span style="font-variant-ligatures: \
no-common-ligatures; color: #4f8187" class="">ModuleMacro</span> *module_macro : \
<span style="font-variant-ligatures: no-common-ligatures; color: #4f8187" \
class="">m_compiler_instance</span>-&gt;<span style="font-variant-ligatures: \
no-common-ligatures; color: #31595d" class="">getPreprocessor</span>().<span \
style="font-variant-ligatures: no-common-ligatures; 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><p style="margin: 0px; font-size: 11px; line-height: normal; \
font-family: Menlo; min-height: 13px;" class="">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;<br \
class="webkit-block-placeholder"></p><div style="margin: 0px; font-size: 11px; \
line-height: normal; font-family: Menlo;" class="">&nbsp;&nbsp;<span \
style="font-variant-ligatures: no-common-ligatures; 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 class=""><br class=""></div><div \
class="">Sean</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