return ParseMDNodeID(N);
}
+namespace {
+
+/// Structure to represent an optional metadata field.
+template <class FieldTy> struct MDFieldImpl {
+ typedef MDFieldImpl ImplTy;
+ FieldTy Val;
+ bool Seen;
+
+ void assign(FieldTy Val) {
+ Seen = true;
+ this->Val = std::move(Val);
+ }
+
+ explicit MDFieldImpl(FieldTy Default)
+ : Val(std::move(Default)), Seen(false) {}
+};
+struct MDUnsignedField : public MDFieldImpl<uint64_t> {
+ uint64_t Max;
+
+ MDUnsignedField(uint64_t Default = 0, uint64_t Max = UINT64_MAX)
+ : ImplTy(Default), Max(Max) {}
+};
+struct LineField : public MDUnsignedField {
+ LineField() : MDUnsignedField(0, UINT32_MAX >> 8) {}
+};
+struct ColumnField : public MDUnsignedField {
+ ColumnField() : MDUnsignedField(0, UINT16_MAX) {}
+};
+struct DwarfTagField : public MDUnsignedField {
+ DwarfTagField() : MDUnsignedField(0, ~0u >> 16) {}
+};
+struct MDField : public MDFieldImpl<Metadata *> {
+ MDField() : ImplTy(nullptr) {}
+};
+struct MDStringField : public MDFieldImpl<std::string> {
+ MDStringField() : ImplTy(std::string()) {}
+};
+struct MDFieldList : public MDFieldImpl<SmallVector<Metadata *, 4>> {
+ MDFieldList() : ImplTy(SmallVector<Metadata *, 4>()) {}
+};
+
+} // end namespace
+
+namespace llvm {
+
+template <>
bool LLParser::ParseMDField(LocTy Loc, StringRef Name,
MDUnsignedField &Result) {
if (Lex.getKind() != lltok::APSInt || Lex.getAPSIntVal().isSigned())
return false;
}
+template <>
+bool LLParser::ParseMDField(LocTy Loc, StringRef Name, LineField &Result) {
+ return ParseMDField(Loc, Name, static_cast<MDUnsignedField &>(Result));
+}
+template <>
+bool LLParser::ParseMDField(LocTy Loc, StringRef Name, ColumnField &Result) {
+ return ParseMDField(Loc, Name, static_cast<MDUnsignedField &>(Result));
+}
+
+template <>
bool LLParser::ParseMDField(LocTy Loc, StringRef Name, DwarfTagField &Result) {
if (Lex.getKind() == lltok::APSInt)
return ParseMDField(Loc, Name, static_cast<MDUnsignedField &>(Result));
return false;
}
+template <>
bool LLParser::ParseMDField(LocTy Loc, StringRef Name, MDField &Result) {
Metadata *MD;
if (ParseMetadata(MD, nullptr))
return false;
}
+template <>
bool LLParser::ParseMDField(LocTy Loc, StringRef Name, MDStringField &Result) {
std::string S;
if (ParseStringConstant(S))
return false;
}
+template <>
bool LLParser::ParseMDField(LocTy Loc, StringRef Name, MDFieldList &Result) {
SmallVector<Metadata *, 4> MDs;
if (ParseMDNodeVector(MDs))
return false;
}
+} // end namespace llvm
+
template <class ParserTy>
bool LLParser::ParseMDFieldsImplBody(ParserTy parseField) {
do {
/// ::= !MDLocation(line: 43, column: 8, scope: !5, inlinedAt: !6)
bool LLParser::ParseMDLocation(MDNode *&Result, bool IsDistinct) {
#define VISIT_MD_FIELDS(OPTIONAL, REQUIRED) \
- OPTIONAL(line, MDUnsignedField, (0, ~0u >> 8)); \
- OPTIONAL(column, MDUnsignedField, (0, ~0u >> 16)); \
+ OPTIONAL(line, LineField, ); \
+ OPTIONAL(column, ColumnField, ); \
REQUIRED(scope, MDField, ); \
OPTIONAL(inlinedAt, MDField, );
PARSE_MD_FIELDS();