llvm.org GIT mirror llvm / f8d95d2
[Remarks][NFC] Rename RemarkParser to YAMLRemarkParser Rename it to reflect that it's parsing YAML remarks. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@355441 91177308-0d34-0410-b5e6-96231b3b80d8 Francis Visoiu Mistrih 5 months ago
1 changed file(s) with 20 addition(s) and 19 deletion(s). Raw diff Collapse all Expand all
1818 using namespace llvm;
1919
2020 namespace {
21 struct RemarkParser {
21 struct YAMLRemarkParser {
2222 /// Source manager for better error messages.
2323 SourceMgr SM;
2424 /// Stream for yaml parsing.
5858 /// Set to `true` if we had any errors during parsing.
5959 bool HadAnyErrors = false;
6060
61 RemarkParser(StringRef Buf)
61 YAMLRemarkParser(StringRef Buf)
6262 : SM(), Stream(Buf, SM), ErrorString(), ErrorStream(ErrorString),
6363 DI(Stream.begin()), LastRemark(), TmpArgs(), State(TmpArgs) {
64 SM.setDiagHandler(RemarkParser::HandleDiagnostic, this);
64 SM.setDiagHandler(YAMLRemarkParser::HandleDiagnostic, this);
6565 }
6666
6767 /// Parse a YAML element.
8282 Error parseArg(SmallVectorImpl &TmpArgs, yaml::Node &Node);
8383
8484 /// Handle a diagnostic from the YAML stream. Records the error in the
85 /// RemarkParser class.
85 /// YAMLRemarkParser class.
8686 static void HandleDiagnostic(const SMDiagnostic &Diag, void *Ctx) {
8787 assert(Ctx && "Expected non-null Ctx in diagnostic handler.");
88 auto *Parser = static_cast<RemarkParser *>(Ctx);
88 auto *Parser = static_cast<YAMLRemarkParser *>(Ctx);
8989 Diag.print(/*ProgName=*/nullptr, Parser->ErrorStream, /*ShowColors*/ false,
9090 /*ShowKindLabels*/ true);
9191 }
117117 return {Str.data(), static_cast(Str.size())};
118118 }
119119
120 Error RemarkParser::parseKey(StringRef &Result, yaml::KeyValueNode &Node) {
120 Error YAMLRemarkParser::parseKey(StringRef &Result, yaml::KeyValueNode &Node) {
121121 auto *Key = dyn_cast(Node.getKey());
122122 if (!Key)
123123 return make_error("key is not a string.", Node);
126126 return Error::success();
127127 }
128128
129 Error RemarkParser::parseValue(StringRef &Result, yaml::KeyValueNode &Node) {
129 Error YAMLRemarkParser::parseValue(StringRef &Result,
130 yaml::KeyValueNode &Node) {
130131 auto *Value = dyn_cast(Node.getValue());
131132 if (!Value)
132133 return make_error("expected a value of scalar type.", Node);
141142 return Error::success();
142143 }
143144
144 Error RemarkParser::parseValue(Optional &Result,
145 yaml::KeyValueNode &Node) {
145 Error YAMLRemarkParser::parseValue(Optional &Result,
146 yaml::KeyValueNode &Node) {
146147 SmallVector Tmp;
147148 auto *Value = dyn_cast(Node.getValue());
148149 if (!Value)
154155 return Error::success();
155156 }
156157
157 Error RemarkParser::parseDebugLoc(Optional &File,
158 Optional &Line,
159 Optional &Column,
160 yaml::KeyValueNode &Node) {
158 Error YAMLRemarkParser::parseDebugLoc(Optional &File,
159 Optional &Line,
160 Optional &Column,
161 yaml::KeyValueNode &Node) {
161162 auto *DebugLoc = dyn_cast(Node.getValue());
162163 if (!DebugLoc)
163164 return make_error("expected a value of mapping type.", Node);
189190 return Error::success();
190191 }
191192
192 Error RemarkParser::parseArg(SmallVectorImpl &Args,
193 yaml::Node &Node) {
193 Error YAMLRemarkParser::parseArg(SmallVectorImpl &Args,
194 yaml::Node &Node) {
194195 auto *ArgMap = dyn_cast(&Node);
195196 if (!ArgMap)
196197 return make_error("expected a value of mapping type.", Node);
244245 return Error::success();
245246 }
246247
247 Error RemarkParser::parseYAMLElement(yaml::Document &Remark) {
248 Error YAMLRemarkParser::parseYAMLElement(yaml::Document &Remark) {
248249 // Parsing a new remark, clear the previous one.
249250 LastRemark = None;
250251 State = ParseState(TmpArgs);
317318 } // namespace
318319
319320 // Create wrappers for C Binding types (see CBindingWrapping.h).
320 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(RemarkParser, LLVMRemarkParserRef)
321 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(YAMLRemarkParser, LLVMRemarkParserRef)
321322
322323 extern "C" LLVMRemarkParserRef LLVMRemarkParserCreate(const void *Buf,
323324 uint64_t Size) {
324325 return wrap(
325 new RemarkParser(StringRef(static_cast(Buf), Size)));
326 new YAMLRemarkParser(StringRef(static_cast(Buf), Size)));
326327 }
327328
328329 extern "C" LLVMRemarkEntry *
329330 LLVMRemarkParserGetNext(LLVMRemarkParserRef Parser) {
330 RemarkParser &TheParser = *unwrap(Parser);
331 YAMLRemarkParser &TheParser = *unwrap(Parser);
331332 // Check for EOF.
332333 if (TheParser.HadAnyErrors || TheParser.DI == TheParser.Stream.end())
333334 return nullptr;