Skip to content

Commit 6a3db2f

Browse files
MatWisetautschnig
authored andcommitted
Adjust STL label parsing
Changes the accepted format for labels and wraps instructions that have a label in a code label.
1 parent 8f30441 commit 6a3db2f

File tree

5 files changed

+25
-17
lines changed

5 files changed

+25
-17
lines changed

src/statement-list/converters/convert_string_value.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,12 @@ string_constantt convert_version(const std::string &src)
3232
return result;
3333
}
3434

35-
code_labelt convert_label(const std::string &src)
35+
string_constantt convert_label(const std::string &src)
3636
{
3737
// Cut the trailing colon
3838
std::string value = src.substr(0, src.length() - 1);
3939

40-
return code_labelt{value, codet(ID_label)};
40+
string_constantt result{value};
41+
result.set(ID_statement_list_type, ID_label);
42+
return result;
4143
}

src/statement-list/converters/convert_string_value.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ string_constantt convert_version(const std::string &src);
3232

3333
/// Converts a string into a Statement List label.
3434
/// \param src: String returned by the parser.
35-
/// \return Code label expression representing the label.
36-
code_labelt convert_label(const std::string &src);
35+
/// \return String constant representing the label.
36+
string_constantt convert_label(const std::string &src);
3737

3838
#endif // CPROVER_STATEMENT_LIST_CONVERTERS_CONVERT_STRING_VALUE_H

src/statement-list/parser.y

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -688,7 +688,7 @@ Oom_IL_Instruction:
688688
;
689689

690690
IL_Instruction:
691-
Opt_Label Opt_Instruction ';'
691+
Opt_Label Instruction ';'
692692
{
693693
$$ = $2;
694694
parser_stack($$).add_to_operands(std::move(parser_stack($1)));
@@ -708,14 +708,9 @@ IL_Label:
708708
TOK_LABEL
709709
;
710710

711-
Opt_Instruction:
711+
Instruction:
712712
IL_Simple_Operation
713713
| IL_Invocation
714-
| /* nothing */
715-
{
716-
newstack($$);
717-
parser_stack($$).id(ID_statement_list_instruction);
718-
}
719714
;
720715

721716
IL_Simple_Operation:

src/statement-list/scanner.l

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,7 @@ void statement_list_scanner_init()
272272
return TOK_IDENTIFIER;
273273
}
274274

275-
[a-zA-Z_\.][a-zA-Z0-9_\.]*: {
275+
[a-zA-Z_][a-zA-Z0-9_]*: {
276276
newstack(yystatement_listlval);
277277
parser_stack(yystatement_listlval) =
278278
convert_label(yytext);

src/statement-list/statement_list_parser.cpp

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@ static exprt find_network_instructions(const exprt &network)
248248
UNREACHABLE; // Network expression should always have an instruction list
249249
}
250250

251-
/// Adds all valid instructions to the given network.
251+
/// Adds all valid instructions to the given network.
252252
/// \param network: The network to which the instructions belong.
253253
/// \param instructions: The root expression of a valid instruction list.
254254
static void find_instructions(
@@ -258,13 +258,24 @@ static void find_instructions(
258258
for(const exprt &instruction_expr : instructions.operands())
259259
{
260260
statement_list_parse_treet::instructiont instruction;
261+
261262
codet code_token(to_multi_ary_expr(instruction_expr).op0().id());
262-
for(const exprt &operand : instruction_expr.operands())
263+
string_constantt label{ID_nil};
264+
for(auto op_it = std::next(instruction_expr.operands().begin());
265+
op_it != end(instruction_expr.operands());
266+
++op_it)
263267
{
264-
if(operand.is_not_nil() && operand.id() != code_token.get_statement())
265-
code_token.add_to_operands(operand);
268+
if(op_it->get(ID_statement_list_type) == ID_label)
269+
label = to_string_constant(*op_it);
270+
else if(op_it->is_not_nil())
271+
code_token.add_to_operands(*op_it);
266272
}
267-
instruction.add_token(code_token);
273+
274+
if(label.get_value() == ID_nil)
275+
instruction.add_token(code_token);
276+
else
277+
instruction.add_token(code_labelt{label.get_value(), code_token});
278+
268279
network.add_instruction(instruction);
269280
}
270281
}

0 commit comments

Comments
 (0)