[clang] a735d6e - JSONCompilationDatabase.cpp - cleanup key parsing error checks. NFCI.
Simon Pilgrim via cfe-commits
cfe-commits at lists.llvm.org
Sun Sep 20 06:01:14 PDT 2020
Author: Simon Pilgrim
Date: 2020-09-20T13:55:29+01:00
New Revision: a735d6eae2847b039d12c75d4c794862dad59bc1
URL: https://github.com/llvm/llvm-project/commit/a735d6eae2847b039d12c75d4c794862dad59bc1
DIFF: https://github.com/llvm/llvm-project/commit/a735d6eae2847b039d12c75d4c794862dad59bc1.diff
LOG: JSONCompilationDatabase.cpp - cleanup key parsing error checks. NFCI.
Merge the key + sequence/value checks with the key handling code.
Reduces the number of key string comparisons and avoids a number of clang static analyzer null dereference warnings.
Added:
Modified:
clang/lib/Tooling/JSONCompilationDatabase.cpp
Removed:
################################################################################
diff --git a/clang/lib/Tooling/JSONCompilationDatabase.cpp b/clang/lib/Tooling/JSONCompilationDatabase.cpp
index 4af361f538cb..67a42d3c55a7 100644
--- a/clang/lib/Tooling/JSONCompilationDatabase.cpp
+++ b/clang/lib/Tooling/JSONCompilationDatabase.cpp
@@ -369,16 +369,11 @@ bool JSONCompilationDatabase::parse(std::string &ErrorMessage) {
}
auto *ValueString = dyn_cast<llvm::yaml::ScalarNode>(Value);
auto *SequenceString = dyn_cast<llvm::yaml::SequenceNode>(Value);
- if (KeyValue == "arguments" && !SequenceString) {
- ErrorMessage = "Expected sequence as value.";
- return false;
- } else if (KeyValue != "arguments" && !ValueString) {
- ErrorMessage = "Expected string as value.";
- return false;
- }
- if (KeyValue == "directory") {
- Directory = ValueString;
- } else if (KeyValue == "arguments") {
+ if (KeyValue == "arguments") {
+ if (!SequenceString) {
+ ErrorMessage = "Expected sequence as value.";
+ return false;
+ }
Command = std::vector<llvm::yaml::ScalarNode *>();
for (auto &Argument : *SequenceString) {
auto *Scalar = dyn_cast<llvm::yaml::ScalarNode>(&Argument);
@@ -388,17 +383,25 @@ bool JSONCompilationDatabase::parse(std::string &ErrorMessage) {
}
Command->push_back(Scalar);
}
- } else if (KeyValue == "command") {
- if (!Command)
- Command = std::vector<llvm::yaml::ScalarNode *>(1, ValueString);
- } else if (KeyValue == "file") {
- File = ValueString;
- } else if (KeyValue == "output") {
- Output = ValueString;
} else {
- ErrorMessage = ("Unknown key: \"" +
- KeyString->getRawValue() + "\"").str();
- return false;
+ if (!ValueString) {
+ ErrorMessage = "Expected string as value.";
+ return false;
+ }
+ if (KeyValue == "directory") {
+ Directory = ValueString;
+ } else if (KeyValue == "command") {
+ if (!Command)
+ Command = std::vector<llvm::yaml::ScalarNode *>(1, ValueString);
+ } else if (KeyValue == "file") {
+ File = ValueString;
+ } else if (KeyValue == "output") {
+ Output = ValueString;
+ } else {
+ ErrorMessage =
+ ("Unknown key: \"" + KeyString->getRawValue() + "\"").str();
+ return false;
+ }
}
}
if (!File) {
More information about the cfe-commits
mailing list