Skip to content

Commit 6b83629

Browse files
author
kroening
committed
C++--11 requires to support both > > and >> to close
nested template arguments git-svn-id: svn+ssh://svn.cprover.org/srv/svn/cbmc/trunk@6098 6afb6bc1-c8e4-404c-8f48-9ae832c5b171
1 parent 9d4e9fa commit 6b83629

File tree

4 files changed

+61
-13
lines changed

4 files changed

+61
-13
lines changed

src/cpp/cpp_token.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ class cpp_tokent
2121
std::string text;
2222
unsigned line_no;
2323
irep_idt filename;
24-
unsigned pos;
2524

2625
void clear()
2726
{
@@ -30,7 +29,6 @@ class cpp_tokent
3029
text="";
3130
line_no=0;
3231
filename="";
33-
pos=0;
3432
}
3533

3634
void swap(cpp_tokent &token)
@@ -40,7 +38,6 @@ class cpp_tokent
4038
text.swap(token.text);
4139
std::swap(line_no, token.line_no);
4240
filename.swap(token.filename);
43-
std::swap(pos, token.pos);
4441
}
4542
};
4643

src/cpp/cpp_token_buffer.cpp

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,6 @@ void cpp_token_buffert::read_token()
148148
//std::cout << "TOKEN: " << kind << " " << tokens.back().text << std::endl;
149149

150150
tokens.back().kind=kind;
151-
tokens.back().pos=token_vector.size()-1;
152151

153152
//std::cout << "II: " << token_vector.back()->kind << std::endl;
154153
//std::cout << "I2: " << token_vector.size() << std::endl;
@@ -187,3 +186,46 @@ void cpp_token_buffert::Restore(post pos)
187186
{
188187
current_pos=pos;
189188
}
189+
190+
/*******************************************************************\
191+
192+
Function: cpp_token_buffert::Replace
193+
194+
Inputs:
195+
196+
Outputs:
197+
198+
Purpose:
199+
200+
\*******************************************************************/
201+
202+
void cpp_token_buffert::Replace(const cpp_tokent &token)
203+
{
204+
assert(current_pos<=token_vector.size());
205+
206+
if(token_vector.size()==current_pos) read_token();
207+
208+
*token_vector[current_pos]=token;
209+
}
210+
211+
/*******************************************************************\
212+
213+
Function: cpp_token_buffert::Replace
214+
215+
Inputs:
216+
217+
Outputs:
218+
219+
Purpose:
220+
221+
\*******************************************************************/
222+
223+
void cpp_token_buffert::Insert(const cpp_tokent &token)
224+
{
225+
assert(current_pos<=token_vector.size());
226+
227+
tokens.push_back(token);
228+
229+
token_vector.insert(token_vector.begin()+current_pos,
230+
--tokens.end());
231+
}

src/cpp/cpp_token_buffer.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ class cpp_token_buffert
2727

2828
post Save();
2929
void Restore(post pos);
30+
void Replace(const cpp_tokent &token);
31+
void Insert(const cpp_tokent &token);
3032

3133
void clear()
3234
{

src/cpp/parse.cpp

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4208,8 +4208,11 @@ bool Parser::rTemplateArgs(irept &template_args)
42084208

42094209
// try type name first
42104210
if(rTypeNameOrFunctionType(a) &&
4211-
((lex.LookAhead(0) == '>' || lex.LookAhead(0) == ',') ||
4212-
(lex.LookAhead(0)==TOK_ELLIPSIS && lex.LookAhead(1) == '>'))
4211+
((lex.LookAhead(0) == '>' || lex.LookAhead(0) == ',' ||
4212+
lex.LookAhead(0)==TOK_SHIFTRIGHT) ||
4213+
(lex.LookAhead(0)==TOK_ELLIPSIS &&
4214+
(lex.LookAhead(1) == '>' ||
4215+
lex.LookAhead(1)==TOK_SHIFTRIGHT)))
42134216
)
42144217
{
42154218
#ifdef DEBUG
@@ -4270,6 +4273,7 @@ bool Parser::rTemplateArgs(irept &template_args)
42704273
template_args.get_sub().push_back(irept(irep_idt()));
42714274
template_args.get_sub().back().swap(exp);
42724275

4276+
pos=lex.Save();
42734277
cpp_tokent tk2;
42744278
switch(lex.get_token(tk2))
42754279
{
@@ -4280,13 +4284,14 @@ bool Parser::rTemplateArgs(irept &template_args)
42804284
break;
42814285

42824286
case TOK_SHIFTRIGHT: // turn >> into > >
4283-
// the newer C++ standards frown on this!
4284-
4285-
// turn >> into > > // TODO
4286-
//lex.GetOnlyClosingBracket(tk2);
4287-
//temp_args=Ptree::List(new Leaf(tk1), args,
4288-
// new Leaf(tk2.ptr, 1));
4289-
return false;
4287+
lex.Restore(pos);
4288+
tk2.kind='>';
4289+
tk2.text='>';
4290+
lex.Replace(tk2);
4291+
lex.Insert(tk2);
4292+
assert(lex.LookAhead(0)=='>');
4293+
assert(lex.LookAhead(1)=='>');
4294+
return true;
42904295

42914296
default:
42924297
return false;
@@ -7902,6 +7907,8 @@ bool Parser::maybeTemplateArgs()
79027907
}
79037908
else if(u=='\0' || u==';' || u=='}')
79047909
return false;
7910+
else if(u==TOK_SHIFTRIGHT && n>=2)
7911+
n-=2;
79057912
79067913
#ifdef DEBUG
79077914
std::cout << std::string(__indent, ' ') << "Parser::maybeTemplateArgs 4\n";

0 commit comments

Comments
 (0)