[llvm] 880e875 - [demangler][NFC] Tweak legacy uuidof handling
Nathan Sidwell via llvm-commits
llvm-commits at lists.llvm.org
Mon Feb 14 04:12:35 PST 2022
Author: Nathan Sidwell
Date: 2022-02-14T04:00:49-08:00
New Revision: 880e87580a219996f96ebf2cc9be9740f1a99a4c
URL: https://github.com/llvm/llvm-project/commit/880e87580a219996f96ebf2cc9be9740f1a99a4c
DIFF: https://github.com/llvm/llvm-project/commit/880e87580a219996f96ebf2cc9be9740f1a99a4c.diff
LOG: [demangler][NFC] Tweak legacy uuidof handling
We have to special-case 'u 8__uuidof [tz]' demangling for legacy
support. That handling is a little duplicative.
* It seems better to just push the single expected node.
* We can also use 'consumeIf' rather than open-coding the peeking and increment.
* We don't need the numLeft < 2 check, as if there are few than that
other paths will end up with detecting the error.
FWIW This simplifies a future change adding operator precedence.
Reviewed By: ChuanqiXu
Differential Revision: https://reviews.llvm.org/D119543
Added:
Modified:
libcxxabi/src/demangle/ItaniumDemangle.h
llvm/include/llvm/Demangle/ItaniumDemangle.h
Removed:
################################################################################
diff --git a/libcxxabi/src/demangle/ItaniumDemangle.h b/libcxxabi/src/demangle/ItaniumDemangle.h
index 7d28f4da87c1..a8d96fd2a9fd 100644
--- a/libcxxabi/src/demangle/ItaniumDemangle.h
+++ b/libcxxabi/src/demangle/ItaniumDemangle.h
@@ -5032,30 +5032,29 @@ Node *AbstractManglingParser<Derived, Alloc>::parseExpr() {
// interpreted as <type> node 'short' or 'ellipsis'. However, neither
// __uuidof(short) nor __uuidof(...) can actually appear, so there is no
// actual conflict here.
+ bool IsUUID = false;
+ Node *UUID = nullptr;
if (Name->getBaseName() == "__uuidof") {
- if (numLeft() < 2)
- return nullptr;
- if (*First == 't') {
- ++First;
- Node *Ty = getDerived().parseType();
- if (!Ty)
- return nullptr;
- return make<CallExpr>(Name, makeNodeArray(&Ty, &Ty + 1));
- }
- if (*First == 'z') {
- ++First;
- Node *Ex = getDerived().parseExpr();
- if (!Ex)
- return nullptr;
- return make<CallExpr>(Name, makeNodeArray(&Ex, &Ex + 1));
+ if (consumeIf('t')) {
+ UUID = getDerived().parseType();
+ IsUUID = true;
+ } else if (consumeIf('z')) {
+ UUID = getDerived().parseExpr();
+ IsUUID = true;
}
}
size_t ExprsBegin = Names.size();
- while (!consumeIf('E')) {
- Node *E = getDerived().parseTemplateArg();
- if (E == nullptr)
- return E;
- Names.push_back(E);
+ if (IsUUID) {
+ if (UUID == nullptr)
+ return nullptr;
+ Names.push_back(UUID);
+ } else {
+ while (!consumeIf('E')) {
+ Node *E = getDerived().parseTemplateArg();
+ if (E == nullptr)
+ return E;
+ Names.push_back(E);
+ }
}
return make<CallExpr>(Name, popTrailingNodeArray(ExprsBegin));
}
diff --git a/llvm/include/llvm/Demangle/ItaniumDemangle.h b/llvm/include/llvm/Demangle/ItaniumDemangle.h
index 144f65446b0e..de0a53beecac 100644
--- a/llvm/include/llvm/Demangle/ItaniumDemangle.h
+++ b/llvm/include/llvm/Demangle/ItaniumDemangle.h
@@ -5032,30 +5032,29 @@ Node *AbstractManglingParser<Derived, Alloc>::parseExpr() {
// interpreted as <type> node 'short' or 'ellipsis'. However, neither
// __uuidof(short) nor __uuidof(...) can actually appear, so there is no
// actual conflict here.
+ bool IsUUID = false;
+ Node *UUID = nullptr;
if (Name->getBaseName() == "__uuidof") {
- if (numLeft() < 2)
- return nullptr;
- if (*First == 't') {
- ++First;
- Node *Ty = getDerived().parseType();
- if (!Ty)
- return nullptr;
- return make<CallExpr>(Name, makeNodeArray(&Ty, &Ty + 1));
- }
- if (*First == 'z') {
- ++First;
- Node *Ex = getDerived().parseExpr();
- if (!Ex)
- return nullptr;
- return make<CallExpr>(Name, makeNodeArray(&Ex, &Ex + 1));
+ if (consumeIf('t')) {
+ UUID = getDerived().parseType();
+ IsUUID = true;
+ } else if (consumeIf('z')) {
+ UUID = getDerived().parseExpr();
+ IsUUID = true;
}
}
size_t ExprsBegin = Names.size();
- while (!consumeIf('E')) {
- Node *E = getDerived().parseTemplateArg();
- if (E == nullptr)
- return E;
- Names.push_back(E);
+ if (IsUUID) {
+ if (UUID == nullptr)
+ return nullptr;
+ Names.push_back(UUID);
+ } else {
+ while (!consumeIf('E')) {
+ Node *E = getDerived().parseTemplateArg();
+ if (E == nullptr)
+ return E;
+ Names.push_back(E);
+ }
}
return make<CallExpr>(Name, popTrailingNodeArray(ExprsBegin));
}
More information about the llvm-commits
mailing list