[clang] 188405b - [AST] Ensure that an empty json file is generated if compile errors
Stephen Kelly via cfe-commits
cfe-commits at lists.llvm.org
Sat Mar 20 11:08:30 PDT 2021
Author: Stephen Kelly
Date: 2021-03-20T18:08:01Z
New Revision: 188405bc192df54fbf048ddd3da071c9fff4d0d1
URL: https://github.com/llvm/llvm-project/commit/188405bc192df54fbf048ddd3da071c9fff4d0d1
DIFF: https://github.com/llvm/llvm-project/commit/188405bc192df54fbf048ddd3da071c9fff4d0d1.diff
LOG: [AST] Ensure that an empty json file is generated if compile errors
Differential Revision: https://reviews.llvm.org/D98827
Added:
Modified:
clang/lib/Tooling/DumpTool/ASTSrcLocProcessor.cpp
clang/lib/Tooling/DumpTool/ASTSrcLocProcessor.h
clang/lib/Tooling/DumpTool/ClangSrcLocDump.cpp
Removed:
################################################################################
diff --git a/clang/lib/Tooling/DumpTool/ASTSrcLocProcessor.cpp b/clang/lib/Tooling/DumpTool/ASTSrcLocProcessor.cpp
index ff279d9425d8..e7400e958716 100644
--- a/clang/lib/Tooling/DumpTool/ASTSrcLocProcessor.cpp
+++ b/clang/lib/Tooling/DumpTool/ASTSrcLocProcessor.cpp
@@ -79,17 +79,16 @@ llvm::json::Object toJSON(llvm::StringMap<ClassData> const &Obj) {
return JsonObj;
}
-void WriteJSON(std::string JsonPath,
- llvm::StringMap<StringRef> const &ClassInheritance,
- llvm::StringMap<std::vector<StringRef>> const &ClassesInClade,
- llvm::StringMap<ClassData> const &ClassEntries) {
+void WriteJSON(std::string JsonPath, llvm::json::Object &&ClassInheritance,
+ llvm::json::Object &&ClassesInClade,
+ llvm::json::Object &&ClassEntries) {
llvm::json::Object JsonObj;
using llvm::json::toJSON;
- JsonObj["classInheritance"] = ::toJSON(ClassInheritance);
- JsonObj["classesInClade"] = ::toJSON(ClassesInClade);
- JsonObj["classEntries"] = ::toJSON(ClassEntries);
+ JsonObj["classInheritance"] = std::move(ClassInheritance);
+ JsonObj["classesInClade"] = std::move(ClassesInClade);
+ JsonObj["classEntries"] = std::move(ClassEntries);
std::error_code EC;
llvm::raw_fd_ostream JsonOut(JsonPath, EC, llvm::sys::fs::F_Text);
@@ -101,9 +100,12 @@ void WriteJSON(std::string JsonPath,
}
void ASTSrcLocProcessor::generate() {
- WriteJSON(JsonPath, ClassInheritance, ClassesInClade, ClassEntries);
+ WriteJSON(JsonPath, ::toJSON(ClassInheritance), ::toJSON(ClassesInClade),
+ ::toJSON(ClassEntries));
}
+void ASTSrcLocProcessor::generateEmpty() { WriteJSON(JsonPath, {}, {}, {}); }
+
std::vector<std::string>
CaptureMethods(std::string TypeString, const clang::CXXRecordDecl *ASTClass,
const MatchFinder::MatchResult &Result) {
diff --git a/clang/lib/Tooling/DumpTool/ASTSrcLocProcessor.h b/clang/lib/Tooling/DumpTool/ASTSrcLocProcessor.h
index 00994758e03c..5d848f48ed54 100644
--- a/clang/lib/Tooling/DumpTool/ASTSrcLocProcessor.h
+++ b/clang/lib/Tooling/DumpTool/ASTSrcLocProcessor.h
@@ -30,6 +30,7 @@ class ASTSrcLocProcessor : public ast_matchers::MatchFinder::MatchCallback {
StringRef File);
void generate();
+ void generateEmpty();
private:
void run(const ast_matchers::MatchFinder::MatchResult &Result) override;
diff --git a/clang/lib/Tooling/DumpTool/ClangSrcLocDump.cpp b/clang/lib/Tooling/DumpTool/ClangSrcLocDump.cpp
index 06b58c6382ed..8328977178cc 100644
--- a/clang/lib/Tooling/DumpTool/ClangSrcLocDump.cpp
+++ b/clang/lib/Tooling/DumpTool/ClangSrcLocDump.cpp
@@ -48,7 +48,13 @@ class ASTSrcLocGenerationAction : public clang::ASTFrontendAction {
public:
ASTSrcLocGenerationAction() : Processor(JsonOutputPath) {}
- ~ASTSrcLocGenerationAction() { Processor.generate(); }
+ void ExecuteAction() override {
+ clang::ASTFrontendAction::ExecuteAction();
+ if (getCompilerInstance().getDiagnostics().getNumErrors() > 0)
+ Processor.generateEmpty();
+ else
+ Processor.generate();
+ }
std::unique_ptr<clang::ASTConsumer>
CreateASTConsumer(clang::CompilerInstance &Compiler,
More information about the cfe-commits
mailing list