@@ -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
@@ -1030,6 +1031,11 @@ bool Parser::rLinkageBody(cpp_linkage_spect::itemst &items)
10301031*/
10311032bool Parser::rTemplateDecl (cpp_declarationt &decl)
10321033{
1034+ #ifdef DEBUG
1035+ indenter _i;
1036+ std::cout << std::string (__indent, ' ' ) << " Parser::rTemplateDecl 1\n " ;
1037+ #endif
1038+
10331039 TemplateDeclKind kind=tdk_unknown;
10341040
10351041 make_sub_scope (" #template" , new_scopet::kindt::TEMPLATE);
@@ -1039,6 +1045,10 @@ bool Parser::rTemplateDecl(cpp_declarationt &decl)
10391045 if (!rTemplateDecl2 (template_type, kind))
10401046 return false ;
10411047
1048+ #ifdef DEBUG
1049+ std::cout << std::string (__indent, ' ' ) << " Parser::rTemplateDecl 2\n " ;
1050+ #endif
1051+
10421052 cpp_declarationt body;
10431053 if (lex.LookAhead (0 )==TOK_USING)
10441054 {
@@ -1086,11 +1096,20 @@ bool Parser::rTemplateDecl(cpp_declarationt &decl)
10861096
10871097bool Parser::rTemplateDecl2 (typet &decl, TemplateDeclKind &kind)
10881098{
1099+ #ifdef DEBUG
1100+ indenter _i;
1101+ std::cout << std::string (__indent, ' ' ) << " Parser::rTemplateDecl2 1\n " ;
1102+ #endif
1103+
10891104 cpp_tokent tk;
10901105
10911106 if (lex.get_token (tk)!=TOK_TEMPLATE)
10921107 return false ;
10931108
1109+ #ifdef DEBUG
1110+ std::cout << std::string (__indent, ' ' ) << " Parser::rTemplateDecl2 2\n " ;
1111+ #endif
1112+
10941113 decl=typet (ID_template);
10951114 set_location (decl, tk);
10961115
@@ -1101,17 +1120,33 @@ bool Parser::rTemplateDecl2(typet &decl, TemplateDeclKind &kind)
11011120 return true ; // ignore TEMPLATE
11021121 }
11031122
1123+ #ifdef DEBUG
1124+ std::cout << std::string (__indent, ' ' ) << " Parser::rTemplateDecl2 3\n " ;
1125+ #endif
1126+
11041127 if (lex.get_token (tk)!=' <' )
11051128 return false ;
11061129
11071130 irept &template_parameters=decl.add (ID_template_parameters);
11081131
1132+ #ifdef DEBUG
1133+ std::cout << std::string (__indent, ' ' ) << " Parser::rTemplateDecl2 4\n " ;
1134+ #endif
1135+
11091136 if (!rTempArgList (template_parameters))
11101137 return false ;
11111138
1139+ #ifdef DEBUG
1140+ std::cout << std::string (__indent, ' ' ) << " Parser::rTemplateDecl2 5\n " ;
1141+ #endif
1142+
11121143 if (lex.get_token (tk)!=' >' )
11131144 return false ;
11141145
1146+ #ifdef DEBUG
1147+ std::cout << std::string (__indent, ' ' ) << " Parser::rTemplateDecl2 6\n " ;
1148+ #endif
1149+
11151150 // ignore nested TEMPLATE
11161151 while (lex.LookAhead (0 )==TOK_TEMPLATE)
11171152 {
@@ -1128,6 +1163,10 @@ bool Parser::rTemplateDecl2(typet &decl, TemplateDeclKind &kind)
11281163 return false ;
11291164 }
11301165
1166+ #ifdef DEBUG
1167+ std::cout << std::string (__indent, ' ' ) << " Parser::rTemplateDecl2 7\n " ;
1168+ #endif
1169+
11311170 if (template_parameters.get_sub ().empty ())
11321171 // template < > declaration
11331172 kind=tdk_specialization;
@@ -1188,6 +1227,10 @@ bool Parser::rTempArgDeclaration(cpp_declarationt &declaration)
11881227
11891228 if ((t0==TOK_CLASS || t0==TOK_TYPENAME))
11901229 {
1230+ #ifdef DEBUG
1231+ std::cout << std::string (__indent, ' ' ) << " Parser::rTempArgDeclaration 0.1\n " ;
1232+ #endif
1233+
11911234 cpp_token_buffert::post pos=lex.Save ();
11921235
11931236 cpp_tokent tk1;
@@ -1227,6 +1270,10 @@ bool Parser::rTempArgDeclaration(cpp_declarationt &declaration)
12271270
12281271 if (lex.LookAhead (0 )==' =' )
12291272 {
1273+ #ifdef DEBUG
1274+ std::cout << std::string (__indent, ' ' ) << " Parser::rTempArgDeclaration 0.2\n " ;
1275+ #endif
1276+
12301277 if (declarator.get_has_ellipsis ())
12311278 return false ;
12321279
@@ -1239,10 +1286,38 @@ bool Parser::rTempArgDeclaration(cpp_declarationt &declaration)
12391286 declarator.value ()=exprt (ID_type);
12401287 declarator.value ().type ().swap (default_type);
12411288 }
1289+ #ifdef DEBUG
1290+ std::cout << std::string (__indent, ' ' ) << " Parser::rTempArgDeclaration 0.3\n " ;
1291+ #endif
12421292
12431293 if (lex.LookAhead (0 )==' ,' ||
12441294 lex.LookAhead (0 )==' >' )
12451295 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+
12461321
12471322 lex.Restore (pos);
12481323 }
@@ -3968,7 +4043,8 @@ bool Parser::rTemplateArgs(irept &template_args)
39684043 )
39694044 {
39704045#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 " ;
39724048#endif
39734049
39744050 // ok
@@ -3980,20 +4056,30 @@ bool Parser::rTemplateArgs(irept &template_args)
39804056 lex.Restore (pos);
39814057 exprt tmp;
39824058 if (rConditionalExpr (tmp, true ))
4059+ {
4060+ #ifdef DEBUG
4061+ std::cout << std::string (__indent, ' ' ) << " Parser::rTemplateArgs 4.0\n " ;
4062+ #endif
39834063 exp.id (ID_ambiguous);
4064+ }
39844065#ifdef DEBUG
39854066 std::cout << std::string (__indent, ' ' ) << " Parser::rTemplateArgs 4.1\n " ;
39864067#endif
39874068 lex.Restore (pos);
39884069 rTypeNameOrFunctionType (a);
39894070
4071+ #ifdef DEBUG
4072+ std::cout << std::string (__indent, ' ' ) << " Parser::rTemplateArgs 4.1a " <<
4073+ lex.LookAhead (0 ) << " \n " ;
4074+ #endif
39904075 if (lex.LookAhead (0 )==TOK_ELLIPSIS)
39914076 {
39924077 lex.get_token (tk1);
39934078 exp.set (ID_ellipsis, true );
39944079 }
39954080#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 " ;
39974083#endif
39984084 }
39994085 else
0 commit comments