[llvm] r365101 - [Remarks][NFC] Move the string table parsing out of the parser constructor
Francis Visoiu Mistrih via llvm-commits
llvm-commits at lists.llvm.org
Wed Jul 3 17:30:59 PDT 2019
Author: thegameg
Date: Wed Jul 3 17:30:58 2019
New Revision: 365101
URL: http://llvm.org/viewvc/llvm-project?rev=365101&view=rev
Log:
[Remarks][NFC] Move the string table parsing out of the parser constructor
Make the parser take an already-parsed string table.
Modified:
llvm/trunk/include/llvm/Remarks/RemarkParser.h
llvm/trunk/lib/Remarks/RemarkParser.cpp
llvm/trunk/lib/Remarks/YAMLRemarkParser.cpp
llvm/trunk/lib/Remarks/YAMLRemarkParser.h
llvm/trunk/unittests/Remarks/YAMLRemarksParsingTest.cpp
Modified: llvm/trunk/include/llvm/Remarks/RemarkParser.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Remarks/RemarkParser.h?rev=365101&r1=365100&r2=365101&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Remarks/RemarkParser.h (original)
+++ llvm/trunk/include/llvm/Remarks/RemarkParser.h Wed Jul 3 17:30:58 2019
@@ -23,6 +23,7 @@ namespace llvm {
namespace remarks {
struct ParserImpl;
+struct ParsedStringTable;
/// Parser used to parse a raw buffer to remarks::Remark objects.
struct Parser {
@@ -33,10 +34,10 @@ struct Parser {
/// This constructor should be only used for parsing YAML remarks.
Parser(StringRef Buffer);
- /// Create a parser parsing \p Buffer to Remark objects, using \p StrTabBuf as
+ /// Create a parser parsing \p Buffer to Remark objects, using \p StrTab as a
/// string table.
/// This constructor should be only used for parsing YAML remarks.
- Parser(StringRef Buffer, StringRef StrTabBuf);
+ Parser(StringRef Buffer, const ParsedStringTable &StrTab);
// Needed because ParserImpl is an incomplete type.
~Parser();
@@ -54,7 +55,7 @@ struct ParsedStringTable {
/// Collection of offsets in the buffer for each string entry.
SmallVector<size_t, 8> Offsets;
- Expected<StringRef> operator[](size_t Index);
+ Expected<StringRef> operator[](size_t Index) const;
ParsedStringTable(StringRef Buffer);
};
Modified: llvm/trunk/lib/Remarks/RemarkParser.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Remarks/RemarkParser.cpp?rev=365101&r1=365100&r2=365101&view=diff
==============================================================================
--- llvm/trunk/lib/Remarks/RemarkParser.cpp (original)
+++ llvm/trunk/lib/Remarks/RemarkParser.cpp Wed Jul 3 17:30:58 2019
@@ -22,8 +22,8 @@ using namespace llvm::remarks;
Parser::Parser(StringRef Buf) : Impl(llvm::make_unique<YAMLParserImpl>(Buf)) {}
-Parser::Parser(StringRef Buf, StringRef StrTabBuf)
- : Impl(llvm::make_unique<YAMLParserImpl>(Buf, StrTabBuf)) {}
+Parser::Parser(StringRef Buf, const ParsedStringTable &StrTab)
+ : Impl(llvm::make_unique<YAMLParserImpl>(Buf, &StrTab)) {}
Parser::~Parser() = default;
@@ -69,7 +69,7 @@ ParsedStringTable::ParsedStringTable(Str
}
}
-Expected<StringRef> ParsedStringTable::operator[](size_t Index) {
+Expected<StringRef> ParsedStringTable::operator[](size_t Index) const {
if (Index >= Offsets.size())
return createStringError(
std::make_error_code(std::errc::invalid_argument),
Modified: llvm/trunk/lib/Remarks/YAMLRemarkParser.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Remarks/YAMLRemarkParser.cpp?rev=365101&r1=365100&r2=365101&view=diff
==============================================================================
--- llvm/trunk/lib/Remarks/YAMLRemarkParser.cpp (original)
+++ llvm/trunk/lib/Remarks/YAMLRemarkParser.cpp Wed Jul 3 17:30:58 2019
@@ -42,7 +42,7 @@ Error YAMLRemarkParser::parseStr(T &Resu
unsigned StrID = 0;
if (Error E = parseUnsigned(StrID, Node))
return E;
- if (Expected<StringRef> Str = (*StrTab)[StrID])
+ if (Expected<StringRef> Str = (**StrTab)[StrID])
Tmp = *Str;
else
return Str.takeError();
Modified: llvm/trunk/lib/Remarks/YAMLRemarkParser.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Remarks/YAMLRemarkParser.h?rev=365101&r1=365100&r2=365101&view=diff
==============================================================================
--- llvm/trunk/lib/Remarks/YAMLRemarkParser.h (original)
+++ llvm/trunk/lib/Remarks/YAMLRemarkParser.h Wed Jul 3 17:30:58 2019
@@ -40,7 +40,7 @@ struct YAMLRemarkParser {
/// Temporary parsing buffer for the arguments.
SmallVector<Argument, 8> TmpArgs;
/// The string table used for parsing strings.
- Optional<ParsedStringTable> StrTab;
+ Optional<const ParsedStringTable *> StrTab;
/// The state used by the parser to parse a remark entry. Invalidated with
/// every call to `parseYAMLElement`.
struct ParseState {
@@ -59,13 +59,11 @@ struct YAMLRemarkParser {
/// not be containing any value.
Optional<ParseState> State;
- YAMLRemarkParser(StringRef Buf, Optional<StringRef> StrTabBuf = None)
+ YAMLRemarkParser(StringRef Buf,
+ Optional<const ParsedStringTable *> StrTab = None)
: SM(), Stream(Buf, SM), ErrorString(), ErrorStream(ErrorString),
- TmpArgs(), StrTab() {
+ TmpArgs(), StrTab(StrTab) {
SM.setDiagHandler(YAMLRemarkParser::HandleDiagnostic, this);
-
- if (StrTabBuf)
- StrTab.emplace(*StrTabBuf);
}
/// Parse a YAML element.
@@ -127,8 +125,9 @@ struct YAMLParserImpl : public ParserImp
/// Set to `true` if we had any errors during parsing.
bool HasErrors = false;
- YAMLParserImpl(StringRef Buf, Optional<StringRef> StrTabBuf = None)
- : ParserImpl{ParserImpl::Kind::YAML}, YAMLParser(Buf, StrTabBuf),
+ YAMLParserImpl(StringRef Buf,
+ Optional<const ParsedStringTable *> StrTab = None)
+ : ParserImpl{ParserImpl::Kind::YAML}, YAMLParser(Buf, StrTab),
YAMLIt(YAMLParser.Stream.begin()), HasErrors(false) {}
static bool classof(const ParserImpl *PI) {
Modified: llvm/trunk/unittests/Remarks/YAMLRemarksParsingTest.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/unittests/Remarks/YAMLRemarksParsingTest.cpp?rev=365101&r1=365100&r2=365101&view=diff
==============================================================================
--- llvm/trunk/unittests/Remarks/YAMLRemarksParsingTest.cpp (original)
+++ llvm/trunk/unittests/Remarks/YAMLRemarksParsingTest.cpp Wed Jul 3 17:30:58 2019
@@ -515,7 +515,8 @@ TEST(YAMLRemarks, ContentsStrTab) {
"unavailable",
115);
- remarks::Parser Parser(Buf, StrTabBuf);
+ remarks::ParsedStringTable StrTab(StrTabBuf);
+ remarks::Parser Parser(Buf, StrTab);
Expected<const remarks::Remark *> RemarkOrErr = Parser.getNext();
EXPECT_FALSE(errorToBool(RemarkOrErr.takeError()));
EXPECT_TRUE(*RemarkOrErr != nullptr);
@@ -582,7 +583,8 @@ TEST(YAMLRemarks, ParsingBadStringTableI
StringRef StrTabBuf = StringRef("inline");
- remarks::Parser Parser(Buf, StrTabBuf);
+ remarks::ParsedStringTable StrTab(StrTabBuf);
+ remarks::Parser Parser(Buf, StrTab);
Expected<const remarks::Remark *> Remark = Parser.getNext();
EXPECT_FALSE(Remark); // Expect an error here.
More information about the llvm-commits
mailing list