[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
Sat Mar 20 11:08:43 PDT 2021
This revision was automatically updated to reflect the committed changes.
Closed by commit rG188405bc192d: [AST] Ensure that an empty json file is generated if compile errors (authored by stephenkelly).
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D98827/new/
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.332118.patch
Type: text/x-patch
Size: 2876 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20210320/cd5c3404/attachment-0001.bin>
More information about the cfe-commits
mailing list