Skip to content

Commit fa80826

Browse files
committed
DEBUG
1 parent 29b9e73 commit fa80826

File tree

1 file changed

+88
-2
lines changed

1 file changed

+88
-2
lines changed

src/cpp/parse.cpp

+88-2
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ Author: Daniel Kroening, [email protected]
2323
#include "cpp_member_spec.h"
2424
#include "cpp_enum_type.h"
2525

26+
#define DEBUG
2627
#ifdef DEBUG
2728
#include <iostream>
2829

@@ -1046,6 +1047,11 @@ bool Parser::rLinkageBody(cpp_linkage_spect::itemst &items)
10461047
*/
10471048
bool Parser::rTemplateDecl(cpp_declarationt &decl)
10481049
{
1050+
#ifdef DEBUG
1051+
indenter _i;
1052+
std::cout << std::string(__indent, ' ') << "Parser::rTemplateDecl 1\n";
1053+
#endif
1054+
10491055
TemplateDeclKind kind=tdk_unknown;
10501056

10511057
make_sub_scope("#template", new_scopet::kindt::TEMPLATE);
@@ -1055,6 +1061,10 @@ bool Parser::rTemplateDecl(cpp_declarationt &decl)
10551061
if(!rTemplateDecl2(template_type, kind))
10561062
return false;
10571063

1064+
#ifdef DEBUG
1065+
std::cout << std::string(__indent, ' ') << "Parser::rTemplateDecl 2\n";
1066+
#endif
1067+
10581068
cpp_declarationt body;
10591069
if(lex.LookAhead(0)==TOK_USING)
10601070
{
@@ -1102,11 +1112,20 @@ bool Parser::rTemplateDecl(cpp_declarationt &decl)
11021112

11031113
bool Parser::rTemplateDecl2(typet &decl, TemplateDeclKind &kind)
11041114
{
1115+
#ifdef DEBUG
1116+
indenter _i;
1117+
std::cout << std::string(__indent, ' ') << "Parser::rTemplateDecl2 1\n";
1118+
#endif
1119+
11051120
cpp_tokent tk;
11061121

11071122
if(lex.get_token(tk)!=TOK_TEMPLATE)
11081123
return false;
11091124

1125+
#ifdef DEBUG
1126+
std::cout << std::string(__indent, ' ') << "Parser::rTemplateDecl2 2\n";
1127+
#endif
1128+
11101129
decl=typet(ID_template);
11111130
set_location(decl, tk);
11121131

@@ -1117,17 +1136,33 @@ bool Parser::rTemplateDecl2(typet &decl, TemplateDeclKind &kind)
11171136
return true; // ignore TEMPLATE
11181137
}
11191138

1139+
#ifdef DEBUG
1140+
std::cout << std::string(__indent, ' ') << "Parser::rTemplateDecl2 3\n";
1141+
#endif
1142+
11201143
if(lex.get_token(tk)!='<')
11211144
return false;
11221145

11231146
irept &template_parameters=decl.add(ID_template_parameters);
11241147

1148+
#ifdef DEBUG
1149+
std::cout << std::string(__indent, ' ') << "Parser::rTemplateDecl2 4\n";
1150+
#endif
1151+
11251152
if(!rTempArgList(template_parameters))
11261153
return false;
11271154

1155+
#ifdef DEBUG
1156+
std::cout << std::string(__indent, ' ') << "Parser::rTemplateDecl2 5\n";
1157+
#endif
1158+
11281159
if(lex.get_token(tk)!='>')
11291160
return false;
11301161

1162+
#ifdef DEBUG
1163+
std::cout << std::string(__indent, ' ') << "Parser::rTemplateDecl2 6\n";
1164+
#endif
1165+
11311166
// ignore nested TEMPLATE
11321167
while(lex.LookAhead(0)==TOK_TEMPLATE)
11331168
{
@@ -1144,6 +1179,10 @@ bool Parser::rTemplateDecl2(typet &decl, TemplateDeclKind &kind)
11441179
return false;
11451180
}
11461181

1182+
#ifdef DEBUG
1183+
std::cout << std::string(__indent, ' ') << "Parser::rTemplateDecl2 7\n";
1184+
#endif
1185+
11471186
if(template_parameters.get_sub().empty())
11481187
// template < > declaration
11491188
kind=tdk_specialization;
@@ -1204,6 +1243,10 @@ bool Parser::rTempArgDeclaration(cpp_declarationt &declaration)
12041243

12051244
if((t0==TOK_CLASS || t0==TOK_TYPENAME))
12061245
{
1246+
#ifdef DEBUG
1247+
std::cout << std::string(__indent, ' ') << "Parser::rTempArgDeclaration 0.1\n";
1248+
#endif
1249+
12071250
cpp_token_buffert::post pos=lex.Save();
12081251

12091252
cpp_tokent tk1;
@@ -1243,6 +1286,10 @@ bool Parser::rTempArgDeclaration(cpp_declarationt &declaration)
12431286

12441287
if(lex.LookAhead(0)=='=')
12451288
{
1289+
#ifdef DEBUG
1290+
std::cout << std::string(__indent, ' ') << "Parser::rTempArgDeclaration 0.2\n";
1291+
#endif
1292+
12461293
if(declarator.get_has_ellipsis())
12471294
return false;
12481295

@@ -1255,10 +1302,38 @@ bool Parser::rTempArgDeclaration(cpp_declarationt &declaration)
12551302
declarator.value()=exprt(ID_type);
12561303
declarator.value().type().swap(default_type);
12571304
}
1305+
#ifdef DEBUG
1306+
std::cout << std::string(__indent, ' ') << "Parser::rTempArgDeclaration 0.3\n";
1307+
#endif
12581308

12591309
if(lex.LookAhead(0)==',' ||
12601310
lex.LookAhead(0)=='>')
12611311
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+
12621337

12631338
lex.Restore(pos);
12641339
}
@@ -3984,7 +4059,8 @@ bool Parser::rTemplateArgs(irept &template_args)
39844059
)
39854060
{
39864061
#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";
39884064
#endif
39894065

39904066
// ok
@@ -3996,20 +4072,30 @@ bool Parser::rTemplateArgs(irept &template_args)
39964072
lex.Restore(pos);
39974073
exprt tmp;
39984074
if(rConditionalExpr(tmp, true))
4075+
{
4076+
#ifdef DEBUG
4077+
std::cout << std::string(__indent, ' ') << "Parser::rTemplateArgs 4.0\n";
4078+
#endif
39994079
exp.id(ID_ambiguous);
4080+
}
40004081
#ifdef DEBUG
40014082
std::cout << std::string(__indent, ' ') << "Parser::rTemplateArgs 4.1\n";
40024083
#endif
40034084
lex.Restore(pos);
40044085
rTypeNameOrFunctionType(a);
40054086

4087+
#ifdef DEBUG
4088+
std::cout << std::string(__indent, ' ') << "Parser::rTemplateArgs 4.1a " <<
4089+
lex.LookAhead(0) << "\n";
4090+
#endif
40064091
if(lex.LookAhead(0)==TOK_ELLIPSIS)
40074092
{
40084093
lex.get_token(tk1);
40094094
exp.set(ID_ellipsis, true);
40104095
}
40114096
#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";
40134099
#endif
40144100
}
40154101
else

0 commit comments

Comments
 (0)