]> granicus.if.org Git - clang/commitdiff
When indexing a module file, for the ppIncludedFile callback give
authorArgyrios Kyrtzidis <akyrtzi@gmail.com>
Wed, 10 Oct 2012 02:12:47 +0000 (02:12 +0000)
committerArgyrios Kyrtzidis <akyrtzi@gmail.com>
Wed, 10 Oct 2012 02:12:47 +0000 (02:12 +0000)
an invalid location if the location points to the synthetic buffer
for the module input.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@165592 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/Frontend/ASTUnit.h
include/clang/Serialization/ASTReader.h
lib/Frontend/ASTUnit.cpp
lib/Serialization/ASTReader.cpp
tools/libclang/Indexing.cpp

index cadf2810b97e1652e8802799ce1ec0e08b3bf3cc..d1e0edbeab552def9e8c8861defb6323dca08a99 100644 (file)
@@ -626,6 +626,10 @@ public:
   /// \brief Get the PCH file if one was included.
   const FileEntry *getPCHFile();
 
+  /// \brief Returns true if the ASTUnit was constructed from a serialized
+  /// module file.
+  bool isModuleFile();
+
   llvm::MemoryBuffer *getBufferForFile(StringRef Filename,
                                        std::string *ErrorStr = 0);
 
index a5fb396a501bcff66382f5065ac305654cf5d556..c7e3bb8ba987296276273114fc55eb4f08e14b7a 100644 (file)
@@ -105,14 +105,16 @@ public:
   /// \brief Receives the language options.
   ///
   /// \returns true to indicate the options are invalid or false otherwise.
