@@ -23,6 +23,7 @@ Author: Daniel Kroening, kroening@cs.cmu.edu
2323#include " cpp_member_spec.h"
2424#include " cpp_enum_type.h"
2525
26+ #define DEBUG
2627#ifdef DEBUG
2728#include < iostream>
2829
@@ -1013,6 +1014,11 @@ bool Parser::rLinkageBody(cpp_linkage_spect::itemst &items)
10131014*/
10141015bool Parser::rTemplateDecl (cpp_declarationt &decl)
10151016{
1017+ #ifdef DEBUG
1018+ indenter _i;
1019+ std::cout << std::string (__indent, ' ' ) << " Parser::rTemplateDecl 1\n " ;
1020+ #endif
1021+
10161022 TemplateDeclKind kind=tdk_unknown;
10171023
10181024 make_sub_scope (" #template" , new_scopet::kindt::TEMPLATE);
@@ -1022,6 +1028,10 @@ bool Parser::rTemplateDecl(cpp_declarationt &decl)
10221028 if (!rTemplateDecl2 (template_type, kind))
10231029 return false ;
10241030
1031+ #ifdef DEBUG
1032+ std::cout << std::string (__indent, ' ' ) << " Parser::rTemplateDecl 2\n " ;
1033+ #endif
1034+
10251035 cpp_declarationt body;
10261036 if (lex.LookAhead (0 )==TOK_USING)
10271037 {
@@ -1069,11 +1079,20 @@ bool Parser::rTemplateDecl(cpp_declarationt &decl)
10691079
10701080bool Parser::rTemplateDecl2 (typet &decl, TemplateDeclKind &kind)
10711081{
1082+ #ifdef DEBUG
1083+ indenter _i;
1084+ std::cout << std::string (__indent, ' ' ) << " Parser::rTemplateDecl2 1\n " ;
1085+ #endif
1086+
10721087 cpp_tokent tk;
10731088
10741089 if (lex.get_token (tk)!=TOK_TEMPLATE)
10751090 return false ;
10761091
1092+ #ifdef DEBUG
1093+ std::cout << std::string (__indent, ' ' ) << " Parser::rTemplateDecl2 2\n " ;
1094+ #endif
1095+
10771096 decl=typet (ID_template);
10781097 set_location (decl, tk);
10791098
@@ -1084,17 +1103,33 @@ bool Parser::rTemplateDecl2(typet &decl, TemplateDeclKind &kind)
10841103 return true ; // ignore TEMPLATE
10851104 }
10861105
1106+ #ifdef DEBUG
1107+ std::cout << std::string (__indent, ' ' ) << " Parser::rTemplateDecl2 3\n " ;
1108+ #endif
1109+
10871110 if (lex.get_token (tk)!=' <' )
10881111 return false ;
10891112
10901113 irept &template_parameters=decl.add (ID_template_parameters);
10911114
1115+ #ifdef DEBUG
1116+ std::cout << std::string (__indent, ' ' ) << " Parser::rTemplateDecl2 4\n " ;
1117+ #endif
1118+
10921119 if (!rTempArgList (template_parameters))
10931120 return false ;
10941121
1122+ #ifdef DEBUG
1123+ std::cout << std::string (__indent, ' ' ) << " Parser::rTemplateDecl2 5\n " ;
1124+ #endif
1125+
10951126 if (lex.get_token (tk)!=' >' )
10961127 return false ;
10971128
1129+ #ifdef DEBUG
1130+ std::cout << std::string (__indent, ' ' ) << " Parser::rTemplateDecl2 6\n " ;
1131+ #endif
1132+
10981133 // ignore nested TEMPLATE
10991134 while (lex.LookAhead (0 )==TOK_TEMPLATE)
11001135 {
@@ -1111,6 +1146,10 @@ bool Parser::rTemplateDecl2(typet &decl, TemplateDeclKind &kind)
11111146 return false ;
11121147 }
11131148
1149+ #ifdef DEBUG
1150+ std::cout << std::string (__indent, ' ' ) << " Parser::rTemplateDecl2 7\n " ;
1151+ #endif
1152+
11141153 if (template_parameters.get_sub ().empty ())
11151154 // template < > declaration
11161155 kind=tdk_specialization;
@@ -1171,6 +1210,10 @@ bool Parser::rTempArgDeclaration(cpp_declarationt &declaration)
11711210
11721211 if ((t0==TOK_CLASS || t0==TOK_TYPENAME))
11731212 {
1213+ #ifdef DEBUG
1214+ std::cout << std::string (__indent, ' ' ) << " Parser::rTempArgDeclaration 0.1\n " ;
1215+ #endif
1216+
11741217 cpp_token_buffert::post pos=lex.Save ();
11751218
11761219 cpp_tokent tk1;
@@ -1210,6 +1253,10 @@ bool Parser::rTempArgDeclaration(cpp_declarationt &declaration)
12101253
12111254 if (lex.LookAhead (0 )==' =' )
12121255 {
1256+ #ifdef DEBUG
1257+ std::cout << std::string (__indent, ' ' ) << " Parser::rTempArgDeclaration 0.2\n " ;
1258+ #endif
1259+
12131260 if (declarator.get_has_ellipsis ())
12141261 return false ;
12151262
@@ -1222,10 +1269,38 @@ bool Parser::rTempArgDeclaration(cpp_declarationt &declaration)
12221269 declarator.value ()=exprt (ID_type);
12231270 declarator.value ().type ().swap (default_type);
12241271 }
1272+ #ifdef DEBUG
1273+ std::cout << std::string (__indent, ' ' ) << " Parser::rTempArgDeclaration 0.3\n " ;
1274+ #endif
12251275
12261276 if (lex.LookAhead (0 )==' ,' ||
12271277 lex.LookAhead (0 )==' >' )
12281278 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+
12291304
12301305 lex.Restore (pos);
12311306 }
@@ -3936,7 +4011,8 @@ bool Parser::rTemplateArgs(irept &template_args)
39364011 )
39374012 {
39384013#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 " ;
39404016#endif
39414017
39424018 // ok
@@ -3948,20 +4024,30 @@ bool Parser::rTemplateArgs(irept &template_args)
39484024 lex.Restore (pos);
39494025 exprt tmp;
39504026 if (rConditionalExpr (tmp, true ))
4027+ {
4028+ #ifdef DEBUG
4029+ std::cout << std::string (__indent, ' ' ) << " Parser::rTemplateArgs 4.0\n " ;
4030+ #endif
39514031 exp.id (ID_ambiguous);
4032+ }
39524033#ifdef DEBUG
39534034 std::cout << std::string (__indent, ' ' ) << " Parser::rTemplateArgs 4.1\n " ;
39544035#endif
39554036 lex.Restore (pos);
39564037 rTypeNameOrFunctionType (a);
39574038
4039+ #ifdef DEBUG
4040+ std::cout << std::string (__indent, ' ' ) << " Parser::rTemplateArgs 4.1a " <<
4041+ lex.LookAhead (0 ) << " \n " ;
4042+ #endif
39584043 if (lex.LookAhead (0 )==TOK_ELLIPSIS)
39594044 {
39604045 lex.get_token (tk1);
39614046 exp.set (ID_ellipsis, true );
39624047 }
39634048#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 " ;
39654051#endif
39664052 }
39674053 else
0 commit comments