[demangler] Fix demangling of enumerators with negative values

rdar://27527445
This commit is contained in:
Erik Pilkington 2020-05-13 14:13:37 -04:00
parent fcfb3170a7
commit 15426b2161
3 changed files with 28 additions and 18 deletions

View File

@ -98,7 +98,7 @@
X(BoolExpr) \
X(StringLiteral) \
X(LambdaExpr) \
X(IntegerCastExpr) \
X(EnumLiteral) \
X(IntegerLiteral) \
X(FloatLiteral) \
X(DoubleLiteral) \
@ -2036,22 +2036,26 @@ public:
}
};
class IntegerCastExpr : public Node {
class EnumLiteral : public Node {
// ty(integer)
const Node *Ty;
StringView Integer;
public:
IntegerCastExpr(const Node *Ty_, StringView Integer_)
: Node(KIntegerCastExpr), Ty(Ty_), Integer(Integer_) {}
EnumLiteral(const Node *Ty_, StringView Integer_)
: Node(KEnumLiteral), Ty(Ty_), Integer(Integer_) {}
template<typename Fn> void match(Fn F) const { F(Ty, Integer); }
void printLeft(OutputStream &S) const override {
S += "(";
S << "(";
Ty->print(S);
S += ")";
S += Integer;
S << ")";
if (Integer[0] == 'n')
S << "-" << Integer.dropFront(1);
else
S << Integer;
}
};
@ -4270,12 +4274,12 @@ Node *AbstractManglingParser<Derived, Alloc>::parseExprPrimary() {
Node *T = getDerived().parseType();
if (T == nullptr)
return nullptr;
StringView N = parseNumber();
StringView N = parseNumber(/*AllowNegative=*/true);
if (N.empty())
return nullptr;
if (!consumeIf('E'))
return nullptr;
return make<IntegerCastExpr>(T, N);
return make<EnumLiteral>(T, N);
}
}
}

View File

@ -29792,6 +29792,8 @@ const char* cases[][2] =
// "auto inline_func()::'lambda'<int, int>(int, int) const"
{"_ZZ11inline_funcvENKUlTyTyT_T0_E_clIiiEEDaS_S0_", "auto inline_func()::'lambda'<typename $T, typename $T0>($T, $T0)::operator()<int, int>($T, $T0) const"},
{"_ZZ11inline_funcvENKUlTyTyT_T1_T0_E_clIiiiEEDaS_S0_S1_", "auto inline_func()::'lambda'<typename $T, typename $T0>($T, auto, $T0)::operator()<int, int, int>($T, auto, $T0) const"},
{"_Z1fIL4Enumn1EEvv", "void f<(Enum)-1>()"},
};
const unsigned N = sizeof(cases) / sizeof(cases[0]);

View File

@ -98,7 +98,7 @@
X(BoolExpr) \
X(StringLiteral) \
X(LambdaExpr) \
X(IntegerCastExpr) \
X(EnumLiteral) \
X(IntegerLiteral) \
X(FloatLiteral) \
X(DoubleLiteral) \
@ -2036,22 +2036,26 @@ public:
}
};
class IntegerCastExpr : public Node {
class EnumLiteral : public Node {
// ty(integer)
const Node *Ty;
StringView Integer;
public:
IntegerCastExpr(const Node *Ty_, StringView Integer_)
: Node(KIntegerCastExpr), Ty(Ty_), Integer(Integer_) {}
EnumLiteral(const Node *Ty_, StringView Integer_)
: Node(KEnumLiteral), Ty(Ty_), Integer(Integer_) {}
template<typename Fn> void match(Fn F) const { F(Ty, Integer); }
void printLeft(OutputStream &S) const override {
S += "(";
S << "(";
Ty->print(S);
S += ")";
S += Integer;
S << ")";
if (Integer[0] == 'n')
S << "-" << Integer.dropFront(1);
else
S << Integer;
}
};
@ -4270,12 +4274,12 @@ Node *AbstractManglingParser<Derived, Alloc>::parseExprPrimary() {
Node *T = getDerived().parseType();
if (T == nullptr)
return nullptr;
StringView N = parseNumber();
StringView N = parseNumber(/*AllowNegative=*/true);
if (N.empty())
return nullptr;
if (!consumeIf('E'))
return nullptr;
return make<IntegerCastExpr>(T, N);
return make<EnumLiteral>(T, N);
}
}
}