-  virtual bool ReadLanguageOptions(const LangOptions &LangOpts) {
+  virtual bool ReadLanguageOptions(const serialization::ModuleFile &M,
+                                   const LangOptions &LangOpts) {
     return false;
   }
 
   /// \brief Receives the target triple.
   ///
   /// \returns true to indicate the target triple is invalid or false otherwise.
-  virtual bool ReadTargetTriple(StringRef Triple) {
+  virtual bool ReadTargetTriple(const serialization::ModuleFile &M,
+                                StringRef Triple) {
     return false;
   }
 
@@ -138,7 +140,8 @@ public:
   virtual void ReadHeaderFileInfo(const HeaderFileInfo &HFI, unsigned ID) {}
 
   /// \brief Receives __COUNTER__ value.
-  virtual void ReadCounter(unsigned Value) {}
+  virtual void ReadCounter(const serialization::ModuleFile &M,
+                           unsigned Value) {}
 };
 
 /// \brief ASTReaderListener implementation to validate the information of
@@ -153,14 +156,16 @@ public:
   PCHValidator(Preprocessor &PP, ASTReader &Reader)
     : PP(PP), Reader(Reader), NumHeaderInfos(0) {}
 
-  virtual bool ReadLanguageOptions(const LangOptions &LangOpts);
-  virtual bool ReadTargetTriple(StringRef Triple);
+  virtual bool ReadLanguageOptions(const serialization::ModuleFile &M,
+                                   const LangOptions &LangOpts);
+  virtual bool ReadTargetTriple(const serialization::ModuleFile &M,
+                                StringRef Triple);
   virtual bool ReadPredefinesBuffer(const PCHPredefinesBlocks &Buffers,
                                     StringRef OriginalFileName,
                                     std::string &SuggestedPredefines,
                                     FileManager &FileMgr);
   virtual void ReadHeaderFileInfo(const HeaderFileInfo &HFI, unsigned ID);
-  virtual void ReadCounter(unsigned Value);
+  virtual void ReadCounter(const serialization::ModuleFile &M, unsigned Value);
 
 private:
   void Error(const char *Msg);
@@ -834,7 +839,7 @@ private:
   llvm::BitstreamCursor &SLocCursorForID(int ID);
   SourceLocation getImportLocation(ModuleFile *F);
   ASTReadResult ReadSubmoduleBlock(ModuleFile &F);
-  bool ParseLanguageOptions(const RecordData &Record);
+  bool ParseLanguageOptions(const ModuleFile &M, const RecordData &Record);
   
   struct RecordLocation {
     RecordLocation(ModuleFile *M, uint64_t O)
index 136e72a6c6c46b3d85f5699f789f9e2a40f5835a..6a4f0eb6d73842647d27351643a796e5cbd0c8a0 100644 (file)
@@ -512,8 +512,9 @@ public:
       Predefines(Predefines), Counter(Counter), NumHeaderInfos(0),
       InitializedLanguage(false) {}
 
-  virtual bool ReadLanguageOptions(const LangOptions &LangOpts) {
-    if (InitializedLanguage)
+  virtual bool ReadLanguageOptions(const serialization::ModuleFile &M,
+                                   const LangOptions &LangOpts) {
+    if (InitializedLanguage || M.Kind != serialization::MK_MainFile)
       return false;
     
     LangOpt = LangOpts;
@@ -530,9 +531,10 @@ public:
     return false;
   }
 
-  virtual bool ReadTargetTriple(StringRef Triple) {
+  virtual bool ReadTargetTriple(const serialization::ModuleFile &M,
+                                StringRef Triple) {
     // If we've already initialized the target, don't do it again.
-    if (Target)
+    if (Target || M.Kind != serialization::MK_MainFile)
       return false;
     
     // FIXME: This is broken, we should store the TargetOptions in the AST file.
@@ -563,7 +565,7 @@ public:
     HSI.setHeaderFileInfoForUID(HFI, NumHeaderInfos++);
   }
 
-  virtual void ReadCounter(unsigned Value) {
+  virtual void ReadCounter(const serialization::ModuleFile &M, unsigned Value) {
     Counter = Value;
   }
 
@@ -2852,6 +2854,10 @@ const FileEntry *ASTUnit::getPCHFile() {
   return 0;
 }
 
+bool ASTUnit::isModuleFile() {
+  return isMainFileAST() && !ASTFileLangOpts.CurrentModule.empty();
+}
+
 void ASTUnit::PreambleData::countLines() const {
   NumLines = 0;
   if (empty())
index d060e795ded858769024a6eaee9e813e39673f89..4e6673bedd132d504e1cf246c3834867ac181801 100644 (file)
@@ -63,7 +63,8 @@ using namespace clang::serialization::reader;
 ASTReaderListener::~ASTReaderListener() {}
 
 bool
-PCHValidator::ReadLanguageOptions(const LangOptions &LangOpts) {
+PCHValidator::ReadLanguageOptions(const ModuleFile &M,
+                                  const LangOptions &LangOpts) {
   const LangOptions &PPLangOpts = PP.getLangOpts();
   
 #define LANGOPT(Name, Bits, Default, Description)         \
@@ -100,7 +101,7 @@ PCHValidator::ReadLanguageOptions(const LangOptions &LangOpts) {
   return false;
 }
 
-bool PCHValidator::ReadTargetTriple(StringRef Triple) {
+bool PCHValidator::ReadTargetTriple(const ModuleFile &M, StringRef Triple) {
   if (Triple == PP.getTargetInfo().getTriple().str())
     return false;
 
@@ -408,7 +409,7 @@ void PCHValidator::ReadHeaderFileInfo(const HeaderFileInfo &HFI,
   ++NumHeaderInfos;
 }
 
-void PCHValidator::ReadCounter(unsigned Value) {
+void PCHValidator::ReadCounter(const ModuleFile &M, unsigned Value) {
   PP.setCounterValue(Value);
 }
 
@@ -1828,7 +1829,7 @@ ASTReader::ReadASTBlock(ModuleFile &F) {
       RelocatablePCH = Record[4];
       if (Listener) {
         std::string TargetTriple(BlobStart, BlobLen);
-        if (Listener->ReadTargetTriple(TargetTriple))
+        if (Listener->ReadTargetTriple(F, TargetTriple))
           return IgnorePCH;
       }
       break;
@@ -1938,7 +1939,7 @@ ASTReader::ReadASTBlock(ModuleFile &F) {
     }
 
     case LANGUAGE_OPTIONS:
-      if (ParseLanguageOptions(Record) && !DisableValidation)
+      if (ParseLanguageOptions(F, Record) && !DisableValidation)
         return IgnorePCH;
       break;
 
@@ -2083,7 +2084,7 @@ ASTReader::ReadASTBlock(ModuleFile &F) {
 
     case PP_COUNTER_VALUE:
       if (!Record.empty() && Listener)
-        Listener->ReadCounter(Record[0]);
+        Listener->ReadCounter(F, Record[0]);
       break;
       
     case FILE_SORTED_DECLS:
@@ -3430,7 +3431,8 @@ ASTReader::ASTReadResult ASTReader::ReadSubmoduleBlock(ModuleFile &F) {
 /// them to the AST listener if one is set.
 ///
 /// \returns true if the listener deems the file unacceptable, false otherwise.
-bool ASTReader::ParseLanguageOptions(const RecordData &Record) {
+bool ASTReader::ParseLanguageOptions(const ModuleFile &M,
+                                     const RecordData &Record) {
   if (Listener) {
     LangOptions LangOpts;
     unsigned Idx = 0;
@@ -3447,7 +3449,7 @@ bool ASTReader::ParseLanguageOptions(const RecordData &Record) {
     unsigned Length = Record[Idx++];
     LangOpts.CurrentModule.assign(Record.begin() + Idx, 
                                   Record.begin() + Idx + Length);
-    return Listener->ReadLanguageOptions(LangOpts);
+    return Listener->ReadLanguageOptions(M, LangOpts);
   }
 
   return false;
index 6ea87eb95ed51669b6e2e2197bf90d541e64252c..d2b0ab3c8ddb12ea6e65e9f0796b09b7d4482628 100644 (file)
@@ -450,14 +450,21 @@ static void indexPreprocessingRecord(ASTUnit &Unit, IndexingContext &IdxCtx) {
   PreprocessingRecord::iterator I, E;
   llvm::tie(I, E) = Unit.getLocalPreprocessingEntities();
 
+  bool isModuleFile = Unit.isModuleFile();
   for (; I != E; ++I) {
     PreprocessedEntity *PPE = *I;
 
     if (InclusionDirective *ID = dyn_cast<InclusionDirective>(PPE)) {
-      if (!ID->importedModule())
-        IdxCtx.ppIncludedFile(ID->getSourceRange().getBegin(),ID->getFileName(),
+      if (!ID->importedModule()) {
+        SourceLocation Loc = ID->getSourceRange().getBegin();
+        // Modules have synthetic main files as input, give an invalid location
+        // if the location points to such a file.
+        if (isModuleFile && Unit.isInMainFileID(Loc))
+          Loc = SourceLocation();
+        IdxCtx.ppIncludedFile(Loc, ID->getFileName(),
                      ID->getFile(), ID->getKind() == InclusionDirective::Import,
                      !ID->wasInQuotes());
+      }
     }
   }
 }