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