@@ -1391,10 +1391,13 @@ relation lookup_classdef: (Absyn.Path, Absyn.Path, Absyn.Program) => (Absyn.Clas
13911391end
13921392
13931393(** relation: delete_component
1394- ** This relation deletes a component from a class.
1395- **)
1394+ ** This relation deletes a component from a class given the name of the component instance,
1395+ ** the model in which the component is instantiated in, and the Program.
1396+ **
1397+ ** Both public and protected lists are searched.
1398+ **)
13961399relation delete_component: (string, Absyn.ComponentRef, Absyn.Program)
1397- => (Absyn.Program ,string) =
1400+ => (Absyn.Program ,string) =
13981401
13991402 rule Absyn.cref_to_path(model) => modelpath &
14001403 not get_pathed_class_in_program(modelpath,p) => _
@@ -1419,8 +1422,15 @@ relation delete_component: (string, Absyn.ComponentRef, Absyn.Program)
14191422 axiom delete_component(_,_,p) => (p,"false\n")
14201423end
14211424
1422- relation delete_component_from_class: (string, Absyn.Class) => Absyn.Class =
1425+ (** relation: delete_component_from_class
1426+ ** This relation deletes a component from a class given the name of the component instance, and a 'Class'.
1427+ **
1428+ ** Both public and protected lists are searched.
1429+ **)
1430+ relation delete_component_from_class: (string, Absyn.Class)
1431+ => Absyn.Class =
14231432
1433+ (* Search in public list *)
14241434 rule get_public_list(parts) => publst &
14251435 delete_component_from_elementitems(name,publst) => publst2 &
14261436 list_length(publst2) => l2 &
@@ -1429,8 +1439,20 @@ relation delete_component_from_class: (string, Absyn.Class) => Absyn.Class =
14291439 l1' = l2 &
14301440 replace_public_list(parts,publst2) => parts2
14311441 --------------------------------------------
1432- delete_component_from_class ( name, Absyn.CLASS(i,p,f,e,r,Absyn.PARTS(parts,cmt)))
1433- => Absyn.CLASS(i,p,f,e,r,Absyn.PARTS(parts2,cmt))
1442+ delete_component_from_class(name, Absyn.CLASS(i,p,f,e,r,Absyn.PARTS(parts,cmt)))
1443+ => Absyn.CLASS(i,p,f,e,r,Absyn.PARTS(parts2,cmt))
1444+
1445+ (* Search in protected list *)
1446+ rule get_protected_list(parts) => protlst &
1447+ delete_component_from_elementitems(name,protlst) => protlst2 &
1448+ list_length(protlst2) => l2 &
1449+ list_length(protlst) => l1 &
1450+ int_sub(l1,1) => l1' &
1451+ l1' = l2 &
1452+ replace_protected_list(parts,protlst2) => parts2
1453+ --------------------------------------------
1454+ delete_component_from_class(name, Absyn.CLASS(i,p,f,e,r,Absyn.PARTS(parts,cmt)))
1455+ => Absyn.CLASS(i,p,f,e,r,Absyn.PARTS(parts2,cmt))
14341456end
14351457
14361458relation delete_component_from_elementitems: (string, Absyn.ElementItem list)
@@ -1505,7 +1527,7 @@ end
15051527relation update_component: (string, Absyn.ComponentRef,Absyn.ComponentRef,Absyn.NamedArg list,
15061528 Absyn.Program) => (Absyn.Program ,string) =
15071529
1508- rule (* Updating component to model that resides inside package*)
1530+ rule (* Updating a public component to model that resides inside package *)
15091531 Absyn.cref_to_path(model) => modelpath &
15101532 Absyn.strip_last(modelpath) => modelwithin &
15111533 delete_component(name,model,p) => (p',_) &
@@ -1527,7 +1549,29 @@ relation update_component: (string, Absyn.ComponentRef,Absyn.ComponentRef,Absyn.
15271549 update_component( name,tp,model as Absyn.CREF_QUAL(_,_,_),nargs,p as Absyn.PROGRAM(_,w))
15281550 => (newp, "true\n")
15291551
1530- rule (* Updating component to model that resides on top level *)
1552+ rule (* Updating a protected component to model that resides inside package*)
1553+ Absyn.cref_to_path(model) => modelpath &
1554+ Absyn.strip_last(modelpath) => modelwithin &
1555+ delete_component(name,model,p) => (p',_) &
1556+ get_pathed_class_in_program(modelpath,p) => Absyn.CLASS(_,_,_,_,_,Absyn.PARTS(parts,_)) &
1557+ get_pathed_class_in_program(modelpath,p') => cdef &
1558+ get_protected_list(parts) => protlst &
1559+ get_components_contains_name(Absyn.CREF_IDENT(name,[]),protlst)
1560+ => Absyn.COMPONENTS(attr,tp,items) &
1561+ get_compitem_named(Absyn.CREF_IDENT(name,[]),items)
1562+ => Absyn.COMPONENTITEM(Absyn.COMPONENT(_,_,mod),ann) &
1563+ annotation_list_to_absyn_comment(nargs,ann) => annotation &
1564+ modification_to_absyn(nargs,mod) => modification &
1565+ add_to_protected(cdef,Absyn.ELEMENTITEM(Absyn.ELEMENT(false,false,Absyn.UNSPECIFIED,"",
1566+ Absyn.COMPONENTS(attr,tp,
1567+ [Absyn.COMPONENTITEM(Absyn.COMPONENT(name,[],modification),annotation)]),NONE)))
1568+ => newcdef &
1569+ update_program(Absyn.PROGRAM([newcdef], Absyn.WITHIN(modelwithin)),p) => newp
1570+ --------------------------
1571+ update_component( name,tp,model as Absyn.CREF_QUAL(_,_,_),nargs,p as Absyn.PROGRAM(_,w))
1572+ => (newp, "true\n")
1573+
1574+ rule (* Updating a public component to model that resides on top level *)
15311575 Absyn.cref_to_path(model) => modelpath &
15321576 get_pathed_class_in_program(modelpath,p) => cdef &
15331577 Absyn.cref_to_path(tp) => tppath &
@@ -1549,6 +1593,30 @@ relation update_component: (string, Absyn.ComponentRef,Absyn.ComponentRef,Absyn.
15491593 ------------------------------------------------
15501594 update_component( name,tp,model as Absyn.CREF_IDENT(_,_),nargs,p as Absyn.PROGRAM(_,w))
15511595 => (newp,"true\n")
1596+
1597+ rule (* Updating a protected component to model that resides on top level *)
1598+ Absyn.cref_to_path(model) => modelpath &
1599+ get_pathed_class_in_program(modelpath,p) => cdef &
1600+ Absyn.cref_to_path(tp) => tppath &
1601+ delete_component(name,model,p) => (p',_) &
1602+ get_pathed_class_in_program(modelpath,p') => cdef &
1603+ get_pathed_class_in_program(modelpath,p) => Absyn.CLASS(_,_,_,_,_,Absyn.PARTS(parts,_)) &
1604+ get_protected_list(parts) => protlst &
1605+ get_components_contains_name(Absyn.CREF_IDENT(name,[]),protlst)
1606+ =>Absyn.COMPONENTS(attr,tp,items) &
1607+ get_compitem_named(Absyn.CREF_IDENT(name,[]),items)
1608+ => Absyn.COMPONENTITEM(Absyn.COMPONENT(_,_,mod),ann) &
1609+ annotation_list_to_absyn_comment(nargs,ann) => annotation &
1610+ modification_to_absyn(nargs,mod) => modification &
1611+ add_to_protected(cdef,Absyn.ELEMENTITEM(Absyn.ELEMENT(false,false,Absyn.UNSPECIFIED,"",
1612+ Absyn.COMPONENTS(attr,tppath,
1613+ [Absyn.COMPONENTITEM(Absyn.COMPONENT(name,[],modification),annotation)]),NONE)))
1614+ => newcdef &
1615+ update_program(Absyn.PROGRAM([newcdef], Absyn.TOP),p) => newp
1616+ ------------------------------------------------
1617+ update_component( name,tp,model as Absyn.CREF_IDENT(_,_),nargs,p as Absyn.PROGRAM(_,w))
1618+ => (newp,"true\n")
1619+
15521620end
15531621
15541622(** relation:add_class_annotation
@@ -3326,6 +3394,26 @@ relation add_to_public: (Absyn.Class, Absyn.ElementItem) => Absyn.Class =
33263394
33273395end
33283396
3397+ (** relation: add_to_protected
3398+ ** This relation takes a 'Class' definition and adds an `ElementItem' to the first protected list in the class.
3399+ ** If no protected list is available in the class one is created.
3400+ **)
3401+ relation add_to_protected: (Absyn.Class, Absyn.ElementItem) => Absyn.Class =
3402+
3403+ rule get_protected_list(parts) => protlst &
3404+ list_append(protlst,[eitem]) => protlst2 &
3405+ replace_protected_list(parts,protlst2) => parts2
3406+ --------------------------------------------
3407+ add_to_protected ( Absyn.CLASS(i,p,f,e,r,Absyn.PARTS(parts,cmt)), eitem)
3408+ => Absyn.CLASS(i,p,f,e,r,Absyn.PARTS(parts2,cmt))
3409+
3410+ axiom add_to_protected ( Absyn.CLASS(i,p,f,e,r,Absyn.DERIVED(_,_,_,_,_)),eitem) => fail
3411+
3412+ axiom add_to_protected(Absyn.CLASS(i,p,f,e,r,Absyn.PARTS(parts,cmt)),eitem)
3413+ => Absyn.CLASS(i,p,f,e,r,Absyn.PARTS(Absyn.PROTECTED([eitem])::parts,cmt))
3414+
3415+ end
3416+
33293417(** relation: add_to_equation
33303418 ** This relation takes a 'Class' definition and adds an `EquationItem' to the first equation list in the class.
33313419 ** If no public list is available in the class one is created.
@@ -3516,6 +3604,24 @@ relation replace_public_list: (Absyn.ClassPart list,Absyn.ElementItem list) => A
35163604 axiom replace_public_list([],_) => []
35173605end
35183606
3607+ (** relation: replace_public_list
3608+ ** This relation replaces the `ElementItem' list in the `ClassPart' list, and returns the updated
3609+ ** list.
3610+ *)
3611+ relation replace_protected_list: (Absyn.ClassPart list,Absyn.ElementItem list) => Absyn.ClassPart list =
3612+
3613+ rule delete_protected_list(rest) => rest'
3614+ ---------------------------------
3615+ replace_protected_list ((lst as Absyn.PROTECTED(_))::rest,newprotlist)
3616+ => Absyn.PROTECTED(newprotlist)::rest'
3617+
3618+ rule replace_protected_list(xs,new) => ys
3619+ ---------------------------------
3620+ replace_protected_list(x::xs,new) => x::ys
3621+
3622+ axiom replace_protected_list([],_) => []
3623+ end
3624+
35193625relation delete_public_list:(Absyn.ClassPart list)
35203626 => Absyn.ClassPart list =
35213627 axiom delete_public_list([]) => []
@@ -3529,6 +3635,19 @@ relation delete_public_list:(Absyn.ClassPart list)
35293635 delete_public_list(x::xs) => x::res
35303636end
35313637
3638+ relation delete_protected_list:(Absyn.ClassPart list)
3639+ => Absyn.ClassPart list =
3640+ axiom delete_protected_list([]) => []
3641+
3642+ rule delete_protected_list(xs) => res
3643+ -----------------------------
3644+ delete_protected_list(Absyn.PROTECTED(_)::xs) => res
3645+
3646+ rule delete_protected_list(xs) => res
3647+ -----------------------------
3648+ delete_protected_list(x::xs) => x::res
3649+ end
3650+
35323651(** relation: replace_equation_list
35333652 ** This relation replaces the `EquationItem' list in the `ClassPart' list, and returns the updated
35343653 ** list.
0 commit comments