diff options
| author | 2019-01-27 16:42:12 +0000 | |
|---|---|---|
| committer | 2019-01-27 16:42:12 +0000 | |
| commit | b773203fb58f3ef282fb69c832d8710cab5bc82d (patch) | |
| tree | e75913f147570fbd75169647b144df85b88a038c /gnu/llvm/tools/clang/lib/Lex/PreprocessingRecord.cpp | |
| parent | tweak errno in previous (diff) | |
| download | wireguard-openbsd-b773203fb58f3ef282fb69c832d8710cab5bc82d.tar.xz wireguard-openbsd-b773203fb58f3ef282fb69c832d8710cab5bc82d.zip | |
Import LLVM 7.0.1 release including clang, lld and lldb.
Diffstat (limited to 'gnu/llvm/tools/clang/lib/Lex/PreprocessingRecord.cpp')
| -rw-r--r-- | gnu/llvm/tools/clang/lib/Lex/PreprocessingRecord.cpp | 78 |
1 files changed, 49 insertions, 29 deletions
diff --git a/gnu/llvm/tools/clang/lib/Lex/PreprocessingRecord.cpp b/gnu/llvm/tools/clang/lib/Lex/PreprocessingRecord.cpp index af439dbfa58..b37a8cf1ced 100644 --- a/gnu/llvm/tools/clang/lib/Lex/PreprocessingRecord.cpp +++ b/gnu/llvm/tools/clang/lib/Lex/PreprocessingRecord.cpp @@ -54,7 +54,7 @@ InclusionDirective::InclusionDirective(PreprocessingRecord &PPRec, PreprocessingRecord::PreprocessingRecord(SourceManager &SM) : SourceMgr(SM) {} -/// \brief Returns a pair of [Begin, End) iterators of preprocessed entities +/// Returns a pair of [Begin, End) iterators of preprocessed entities /// that source range \p Range encompasses. llvm::iterator_range<PreprocessingRecord::iterator> PreprocessingRecord::getPreprocessedEntitiesInRange(SourceRange Range) { @@ -67,7 +67,7 @@ PreprocessingRecord::getPreprocessedEntitiesInRange(SourceRange Range) { } std::pair<int, int> Res = getPreprocessedEntitiesInRangeSlow(Range); - + CachedRangeQuery.Range = Range; CachedRangeQuery.Result = Res; @@ -88,7 +88,7 @@ static bool isPreprocessedEntityIfInFileID(PreprocessedEntity *PPE, FileID FID, return SM.isInFileID(SM.getFileLoc(Loc), FID); } -/// \brief Returns true if the preprocessed entity that \arg PPEI iterator +/// Returns true if the preprocessed entity that \arg PPEI iterator /// points to is coming from the file \arg FID. /// /// Can be used to avoid implicit deserializations of preallocated @@ -132,34 +132,34 @@ bool PreprocessingRecord::isEntityInFileID(iterator PPEI, FileID FID) { FID, SourceMgr); } -/// \brief Returns a pair of [Begin, End) iterators of preprocessed entities +/// Returns a pair of [Begin, End) iterators of preprocessed entities /// that source range \arg R encompasses. std::pair<int, int> PreprocessingRecord::getPreprocessedEntitiesInRangeSlow(SourceRange Range) { assert(Range.isValid()); assert(!SourceMgr.isBeforeInTranslationUnit(Range.getEnd(),Range.getBegin())); - + std::pair<unsigned, unsigned> Local = findLocalPreprocessedEntitiesInRange(Range); - + // Check if range spans local entities. if (!ExternalSource || SourceMgr.isLocalSourceLocation(Range.getBegin())) return std::make_pair(Local.first, Local.second); - + std::pair<unsigned, unsigned> Loaded = ExternalSource->findPreprocessedEntitiesInRange(Range); - + // Check if range spans local entities. if (Loaded.first == Loaded.second) return std::make_pair(Local.first, Local.second); - + unsigned TotalLoaded = LoadedPreprocessedEntities.size(); - + // Check if range spans loaded entities. if (Local.first == Local.second) return std::make_pair(int(Loaded.first)-TotalLoaded, int(Loaded.second)-TotalLoaded); - + // Range spands loaded and local entities. return std::make_pair(int(Loaded.first)-TotalLoaded, Local.second); } @@ -324,17 +324,34 @@ void PreprocessingRecord::SetExternalSource( unsigned PreprocessingRecord::allocateLoadedEntities(unsigned NumEntities) { unsigned Result = LoadedPreprocessedEntities.size(); - LoadedPreprocessedEntities.resize(LoadedPreprocessedEntities.size() + LoadedPreprocessedEntities.resize(LoadedPreprocessedEntities.size() + NumEntities); return Result; } +unsigned PreprocessingRecord::allocateSkippedRanges(unsigned NumRanges) { + unsigned Result = SkippedRanges.size(); + SkippedRanges.resize(SkippedRanges.size() + NumRanges); + SkippedRangesAllLoaded = false; + return Result; +} + +void PreprocessingRecord::ensureSkippedRangesLoaded() { + if (SkippedRangesAllLoaded || !ExternalSource) + return; + for (unsigned Index = 0; Index != SkippedRanges.size(); ++Index) { + if (SkippedRanges[Index].isInvalid()) + SkippedRanges[Index] = ExternalSource->ReadSkippedRange(Index); + } + SkippedRangesAllLoaded = true; +} + void PreprocessingRecord::RegisterMacroDefinition(MacroInfo *Macro, MacroDefinitionRecord *Def) { MacroDefinitions[Macro] = Def; } -/// \brief Retrieve the preprocessed entity at the given ID. +/// Retrieve the preprocessed entity at the given ID. PreprocessedEntity *PreprocessingRecord::getPreprocessedEntity(PPEntityID PPID){ if (PPID.ID < 0) { unsigned Index = -PPID.ID - 1; @@ -351,10 +368,10 @@ PreprocessedEntity *PreprocessingRecord::getPreprocessedEntity(PPEntityID PPID){ return PreprocessedEntities[Index]; } -/// \brief Retrieve the loaded preprocessed entity at the given index. +/// Retrieve the loaded preprocessed entity at the given index. PreprocessedEntity * PreprocessingRecord::getLoadedPreprocessedEntity(unsigned Index) { - assert(Index < LoadedPreprocessedEntities.size() && + assert(Index < LoadedPreprocessedEntities.size() && "Out-of bounds loaded preprocessed entity"); assert(ExternalSource && "No external source to load from"); PreprocessedEntity *&Entity = LoadedPreprocessedEntities[Index]; @@ -418,6 +435,7 @@ void PreprocessingRecord::Defined(const Token &MacroNameTok, void PreprocessingRecord::SourceRangeSkipped(SourceRange Range, SourceLocation EndifLoc) { + assert(Range.isValid()); SkippedRanges.emplace_back(Range.getBegin(), EndifLoc); } @@ -453,26 +471,27 @@ void PreprocessingRecord::InclusionDirective( const FileEntry *File, StringRef SearchPath, StringRef RelativePath, - const Module *Imported) { + const Module *Imported, + SrcMgr::CharacteristicKind FileType) { InclusionDirective::InclusionKind Kind = InclusionDirective::Include; - + switch (IncludeTok.getIdentifierInfo()->getPPKeywordID()) { - case tok::pp_include: - Kind = InclusionDirective::Include; + case tok::pp_include: + Kind = InclusionDirective::Include; break; - - case tok::pp_import: - Kind = InclusionDirective::Import; + + case tok::pp_import: + Kind = InclusionDirective::Import; break; - - case tok::pp_include_next: - Kind = InclusionDirective::IncludeNext; + + case tok::pp_include_next: + Kind = InclusionDirective::IncludeNext; break; - - case tok::pp___include_macros: + + case tok::pp___include_macros: Kind = InclusionDirective::IncludeMacros; break; - + default: llvm_unreachable("Unknown include directive kind"); } @@ -497,5 +516,6 @@ size_t PreprocessingRecord::getTotalMemory() const { return BumpAlloc.getTotalMemory() + llvm::capacity_in_bytes(MacroDefinitions) + llvm::capacity_in_bytes(PreprocessedEntities) - + llvm::capacity_in_bytes(LoadedPreprocessedEntities); + + llvm::capacity_in_bytes(LoadedPreprocessedEntities) + + llvm::capacity_in_bytes(SkippedRanges); } |
