diff options
Diffstat (limited to 'clang/lib/Tooling/Core')
-rw-r--r-- | clang/lib/Tooling/Core/Diagnostic.cpp | 18 | ||||
-rw-r--r-- | clang/lib/Tooling/Core/Lookup.cpp | 11 | ||||
-rw-r--r-- | clang/lib/Tooling/Core/Replacement.cpp | 12 |
3 files changed, 28 insertions, 13 deletions
diff --git a/clang/lib/Tooling/Core/Diagnostic.cpp b/clang/lib/Tooling/Core/Diagnostic.cpp index 235bd7fc1433..b0c4ea8c5608 100644 --- a/clang/lib/Tooling/Core/Diagnostic.cpp +++ b/clang/lib/Tooling/Core/Diagnostic.cpp @@ -11,6 +11,7 @@ //===----------------------------------------------------------------------===// #include "clang/Tooling/Core/Diagnostic.h" +#include "clang/Basic/SourceLocation.h" #include "clang/Basic/SourceManager.h" #include "llvm/ADT/STLExtras.h" @@ -25,7 +26,7 @@ DiagnosticMessage::DiagnosticMessage(llvm::StringRef Message, SourceLocation Loc) : Message(Message), FileOffset(0) { assert(Loc.isValid() && Loc.isFileID()); - FilePath = Sources.getFilename(Loc); + FilePath = std::string(Sources.getFilename(Loc)); // Don't store offset in the scratch space. It doesn't tell anything to the // user. Moreover, it depends on the history of macro expansions and thus @@ -34,6 +35,16 @@ DiagnosticMessage::DiagnosticMessage(llvm::StringRef Message, FileOffset = Sources.getFileOffset(Loc); } +FileByteRange::FileByteRange( + const SourceManager &Sources, CharSourceRange Range) + : FileOffset(0), Length(0) { + FilePath = std::string(Sources.getFilename(Range.getBegin())); + if (!FilePath.empty()) { + FileOffset = Sources.getFileOffset(Range.getBegin()); + Length = Sources.getFileOffset(Range.getEnd()) - FileOffset; + } +} + Diagnostic::Diagnostic(llvm::StringRef DiagnosticName, Diagnostic::Level DiagLevel, StringRef BuildDirectory) : DiagnosticName(DiagnosticName), DiagLevel(DiagLevel), @@ -42,9 +53,10 @@ Diagnostic::Diagnostic(llvm::StringRef DiagnosticName, Diagnostic::Diagnostic(llvm::StringRef DiagnosticName, const DiagnosticMessage &Message, const SmallVector<DiagnosticMessage, 1> &Notes, - Level DiagLevel, llvm::StringRef BuildDirectory) + Level DiagLevel, llvm::StringRef BuildDirectory, + const SmallVector<FileByteRange, 1> &Ranges) : DiagnosticName(DiagnosticName), Message(Message), Notes(Notes), - DiagLevel(DiagLevel), BuildDirectory(BuildDirectory) {} + DiagLevel(DiagLevel), BuildDirectory(BuildDirectory), Ranges(Ranges) {} const llvm::StringMap<Replacements> *selectFirstFix(const Diagnostic& D) { if (!D.Message.Fix.empty()) diff --git a/clang/lib/Tooling/Core/Lookup.cpp b/clang/lib/Tooling/Core/Lookup.cpp index 735a5df5ed21..712724a268fb 100644 --- a/clang/lib/Tooling/Core/Lookup.cpp +++ b/clang/lib/Tooling/Core/Lookup.cpp @@ -11,10 +11,12 @@ //===----------------------------------------------------------------------===// #include "clang/Tooling/Core/Lookup.h" +#include "clang/AST/ASTContext.h" #include "clang/AST/Decl.h" #include "clang/AST/DeclCXX.h" #include "clang/AST/DeclarationName.h" #include "clang/Basic/SourceLocation.h" +#include "clang/Basic/SourceManager.h" #include "llvm/ADT/SmallVector.h" using namespace clang; using namespace clang::tooling; @@ -129,7 +131,7 @@ static std::string disambiguateSpellingInScope(StringRef Spelling, assert(QName.startswith("::")); assert(QName.endswith(Spelling)); if (Spelling.startswith("::")) - return Spelling; + return std::string(Spelling); auto UnspelledSpecifier = QName.drop_back(Spelling.size()); llvm::SmallVector<llvm::StringRef, 2> UnspelledScopes; @@ -168,7 +170,7 @@ static std::string disambiguateSpellingInScope(StringRef Spelling, }; // Add more qualifiers until the spelling is not ambiguous. - std::string Disambiguated = Spelling; + std::string Disambiguated = std::string(Spelling); while (IsAmbiguousSpelling(Disambiguated)) { if (UnspelledScopes.empty()) { Disambiguated = "::" + Disambiguated; @@ -206,8 +208,9 @@ std::string tooling::replaceNestedName(const NestedNameSpecifier *Use, !usingFromDifferentCanonicalNamespace(FromDecl->getDeclContext(), UseContext)) { auto Pos = ReplacementString.rfind("::"); - return Pos != StringRef::npos ? ReplacementString.substr(Pos + 2) - : ReplacementString; + return std::string(Pos != StringRef::npos + ? ReplacementString.substr(Pos + 2) + : ReplacementString); } // We did not match this because of a using statement, so we will need to // figure out how good a namespace match we have with our destination type. diff --git a/clang/lib/Tooling/Core/Replacement.cpp b/clang/lib/Tooling/Core/Replacement.cpp index 9ed03655bf2c..ab8e20539559 100644 --- a/clang/lib/Tooling/Core/Replacement.cpp +++ b/clang/lib/Tooling/Core/Replacement.cpp @@ -46,8 +46,8 @@ Replacement::Replacement() : FilePath(InvalidLocation) {} Replacement::Replacement(StringRef FilePath, unsigned Offset, unsigned Length, StringRef ReplacementText) - : FilePath(FilePath), ReplacementRange(Offset, Length), - ReplacementText(ReplacementText) {} + : FilePath(std::string(FilePath)), ReplacementRange(Offset, Length), + ReplacementText(std::string(ReplacementText)) {} Replacement::Replacement(const SourceManager &Sources, SourceLocation Start, unsigned Length, StringRef ReplacementText) { @@ -123,9 +123,9 @@ void Replacement::setFromSourceLocation(const SourceManager &Sources, const std::pair<FileID, unsigned> DecomposedLocation = Sources.getDecomposedLoc(Start); const FileEntry *Entry = Sources.getFileEntryForID(DecomposedLocation.first); - this->FilePath = Entry ? Entry->getName() : InvalidLocation; + this->FilePath = std::string(Entry ? Entry->getName() : InvalidLocation); this->ReplacementRange = Range(DecomposedLocation.second, Length); - this->ReplacementText = ReplacementText; + this->ReplacementText = std::string(ReplacementText); } // FIXME: This should go into the Lexer, but we need to figure out how @@ -367,8 +367,8 @@ class MergedReplacement { public: MergedReplacement(const Replacement &R, bool MergeSecond, int D) : MergeSecond(MergeSecond), Delta(D), FilePath(R.getFilePath()), - Offset(R.getOffset() + (MergeSecond ? 0 : Delta)), Length(R.getLength()), - Text(R.getReplacementText()) { + Offset(R.getOffset() + (MergeSecond ? 0 : Delta)), + Length(R.getLength()), Text(std::string(R.getReplacementText())) { Delta += MergeSecond ? 0 : Text.size() - Length; DeltaFirst = MergeSecond ? Text.size() - Length : 0; } |