71
71
#define _assertm (condition, message, call ) \
72
72
do { \
73
73
if (!(condition)) { \
74
- std::cerr << " Assert at " \
74
+ std::cerr << " Assert at ` " \
75
75
<< __FILE__ \
76
76
<< " :" \
77
77
<< __LINE__ \
78
- << " in " \
78
+ << " ` in ` " \
79
79
<< __FUNCTION__ \
80
- << " failed. " \
80
+ << " ` failed. " \
81
81
<< message; \
82
82
call; \
83
83
} \
89
89
if (!(condition)) { \
90
90
const clang::SourceManager& _sm = sm; \
91
91
clang::SourceLocation _loc = loc; \
92
- std::cerr << " Assert at " \
92
+ std::cerr << " Assert at ` " \
93
93
<< __FILE__ \
94
94
<< " :" \
95
95
<< __LINE__ \
96
- << " in " \
96
+ << " ` in ` " \
97
97
<< __FUNCTION__ \
98
- << " failed. " \
98
+ << " ` failed. " \
99
99
<< message \
100
- << " Filename " \
100
+ << " Filename ` " \
101
101
<< _sm.getFilename (_loc).str () \
102
102
<< " :" \
103
103
<< _sm.getSpellingLineNumber (_loc) \
104
- << " \n " ; \
104
+ << " ` \n " ; \
105
105
call; \
106
106
} \
107
107
}while (0 )
108
108
109
109
// Macros which output messages to console if parsing encounters oddity.
110
- // If _DEBUG is defined but DEBUG_NO_ABORT is not macros abort .
110
+ // In debug builds, macros abort unless DEBUG_NO_ABORT is defined .
111
111
//
112
112
// Macro assertm outputs a message if condition is false.
113
113
// Macro assertml outputs a message and parsing file and line on given source manager and source line.
114
114
//
115
115
// assertml adds newline ending.
116
- #if defined(_DEBUG) && !defined(DEBUG_NO_ABORT)
117
- #define assertm ( condition, message ) _assertm(condition, message, abort() )
118
- #define assertml ( condition, message, sm, source ) _assertml(condition, message, sm, source, abort() )
116
+ #ifdef NDEBUG
117
+ #define debug_break () (( void ) 0 )
118
+ #define debug_fail () (( void ) 0 )
119
119
#else
120
- #define assertm (condition, message ) _assertm(condition, message, )
121
- #define assertml (condition, message, sm, source ) _assertml(condition, message, sm, source, )
120
+
121
+ #if __GNUC__
122
+ #define debug_break () \
123
+ __builtin_trap ()
124
+ #elif _MSC_VER
125
+ #define debug_break () \
126
+ __debugbreak ()
127
+ #else
128
+ #define debug_break (c ) \
129
+ *reinterpret_cast <volatile int *>(0 ) = 47283 ;
130
+ #endif
131
+
132
+ #ifdef DEBUG_NO_ABORT
133
+ #define debug_fail () debug_break()
134
+ #else
135
+ #define debug_fail () debug_break(); abort()
122
136
#endif
123
137
138
+ #endif
139
+
140
+ #define assertm (condition, message ) _assertm(condition, message, debug_fail())
141
+ #define assertml (condition, message, sm, source ) _assertml(condition, message, sm, source, debug_fail())
142
+
124
143
using namespace CppSharp ::CppParser;
125
144
126
145
// We use this as a placeholder for pointer values that should be ignored.
@@ -959,7 +978,14 @@ static clang::CXXRecordDecl* GetCXXRecordDeclFromBaseType(const clang::ASTContex
959
978
return GetCXXRecordDeclFromTemplateName (TST->getTemplateName ());
960
979
else if (auto Injected = Ty->getAs <clang::InjectedClassNameType>())
961
980
return Injected->getDecl ();
981
+ else if (auto TTPT = Ty->getAs <clang::TemplateTypeParmType>()) {
982
+ return nullptr ;
983
+ }
984
+ else if (auto DNT = Ty->getAs <clang::DependentNameType>()) {
985
+ return nullptr ;
986
+ }
962
987
988
+ Ty->dump ();
963
989
assertml (0 , " Could not get base CXX record from type. Unhandled type: " , context.getSourceManager (), base.getBeginLoc ());
964
990
965
991
return nullptr ;
@@ -2695,41 +2721,59 @@ Type* Parser::WalkType(clang::QualType QualType, const clang::TypeLoc* TL,
2695
2721
auto TST = new TemplateSpecializationType ();
2696
2722
2697
2723
TemplateName Name = TS->getTemplateName ();
2698
- TST->_template = static_cast <Template*>(WalkDeclaration (
2699
- Name. getAsTemplateDecl ()));
2724
+ TST->_template = static_cast <Template*>(WalkDeclaration (Name. getAsTemplateDecl ()));
2725
+
2700
2726
if (TS->isSugared ())
2701
2727
TST->desugared = GetQualifiedType (TS->getCanonicalTypeInternal (), TL);
2702
2728
2703
- TypeLoc UTL, ETL, ITL ;
2729
+ TemplateArgumentList TArgs (TemplateArgumentList::OnStack, TS-> template_arguments ()) ;
2704
2730
2705
- if (LocValid)
2731
+ if (! LocValid)
2706
2732
{
2707
- auto TypeLocClass = TL->getTypeLocClass ();
2708
- if (TypeLocClass == TypeLoc::Qualified)
2709
- {
2710
- UTL = TL->getUnqualifiedLoc ();
2711
- TL = &UTL;
2712
- }
2713
- else if (TypeLocClass == TypeLoc::Elaborated)
2714
- {
2715
- ETL = TL->getAs <ElaboratedTypeLoc>();
2716
- ITL = ETL.getNextTypeLoc ();
2717
- TL = &ITL;
2718
- }
2719
-
2720
- assertm (TL->getTypeLocClass () == TypeLoc::TemplateSpecialization, " Only Template specialization accepted!\n " );
2733
+ TST->Arguments = WalkTemplateArgumentList (&TArgs, (TemplateSpecializationTypeLoc*)nullptr );
2734
+ Ty = TST;
2735
+ break ;
2721
2736
}
2722
2737
2723
- TemplateSpecializationTypeLoc TSpecTL;
2724
- TemplateSpecializationTypeLoc *TSTL = 0 ;
2725
- if (LocValid)
2738
+ TypeLoc UTL, ETL, ITL;
2739
+ if (TL->getTypeLocClass () == TypeLoc::Qualified)
2726
2740
{
2727
- TSpecTL = TL->getAs <TemplateSpecializationTypeLoc>();
2728
- TSTL = &TSpecTL;
2741
+ UTL = TL->getUnqualifiedLoc ();
2742
+ TL = &UTL;
2743
+ }
2744
+
2745
+ if (TL->getTypeLocClass () == TypeLoc::Elaborated)
2746
+ {
2747
+ ETL = TL->getAs <ElaboratedTypeLoc>();
2748
+ ITL = ETL.getNextTypeLoc ();
2749
+ TL = &ITL;
2729
2750
}
2730
2751
2731
- TemplateArgumentList TArgs (TemplateArgumentList::OnStack, TS->template_arguments ());
2732
- TST->Arguments = WalkTemplateArgumentList (&TArgs, TSTL);
2752
+ switch (TL->getTypeLocClass ()) {
2753
+ case TypeLoc::DependentTemplateSpecialization:
2754
+ {
2755
+ DependentTemplateSpecializationTypeLoc TSpecTL = TL->getAs <DependentTemplateSpecializationTypeLoc>();
2756
+ TST->Arguments = WalkTemplateArgumentList (&TArgs, &TSpecTL);
2757
+ Ty = TST;
2758
+ break ;
2759
+ }
2760
+ case TypeLoc::TemplateSpecialization:
2761
+ {
2762
+ TemplateSpecializationTypeLoc TSpecTL = TL->getAs <TemplateSpecializationTypeLoc>();
2763
+ TST->Arguments = WalkTemplateArgumentList (&TArgs, &TSpecTL);
2764
+ Ty = TST;
2765
+ break ;
2766
+ }
2767
+ case TypeLoc::TemplateTypeParm:
2768
+ {
2769
+ TemplateTypeParmTypeLoc TTPTL = TL->getAs <TemplateTypeParmTypeLoc>();
2770
+ TST->Arguments = WalkTemplateArgumentList (&TArgs, (TemplateSpecializationTypeLoc*)nullptr );
2771
+ break ;
2772
+ }
2773
+ default :
2774
+ assertml (0 , " Unhandled TemplateSpecializationTypeLoc!\n " , c->getSourceManager (), TL->getBeginLoc ());
2775
+ break ;
2776
+ }
2733
2777
2734
2778
Ty = TST;
2735
2779
break ;
@@ -2741,38 +2785,52 @@ Type* Parser::WalkType(clang::QualType QualType, const clang::TypeLoc* TL,
2741
2785
2742
2786
if (TS->isSugared ())
2743
2787
TST->desugared = GetQualifiedType (TS->getCanonicalTypeInternal (), TL);
2788
+
2789
+ TemplateArgumentList TArgs (TemplateArgumentList::OnStack, TS->template_arguments ());
2744
2790
2745
- TypeLoc UTL, ETL, ITL;
2746
-
2747
- if (LocValid)
2791
+ if (!LocValid)
2748
2792
{
2749
- auto TypeLocClass = TL->getTypeLocClass ();
2750
- if (TypeLocClass == TypeLoc::Qualified)
2751
- {
2752
- UTL = TL->getUnqualifiedLoc ();
2753
- TL = &UTL;
2754
- }
2755
- else if (TypeLocClass == TypeLoc::Elaborated)
2756
- {
2757
- ETL = TL->getAs <ElaboratedTypeLoc>();
2758
- ITL = ETL.getNextTypeLoc ();
2759
- TL = &ITL;
2760
- }
2761
- assertml (TL->getTypeLocClass () == TypeLoc::DependentTemplateSpecialization,
2762
- " Dependent template only accepted!" ,
2763
- c->getSourceManager (), TL->getBeginLoc ());
2793
+ TST->Arguments = WalkTemplateArgumentList (&TArgs, (DependentTemplateSpecializationTypeLoc*)nullptr );
2794
+ Ty = TST;
2795
+ break ;
2764
2796
}
2765
2797
2766
- DependentTemplateSpecializationTypeLoc TSpecTL;
2767
- DependentTemplateSpecializationTypeLoc *TSTL = 0 ;
2768
- if (LocValid)
2798
+ TypeLoc UTL, ETL, ITL;
2799
+ if (TL->getTypeLocClass () == TypeLoc::Qualified)
2769
2800
{
2770
- TSpecTL = TL->getAs <DependentTemplateSpecializationTypeLoc>();
2771
- TSTL = &TSpecTL;
2801
+ UTL = TL->getUnqualifiedLoc ();
2802
+ TL = &UTL;
2803
+ }
2804
+
2805
+ if (TL->getTypeLocClass () == TypeLoc::Elaborated)
2806
+ {
2807
+ ETL = TL->getAs <ElaboratedTypeLoc>();
2808
+ ITL = ETL.getNextTypeLoc ();
2809
+ TL = &ITL;
2772
2810
}
2773
2811
2774
- TemplateArgumentList TArgs (TemplateArgumentList::OnStack, TS->template_arguments ());
2775
- TST->Arguments = WalkTemplateArgumentList (&TArgs, TSTL);
2812
+ switch (TL->getTypeLocClass ()) {
2813
+ case TypeLoc::DependentTemplateSpecialization:
2814
+ {
2815
+ DependentTemplateSpecializationTypeLoc TSpecTL = TL->getAs <DependentTemplateSpecializationTypeLoc>();
2816
+ TST->Arguments = WalkTemplateArgumentList (&TArgs, &TSpecTL);
2817
+ break ;
2818
+ }
2819
+ case TypeLoc::TemplateSpecialization:
2820
+ {
2821
+ TemplateSpecializationTypeLoc TSpecTL = TL->getAs <TemplateSpecializationTypeLoc>();
2822
+ TST->Arguments = WalkTemplateArgumentList (&TArgs, &TSpecTL);
2823
+ break ;
2824
+ }
2825
+ case TypeLoc::TemplateTypeParm:
2826
+ {
2827
+ TST->Arguments = WalkTemplateArgumentList (&TArgs, (DependentTemplateSpecializationTypeLoc*)nullptr );
2828
+ break ;
2829
+ }
2830
+ default :
2831
+ assertml (0 , " Unhandled DependentTemplateSpecializationTypeLoc!\n " , c->getSourceManager (), TL->getBeginLoc ());
2832
+ break ;
2833
+ }
2776
2834
2777
2835
Ty = TST;
2778
2836
break ;
0 commit comments