[PATCH] D153760: [YAMLParser] Support block nodes when parsing YAML strings.
Zain Jaffal via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Mon Jun 26 06:31:22 PDT 2023
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rGe800967eb110: [YAMLParser] Support block nodes when parsing YAML strings. (authored by zjaffal).
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D153760/new/
https://reviews.llvm.org/D153760
Files:
llvm/lib/Remarks/YAMLRemarkParser.cpp
llvm/unittests/Remarks/YAMLRemarksParsingTest.cpp
Index: llvm/unittests/Remarks/YAMLRemarksParsingTest.cpp
===================================================================
--- llvm/unittests/Remarks/YAMLRemarksParsingTest.cpp
+++ llvm/unittests/Remarks/YAMLRemarksParsingTest.cpp
@@ -154,6 +154,16 @@
" - String: ' because its definition is unavailable'\n"
"Pass: inline\n"
"");
+
+ // Block Remark.
+ parseGood("\n"
+ "--- !Missed\n"
+ "Function: foo\n"
+ "Name: NoDefinition\n"
+ "Args:\n"
+ " - String: |\n \n \n blocks\n"
+ "Pass: inline\n"
+ "");
}
// Mandatory common part of a remark.
Index: llvm/lib/Remarks/YAMLRemarkParser.cpp
===================================================================
--- llvm/lib/Remarks/YAMLRemarkParser.cpp
+++ llvm/lib/Remarks/YAMLRemarkParser.cpp
@@ -293,9 +293,16 @@
Expected<StringRef> YAMLRemarkParser::parseStr(yaml::KeyValueNode &Node) {
auto *Value = dyn_cast<yaml::ScalarNode>(Node.getValue());
- if (!Value)
- return error("expected a value of scalar type.", Node);
- StringRef Result = Value->getRawValue();
+ yaml::BlockScalarNode *ValueBlock;
+ StringRef Result;
+ if (!Value) {
+ // Try to parse the value as a block node.
+ ValueBlock = dyn_cast<yaml::BlockScalarNode>(Node.getValue());
+ if (!ValueBlock)
+ return error("expected a value of scalar type.", Node);
+ Result = ValueBlock->getValue();
+ } else
+ Result = Value->getRawValue();
if (Result.front() == '\'')
Result = Result.drop_front();
@@ -429,9 +436,16 @@
Expected<StringRef> YAMLStrTabRemarkParser::parseStr(yaml::KeyValueNode &Node) {
auto *Value = dyn_cast<yaml::ScalarNode>(Node.getValue());
- if (!Value)
- return error("expected a value of scalar type.", Node);
+ yaml::BlockScalarNode *ValueBlock;
StringRef Result;
+ if (!Value) {
+ // Try to parse the value as a block node.
+ ValueBlock = dyn_cast<yaml::BlockScalarNode>(Node.getValue());
+ if (!ValueBlock)
+ return error("expected a value of scalar type.", Node);
+ Result = ValueBlock->getValue();
+ } else
+ Result = Value->getRawValue();
// If we have a string table, parse it as an unsigned.
unsigned StrID = 0;
if (Expected<unsigned> MaybeStrID = parseUnsigned(Node))
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D153760.534520.patch
Type: text/x-patch
Size: 2346 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230626/976a6a32/attachment.bin>
More information about the llvm-commits
mailing list