13 #include "clang/AST/RecursiveASTVisitor.h" 14 #include "clang/Frontend/CompilerInvocation.h" 15 #include "clang/Frontend/Utils.h" 23 ImportThunk =
testPath(
"import_thunk.h");
27 std::string ThunkContents =
"#import \"" + FullHeaderName +
"\"\n";
30 Files[FullFilename] =
Code;
32 Files[ImportThunk] = ThunkContents;
34 std::vector<const char *> Cmd = {
"clang"};
38 Cmd.push_back(
"-include");
40 : FullHeaderName.c_str());
44 Cmd.push_back(
"-fno-ms-compatibility");
49 Cmd.push_back(FullFilename.c_str());
63 assert(CI &&
"Failed to build compilation invocation.");
70 if (!
AST.hasValue()) {
71 ADD_FAILURE() <<
"Failed to build code:\n" <<
Code;
72 llvm_unreachable(
"Failed to build TestTU!");
74 return std::move(*
AST);
80 AST.getPreprocessorPtr(),
81 AST.getCanonicalIncludes()));
86 auto Idx = llvm::make_unique<FileIndex>(
true);
87 Idx->updatePreamble(
Filename,
AST.getASTContext(),
AST.getPreprocessorPtr(),
88 AST.getCanonicalIncludes());
90 return std::move(Idx);
95 for (
const Symbol &S : Slab) {
96 if (QName != (S.Scope + S.Name).str())
99 ADD_FAILURE() <<
"Multiple symbols named " << QName <<
":\n" 100 << *Result <<
"\n---\n" 102 assert(
false &&
"QName is not unique");
107 ADD_FAILURE() <<
"No symbol named " << QName <<
" in " 108 << ::testing::PrintToString(Slab);
109 assert(
false &&
"No symbol with QName");
115 llvm::SmallVector<llvm::StringRef, 4> Components;
116 QName.split(Components,
"::");
119 auto LookupDecl = [&
Ctx](
const DeclContext &Scope,
120 llvm::StringRef
Name) ->
const NamedDecl & {
121 auto LookupRes = Scope.lookup(DeclarationName(&
Ctx.Idents.get(
Name)));
122 assert(!LookupRes.empty() &&
"Lookup failed");
123 assert(LookupRes.size() == 1 &&
"Lookup returned multiple results");
124 return *LookupRes.front();
127 const DeclContext *Scope =
Ctx.getTranslationUnitDecl();
128 for (
auto NameIt = Components.begin(), End = Components.end() - 1;
129 NameIt != End; ++NameIt) {
130 Scope = &cast<DeclContext>(LookupDecl(*Scope, *NameIt));
132 return LookupDecl(*Scope, Components.back());
136 std::function<
bool(
const NamedDecl &)> Filter) {
137 struct Visitor : RecursiveASTVisitor<Visitor> {
139 llvm::SmallVector<const NamedDecl *, 1> Decls;
140 bool VisitNamedDecl(
const NamedDecl *ND) {
147 Visitor.TraverseDecl(AST.
getASTContext().getTranslationUnitDecl());
148 if (Visitor.Decls.size() != 1) {
149 ADD_FAILURE() << Visitor.Decls.size() <<
" symbols matched.";
150 assert(Visitor.Decls.size() == 1);
152 return *Visitor.Decls.front();
156 return findDecl(AST, [Name](
const NamedDecl &ND) {
157 if (
auto *ID = ND.getIdentifier())
158 if (ID->getName() ==
Name)
llvm::Optional< std::string > Checks
Checks filter.
An immutable symbol container that stores a set of symbols.
llvm::Optional< std::string > ClangTidyChecks
bool SuggestMissingIncludes
tidy::ClangTidyOptions ClangTidyOpts
const NamedDecl & findUnqualifiedDecl(ParsedAST &AST, llvm::StringRef Name)
ASTContext & getASTContext()
Note that the returned ast will not contain decls from the preamble that were not deserialized during...
std::shared_ptr< const PreambleData > buildPreamble(PathRef FileName, CompilerInvocation &CI, std::shared_ptr< const PreambleData > OldPreamble, const tooling::CompileCommand &OldCompileCommand, const ParseInputs &Inputs, bool StoreInMemory, PreambleParsedCallback PreambleCallback)
Rebuild the preamble for the new inputs unless the old one can be reused.
std::vector< const char * > ExtraArgs
llvm::IntrusiveRefCntPtr< llvm::vfs::FileSystem > buildTestFS(llvm::StringMap< std::string > const &Files, llvm::StringMap< time_t > const &Timestamps)
const SymbolIndex * ExternalIndex
std::string testPath(PathRef File)
llvm::Optional< std::string > ClangTidyWarningsAsErrors
llvm::Optional< ParsedAST > buildAST(PathRef FileName, std::unique_ptr< CompilerInvocation > Invocation, const ParseInputs &Inputs, std::shared_ptr< const PreambleData > Preamble)
Build an AST from provided user inputs.
std::unique_ptr< CompilerInvocation > buildCompilerInvocation(const ParseInputs &Inputs)
Builds compiler invocation that could be used to build AST or preamble.
static constexpr llvm::StringLiteral Name
llvm::Optional< std::string > WarningsAsErrors
WarningsAsErrors filter.
Stores and provides access to parsed AST.
SymbolSlab headerSymbols() const
The class presents a C++ symbol, e.g.
const PreambleData * Preamble
===– Representation.cpp - ClangDoc Representation --------—*- C++ -*-===//
const Symbol & findSymbol(const SymbolSlab &Slab, llvm::StringRef QName)
std::unique_ptr< SymbolIndex > index() const
llvm::Optional< llvm::Expected< tooling::AtomicChanges > > Result
std::string HeaderFilename
llvm::StringMap< std::string > Files
llvm::StringMap< std::string > AdditionalFiles
SlabTuple indexHeaderSymbols(ASTContext &AST, std::shared_ptr< Preprocessor > PP, const CanonicalIncludes &Includes)
Idex declarations from AST and macros from PP that are declared in included headers.
const NamedDecl & findDecl(ParsedAST &AST, llvm::StringRef QName)