Skip to content

Commit a29b952

Browse files
committed
More DEBUG
1 parent 83c69c6 commit a29b952

File tree

2 files changed

+88
-9
lines changed

2 files changed

+88
-9
lines changed

src/cpp/cpp_token_buffer.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,11 @@ class cpp_token_buffert
4949
void Restore(post pos);
5050
void Replace(const cpp_tokent &token);
5151
void Insert(const cpp_tokent &token);
52+
const cpp_tokent &peek()
53+
{
54+
PRECONDITION(current_pos <= token_vector.size());
55+
return *token_vector[current_pos];
56+
}
5257

5358
void clear()
5459
{

src/cpp/parse.cpp

Lines changed: 83 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ Author: Daniel Kroening, [email protected]
2323
#include "cpp_member_spec.h"
2424
#include "cpp_enum_type.h"
2525

26-
#define DEBUG
26+
// #define DEBUG
2727
#ifdef DEBUG
2828
#include <iostream>
2929

@@ -3157,7 +3157,10 @@ bool Parser::rDeclarator(
31573157
}
31583158

31593159
#ifdef DEBUG
3160-
std::cout << std::string(__indent, ' ') << "Parser::rDeclarator2 2\n";
3160+
std::cout << std::string(__indent, ' ') << "Parser::rDeclarator2 2 "
3161+
<< lex.LookAhead(0)
3162+
<< ' ' << lex.peek().text
3163+
<< '\n';
31613164
#endif
31623165

31633166
t=lex.LookAhead(0);
@@ -3621,7 +3624,11 @@ bool Parser::rName(irept &name)
36213624
{
36223625
#ifdef DEBUG
36233626
indenter _i;
3624-
std::cout << std::string(__indent, ' ') << "Parser::rName 0\n";
3627+
std::cout << std::string(__indent, ' ') << "Parser::rName 0 "
3628+
<< lex.LookAhead(0)
3629+
<< ' ' << lex.peek().text
3630+
<< ' ' << lex.Save()
3631+
<< '\n';
36253632
#endif
36263633

36273634
name=cpp_namet();
@@ -4167,9 +4174,20 @@ bool Parser::rArgDeclListOrInit(
41674174
bool &is_args,
41684175
bool maybe_init)
41694176
{
4177+
#ifdef DEBUG
4178+
indenter _i;
4179+
std::cout << std::string(__indent, ' ') << "Parser::rArgDeclListOrInit 0 "
4180+
<< lex.LookAhead(0)
4181+
<< ' ' << lex.peek().text
4182+
<< '\n';
4183+
#endif
4184+
41704185
cpp_token_buffert::post pos=lex.Save();
41714186
if(maybe_init)
41724187
{
4188+
#ifdef DEBUG
4189+
std::cout << std::string(__indent, ' ') << "Parser::rArgDeclListOrInit 1" << std::endl;
4190+
#endif
41734191
if(rFunctionArguments(arglist))
41744192
if(lex.LookAhead(0)==')')
41754193
{
@@ -4183,12 +4201,18 @@ bool Parser::rArgDeclListOrInit(
41834201
}
41844202
else
41854203
{
4204+
#ifdef DEBUG
4205+
std::cout << std::string(__indent, ' ') << "Parser::rArgDeclListOrInit 2" << std::endl;
4206+
#endif
41864207
is_args = rArgDeclList(arglist);
41874208

41884209
if(is_args)
41894210
return true;
41904211
else
41914212
{
4213+
#ifdef DEBUG
4214+
std::cout << std::string(__indent, ' ') << "Parser::rArgDeclListOrInit 3" << std::endl;
4215+
#endif
41924216
lex.Restore(pos);
41934217
// encode.Clear();
41944218
return rFunctionArguments(arglist);
@@ -4203,25 +4227,45 @@ bool Parser::rArgDeclListOrInit(
42034227
*/
42044228
bool Parser::rArgDeclList(irept &arglist)
42054229
{
4230+
#ifdef DEBUG
4231+
indenter _i;
4232+
std::cout << std::string(__indent, ' ') << "Parser::rArgDeclList 0 "
4233+
<< lex.LookAhead(0)
4234+
<< ' ' << lex.peek().text
4235+
<< '\n';
4236+
#endif
4237+
42064238
irept list;
42074239

42084240
list.clear();
42094241
for(;;)
42104242
{
4243+
#ifdef DEBUG
4244+
std::cout << std::string(__indent, ' ') << "Parser::rArgDeclList 1" << std::endl;
4245+
#endif
42114246
cpp_declarationt declaration;
42124247

42134248
int t=lex.LookAhead(0);
42144249
if(t==')')
42154250
break;
42164251
else if(t==TOK_ELLIPSIS)
42174252
{
4253+
#ifdef DEBUG
4254+
std::cout << std::string(__indent, ' ') << "Parser::rArgDeclList 2" << std::endl;
4255+
#endif
42184256
cpp_tokent tk;
42194257
lex.get_token(tk);
42204258
list.get_sub().push_back(irept(ID_ellipsis));
42214259
break;
42224260
}
42234261
else if(rArgDeclaration(declaration))
42244262
{
4263+
#ifdef DEBUG
4264+
std::cout << std::string(__indent, ' ') << "Parser::rArgDeclList 3 "
4265+
<< lex.LookAhead(0)
4266+
<< ' ' << lex.peek().text
4267+
<< '\n';
4268+
#endif
42254269
cpp_tokent tk;
42264270

42274271
list.get_sub().push_back(irept(irep_idt()));
@@ -4306,7 +4350,7 @@ bool Parser::rInitializeExpr(exprt &expr)
43064350
indenter _i;
43074351
std::cout << std::string(__indent, ' ') << "Parser::rInitializeExpr 0 "
43084352
<< lex.LookAhead(0)
4309-
<< ' ' << lex.current_token().text
4353+
<< ' ' << lex.peek().text
43104354
<< '\n';
43114355
#endif
43124356

@@ -4402,6 +4446,11 @@ bool Parser::rInitializeExpr(exprt &expr)
44024446
*/
44034447
bool Parser::rFunctionArguments(exprt &args)
44044448
{
4449+
#ifdef DEBUG
4450+
indenter _i;
4451+
std::cout << std::string(__indent, ' ') << "Parser::rFunctionArguments 1\n";
4452+
#endif
4453+
44054454
exprt exp;
44064455
cpp_tokent tk;
44074456

@@ -4411,11 +4460,19 @@ bool Parser::rFunctionArguments(exprt &args)
44114460

44124461
for(;;)
44134462
{
4463+
#ifdef DEBUG
4464+
std::cout << std::string(__indent, ' ') << "Parser::rFunctionArguments 2\n";
4465+
#endif
4466+
44144467
if(!rInitializeExpr(exp))
44154468
return false;
44164469

44174470
args.add_to_operands(std::move(exp));
44184471

4472+
#ifdef DEBUG
4473+
std::cout << std::string(__indent, ' ') << "Parser::rFunctionArguments 3\n";
4474+
#endif
4475+
44194476
if(lex.LookAhead(0)==TOK_ELLIPSIS &&
44204477
(lex.LookAhead(1)==')' || lex.LookAhead(1)==','))
44214478
{
@@ -5111,7 +5168,10 @@ bool Parser::rLogicalOrExpr(exprt &exp, bool template_args)
51115168
{
51125169
#ifdef DEBUG
51135170
indenter _i;
5114-
std::cout << std::string(__indent, ' ') << "Parser::rLogicalOrExpr 0\n";
5171+
std::cout << std::string(__indent, ' ') << "Parser::rLogicalOrExpr 0 "
5172+
<< lex.LookAhead(0)
5173+
<< ' ' << lex.peek().text
5174+
<< '\n';
51155175
#endif
51165176

51175177
if(!rLogicalAndExpr(exp, template_args))
@@ -6518,7 +6578,11 @@ bool Parser::rPostfixExpr(exprt &exp)
65186578
{
65196579
#ifdef DEBUG
65206580
indenter _i;
6521-
std::cout << std::string(__indent, ' ') << "Parser::rPostfixExpr 0\n";
6581+
std::cout << std::string(__indent, ' ') << "Parser::rPostfixExpr 0 "
6582+
<< lex.LookAhead(0)
6583+
<< ' ' << lex.peek().text
6584+
<< ' ' << lex.Save()
6585+
<< '\n';
65226586
#endif
65236587

65246588
typet type;
@@ -6574,13 +6638,16 @@ bool Parser::rPostfixExpr(exprt &exp)
65746638
else
65756639
{
65766640
lex.Restore(pos);
6641+
#ifdef DEBUG
6642+
std::cout << std::string(__indent, ' ') << "Parser::rPostfixExpr 0.2\n";
6643+
#endif
65776644

65786645
exprt type_or_function_name;
65796646
if(rName(type_or_function_name) &&
65806647
(lex.LookAhead(0) == '(' || lex.LookAhead(0) == '{'))
65816648
{
65826649
#ifdef DEBUG
6583-
std::cout << std::string(__indent, ' ') << "Parser::rPostfixExpr 0.2\n";
6650+
std::cout << std::string(__indent, ' ') << "Parser::rPostfixExpr 0.3\n";
65846651
#endif
65856652

65866653
cpp_tokent tk;
@@ -6612,6 +6679,9 @@ bool Parser::rPostfixExpr(exprt &exp)
66126679
}
66136680
else
66146681
{
6682+
#ifdef DEBUG
6683+
std::cout << std::string(__indent, ' ') << "Parser::rPostfixExpr 0.4\n";
6684+
#endif
66156685
lex.Restore(pos);
66166686
if(!rPrimaryExpr(exp))
66176687
return false;
@@ -7011,7 +7081,7 @@ bool Parser::rPrimaryExpr(exprt &exp)
70117081
#ifdef DEBUG
70127082
indenter _i;
70137083
std::cout << std::string(__indent, ' ') << "Parser::rPrimaryExpr 0 "
7014-
<< lex.LookAhead(0) << ' ' << lex.current_token().text << '\n';
7084+
<< lex.LookAhead(0) << ' ' << lex.peek().text << '\n';
70157085
#endif
70167086

70177087
switch(lex.LookAhead(0))
@@ -7175,7 +7245,11 @@ bool Parser::rVarName(exprt &name)
71757245
{
71767246
#ifdef DEBUG
71777247
indenter _i;
7178-
std::cout << std::string(__indent, ' ') << "Parser::rVarName 0\n";
7248+
std::cout << std::string(__indent, ' ') << "Parser::rVarName 0 "
7249+
<< lex.LookAhead(0)
7250+
<< ' ' << lex.peek().text
7251+
<< ' ' << lex.Save()
7252+
<< '\n';
71797253
#endif
71807254

71817255
if(rVarNameCore(name))

0 commit comments

Comments
 (0)