Skip to content
This repository was archived by the owner on Jan 30, 2026. It is now read-only.

Commit bd3b3ee

Browse files
committed
Les references dans champ_evenent peuvent être des ref
1 parent 78fb2a6 commit bd3b3ee

1 file changed

Lines changed: 25 additions & 27 deletions

File tree

src/mlang/m_frontend/validator.ml

Lines changed: 25 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1525,29 +1525,8 @@ let check_var_space (m_sp_opt : Com.var_space) (env : var_env) : unit =
15251525
| Some _ -> ()
15261526
| None -> Err.unknown_var_space sp_name (Pos.get m_sp)))
15271527

1528-
let check_right_scope ~env ~must_be (Pos.Mark (var, _) as m_vn) =
1529-
let v_name = Com.get_normal_var var in
1530-
let var =
1531-
let id = StrMap.find v_name env.vars in
1532-
IntMap.find id env.prog.prog_dict
1533-
in
1534-
match must_be with
1535-
| `Tgv when Com.Var.is_tgv var -> ()
1536-
| `Ref when Com.Var.is_ref var -> ()
1537-
| `Temp when Com.Var.is_temp var -> ()
1538-
| `Tgv ->
1539-
Err.unexpected_variable_scope m_vn ~var_scope:var.scope
1540-
~expected_scope:"TGV"
1541-
| `Ref ->
1542-
Err.unexpected_variable_scope m_vn ~var_scope:var.scope
1543-
~expected_scope:"reference"
1544-
| `Temp ->
1545-
Err.unexpected_variable_scope m_vn ~var_scope:var.scope
1546-
~expected_scope:"temp"
1547-
1548-
let check_variable ?(must_be : [ `Tgv | `Ref | `Temp ] option)
1549-
(m_sp_opt : Com.var_space) (m_vn : Com.m_var_name) (idx_mem : var_mem_type)
1550-
(env : var_env) : unit =
1528+
let check_variable (m_sp_opt : Com.var_space) (m_vn : Com.m_var_name)
1529+
(idx_mem : var_mem_type) (env : var_env) : unit =
15511530
let decl_mem, decl_pos = Pos.to_couple @@ get_var_mem_type m_vn env in
15521531
(match (decl_mem, idx_mem) with
15531532
| _, Both | Num, Num | Table, Table -> ()
@@ -1556,9 +1535,6 @@ let check_variable ?(must_be : [ `Tgv | `Ref | `Temp ] option)
15561535
| Both, Table -> Err.mixed_variable_used_as_table decl_pos (Pos.get m_vn)*)
15571536
| Num, Table -> Err.variable_used_as_table decl_pos (Pos.get m_vn)
15581537
| Table, Num -> Err.table_used_as_variable decl_pos (Pos.get m_vn));
1559-
(match must_be with
1560-
| None -> ()
1561-
| Some must_be -> check_right_scope ~env ~must_be m_vn);
15621538
match m_sp_opt with
15631539
| None -> ()
15641540
| Some (m_sp, _) ->
@@ -1577,6 +1553,27 @@ let check_variable ?(must_be : [ `Tgv | `Ref | `Temp ] option)
15771553
else if Com.Var.is_temp var then
15781554
Err.tmp_var_has_no_var_space v_name (Pos.get m_vn)
15791555

1556+
let check_variable_can_be_referenced
1557+
(Pos.Mark (v_name, pos) as m_v : Com.m_var_name) (env : var_env) : unit =
1558+
let v_name = Com.get_normal_var v_name in
1559+
let var =
1560+
let id = StrMap.find v_name env.vars in
1561+
IntMap.find id env.prog.prog_dict
1562+
in
1563+
match var.scope with
1564+
| Tgv _ -> ()
1565+
| Ref ->
1566+
Errors.print_spanned_warning
1567+
(Format.sprintf
1568+
"Variable %s used to set an event reference. Make sure it is not a \
1569+
temporary variable, otherwise this instruction will have no \
1570+
effect."
1571+
v_name)
1572+
pos
1573+
| Temp _ ->
1574+
Err.unexpected_variable_scope ~var_scope:var.scope ~expected_scope:"Tgv"
1575+
m_v
1576+
15801577
let check_expression (env : var_env) (m_expr : Mast.m_expression) : unit =
15811578
let get_var m_v = Pos.same (Com.get_normal_var @@ Pos.unmark m_v) m_v in
15821579
let fold_sp m_sp_opt env _acc = check_var_space m_sp_opt env in
@@ -1763,7 +1760,8 @@ let rec check_instructions (env : var_env)
17631760
| Some _ -> Err.event_field_is_not_a_reference f_name f_pos
17641761
| None -> Err.unknown_event_field f_name f_pos);
17651762
let m_i' = map_expr env m_i in
1766-
check_variable ~must_be:`Tgv None m_v Num env;
1763+
check_variable None m_v Num env;
1764+
check_variable_can_be_referenced m_v env;
17671765
let m_v' = map_var env m_v in
17681766
let f' =
17691767
Com.SingleFormula (EventFieldRef (m_i', f, iFmt, m_v'))

0 commit comments

Comments
 (0)