From 4fcd2885deb078fa46b39666a2fe8c8d3cdfaa68 Mon Sep 17 00:00:00 2001 From: Argyrios Kyrtzidis Date: Thu, 27 Sep 2012 01:42:07 +0000 Subject: [PATCH] Per discussion in http://lists.cs.uiuc.edu/pipermail/cfe-commits/Week-of-Mon-20120917/064551.html have PPCallbacks::InclusionDirective pass the character range for the filename quotes or brackets. rdar://11113134 & http://llvm.org/PR13880 llvm-svn: 164743 --- clang/include/clang/Lex/PPCallbacks.h | 15 +++++++++------ clang/include/clang/Lex/PreprocessingRecord.h | 2 +- clang/lib/Frontend/DependencyFile.cpp | 4 ++-- clang/lib/Frontend/DependencyGraph.cpp | 4 ++-- clang/lib/Lex/PPDirectives.cpp | 8 +++----- clang/lib/Lex/PreprocessingRecord.cpp | 13 +++++++++++-- clang/lib/Rewrite/Frontend/InclusionRewriter.cpp | 4 ++-- clang/test/FixIt/fixit-include.c | 2 ++ clang/tools/libclang/Indexing.cpp | 2 +- 9 files changed, 33 insertions(+), 21 deletions(-) diff --git a/clang/include/clang/Lex/PPCallbacks.h b/clang/include/clang/Lex/PPCallbacks.h index 962b4df..ec63ff3 100644 --- a/clang/include/clang/Lex/PPCallbacks.h +++ b/clang/include/clang/Lex/PPCallbacks.h @@ -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() { diff --git a/clang/include/clang/Lex/PreprocessingRecord.h b/clang/include/clang/Lex/PreprocessingRecord.h index 4fd4345..ffff04d 100644 --- a/clang/include/clang/Lex/PreprocessingRecord.h +++ b/clang/include/clang/Lex/PreprocessingRecord.h @@ -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); diff --git a/clang/lib/Frontend/DependencyFile.cpp b/clang/lib/Frontend/DependencyFile.cpp index 21f5daa..adc9660 100644 --- a/clang/lib/Frontend/DependencyFile.cpp +++ b/clang/lib/Frontend/DependencyFile.cpp @@ -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) { diff --git a/clang/lib/Frontend/DependencyGraph.cpp b/clang/lib/Frontend/DependencyGraph.cpp index eebaf0c..7fb4ad7 100644 --- a/clang/lib/Frontend/DependencyGraph.cpp +++ b/clang/lib/Frontend/DependencyGraph.cpp @@ -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) diff --git a/clang/lib/Lex/PPDirectives.cpp b/clang/lib/Lex/PPDirectives.cpp index 70302f1..ccbee63 100644 --- a/clang/lib/Lex/PPDirectives.cpp +++ b/clang/lib/Lex/PPDirectives.cpp @@ -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) { diff --git a/clang/lib/Lex/PreprocessingRecord.cpp b/clang/lib/Lex/PreprocessingRecord.cpp index dfdeba3..40250f6 100644 --- a/clang/lib/Lex/PreprocessingRecord.cpp +++ b/clang/lib/Lex/PreprocessingRecord.cpp @@ -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)); diff --git a/clang/lib/Rewrite/Frontend/InclusionRewriter.cpp b/clang/lib/Rewrite/Frontend/InclusionRewriter.cpp index 1929d72..9c3c43b 100644 --- a/clang/lib/Rewrite/Frontend/InclusionRewriter.cpp +++ b/clang/lib/Rewrite/Frontend/InclusionRewriter.cpp @@ -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 " diff --git a/clang/test/FixIt/fixit-include.c b/clang/test/FixIt/fixit-include.c index 51bd9b0..383c513 100644 --- a/clang/test/FixIt/fixit-include.c +++ b/clang/test/FixIt/fixit-include.c @@ -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 // expected-error {{'fixit-include.h' file not found with include; use "quotes" instead}} +// CHECK: fix-it:{{.*}}:{8:10-8:27} #pragma does_not_exist // expected-warning {{unknown pragma ignored}} diff --git a/clang/tools/libclang/Indexing.cpp b/clang/tools/libclang/Indexing.cpp index ae52004..7e65483 100644 --- a/clang/tools/libclang/Indexing.cpp +++ b/clang/tools/libclang/Indexing.cpp @@ -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) && -- 2.7.4