[PATCH] D98827: [AST] Ensure that an empty json file is generated if compile errors
Stephen Kelly via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Wed Mar 17 16:30:49 PDT 2021
steveire created this revision.
steveire added a reviewer: njames93.
steveire requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D98827
Files:
clang/lib/Tooling/DumpTool/ASTSrcLocProcessor.cpp
clang/lib/Tooling/DumpTool/ASTSrcLocProcessor.h
clang/lib/Tooling/DumpTool/ClangSrcLocDump.cpp
Index: clang/lib/Tooling/DumpTool/ClangSrcLocDump.cpp
===================================================================
--- clang/lib/Tooling/DumpTool/ClangSrcLocDump.cpp
+++ clang/lib/Tooling/DumpTool/ClangSrcLocDump.cpp
@@ -48,7 +48,13 @@
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,
Index: clang/lib/Tooling/DumpTool/ASTSrcLocProcessor.h
===================================================================
--- clang/lib/Tooling/DumpTool/ASTSrcLocProcessor.h
+++ clang/lib/Tooling/DumpTool/ASTSrcLocProcessor.h
@@ -30,6 +30,7 @@
StringRef File);
void generate();
+ void generateEmpty();
private:
void run(const ast_matchers::MatchFinder::MatchResult &Result) override;
Index: clang/lib/Tooling/DumpTool/ASTSrcLocProcessor.cpp
===================================================================
--- clang/lib/Tooling/DumpTool/ASTSrcLocProcessor.cpp
+++ clang/lib/Tooling/DumpTool/ASTSrcLocProcessor.cpp
@@ -79,17 +79,16 @@
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 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) {
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D98827.331412.patch
Type: text/x-patch
Size: 2876 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20210317/4fd8d927/attachment.bin>
More information about the cfe-commits
mailing list