mirror of
https://github.com/RPCS3/llvm-mirror.git
synced 2025-01-31 12:41:49 +01:00
[YAML] Use correct source location for unknown key errors.
Currently unknown keys when inputting mapping traits have the location set to the Value. Example: ``` YAML:1:14: error: unknown key 'UnknownKey' {UnknownKey: SomeValue} ^~~~~~~~~ ``` This is unhelpful for a user as it draws them to fix the wrong item. Reviewed By: silvas Differential Revision: https://reviews.llvm.org/D93037
This commit is contained in:
parent
2622f275cb
commit
5aeae74b36
@ -102,6 +102,8 @@ public:
|
||||
|
||||
void printError(Node *N, const Twine &Msg,
|
||||
SourceMgr::DiagKind Kind = SourceMgr::DK_Error);
|
||||
void printError(const SMRange &Range, const Twine &Msg,
|
||||
SourceMgr::DiagKind Kind = SourceMgr::DK_Error);
|
||||
|
||||
private:
|
||||
friend class Document;
|
||||
|
@ -18,6 +18,7 @@
|
||||
#include "llvm/Support/Allocator.h"
|
||||
#include "llvm/Support/Endian.h"
|
||||
#include "llvm/Support/Regex.h"
|
||||
#include "llvm/Support/SMLoc.h"
|
||||
#include "llvm/Support/SourceMgr.h"
|
||||
#include "llvm/Support/VersionTuple.h"
|
||||
#include "llvm/Support/YAMLParser.h"
|
||||
@ -1471,9 +1472,10 @@ private:
|
||||
|
||||
static bool classof(const MapHNode *) { return true; }
|
||||
|
||||
using NameToNode = StringMap<std::unique_ptr<HNode>>;
|
||||
using NameToNodeAndLoc =
|
||||
StringMap<std::pair<std::unique_ptr<HNode>, SMRange>>;
|
||||
|
||||
NameToNode Mapping;
|
||||
NameToNodeAndLoc Mapping;
|
||||
SmallVector<std::string, 6> ValidKeys;
|
||||
};
|
||||
|
||||
@ -1495,9 +1497,11 @@ private:
|
||||
std::unique_ptr<Input::HNode> createHNodes(Node *node);
|
||||
void setError(HNode *hnode, const Twine &message);
|
||||
void setError(Node *node, const Twine &message);
|
||||
void setError(const SMRange &Range, const Twine &message);
|
||||
|
||||
void reportWarning(HNode *hnode, const Twine &message);
|
||||
void reportWarning(Node *hnode, const Twine &message);
|
||||
void reportWarning(const SMRange &Range, const Twine &message);
|
||||
|
||||
public:
|
||||
// These are only used by operator>>. They could be private
|
||||
|
@ -1774,7 +1774,11 @@ Stream::~Stream() = default;
|
||||
bool Stream::failed() { return scanner->failed(); }
|
||||
|
||||
void Stream::printError(Node *N, const Twine &Msg, SourceMgr::DiagKind Kind) {
|
||||
SMRange Range = N ? N->getSourceRange() : SMRange();
|
||||
printError(N ? N->getSourceRange() : SMRange(), Msg, Kind);
|
||||
}
|
||||
|
||||
void Stream::printError(const SMRange &Range, const Twine &Msg,
|
||||
SourceMgr::DiagKind Kind) {
|
||||
scanner->printError(Range.Start, Kind, Msg, Range);
|
||||
}
|
||||
|
||||
|
@ -175,7 +175,7 @@ bool Input::preflightKey(const char *Key, bool Required, bool, bool &UseDefault,
|
||||
return false;
|
||||
}
|
||||
MN->ValidKeys.push_back(Key);
|
||||
HNode *Value = MN->Mapping[Key].get();
|
||||
HNode *Value = MN->Mapping[Key].first.get();
|
||||
if (!Value) {
|
||||
if (Required)
|
||||
setError(CurrentNode, Twine("missing required key '") + Key + "'");
|
||||
@ -201,12 +201,12 @@ void Input::endMapping() {
|
||||
return;
|
||||
for (const auto &NN : MN->Mapping) {
|
||||
if (!is_contained(MN->ValidKeys, NN.first())) {
|
||||
HNode *ReportNode = NN.second.get();
|
||||
const SMRange &ReportLoc = NN.second.second;
|
||||
if (!AllowUnknownKeys) {
|
||||
setError(ReportNode, Twine("unknown key '") + NN.first() + "'");
|
||||
setError(ReportLoc, Twine("unknown key '") + NN.first() + "'");
|
||||
break;
|
||||
} else
|
||||
reportWarning(ReportNode, Twine("unknown key '") + NN.first() + "'");
|
||||
reportWarning(ReportLoc, Twine("unknown key '") + NN.first() + "'");
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -378,11 +378,24 @@ void Input::setError(Node *node, const Twine &message) {
|
||||
EC = make_error_code(errc::invalid_argument);
|
||||
}
|
||||
|
||||
void Input::setError(const SMRange &range, const Twine &message) {
|
||||
Strm->printError(range, message);
|
||||
EC = make_error_code(errc::invalid_argument);
|
||||
}
|
||||
|
||||
void Input::reportWarning(HNode *hnode, const Twine &message) {
|
||||
assert(hnode && "HNode must not be NULL");
|
||||
Strm->printError(hnode->_node, message, SourceMgr::DK_Warning);
|
||||
}
|
||||
|
||||
void Input::reportWarning(Node *node, const Twine &message) {
|
||||
Strm->printError(node, message, SourceMgr::DK_Warning);
|
||||
}
|
||||
|
||||
void Input::reportWarning(const SMRange &range, const Twine &message) {
|
||||
Strm->printError(range, message, SourceMgr::DK_Warning);
|
||||
}
|
||||
|
||||
std::unique_ptr<Input::HNode> Input::createHNodes(Node *N) {
|
||||
SmallString<128> StringStorage;
|
||||
if (ScalarNode *SN = dyn_cast<ScalarNode>(N)) {
|
||||
@ -426,7 +439,8 @@ std::unique_ptr<Input::HNode> Input::createHNodes(Node *N) {
|
||||
auto ValueHNode = createHNodes(Value);
|
||||
if (EC)
|
||||
break;
|
||||
mapHNode->Mapping[KeyStr] = std::move(ValueHNode);
|
||||
mapHNode->Mapping[KeyStr] =
|
||||
std::make_pair(std::move(ValueHNode), KeyNode->getSourceRange());
|
||||
}
|
||||
return std::move(mapHNode);
|
||||
} else if (isa<NullNode>(N)) {
|
||||
|
@ -18,7 +18,7 @@ name: test
|
||||
frameInfo:
|
||||
maxAlignment: 4
|
||||
fixedStack:
|
||||
# CHECK: [[@LINE+1]]:63: unknown key 'isAliased'
|
||||
# CHECK: [[@LINE+1]]:52: unknown key 'isAliased'
|
||||
- { id: 0, type: spill-slot, offset: 0, size: 4, isAliased: true }
|
||||
stack:
|
||||
- { id: 0, offset: -12, size: 4, alignment: 4 }
|
||||
|
@ -18,7 +18,7 @@ name: test
|
||||
frameInfo:
|
||||
maxAlignment: 4
|
||||
fixedStack:
|
||||
# CHECK: [[@LINE+1]]:65: unknown key 'isImmutable'
|
||||
# CHECK: [[@LINE+1]]:52: unknown key 'isImmutable'
|
||||
- { id: 0, type: spill-slot, offset: 0, size: 4, isImmutable: true }
|
||||
stack:
|
||||
- { id: 0, offset: -12, size: 4, alignment: 4 }
|
||||
|
@ -23,7 +23,7 @@ frameInfo:
|
||||
stack:
|
||||
- { id: 0, offset: -20, size: 4, alignment: 4 }
|
||||
- { id: 1, offset: -32, size: 8, alignment: 8 }
|
||||
# CHECK: [[@LINE+1]]:55: unknown key 'size'
|
||||
# CHECK: [[@LINE+1]]:49: unknown key 'size'
|
||||
- { id: 2, type: variable-sized, offset: -32, size: 42, alignment: 1 }
|
||||
body: |
|
||||
bb.0.entry:
|
||||
|
@ -9,7 +9,7 @@ RUN: | FileCheck %s -check-prefix V3
|
||||
|
||||
# Typo Check
|
||||
V1: tapi-invalid-v1.tbd malformed file
|
||||
V1-NEXT: tapi-invalid-v1.tbd:12:2: error: unknown key 'expors'
|
||||
V1-NEXT: tapi-invalid-v1.tbd:11:1: error: unknown key 'expors'
|
||||
|
||||
# Missing required key
|
||||
V2: tapi-invalid-v2.tbd malformed file
|
||||
@ -17,4 +17,4 @@ V2-NEXT: tapi-invalid-v2.tbd:2:1: error: missing required key 'archs'
|
||||
|
||||
# v2 key in v3 specified file
|
||||
V3: tapi-invalid-v3.tbd malformed file
|
||||
V3-NEXT: tapi-invalid-v3.tbd:19:16: error: unknown key 'swift-version'
|
||||
V3-NEXT: tapi-invalid-v3.tbd:19:1: error: unknown key 'swift-version'
|
||||
|
@ -451,8 +451,8 @@ TEST(TBDv1, MalformedFile2) {
|
||||
EXPECT_FALSE(!!Result);
|
||||
std::string ErrorMessage = toString(Result.takeError());
|
||||
ASSERT_EQ(
|
||||
"malformed file\nTest.tbd:5:9: error: unknown key 'foobar'\nfoobar: "
|
||||
"\"Unsupported key\"\n ^~~~~~~~~~~~~~~~~\n",
|
||||
"malformed file\nTest.tbd:5:1: error: unknown key 'foobar'\nfoobar: "
|
||||
"\"Unsupported key\"\n^~~~~~\n",
|
||||
ErrorMessage);
|
||||
}
|
||||
|
||||
|
@ -486,8 +486,8 @@ TEST(TBDv2, MalformedFile2) {
|
||||
EXPECT_FALSE(!!Result);
|
||||
std::string ErrorMessage = toString(Result.takeError());
|
||||
ASSERT_EQ(
|
||||
"malformed file\nTest.tbd:5:9: error: unknown key 'foobar'\nfoobar: "
|
||||
"\"Unsupported key\"\n ^~~~~~~~~~~~~~~~~\n",
|
||||
"malformed file\nTest.tbd:5:1: error: unknown key 'foobar'\nfoobar: "
|
||||
"\"Unsupported key\"\n^~~~~~\n",
|
||||
ErrorMessage);
|
||||
}
|
||||
|
||||
|
@ -831,8 +831,8 @@ TEST(TBDv3, MalformedFile2) {
|
||||
EXPECT_FALSE(!!Result);
|
||||
std::string ErrorMessage = toString(Result.takeError());
|
||||
ASSERT_EQ(
|
||||
"malformed file\nTest.tbd:5:9: error: unknown key 'foobar'\nfoobar: "
|
||||
"\"Unsupported key\"\n ^~~~~~~~~~~~~~~~~\n",
|
||||
"malformed file\nTest.tbd:5:1: error: unknown key 'foobar'\nfoobar: "
|
||||
"\"Unsupported key\"\n^~~~~~\n",
|
||||
ErrorMessage);
|
||||
}
|
||||
|
||||
|
@ -924,8 +924,8 @@ TEST(TBDv4, MalformedFile2) {
|
||||
EXPECT_FALSE(!!Result);
|
||||
std::string ErrorMessage = toString(Result.takeError());
|
||||
ASSERT_EQ(
|
||||
"malformed file\nTest.tbd:5:9: error: unknown key 'foobar'\nfoobar: "
|
||||
"\"unsupported key\"\n ^~~~~~~~~~~~~~~~~\n",
|
||||
"malformed file\nTest.tbd:5:1: error: unknown key 'foobar'\nfoobar: "
|
||||
"\"unsupported key\"\n^~~~~~\n",
|
||||
ErrorMessage);
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user