[cfe-dev] macro_begin()/macro_end()

Richard Smith richard at metafoo.co.uk
Wed Jul 29 17:36:11 PDT 2015


On Wed, Jul 29, 2015 at 5:35 PM, Richard Smith <richard at metafoo.co.uk>
wrote:

> On Wed, Jul 29, 2015 at 10:43 AM, Sean Callanan <scallanan at 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_lldb_trunk_source_Expression_ClangModulesDeclVendor.cpp&d=AwMFaQ&c=8hUWFZcy2Z-Za5rBPlktOQ&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:
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20150729/8b74686f/attachment.html>


More information about the cfe-dev mailing list