From: Argyrios Kyrtzidis Date: Tue, 2 Oct 2012 16:10:46 +0000 (+0000) Subject: Add info in the preprocessing record whether an inclusion directive X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=8dd927cf03e85b942f323eebb42e06c839887ebb;p=clang Add info in the preprocessing record whether an inclusion directive resulted in an automatic module import. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@165022 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/clang/Lex/PreprocessingRecord.h b/include/clang/Lex/PreprocessingRecord.h index c76a148af3..1a0734b543 100644 --- a/include/clang/Lex/PreprocessingRecord.h +++ b/include/clang/Lex/PreprocessingRecord.h @@ -227,13 +227,18 @@ namespace clang { /// This is a value of type InclusionKind. unsigned Kind : 2; + /// \brief Whether the inclusion directive was automatically turned into + /// a module import. + unsigned ImportedModule : 1; + /// \brief The file that was included. const FileEntry *File; public: InclusionDirective(PreprocessingRecord &PPRec, InclusionKind Kind, StringRef FileName, - bool InQuotes, const FileEntry *File, SourceRange Range); + bool InQuotes, bool ImportedModule, + const FileEntry *File, SourceRange Range); /// \brief Determine what kind of inclusion directive this is. InclusionKind getKind() const { return static_cast(Kind); } @@ -244,6 +249,10 @@ namespace clang { /// \brief Determine whether the included file name was written in quotes; /// otherwise, it was written in angle brackets. bool wasInQuotes() const { return InQuotes; } + + /// \brief Determine whether the inclusion directive was automatically + /// turned into a module import. + bool importedModule() const { return ImportedModule; } /// \brief Retrieve the file entry for the actual file that was included /// by this directive. diff --git a/lib/Lex/PreprocessingRecord.cpp b/lib/Lex/PreprocessingRecord.cpp index 4f4ff4b51e..05fbde4944 100644 --- a/lib/Lex/PreprocessingRecord.cpp +++ b/lib/Lex/PreprocessingRecord.cpp @@ -25,10 +25,11 @@ ExternalPreprocessingRecordSource::~ExternalPreprocessingRecordSource() { } InclusionDirective::InclusionDirective(PreprocessingRecord &PPRec, InclusionKind Kind, StringRef FileName, - bool InQuotes, const FileEntry *File, + bool InQuotes, bool ImportedModule, + const FileEntry *File, SourceRange Range) : PreprocessingDirective(InclusionDirectiveKind, Range), - InQuotes(InQuotes), Kind(Kind), File(File) + InQuotes(InQuotes), Kind(Kind), ImportedModule(ImportedModule), File(File) { char *Memory = (char*)PPRec.Allocate(FileName.size() + 1, llvm::alignOf()); @@ -427,7 +428,8 @@ void PreprocessingRecord::InclusionDirective( // a token range. } clang::InclusionDirective *ID - = new (*this) clang::InclusionDirective(*this, Kind, FileName, !IsAngled, + = new (*this) clang::InclusionDirective(*this, Kind, FileName, !IsAngled, + (bool)Imported, File, SourceRange(HashLoc, EndLoc)); addPreprocessedEntity(ID); } diff --git a/lib/Serialization/ASTReader.cpp b/lib/Serialization/ASTReader.cpp index c5153b5672..b5e579566a 100644 --- a/lib/Serialization/ASTReader.cpp +++ b/lib/Serialization/ASTReader.cpp @@ -3471,7 +3471,7 @@ PreprocessedEntity *ASTReader::ReadPreprocessedEntity(unsigned Index) { InclusionDirective *ID = new (PPRec) InclusionDirective(PPRec, Kind, StringRef(BlobStart, Record[0]), - Record[1], + Record[1], Record[3], File, Range); return ID; diff --git a/lib/Serialization/ASTWriter.cpp b/lib/Serialization/ASTWriter.cpp index 4b2a8a7c79..7aa68b7bc6 100644 --- a/lib/Serialization/ASTWriter.cpp +++ b/lib/Serialization/ASTWriter.cpp @@ -1805,6 +1805,7 @@ void ASTWriter::WritePreprocessorDetail(PreprocessingRecord &PPRec) { Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); // filename length Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // in quotes Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 2)); // kind + Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // imported module Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); InclusionAbbrev = Stream.EmitAbbrev(Abbrev); } @@ -1847,6 +1848,7 @@ void ASTWriter::WritePreprocessorDetail(PreprocessingRecord &PPRec) { Record.push_back(ID->getFileName().size()); Record.push_back(ID->wasInQuotes()); Record.push_back(static_cast(ID->getKind())); + Record.push_back(ID->importedModule()); SmallString<64> Buffer; Buffer += ID->getFileName(); // Check that the FileEntry is not null because it was not resolved and diff --git a/tools/libclang/Indexing.cpp b/tools/libclang/Indexing.cpp index 963e002643..f6314b90ec 100644 --- a/tools/libclang/Indexing.cpp +++ b/tools/libclang/Indexing.cpp @@ -475,7 +475,8 @@ static void indexPreprocessingRecord(ASTUnit &Unit, IndexingContext &IdxCtx) { PreprocessedEntity *PPE = *I; if (InclusionDirective *ID = dyn_cast(PPE)) { - IdxCtx.ppIncludedFile(ID->getSourceRange().getBegin(), ID->getFileName(), + if (!ID->importedModule()) + IdxCtx.ppIncludedFile(ID->getSourceRange().getBegin(),ID->getFileName(), ID->getFile(), ID->getKind() == InclusionDirective::Import, !ID->wasInQuotes()); }