From 1d5ae1026e831016fc29fd927877c86af904481f Mon Sep 17 00:00:00 2001 From: Dimitry Andric Date: Wed, 23 Oct 2019 17:51:42 +0000 Subject: Vendor import of stripped llvm trunk r375505, the last commit before the upstream Subversion repository was made read-only, and the LLVM project migrated to GitHub: https://llvm.org/svn/llvm-project/llvm/trunk@375505 --- lib/Remarks/YAMLRemarkParser.h | 38 +++++++++++++++++++++++++++++++------- 1 file changed, 31 insertions(+), 7 deletions(-) (limited to 'lib/Remarks/YAMLRemarkParser.h') 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 StrTab; + Optional 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 SeparateBuf; - YAMLRemarkParser(StringRef Buf, - Optional StrTab = None); + YAMLRemarkParser(StringRef Buf); Expected> 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 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 parseKey(yaml::KeyValueNode &Node); /// Parse one value to a string. - Expected parseStr(yaml::KeyValueNode &Node); + virtual Expected parseStr(yaml::KeyValueNode &Node); /// Parse one value to an unsigned. Expected parseUnsigned(yaml::KeyValueNode &Node); /// Parse a debug location. @@ -90,6 +94,26 @@ private: /// Parse an argument. Expected 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 parseStr(yaml::KeyValueNode &Node) override; +}; + +Expected> +createYAMLParserFromMeta(StringRef Buf, + Optional StrTab = None, + Optional ExternalFilePrependPath = None); + } // end namespace remarks } // end namespace llvm -- cgit v1.2.3