Browse Source

Fixed the parsing of typedefs with the same name in different specialisations of a template.

Signed-off-by: Dimitar Dobrev <dpldobrev@protonmail.com>
pull/661/head
Dimitar Dobrev 9 years ago
parent
commit
0c7031e951
  1. 2
      src/CppParser/AST.cpp
  2. 20
      src/CppParser/Parser.cpp
  3. 17
      tests/Common/Common.h

2
src/CppParser/AST.cpp

@ -519,7 +519,6 @@ TypedefDecl* DeclarationContext::FindTypedef(const std::string& Name, bool Creat @@ -519,7 +519,6 @@ TypedefDecl* DeclarationContext::FindTypedef(const std::string& Name, bool Creat
auto tdef = new TypedefDecl();
tdef->Name = Name;
tdef->_Namespace = this;
Typedefs.push_back(tdef);
return tdef;
}
@ -538,7 +537,6 @@ TypeAlias* DeclarationContext::FindTypeAlias(const std::string& Name, bool Creat @@ -538,7 +537,6 @@ TypeAlias* DeclarationContext::FindTypeAlias(const std::string& Name, bool Creat
auto talias = new TypeAlias();
talias->Name = Name;
talias->_Namespace = this;
TypeAliases.push_back(talias);
return talias;
}

20
src/CppParser/Parser.cpp

@ -3229,7 +3229,7 @@ Declaration* Parser::WalkDeclaration(const clang::Decl* D, @@ -3229,7 +3229,7 @@ Declaration* Parser::WalkDeclaration(const clang::Decl* D,
}
case Decl::Typedef:
{
auto TD = cast<clang::TypedefNameDecl>(D);
auto TD = cast<clang::TypedefDecl>(D);
auto NS = GetNamespace(TD);
auto Name = GetDeclName(TD);
@ -3240,9 +3240,17 @@ Declaration* Parser::WalkDeclaration(const clang::Decl* D, @@ -3240,9 +3240,17 @@ Declaration* Parser::WalkDeclaration(const clang::Decl* D,
HandleDeclaration(TD, Typedef);
auto TTL = TD->getTypeSourceInfo()->getTypeLoc();
// resolve the typedef before adding it to the list otherwise it might be found and returned prematurely
// see "typedef _Aligned<16, char>::type type;" and the related classes in Common.h in the tests
Typedef->QualifiedType = GetQualifiedType(TD->getUnderlyingType(), &TTL);
AST::TypedefDecl* Existing;
// if the typedef was added along the way, the just created one is useless, delete it
if (Existing = NS->FindTypedef(Name, /*Create=*/false))
delete Typedef;
else
NS->Typedefs.push_back(Existing = Typedef);
Decl = Typedef;
Decl = Existing;
break;
}
case Decl::TypeAlias:
@ -3258,12 +3266,18 @@ Declaration* Parser::WalkDeclaration(const clang::Decl* D, @@ -3258,12 +3266,18 @@ Declaration* Parser::WalkDeclaration(const clang::Decl* D,
HandleDeclaration(TD, TypeAlias);
auto TTL = TD->getTypeSourceInfo()->getTypeLoc();
// see above the case for "Typedef"
TypeAlias->QualifiedType = GetQualifiedType(TD->getUnderlyingType(), &TTL);
AST::TypeAlias* Existing;
if (Existing = NS->FindTypeAlias(Name, /*Create=*/false))
delete TypeAlias;
else
NS->TypeAliases.push_back(Existing = TypeAlias);
if (auto TAT = TD->getDescribedAliasTemplate())
TypeAlias->DescribedAliasTemplate = WalkTypeAliasTemplate(TAT);
Decl = TypeAlias;
Decl = Existing;
break;
}
case Decl::Namespace:

17
tests/Common/Common.h

@ -1138,4 +1138,19 @@ public: @@ -1138,4 +1138,19 @@ public:
virtual bool operator==(const HasAbstractOperator& other) = 0;
};
using data_type = typename std::aligned_storage<16, 8>::type;
template<size_t _Len, class _Ty>
struct _Aligned;
template<size_t _Len>
struct _Aligned<_Len, int>
{
typedef int type;
};
template<size_t _Len>
struct _Aligned<_Len, char>
{
typedef typename _Aligned<_Len, int>::type type;
};
typedef _Aligned<16, char>::type type;

Loading…
Cancel
Save