37 #include "llvm/ADT/ArrayRef.h"
38 #include "llvm/ADT/StringExtras.h"
39 #include "llvm/ADT/StringSet.h"
40 #include "llvm/Support/CrashRecoveryContext.h"
41 #include "llvm/Support/Host.h"
42 #include "llvm/Support/MemoryBuffer.h"
43 #include "llvm/Support/Mutex.h"
44 #include "llvm/Support/MutexGuard.h"
45 #include "llvm/Support/Timer.h"
46 #include "llvm/Support/raw_ostream.h"
51 using namespace clang;
53 using llvm::TimeRecord;
62 explicit SimpleTimer(
bool WantTiming) : WantTiming(WantTiming) {
64 Start = TimeRecord::getCurrentTime();
67 void setOutput(
const Twine &Output) {
69 this->Output = Output.str();
74 TimeRecord Elapsed = TimeRecord::getCurrentTime();
76 llvm::errs() << Output <<
':';
77 Elapsed.print(Elapsed, llvm::errs());
84 std::unique_ptr<T> valueOrNull(llvm::ErrorOr<std::unique_ptr<T>> Val) {
87 return std::move(*Val);
91 bool moveOnNoError(llvm::ErrorOr<T> Val, T &Output) {
94 Output = std::move(*Val);
100 static std::unique_ptr<llvm::MemoryBuffer>
109 llvm::MemoryBuffer *
Buffer =
nullptr;
110 std::unique_ptr<llvm::MemoryBuffer> BufferOwner;
111 auto FileStatus = VFS->
status(FilePath);
113 llvm::sys::fs::UniqueID MainFileID = FileStatus->getUniqueID();
116 for (
const auto &RF : PreprocessorOpts.RemappedFiles) {
117 std::string MPath(RF.first);
118 auto MPathStatus = VFS->
status(MPath);
120 llvm::sys::fs::UniqueID MID = MPathStatus->getUniqueID();
121 if (MainFileID == MID) {
132 for (
const auto &RB : PreprocessorOpts.RemappedFileBuffers) {
133 std::string MPath(RB.first);
134 auto MPathStatus = VFS->
status(MPath);
136 llvm::sys::fs::UniqueID MID = MPathStatus->getUniqueID();
137 if (MainFileID == MID) {
140 Buffer =
const_cast<llvm::MemoryBuffer *
>(RB.second);
147 if (!Buffer && !BufferOwner) {
157 return llvm::MemoryBuffer::getMemBufferCopy(Buffer->getBuffer(),
FilePath);
170 void ASTUnit::clearFileLevelDecls() {
171 llvm::DeleteContainerSeconds(FileDecls);
185 ASTUnit::ASTUnit(
bool _MainFileIsAST)
186 : Reader(nullptr), HadModuleLoaderFatalFailure(
false),
187 OnlyLocalDecls(
false), CaptureDiagnostics(
false),
188 MainFileIsAST(_MainFileIsAST),
189 TUKind(
TU_Complete), WantTiming(getenv(
"LIBCLANG_TIMING")),
190 OwnsRemappedFileBuffers(
true),
191 NumStoredDiagnosticsFromDriver(0),
192 PreambleRebuildCounter(0),
193 NumWarningsInPreamble(0),
194 ShouldCacheCodeCompletionResults(
false),
195 IncludeBriefCommentsInCodeCompletion(
false), UserFilesAreVolatile(
false),
196 CompletionCacheTopLevelHashValue(0),
197 PreambleTopLevelHashValue(0),
198 CurrentTopLevelHashValue(0),
199 UnsafeToFree(
false) {
200 if (getenv(
"LIBCLANG_OBJTRACKING"))
204 ASTUnit::~ASTUnit() {
210 clearFileLevelDecls();
216 if (Invocation && OwnsRemappedFileBuffers) {
222 ClearCachedCompletionResults();
224 if (getenv(
"LIBCLANG_OBJTRACKING"))
229 this->PP = std::move(PP);
236 bool &IsNestedNameSpecifier) {
237 IsNestedNameSpecifier =
false;
239 if (isa<UsingShadowDecl>(ND))
245 if (isa<TypeDecl>(ND) || isa<ObjCInterfaceDecl>(ND) ||
246 isa<ClassTemplateDecl>(ND) || isa<TemplateTemplateParmDecl>(ND)) {
248 if (LangOpts.CPlusPlus || !isa<TagDecl>(ND))
257 if (LangOpts.CPlusPlus)
262 if (LangOpts.CPlusPlus || isa<ObjCInterfaceDecl>(ND))
266 if (isa<ObjCInterfaceDecl>(ND))
270 if (isa<EnumDecl>(ND)) {
274 if (LangOpts.CPlusPlus11)
275 IsNestedNameSpecifier =
true;
276 }
else if (
const RecordDecl *Record = dyn_cast<RecordDecl>(ND)) {
277 if (Record->isUnion())
282 if (LangOpts.CPlusPlus)
283 IsNestedNameSpecifier =
true;
284 }
else if (isa<ClassTemplateDecl>(ND))
285 IsNestedNameSpecifier =
true;
286 }
else if (isa<ValueDecl>(ND) || isa<FunctionTemplateDecl>(ND)) {
292 }
else if (isa<ObjCProtocolDecl>(ND)) {
294 }
else if (isa<ObjCCategoryDecl>(ND)) {
296 }
else if (isa<NamespaceDecl>(ND) || isa<NamespaceAliasDecl>(ND)) {
300 IsNestedNameSpecifier =
true;
306 void ASTUnit::CacheCodeCompletionResults() {
310 SimpleTimer Timer(WantTiming);
311 Timer.setOutput(
"Cache global code completions for " +
getMainFileName());
314 ClearCachedCompletionResults();
319 CachedCompletionAllocator = std::make_shared<GlobalCodeCompletionAllocator>();
321 TheSema->GatherGlobalCodeCompletions(*CachedCompletionAllocator,
325 llvm::DenseMap<CanQualType, unsigned> CompletionTypes;
328 for (Result &R : Results) {
330 case Result::RK_Declaration: {
331 bool IsNestedNameSpecifier =
false;
332 CachedCodeCompletionResult CachedResult;
333 CachedResult.Completion = R.CreateCodeCompletionString(
334 *TheSema, CCContext, *CachedCompletionAllocator, CCTUInfo,
335 IncludeBriefCommentsInCodeCompletion);
337 R.Declaration, Ctx->getLangOpts(), IsNestedNameSpecifier);
338 CachedResult.Priority = R.Priority;
339 CachedResult.Kind = R.CursorKind;
340 CachedResult.Availability = R.Availability;
347 CachedResult.Type = 0;
356 unsigned &TypeValue = CompletionTypes[CanUsageType];
357 if (TypeValue == 0) {
358 TypeValue = CompletionTypes.size();
363 CachedResult.Type = TypeValue;
366 CachedCompletionResults.push_back(CachedResult);
369 if (TheSema->Context.getLangOpts().CPlusPlus && IsNestedNameSpecifier &&
370 !R.StartsNestedNameSpecifier) {
386 if (isa<NamespaceDecl>(R.Declaration) ||
387 isa<NamespaceAliasDecl>(R.Declaration))
390 if (
unsigned RemainingContexts
391 = NNSContexts & ~CachedResult.ShowInContexts) {
395 R.StartsNestedNameSpecifier =
true;
396 CachedResult.Completion = R.CreateCodeCompletionString(
397 *TheSema, CCContext, *CachedCompletionAllocator, CCTUInfo,
398 IncludeBriefCommentsInCodeCompletion);
399 CachedResult.ShowInContexts = RemainingContexts;
402 CachedResult.Type = 0;
403 CachedCompletionResults.push_back(CachedResult);
409 case Result::RK_Keyword:
410 case Result::RK_Pattern:
415 case Result::RK_Macro: {
416 CachedCodeCompletionResult CachedResult;
417 CachedResult.Completion = R.CreateCodeCompletionString(
418 *TheSema, CCContext, *CachedCompletionAllocator, CCTUInfo,
419 IncludeBriefCommentsInCodeCompletion);
420 CachedResult.ShowInContexts
434 CachedResult.Priority = R.Priority;
435 CachedResult.Kind = R.CursorKind;
436 CachedResult.Availability = R.Availability;
438 CachedResult.Type = 0;
439 CachedCompletionResults.push_back(CachedResult);
446 CompletionCacheTopLevelHashValue = CurrentTopLevelHashValue;
449 void ASTUnit::ClearCachedCompletionResults() {
450 CachedCompletionResults.clear();
451 CachedCompletionTypes.clear();
452 CachedCompletionAllocator =
nullptr;
465 std::shared_ptr<TargetOptions> &TargetOpts;
469 bool InitializedLanguage;
474 std::shared_ptr<TargetOptions> &TargetOpts,
476 : PP(PP), Context(Context), HSOpts(HSOpts), PPOpts(PPOpts),
477 LangOpt(LangOpt), TargetOpts(TargetOpts), Target(Target),
478 Counter(Counter), InitializedLanguage(
false) {}
480 bool ReadLanguageOptions(
const LangOptions &LangOpts,
bool Complain,
481 bool AllowCompatibleDifferences)
override {
482 if (InitializedLanguage)
486 InitializedLanguage =
true;
493 StringRef SpecificModuleCachePath,
494 bool Complain)
override {
495 this->HSOpts = HSOpts;
501 std::string &SuggestedPredefines)
override {
502 this->PPOpts = PPOpts;
506 bool ReadTargetOptions(
const TargetOptions &TargetOpts,
bool Complain,
507 bool AllowCompatibleDifferences)
override {
512 this->TargetOpts = std::make_shared<TargetOptions>(TargetOpts);
521 unsigned Value)
override {
527 if (!Target || !InitializedLanguage)
534 Target->adjust(LangOpt);
537 PP.Initialize(*Target);
548 LangOpt.CommentOpts);
560 StoredDiagnosticConsumer(
563 : StoredDiags(StoredDiags), StandaloneDiags(StandaloneDiags),
565 assert((StoredDiags || StandaloneDiags) &&
566 "No output collections were passed to StoredDiagnosticConsumer.");
571 this->LangOpts = &LangOpts;
582 class CaptureDroppedDiagnostics {
584 StoredDiagnosticConsumer Client;
586 std::unique_ptr<DiagnosticConsumer> OwningPreviousClient;
592 : Diags(Diags), Client(StoredDiags, StandaloneDiags), PreviousClient(nullptr)
594 if (RequestCapture || Diags.
getClient() ==
nullptr) {
601 ~CaptureDroppedDiagnostics() {
603 Diags.
setClient(PreviousClient, !!OwningPreviousClient.release());
624 StoredDiags->emplace_back(Level, Info);
625 ResultDiag = &StoredDiags->back();
628 if (StandaloneDiags) {
631 StoredDiag.emplace(Level, Info);
632 ResultDiag = StoredDiag.getPointer();
634 StandaloneDiags->push_back(
646 return &WriterData->Writer;
652 return &WriterData->Writer;
656 std::unique_ptr<llvm::MemoryBuffer>
659 auto Buffer = FileMgr->getBufferForFile(Filename);
661 return std::move(*Buffer);
663 *ErrorStr = Buffer.getError().message();
669 ASTUnit &AST,
bool CaptureDiagnostics) {
670 assert(Diags.get() &&
"no DiagnosticsEngine was provided");
671 if (CaptureDiagnostics)
672 Diags->setClient(
new StoredDiagnosticConsumer(&AST.StoredDiagnostics,
nullptr));
680 bool CaptureDiagnostics,
bool AllowPCHWithCompilerErrors,
681 bool UserFilesAreVolatile) {
682 std::unique_ptr<ASTUnit> AST(
new ASTUnit(
true));
685 llvm::CrashRecoveryContextCleanupRegistrar<ASTUnit>
686 ASTUnitCleanup(AST.get());
688 llvm::CrashRecoveryContextReleaseRefCleanup<DiagnosticsEngine> >
689 DiagCleanup(Diags.get());
691 ConfigureDiags(Diags, *AST, CaptureDiagnostics);
693 AST->LangOpts = std::make_shared<LangOptions>();
694 AST->OnlyLocalDecls = OnlyLocalDecls;
695 AST->CaptureDiagnostics = CaptureDiagnostics;
696 AST->Diagnostics = Diags;
698 AST->FileMgr =
new FileManager(FileSystemOpts, VFS);
699 AST->UserFilesAreVolatile = UserFilesAreVolatile;
701 AST->getFileManager(),
702 UserFilesAreVolatile);
704 AST->HSOpts = std::make_shared<HeaderSearchOptions>();
705 AST->HSOpts->ModuleFormat = PCHContainerRdr.
getFormat();
707 AST->getSourceManager(),
708 AST->getDiagnostics(),
711 AST->PPOpts = std::make_shared<PreprocessorOptions>();
721 AST->PP = std::make_shared<Preprocessor>(
722 AST->PPOpts, AST->getDiagnostics(), *AST->LangOpts,
723 AST->getSourceManager(), *AST->PCMCache, HeaderInfo, AST->ModuleLoader,
729 AST->Ctx =
new ASTContext(*AST->LangOpts, AST->getSourceManager(),
730 PP.getIdentifierTable(), PP.getSelectorTable(),
731 PP.getBuiltinInfo());
733 bool disableValid =
false;
734 if (::getenv(
"LIBCLANG_DISABLE_PCH_VALIDATION"))
736 AST->Reader =
new ASTReader(PP, AST->Ctx.get(), PCHContainerRdr, { },
739 AllowPCHWithCompilerErrors);
741 AST->Reader->
setListener(llvm::make_unique<ASTInfoCollector>(
742 *AST->PP, AST->Ctx.get(), *AST->HSOpts, *AST->PPOpts, *AST->LangOpts,
743 AST->TargetOpts, AST->Target, Counter));
751 AST->Ctx->setExternalSource(AST->Reader);
764 AST->getDiagnostics().Report(diag::err_fe_unable_to_load_pch);
768 AST->OriginalSourceFile = AST->Reader->getOriginalSourceFile();
770 PP.setCounterValue(Counter);
778 AST->TheSema.reset(
new Sema(PP, *AST->Ctx, *AST->Consumer));
779 AST->TheSema->Initialize();
780 AST->Reader->InitializeSema(*AST->TheSema);
784 AST->getDiagnostics().getClient()->BeginSourceFile(PP.getLangOpts(), &PP);
792 void AddDefinedMacroToHash(
const Token &MacroNameTok,
unsigned &Hash) {
798 class MacroDefinitionTrackerPPCallbacks :
public PPCallbacks {
802 explicit MacroDefinitionTrackerPPCallbacks(
unsigned &Hash) : Hash(Hash) { }
804 void MacroDefined(
const Token &MacroNameTok,
806 AddDefinedMacroToHash(MacroNameTok, Hash);
811 void AddTopLevelDeclarationToHash(
Decl *D,
unsigned &Hash) {
822 if (
NamedDecl *ND = dyn_cast<NamedDecl>(D)) {
823 if (
EnumDecl *EnumD = dyn_cast<EnumDecl>(D)) {
826 if (!EnumD->isScoped()) {
827 for (
const auto *EI : EnumD->enumerators()) {
828 if (EI->getIdentifier())
829 Hash = llvm::HashString(EI->getIdentifier()->getName(), Hash);
834 if (ND->getIdentifier())
835 Hash = llvm::HashString(ND->getIdentifier()->getName(), Hash);
837 std::string NameStr =
Name.getAsString();
838 Hash = llvm::HashString(NameStr, Hash);
843 if (
ImportDecl *ImportD = dyn_cast<ImportDecl>(D)) {
844 if (
Module *Mod = ImportD->getImportedModule()) {
845 std::string ModName = Mod->getFullModuleName();
846 Hash = llvm::HashString(ModName, Hash);
852 class TopLevelDeclTrackerConsumer :
public ASTConsumer {
857 TopLevelDeclTrackerConsumer(
ASTUnit &_Unit,
unsigned &Hash)
858 : Unit(_Unit), Hash(Hash) {
862 void handleTopLevelDecl(
Decl *D) {
870 if (isa<ObjCMethodDecl>(D))
873 AddTopLevelDeclarationToHash(D, Hash);
874 Unit.addTopLevelDecl(D);
876 handleFileLevelDecl(D);
879 void handleFileLevelDecl(
Decl *D) {
880 Unit.addFileLevelDecl(D);
882 for (
auto *
I : NSD->decls())
883 handleFileLevelDecl(
I);
888 for (
Decl *TopLevelDecl : D)
889 handleTopLevelDecl(TopLevelDecl);
896 void HandleTopLevelDeclInObjCContainer(
DeclGroupRef D)
override {
897 for (
Decl *TopLevelDecl : D)
898 handleTopLevelDecl(TopLevelDecl);
902 return Unit.getASTMutationListener();
906 return Unit.getDeserializationListener();
915 StringRef InFile)
override {
917 llvm::make_unique<MacroDefinitionTrackerPPCallbacks>(
918 Unit.getCurrentTopLevelHashValue()));
919 return llvm::make_unique<TopLevelDeclTrackerConsumer>(
920 Unit, Unit.getCurrentTopLevelHashValue());
924 TopLevelDeclTrackerAction(
ASTUnit &_Unit) : Unit(_Unit) {}
926 bool hasCodeCompletionSupport()
const override {
return false; }
928 return Unit.getTranslationUnitKind();
934 unsigned getHash()
const {
return Hash; }
936 std::vector<Decl *> takeTopLevelDecls() {
return std::move(TopLevelDecls); }
938 std::vector<serialization::DeclID> takeTopLevelDeclIDs() {
939 return std::move(TopLevelDeclIDs);
942 void AfterPCHEmitted(
ASTWriter &Writer)
override {
943 TopLevelDeclIDs.reserve(TopLevelDecls.size());
944 for (
Decl *D : TopLevelDecls) {
946 if (D->isInvalidDecl())
948 TopLevelDeclIDs.push_back(Writer.
getDeclID(D));
958 if (isa<ObjCMethodDecl>(D))
960 AddTopLevelDeclarationToHash(D, Hash);
961 TopLevelDecls.push_back(D);
965 void HandleMacroDefined(
const Token &MacroNameTok,
967 AddDefinedMacroToHash(MacroNameTok, Hash);
972 std::vector<Decl *> TopLevelDecls;
973 std::vector<serialization::DeclID> TopLevelDeclIDs;
988 std::remove_if(StoredDiags.begin(), StoredDiags.end(),
isNonDriverDiag),
1001 if (SD.getLocation().isValid()) {
1003 SD.setLocation(Loc);
1013 bool ASTUnit::Parse(std::shared_ptr<PCHContainerOperations> PCHContainerOps,
1014 std::unique_ptr<llvm::MemoryBuffer> OverrideMainBuffer,
1020 std::unique_ptr<CompilerInstance> Clang(
1022 if (FileMgr && VFS) {
1023 assert(VFS == FileMgr->getVirtualFileSystem() &&
1024 "VFS passed to Parse and VFS in FileMgr are different");
1026 Clang->setVirtualFileSystem(VFS);
1030 llvm::CrashRecoveryContextCleanupRegistrar<CompilerInstance>
1031 CICleanup(Clang.get());
1033 Clang->setInvocation(std::make_shared<CompilerInvocation>(*Invocation));
1034 OriginalSourceFile = Clang->getFrontendOpts().Inputs[0].getFile();
1042 Clang->getDiagnostics(), Clang->getInvocation().TargetOpts));
1043 if (!Clang->hasTarget())
1050 Clang->getTarget().adjust(Clang->getLangOpts());
1052 assert(Clang->getFrontendOpts().Inputs.size() == 1 &&
1053 "Invocation must have exactly one source file!");
1054 assert(Clang->getFrontendOpts().Inputs[0].getKind().getFormat() ==
1056 "FIXME: AST inputs not yet supported here!");
1057 assert(Clang->getFrontendOpts().Inputs[0].getKind().getLanguage() !=
1059 "IR inputs not support here!");
1062 LangOpts = Clang->getInvocation().LangOpts;
1063 FileSystemOpts = Clang->getFileSystemOpts();
1065 Clang->createFileManager();
1066 FileMgr = &Clang->getFileManager();
1072 UserFilesAreVolatile);
1073 if (!OverrideMainBuffer) {
1075 TopLevelDeclsInPreamble.clear();
1086 if (OverrideMainBuffer) {
1087 assert(Preamble &&
"No preamble was built, but OverrideMainBuffer is not null");
1088 Preamble->AddImplicitPreamble(Clang->getInvocation(), OverrideMainBuffer.get());
1098 SavedMainFileBuffer = std::move(OverrideMainBuffer);
1101 std::unique_ptr<TopLevelDeclTrackerAction> Act(
1102 new TopLevelDeclTrackerAction(*
this));
1105 llvm::CrashRecoveryContextCleanupRegistrar<TopLevelDeclTrackerAction>
1106 ActCleanup(Act.get());
1108 if (!Act->BeginSourceFile(*Clang.get(), Clang->getFrontendOpts().Inputs[0]))
1111 if (SavedMainFileBuffer)
1113 PreambleDiagnostics, StoredDiagnostics);
1115 PreambleSrcLocCache.clear();
1117 if (!Act->Execute())
1120 transferASTDataFromCompilerInstance(*Clang);
1122 Act->EndSourceFile();
1124 FailedParseDiagnostics.clear();
1130 SavedMainFileBuffer =
nullptr;
1134 transferASTDataFromCompilerInstance(*Clang);
1135 FailedParseDiagnostics.swap(StoredDiagnostics);
1136 StoredDiagnostics.clear();
1137 NumStoredDiagnosticsFromDriver = 0;
1141 static std::pair<unsigned, unsigned>
1147 return std::make_pair(Offset, EndOffset);
1206 std::unique_ptr<llvm::MemoryBuffer>
1207 ASTUnit::getMainBufferWithPrecompiledPreamble(
1208 std::shared_ptr<PCHContainerOperations> PCHContainerOps,
1211 unsigned MaxLines) {
1215 std::unique_ptr<llvm::MemoryBuffer> MainFileBuffer =
1216 getBufferForFileHandlingRemapping(PreambleInvocationIn, VFS.get(),
1218 if (!MainFileBuffer)
1223 MainFileBuffer.get(), MaxLines);
1228 if (Preamble->CanReuse(PreambleInvocationIn, MainFileBuffer.get(), Bounds,
1239 PreambleRebuildCounter = 1;
1240 return MainFileBuffer;
1243 PreambleDiagnostics.clear();
1244 TopLevelDeclsInPreamble.clear();
1245 PreambleRebuildCounter = 1;
1252 if (PreambleRebuildCounter > 1) {
1253 --PreambleRebuildCounter;
1257 assert(!Preamble &&
"No Preamble should be stored at that point");
1265 ASTUnitPreambleCallbacks Callbacks;
1268 if (CaptureDiagnostics)
1269 Capture.emplace(
true, *Diagnostics, &NewPreambleDiags,
1270 &NewPreambleDiagsStandalone);
1273 SimpleTimer PreambleTimer(WantTiming);
1274 PreambleTimer.setOutput(
"Precompiling preamble");
1277 PreambleInvocationIn, MainFileBuffer.get(), Bounds, *Diagnostics, VFS,
1278 PCHContainerOps, Callbacks);
1280 Preamble = std::move(*NewPreamble);
1281 PreambleRebuildCounter = 1;
1283 switch (static_cast<BuildPreambleError>(NewPreamble.getError().value())) {
1287 PreambleRebuildCounter = 1;
1297 llvm_unreachable(
"unexpected BuildPreambleError");
1301 assert(Preamble &&
"Preamble wasn't built");
1303 TopLevelDecls.clear();
1304 TopLevelDeclsInPreamble = Callbacks.takeTopLevelDeclIDs();
1305 PreambleTopLevelHashValue = Callbacks.getHash();
1310 StoredDiagnostics = std::move(NewPreambleDiags);
1311 PreambleDiagnostics = std::move(NewPreambleDiagsStandalone);
1316 if (CurrentTopLevelHashValue != PreambleTopLevelHashValue) {
1317 CompletionCacheTopLevelHashValue = 0;
1318 PreambleTopLevelHashValue = CurrentTopLevelHashValue;
1321 return MainFileBuffer;
1324 void ASTUnit::RealizeTopLevelDeclsFromPreamble() {
1325 assert(Preamble &&
"Should only be called when preamble was built");
1327 std::vector<Decl *> Resolved;
1328 Resolved.reserve(TopLevelDeclsInPreamble.size());
1334 Resolved.push_back(D);
1336 TopLevelDeclsInPreamble.clear();
1337 TopLevelDecls.insert(TopLevelDecls.begin(), Resolved.begin(), Resolved.end());
1365 return Input.
getBuffer()->getBufferIdentifier();
1370 FE = SourceMgr->getFileEntryForID(SourceMgr->getMainFileID()))
1371 return FE->getName();
1382 Mod = Reader->getModuleManager().getPrimaryModule();
1386 std::unique_ptr<ASTUnit>
1389 bool CaptureDiagnostics,
bool UserFilesAreVolatile) {
1390 std::unique_ptr<ASTUnit> AST(
new ASTUnit(
false));
1391 ConfigureDiags(Diags, *AST, CaptureDiagnostics);
1396 AST->Diagnostics = Diags;
1397 AST->FileSystemOpts = CI->getFileSystemOpts();
1398 AST->Invocation = std::move(CI);
1399 AST->FileMgr =
new FileManager(AST->FileSystemOpts, VFS);
1400 AST->UserFilesAreVolatile = UserFilesAreVolatile;
1401 AST->SourceMgr =
new SourceManager(AST->getDiagnostics(), *AST->FileMgr,
1402 UserFilesAreVolatile);
1409 std::shared_ptr<CompilerInvocation> CI,
1410 std::shared_ptr<PCHContainerOperations> PCHContainerOps,
1412 ASTUnit *Unit,
bool Persistent, StringRef ResourceFilesPath,
1413 bool OnlyLocalDecls,
bool CaptureDiagnostics,
1414 unsigned PrecompilePreambleAfterNParses,
bool CacheCodeCompletionResults,
1415 bool IncludeBriefCommentsInCodeCompletion,
bool UserFilesAreVolatile,
1416 std::unique_ptr<ASTUnit> *ErrAST) {
1417 assert(CI &&
"A CompilerInvocation is required");
1419 std::unique_ptr<ASTUnit> OwnAST;
1423 OwnAST =
create(CI, Diags, CaptureDiagnostics, UserFilesAreVolatile);
1429 if (!ResourceFilesPath.empty()) {
1433 AST->OnlyLocalDecls = OnlyLocalDecls;
1434 AST->CaptureDiagnostics = CaptureDiagnostics;
1435 if (PrecompilePreambleAfterNParses > 0)
1436 AST->PreambleRebuildCounter = PrecompilePreambleAfterNParses;
1438 AST->ShouldCacheCodeCompletionResults = CacheCodeCompletionResults;
1439 AST->IncludeBriefCommentsInCodeCompletion
1440 = IncludeBriefCommentsInCodeCompletion;
1443 llvm::CrashRecoveryContextCleanupRegistrar<ASTUnit>
1444 ASTUnitCleanup(OwnAST.get());
1446 llvm::CrashRecoveryContextReleaseRefCleanup<DiagnosticsEngine> >
1447 DiagCleanup(Diags.get());
1450 CI->getPreprocessorOpts().RetainRemappedFileBuffers =
true;
1451 CI->getFrontendOpts().DisableFree =
false;
1455 std::unique_ptr<CompilerInstance> Clang(
1459 llvm::CrashRecoveryContextCleanupRegistrar<CompilerInstance>
1460 CICleanup(Clang.get());
1462 Clang->setInvocation(std::move(CI));
1463 AST->OriginalSourceFile = Clang->getFrontendOpts().Inputs[0].getFile();
1471 Clang->getDiagnostics(), Clang->getInvocation().TargetOpts));
1472 if (!Clang->hasTarget())
1479 Clang->getTarget().adjust(Clang->getLangOpts());
1481 assert(Clang->getFrontendOpts().Inputs.size() == 1 &&
1482 "Invocation must have exactly one source file!");
1483 assert(Clang->getFrontendOpts().Inputs[0].getKind().getFormat() ==
1485 "FIXME: AST inputs not yet supported here!");
1486 assert(Clang->getFrontendOpts().Inputs[0].getKind().getLanguage() !=
1488 "IR inputs not support here!");
1491 AST->TheSema.reset();
1494 AST->Reader =
nullptr;
1504 std::unique_ptr<TopLevelDeclTrackerAction> TrackerAct;
1506 TrackerAct.reset(
new TopLevelDeclTrackerAction(*AST));
1507 Act = TrackerAct.get();
1511 llvm::CrashRecoveryContextCleanupRegistrar<TopLevelDeclTrackerAction>
1512 ActCleanup(TrackerAct.get());
1514 if (!Act->
BeginSourceFile(*Clang.get(), Clang->getFrontendOpts().Inputs[0])) {
1515 AST->transferASTDataFromCompilerInstance(*Clang);
1516 if (OwnAST && ErrAST)
1517 ErrAST->swap(OwnAST);
1522 if (Persistent && !TrackerAct) {
1523 Clang->getPreprocessor().addPPCallbacks(
1524 llvm::make_unique<MacroDefinitionTrackerPPCallbacks>(
1526 std::vector<std::unique_ptr<ASTConsumer>> Consumers;
1527 if (Clang->hasASTConsumer())
1528 Consumers.push_back(Clang->takeASTConsumer());
1529 Consumers.push_back(llvm::make_unique<TopLevelDeclTrackerConsumer>(
1531 Clang->setASTConsumer(
1532 llvm::make_unique<MultiplexConsumer>(std::move(Consumers)));
1535 AST->transferASTDataFromCompilerInstance(*Clang);
1536 if (OwnAST && ErrAST)
1537 ErrAST->swap(OwnAST);
1543 AST->transferASTDataFromCompilerInstance(*Clang);
1548 return OwnAST.release();
1553 bool ASTUnit::LoadFromCompilerInvocation(
1554 std::shared_ptr<PCHContainerOperations> PCHContainerOps,
1555 unsigned PrecompilePreambleAfterNParses,
1560 assert(VFS &&
"VFS is null");
1568 std::unique_ptr<llvm::MemoryBuffer> OverrideMainBuffer;
1569 if (PrecompilePreambleAfterNParses > 0) {
1570 PreambleRebuildCounter = PrecompilePreambleAfterNParses;
1571 OverrideMainBuffer =
1572 getMainBufferWithPrecompiledPreamble(PCHContainerOps, *Invocation, VFS);
1577 SimpleTimer ParsingTimer(WantTiming);
1581 llvm::CrashRecoveryContextCleanupRegistrar<llvm::MemoryBuffer>
1582 MemBufferCleanup(OverrideMainBuffer.get());
1584 return Parse(std::move(PCHContainerOps), std::move(OverrideMainBuffer), VFS);
1587 std::unique_ptr<ASTUnit> ASTUnit::LoadFromCompilerInvocation(
1588 std::shared_ptr<CompilerInvocation> CI,
1589 std::shared_ptr<PCHContainerOperations> PCHContainerOps,
1591 bool OnlyLocalDecls,
bool CaptureDiagnostics,
1593 bool CacheCodeCompletionResults,
bool IncludeBriefCommentsInCodeCompletion,
1594 bool UserFilesAreVolatile) {
1596 std::unique_ptr<ASTUnit> AST(
new ASTUnit(
false));
1597 ConfigureDiags(Diags, *AST, CaptureDiagnostics);
1598 AST->Diagnostics = Diags;
1599 AST->OnlyLocalDecls = OnlyLocalDecls;
1600 AST->CaptureDiagnostics = CaptureDiagnostics;
1601 AST->TUKind = TUKind;
1602 AST->ShouldCacheCodeCompletionResults = CacheCodeCompletionResults;
1603 AST->IncludeBriefCommentsInCodeCompletion
1604 = IncludeBriefCommentsInCodeCompletion;
1605 AST->Invocation = std::move(CI);
1607 AST->FileMgr = FileMgr;
1608 AST->UserFilesAreVolatile = UserFilesAreVolatile;
1611 llvm::CrashRecoveryContextCleanupRegistrar<ASTUnit>
1612 ASTUnitCleanup(AST.get());
1614 llvm::CrashRecoveryContextReleaseRefCleanup<DiagnosticsEngine> >
1615 DiagCleanup(Diags.get());
1617 if (AST->LoadFromCompilerInvocation(std::move(PCHContainerOps),
1618 PrecompilePreambleAfterNParses,
1619 AST->FileMgr->getVirtualFileSystem()))
1625 const char **ArgBegin,
const char **ArgEnd,
1626 std::shared_ptr<PCHContainerOperations> PCHContainerOps,
1628 bool OnlyLocalDecls,
bool CaptureDiagnostics,
1631 bool CacheCodeCompletionResults,
bool IncludeBriefCommentsInCodeCompletion,
1632 bool AllowPCHWithCompilerErrors,
bool SkipFunctionBodies,
1633 bool SingleFileParse,
bool UserFilesAreVolatile,
bool ForSerialization,
1636 assert(Diags.get() &&
"no DiagnosticsEngine was provided");
1640 std::shared_ptr<CompilerInvocation> CI;
1644 CaptureDroppedDiagnostics Capture(CaptureDiagnostics, *Diags,
1645 &StoredDiagnostics,
nullptr);
1648 llvm::makeArrayRef(ArgBegin, ArgEnd), Diags, VFS);
1655 CI->getPreprocessorOpts().addRemappedFile(
RemappedFile.first,
1665 CI->getHeaderSearchOpts().ResourceDir = ResourceFilesPath;
1667 CI->getFrontendOpts().SkipFunctionBodies = SkipFunctionBodies;
1670 CI->getHeaderSearchOpts().ModuleFormat = ModuleFormat.getValue();
1673 std::unique_ptr<ASTUnit> AST;
1674 AST.reset(
new ASTUnit(
false));
1675 ConfigureDiags(Diags, *AST, CaptureDiagnostics);
1676 AST->Diagnostics = Diags;
1677 AST->FileSystemOpts = CI->getFileSystemOpts();
1683 AST->FileMgr =
new FileManager(AST->FileSystemOpts, VFS);
1685 AST->OnlyLocalDecls = OnlyLocalDecls;
1686 AST->CaptureDiagnostics = CaptureDiagnostics;
1687 AST->TUKind = TUKind;
1688 AST->ShouldCacheCodeCompletionResults = CacheCodeCompletionResults;
1689 AST->IncludeBriefCommentsInCodeCompletion
1690 = IncludeBriefCommentsInCodeCompletion;
1691 AST->UserFilesAreVolatile = UserFilesAreVolatile;
1692 AST->NumStoredDiagnosticsFromDriver = StoredDiagnostics.size();
1693 AST->StoredDiagnostics.swap(StoredDiagnostics);
1694 AST->Invocation = CI;
1695 if (ForSerialization)
1702 llvm::CrashRecoveryContextCleanupRegistrar<ASTUnit>
1703 ASTUnitCleanup(AST.get());
1705 if (AST->LoadFromCompilerInvocation(std::move(PCHContainerOps),
1706 PrecompilePreambleAfterNParses,
1711 AST->StoredDiagnostics.swap(AST->FailedParseDiagnostics);
1717 return AST.release();
1727 assert(FileMgr &&
"FileMgr is null on Reparse call");
1728 VFS = FileMgr->getVirtualFileSystem();
1731 clearFileLevelDecls();
1733 SimpleTimer ParsingTimer(WantTiming);
1749 std::unique_ptr<llvm::MemoryBuffer> OverrideMainBuffer;
1750 if (Preamble || PreambleRebuildCounter > 0)
1751 OverrideMainBuffer =
1752 getMainBufferWithPrecompiledPreamble(PCHContainerOps, *Invocation, VFS);
1759 if (OverrideMainBuffer)
1764 Parse(std::move(PCHContainerOps), std::move(OverrideMainBuffer), VFS);
1768 if (!Result && ShouldCacheCodeCompletionResults &&
1769 CurrentTopLevelHashValue != CompletionCacheTopLevelHashValue)
1770 CacheCodeCompletionResults();
1780 SavedMainFileBuffer.reset();
1788 TopLevelDecls.clear();
1789 clearFileLevelDecls();
1801 uint64_t NormalContexts;
1809 AST(AST), Next(Next)
1836 unsigned NumResults)
override;
1838 void ProcessOverloadCandidates(
Sema &
S,
unsigned CurrentArg,
1840 unsigned NumCandidates)
override {
1858 unsigned NumResults,
1860 llvm::StringSet<llvm::BumpPtrAllocator> &HiddenNames){
1861 bool OnlyTagNames =
false;
1886 OnlyTagNames =
true;
1908 for (
unsigned I = 0;
I != NumResults; ++
I) {
1909 if (Results[
I].
Kind != Result::RK_Declaration)
1915 bool Hiding =
false;
1924 Hiding = (IDNS & HiddenIDNS);
1932 HiddenNames.insert(Identifier->getName());
1938 void AugmentedCodeCompleteConsumer::ProcessCodeCompleteResults(
Sema &S,
1941 unsigned NumResults) {
1943 bool AddedResult =
false;
1944 uint64_t InContexts =
1946 ? NormalContexts : (1LL << Context.
getKind());
1948 llvm::StringSet<llvm::BumpPtrAllocator> HiddenNames;
1957 if ((
C->ShowInContexts & InContexts) == 0)
1964 AllResults.insert(AllResults.end(), Results, Results + NumResults);
1971 HiddenNames.count(
C->Completion->getTypedText()))
1975 unsigned Priority =
C->Priority;
1982 }
else if (
C->Type) {
1987 if (ExpectedSTC ==
C->TypeClass) {
1989 llvm::StringMap<unsigned> &CachedCompletionTypes
1991 llvm::StringMap<unsigned>::iterator Pos
1992 = CachedCompletionTypes.find(
QualType(Expected).getAsString());
1993 if (Pos != CachedCompletionTypes.end() && Pos->second ==
C->Type)
2008 Builder.AddTypedTextChunk(
C->Completion->getTypedText());
2010 Completion =
Builder.TakeString();
2013 AllResults.push_back(Result(Completion, Priority,
C->Kind,
2029 StringRef File,
unsigned Line,
unsigned Column,
2031 bool IncludeCodePatterns,
bool IncludeBriefComments,
2033 std::shared_ptr<PCHContainerOperations> PCHContainerOps,
2040 SimpleTimer CompletionTimer(WantTiming);
2041 CompletionTimer.setOutput(
"Code completion @ " + File +
":" +
2042 Twine(Line) +
":" + Twine(Column));
2044 auto CCInvocation = std::make_shared<CompilerInvocation>(*Invocation);
2051 CachedCompletionResults.empty();
2053 CodeCompleteOpts.
IncludeGlobals = CachedCompletionResults.empty();
2056 assert(IncludeBriefComments == this->IncludeBriefCommentsInCodeCompletion);
2063 LangOpts = *CCInvocation->getLangOpts();
2066 LangOpts.SpellChecking =
false;
2067 CCInvocation->getDiagnosticOpts().IgnoreWarnings =
true;
2069 std::unique_ptr<CompilerInstance> Clang(
2073 llvm::CrashRecoveryContextCleanupRegistrar<CompilerInstance>
2074 CICleanup(Clang.get());
2076 auto &Inv = *CCInvocation;
2077 Clang->setInvocation(std::move(CCInvocation));
2078 OriginalSourceFile = Clang->getFrontendOpts().Inputs[0].getFile();
2081 Clang->setDiagnostics(&Diag);
2082 CaptureDroppedDiagnostics Capture(
true,
2083 Clang->getDiagnostics(),
2084 &StoredDiagnostics,
nullptr);
2089 Clang->getDiagnostics(), Clang->getInvocation().TargetOpts));
2090 if (!Clang->hasTarget()) {
2091 Clang->setInvocation(
nullptr);
2099 Clang->getTarget().adjust(Clang->getLangOpts());
2101 assert(Clang->getFrontendOpts().Inputs.size() == 1 &&
2102 "Invocation must have exactly one source file!");
2103 assert(Clang->getFrontendOpts().Inputs[0].getKind().getFormat() ==
2105 "FIXME: AST inputs not yet supported here!");
2106 assert(Clang->getFrontendOpts().Inputs[0].getKind().getLanguage() !=
2108 "IR inputs not support here!");
2111 Clang->setFileManager(&FileMgr);
2112 Clang->setSourceManager(&SourceMgr);
2124 AugmentedCodeCompleteConsumer *AugmentedConsumer
2125 =
new AugmentedCodeCompleteConsumer(*
this, Consumer, CodeCompleteOpts);
2126 Clang->setCodeCompletionConsumer(AugmentedConsumer);
2132 std::unique_ptr<llvm::MemoryBuffer> OverrideMainBuffer;
2134 std::string CompleteFilePath(File);
2137 auto CompleteFileStatus = VFS->status(CompleteFilePath);
2138 if (CompleteFileStatus) {
2139 llvm::sys::fs::UniqueID CompleteFileID = CompleteFileStatus->getUniqueID();
2141 std::string MainPath(OriginalSourceFile);
2142 auto MainStatus = VFS->status(MainPath);
2144 llvm::sys::fs::UniqueID MainID = MainStatus->getUniqueID();
2145 if (CompleteFileID == MainID && Line > 1)
2146 OverrideMainBuffer = getMainBufferWithPrecompiledPreamble(
2147 PCHContainerOps, Inv, VFS,
false, Line - 1);
2154 if (OverrideMainBuffer) {
2155 assert(Preamble &&
"No preamble was built, but OverrideMainBuffer is not null");
2156 Preamble->AddImplicitPreamble(Clang->getInvocation(), OverrideMainBuffer.get());
2157 OwnedBuffers.push_back(OverrideMainBuffer.release());
2164 if (!Clang->getLangOpts().Modules)
2167 std::unique_ptr<SyntaxOnlyAction> Act;
2169 if (Act->BeginSourceFile(*Clang.get(), Clang->getFrontendOpts().Inputs[0])) {
2171 Act->EndSourceFile();
2176 if (HadModuleLoaderFatalFailure)
2183 TempPath +=
"-%%%%%%%%";
2185 if (llvm::sys::fs::createUniqueFile(TempPath, fd, TempPath))
2190 llvm::raw_fd_ostream Out(fd,
true);
2194 if (Out.has_error()) {
2199 if (llvm::sys::fs::rename(TempPath, File)) {
2200 llvm::sys::fs::remove(TempPath);
2212 Writer.
WriteAST(S, std::string(),
nullptr,
"", hasErrors);
2215 if (!Buffer.empty())
2216 OS.write(Buffer.data(), Buffer.size());
2226 return serializeUnit(WriterData->Writer, WriterData->Buffer,
2230 llvm::BitstreamWriter Stream(Buffer);
2232 ASTWriter Writer(Stream, Buffer, PCMCache, {});
2238 void ASTUnit::TranslateStoredDiagnostics(
2248 Result.reserve(Diags.size());
2250 for (
const StandaloneDiagnostic &SD : Diags) {
2252 if (SD.Filename.empty())
2258 auto ItFileID = PreambleSrcLocCache.find(SD.Filename);
2259 if (ItFileID == PreambleSrcLocCache.end()) {
2262 PreambleSrcLocCache[SD.Filename] = FileLoc;
2264 FileLoc = ItFileID->getValue();
2273 Ranges.reserve(SD.Ranges.size());
2274 for (
const auto &Range : SD.Ranges) {
2281 FixIts.reserve(SD.FixIts.size());
2282 for (
const StandaloneFixIt &
FixIt : SD.FixIts) {
2292 SD.Message, Loc, Ranges, FixIts));
2318 if (FID.isInvalid())
2325 std::pair<unsigned, Decl *> LocDecl(Offset, D);
2327 if (Decls->empty() || Decls->back().first <=
Offset) {
2328 Decls->push_back(LocDecl);
2332 LocDeclsTy::iterator
I = std::upper_bound(Decls->begin(), Decls->end(),
2333 LocDecl, llvm::less_first());
2335 Decls->insert(I, LocDecl);
2343 if (SourceMgr->isLoadedFileID(File)) {
2344 assert(Ctx->getExternalSource() &&
"No external source!");
2345 return Ctx->getExternalSource()->FindFileRegionDecls(File, Offset, Length,
2349 FileDeclsTy::iterator
I = FileDecls.find(File);
2350 if (I == FileDecls.end())
2354 if (LocDecls.empty())
2357 LocDeclsTy::iterator BeginIt =
2358 std::lower_bound(LocDecls.begin(), LocDecls.end(),
2359 std::make_pair(Offset, (
Decl *)
nullptr),
2360 llvm::less_first());
2361 if (BeginIt != LocDecls.begin())
2367 while (BeginIt != LocDecls.begin() &&
2368 BeginIt->second->isTopLevelDeclInObjCContainer())
2371 LocDeclsTy::iterator EndIt = std::upper_bound(
2372 LocDecls.begin(), LocDecls.end(),
2373 std::make_pair(Offset + Length, (
Decl *)
nullptr), llvm::less_first());
2374 if (EndIt != LocDecls.end())
2377 for (LocDeclsTy::iterator DIt = BeginIt; DIt != EndIt; ++DIt)
2378 Decls.push_back(DIt->second);
2382 unsigned Line,
unsigned Col)
const {
2401 PreambleID = SourceMgr->getPreambleFileID();
2407 if (SourceMgr->isInFileID(Loc, PreambleID, &Offs) && Offs < Preamble->getBounds().Size) {
2409 = SourceMgr->getLocForStartOfFile(SourceMgr->getMainFileID());
2422 PreambleID = SourceMgr->getPreambleFileID();
2428 if (SourceMgr->isInFileID(Loc, SourceMgr->getMainFileID(), &Offs) &&
2429 Offs < Preamble->getBounds().Size) {
2430 SourceLocation FileLoc = SourceMgr->getLocForStartOfFile(PreambleID);
2440 FID = SourceMgr->getPreambleFileID();
2445 return SourceMgr->isInFileID(Loc, FID);
2451 FID = SourceMgr->getMainFileID();
2456 return SourceMgr->isInFileID(Loc, FID);
2462 FID = SourceMgr->getPreambleFileID();
2467 return SourceMgr->getLocForEndOfFile(FID);
2473 FID = SourceMgr->getMainFileID();
2478 return SourceMgr->getLocForStartOfFile(FID);
2481 llvm::iterator_range<PreprocessingRecord::iterator>
2485 Mod = Reader->getModuleManager().getPrimaryModule();
2486 return Reader->getModulePreprocessedEntities(Mod);
2490 return llvm::make_range(PPRec->local_begin(), PPRec->local_end());
2499 Mod = Reader->getModuleManager().getPrimaryModule();
2500 for (
const Decl *D : Reader->getModuleFileLevelDecls(Mod)) {
2501 if (!Fn(context, D))
2510 TL != TLEnd; ++TL) {
2511 if (!Fn(context, *TL))
2546 bool ASTUnit::isModuleFile() {
2554 if (LangOpts.OpenCL)
2556 else if (LangOpts.CUDA)
2558 else if (LangOpts.RenderScript)
2560 else if (LangOpts.CPlusPlus)
2576 ASTUnit::ConcurrencyState::ConcurrencyState() {
2577 Mutex =
new llvm::sys::MutexImpl(
true);
2580 ASTUnit::ConcurrencyState::~ConcurrencyState() {
2581 delete static_cast<llvm::sys::MutexImpl *
>(Mutex);
2584 void ASTUnit::ConcurrencyState::start() {
2585 bool acquired =
static_cast<llvm::sys::MutexImpl *
>(Mutex)->tryacquire();
2586 assert(acquired &&
"Concurrent access to ASTUnit!");
2589 void ASTUnit::ConcurrencyState::finish() {
2590 static_cast<llvm::sys::MutexImpl *
>(Mutex)->release();
2595 ASTUnit::ConcurrencyState::ConcurrencyState() { Mutex =
nullptr; }
2596 ASTUnit::ConcurrencyState::~ConcurrencyState() {}
2597 void ASTUnit::ConcurrencyState::start() {}
2598 void ASTUnit::ConcurrencyState::finish() {}
An unknown context, in which we are recovering from a parsing error and don't know which completions ...
Defines the clang::ASTContext interface.
A size of the preamble and a flag required by PreprocessorOptions::PrecompiledPreambleBytes.
ASTContext & getASTContext() const
StringRef getMainFileName() const
void ResetForParse()
Free data that will be re-generated on the next parse.
llvm::iterator_range< PreprocessingRecord::iterator > getLocalPreprocessingEntities() const
Returns an iterator range for the local preprocessing entities of the local Preprocessor, if this is a parsed source file, or the loaded preprocessing entities of the primary module if this is an AST file.
static DiagnosticBuilder Diag(DiagnosticsEngine *Diags, const LangOptions &Features, FullSourceLoc TokLoc, const char *TokBegin, const char *TokRangeBegin, const char *TokRangeEnd, unsigned DiagID)
Produce a diagnostic highlighting some portion of a literal.
CompilerInvocation & getInvocation()
unsigned getNumWarnings() const
bool isInMainFileID(SourceLocation Loc)
DiagnosticConsumer * getClient()
A (possibly-)qualified type.
virtual Decl * GetExternalDecl(uint32_t ID)
Resolve a declaration ID into a declaration, potentially building a new declaration.
SourceLocation getBegin() const
unsigned IncludeBriefComments
Show brief documentation comments in code completion results.
bool RemappedFilesKeepOriginalName
True if the SourceManager should report the original file name for contents of files that were remapp...
Implements support for file system lookup, file system caching, and directory search management...
ASTConsumer - This is an abstract interface that should be implemented by clients that read ASTs...
std::pair< unsigned, unsigned > InsertFromRange
Code completion for a selector, as in an @selector expression.
void EndSourceFile()
Perform any per-file post processing, deallocate per-file objects, and run statistics and output file...
const LangOptions & getLangOpts() const
unsigned IncludeGlobals
Show top-level decls in code completion results.
unsigned getMacroUsagePriority(StringRef MacroName, const LangOptions &LangOpts, bool PreferredTypeIsPointer=false)
Determine the priority to be given to a macro code completion result with the given name...
Code completion where an Objective-C class message is expected.
const DiagnosticsEngine & getDiagnostics() const
IntrusiveRefCntPtr< FileSystem > getRealFileSystem()
Gets an vfs::FileSystem for the 'real' file system, as seen by the operating system.
Code completion within a type-qualifier list.
Load everything, including Sema.
StringRef getMessage() const
Abstract base class for actions which can be performed by the frontend.
Decl - This represents one declaration (or definition), e.g.
SourceLocation getEndOfPreambleFileID()
ModuleKind Kind
The type of this module.
const unsigned DefaultPreambleRebuildInterval
After failing to build a precompiled preamble (due to errors in the source that occurs in the preambl...
Represents a diagnostic in a form that can be retained until its corresponding source manager is dest...
const SourceManager & getManager() const
std::string getAsString() const
IdentifierInfo * getAsIdentifierInfo() const
getAsIdentifierInfo - Retrieve the IdentifierInfo * stored in this declaration name, or NULL if this declaration name isn't a simple identifier.
const FullSourceLoc & getLocation() const
uint32_t DeclID
An ID number that refers to a declaration in an AST file.
std::string CodeToInsert
The actual code to insert at the insertion location, as a string.
std::unique_ptr< llvm::MemoryBuffer > Buffer
An unspecified code-completion context.
NamespaceDecl - Represent a C++ namespace.
bool hasInvocation() const
std::shared_ptr< LangOptions > LangOpts
Options controlling the language variant.
PreprocessorOptions - This class is used for passing the various options used in preprocessor initial...
static std::unique_ptr< ASTUnit > LoadFromASTFile(const std::string &Filename, const PCHContainerReader &PCHContainerRdr, WhatToLoad ToLoad, IntrusiveRefCntPtr< DiagnosticsEngine > Diags, const FileSystemOptions &FileSystemOpts, bool UseDebugInfo=false, bool OnlyLocalDecls=false, ArrayRef< RemappedFile > RemappedFiles=None, bool CaptureDiagnostics=false, bool AllowPCHWithCompilerErrors=false, bool UserFilesAreVolatile=false)
Create a ASTUnit from an AST file.
std::unique_ptr< DiagnosticConsumer > takeClient()
Return the current diagnostic client along with ownership of that client.
Code completion occurred where an Objective-C message receiver is expected.
Code completion occurred on the right-hand side of a member access expression using the arrow operato...
Code completion occurred after the "enum" keyword, to indicate an enumeration name.
TargetInfo & getTarget() const
void setSourceManager(SourceManager *Value)
setSourceManager - Replace the current source manager.
virtual void EndSourceFile()
Callback to inform the diagnostic client that processing of a source file has ended.
Options for controlling the target.
Manage memory buffers across multiple users.
void addRemappedFile(StringRef From, StringRef To)
Abstract interface, implemented by clients of the front-end, which formats and prints fully processed...
NamedDecl * getUnderlyingDecl()
Looks through UsingDecls and ObjCCompatibleAliasDecls for the underlying named decl.
static void checkAndSanitizeDiags(SmallVectorImpl< StoredDiagnostic > &StoredDiagnostics, SourceManager &SM)
Code completion occurred within the instance variable list of an Objective-C interface, implementation, or category implementation.
This interface provides a way to observe the actions of the preprocessor as it does its thing...
Parse and apply any fixits to the source.
static std::unique_ptr< ASTUnit > create(std::shared_ptr< CompilerInvocation > CI, IntrusiveRefCntPtr< DiagnosticsEngine > Diags, bool CaptureDiagnostics, bool UserFilesAreVolatile)
Create a ASTUnit. Gets ownership of the passed CompilerInvocation.
Types, declared with 'struct foo', typedefs, etc.
std::vector< std::pair< unsigned, unsigned > > Ranges
RecordDecl - Represents a struct/union/class.
The virtual file system interface.
One of these records is kept for each identifier that is lexed.
comments::CommandTraits & getCommentCommandTraits() const
cached_completion_iterator cached_completion_end()
void setClient(DiagnosticConsumer *client, bool ShouldOwnClient=true)
Set the diagnostic client associated with this diagnostic object.
Iteration over the preprocessed entities.
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
Utility class for loading a ASTContext from an AST file.
bool BeginSourceFile(CompilerInstance &CI, const FrontendInputFile &Input)
Prepare the action for processing the input file Input.
A "string" used to describe how code completion can be performed for an entity.
bool isAnyPointerType() const
static std::atomic< unsigned > ActiveASTUnitObjects
Tracks the number of ASTUnit objects that are currently active.
unsigned getIdentifierNamespace() const
bool isTranslationUnit() const
Token - This structure provides full information about a lexed token.
unsigned DetailedRecord
Whether we should maintain a detailed record of all macro definitions and expansions.
std::unique_ptr< llvm::MemoryBuffer > getBufferForFile(StringRef Filename, std::string *ErrorStr=nullptr)
bool BeforePreviousInsertions
std::shared_ptr< Preprocessor > getPreprocessorPtr()
Keeps track of the various options that can be enabled, which controls the dialect of C or C++ that i...
Compiling a module from a module map.
Describes a module or submodule.
const SourceManager & getSourceManager() const
unsigned IncludeCodePatterns
Show code patterns in code completion results.
An allocator used specifically for the purpose of code completion.
DiagnosticsEngine::Level Level
virtual llvm::ErrorOr< Status > status(const Twine &Path)=0
Get the status of the entry at Path, if one exists.
Load the AST, but do not restore Sema state.
static ASTUnit * LoadFromCommandLine(const char **ArgBegin, const char **ArgEnd, std::shared_ptr< PCHContainerOperations > PCHContainerOps, IntrusiveRefCntPtr< DiagnosticsEngine > Diags, StringRef ResourceFilesPath, bool OnlyLocalDecls=false, bool CaptureDiagnostics=false, ArrayRef< RemappedFile > RemappedFiles=None, bool RemappedFilesKeepOriginalName=true, unsigned PrecompilePreambleAfterNParses=0, TranslationUnitKind TUKind=TU_Complete, bool CacheCodeCompletionResults=false, bool IncludeBriefCommentsInCodeCompletion=false, bool AllowPCHWithCompilerErrors=false, bool SkipFunctionBodies=false, bool SingleFileParse=false, bool UserFilesAreVolatile=false, bool ForSerialization=false, llvm::Optional< StringRef > ModuleFormat=llvm::None, std::unique_ptr< ASTUnit > *ErrAST=nullptr, IntrusiveRefCntPtr< vfs::FileSystem > VFS=nullptr)
LoadFromCommandLine - Create an ASTUnit from a vector of command line arguments, which must specify e...
void setPreprocessor(std::shared_ptr< Preprocessor > pp)
Divide by this factor when a code-completion result's type exactly matches the type we expect...
SourceLocation getLocWithOffset(int Offset) const
Return a source location with the specified offset from this SourceLocation.
const LangOptions & getLangOpts() const
A record of the steps taken while preprocessing a source file, including the various preprocessing di...
Namespaces, declared with 'namespace foo {}'.
const FileEntry * getPCHFile()
Get the PCH file if one was included.
IntrusiveRefCntPtr< vfs::FileSystem > getVirtualFileSystem() const
Code completion occurred where a preprocessor directive is expected.
bool serialize(raw_ostream &OS)
Serialize this translation unit with the given output stream.
Concrete class used by the front-end to report problems and issues.
virtual CodeCompletionTUInfo & getCodeCompletionTUInfo()=0
Code completion occurred within an Objective-C implementation or category implementation.
Defines the Diagnostic-related interfaces.
bool RetainRemappedFileBuffers
Whether the compiler instance should retain (i.e., not free) the buffers associated with remapped fil...
SourceLocation getFileLoc(SourceLocation Loc) const
Given Loc, if it is a macro location return the expansion location or the spelling location...
IntrusiveRefCntPtr< ASTReader > getModuleManager() const
void addFileLevelDecl(Decl *D)
Add a new local file-level declaration.
QualType getDeclUsageType(ASTContext &C, const NamedDecl *ND)
Determine the type that this declaration will have if it is used as a type or in an expression...
Code completion occurred where a namespace or namespace alias is expected.
ASTDeserializationListener * getDeserializationListener()
DeclContext * getLexicalDeclContext()
getLexicalDeclContext - The declaration context where this Decl was lexically declared (LexicalDC)...
std::string getAsString() const
getNameAsString - Retrieve the human-readable string for this name.
void setFileManager(FileManager *Value)
Replace the current file manager and virtual file system.
static bool isNonDriverDiag(const StoredDiagnostic &StoredDiag)
void Reset()
Reset the state of the diagnostic object to its initial configuration.
SourceLocation translateFileLineCol(const FileEntry *SourceFile, unsigned Line, unsigned Col) const
Get the source location for the given file:line:col triplet.
This abstract interface provides operations for unwrapping containers for serialized ASTs (precompile...
The AST file itself appears corrupted.
detail::InMemoryDirectory::const_iterator I
Preprocessor & getPreprocessor() const
Return the current preprocessor.
QualType getPreferredType() const
Retrieve the type that this expression would prefer to have, e.g., if the expression is a variable in...
std::vector< std::pair< std::string, llvm::MemoryBuffer * > > RemappedFileBuffers
The set of file-to-buffer remappings, which take existing files on the system (the first part of each...
FrontendOptions & getFrontendOpts()
A set of callbacks to gather useful information while building a preamble.
Code completion where an Objective-C category name is expected.
const LangOptions & getLangOpts() const
const FileEntry * getFile(StringRef Filename, bool OpenFile=false, bool CacheFailure=true)
Lookup, cache, and verify the specified file (real or virtual).
static void checkAndRemoveNonDriverDiags(SmallVectorImpl< StoredDiagnostic > &StoredDiags)
Sema - This implements semantic analysis and AST building for C.
Code completion occurred within a "top-level" completion context, e.g., at namespace or global scope...
StringRef getASTFileName() const
If this ASTUnit came from an AST file, returns the filename for it.
This declaration is a C++ operator declared in a non-class context.
StringRef getFilename(SourceLocation SpellingLoc) const
Return the filename of the file containing a SourceLocation.
const FileManager & getFileManager() const
Code completion occurred where a protocol name is expected.
SourceLocation getMacroArgExpandedLocation(SourceLocation Loc) const
If Loc points inside a function macro argument, the returned location will be the macro location in w...
bool hadModuleLoaderFatalFailure() const
Allows QualTypes to be sorted and hence used in maps and sets.
void findFileRegionDecls(FileID File, unsigned Offset, unsigned Length, SmallVectorImpl< Decl * > &Decls)
Get the decls that are contained in a file in the Offset/Length range.
File is from a prebuilt module path.
StringRef getName() const
Return the actual identifier string.
Code completion occurred where a new name is expected.
Represents a character-granular source range.
std::pair< unsigned, unsigned > RemoveRange
SourceLocation getEnd() const
unsigned & getCurrentTopLevelHashValue()
Retrieve a reference to the current top-level name hash value.
virtual void ProcessCodeCompleteResults(Sema &S, CodeCompletionContext Context, CodeCompletionResult *Results, unsigned NumResults)
Process the finalized code-completion results.
std::vector< StandaloneFixIt > FixIts
Defines the clang::Preprocessor interface.
IntrusiveRefCntPtr< vfs::FileSystem > createVFSFromCompilerInvocation(const CompilerInvocation &CI, DiagnosticsEngine &Diags)
const NamedDecl * Declaration
When Kind == RK_Declaration or RK_Pattern, the declaration we are referring to.
DeclContext * getDeclContext()
An abstract interface that should be implemented by listeners that want to be notified when an AST en...
Information about a module that has been loaded by the ASTReader.
Captures a result of code completion.
Code completion occurred where a new name is expected and a qualified name is permissible.
static unsigned getDeclShowContexts(const NamedDecl *ND, const LangOptions &LangOpts, bool &IsNestedNameSpecifier)
Determine the set of code-completion contexts in which this declaration should be shown...
Code completion in a parenthesized expression, which means that we may also have types here in C and ...
std::string FileName
The file name of the module file.
bool BeforePreviousInsertions
bool isFromASTFile() const
Determine whether this declaration came from an AST file (such as a precompiled header or module) rat...
Code completion occurred in a context where natural language is expected, e.g., a comment or string l...
static TargetInfo * CreateTargetInfo(DiagnosticsEngine &Diags, const std::shared_ptr< TargetOptions > &Opts)
Construct a target for the given options.
bool GeneratePreamble
True indicates that a preamble is being generated.
PreambleBounds ComputePreambleBounds(const LangOptions &LangOpts, llvm::MemoryBuffer *Buffer, unsigned MaxLines)
Runs lexer to compute suggested preamble bounds.
SmallString< 128 > Buffer
DeclarationName getDeclName() const
getDeclName - Get the actual, stored name of the declaration, which may be a special name...
static ASTUnit::StandaloneFixIt makeStandaloneFixIt(const SourceManager &SM, const LangOptions &LangOpts, const FixItHint &InFix)
top_level_iterator top_level_begin()
The result type of a method or function.
The client can't handle any AST loading failures.
The AST file was missing.
CharSourceRange InsertFromRange
Code in the specific range that should be inserted in the insertion location.
std::unique_ptr< Sema > takeSema()
static CharSourceRange getCharRange(SourceRange R)
The context in which code completion occurred, so that the code-completion consumer can process the r...
bool AllowPCHWithCompilerErrors
When true, a PCH with compiler errors will not be rejected.
CharSourceRange RemoveRange
Code that should be replaced to correct the error.
Abstract interface for external sources of AST nodes.
static void CalculateHiddenNames(const CodeCompletionContext &Context, CodeCompletionResult *Results, unsigned NumResults, ASTContext &Ctx, llvm::StringSet< llvm::BumpPtrAllocator > &HiddenNames)
Helper function that computes which global names are hidden by the local code-completion results...
ArrayRef< FixItHint > getFixIts() const
The control block was read successfully.
Code completion occurred within a class, struct, or union.
Encapsulates changes to the "macros namespace" (the location where the macro name became active...
bool Reparse(std::shared_ptr< PCHContainerOperations > PCHContainerOps, ArrayRef< RemappedFile > RemappedFiles=None, IntrusiveRefCntPtr< vfs::FileSystem > VFS=nullptr)
Reparse the source files using the same command-line options that were originally used to produce thi...
OverloadCandidate - A single candidate in an overload set (C++ 13.3).
File is a PCH file treated as the preamble.
ContinuousRangeMap< unsigned, int, 2 > SLocRemap
CompilerInstance - Helper class for managing a single instance of the Clang compiler.
Encodes a location in the source.
std::pair< std::string, llvm::MemoryBuffer * > RemappedFile
A mapping from a file name to the memory buffer that stores the remapped contents of that file...
ExternalASTSource * getExternalSource() const
Retrieve a pointer to the external AST source associated with this AST context, if any...
bool Execute()
Set the source manager's main input file, and run the action.
Members, declared with object declarations within tag definitions.
FileSystemOptions & getFileSystemOpts()
Returns the current file system options.
File is a PCH file treated as such.
ParsedSourceLocation CodeCompletionAt
If given, enable code completion at the provided location.
virtual TranslationUnitKind getTranslationUnitKind()
For AST-based actions, the kind of translation unit we're handling.
ASTWriterData(MemoryBufferCache &PCMCache)
bool isValid() const
Return true if this is a valid SourceLocation object.
llvm::StringMap< unsigned > & getCachedCompletionTypes()
Retrieve the mapping from formatted type names to unique type identifiers.
std::vector< FrontendInputFile > Inputs
The input files and their types.
File is an implicitly-loaded module.
Cached information about one file (either on disk or in the virtual file system). ...
Code completion where the name of an Objective-C class is expected.
void ProcessWarningOptions(DiagnosticsEngine &Diags, const DiagnosticOptions &Opts, bool ReportDiags=true)
ProcessWarningOptions - Initialize the diagnostic client and process the warning options specified on...
Abstract base class to use for AST consumer-based frontend actions.
Code completion occurred within an Objective-C interface, protocol, or category interface.
virtual void ProcessOverloadCandidates(Sema &S, unsigned CurrentArg, OverloadCandidate *Candidates, unsigned NumCandidates)
InputKind getInputKind() const
Determine the input kind this AST unit represents.
Defines the clang::TargetOptions class.
static std::pair< unsigned, unsigned > makeStandaloneRange(CharSourceRange Range, const SourceManager &SM, const LangOptions &LangOpts)
virtual void HandleDiagnostic(DiagnosticsEngine::Level DiagLevel, const Diagnostic &Info)
Handle this diagnostic, reporting it to the user or capturing it to a log as needed.
void setListener(std::unique_ptr< ASTReaderListener > Listener)
Set the AST callbacks listener.
void InitBuiltinTypes(const TargetInfo &Target, const TargetInfo *AuxTarget=nullptr)
Initialize built-in types.
SimplifiedTypeClass getSimplifiedTypeClass(CanQualType T)
Determine the simplified type class of the given canonical type.
llvm::BitstreamWriter Stream
bool isFileContext() const
void setNumWarnings(unsigned NumWarnings)
The AST file was writtten with a different language/target configuration.
bool visitLocalTopLevelDecls(void *context, DeclVisitorFn Fn)
Iterate over local declarations (locally parsed if this is a parsed source file or the loaded declara...
const ASTContext & getASTContext() const
File is a PCH file treated as the actual main file.
bool isInPreambleFileID(SourceLocation Loc)
bool isLocalSourceLocation(SourceLocation Loc) const
Returns true if Loc did not come from a PCH/Module.
static ASTUnit * LoadFromCompilerInvocationAction(std::shared_ptr< CompilerInvocation > CI, std::shared_ptr< PCHContainerOperations > PCHContainerOps, IntrusiveRefCntPtr< DiagnosticsEngine > Diags, FrontendAction *Action=nullptr, ASTUnit *Unit=nullptr, bool Persistent=true, StringRef ResourceFilesPath=StringRef(), bool OnlyLocalDecls=false, bool CaptureDiagnostics=false, unsigned PrecompilePreambleAfterNParses=0, bool CacheCodeCompletionResults=false, bool IncludeBriefCommentsInCodeCompletion=false, bool UserFilesAreVolatile=false, std::unique_ptr< ASTUnit > *ErrAST=nullptr)
Create an ASTUnit from a source file, via a CompilerInvocation object, by invoking the optionally pro...
Describes a module import declaration, which makes the contents of the named module visible in the cu...
virtual StringRef getFormat() const =0
Equivalent to the format passed to -fmodule-format=.
Abstract interface for a consumer of code-completion information.
An opaque identifier used by SourceManager which refers to a source file (MemoryBuffer) along with it...
Options controlling the behavior of code completion.
static ASTUnit::StandaloneDiagnostic makeStandaloneDiagnostic(const LangOptions &LangOpts, const StoredDiagnostic &InDiag)
Code completion occurred where an macro is being defined.
DeclContext - This is used only as base class of specific decl types that can act as declaration cont...
bool hasSourceManager() const
PreprocessorOptions & getPreprocessorOpts()
static CharSourceRange makeFileCharRange(CharSourceRange Range, const SourceManager &SM, const LangOptions &LangOpts)
Accepts a range and returns a character range with file locations.
Code completion occurred after the "struct" or "class" keyword, to indicate a struct or class name...
Reads an AST files chain containing the contents of a translation unit.
const HeaderSearchOptions & getHeaderSearchOpts() const
File is an explicitly-loaded module.
IntrusiveRefCntPtr< ASTReader > getASTReader() const
Code completion occurred after the "union" keyword, to indicate a union name.
Code completion occurred where a macro name is expected (without any arguments, in the case of a func...
std::vector< Decl * >::iterator top_level_iterator
A builder class used to construct new code-completion strings.
Code completion where an Objective-C instance message is expected.
DeclarationName - The name of a declaration.
ASTMutationListener * getASTMutationListener()
bool SingleFileParseMode
When enabled, preprocessor is in a mode for parsing a single file only.
Helper class for holding the data necessary to invoke the compiler.
DiagnosticOptions & getDiagnosticOpts() const
Defines the virtual file system interface vfs::FileSystem.
EnumDecl - Represents an enum.
top_level_iterator top_level_end()
Divide by this factor when a code-completion result's type is similar to the type we expect (e...
CanQualType getCanonicalType(QualType T) const
Return the canonical (structural) type corresponding to the specified potentially non-canonical type ...
A map from continuous integer ranges to some value, with a very specialized interface.
Tags, declared with 'struct foo;' and referenced with 'struct foo'.
FrontendOptions - Options for controlling the behavior of the frontend.
FileID translateFile(const FileEntry *SourceFile) const
Get the FileID for the given file.
Code completion occurred where a statement (or declaration) is expected in a function, method, or block.
bool isMainFileAST() const
SourceLocation getStartOfMainFileID()
Code completion occurred on the right-hand side of an Objective-C property access expression...
SmallVector< Context, 8 > Contexts
SourceLocation mapLocationFromPreamble(SourceLocation Loc)
If Loc is a loaded location from the preamble, returns the corresponding local location of the main f...
bool Save(StringRef File)
Save this translation unit to a file with the given name.
cached_completion_iterator cached_completion_begin()
Abstract interface for callback invocations by the ASTReader.
SourceManager & getSourceManager() const
enum Kind getKind() const
Retrieve the kind of code-completion context.
CodeCompleteOptions CodeCompleteOpts
unsigned Size
Size of the preamble in bytes.
llvm::ErrorOr< std::unique_ptr< llvm::MemoryBuffer > > getBufferForFile(const Twine &Name, int64_t FileSize=-1, bool RequiresNullTerminator=true, bool IsVolatile=false)
This is a convenience method that opens a file, gets its content and then closes the file...
bool hasASTContext() const
ArrayRef< CharSourceRange > getRanges() const
Keeps track of options that affect how file operations are performed.
unsigned DisableFree
Disable memory freeing on exit.
static bool serializeUnit(ASTWriter &Writer, SmallVectorImpl< char > &Buffer, Sema &S, bool hasErrors, raw_ostream &OS)
Code completion occurred within a preprocessor expression.
Code completion occurred where an expression is expected.
QualType getUnqualifiedType() const
Retrieve the unqualified variant of the given type, removing as little sugar as possible.
BoundNodesTreeBuilder *const Builder
Priority for a nested-name-specifier.
virtual CodeCompletionAllocator & getAllocator()=0
Retrieve the allocator that will be used to allocate code completion strings.
SourceLocation getLocation(const FileEntry *File, unsigned Line, unsigned Col) const
Get the source location for the given file:line:col triplet.
std::unique_ptr< CompilerInvocation > createInvocationFromCommandLine(ArrayRef< const char * > Args, IntrusiveRefCntPtr< DiagnosticsEngine > Diags=IntrusiveRefCntPtr< DiagnosticsEngine >(), IntrusiveRefCntPtr< vfs::FileSystem > VFS=nullptr)
createInvocationFromCommandLine - Construct a compiler invocation object for a command line argument ...
An unspecified code-completion context where we should also add macro completions.
Level
The level of the diagnostic, after it has been through mapping.
ASTFileSignature WriteAST(Sema &SemaRef, const std::string &OutputFile, Module *WritingModule, StringRef isysroot, bool hasErrors=false)
Write a precompiled header for the given semantic analysis.
std::vector< CachedCodeCompletionResult >::iterator cached_completion_iterator
TranslationUnitKind
Describes the kind of translation unit being processed.
DeclContext * getLookupParent()
Find the parent context of this context that will be used for unqualified name lookup.
Writes an AST file containing the contents of a translation unit.
serialization::DeclID getDeclID(const Decl *D)
Determine the declaration ID of an already-emitted declaration.
DiagnosticsEngine::Level getLevel() const
A little helper class (which is basically a smart pointer that forwards info from DiagnosticsEngine) ...
std::pair< unsigned, bool > PrecompiledPreambleBytes
If non-zero, the implicit PCH include is actually a precompiled preamble that covers this number of b...
Defines the clang::TargetInfo interface.
The AST file is out-of-date relative to its input files, and needs to be regenerated.
A SourceLocation and its associated SourceManager.
The translation unit is a complete translation unit.
SourceLocation mapLocationToPreamble(SourceLocation Loc)
If Loc is a local location of the main file but inside the preamble chunk, returns the corresponding ...
bool hasPreprocessor() const
bool isCompilingModule() const
Are we compiling a module interface (.cppm or module map)?
std::unique_ptr< ASTConsumer > takeASTConsumer()
takeASTConsumer - Remove the current AST consumer and give ownership to the caller.
The AST file was written by a different version of Clang.
Code completion occurred on the right-hand side of a member access expression using the dot operator...
void clearRemappedFiles()
SimplifiedTypeClass
A simplified classification of types used when determining "similar" types for code completion...
static llvm::ErrorOr< PrecompiledPreamble > Build(const CompilerInvocation &Invocation, const llvm::MemoryBuffer *MainFileBuffer, PreambleBounds Bounds, DiagnosticsEngine &Diagnostics, IntrusiveRefCntPtr< vfs::FileSystem > VFS, std::shared_ptr< PCHContainerOperations > PCHContainerOps, PreambleCallbacks &Callbacks)
Try to build PrecompiledPreamble for Invocation.
Code completion occurred where a type name is expected.
SourceLocation getLocForStartOfFile(FileID FID) const
Return the source location corresponding to the first byte of the specified file. ...
Annotates a diagnostic with some code that should be inserted, removed, or replaced to fix the proble...
unsigned getFileOffset(SourceLocation SpellingLoc) const
Returns the offset from the start of the file that the specified SourceLocation represents.
unsigned IncludeMacros
Show macros in code completion results.
SourceLocation getLocation() const
NamedDecl - This represents a decl with a name.
void CodeComplete(StringRef File, unsigned Line, unsigned Column, ArrayRef< RemappedFile > RemappedFiles, bool IncludeMacros, bool IncludeCodePatterns, bool IncludeBriefComments, CodeCompleteConsumer &Consumer, std::shared_ptr< PCHContainerOperations > PCHContainerOps, DiagnosticsEngine &Diag, LangOptions &LangOpts, SourceManager &SourceMgr, FileManager &FileMgr, SmallVectorImpl< StoredDiagnostic > &StoredDiagnostics, SmallVectorImpl< const llvm::MemoryBuffer * > &OwnedBuffers)
Perform code completion at the given file, line, and column within this translation unit...
LangOptions * getLangOpts()
std::pair< FileID, unsigned > getDecomposedLoc(SourceLocation Loc) const
Decompose the specified location into a raw FileID + Offset pair.
Priority for a code pattern.
bool isNull() const
Return true if this QualType doesn't point to a type yet.
bool hasUncompilableErrorOccurred() const
Errors that actually prevent compilation, not those that are upgraded from a warning by -Werror...
void addPPCallbacks(std::unique_ptr< PPCallbacks > C)
This class handles loading and caching of source files into memory.
Engages in a tight little dance with the lexer to efficiently preprocess tokens.
IdentifierInfo * getIdentifierInfo() const