namespace remarks {
struct ParserImpl;
+struct ParsedStringTable;
/// Parser used to parse a raw buffer to remarks::Remark objects.
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();
/// 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);
};
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;
}
}
-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),
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();
/// 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 {
/// 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.
/// 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) {
"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);
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.