if (look() == 'Z')
return getDerived().parseLocalName(State);
- // ::= <unscoped-template-name> <template-args>
- if (look() == 'S' && look(1) != 't') {
- Node *S = getDerived().parseSubstitution();
- if (S == nullptr)
- return nullptr;
- if (look() != 'I')
- return nullptr;
- Node *TA = getDerived().parseTemplateArgs(State != nullptr);
- if (TA == nullptr)
- return nullptr;
- if (State) State->EndsWithTemplateArgs = true;
- return make<NameWithTemplateArgs>(S, TA);
+ Node *Result = nullptr;
+ bool IsSubst = look() == 'S' && look(1) != 't';
+ if (IsSubst) {
+ // A substitution must lead to:
+ // ::= <unscoped-template-name> <template-args>
+ Result = getDerived().parseSubstitution();
+ } else {
+ // An unscoped name can be one of:
+ // ::= <unscoped-name>
+ // ::= <unscoped-template-name> <template-args>
+ Result = getDerived().parseUnscopedName(State);
}
-
- Node *N = getDerived().parseUnscopedName(State);
- if (N == nullptr)
+ if (Result == nullptr)
return nullptr;
- // ::= <unscoped-template-name> <template-args>
+
if (look() == 'I') {
- Subs.push_back(N);
+ // ::= <unscoped-template-name> <template-args>
+ if (!IsSubst)
+ // An unscoped-template-name is substitutable.
+ Subs.push_back(Result);
Node *TA = getDerived().parseTemplateArgs(State != nullptr);
if (TA == nullptr)
return nullptr;
- if (State) State->EndsWithTemplateArgs = true;
- return make<NameWithTemplateArgs>(N, TA);
+ if (State)
+ State->EndsWithTemplateArgs = true;
+ Result = make<NameWithTemplateArgs>(Result, TA);
+ } else if (IsSubst) {
+ // The substitution case must be followed by <template-args>.
+ return nullptr;
}
- // ::= <unscoped-name>
- return N;
+
+ return Result;
}
// <local-name> := Z <function encoding> E <entity name> [<discriminator>]
template <typename Derived, typename Alloc>
Node *
AbstractManglingParser<Derived, Alloc>::parseUnscopedName(NameState *State) {
- if (consumeIf("StL") || consumeIf("St")) {
- Node *R = getDerived().parseUnqualifiedName(State);
- if (R == nullptr)
- return nullptr;
- return make<StdQualifiedName>(R);
- }
- return getDerived().parseUnqualifiedName(State);
+ bool IsStd = consumeIf("St");
+ if (IsStd)
+ consumeIf('L');
+
+ Node *Result = getDerived().parseUnqualifiedName(State);
+ if (Result == nullptr)
+ return nullptr;
+ if (IsStd)
+ Result = make<StdQualifiedName>(Result);
+
+ return Result;
}
// <unqualified-name> ::= <operator-name> [abi-tags]
}
// ::= <substitution> # See Compression below
case 'S': {
- if (look(1) && look(1) != 't') {
- Node *Sub = getDerived().parseSubstitution();
- if (Sub == nullptr)
+ if (look(1) != 't') {
+ Result = getDerived().parseSubstitution();
+ if (Result == nullptr)
return nullptr;
// Sub could be either of:
Node *TA = getDerived().parseTemplateArgs();
if (TA == nullptr)
return nullptr;
- Result = make<NameWithTemplateArgs>(Sub, TA);
- break;
+ Result = make<NameWithTemplateArgs>(Result, TA);
+ } else {
+ // If all we parsed was a substitution, don't re-insert into the
+ // substitution table.
+ return Result;
}
-
- // If all we parsed was a substitution, don't re-insert into the
- // substitution table.
- return Sub;
+ break;
}
DEMANGLE_FALLTHROUGH;
}
// This should be invalid, but it is currently not recognized as such
// See https://llvm.org/PR51407
{"_Zcv1BIRT_EIS1_E", "operator B<><>"},
+
+ {"_Z3TPLIiET_S0_", "int TPL<int>(int)"},
};
const unsigned N = sizeof(cases) / sizeof(cases[0]);
if (look() == 'Z')
return getDerived().parseLocalName(State);
- // ::= <unscoped-template-name> <template-args>
- if (look() == 'S' && look(1) != 't') {
- Node *S = getDerived().parseSubstitution();
- if (S == nullptr)
- return nullptr;
- if (look() != 'I')
- return nullptr;
- Node *TA = getDerived().parseTemplateArgs(State != nullptr);
- if (TA == nullptr)
- return nullptr;
- if (State) State->EndsWithTemplateArgs = true;
- return make<NameWithTemplateArgs>(S, TA);
+ Node *Result = nullptr;
+ bool IsSubst = look() == 'S' && look(1) != 't';
+ if (IsSubst) {
+ // A substitution must lead to:
+ // ::= <unscoped-template-name> <template-args>
+ Result = getDerived().parseSubstitution();
+ } else {
+ // An unscoped name can be one of:
+ // ::= <unscoped-name>
+ // ::= <unscoped-template-name> <template-args>
+ Result = getDerived().parseUnscopedName(State);
}
-
- Node *N = getDerived().parseUnscopedName(State);
- if (N == nullptr)
+ if (Result == nullptr)
return nullptr;
- // ::= <unscoped-template-name> <template-args>
+
if (look() == 'I') {
- Subs.push_back(N);
+ // ::= <unscoped-template-name> <template-args>
+ if (!IsSubst)
+ // An unscoped-template-name is substitutable.
+ Subs.push_back(Result);
Node *TA = getDerived().parseTemplateArgs(State != nullptr);
if (TA == nullptr)
return nullptr;
- if (State) State->EndsWithTemplateArgs = true;
- return make<NameWithTemplateArgs>(N, TA);
+ if (State)
+ State->EndsWithTemplateArgs = true;
+ Result = make<NameWithTemplateArgs>(Result, TA);
+ } else if (IsSubst) {
+ // The substitution case must be followed by <template-args>.
+ return nullptr;
}
- // ::= <unscoped-name>
- return N;
+
+ return Result;
}
// <local-name> := Z <function encoding> E <entity name> [<discriminator>]
template <typename Derived, typename Alloc>
Node *
AbstractManglingParser<Derived, Alloc>::parseUnscopedName(NameState *State) {
- if (consumeIf("StL") || consumeIf("St")) {
- Node *R = getDerived().parseUnqualifiedName(State);
- if (R == nullptr)
- return nullptr;
- return make<StdQualifiedName>(R);
- }
- return getDerived().parseUnqualifiedName(State);
+ bool IsStd = consumeIf("St");
+ if (IsStd)
+ consumeIf('L');
+
+ Node *Result = getDerived().parseUnqualifiedName(State);
+ if (Result == nullptr)
+ return nullptr;
+ if (IsStd)
+ Result = make<StdQualifiedName>(Result);
+
+ return Result;
}
// <unqualified-name> ::= <operator-name> [abi-tags]
}
// ::= <substitution> # See Compression below
case 'S': {
- if (look(1) && look(1) != 't') {
- Node *Sub = getDerived().parseSubstitution();
- if (Sub == nullptr)
+ if (look(1) != 't') {
+ Result = getDerived().parseSubstitution();
+ if (Result == nullptr)
return nullptr;
// Sub could be either of:
Node *TA = getDerived().parseTemplateArgs();
if (TA == nullptr)
return nullptr;
- Result = make<NameWithTemplateArgs>(Sub, TA);
- break;
+ Result = make<NameWithTemplateArgs>(Result, TA);
+ } else {
+ // If all we parsed was a substitution, don't re-insert into the
+ // substitution table.
+ return Result;
}
-
- // If all we parsed was a substitution, don't re-insert into the
- // substitution table.
- return Sub;
+ break;
}
DEMANGLE_FALLTHROUGH;
}