Index: llvm/trunk/include/llvm/Demangle/ItaniumDemangle.h =================================================================== --- llvm/trunk/include/llvm/Demangle/ItaniumDemangle.h +++ llvm/trunk/include/llvm/Demangle/ItaniumDemangle.h @@ -2134,8 +2134,7 @@ } }; -template -struct Db { +template struct AbstractManglingParser { const char *First; const char *Last; @@ -2167,7 +2166,10 @@ Alloc ASTAllocator; - Db(const char *First_, const char *Last_) : First(First_), Last(Last_) {} + AbstractManglingParser(const char *First_, const char *Last_) + : First(First_), Last(Last_) {} + + Derived &getDerived() { return static_cast(*this); } void reset(const char *First_, const char *Last_) { First = First_; @@ -2274,7 +2276,7 @@ FunctionRefQual ReferenceQualifier = FrefQualNone; size_t ForwardTemplateRefsBegin; - NameState(Db *Enclosing) + NameState(AbstractManglingParser *Enclosing) : ForwardTemplateRefsBegin(Enclosing->ForwardTemplateRefs.size()) {} }; @@ -2324,35 +2326,36 @@ // // ::= // ::= -template Node *Db::parseName(NameState *State) { +template +Node *AbstractManglingParser::parseName(NameState *State) { consumeIf('L'); // extension if (look() == 'N') - return parseNestedName(State); + return getDerived().parseNestedName(State); if (look() == 'Z') - return parseLocalName(State); + return getDerived().parseLocalName(State); // ::= if (look() == 'S' && look(1) != 't') { - Node *S = parseSubstitution(); + Node *S = getDerived().parseSubstitution(); if (S == nullptr) return nullptr; if (look() != 'I') return nullptr; - Node *TA = parseTemplateArgs(State != nullptr); + Node *TA = getDerived().parseTemplateArgs(State != nullptr); if (TA == nullptr) return nullptr; if (State) State->EndsWithTemplateArgs = true; return make(S, TA); } - Node *N = parseUnscopedName(State); + Node *N = getDerived().parseUnscopedName(State); if (N == nullptr) return nullptr; // ::= if (look() == 'I') { Subs.push_back(N); - Node *TA = parseTemplateArgs(State != nullptr); + Node *TA = getDerived().parseTemplateArgs(State != nullptr); if (TA == nullptr) return nullptr; if (State) State->EndsWithTemplateArgs = true; @@ -2365,10 +2368,11 @@ // := Z E [] // := Z E s [] // := Z Ed [ ] _ -template Node *Db::parseLocalName(NameState *State) { +template +Node *AbstractManglingParser::parseLocalName(NameState *State) { if (!consumeIf('Z')) return nullptr; - Node *Encoding = parseEncoding(); + Node *Encoding = getDerived().parseEncoding(); if (Encoding == nullptr || !consumeIf('E')) return nullptr; @@ -2384,13 +2388,13 @@ parseNumber(true); if (!consumeIf('_')) return nullptr; - Node *N = parseName(State); + Node *N = getDerived().parseName(State); if (N == nullptr) return nullptr; return make(Encoding, N); } - Node *Entity = parseName(State); + Node *Entity = getDerived().parseName(State); if (Entity == nullptr) return nullptr; First = parse_discriminator(First, Last); @@ -2400,14 +2404,16 @@ // ::= // ::= St # ::std:: // extension ::= StL -template Node *Db::parseUnscopedName(NameState *State) { - if (consumeIf("StL") || consumeIf("St")) { - Node *R = parseUnqualifiedName(State); - if (R == nullptr) - return nullptr; - return make(R); - } - return parseUnqualifiedName(State); +template +Node * +AbstractManglingParser::parseUnscopedName(NameState *State) { + if (consumeIf("StL") || consumeIf("St")) { + Node *R = getDerived().parseUnqualifiedName(State); + if (R == nullptr) + return nullptr; + return make(R); + } + return getDerived().parseUnqualifiedName(State); } // ::= [abi-tags] @@ -2415,27 +2421,28 @@ // ::= // ::= // ::= DC + E # structured binding declaration -template -Node *Db::parseUnqualifiedName(NameState *State) { +template +Node * +AbstractManglingParser::parseUnqualifiedName(NameState *State) { // s are special-cased in parseNestedName(). Node *Result; if (look() == 'U') - Result = parseUnnamedTypeName(State); + Result = getDerived().parseUnnamedTypeName(State); else if (look() >= '1' && look() <= '9') - Result = parseSourceName(State); + Result = getDerived().parseSourceName(State); else if (consumeIf("DC")) { size_t BindingsBegin = Names.size(); do { - Node *Binding = parseSourceName(State); + Node *Binding = getDerived().parseSourceName(State); if (Binding == nullptr) return nullptr; Names.push_back(Binding); } while (!consumeIf('E')); Result = make(popTrailingNodeArray(BindingsBegin)); } else - Result = parseOperatorName(State); + Result = getDerived().parseOperatorName(State); if (Result != nullptr) - Result = parseAbiTags(Result); + Result = getDerived().parseAbiTags(Result); return Result; } @@ -2445,7 +2452,9 @@ // ::= Ul E [ ] _ // // ::= + # Parameter types or "v" if the lambda has no parameters -template Node *Db::parseUnnamedTypeName(NameState *) { +template +Node * +AbstractManglingParser::parseUnnamedTypeName(NameState *) { if (consumeIf("Ut")) { StringView Count = parseNumber(); if (!consumeIf('_')) @@ -2458,7 +2467,7 @@ if (!consumeIf("vE")) { size_t ParamsBegin = Names.size(); do { - Node *P = parseType(); + Node *P = getDerived().parseType(); if (P == nullptr) return nullptr; Names.push_back(P); @@ -2474,7 +2483,8 @@ } // ::= -template Node *Db::parseSourceName(NameState *) { +template +Node *AbstractManglingParser::parseSourceName(NameState *) { size_t Length = 0; if (parsePositiveInteger(&Length)) return nullptr; @@ -2538,7 +2548,9 @@ // ::= rS # >>= // ::= ss # <=> C++2a // ::= v # vendor extended operator -template Node *Db::parseOperatorName(NameState *State) { +template +Node * +AbstractManglingParser::parseOperatorName(NameState *State) { switch (look()) { case 'a': switch (look(1)) { @@ -2578,7 +2590,7 @@ SwapAndRestore SavePermit(PermitForwardTemplateReferences, PermitForwardTemplateReferences || State != nullptr); - Node* Ty = parseType(); + Node *Ty = getDerived().parseType(); if (Ty == nullptr) return nullptr; if (State) State->CtorDtorConversion = true; @@ -2642,7 +2654,7 @@ // ::= li # operator "" case 'i': { First += 2; - Node *SN = parseSourceName(State); + Node *SN = getDerived().parseSourceName(State); if (SN == nullptr) return nullptr; return make(SN); @@ -2763,7 +2775,7 @@ case 'v': if (std::isdigit(look(1))) { First += 2; - Node *SN = parseSourceName(State); + Node *SN = getDerived().parseSourceName(State); if (SN == nullptr) return nullptr; return make(SN); @@ -2781,8 +2793,10 @@ // ::= D1 # complete object destructor // ::= D2 # base object destructor // extension ::= D5 # ? -template -Node *Db::parseCtorDtorName(Node *&SoFar, NameState *State) { +template +Node * +AbstractManglingParser::parseCtorDtorName(Node *&SoFar, + NameState *State) { if (SoFar->getKind() == Node::KSpecialSubstitution) { auto SSK = static_cast(SoFar)->SSK; switch (SSK) { @@ -2806,7 +2820,7 @@ ++First; if (State) State->CtorDtorConversion = true; if (IsInherited) { - if (parseName(State) == nullptr) + if (getDerived().parseName(State) == nullptr) return nullptr; } return make(SoFar, false, Variant); @@ -2840,7 +2854,9 @@ // ::=