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
@@ -1046,6 +1047,11 @@ bool Parser::rLinkageBody(cpp_linkage_spect::itemst &items)
1046
1047
*/
1047
1048
bool Parser::rTemplateDecl (cpp_declarationt &decl)
1048
1049
{
1050
+ #ifdef DEBUG
1051
+ indenter _i;
1052
+ std::cout << std::string (__indent, ' ' ) << " Parser::rTemplateDecl 1\n " ;
1053
+ #endif
1054
+
1049
1055
TemplateDeclKind kind=tdk_unknown;
1050
1056
1051
1057
make_sub_scope (" #template" , new_scopet::kindt::TEMPLATE);
@@ -1055,6 +1061,10 @@ bool Parser::rTemplateDecl(cpp_declarationt &decl)
1055
1061
if (!rTemplateDecl2 (template_type, kind))
1056
1062
return false ;
1057
1063
1064
+ #ifdef DEBUG
1065
+ std::cout << std::string (__indent, ' ' ) << " Parser::rTemplateDecl 2\n " ;
1066
+ #endif
1067
+
1058
1068
cpp_declarationt body;
1059
1069
if (lex.LookAhead (0 )==TOK_USING)
1060
1070
{
@@ -1102,11 +1112,20 @@ bool Parser::rTemplateDecl(cpp_declarationt &decl)
1102
1112
1103
1113
bool Parser::rTemplateDecl2 (typet &decl, TemplateDeclKind &kind)
1104
1114
{
1115
+ #ifdef DEBUG
1116
+ indenter _i;
1117
+ std::cout << std::string (__indent, ' ' ) << " Parser::rTemplateDecl2 1\n " ;
1118
+ #endif
1119
+
1105
1120
cpp_tokent tk;
1106
1121
1107
1122
if (lex.get_token (tk)!=TOK_TEMPLATE)
1108
1123
return false ;
1109
1124
1125
+ #ifdef DEBUG
1126
+ std::cout << std::string (__indent, ' ' ) << " Parser::rTemplateDecl2 2\n " ;
1127
+ #endif
1128
+
1110
1129
decl=typet (ID_template);
1111
1130
set_location (decl, tk);
1112
1131
@@ -1117,17 +1136,33 @@ bool Parser::rTemplateDecl2(typet &decl, TemplateDeclKind &kind)
1117
1136
return true ; // ignore TEMPLATE
1118
1137
}
1119
1138
1139
+ #ifdef DEBUG
1140
+ std::cout << std::string (__indent, ' ' ) << " Parser::rTemplateDecl2 3\n " ;
1141
+ #endif
1142
+
1120
1143
if (lex.get_token (tk)!=' <' )
1121
1144
return false ;
1122
1145
1123
1146
irept &template_parameters=decl.add (ID_template_parameters);
1124
1147
1148
+ #ifdef DEBUG
1149
+ std::cout << std::string (__indent, ' ' ) << " Parser::rTemplateDecl2 4\n " ;
1150
+ #endif
1151
+
1125
1152
if (!rTempArgList (template_parameters))
1126
1153
return false ;
1127
1154
1155
+ #ifdef DEBUG
1156
+ std::cout << std::string (__indent, ' ' ) << " Parser::rTemplateDecl2 5\n " ;
1157
+ #endif
1158
+
1128
1159
if (lex.get_token (tk)!=' >' )
1129
1160
return false ;
1130
1161
1162
+ #ifdef DEBUG
1163
+ std::cout << std::string (__indent, ' ' ) << " Parser::rTemplateDecl2 6\n " ;
1164
+ #endif
1165
+
1131
1166
// ignore nested TEMPLATE
1132
1167
while (lex.LookAhead (0 )==TOK_TEMPLATE)
1133
1168
{
@@ -1144,6 +1179,10 @@ bool Parser::rTemplateDecl2(typet &decl, TemplateDeclKind &kind)
1144
1179
return false ;
1145
1180
}
1146
1181
1182
+ #ifdef DEBUG
1183
+ std::cout << std::string (__indent, ' ' ) << " Parser::rTemplateDecl2 7\n " ;
1184
+ #endif
1185
+
1147
1186
if (template_parameters.get_sub ().empty ())
1148
1187
// template < > declaration
1149
1188
kind=tdk_specialization;
@@ -1204,6 +1243,10 @@ bool Parser::rTempArgDeclaration(cpp_declarationt &declaration)
1204
1243
1205
1244
if ((t0==TOK_CLASS || t0==TOK_TYPENAME))
1206
1245
{
1246
+ #ifdef DEBUG
1247
+ std::cout << std::string (__indent, ' ' ) << " Parser::rTempArgDeclaration 0.1\n " ;
1248
+ #endif
1249
+
1207
1250
cpp_token_buffert::post pos=lex.Save ();
1208
1251
1209
1252
cpp_tokent tk1;
@@ -1243,6 +1286,10 @@ bool Parser::rTempArgDeclaration(cpp_declarationt &declaration)
1243
1286
1244
1287
if (lex.LookAhead (0 )==' =' )
1245
1288
{
1289
+ #ifdef DEBUG
1290
+ std::cout << std::string (__indent, ' ' ) << " Parser::rTempArgDeclaration 0.2\n " ;
1291
+ #endif
1292
+
1246
1293
if (declarator.get_has_ellipsis ())
1247
1294
return false ;
1248
1295
@@ -1255,10 +1302,38 @@ bool Parser::rTempArgDeclaration(cpp_declarationt &declaration)
1255
1302
declarator.value ()=exprt (ID_type);
1256
1303
declarator.value ().type ().swap (default_type);
1257
1304
}
1305
+ #ifdef DEBUG
1306
+ std::cout << std::string (__indent, ' ' ) << " Parser::rTempArgDeclaration 0.3\n " ;
1307
+ #endif
1258
1308
1259
1309
if (lex.LookAhead (0 )==' ,' ||
1260
1310
lex.LookAhead (0 )==' >' )
1261
1311
return true ;
1312
+ #if 0
1313
+ else if(lex.LookAhead(0) == TOK_SHIFTRIGHT)
1314
+ {
1315
+ #ifdef DEBUG
1316
+ std::cout << std::string(__indent, ' ') << "Parser::rTempArgDeclaration 0.4\n";
1317
+ #endif
1318
+
1319
+ // turn >> into > >
1320
+ cpp_token_buffert::post pos=lex.Save();
1321
+ cpp_tokent tk;
1322
+ lex.get_token(tk);
1323
+ lex.Restore(pos);
1324
+ tk.kind='>';
1325
+ tk.text='>';
1326
+ lex.Replace(tk);
1327
+ lex.Insert(tk);
1328
+ DATA_INVARIANT(lex.LookAhead(0) == '>', "should be >");
1329
+ DATA_INVARIANT(lex.LookAhead(1) == '>', "should be >");
1330
+ return true;
1331
+ }
1332
+ #endif
1333
+ #ifdef DEBUG
1334
+ std::cout << std::string (__indent, ' ' ) << " Parser::rTempArgDeclaration 0.5\n " ;
1335
+ #endif
1336
+
1262
1337
1263
1338
lex.Restore (pos);
1264
1339
}
@@ -3984,7 +4059,8 @@ bool Parser::rTemplateArgs(irept &template_args)
3984
4059
)
3985
4060
{
3986
4061
#ifdef DEBUG
3987
- std::cout << std::string (__indent, ' ' ) << " Parser::rTemplateArgs 4\n " ;
4062
+ std::cout << std::string (__indent, ' ' ) << " Parser::rTemplateArgs 4 " <<
4063
+ lex.LookAhead (0 ) << " \n " ;
3988
4064
#endif
3989
4065
3990
4066
// ok
@@ -3996,20 +4072,30 @@ bool Parser::rTemplateArgs(irept &template_args)
3996
4072
lex.Restore (pos);
3997
4073
exprt tmp;
3998
4074
if (rConditionalExpr (tmp, true ))
4075
+ {
4076
+ #ifdef DEBUG
4077
+ std::cout << std::string (__indent, ' ' ) << " Parser::rTemplateArgs 4.0\n " ;
4078
+ #endif
3999
4079
exp .id (ID_ambiguous);
4080
+ }
4000
4081
#ifdef DEBUG
4001
4082
std::cout << std::string (__indent, ' ' ) << " Parser::rTemplateArgs 4.1\n " ;
4002
4083
#endif
4003
4084
lex.Restore (pos);
4004
4085
rTypeNameOrFunctionType (a);
4005
4086
4087
+ #ifdef DEBUG
4088
+ std::cout << std::string (__indent, ' ' ) << " Parser::rTemplateArgs 4.1a " <<
4089
+ lex.LookAhead (0 ) << " \n " ;
4090
+ #endif
4006
4091
if (lex.LookAhead (0 )==TOK_ELLIPSIS)
4007
4092
{
4008
4093
lex.get_token (tk1);
4009
4094
exp .set (ID_ellipsis, true );
4010
4095
}
4011
4096
#ifdef DEBUG
4012
- std::cout << std::string (__indent, ' ' ) << " Parser::rTemplateArgs 4.2\n " ;
4097
+ std::cout << std::string (__indent, ' ' ) << " Parser::rTemplateArgs 4.2 " <<
4098
+ lex.LookAhead (0 ) << " \n " ;
4013
4099
#endif
4014
4100
}
4015
4101
else
0 commit comments