3737 (ExceptionDefn .Malformed_Decl
3838 ("The mod component is not consistent (mixture compilation)." ,e))
3939
40+ let fail_sig_error_mod_compilation e _ =
41+ raise
42+ (ExceptionDefn .Malformed_Decl
43+ ("The mod component is not consistent (signature compilation)." ,e))
44+
4045let fail_with_two_occurrences_of_a_site _ site =
4146 raise
4247 (ExceptionDefn .Malformed_Decl
@@ -68,10 +73,15 @@ let fail_with_two_occurrences_of_a_site _ site =
6873 (ExceptionDefn.Malformed_Decl
6974 ((Format.sprintf "Lnk state is missing in a site.",e)))*)
7075
71- let fail_with_several_lnk_states e =
76+ let fail_with_absent_agent_in_sig e =
77+ raise
78+ (ExceptionDefn .Malformed_Decl
79+ ("Absent agents are not allowed in agent signature" ,e))
80+
81+ let fail_with_several_lnk_states s e =
7282 raise
7383 (ExceptionDefn .Malformed_Decl
74- ((Format .sprintf "Several Lnk states in a site." ,e)))
84+ ((Format .sprintf "Several Lnk states in the site %s." s ,e)))
7585
7686 let fail_with_bad_counter_test e =
7787 raise
@@ -103,7 +113,7 @@ let fail_with_two_occurrences_of_a_site _ site =
103113 (ExceptionDefn .Malformed_Decl
104114 ((Format .sprintf "The binding state of the site %s is not specified enough in the lhs" s ),e))
105115
106- let fail_with_several_link_state s e =
116+ let fail_with_several_link_states s e =
107117 raise
108118 (ExceptionDefn .Malformed_Decl
109119 ((Format .sprintf "Site %s has several binding states" s ),e))
@@ -123,6 +133,18 @@ let fail_with_underspecified_internal_state_in_rhs s e =
123133 (ExceptionDefn .Malformed_Decl
124134 ((Format .sprintf "Site %s has several internal states" s ),e))
125135
136+ let fail_with_multiple_occurrence_of_the_link_state s e =
137+ raise
138+ (ExceptionDefn .Malformed_Decl
139+ ((Format .sprintf "Multiple occurrence of the link state %s" s ),e))
140+
141+ let fail_with_multiple_occurrence_of_the_internal_state s e =
142+ raise
143+ (ExceptionDefn .Malformed_Decl
144+ ((Format .sprintf "Multiple occurrence of the internal state %s" s ),e))
145+
146+
147+
126148 let rec check_list get_pos_elt check_elt e a =
127149 match a with
128150 | [] -> ()
@@ -155,15 +177,77 @@ let fail_with_underspecified_internal_state_in_rhs s e =
155177 if a .Ast .counter_test = None
156178 then ()
157179 else fail_with_bad_counter_test loc
180+ let check_counter_sig _loc _a = ()
181+
182+
183+
184+ let anonym a =
185+ match a with
186+ | LKappa .ANY_FREE
187+ | LKappa .LNK_FREE
188+ | LKappa .LNK_ANY
189+ | LKappa .LNK_SOME -> a
190+ | LKappa .LNK_TYPE ((s ,_),(s ',_)) ->
191+ LKappa .LNK_TYPE (Loc .annot_with_dummy s ,Loc .annot_with_dummy s ')
192+ | LKappa .LNK_VALUE (_i ,()) -> a
193+
194+ let check_port_int_link_sig anonym m s _e a =
195+ let a =
196+ List .sort (fun (a ,_) (b ,_) -> compare (anonym a ) (anonym b )) a in
197+ let rec aux l =
198+ match l with
199+ | (a ,_)::(b ,pos)::_ when anonym a = anonym b -> m s pos
200+ | _ ::q -> aux q
201+ | [] -> ()
202+ in aux a
203+
204+ let check_port_link_sig =
205+ check_port_int_link_sig anonym
206+ (fun s e ->
207+ fail_with_multiple_occurrence_of_the_link_state (s :string ) (e :Loc .t )
208+ )
209+
210+ let check_port_int_sig s e =
211+ check_port_int_link_sig (fun a -> a )
212+ (fun s e ->
213+ fail_with_multiple_occurrence_of_the_internal_state (s :string ) (e :Loc .t )
214+ ) s e
158215
159- let check_port_int _e _a = ()
160- let check_port_link _e _a = ()
216+
217+ let check_port_int _e s a =
218+ match a with
219+ | [] | [_] -> ()
220+ | _ :: (_ , pos ) :: _ ->
221+ fail_with_several_internal_states (fst s ) pos
222+
223+ let check_port_link _e (s :string * Loc .t ) a =
224+ match a with
225+ | [] | [_] -> ()
226+ | _ :: (_ , (pos :Loc .t )) :: _ ->
227+ fail_with_several_lnk_states (fst s ) pos
228+
229+
230+ let check_port_sig (e :Loc.t ) a =
231+ if a .Ast .port_int_mod = None && a .Ast .port_link_mod = None
232+ then
233+ begin
234+ let () =
235+ check_port_int_sig
236+ (fst a .Ast .port_name )
237+ e
238+ a .Ast .port_int
239+ in
240+ check_port_link_sig (fst a .Ast .port_name ) e a .Ast .port_link
241+ end
242+ else
243+ fail_with_bad_site_state_modification e
244+
161245 let check_port_lhs e a =
162246 if a .Ast .port_int_mod = None && a .Ast .port_link_mod = None
163247 then
164248 begin
165- let () = check_port_int e a .Ast .port_int in
166- check_port_link e a .Ast .port_link
249+ let () = check_port_int e a .Ast .port_name a . Ast . port_int in
250+ check_port_link e a .Ast .port_name a . Ast . port_link
167251 end
168252 else
169253 fail_with_bad_site_state_modification e
@@ -173,8 +257,8 @@ let fail_with_underspecified_internal_state_in_rhs s e =
173257 if a .Ast .port_int_mod = None && a .Ast .port_link_mod = None
174258 then
175259 begin
176- let () = check_port_int e a .Ast .port_int in
177- check_port_link e a .Ast .port_link
260+ let () = check_port_int e a .Ast .port_name a . Ast . port_int in
261+ check_port_link e a .Ast .port_name a . Ast . port_link
178262 end
179263 else
180264 fail_with_bad_site_state_modification_in_creation e
@@ -231,7 +315,7 @@ let fail_with_underspecified_internal_state_in_rhs s e =
231315
232316 | _ , _ :: (_ , pos ) :: _
233317 | _ :: (_ , pos ) :: _ , _ ->
234- fail_with_several_link_state s pos
318+ fail_with_several_link_states s pos
235319 in
236320 match sa .Ast .port_int , sb .Ast .port_int with
237321 | [], [] | [ (None , _ ) ], [ _ ]
@@ -245,28 +329,28 @@ let fail_with_underspecified_internal_state_in_rhs s e =
245329 fail_with_several_internal_states s pos
246330
247331
248- let sort_interface =
332+ let sort_interface get_counter_name =
249333 List .sort
250334 (fun x y ->
251335 match x ,y with Ast .Port a ,Port b -> compare (fst a .port_name) (fst b .port_name)
252- | Ast .Counter a ,Ast .Counter b -> compare (fst a . Ast .counter_name ) (fst b . Ast .counter_name )
336+ | Ast .Counter a ,Ast .Counter b -> compare (fst ( get_counter_name a )) (fst ( get_counter_name b ) )
253337 | Ast .Port _ ,Ast .Counter _ -> - 1
254338 | Ast .Counter _ , Ast .Port _ -> 1 )
255339
256340
257- let check_interface_gen check_port check_counter e inta =
258- let inta = sort_interface inta in
341+ let check_interface_gen check_port get_counter_name check_counter e inta =
342+ let inta = sort_interface get_counter_name inta in
259343 let check_elt e a former =
260344 match a with
261345 | Ast .Port a when (Some (fst a .Ast .port_name )) = former -> fail_with_two_occurrences_of_a_site e a .Ast .port_name
262- | Ast .Counter a when (Some (fst a . Ast .counter_name )) = former ->
263- fail_with_two_occurrences_of_a_site e a . Ast .counter_name
346+ | Ast .Counter a when (Some (fst ( get_counter_name a ) )) = former ->
347+ fail_with_two_occurrences_of_a_site e ( get_counter_name a )
264348 | Ast .Port a ->
265349 let () = check_port e a in
266350 Some (fst a .Ast .port_name )
267351 | Ast .Counter a ->
268352 let () = check_counter e a
269- in Some (fst a . Ast .counter_name )
353+ in Some (fst ( get_counter_name a ))
270354 in
271355 let rec aux e inta former =
272356 match inta with
@@ -276,13 +360,14 @@ let fail_with_underspecified_internal_state_in_rhs s e =
276360 | [] -> ()
277361 in aux e inta None
278362
279- let check_interface_lhs = check_interface_gen check_port_lhs check_counter_lhs
280- let check_interface_rhs = check_interface_gen check_port_rhs check_counter_rhs
281-
363+ let check_interface_lhs = check_interface_gen check_port_lhs (fun a -> a .Ast .counter_name ) check_counter_lhs
364+ let check_interface_rhs = check_interface_gen check_port_rhs (fun a -> a .Ast .counter_name ) check_counter_rhs
365+ let check_interface_sig = check_interface_gen
366+ check_port_sig (fun (a :Counters_info .counter_sig ) -> a .Counters_info .counter_sig_name ) check_counter_sig
282367
283368 let check_interface_both e inta intb =
284- let inta = sort_interface inta in
285- let intb = sort_interface intb in
369+ let inta = sort_interface ( fun a ->a. Ast .counter_name ) inta in
370+ let intb = sort_interface ( fun a -> a . Ast .counter_name ) intb in
286371 let check_elt e a b former =
287372 match a , b with
288373 | Ast .Port a , Ast .Port b ->
@@ -319,6 +404,13 @@ let fail_with_underspecified_internal_state_in_rhs s e =
319404 | _ ::_, [] | [],_::_-> fail_with_site_mismatch e inta intb
320405 in aux e inta intb None
321406
407+ let check_agent_sig e a =
408+ match a with
409+ | Ast .Absent pos -> fail_with_absent_agent_in_sig pos
410+ | Ast .Present (_ ,intf, Ast .NoMod ) -> check_interface_sig e intf
411+ | Ast .Present (_ ,_,(Ast .Erase | Ast .Create )) ->
412+ fail_sig_error_mod_compilation e ()
413+
322414 let check_agent_lhs e (_ ,intf) =
323415 check_interface_lhs e intf
324416 let check_agent_rhs e (_ ,intf) =
@@ -344,7 +436,7 @@ let fail_with_underspecified_internal_state_in_rhs s e =
344436 let check_rule_line =
345437 check_list2 get_pos_agent fail_missing_agent fail_missing_agent check_agent_both
346438
347- let _get_pos_parametric_agent _ agent_sig =
439+ let get_pos_parametric_agent agent_sig =
348440 match agent_sig with
349441 | Ast .Absent pos -> pos
350442 | Ast .Present ((_ ,pos),_,_) -> pos
@@ -357,8 +449,8 @@ let fail_with_underspecified_internal_state_in_rhs s e =
357449 | Ast .GUARD_PARAM ((_ ,pos),_)
358450 | Ast .TOKENSIG (_ ,pos)
359451 | Ast .PLOT (_ ,pos)
360- | Ast .PERT (_ ,pos) -> pos
361- | Ast .SIG _
452+ | Ast .PERT (_ ,pos) -> pos
453+ | Ast .SIG ag -> get_pos_parametric_agent ag
362454 | Ast .CONFIG _
363455 | Ast .VOLSIG _
364456 | Ast .INIT _
@@ -370,11 +462,13 @@ let fail_with_underspecified_internal_state_in_rhs s e =
370462 check_list2 get_pos_rule_line fail_missing_rule_line fail_missing_rule_line check_rule_line
371463
372464
465+
466+
373467 let deal_with_port _e acc port =
374468 match port .Ast .port_link with
375469 | [ (ANY_FREE | LNK_FREE | LNK_ANY | LNK_SOME | LNK_TYPE _ ) ,_ ] | [] -> acc
376470 | [ LNK_VALUE (i , _ ),_ ] -> i ::acc
377- | (_ ,e)::_::_ -> fail_with_several_lnk_states e
471+ | (_ ,e)::_::_ -> fail_with_several_link_states ( fst port . Ast .port_name ) e
378472
379473 let deal_with_site e acc site =
380474 match site with
@@ -467,6 +561,7 @@ let check_expr e a =
467561
468562
469563
564+
470565
471566
472567
@@ -491,7 +586,7 @@ let check_init_statement e (_,expr,i) =
491586 | Ast .RULE (_ ,_,rule,_) -> check_rule e rule
492587 | Ast .INIT (init_statement ,_) ->
493588 check_init_statement e init_statement
494- | Ast .SIG _
589+ | Ast .SIG agent_sig -> check_agent_sig e agent_sig
495590 | Ast .TOKENSIG _ | Ast .VOLSIG _ -> ()
496591 | Ast .DECLARE var_def
497592 | Ast .OBS var_def -> check_var_def e var_def
0 commit comments