Skip to content

Commit 66c892b

Browse files
authored
Merge pull request #1401 from diffblue/smv-identifier
SMV: add source locations to identifiers
2 parents ccf6184 + 7634268 commit 66c892b

File tree

2 files changed

+16
-19
lines changed

2 files changed

+16
-19
lines changed

src/smvlang/parser.y

Lines changed: 9 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -406,17 +406,13 @@ ivar_declaration:
406406
ivar_simple_var_list:
407407
identifier ':' simple_type_specifier ';'
408408
{
409-
irep_idt identifier = stack_expr($1).id();
410-
stack_expr($1).id(ID_smv_identifier);
411-
stack_expr($1).set(ID_identifier, identifier);
412-
PARSER.module->add_ivar(stack_expr($1), stack_type($3));
409+
smv_identifier_exprt identifier{stack_expr($1).id(), PARSER.source_location()};
410+
PARSER.module->add_ivar(std::move(identifier), stack_type($3));
413411
}
414412
| ivar_simple_var_list identifier ':' simple_type_specifier ';'
415413
{
416-
irep_idt identifier = stack_expr($2).id();
417-
stack_expr($2).id(ID_smv_identifier);
418-
stack_expr($2).set(ID_identifier, identifier);
419-
PARSER.module->add_ivar(stack_expr($2), stack_type($4));
414+
smv_identifier_exprt identifier{stack_expr($2).id(), PARSER.source_location()};
415+
PARSER.module->add_ivar(std::move(identifier), stack_type($4));
420416
}
421417
;
422418

@@ -681,11 +677,8 @@ enum_element: IDENTIFIER_Token
681677
{
682678
$$=$1;
683679
PARSER.module->enum_set.insert(stack_expr($1).id_string());
684-
685-
exprt expr(ID_smv_identifier);
686-
expr.set(ID_identifier, stack_expr($1).id());
687-
PARSER.set_source_location(expr);
688-
PARSER.module->add_enum(std::move(expr));
680+
PARSER.module->add_enum(
681+
smv_identifier_exprt{stack_expr($1).id(), PARSER.source_location()});
689682
}
690683
;
691684

@@ -790,9 +783,7 @@ basic_expr : constant
790783
// This rule is part of "complex_identifier" in the NuSMV manual.
791784
$$ = $1;
792785
irep_idt identifier = stack_expr($$).id();
793-
stack_expr($$).id(ID_smv_identifier);
794-
stack_expr($$).set(ID_identifier, identifier);
795-
PARSER.set_source_location(stack_expr($$));
786+
stack_expr($$) = smv_identifier_exprt{identifier, PARSER.source_location()};
796787
}
797788
| basic_expr DOT_Token IDENTIFIER_Token
798789
{
@@ -956,9 +947,8 @@ complex_identifier:
956947
identifier
957948
{
958949
$$ = $1;
959-
irep_idt identifier = stack_expr($$).id();
960-
stack_expr($$).id(ID_smv_identifier);
961-
stack_expr($$).set(ID_identifier, identifier);
950+
auto identifier = stack_expr($$).id();
951+
stack_expr($$) = smv_identifier_exprt{identifier, PARSER.source_location()};
962952
}
963953
| complex_identifier DOT_Token QIDENTIFIER_Token
964954
{

src/smvlang/smv_expr.h

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

340+
smv_identifier_exprt(irep_idt _identifier, source_locationt _location)
341+
: smv_identifier_exprt{_identifier}
342+
{
343+
if(_location.is_not_nil())
344+
add_source_location() = _location;
345+
}
346+
340347
irep_idt identifier() const
341348
{
342349
return get(ID_identifier);

0 commit comments

Comments
 (0)