]> granicus.if.org Git - clang/commitdiff
Per discussion in http://lists.cs.uiuc.edu/pipermail/cfe-commits/Week-of-Mon-20120917...
authorArgyrios Kyrtzidis <akyrtzi@gmail.com>
Thu, 27 Sep 2012 01:42:07 +0000 (01:42 +0000)
committerArgyrios Kyrtzidis <akyrtzi@gmail.com>
Thu, 27 Sep 2012 01:42:07 +0000 (01:42 +0000)
have PPCallbacks::InclusionDirective pass the character range for the filename quotes or brackets.

rdar://11113134 & http://llvm.org/PR13880

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

include/clang/Lex/PPCallbacks.h
include/clang/Lex/PreprocessingRecord.h
lib/Frontend/DependencyFile.cpp
lib/Frontend/DependencyGraph.cpp
lib/Lex/PPDirectives.cpp
lib/Lex/PreprocessingRecord.cpp
lib/Rewrite/Frontend/InclusionRewriter.cpp
test/FixIt/fixit-include.c
tools/libclang/Indexing.cpp

index 962b4df6c492766c3951d4a6b37c97337b7876b6..ec63ff3d035e6aa6fdcf35a02ffcb6909807e8bc 100644 (file)
@@ -93,6 +93,9 @@ public:
   /// \param IsAngled Whether the file name was enclosed in angle brackets;
   /// otherwise, it was enclosed in quotes.
   ///
+  /// \param FilenameRange The character range of the quotes or angle brackets
+  /// for the written file name.
+  ///
   /// \param File The actual file that may be included by this inclusion 
   /// directive.
   ///
@@ -114,8 +117,8 @@ public:
                                   const Token &IncludeTok,
                                   StringRef FileName,
                                   bool IsAngled,
+                                  CharSourceRange FilenameRange,
                                   const FileEntry *File,
-                                  SourceLocation EndLoc,
                                   StringRef SearchPath,
                                   StringRef RelativePath) {
   }
@@ -266,14 +269,14 @@ public:
                                   const Token &IncludeTok,
                                   StringRef FileName,
                                   bool IsAngled,
+                                  CharSourceRange FilenameRange,
                                   const FileEntry *File,
-                                  SourceLocation EndLoc,
                                   StringRef SearchPath,
                                   StringRef RelativePath) {
-    First->InclusionDirective(HashLoc, IncludeTok, FileName, IsAngled, File,
-                              EndLoc, SearchPath, RelativePath);
-    Second->InclusionDirective(HashLoc, IncludeTok, FileName, IsAngled, File,
-                               EndLoc, SearchPath, RelativePath);
+    First->InclusionDirective(HashLoc, IncludeTok, FileName, IsAngled,
+                              FilenameRange, File, SearchPath, RelativePath);
+    Second->InclusionDirective(HashLoc, IncludeTok, FileName, IsAngled,
+                               FilenameRange, File, SearchPath, RelativePath);
   }
 
   virtual void EndOfMainFile() {
index 4fd43453d6bb0f9a4aa18eb2f5afd0b234991353..ffff04d0bbe3f2aa821811b796c517e067a53294 100644 (file)
@@ -597,8 +597,8 @@ namespace clang {
                                     const Token &IncludeTok,
                                     StringRef FileName,
                                     bool IsAngled,
+                                    CharSourceRange FilenameRange,
                                     const FileEntry *File,
-                                    SourceLocation EndLoc,
                                     StringRef SearchPath,
                                     StringRef RelativePath);
     virtual void If(SourceLocation Loc, SourceRange ConditionRange);
index 21f5daa9ee39eac403efb738d2dfcd3e172b9213..adc96604e7e4b534165b29982637c822d5e433df 100644 (file)
@@ -59,8 +59,8 @@ public:
                                   const Token &IncludeTok,
                                   StringRef FileName,
                                   bool IsAngled,
+                                  CharSourceRange FilenameRange,
                                   const FileEntry *File,
-                                  SourceLocation EndLoc,
                                   StringRef SearchPath,
                                   StringRef RelativePath);
 
