diff --git a/libcxxabi/src/demangle/ItaniumDemangle.h b/libcxxabi/src/demangle/ItaniumDemangle.h index 8d90a10aa446d6..7d28f4da87c19e 100644 --- a/libcxxabi/src/demangle/ItaniumDemangle.h +++ b/libcxxabi/src/demangle/ItaniumDemangle.h @@ -2547,7 +2547,7 @@ template struct AbstractManglingParser { Node *parseName(NameState *State = nullptr); Node *parseLocalName(NameState *State); Node *parseOperatorName(NameState *State); - Node *parseUnqualifiedName(NameState *State); + Node *parseUnqualifiedName(NameState *State, Node *Scope); Node *parseUnnamedTypeName(NameState *State); Node *parseSourceName(NameState *State); Node *parseUnscopedName(NameState *State); @@ -2659,37 +2659,33 @@ Node *AbstractManglingParser::parseLocalName(NameState *State) { template Node * AbstractManglingParser::parseUnscopedName(NameState *State) { - bool IsStd = consumeIf("St"); - consumeIf('L'); - - Node *Result = getDerived().parseUnqualifiedName(State); - if (Result == nullptr) - return nullptr; - if (IsStd) { - if (auto *Std = make("std")) - Result = make(Std, Result); - else + Node *Std = nullptr; + if (consumeIf("St")) { + Std = make("std"); + if (Std == nullptr) return nullptr; } + consumeIf('L'); - return Result; + return getDerived().parseUnqualifiedName(State, Std); } // ::= [abi-tags] -// ::= -// ::= -// ::= +// ::= [] +// ::= [] +// ::= [] // ::= DC + E # structured binding declaration template Node * -AbstractManglingParser::parseUnqualifiedName(NameState *State) { - // s are special-cased in parseNestedName(). +AbstractManglingParser::parseUnqualifiedName(NameState *State, + Node *Scope) { Node *Result; if (look() == 'U') Result = getDerived().parseUnnamedTypeName(State); else if (look() >= '1' && look() <= '9') Result = getDerived().parseSourceName(State); else if (consumeIf("DC")) { + // Structured binding size_t BindingsBegin = Names.size(); do { Node *Binding = getDerived().parseSourceName(State); @@ -2698,10 +2694,18 @@ AbstractManglingParser::parseUnqualifiedName(NameState *State) { Names.push_back(Binding); } while (!consumeIf('E')); Result = make(popTrailingNodeArray(BindingsBegin)); - } else + } else if (look() == 'C' || look() == 'D') { + // A . + if (Scope == nullptr) + return nullptr; + Result = getDerived().parseCtorDtorName(Scope, State); + } else { Result = getDerived().parseOperatorName(State); + } if (Result != nullptr) Result = getDerived().parseAbiTags(Result); + if (Result != nullptr && Scope != nullptr) + Result = make(Scope, Result); return Result; } @@ -3237,24 +3241,8 @@ AbstractManglingParser::parseNestedName(NameState *State) { return nullptr; continue; // Do not push a new substitution. } else { - Node *N = nullptr; - if (look() == 'C' || (look() == 'D' && look(1) != 'C')) { - // An that's actually a . - if (SoFar == nullptr) - return nullptr; - N = getDerived().parseCtorDtorName(SoFar, State); - if (N != nullptr) - N = getDerived().parseAbiTags(N); - } else { - // ::= - N = getDerived().parseUnqualifiedName(State); - } - if (N == nullptr) - return nullptr; - if (SoFar) - SoFar = make(SoFar, N); - else - SoFar = N; + // ::= [] + SoFar = getDerived().parseUnqualifiedName(State, SoFar); } if (SoFar == nullptr) return nullptr; diff --git a/llvm/include/llvm/Demangle/ItaniumDemangle.h b/llvm/include/llvm/Demangle/ItaniumDemangle.h index dbd93cda871512..144f65446b0e5b 100644 --- a/llvm/include/llvm/Demangle/ItaniumDemangle.h +++ b/llvm/include/llvm/Demangle/ItaniumDemangle.h @@ -2547,7 +2547,7 @@ template struct AbstractManglingParser { Node *parseName(NameState *State = nullptr); Node *parseLocalName(NameState *State); Node *parseOperatorName(NameState *State); - Node *parseUnqualifiedName(NameState *State); + Node *parseUnqualifiedName(NameState *State, Node *Scope); Node *parseUnnamedTypeName(NameState *State); Node *parseSourceName(NameState *State); Node *parseUnscopedName(NameState *State); @@ -2659,37 +2659,33 @@ Node *AbstractManglingParser::parseLocalName(NameState *State) { template Node * AbstractManglingParser::parseUnscopedName(NameState *State) { - bool IsStd = consumeIf("St"); - consumeIf('L'); - - Node *Result = getDerived().parseUnqualifiedName(State); - if (Result == nullptr) - return nullptr; - if (IsStd) { - if (auto *Std = make("std")) - Result = make(Std, Result); - else + Node *Std = nullptr; + if (consumeIf("St")) { + Std = make("std"); + if (Std == nullptr) return nullptr; } + consumeIf('L'); - return Result; + return getDerived().parseUnqualifiedName(State, Std); } // ::= [abi-tags] -// ::= -// ::= -// ::= +// ::= [] +// ::= [] +// ::= [] // ::= DC + E # structured binding declaration template Node * -AbstractManglingParser::parseUnqualifiedName(NameState *State) { - // s are special-cased in parseNestedName(). +AbstractManglingParser::parseUnqualifiedName(NameState *State, + Node *Scope) { Node *Result; if (look() == 'U') Result = getDerived().parseUnnamedTypeName(State); else if (look() >= '1' && look() <= '9') Result = getDerived().parseSourceName(State); else if (consumeIf("DC")) { + // Structured binding size_t BindingsBegin = Names.size(); do { Node *Binding = getDerived().parseSourceName(State); @@ -2698,10 +2694,18 @@ AbstractManglingParser::parseUnqualifiedName(NameState *State) { Names.push_back(Binding); } while (!consumeIf('E')); Result = make(popTrailingNodeArray(BindingsBegin)); - } else + } else if (look() == 'C' || look() == 'D') { + // A . + if (Scope == nullptr) + return nullptr; + Result = getDerived().parseCtorDtorName(Scope, State); + } else { Result = getDerived().parseOperatorName(State); + } if (Result != nullptr) Result = getDerived().parseAbiTags(Result); + if (Result != nullptr && Scope != nullptr) + Result = make(Scope, Result); return Result; } @@ -3237,24 +3241,8 @@ AbstractManglingParser::parseNestedName(NameState *State) { return nullptr; continue; // Do not push a new substitution. } else { - Node *N = nullptr; - if (look() == 'C' || (look() == 'D' && look(1) != 'C')) { - // An that's actually a . - if (SoFar == nullptr) - return nullptr; - N = getDerived().parseCtorDtorName(SoFar, State); - if (N != nullptr) - N = getDerived().parseAbiTags(N); - } else { - // ::= - N = getDerived().parseUnqualifiedName(State); - } - if (N == nullptr) - return nullptr; - if (SoFar) - SoFar = make(SoFar, N); - else - SoFar = N; + // ::= [] + SoFar = getDerived().parseUnqualifiedName(State, SoFar); } if (SoFar == nullptr) return nullptr;