LLVM 22.0.0git
YAMLRemarkParser.h
Go to the documentation of this file.
1//===-- YAMLRemarkParser.h - Parser for YAML remarks ------------*- C++/-*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8//
9// This file provides the impementation of the YAML remark parser.
10//
11//===----------------------------------------------------------------------===//
12
13#ifndef LLVM_REMARKS_YAML_REMARK_PARSER_H
14#define LLVM_REMARKS_YAML_REMARK_PARSER_H
15
16#include "llvm/Remarks/Remark.h"
18#include "llvm/Support/Error.h"
23#include <optional>
24#include <string>
25
26namespace llvm {
27namespace remarks {
28
29class YAMLParseError : public ErrorInfo<YAMLParseError> {
30public:
31 static char ID;
32
33 YAMLParseError(StringRef Message, SourceMgr &SM, yaml::Stream &Stream,
35
36 YAMLParseError(StringRef Message) : Message(std::string(Message)) {}
37
38 void log(raw_ostream &OS) const override { OS << Message; }
39 std::error_code convertToErrorCode() const override {
41 }
42
43private:
44 std::string Message;
45};
46
47/// Regular YAML to Remark parser.
49 /// Last error message that can come from the YAML parser diagnostics.
50 /// We need this for catching errors in the constructor.
51 std::string LastErrorMessage;
52 /// Source manager for better error messages.
54 /// Stream for yaml parsing.
56 /// Iterator in the YAML stream.
58 /// If we parse remark metadata in separate mode, we need to open a new file
59 /// and parse that.
60 std::unique_ptr<MemoryBuffer> SeparateBuf;
61
63
65
66 static bool classof(const RemarkParser *P) {
67 return P->ParserFormat == Format::YAML;
68 }
69
70protected:
71 /// Create a YAMLParseError error from an existing error generated by the YAML
72 /// parser.
73 /// If there is no error, this returns Success.
74 Error error();
75 /// Create a YAMLParseError error referencing a specific node.
77 /// Parse a YAML remark to a remarks::Remark object.
79 /// Parse the type of a remark to an enum type.
81 /// Parse one key to a string.
83 /// Parse one value to a string.
85 /// Parse one value to an unsigned.
87 /// Parse a debug location.
89 /// Parse an argument.
91};
92
94 StringRef Buf,
95 std::optional<StringRef> ExternalFilePrependPath = std::nullopt);
96
97} // end namespace remarks
98} // end namespace llvm
99
100#endif /* LLVM_REMARKS_YAML_REMARK_PARSER_H */
#define P(N)
raw_pwrite_stream & OS
Base class for user error types.
Definition: Error.h:354
Lightweight error class with error context and mandatory checking.
Definition: Error.h:159
Tagged union holding either a T or a Error.
Definition: Error.h:485
This owns the files read by a parser, handles include stacks, and handles diagnostic wrangling.
Definition: SourceMgr.h:32
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:55
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition: raw_ostream.h:53
void log(raw_ostream &OS) const override
Print an error message to an output stream.
std::error_code convertToErrorCode() const override
Convert this error to a std::error_code.
YAMLParseError(StringRef Message)
A YAML Stream is a sequence of Documents.
Definition: YAMLParser.h:538
A key and value pair.
Definition: YAMLParser.h:292
Represents a YAML map created from either a block map for a flow map.
Definition: YAMLParser.h:421
Abstract base class for all Nodes.
Definition: YAMLParser.h:121
This class represents a YAML stream potentially containing multiple documents.
Definition: YAMLParser.h:88
Iterator abstraction for Documents over a Stream.
Definition: YAMLParser.h:595
Expected< std::unique_ptr< YAMLRemarkParser > > createYAMLParserFromMeta(StringRef Buf, std::optional< StringRef > ExternalFilePrependPath=std::nullopt)
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
LLVM_ABI std::error_code inconvertibleErrorCode()
The value returned by this function can be returned from convertToErrorCode for Error values where no...
Definition: Error.cpp:98
Implement std::hash so that hash_code can be used in STL containers.
Definition: BitVector.h:856
Parser used to parse a raw buffer to remarks::Remark objects.
Definition: RemarkParser.h:41
A remark type used for both emission and parsing.
Definition: Remark.h:98
Regular YAML to Remark parser.
yaml::document_iterator YAMLIt
Iterator in the YAML stream.
Error error()
Create a YAMLParseError error from an existing error generated by the YAML parser.
Expected< unsigned > parseUnsigned(yaml::KeyValueNode &Node)
Parse one value to an unsigned.
yaml::Stream Stream
Stream for yaml parsing.
std::unique_ptr< MemoryBuffer > SeparateBuf
If we parse remark metadata in separate mode, we need to open a new file and parse that.
Expected< RemarkLocation > parseDebugLoc(yaml::KeyValueNode &Node)
Parse a debug location.
virtual Expected< StringRef > parseStr(yaml::KeyValueNode &Node)
Parse one value to a string.
Expected< StringRef > parseKey(yaml::KeyValueNode &Node)
Parse one key to a string.
Expected< Argument > parseArg(yaml::Node &Node)
Parse an argument.
Expected< std::unique_ptr< Remark > > parseRemark(yaml::Document &Remark)
Parse a YAML remark to a remarks::Remark object.
static bool classof(const RemarkParser *P)
Expected< std::unique_ptr< Remark > > next() override
If no error occurs, this returns a valid Remark object.
SourceMgr SM
Source manager for better error messages.
std::string LastErrorMessage
Last error message that can come from the YAML parser diagnostics.
Expected< Type > parseType(yaml::MappingNode &Node)
Parse the type of a remark to an enum type.