@@ -132,8 +132,8 @@ void DependencyFileCallback::InclusionDirective(SourceLocation HashLoc,
                                                 const Token &IncludeTok,
                                                 StringRef FileName,
                                                 bool IsAngled,
+                                                CharSourceRange FilenameRange,
                                                 const FileEntry *File,
-                                                SourceLocation EndLoc,
                                                 StringRef SearchPath,
                                                 StringRef RelativePath) {
   if (!File) {
index eebaf0c8fe4876308d07c5a21b5384272fe7ec4a..7fb4ad72506a563300dbf473951da006a4b44549 100644 (file)
@@ -51,8 +51,8 @@ public:
                                   const Token &IncludeTok,
                                   StringRef FileName,
                                   bool IsAngled,
+                                  CharSourceRange FilenameRange,
                                   const FileEntry *File,
-                                  SourceLocation EndLoc,
                                   StringRef SearchPath,
                                   StringRef RelativePath);
 
@@ -72,8 +72,8 @@ void DependencyGraphCallback::InclusionDirective(SourceLocation HashLoc,
                                                  const Token &IncludeTok,
                                                  StringRef FileName,
                                                  bool IsAngled,
+                                                 CharSourceRange FilenameRange,
                                                  const FileEntry *File,
-                                                 SourceLocation EndLoc,
                                                  StringRef SearchPath,
                                                  StringRef RelativePath) {
   if (!File)
index 70302f10aed665482ea1d13f803330e9c4379432..ccbee631ae2209b58d6994c2b17844e0c615a115 100644 (file)
@@ -1296,9 +1296,6 @@ void Preprocessor::HandleIncludeDirective(SourceLocation HashLoc,
   case tok::string_literal:
     Filename = getSpelling(FilenameTok, FilenameBuffer);
     End = FilenameTok.getLocation();
-    // For an angled include, point the end location at the closing '>'.
-    if (FilenameTok.is(tok::angle_string_literal))
-      End = End.getLocWithOffset(Filename.size()-1);
     CharEnd = End.getLocWithOffset(Filename.size());
     break;
 
@@ -1388,8 +1385,9 @@ void Preprocessor::HandleIncludeDirective(SourceLocation HashLoc,
     }
     
     // Notify the callback object that we've seen an inclusion directive.
-    Callbacks->InclusionDirective(HashLoc, IncludeTok, Filename, isAngled, File,
-                                  End, SearchPath, RelativePath);
+    Callbacks->InclusionDirective(HashLoc, IncludeTok, Filename, isAngled,
+              CharSourceRange::getCharRange(FilenameTok.getLocation(), CharEnd),
+                                  File, SearchPath, RelativePath);
   }
   
   if (File == 0) {
index dfdeba3f9cd961d4f5c26f67c9a5bb6be77f0abf..40250f67862b04a79ab3a750514a798f52e85e3e 100644 (file)
@@ -389,8 +389,8 @@ void PreprocessingRecord::InclusionDirective(
     const clang::Token &IncludeTok,
     StringRef FileName,
     bool IsAngled,
+    CharSourceRange FilenameRange,
     const FileEntry *File,
-    clang::SourceLocation EndLoc,
     StringRef SearchPath,
     StringRef RelativePath) {
   InclusionDirective::InclusionKind Kind = InclusionDirective::Include;
@@ -415,7 +415,16 @@ void PreprocessingRecord::InclusionDirective(
   default:
     llvm_unreachable("Unknown include directive kind");
   }
-  
+
+  SourceLocation EndLoc;
+  if (!IsAngled) {
+    EndLoc = FilenameRange.getBegin();
+  } else {
+    EndLoc = FilenameRange.getEnd();
+    if (FilenameRange.isCharRange())
+      EndLoc = EndLoc.getLocWithOffset(-1); // the InclusionDirective expects
+                                            // a token range.
+  }
   clang::InclusionDirective *ID
     = new (*this) clang::InclusionDirective(*this, Kind, FileName, !IsAngled, 
                                             File, SourceRange(HashLoc, EndLoc));
index 1929d721236c16dd550210e32e58bb8cbaf7fc4b..9c3c43bb514e473a23aad46bf5a6a03149b98efa 100644 (file)
@@ -57,8 +57,8 @@ private:
                                   const Token &IncludeTok,
                                   StringRef FileName,
                                   bool IsAngled,
+                                  CharSourceRange FilenameRange,
                                   const FileEntry *File,
-                                  SourceLocation EndLoc,
                                   StringRef SearchPath,
                                   StringRef RelativePath);
   void WriteLineInfo(const char *Filename, int Line,
@@ -152,8 +152,8 @@ void InclusionRewriter::InclusionDirective(SourceLocation HashLoc,
                                            const Token &/*IncludeTok*/,
                                            StringRef /*FileName*/,
                                            bool /*IsAngled*/,
+                                           CharSourceRange /*FilenameRange*/,
                                            const FileEntry * /*File*/,
-                                           SourceLocation /*EndLoc*/,
                                            StringRef /*SearchPath*/,
                                            StringRef /*RelativePath*/) {
   assert(LastInsertedFileChange == FileChanges.end() && "Another inclusion "
index 51bd9b0dfd50435126a0a182d1ccf82f04672aae..383c51386ab70d0c34830bff43fece132b328d81 100644 (file)
@@ -3,8 +3,10 @@
 // RUN: cp %S/fixit-include.h %T
 // RUN: not %clang_cc1 -fsyntax-only -fixit %t
 // RUN: %clang_cc1 -Wall -pedantic %t
+// RUN: %clang_cc1 -fsyntax-only -fdiagnostics-parseable-fixits %s 2>&1 | FileCheck %s
 
 #include <fixit-include.h> // expected-error {{'fixit-include.h' file not found with <angled> include; use "quotes" instead}}
+// CHECK: fix-it:{{.*}}:{8:10-8:27}
 
 #pragma does_not_exist // expected-warning {{unknown pragma ignored}}
 
index ae5200470e9e23c8429cc6a7c1de94419de20afa..7e65483769b621fa2049e052d2301e4992ea3d8d 100644 (file)
@@ -68,8 +68,8 @@ public:
                                   const Token &IncludeTok,
                                   StringRef FileName,
                                   bool IsAngled,
+                                  CharSourceRange FilenameRange,
                                   const FileEntry *File,
-                                  SourceLocation EndLoc,
                                   StringRef SearchPath,
                                   StringRef RelativePath) {
     bool isImport = (IncludeTok.is(tok::identifier) &&