Created
May 11, 2014 20:53
-
-
Save tritao/f35f738d6cb68ed1f4d4 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
From 3d4770b760da036e27e9bd8528dd42f8282609de Mon Sep 17 00:00:00 2001 | |
From: triton <joao@tritao.eu> | |
Date: Sun, 11 May 2014 21:52:25 +0100 | |
Subject: [PATCH] Improved template parsing error handling. | |
For an example of what can trigger it: | |
template<typename _CharT, typename _Traits = char_traits<_CharT>, | |
typename _Alloc = allocator<_CharT> > | |
class basic_string; | |
extern template class basic_string<char>; | |
--- | |
src/CppParser/Parser.cpp | 31 ++++++++++++++++++++++--------- | |
1 file changed, 22 insertions(+), 9 deletions(-) | |
diff --git a/src/CppParser/Parser.cpp b/src/CppParser/Parser.cpp | |
index 28c35c7..0f14cb9 100644 | |
--- a/src/CppParser/Parser.cpp | |
+++ b/src/CppParser/Parser.cpp | |
@@ -879,7 +879,8 @@ ClassTemplate* Parser::WalkClassTemplate(clang::ClassTemplateDecl* TD) | |
//-----------------------------------// | |
std::vector<CppSharp::CppParser::TemplateArgument> | |
-Parser::WalkTemplateArgumentList(const clang::TemplateArgumentList* TAL, clang::TemplateSpecializationTypeLoc* TSTL) | |
+Parser::WalkTemplateArgumentList(const clang::TemplateArgumentList* TAL, | |
+ clang::TemplateSpecializationTypeLoc* TSTL) | |
{ | |
using namespace clang; | |
@@ -888,8 +889,13 @@ Parser::WalkTemplateArgumentList(const clang::TemplateArgumentList* TAL, clang:: | |
for (size_t i = 0, e = TAL->size(); i < e; i++) | |
{ | |
auto TA = TAL->get(i); | |
- auto ArgLoc = TSTL->getArgLoc(i); | |
- auto Arg = WalkTemplateArgument(TA, &ArgLoc); | |
+ TemplateArgumentLoc *ArgLoc = 0; | |
+ if (TSTL && i < TSTL->getNumArgs()) | |
+ { | |
+ auto TAL = TSTL->getArgLoc(i); | |
+ ArgLoc = &TAL; | |
+ } | |
+ auto Arg = WalkTemplateArgument(TA, ArgLoc); | |
params.push_back(Arg); | |
} | |
@@ -1693,7 +1699,7 @@ Type* Parser::WalkType(clang::QualType QualType, clang::TypeLoc* TL, | |
if (TS->isSugared()) | |
TST->Desugared = WalkType(TS->desugar()); | |
- if (!TL->isNull()) | |
+ if (TL && !TL->isNull()) | |
{ | |
auto TypeLocClass = TL->getTypeLocClass(); | |
if (TypeLocClass == TypeLoc::Qualified) | |
@@ -1709,12 +1715,19 @@ Type* Parser::WalkType(clang::QualType QualType, clang::TypeLoc* TL, | |
} | |
assert(TL->getTypeLocClass() == TypeLoc::TemplateSpecialization); | |
- auto TSTL = TL->getAs<TemplateSpecializationTypeLoc>(); | |
- TST->Arguments = WalkTemplateArgumentList( | |
- &TemplateArgumentList(TemplateArgumentList::OnStack, TS->getArgs(), TS->getNumArgs()), | |
- &TSTL); | |
} | |
+ TemplateSpecializationTypeLoc *TSTL = 0; | |
+ if (TL && !TL->isNull()) | |
+ { | |
+ auto TSpecTL = TL->getAs<TemplateSpecializationTypeLoc>(); | |
+ TSTL = &TSpecTL; | |
+ } | |
+ | |
+ TemplateArgumentList TArgs(TemplateArgumentList::OnStack, TS->getArgs(), | |
+ TS->getNumArgs()); | |
+ TST->Arguments = WalkTemplateArgumentList(&TArgs, TSTL); | |
+ | |
Ty = TST; | |
break; | |
} | |
@@ -1726,7 +1739,7 @@ Type* Parser::WalkType(clang::QualType QualType, clang::TypeLoc* TL, | |
if (auto Ident = TP->getIdentifier()) | |
TPT->Parameter.Name = Ident->getName(); | |
- if (!TL->isNull()) | |
+ if (TL && !TL->isNull()) | |
{ | |
auto TypeLocClass = TL->getTypeLocClass(); | |
if (TypeLocClass == TypeLoc::Qualified) | |
-- | |
1.8.3.msysgit.0 | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment