This is an archive of the discontinued LLVM Phabricator instance.

[clang-import-test] Lookup inside entities
ClosedPublic

Authored by spyffe on Feb 27 2017, 4:16 PM.

Details

Summary

clang-import-test has until now been only able to report top-level entities. This is clearly insufficient; we should be able to look inside structs and namespaces also.
This patch adds new test cases for a variety of lookups inside existing entities, and adds the functionality necessary to make most of these testcases work.
One testcase is known to fail because of ASTImporter limitations when importing templates; this will be addressed separately.

Diff Detail

Repository
rL LLVM

Event Timeline

spyffe created this revision.Feb 27 2017, 4:16 PM
aprantl accepted this revision.Feb 27 2017, 4:28 PM

A few stylistic issues inline.
It also wouldn't hurt to document what is being tested, either in the clang-import-test sources or in the input files. Otherwise this looks fine. More tests are always great!

tools/clang-import-test/clang-import-test.cpp
213 ↗(On Diff #89949)

Sort of an irrelevant nitpick, but we don't typically use curly braces on single statements.

228 ↗(On Diff #89949)

->

// Couldn't find the name, so we have to give up.
return nullptr;

This revision is now accepted and ready to land.Feb 27 2017, 4:28 PM
spyffe updated this revision to Diff 89957.Feb 27 2017, 5:45 PM

• Applied Adrian's suggestion to move comments before the line they apply to.
• Got to 100% coverage by changing a test and making an assert for something I couldn't make happen in a test.

I did not take Adrian's suggestion to remove braces around a single-statement if because (as far as I can tell) the LLVM coding standard is silent on the topic and I prefer to have the braces there.

a.sidorin edited edge metadata.Mar 6 2017, 9:48 AM

Hello Sean,

It is good to have the ability of recursive lookup. But for me (and I'm sorry), the code becomes very hard to understand: I need to track if the Decl/DC is in the source AST or in the AST being imported, if it was imported or if was in the AST before across lambdas and calls. Can we make this more clear?

tools/clang-import-test/clang-import-test.cpp
201 ↗(On Diff #89957)

Can we make the usage of qualified and non-qualified casts consistent? Usually, casts are used as unqualified.

298 ↗(On Diff #89957)

I guess we can use SmallVectors here too.

303 ↗(On Diff #89957)

Nit: to make the code cleaner, we can extract this std::none_of to a separate function like IsFoundAsForward(). Nested lambdas are harder to read.

333 ↗(On Diff #89957)

The loop:

Decls.reserve(DeclsToReport.size());
for (Candidate &C : DeclsToReport)
  Decls.push_back(cast<NamedDecl>(C.second->Import(C.first)));

will look a bit nicer here. What do you think?

spyffe updated this revision to Diff 93721.Mar 31 2017, 3:49 PM

• Removed namespace qualification of cast across the board.
• Standardized on SmallVector
• Factored out the filtering of forward declarations
• Fixed a loop as requested.
• Made a Origin<> wrapper for arbitrary AST objects that makes it clear where they live, so importation and searching gets a little clearer.

spyffe updated this revision to Diff 93927.Apr 3 2017, 12:49 PM

• Broke all the ASTImporter and ExternalASTSource subclassing logic into its own source file, with its API defined in AST/ExternalASTMerger.h.
• Cleaned up the API for LLDB's consumption: now rather than a CompilerInstance a client just has to provide an ASTContext and a FileManager (just like when setting up an ASTImporter). This allows e.g. DWARF to be a valid source.

spyffe updated this revision to Diff 93929.Apr 3 2017, 12:51 PM

Added the ExternalASTMerger implementation/interface, which I hadn't svn added before generating the last diff.

a.sidorin accepted this revision.Apr 10 2017, 7:45 AM

Looks excellent now. Thank you Sean!

This revision was automatically updated to reflect the committed changes.