Skip to content

Commit dfdfd22

Browse files
committed
SMV: add source locations to identifiers
This adds a constructor to smv_identifier_exprt with source location, and uses this constructor in the parser.
1 parent acc4ccd commit dfdfd22

File tree

2 files changed

+18
-19
lines changed

2 files changed

+18
-19
lines changed

src/smvlang/parser.y

Lines changed: 9 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -411,17 +411,13 @@ ivar_declaration:
411411
ivar_simple_var_list:
412412
identifier ':' simple_type_specifier ';'
413413
{
414-
irep_idt identifier = stack_expr($1).id();
415-
stack_expr($1).id(ID_smv_identifier);
416-
stack_expr($1).set(ID_identifier, identifier);
417-
PARSER.module->add_ivar(stack_expr($1), stack_type($3));
414+
smv_identifier_exprt identifier{stack_expr($1).id(), PARSER.source_location()};
415+
PARSER.module->add_ivar(std::move(identifier), stack_type($3));
418416
}
419417
| ivar_simple_var_list identifier ':' simple_type_specifier ';'
420418
{
421-
irep_idt identifier = stack_expr($2).id();
422-
stack_expr($2).id(ID_smv_identifier);
423-
stack_expr($2).set(ID_identifier, identifier);
424-
PARSER.module->add_ivar(stack_expr($2), stack_type($4));
419+
smv_identifier_exprt identifier{stack_expr($2).id(), PARSER.source_location()};
420+
PARSER.module->add_ivar(std::move(identifier), stack_type($4));
425421
}
426422
;
427423

@@ -686,11 +682,8 @@ enum_element: IDENTIFIER_Token
686682
{
687683
$$=$1;
688684
PARSER.module->enum_set.insert(stack_expr($1).id_string());
689-
690-
exprt expr(ID_smv_identifier);
691-
expr.set(ID_identifier, stack_expr($1).id());
692-
PARSER.set_source_location(expr);
693-
PARSER.module->add_enum(std::move(expr));
685+
PARSER.module->add_enum(
686+
smv_identifier_exprt{stack_expr($1).id(), PARSER.source_location()});
694687
}
695688
;
696689

@@ -795,9 +788,7 @@ basic_expr : constant
795788
// This rule is part of "complex_identifier" in the NuSMV manual.
796789
$$ = $1;
797790
irep_idt identifier = stack_expr($$).id();
798-
stack_expr($$).id(ID_smv_identifier);
799-
stack_expr($$).set(ID_identifier, identifier);
800-
PARSER.set_source_location(stack_expr($$));
791+
stack_expr($$) = smv_identifier_exprt{identifier, PARSER.source_location()};
801792
}
802793
| basic_expr DOT_Token IDENTIFIER_Token
803794
{
@@ -961,9 +952,8 @@ complex_identifier:
961952
identifier
962953
{
963954
$$ = $1;
964-
irep_idt identifier = stack_expr($$).id();
965-
stack_expr($$).id(ID_smv_identifier);
966-
stack_expr($$).set(ID_identifier, identifier);
955+
auto identifier = stack_expr($$).id();
956+
stack_expr($$) = smv_identifier_exprt{identifier, PARSER.source_location()};
967957
}
968958
| complex_identifier DOT_Token QIDENTIFIER_Token
969959
{

src/smvlang/smv_expr.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -337,6 +337,15 @@ class smv_identifier_exprt : public nullary_exprt
337337
identifier(_identifier);
338338
}
339339

340+
explicit smv_identifier_exprt(
341+
irep_idt _identifier,
342+
source_locationt _location)
343+
: smv_identifier_exprt{_identifier}
344+
{
345+
if(_location.is_not_nil())
346+
add_source_location() = _location;
347+
}
348+
340349
irep_idt identifier() const
341350
{
342351
return get(ID_identifier);

0 commit comments

Comments
 (0)