From c96090f316e06cb1b4a4bb014ab9cc80142bc172 Mon Sep 17 00:00:00 2001 From: Deadlocklogic Date: Sun, 31 Dec 2023 04:51:27 +0200 Subject: [PATCH] Parser.cpp: refactor unused function ResolveTypeLoc + implement --- src/CppParser/Parser.cpp | 93 ++++++++++++++-------------------------- 1 file changed, 32 insertions(+), 61 deletions(-) diff --git a/src/CppParser/Parser.cpp b/src/CppParser/Parser.cpp index 379a1b8c9..f05f9815b 100644 --- a/src/CppParser/Parser.cpp +++ b/src/CppParser/Parser.cpp @@ -2162,34 +2162,46 @@ static PrimitiveType WalkBuiltinType(const clang::BuiltinType* Builtin) //-----------------------------------// -clang::TypeLoc ResolveTypeLoc(clang::TypeLoc TL, clang::TypeLoc::TypeLocClass Class) +clang::TypeLoc ResolveTypeLoc(clang::TypeLoc TL, bool isRecursive = true, const std::vector& Classes = {}) { using namespace clang; auto TypeLocClass = TL.getTypeLocClass(); - if (TypeLocClass == Class) + if (std::find(Classes.begin(), Classes.end(), TypeLocClass) != Classes.end()) { return TL; } - if (TypeLocClass == TypeLoc::Qualified) + else if (TypeLocClass == TypeLoc::Qualified) { auto UTL = TL.getUnqualifiedLoc(); TL = UTL; + if (isRecursive) + { + return ResolveTypeLoc(TL, isRecursive, Classes); + } } else if (TypeLocClass == TypeLoc::Elaborated) { auto ETL = TL.getAs(); auto ITL = ETL.getNextTypeLoc(); TL = ITL; + if (isRecursive) + { + return ResolveTypeLoc(TL, isRecursive, Classes); + } } - else if (TypeLocClass == TypeLoc::Paren) + else if (!Classes.empty()) { - auto PTL = TL.getAs(); - TL = PTL.getNextTypeLoc(); + auto ITL = TL.getNextTypeLoc(); + TL = ITL; + if (isRecursive) + { + return ResolveTypeLoc(TL, isRecursive, Classes); + } } - assert(TL.getTypeLocClass() == Class); + assert(Classes.empty() || std::find(Classes.begin(), Classes.end(), TL.getTypeLocClass()) != Classes.end()); return TL; } @@ -2642,28 +2654,16 @@ Type* Parser::WalkType(clang::QualType QualType, const clang::TypeLoc* TL, if (LocValid) { - TypeLoc UTL, ETL, ITL; - auto TypeLocClass = TL->getTypeLocClass(); - if (TypeLocClass == TypeLoc::Qualified) - { - UTL = TL->getUnqualifiedLoc(); - TL = &UTL; - } - else if (TypeLocClass == TypeLoc::Elaborated) - { - ETL = TL->getAs(); - ITL = ETL.getNextTypeLoc(); - TL = &ITL; - } + TypeLoc resolvedTypeLoc = ResolveTypeLoc(*TL, true, { TypeLoc::TemplateSpecialization , TypeLoc::DependentTemplateSpecialization }); - if (TL->getTypeLocClass() == TypeLoc::DependentTemplateSpecialization) + if (resolvedTypeLoc.getTypeLocClass() == TypeLoc::DependentTemplateSpecialization) { - DependentTemplateSpecializationTypeLoc TSpecTL = TL->getAs(); + DependentTemplateSpecializationTypeLoc TSpecTL = resolvedTypeLoc.getAs(); TST->Arguments = WalkTemplateArgumentList(&TArgs, &TSpecTL); } - else if (TL->getTypeLocClass() == TypeLoc::TemplateSpecialization) + else if (resolvedTypeLoc.getTypeLocClass() == TypeLoc::TemplateSpecialization) { - TemplateSpecializationTypeLoc TSpecTL = TL->getAs(); + TemplateSpecializationTypeLoc TSpecTL = resolvedTypeLoc.getAs(); TST->Arguments = WalkTemplateArgumentList(&TArgs, &TSpecTL); } else @@ -2691,28 +2691,16 @@ Type* Parser::WalkType(clang::QualType QualType, const clang::TypeLoc* TL, if (LocValid) { - TypeLoc UTL, ETL, ITL; - auto TypeLocClass = TL->getTypeLocClass(); - if (TypeLocClass == TypeLoc::Qualified) - { - UTL = TL->getUnqualifiedLoc(); - TL = &UTL; - } - else if (TypeLocClass == TypeLoc::Elaborated) - { - ETL = TL->getAs(); - ITL = ETL.getNextTypeLoc(); - TL = &ITL; - } + TypeLoc resolvedTypeLoc = ResolveTypeLoc(*TL, true, { TypeLoc::TemplateSpecialization , TypeLoc::DependentTemplateSpecialization }); - if (TL->getTypeLocClass() == TypeLoc::DependentTemplateSpecialization) + if (resolvedTypeLoc.getTypeLocClass() == TypeLoc::DependentTemplateSpecialization) { - DependentTemplateSpecializationTypeLoc TSpecTL = TL->getAs(); + DependentTemplateSpecializationTypeLoc TSpecTL = resolvedTypeLoc.getAs(); TST->Arguments = WalkTemplateArgumentList(&TArgs, &TSpecTL); } - else if (TL->getTypeLocClass() == TypeLoc::TemplateSpecialization) + else if (resolvedTypeLoc.getTypeLocClass() == TypeLoc::TemplateSpecialization) { - TemplateSpecializationTypeLoc TSpecTL = TL->getAs(); + TemplateSpecializationTypeLoc TSpecTL = resolvedTypeLoc.getAs(); TST->Arguments = WalkTemplateArgumentList(&TArgs, &TSpecTL); } else @@ -2741,27 +2729,10 @@ Type* Parser::WalkType(clang::QualType QualType, const clang::TypeLoc* TL, if (LocValid) { - auto TypeLocClass = TL->getTypeLocClass(); - if (TypeLocClass == TypeLoc::Qualified) - { - UTL = TL->getUnqualifiedLoc(); - TL = &UTL; - } - else if (TypeLocClass == TypeLoc::Elaborated) - { - ETL = TL->getAs(); - ITL = ETL.getNextTypeLoc(); - TL = &ITL; - } - - while (TL->getTypeLocClass() != TypeLoc::TemplateTypeParm) - { - Next = TL->getNextTypeLoc(); - TL = &Next; - } + TypeLoc resolvedTypeLoc = ResolveTypeLoc(*TL, true, { TypeLoc::TemplateTypeParm }); - assert(TL->getTypeLocClass() == TypeLoc::TemplateTypeParm); - auto TTTL = TL->getAs(); + assert(resolvedTypeLoc.getTypeLocClass() == TypeLoc::TemplateTypeParm); + auto TTTL = resolvedTypeLoc.getAs(); TPT->parameter = WalkTypeTemplateParameter(TTTL.getDecl()); }