aboutsummaryrefslogtreecommitdiff
path: root/clang/lib/Basic/SourceLocation.cpp
diff options
context:
space:
mode:
authorVaibhav Yenamandra <vyenamandra@bloomberg.net>2022-06-24 07:16:54 -0400
committerAaron Ballman <aaron@aaronballman.com>2022-06-24 07:16:54 -0400
commit6546fdbe36fd1227d7f23f89fd9a9825813b3de9 (patch)
tree813d8be6fc402a6bf3262ee28ca35af0deee0f10 /clang/lib/Basic/SourceLocation.cpp
parente523baa664b7fc678aa1c0963980a70af161469d (diff)
downloadllvm-6546fdbe36fd1227d7f23f89fd9a9825813b3de9.zip
llvm-6546fdbe36fd1227d7f23f89fd9a9825813b3de9.tar.gz
llvm-6546fdbe36fd1227d7f23f89fd9a9825813b3de9.tar.bz2
[clang] Emit SARIF Diagnostics: Create `clang::SarifDocumentWriter` interface
Create an interface for writing SARIF documents from within clang: The primary intent of this change is to introduce the interface clang::SarifDocumentWriter, which allows incrementally adding diagnostic data to a JSON backed document. The proposed interface is not yet connected to the compiler internals, which will be covered in future work. As such this change will not change the input/output interface of clang. This change also introduces the clang::FullSourceRange type that is modeled after clang::SourceRange + clang::FullSourceLoc, this is useful for packaging a pair of clang::SourceLocation objects with their corresponding SourceManagers. Previous discussions: RFC for this change: https://lists.llvm.org/pipermail/cfe-dev/2021-March/067907.html https://lists.llvm.org/pipermail/cfe-dev/2021-July/068480.html SARIF Standard (2.1.0): https://docs.oasis-open.org/sarif/sarif/v2.1.0/os/sarif-v2.1.0-os.html Differential Revision: https://reviews.llvm.org/D109701
Diffstat (limited to 'clang/lib/Basic/SourceLocation.cpp')
-rw-r--r--clang/lib/Basic/SourceLocation.cpp27
1 files changed, 27 insertions, 0 deletions
diff --git a/clang/lib/Basic/SourceLocation.cpp b/clang/lib/Basic/SourceLocation.cpp
index 6e5e55f..931ea22 100644
--- a/clang/lib/Basic/SourceLocation.cpp
+++ b/clang/lib/Basic/SourceLocation.cpp
@@ -270,3 +270,30 @@ StringRef FullSourceLoc::getBufferData(bool *Invalid) const {
std::pair<FileID, unsigned> FullSourceLoc::getDecomposedLoc() const {
return SrcMgr->getDecomposedLoc(*this);
}
+
+//===----------------------------------------------------------------------===//
+// FullSourceRange
+//===----------------------------------------------------------------------===//
+
+void FullSourceRange::print(raw_ostream &OS) const {
+
+ OS << '<';
+ PresumedLoc PrintedLoc = PrintDifference(OS, B.getManager(), B, {});
+ if (B != E) {
+ OS << ", ";
+ PrintDifference(OS, E.getManager(), E, PrintedLoc);
+ }
+ OS << '>';
+}
+
+LLVM_DUMP_METHOD std::string FullSourceRange::printToString() const {
+ std::string S;
+ llvm::raw_string_ostream OS(S);
+ print(OS);
+ return OS.str();
+}
+
+LLVM_DUMP_METHOD void FullSourceRange::dump() const {
+ this->print(llvm::errs());
+ llvm::errs() << '\n';
+}