--===============0907279256684701976== Content-Type: multipart/alternative; boundary=bcaec52d52dd852d3e051c0ce10a --bcaec52d52dd852d3e051c0ce10a Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable On Wed, Jul 29, 2015 at 10:43 AM, Sean Callanan wrote= : > LLDB=E2=80=99s module support (implemented here: > http://llvm.org/svn/llvm-project/lldb/trunk/source/Expression/ClangModule= sDeclVendor.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 =E2=80=93 we iterate across the macros like this: > > =E2=80=93 > if (m_compiler_instance->getPreprocessor().getExternalSource()) > { > m_compiler_instance->getPreprocessor().getExternalSource()-> > ReadDefinedMacros(); > } > > > for (clang::Preprocessor::macro_iterator mi =3D m_compiler_instance-> > getPreprocessor().macro_begin(), > me =3D m_compiler_instance-> > getPreprocessor().macro_end(); > mi !=3D me; ++mi) > { > // ... > clang::MacroInfo *macro_info =3D 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 > } > } > =E2=80=93 > > What Im noticing is that a macro (say, =E2=80=9CMAX=E2=80=9D) doesn=E2=80= =99t appear in the > macro_begin() list at all. Only later, after I=E2=80=99ve done a name lo= okup for > =E2=80=9CMAX" (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 AP= I? > Does this help: Index: lib/Serialization/ASTReader.cpp =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- 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: --bcaec52d52dd852d3e051c0ce10a Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable
On W= ed, Jul 29, 2015 at 10:43 AM, Sean Callanan <scallanan@apple.com&g= t; wrote:
LLDB=E2=80=99s module support (implemented here:=C2=A0htt= p://llvm.org/svn/llvm-project/lldb/trunk/source/Expression/ClangModulesDecl= Vendor.cpp) sets up its own CompilerInstance and then loads modules int= o it.

The way we import macros from modules into express= ions is by textual inclusion =E2=80=93 we iterate across the macros like th= is:

=E2=80=93
if<= /span> (= m_compiler_instance->getPrep= rocessor().getExternalSource())
{
=
=C2=A0=C2=A0m_compiler_instance->getPreprocessor().getExternalSource()->ReadDefinedMacros();
<= div style=3D"color:rgb(79,129,135);margin:0px;line-height:normal">}
=

=
for (clang::Preprocessor::macro_iterato= r mi =3D m_compiler_instance->getPreprocess= or().macro_begin(),
=C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0me =3D= m_compiler_instance->getPreprocessor().m= acro_end();
=C2=A0 =C2=A0 =C2=A0mi !=3D me; ++mi)
{
=C2=A0=C2=A0// ...
=C2=A0=C2=A0clang::MacroInfo *macro_info =3D nullptr;

=C2=A0=C2=A0 =C2=A0 =C2= =A0 =C2=A0

=C2=A0=C2=A0for (= clang::M= oduleMacro *module_macro : m_compiler_= instance->getPreprocessor().= getLeafModuleMacros(ii))
=C2= =A0 {
=C2=A0 =C2=A0=C2=A0// pick= the macro_info from the module we care most about; that might be NULL
=C2=A0 }

=C2=A0=C2=A0 =C2=A0 =C2=A0 =C2=A0=

=C2=A0=C2=A0if (macro_info)=
=C2=A0 {
=C2=A0 =C2=A0=C2=A0// make a string from the macro
=C2=A0 }
= }
=E2=80=93

What Im noticing is that a macro (say, =E2=80=9CMAX=E2=80= =9D) doesn=E2=80=99t appear in the=C2=A0macro_begin()=C2=A0list at all.=C2=A0 Only later, aft= er I=E2=80=99ve done a name lookup for =E2=80=9CMAX" (on the assumptio= n that it might be a variable, see=C2=A0ClangModulesDeclVendorImpl::FindDecls()), does it appear in the list.<= /div>

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
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
--- lib/Serialization/ASTReader.cpp =C2=A0 =C2=A0 (revision 243368)
=
+++ lib/Serialization/ASTReader.cpp =C2=A0 =C2=A0 (working copy)
=
@@ -1623,7 +1623,7 @@

=C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0case PP_MACRO_OBJECT_LIKE:
=C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0case PP_MACRO_FUNCTION_LIKE:
- =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0getLocalIdentifier(**I, Record[0]);
+ =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0updateOutOfDateIdentifier(*getLocalIdentifier(**I, Record[= 0]));
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0break;
<= br>
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0case PP_TOKEN:
<= div>
--bcaec52d52dd852d3e051c0ce10a-- --===============0907279256684701976== Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ cfe-dev mailing list cfe-dev@cs.uiuc.edu http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev --===============0907279256684701976==--