Skip to content

Commit ec68b73

Browse files
committed
Fixed type loc parsing bug with Clang headers.
1 parent 4fcfe4e commit ec68b73

File tree

1 file changed

+45
-41
lines changed

1 file changed

+45
-41
lines changed

src/CppParser/Parser.cpp

+45-41
Original file line numberDiff line numberDiff line change
@@ -2021,7 +2021,34 @@ static PrimitiveType WalkBuiltinType(const clang::BuiltinType* Builtin)
20212021

20222022
//-----------------------------------//
20232023

2024-
clang::TypeLoc ResolveTypeLoc(clang::TypeLoc TL, clang::TypeLoc::TypeLocClass Class)
2024+
#if DEBUG
2025+
static void DumpTypeLoc(clang::TypeLoc TL, bool Recurse = false)
2026+
{
2027+
if (Recurse)
2028+
puts("");
2029+
2030+
switch(TL.getTypeLocClass())
2031+
{
2032+
case clang::TypeLoc::Qualified:
2033+
printf("Type: Qualified\n");
2034+
break;
2035+
#define ABSTRACT_TYPE(Type, Parent)
2036+
#define TYPE(Type, Parent) \
2037+
case clang::TypeLoc::Type: \
2038+
printf("Type: %s\n", #Type); \
2039+
break;
2040+
#include "clang/AST/TypeNodes.def"
2041+
}
2042+
2043+
if (!Recurse) return;
2044+
2045+
clang::TypeLoc Next = TL;
2046+
while((Next = Next.getNextTypeLoc()))
2047+
DumpTypeLoc(Next);
2048+
}
2049+
#endif
2050+
2051+
static clang::TypeLoc ResolveTypeLoc(clang::TypeLoc TL, clang::TypeLoc::TypeLocClass Class)
20252052
{
20262053
using namespace clang;
20272054

@@ -2047,8 +2074,12 @@ clang::TypeLoc ResolveTypeLoc(clang::TypeLoc TL, clang::TypeLoc::TypeLocClass Cl
20472074
auto PTL = TL.getAs<ParenTypeLoc>();
20482075
TL = PTL.getNextTypeLoc();
20492076
}
2077+
else
2078+
{
2079+
auto Next = TL.getNextTypeLoc();
2080+
TL = Next;
2081+
}
20502082

2051-
assert(TL.getTypeLocClass() == Class);
20522083
return TL;
20532084
}
20542085

@@ -2325,7 +2356,7 @@ Type* Parser::WalkType(clang::QualType QualType, const clang::TypeLoc* TL,
23252356
A->qualifiedType = GetQualifiedType(ElemTy, &Next);
23262357
A->sizeType = ArrayType::ArraySize::Constant;
23272358
A->size = AST.getConstantArrayElementCount(AT);
2328-
if (!ElemTy->isDependentType())
2359+
if (CanCheckCodeGenInfo(c->getSema(), ElemTy.getTypePtr()))
23292360
A->elementSize = (long)AST.getTypeSize(ElemTy);
23302361

23312362
Ty = A;
@@ -2486,17 +2517,10 @@ Type* Parser::WalkType(clang::QualType QualType, const clang::TypeLoc* TL,
24862517

24872518
if (LocValid)
24882519
{
2489-
auto TypeLocClass = TL->getTypeLocClass();
2490-
if (TypeLocClass == TypeLoc::Qualified)
2520+
while(TL->getTypeLocClass() != TypeLoc::TemplateSpecialization)
24912521
{
2492-
UTL = TL->getUnqualifiedLoc();
2493-
TL = &UTL;
2494-
}
2495-
else if (TypeLocClass == TypeLoc::Elaborated)
2496-
{
2497-
ETL = TL->getAs<ElaboratedTypeLoc>();
2498-
ITL = ETL.getNextTypeLoc();
2499-
TL = &ITL;
2522+
auto RTL = ResolveTypeLoc(*TL, TypeLoc::TemplateSpecialization);
2523+
TL = &RTL;
25002524
}
25012525

25022526
assert(TL->getTypeLocClass() == TypeLoc::TemplateSpecialization);
@@ -2529,17 +2553,10 @@ Type* Parser::WalkType(clang::QualType QualType, const clang::TypeLoc* TL,
25292553

25302554
if (LocValid)
25312555
{
2532-
auto TypeLocClass = TL->getTypeLocClass();
2533-
if (TypeLocClass == TypeLoc::Qualified)
2534-
{
2535-
UTL = TL->getUnqualifiedLoc();
2536-
TL = &UTL;
2537-
}
2538-
else if (TypeLocClass == TypeLoc::Elaborated)
2556+
while(TL->getTypeLocClass() != TypeLoc::DependentTemplateSpecialization)
25392557
{
2540-
ETL = TL->getAs<ElaboratedTypeLoc>();
2541-
ITL = ETL.getNextTypeLoc();
2542-
TL = &ITL;
2558+
auto RTL = ResolveTypeLoc(*TL, TypeLoc::DependentTemplateSpecialization);
2559+
TL = &RTL;
25432560
}
25442561

25452562
assert(TL->getTypeLocClass() == TypeLoc::DependentTemplateSpecialization);
@@ -2573,28 +2590,15 @@ Type* Parser::WalkType(clang::QualType QualType, const clang::TypeLoc* TL,
25732590

25742591
if (LocValid)
25752592
{
2576-
auto TypeLocClass = TL->getTypeLocClass();
2577-
if (TypeLocClass == TypeLoc::Qualified)
2593+
while(TL->getTypeLocClass() != TypeLoc::TemplateTypeParm)
25782594
{
2579-
UTL = TL->getUnqualifiedLoc();
2580-
TL = &UTL;
2581-
}
2582-
else if (TypeLocClass == TypeLoc::Elaborated)
2583-
{
2584-
ETL = TL->getAs<ElaboratedTypeLoc>();
2585-
ITL = ETL.getNextTypeLoc();
2586-
TL = &ITL;
2587-
}
2588-
2589-
while (TL->getTypeLocClass() != TypeLoc::TemplateTypeParm)
2590-
{
2591-
Next = TL->getNextTypeLoc();
2592-
TL = &Next;
2595+
auto RTL = ResolveTypeLoc(*TL, TypeLoc::TemplateTypeParm);
2596+
TL = &RTL;
25932597
}
25942598

25952599
assert(TL->getTypeLocClass() == TypeLoc::TemplateTypeParm);
2596-
auto TTTL = TL->getAs<TemplateTypeParmTypeLoc>();
25972600

2601+
auto TTTL = TL->getAs<TemplateTypeParmTypeLoc>();
25982602
TPT->parameter = WalkTypeTemplateParameter(TTTL.getDecl());
25992603
}
26002604
else if (TP->getDecl())
@@ -4368,7 +4372,7 @@ ParserResult* Parser::ParseLibrary(const std::string& File)
43684372
break;
43694373
}
43704374

4371-
if (FileEntry.empty())
4375+
if (FileEntry.empty() || !llvm::sys::fs::exists(FileEntry))
43724376
{
43734377
res->kind = ParserResultKind::FileNotFound;
43744378
return res;

0 commit comments

Comments
 (0)