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
@@ -1030,6 +1031,11 @@ bool Parser::rLinkageBody(cpp_linkage_spect::itemst &items)
1030
1031
*/
1031
1032
bool Parser::rTemplateDecl (cpp_declarationt &decl)
1032
1033
{
1034
+ #ifdef DEBUG
1035
+ indenter _i;
1036
+ std::cout << std::string (__indent, ' ' ) << " Parser::rTemplateDecl 1\n " ;
1037
+ #endif
1038
+
1033
1039
TemplateDeclKind kind=tdk_unknown;
1034
1040
1035
1041
make_sub_scope (" #template" , new_scopet::kindt::TEMPLATE);
@@ -1039,6 +1045,10 @@ bool Parser::rTemplateDecl(cpp_declarationt &decl)
1039
1045
if (!rTemplateDecl2 (template_type, kind))
1040
1046
return false ;
1041
1047
1048
+ #ifdef DEBUG
1049
+ std::cout << std::string (__indent, ' ' ) << " Parser::rTemplateDecl 2\n " ;
1050
+ #endif
1051
+
1042
1052
cpp_declarationt body;
1043
1053
if (lex.LookAhead (0 )==TOK_USING)
1044
1054
{
@@ -1086,11 +1096,20 @@ bool Parser::rTemplateDecl(cpp_declarationt &decl)
1086
1096
1087
1097
bool Parser::rTemplateDecl2 (typet &decl, TemplateDeclKind &kind)
1088
1098
{
1099
+ #ifdef DEBUG
1100
+ indenter _i;
1101
+ std::cout << std::string (__indent, ' ' ) << " Parser::rTemplateDecl2 1\n " ;
1102
+ #endif
1103
+
1089
1104
cpp_tokent tk;
1090
1105
1091
1106
if (lex.get_token (tk)!=TOK_TEMPLATE)
1092
1107
return false ;
1093
1108
1109
+ #ifdef DEBUG
1110
+ std::cout << std::string (__indent, ' ' ) << " Parser::rTemplateDecl2 2\n " ;
1111
+ #endif
1112
+
1094
1113
decl=typet (ID_template);
1095
1114
set_location (decl, tk);
1096
1115
@@ -1101,17 +1120,33 @@ bool Parser::rTemplateDecl2(typet &decl, TemplateDeclKind &kind)
1101
1120
return true ; // ignore TEMPLATE
1102
1121
}
1103
1122
1123
+ #ifdef DEBUG
1124
+ std::cout << std::string (__indent, ' ' ) << " Parser::rTemplateDecl2 3\n " ;
1125
+ #endif
1126
+
1104
1127
if (lex.get_token (tk)!=' <' )
1105
1128
return false ;
1106
1129
1107
1130
irept &template_parameters=decl.add (ID_template_parameters);
1108
1131
1132
+ #ifdef DEBUG
1133
+ std::cout << std::string (__indent, ' ' ) << " Parser::rTemplateDecl2 4\n " ;
1134
+ #endif
1135
+
1109
1136
if (!rTempArgList (template_parameters))
1110
1137
return false ;
1111
1138
1139
+ #ifdef DEBUG
1140
+ std::cout << std::string (__indent, ' ' ) << " Parser::rTemplateDecl2 5\n " ;
1141
+ #endif
1142
+
1112
1143
if (lex.get_token (tk)!=' >' )
1113
1144
return false ;
1114
1145
1146
+ #ifdef DEBUG
1147
+ std::cout << std::string (__indent, ' ' ) << " Parser::rTemplateDecl2 6\n " ;
1148
+ #endif
1149
+
1115
1150
// ignore nested TEMPLATE
1116
1151
while (lex.LookAhead (0 )==TOK_TEMPLATE)
1117
1152
{
@@ -1128,6 +1163,10 @@ bool Parser::rTemplateDecl2(typet &decl, TemplateDeclKind &kind)
1128
1163
return false ;
1129
1164
}
1130
1165
1166
+ #ifdef DEBUG
1167
+ std::cout << std::string (__indent, ' ' ) << " Parser::rTemplateDecl2 7\n " ;
1168
+ #endif
1169
+
1131
1170
if (template_parameters.get_sub ().empty ())
1132
1171
// template < > declaration
1133
1172
kind=tdk_specialization;
@@ -1188,6 +1227,10 @@ bool Parser::rTempArgDeclaration(cpp_declarationt &declaration)
1188
1227
1189
1228
if ((t0==TOK_CLASS || t0==TOK_TYPENAME))
1190
1229
{
1230
+ #ifdef DEBUG
1231
+ std::cout << std::string (__indent, ' ' ) << " Parser::rTempArgDeclaration 0.1\n " ;
1232
+ #endif
1233
+
1191
1234
cpp_token_buffert::post pos=lex.Save ();
1192
1235
1193
1236
cpp_tokent tk1;
@@ -1227,6 +1270,10 @@ bool Parser::rTempArgDeclaration(cpp_declarationt &declaration)
1227
1270
1228
1271
if (lex.LookAhead (0 )==' =' )
1229
1272
{
1273
+ #ifdef DEBUG
1274
+ std::cout << std::string (__indent, ' ' ) << " Parser::rTempArgDeclaration 0.2\n " ;
1275
+ #endif
1276
+
1230
1277
if (declarator.get_has_ellipsis ())
1231
1278
return false ;
1232
1279
@@ -1239,10 +1286,38 @@ bool Parser::rTempArgDeclaration(cpp_declarationt &declaration)
1239
1286
declarator.value ()=exprt (ID_type);
1240
1287
declarator.value ().type ().swap (default_type);
1241
1288
}
1289
+ #ifdef DEBUG
1290
+ std::cout << std::string (__indent, ' ' ) << " Parser::rTempArgDeclaration 0.3\n " ;
1291
+ #endif
1242
1292
1243
1293
if (lex.LookAhead (0 )==' ,' ||
1244
1294
lex.LookAhead (0 )==' >' )
1245
1295
return true ;
1296
+ #if 0
1297
+ else if(lex.LookAhead(0) == TOK_SHIFTRIGHT)
1298
+ {
1299
+ #ifdef DEBUG
1300
+ std::cout << std::string(__indent, ' ') << "Parser::rTempArgDeclaration 0.4\n";
1301
+ #endif
1302
+
1303
+ // turn >> into > >
1304
+ cpp_token_buffert::post pos=lex.Save();
1305
+ cpp_tokent tk;
1306
+ lex.get_token(tk);
1307
+ lex.Restore(pos);
1308
+ tk.kind='>';
1309
+ tk.text='>';
1310
+ lex.Replace(tk);
1311
+ lex.Insert(tk);
1312
+ DATA_INVARIANT(lex.LookAhead(0) == '>', "should be >");
1313
+ DATA_INVARIANT(lex.LookAhead(1) == '>', "should be >");
1314
+ return true;
1315
+ }
1316
+ #endif
1317
+ #ifdef DEBUG
1318
+ std::cout << std::string (__indent, ' ' ) << " Parser::rTempArgDeclaration 0.5\n " ;
1319
+ #endif
1320
+
1246
1321
1247
1322
lex.Restore (pos);
1248
1323
}
@@ -3968,7 +4043,8 @@ bool Parser::rTemplateArgs(irept &template_args)
3968
4043
)
3969
4044
{
3970
4045
#ifdef DEBUG
3971
- std::cout << std::string (__indent, ' ' ) << " Parser::rTemplateArgs 4\n " ;
4046
+ std::cout << std::string (__indent, ' ' ) << " Parser::rTemplateArgs 4 " <<
4047
+ lex.LookAhead (0 ) << " \n " ;
3972
4048
#endif
3973
4049
3974
4050
// ok
@@ -3980,20 +4056,30 @@ bool Parser::rTemplateArgs(irept &template_args)
3980
4056
lex.Restore (pos);
3981
4057
exprt tmp;
3982
4058
if (rConditionalExpr (tmp, true ))
4059
+ {
4060
+ #ifdef DEBUG
4061
+ std::cout << std::string (__indent, ' ' ) << " Parser::rTemplateArgs 4.0\n " ;
4062
+ #endif
3983
4063
exp .id (ID_ambiguous);
4064
+ }
3984
4065
#ifdef DEBUG
3985
4066
std::cout << std::string (__indent, ' ' ) << " Parser::rTemplateArgs 4.1\n " ;
3986
4067
#endif
3987
4068
lex.Restore (pos);
3988
4069
rTypeNameOrFunctionType (a);
3989
4070
4071
+ #ifdef DEBUG
4072
+ std::cout << std::string (__indent, ' ' ) << " Parser::rTemplateArgs 4.1a " <<
4073
+ lex.LookAhead (0 ) << " \n " ;
4074
+ #endif
3990
4075
if (lex.LookAhead (0 )==TOK_ELLIPSIS)
3991
4076
{
3992
4077
lex.get_token (tk1);
3993
4078
exp .set (ID_ellipsis, true );
3994
4079
}
3995
4080
#ifdef DEBUG
3996
- std::cout << std::string (__indent, ' ' ) << " Parser::rTemplateArgs 4.2\n " ;
4081
+ std::cout << std::string (__indent, ' ' ) << " Parser::rTemplateArgs 4.2 " <<
4082
+ lex.LookAhead (0 ) << " \n " ;
3997
4083
#endif
3998
4084
}
3999
4085
else
0 commit comments