@@ -461,8 +461,17 @@ relation evaluate_graphical_api: (InteractiveStmts, InteractiveSymbolTable) =>
461
461
),
462
462
st as SYMBOLTABLE(p,s,ic,iv,cf)) => (resstr',SYMBOLTABLE(newp,s,ic,iv,cf))
463
463
464
- rule
465
- add_icon_annotation(cr,annexpr,p) => newp &
464
+ rule delete_component(name,model,p) => (newp,resstr)
465
+ & Print.get_string() => str & string_append(resstr,str) => resstr'
466
+ -----------------------
467
+ evaluate_graphical_api(
468
+ ISTMTS([IEXP(Absyn.CALL(
469
+ Absyn.CREF_IDENT("deleteComponent",_),
470
+ Absyn.FUNCTIONARGS([Absyn.CREF(Absyn.CREF_IDENT(name,_)),Absyn.CREF(model)],annlst)))]
471
+ ),
472
+ st as SYMBOLTABLE(p,s,ic,iv,cf)) => (resstr',SYMBOLTABLE(newp,s,ic,iv,cf))
473
+
474
+ rule add_icon_annotation(cr,annexpr,p) => newp &
466
475
let newst = SYMBOLTABLE(newp,s,ic,iv,cf)
467
476
-----------------------
468
477
evaluate_graphical_api(
@@ -1060,7 +1069,68 @@ relation lookup_classdef: (Absyn.Path, Absyn.Path, Absyn.Program) => (Absyn.Clas
1060
1069
---------------------
1061
1070
lookup_classdef(path,inpath,_) => fail
1062
1071
end
1072
+
1073
+ (** relation: delete_component
1074
+ ** This relation deletes a component from a class.
1075
+ **)
1076
+ relation delete_component: (string, Absyn.ComponentRef, Absyn.Program)
1077
+ => (Absyn.Program ,string) =
1078
+
1079
+ rule Absyn.cref_to_path(model) => modelpath &
1080
+ not get_pathed_class_in_program(modelpath,p) => _
1081
+ ---------------------------------
1082
+ delete_component (name,model,p) => (p,"false\n")
1083
+
1084
+ rule Absyn.cref_to_path(model) => modelpath &
1085
+ Absyn.strip_last(modelpath) => modelwithin &
1086
+ get_pathed_class_in_program(modelpath,p) => cdef &
1087
+ delete_component_from_class(name, cdef) => newcdef &
1088
+ update_program(Absyn.PROGRAM([newcdef], Absyn.WITHIN(modelwithin)),p)=> newp
1089
+ ------------------------------------------------
1090
+ delete_component(name, model as Absyn.CREF_QUAL(_,_,_),p as Absyn.PROGRAM(_,w)) => (newp,"true\n")
1063
1091
1092
+ rule Absyn.cref_to_path(model) => modelpath &
1093
+ get_pathed_class_in_program(modelpath,p) => cdef &
1094
+ delete_component_from_class(name, cdef) => newcdef &
1095
+ update_program(Absyn.PROGRAM([newcdef], Absyn.TOP),p) => newp
1096
+ ------------------------------------------------
1097
+ delete_component( name, model as Absyn.CREF_IDENT(_,_), p as Absyn.PROGRAM(_,w)) => (newp,"true\n")
1098
+
1099
+ axiom delete_component(_,_,p) => (p,"false\n")
1100
+ end
1101
+
1102
+ relation delete_component_from_class: (string, Absyn.Class) => Absyn.Class =
1103
+
1104
+ rule get_public_list(parts) => publst &
1105
+ delete_component_from_elementitems(name,publst) => publst2 &
1106
+ list_length(publst2) => l2 &
1107
+ list_length(publst) => l1 &
1108
+ int_sub(l1,1) => l1' &
1109
+ l1' = l2 &
1110
+ replace_public_list(parts,publst2) => parts2
1111
+ --------------------------------------------
1112
+ delete_component_from_class ( name, Absyn.CLASS(i,p,f,e,r,Absyn.PARTS(parts,cmt)))
1113
+ => Absyn.CLASS(i,p,f,e,r,Absyn.PARTS(parts2,cmt))
1114
+ end
1115
+
1116
+ relation delete_component_from_elementitems: (string, Absyn.ElementItem list)
1117
+ => Absyn.ElementItem list =
1118
+ axiom delete_component_from_elementitems (_,[]) => []
1119
+
1120
+ rule name = name2
1121
+ -------------
1122
+ delete_component_from_elementitems(name,Absyn.ELEMENTITEM(Absyn.ELEMENT(_,_,_,_,Absyn.COMPONENTS(_,_,[Absyn.COMPONENTITEM(Absyn.COMPONENT(name2,_,_),_)]),_))::xs) => xs
1123
+
1124
+ rule not name = name2 &
1125
+ delete_component_from_elementitems(name, xs) => res
1126
+ -------------------------
1127
+ delete_component_from_elementitems(name, (x as Absyn.ELEMENTITEM(Absyn.ELEMENT(_,_,_,_,Absyn.COMPONENTS(_,_,[Absyn.COMPONENTITEM(Absyn.COMPONENT(name2,_,_),_)]),_)))::xs) => x::res
1128
+
1129
+ rule delete_component_from_elementitems(name, xs) => res
1130
+ ---------------------------------------------------
1131
+ delete_component_from_elementitems(name,x::xs) => x::res
1132
+ end
1133
+
1064
1134
(** relation add_component
1065
1135
** This relation takes: arg1 - string giving the instancename, arg2 - `ComponentRef' giving the component type
1066
1136
** arg3 - ComponentRef giving the model to instantiate the component within, arg4 - `NamedArg' list of annotations
@@ -1072,7 +1142,7 @@ relation add_component: (string, Absyn.ComponentRef,Absyn.ComponentRef,Absyn.Nam
1072
1142
rule Absyn.cref_to_path(model) => modelpath &
1073
1143
not get_pathed_class_in_program(modelpath,p) => _
1074
1144
---------------------------------
1075
- add_component (name,tp,model,annlst,p) => (p,"Error, No such model \n")
1145
+ add_component (name,tp,model,annlst,p) => (p,"false \n")
1076
1146
1077
1147
(* Adding component to model that resides inside package *)
1078
1148
(* Without annotation*)
@@ -1085,7 +1155,7 @@ relation add_component: (string, Absyn.ComponentRef,Absyn.ComponentRef,Absyn.Nam
1085
1155
[Absyn.COMPONENTITEM(Absyn.COMPONENT(name,[],NONE),NONE)]),NONE))) => newcdef &
1086
1156
update_program(Absyn.PROGRAM([newcdef], Absyn.WITHIN(modelwithin)),p)=> newp
1087
1157
------------------------------------------------
1088
- add_component( name,tp,model as Absyn.CREF_QUAL(_,_,_),[],p as Absyn.PROGRAM(_,w)) => (newp,"Ok \n")
1158
+ add_component( name,tp,model as Absyn.CREF_QUAL(_,_,_),[],p as Absyn.PROGRAM(_,w)) => (newp,"true \n")
1089
1159
1090
1160
(* Adding component to model that resides inside package *)
1091
1161
(* With annotation*)
0 commit comments