Skip to content

Commit

Permalink
Parser.cpp: refactor unused function ResolveTypeLoc + implement
Browse files Browse the repository at this point in the history
  • Loading branch information
deadlocklogic committed Dec 31, 2023
1 parent 2e1133d commit c96090f
Showing 1 changed file with 32 additions and 61 deletions.
93 changes: 32 additions & 61 deletions src/CppParser/Parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<clang::TypeLoc::TypeLocClass>& 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<ElaboratedTypeLoc>();
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<ParenTypeLoc>();
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;
}

Expand Down Expand Up @@ -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<ElaboratedTypeLoc>();
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>();
DependentTemplateSpecializationTypeLoc TSpecTL = resolvedTypeLoc.getAs<DependentTemplateSpecializationTypeLoc>();
TST->Arguments = WalkTemplateArgumentList(&TArgs, &TSpecTL);
}
else if (TL->getTypeLocClass() == TypeLoc::TemplateSpecialization)
else if (resolvedTypeLoc.getTypeLocClass() == TypeLoc::TemplateSpecialization)
{
TemplateSpecializationTypeLoc TSpecTL = TL->getAs<TemplateSpecializationTypeLoc>();
TemplateSpecializationTypeLoc TSpecTL = resolvedTypeLoc.getAs<TemplateSpecializationTypeLoc>();
TST->Arguments = WalkTemplateArgumentList(&TArgs, &TSpecTL);
}
else
Expand Down Expand Up @@ -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<ElaboratedTypeLoc>();
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>();
DependentTemplateSpecializationTypeLoc TSpecTL = resolvedTypeLoc.getAs<DependentTemplateSpecializationTypeLoc>();
TST->Arguments = WalkTemplateArgumentList(&TArgs, &TSpecTL);
}
else if (TL->getTypeLocClass() == TypeLoc::TemplateSpecialization)
else if (resolvedTypeLoc.getTypeLocClass() == TypeLoc::TemplateSpecialization)
{
TemplateSpecializationTypeLoc TSpecTL = TL->getAs<TemplateSpecializationTypeLoc>();
TemplateSpecializationTypeLoc TSpecTL = resolvedTypeLoc.getAs<TemplateSpecializationTypeLoc>();
TST->Arguments = WalkTemplateArgumentList(&TArgs, &TSpecTL);
}
else
Expand Down Expand Up @@ -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<ElaboratedTypeLoc>();
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<TemplateTypeParmTypeLoc>();
assert(resolvedTypeLoc.getTypeLocClass() == TypeLoc::TemplateTypeParm);
auto TTTL = resolvedTypeLoc.getAs<TemplateTypeParmTypeLoc>();

TPT->parameter = WalkTypeTemplateParameter(TTTL.getDecl());
}
Expand Down

0 comments on commit c96090f

Please sign in to comment.