diff options
Diffstat (limited to 'lib/Remarks/YAMLRemarkParser.h')
-rw-r--r-- | lib/Remarks/YAMLRemarkParser.h | 38 |
1 files changed, 31 insertions, 7 deletions
diff --git a/lib/Remarks/YAMLRemarkParser.h b/lib/Remarks/YAMLRemarkParser.h index cea76e63e75c..03707433bc03 100644 --- a/lib/Remarks/YAMLRemarkParser.h +++ b/lib/Remarks/YAMLRemarkParser.h @@ -18,6 +18,7 @@ #include "llvm/Remarks/Remark.h" #include "llvm/Remarks/RemarkParser.h" #include "llvm/Support/Error.h" +#include "llvm/Support/MemoryBuffer.h" #include "llvm/Support/SourceMgr.h" #include "llvm/Support/YAMLParser.h" #include "llvm/Support/YAMLTraits.h" @@ -46,9 +47,9 @@ private: }; /// Regular YAML to Remark parser. -struct YAMLRemarkParser : public Parser { +struct YAMLRemarkParser : public RemarkParser { /// The string table used for parsing strings. - Optional<const ParsedStringTable *> StrTab; + Optional<ParsedStringTable> StrTab; /// Last error message that can come from the YAML parser diagnostics. /// We need this for catching errors in the constructor. std::string LastErrorMessage; @@ -58,17 +59,20 @@ struct YAMLRemarkParser : public Parser { yaml::Stream Stream; /// Iterator in the YAML stream. yaml::document_iterator YAMLIt; + /// If we parse remark metadata in separate mode, we need to open a new file + /// and parse that. + std::unique_ptr<MemoryBuffer> SeparateBuf; - YAMLRemarkParser(StringRef Buf, - Optional<const ParsedStringTable *> StrTab = None); + YAMLRemarkParser(StringRef Buf); Expected<std::unique_ptr<Remark>> next() override; - static bool classof(const Parser *P) { + static bool classof(const RemarkParser *P) { return P->ParserFormat == Format::YAML; } -private: +protected: + YAMLRemarkParser(StringRef Buf, Optional<ParsedStringTable> StrTab); /// Create a YAMLParseError error from an existing error generated by the YAML /// parser. /// If there is no error, this returns Success. @@ -82,7 +86,7 @@ private: /// Parse one key to a string. Expected<StringRef> parseKey(yaml::KeyValueNode &Node); /// Parse one value to a string. - Expected<StringRef> parseStr(yaml::KeyValueNode &Node); + virtual Expected<StringRef> parseStr(yaml::KeyValueNode &Node); /// Parse one value to an unsigned. Expected<unsigned> parseUnsigned(yaml::KeyValueNode &Node); /// Parse a debug location. @@ -90,6 +94,26 @@ private: /// Parse an argument. Expected<Argument> parseArg(yaml::Node &Node); }; + +/// YAML with a string table to Remark parser. +struct YAMLStrTabRemarkParser : public YAMLRemarkParser { + YAMLStrTabRemarkParser(StringRef Buf, ParsedStringTable StrTab) + : YAMLRemarkParser(Buf, std::move(StrTab)) {} + + static bool classof(const RemarkParser *P) { + return P->ParserFormat == Format::YAMLStrTab; + } + +protected: + /// Parse one value to a string. + Expected<StringRef> parseStr(yaml::KeyValueNode &Node) override; +}; + +Expected<std::unique_ptr<YAMLRemarkParser>> +createYAMLParserFromMeta(StringRef Buf, + Optional<ParsedStringTable> StrTab = None, + Optional<StringRef> ExternalFilePrependPath = None); + } // end namespace remarks } // end namespace llvm |