23
23
#include " cpp_member_spec.h"
24
24
#include " cpp_enum_type.h"
25
25
26
+ #define DEBUG
26
27
#ifdef DEBUG
27
28
#include < iostream>
28
29
@@ -1013,6 +1014,11 @@ bool Parser::rLinkageBody(cpp_linkage_spect::itemst &items)
1013
1014
*/
1014
1015
bool Parser::rTemplateDecl (cpp_declarationt &decl)
1015
1016
{
1017
+ #ifdef DEBUG
1018
+ indenter _i;
1019
+ std::cout << std::string (__indent, ' ' ) << " Parser::rTemplateDecl 1\n " ;
1020
+ #endif
1021
+
1016
1022
TemplateDeclKind kind=tdk_unknown;
1017
1023
1018
1024
make_sub_scope (" #template" , new_scopet::kindt::TEMPLATE);
@@ -1022,6 +1028,10 @@ bool Parser::rTemplateDecl(cpp_declarationt &decl)
1022
1028
if (!rTemplateDecl2 (template_type, kind))
1023
1029
return false ;
1024
1030
1031
+ #ifdef DEBUG
1032
+ std::cout << std::string (__indent, ' ' ) << " Parser::rTemplateDecl 2\n " ;
1033
+ #endif
1034
+
1025
1035
cpp_declarationt body;
1026
1036
if (lex.LookAhead (0 )==TOK_USING)
1027
1037
{
@@ -1069,11 +1079,20 @@ bool Parser::rTemplateDecl(cpp_declarationt &decl)
1069
1079
1070
1080
bool Parser::rTemplateDecl2 (typet &decl, TemplateDeclKind &kind)
1071
1081
{
1082
+ #ifdef DEBUG
1083
+ indenter _i;
1084
+ std::cout << std::string (__indent, ' ' ) << " Parser::rTemplateDecl2 1\n " ;
1085
+ #endif
1086
+
1072
1087
cpp_tokent tk;
1073
1088
1074
1089
if (lex.get_token (tk)!=TOK_TEMPLATE)
1075
1090
return false ;
1076
1091
1092
+ #ifdef DEBUG
1093
+ std::cout << std::string (__indent, ' ' ) << " Parser::rTemplateDecl2 2\n " ;
1094
+ #endif
1095
+
1077
1096
decl=typet (ID_template);
1078
1097
set_location (decl, tk);
1079
1098
@@ -1084,17 +1103,33 @@ bool Parser::rTemplateDecl2(typet &decl, TemplateDeclKind &kind)
1084
1103
return true ; // ignore TEMPLATE
1085
1104
}
1086
1105
1106
+ #ifdef DEBUG
1107
+ std::cout << std::string (__indent, ' ' ) << " Parser::rTemplateDecl2 3\n " ;
1108
+ #endif
1109
+
1087
1110
if (lex.get_token (tk)!=' <' )
1088
1111
return false ;
1089
1112
1090
1113
irept &template_parameters=decl.add (ID_template_parameters);
1091
1114
1115
+ #ifdef DEBUG
1116
+ std::cout << std::string (__indent, ' ' ) << " Parser::rTemplateDecl2 4\n " ;
1117
+ #endif
1118
+
1092
1119
if (!rTempArgList (template_parameters))
1093
1120
return false ;
1094
1121
1122
+ #ifdef DEBUG
1123
+ std::cout << std::string (__indent, ' ' ) << " Parser::rTemplateDecl2 5\n " ;
1124
+ #endif
1125
+
1095
1126
if (lex.get_token (tk)!=' >' )
1096
1127
return false ;
1097
1128
1129
+ #ifdef DEBUG
1130
+ std::cout << std::string (__indent, ' ' ) << " Parser::rTemplateDecl2 6\n " ;
1131
+ #endif
1132
+
1098
1133
// ignore nested TEMPLATE
1099
1134
while (lex.LookAhead (0 )==TOK_TEMPLATE)
1100
1135
{
@@ -1111,6 +1146,10 @@ bool Parser::rTemplateDecl2(typet &decl, TemplateDeclKind &kind)
1111
1146
return false ;
1112
1147
}
1113
1148
1149
+ #ifdef DEBUG
1150
+ std::cout << std::string (__indent, ' ' ) << " Parser::rTemplateDecl2 7\n " ;
1151
+ #endif
1152
+
1114
1153
if (template_parameters.get_sub ().empty ())
1115
1154
// template < > declaration
1116
1155
kind=tdk_specialization;
@@ -1171,6 +1210,10 @@ bool Parser::rTempArgDeclaration(cpp_declarationt &declaration)
1171
1210
1172
1211
if ((t0==TOK_CLASS || t0==TOK_TYPENAME))
1173
1212
{
1213
+ #ifdef DEBUG
1214
+ std::cout << std::string (__indent, ' ' ) << " Parser::rTempArgDeclaration 0.1\n " ;
1215
+ #endif
1216
+
1174
1217
cpp_token_buffert::post pos=lex.Save ();
1175
1218
1176
1219
cpp_tokent tk1;
@@ -1210,6 +1253,10 @@ bool Parser::rTempArgDeclaration(cpp_declarationt &declaration)
1210
1253
1211
1254
if (lex.LookAhead (0 )==' =' )
1212
1255
{
1256
+ #ifdef DEBUG
1257
+ std::cout << std::string (__indent, ' ' ) << " Parser::rTempArgDeclaration 0.2\n " ;
1258
+ #endif
1259
+
1213
1260
if (declarator.get_has_ellipsis ())
1214
1261
return false ;
1215
1262
@@ -1222,10 +1269,38 @@ bool Parser::rTempArgDeclaration(cpp_declarationt &declaration)
1222
1269
declarator.value ()=exprt (ID_type);
1223
1270
declarator.value ().type ().swap (default_type);
1224
1271
}
1272
+ #ifdef DEBUG
1273
+ std::cout << std::string (__indent, ' ' ) << " Parser::rTempArgDeclaration 0.3\n " ;
1274
+ #endif
1225
1275
1226
1276
if (lex.LookAhead (0 )==' ,' ||
1227
1277
lex.LookAhead (0 )==' >' )
1228
1278
return true ;
1279
+ #if 0
1280
+ else if(lex.LookAhead(0) == TOK_SHIFTRIGHT)
1281
+ {
1282
+ #ifdef DEBUG
1283
+ std::cout << std::string(__indent, ' ') << "Parser::rTempArgDeclaration 0.4\n";
1284
+ #endif
1285
+
1286
+ // turn >> into > >
1287
+ cpp_token_buffert::post pos=lex.Save();
1288
+ cpp_tokent tk;
1289
+ lex.get_token(tk);
1290
+ lex.Restore(pos);
1291
+ tk.kind='>';
1292
+ tk.text='>';
1293
+ lex.Replace(tk);
1294
+ lex.Insert(tk);
1295
+ DATA_INVARIANT(lex.LookAhead(0) == '>', "should be >");
1296
+ DATA_INVARIANT(lex.LookAhead(1) == '>', "should be >");
1297
+ return true;
1298
+ }
1299
+ #endif
1300
+ #ifdef DEBUG
1301
+ std::cout << std::string (__indent, ' ' ) << " Parser::rTempArgDeclaration 0.5\n " ;
1302
+ #endif
1303
+
1229
1304
1230
1305
lex.Restore (pos);
1231
1306
}
@@ -3936,7 +4011,8 @@ bool Parser::rTemplateArgs(irept &template_args)
3936
4011
)
3937
4012
{
3938
4013
#ifdef DEBUG
3939
- std::cout << std::string (__indent, ' ' ) << " Parser::rTemplateArgs 4\n " ;
4014
+ std::cout << std::string (__indent, ' ' ) << " Parser::rTemplateArgs 4 " <<
4015
+ lex.LookAhead (0 ) << " \n " ;
3940
4016
#endif
3941
4017
3942
4018
// ok
@@ -3948,20 +4024,30 @@ bool Parser::rTemplateArgs(irept &template_args)
3948
4024
lex.Restore (pos);
3949
4025
exprt tmp;
3950
4026
if (rConditionalExpr (tmp, true ))
4027
+ {
4028
+ #ifdef DEBUG
4029
+ std::cout << std::string (__indent, ' ' ) << " Parser::rTemplateArgs 4.0\n " ;
4030
+ #endif
3951
4031
exp.id (ID_ambiguous);
4032
+ }
3952
4033
#ifdef DEBUG
3953
4034
std::cout << std::string (__indent, ' ' ) << " Parser::rTemplateArgs 4.1\n " ;
3954
4035
#endif
3955
4036
lex.Restore (pos);
3956
4037
rTypeNameOrFunctionType (a);
3957
4038
4039
+ #ifdef DEBUG
4040
+ std::cout << std::string (__indent, ' ' ) << " Parser::rTemplateArgs 4.1a " <<
4041
+ lex.LookAhead (0 ) << " \n " ;
4042
+ #endif
3958
4043
if (lex.LookAhead (0 )==TOK_ELLIPSIS)
3959
4044
{
3960
4045
lex.get_token (tk1);
3961
4046
exp.set (ID_ellipsis, true );
3962
4047
}
3963
4048
#ifdef DEBUG
3964
- std::cout << std::string (__indent, ' ' ) << " Parser::rTemplateArgs 4.2\n " ;
4049
+ std::cout << std::string (__indent, ' ' ) << " Parser::rTemplateArgs 4.2 " <<
4050
+ lex.LookAhead (0 ) << " \n " ;
3965
4051
#endif
3966
4052
}
3967
4053
else
0 commit comments