Skip to content

Commit 1505656

Browse files
committed
Some refactoring to use assignment to fields
git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@23149 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
1 parent 148e7c7 commit 1505656

File tree

1 file changed

+96
-190
lines changed

1 file changed

+96
-190
lines changed

Compiler/FrontEnd/DAEUtil.mo

Lines changed: 96 additions & 190 deletions
Original file line numberDiff line numberDiff line change
@@ -860,19 +860,13 @@ end getMaxAttrFail;
860860
public function setVariableAttributes "sets the attributes of a DAE.Element that is VAR"
861861
input DAE.Element var;
862862
input Option<DAE.VariableAttributes> varOpt;
863-
output DAE.Element outVar;
863+
output DAE.Element v := var;
864864
algorithm
865-
outVar := match(var,varOpt)
866-
local
867-
DAE.ComponentRef cr; DAE.VarKind k;
868-
DAE.VarDirection d ; DAE.VarParallelism prl;
869-
DAE.VarVisibility v; DAE.Type ty; Option<DAE.Exp> b;
870-
DAE.InstDims dims; DAE.ConnectorType ct;
871-
DAE.ElementSource source "the origin of the element";
872-
Option<SCode.Comment> cmt; Absyn.InnerOuter io;
873-
874-
case(DAE.VAR(cr,k,d,prl,v,ty,b,dims,ct,source,_,cmt,io),_)
875-
then DAE.VAR(cr,k,d,prl,v,ty,b,dims,ct,source,varOpt,cmt,io);
865+
v := match v
866+
case DAE.VAR()
867+
algorithm
868+
v.variableAttributesOption := varOpt;
869+
then v;
876870
end match;
877871
end setVariableAttributes;
878872

@@ -882,18 +876,14 @@ public function setStateSelect "
882876
input DAE.StateSelect s;
883877
output Option<DAE.VariableAttributes> outAttr;
884878
algorithm
885-
outAttr:=
886-
match (attr,s)
879+
outAttr := match attr
887880
local
888-
Option<DAE.Exp> q,u,du,f,n,so,start,min,max;
889-
Option<DAE.Uncertainty> unc;
890-
Option<DAE.Distribution> distOpt;
891-
Option<DAE.Exp> eb;
892-
Option<Boolean> ip,fn;
893-
894-
case (SOME(DAE.VAR_ATTR_REAL(q,u,du,min,max,start,f,n,_,unc,distOpt,eb,ip,fn,so)),_)
895-
then SOME(DAE.VAR_ATTR_REAL(q,u,du,min,max,start,f,n,SOME(s),unc,distOpt,eb,ip,fn,so));
896-
case (NONE(),_)
881+
DAE.VariableAttributes va;
882+
case SOME(va as DAE.VAR_ATTR_REAL())
883+
algorithm
884+
va.stateSelectOption := SOME(s);
885+
then SOME(va);
886+
case NONE()
897887
then SOME(DAE.VAR_ATTR_REAL(NONE(),NONE(),NONE(),NONE(),NONE(),NONE(),NONE(),NONE(),SOME(s),NONE(),NONE(),NONE(),NONE(),NONE(),NONE()));
898888
end match;
899889
end setStateSelect;
@@ -904,29 +894,7 @@ public function setStartAttr "
904894
input DAE.Exp start;
905895
output Option<DAE.VariableAttributes> outAttr;
906896
algorithm
907-
outAttr:=
908-
match (attr,start)
909-
local
910-
Option<DAE.Exp> q,u,du,f,n,so,min,max;
911-
Option<DAE.StateSelect> ss;
912-
Option<DAE.Uncertainty> unc;
913-
Option<DAE.Distribution> distOpt;
914-
Option<DAE.Exp> eb;
915-
Option<Boolean> ip,fn;
916-
917-
case (SOME(DAE.VAR_ATTR_REAL(q,u,du,min,max,_,f,n,ss,unc,distOpt,eb,ip,fn,so)),_)
918-
then SOME(DAE.VAR_ATTR_REAL(q,u,du,min,max,SOME(start),f,n,ss,unc,distOpt,eb,ip,fn,so));
919-
case (SOME(DAE.VAR_ATTR_INT(q,min,max,_,f,unc,distOpt,eb,ip,fn,so)),_)
920-
then SOME(DAE.VAR_ATTR_INT(q,min,max,SOME(start),f,unc,distOpt,eb,ip,fn,so));
921-
case (SOME(DAE.VAR_ATTR_BOOL(q,_,f,eb,ip,fn,so)),_)
922-
then SOME(DAE.VAR_ATTR_BOOL(q,SOME(start),f,eb,ip,fn,so));
923-
case (SOME(DAE.VAR_ATTR_STRING(q,_,eb,ip,fn,so)),_)
924-
then SOME(DAE.VAR_ATTR_STRING(q,SOME(start),eb,ip,fn,so));
925-
case (SOME(DAE.VAR_ATTR_ENUMERATION(q,min,max,_,du,eb,ip,fn,so)),_)
926-
then SOME(DAE.VAR_ATTR_ENUMERATION(q,min,max,SOME(start),du,eb,ip,fn,so));
927-
case (NONE(),_)
928-
then SOME(DAE.VAR_ATTR_REAL(NONE(),NONE(),NONE(),NONE(),NONE(),SOME(start),NONE(),NONE(),NONE(),NONE(),NONE(),NONE(),NONE(),NONE(),NONE()));
929-
end match;
897+
outAttr := setStartAttrOption(attr,SOME(start));
930898
end setStartAttr;
931899

932900
public function setStartAttrOption "
@@ -935,29 +903,31 @@ public function setStartAttrOption "
935903
input Option<DAE.Exp> start;
936904
output Option<DAE.VariableAttributes> outAttr;
937905
algorithm
938-
outAttr:=
939-
match (attr,start)
940-
local
941-
Option<DAE.Exp> q,u,du,f,n,so,min,max;
942-
Option<DAE.StateSelect> ss;
943-
Option<DAE.Uncertainty> unc;
944-
Option<DAE.Distribution> distOpt;
945-
Option<DAE.Exp> eb;
946-
Option<Boolean> ip,fn;
947-
948-
case (SOME(DAE.VAR_ATTR_REAL(q,u,du,min,max,_,f,n,ss,unc,distOpt,eb,ip,fn,so)),_)
949-
then SOME(DAE.VAR_ATTR_REAL(q,u,du,min,max,start,f,n,ss,unc,distOpt,eb,ip,fn,so));
950-
case (SOME(DAE.VAR_ATTR_INT(q,min,max,_,f,unc,distOpt,eb,ip,fn,so)),_)
951-
then SOME(DAE.VAR_ATTR_INT(q,min,max,start,f,unc,distOpt,eb,ip,fn,so));
952-
case (SOME(DAE.VAR_ATTR_BOOL(q,_,f,eb,ip,fn,so)),_)
953-
then SOME(DAE.VAR_ATTR_BOOL(q,start,f,eb,ip,fn,so));
954-
case (SOME(DAE.VAR_ATTR_STRING(q,_,eb,ip,fn,so)),_)
955-
then SOME(DAE.VAR_ATTR_STRING(q,start,eb,ip,fn,so));
956-
case (SOME(DAE.VAR_ATTR_ENUMERATION(q,min,max,_,du,eb,ip,fn,so)),_)
957-
then SOME(DAE.VAR_ATTR_ENUMERATION(q,min,max,start,du,eb,ip,fn,so));
958-
case (NONE(),NONE()) then NONE();
959-
case (NONE(),_)
960-
then SOME(DAE.VAR_ATTR_REAL(NONE(),NONE(),NONE(),NONE(),NONE(),start,NONE(),NONE(),NONE(),NONE(),NONE(),NONE(),NONE(),NONE(),NONE()));
906+
outAttr := match attr
907+
local
908+
DAE.VariableAttributes va;
909+
case SOME(va as DAE.VAR_ATTR_REAL())
910+
algorithm
911+
va.start := start;
912+
then SOME(va);
913+
case SOME(va as DAE.VAR_ATTR_INT())
914+
algorithm
915+
va.start := start;
916+
then SOME(va);
917+
case SOME(va as DAE.VAR_ATTR_BOOL())
918+
algorithm
919+
va.start := start;
920+
then SOME(va);
921+
case SOME(va as DAE.VAR_ATTR_STRING())
922+
algorithm
923+
va.start := start;
924+
then SOME(va);
925+
case SOME(va as DAE.VAR_ATTR_ENUMERATION())
926+
algorithm
927+
va.start := start;
928+
then SOME(va);
929+
case NONE()
930+
then if isNone(start) then NONE() else SOME(DAE.VAR_ATTR_REAL(NONE(),NONE(),NONE(),NONE(),NONE(),start,NONE(),NONE(),NONE(),NONE(),NONE(),NONE(),NONE(),NONE(),NONE()));
961931
end match;
962932
end setStartAttrOption;
963933

@@ -967,29 +937,31 @@ public function setStartOrigin "
967937
input Option<DAE.Exp> startOrigin;
968938
output Option<DAE.VariableAttributes> outAttr;
969939
algorithm
970-
outAttr:=
971-
match (attr,startOrigin)
972-
local
973-
Option<DAE.Exp> q,u,du,f,n,s,min,max;
974-
tuple<Option<DAE.Exp>, Option<DAE.Exp>> minMax;
975-
Option<DAE.StateSelect> ss;
976-
Option<DAE.Uncertainty> unc;
977-
Option<DAE.Distribution> distOpt;
978-
Option<DAE.Exp> eb;
979-
Option<Boolean> ip,fn;
980-
981-
case (SOME(DAE.VAR_ATTR_REAL(q,u,du,min,max,s,f,n,ss,unc,distOpt,eb,ip,fn,_)),_)
982-
then SOME(DAE.VAR_ATTR_REAL(q,u,du,min,max,s,f,n,ss,unc,distOpt,eb,ip,fn,startOrigin));
983-
case (SOME(DAE.VAR_ATTR_INT(q,min,max,s,f,unc,distOpt,eb,ip,fn,_)),_)
984-
then SOME(DAE.VAR_ATTR_INT(q,min,max,s,f,unc,distOpt,eb,ip,fn,startOrigin));
985-
case (SOME(DAE.VAR_ATTR_BOOL(q,s,f,eb,ip,fn,_)),_)
986-
then SOME(DAE.VAR_ATTR_BOOL(q,s,f,eb,ip,fn,startOrigin));
987-
case (SOME(DAE.VAR_ATTR_STRING(q,s,eb,ip,fn,_)),_)
988-
then SOME(DAE.VAR_ATTR_STRING(q,s,eb,ip,fn,startOrigin));
989-
case (SOME(DAE.VAR_ATTR_ENUMERATION(q,min,max,s,du,eb,ip,fn,_)),_)
990-
then SOME(DAE.VAR_ATTR_ENUMERATION(q,min,max,s,du,eb,ip,fn,startOrigin));
991-
case (NONE(),_)
992-
then SOME(DAE.VAR_ATTR_REAL(NONE(),NONE(),NONE(),NONE(),NONE(),NONE(),NONE(),NONE(),NONE(),NONE(),NONE(),NONE(),NONE(),NONE(),startOrigin));
940+
outAttr := match attr
941+
local
942+
DAE.VariableAttributes va;
943+
case SOME(va as DAE.VAR_ATTR_REAL())
944+
algorithm
945+
va.startOrigin := startOrigin;
946+
then SOME(va);
947+
case SOME(va as DAE.VAR_ATTR_INT())
948+
algorithm
949+
va.startOrigin := startOrigin;
950+
then SOME(va);
951+
case SOME(va as DAE.VAR_ATTR_BOOL())
952+
algorithm
953+
va.startOrigin := startOrigin;
954+
then SOME(va);
955+
case SOME(va as DAE.VAR_ATTR_STRING())
956+
algorithm
957+
va.startOrigin := startOrigin;
958+
then SOME(va);
959+
case SOME(va as DAE.VAR_ATTR_ENUMERATION())
960+
algorithm
961+
va.startOrigin := startOrigin;
962+
then SOME(va);
963+
case NONE()
964+
then if isNone(startOrigin) then NONE() else SOME(DAE.VAR_ATTR_REAL(NONE(),NONE(),NONE(),NONE(),NONE(),NONE(),NONE(),NONE(),NONE(),NONE(),NONE(),NONE(),NONE(),NONE(),startOrigin));
993965
end match;
994966
end setStartOrigin;
995967

@@ -1013,19 +985,14 @@ public function setNominalAttr "
1013985
input DAE.Exp nominal;
1014986
output Option<DAE.VariableAttributes> outAttr;
1015987
algorithm
1016-
outAttr:=
1017-
match (attr,nominal)
988+
outAttr := match attr
1018989
local
1019-
Option<DAE.Exp> q,u,du,f,s,so,min,max;
1020-
Option<DAE.StateSelect> ss;
1021-
Option<DAE.Uncertainty> unc;
1022-
Option<DAE.Distribution> distOpt;
1023-
Option<DAE.Exp> eb;
1024-
Option<Boolean> ip,fn;
1025-
1026-
case (SOME(DAE.VAR_ATTR_REAL(q,u,du,min,max,s,f,_,ss,unc,distOpt,eb,ip,fn,so)),_)
1027-
then SOME(DAE.VAR_ATTR_REAL(q,u,du,min,max,s,f,SOME(nominal),ss,unc,distOpt,eb,ip,fn,so));
1028-
case (NONE(),_)
990+
DAE.VariableAttributes va;
991+
case SOME(va as DAE.VAR_ATTR_REAL())
992+
algorithm
993+
va.nominal := SOME(nominal);
994+
then SOME(va);
995+
case NONE()
1029996
then SOME(DAE.VAR_ATTR_REAL(NONE(),NONE(),NONE(),NONE(),NONE(),NONE(),NONE(),SOME(nominal),NONE(),NONE(),NONE(),NONE(),NONE(),NONE(),NONE()));
1030997
end match;
1031998
end setNominalAttr;
@@ -1056,106 +1023,45 @@ end setUnitAttr;
10561023
public function setElementVarVisibility "
10571024
This function takes a VAR elemets and sets var visibility."
10581025
input DAE.Element elt;
1059-
input DAE.VarVisibility inVisibility;
1060-
output DAE.Element outElt;
1026+
input DAE.VarVisibility visibility;
1027+
output DAE.Element e = elt;
10611028
algorithm
1062-
outElt := match (elt,inVisibility)
1063-
local
1064-
DAE.ComponentRef cr;
1065-
DAE.VarKind kind;
1066-
DAE.VarDirection dir;
1067-
DAE.VarParallelism prl;
1068-
DAE.Type tp;
1069-
DAE.InstDims dim;
1070-
DAE.ConnectorType ct;
1071-
Option<DAE.Exp> bind;
1072-
Option<DAE.VariableAttributes> dae_var_attr;
1073-
Option<SCode.Comment> comment;
1074-
Absyn.InnerOuter io;
1075-
DAE.ElementSource source "the element origin";
1076-
1077-
case (DAE.VAR(componentRef = cr,
1078-
kind = kind,
1079-
direction = dir,
1080-
parallelism = prl,
1081-
ty = tp,
1082-
binding = bind,
1083-
dims = dim,
1084-
connectorType = ct,
1085-
source = source,
1086-
variableAttributesOption = dae_var_attr,
1087-
comment = comment,
1088-
innerOuter=io),_)
1089-
then
1090-
DAE.VAR(cr,kind,dir,prl,inVisibility,tp,bind,dim,ct,source,dae_var_attr,comment,io);
1091-
else elt;
1029+
e := match e
1030+
case DAE.VAR()
1031+
algorithm
1032+
e.protection := visibility;
1033+
then e;
1034+
else e;
10921035
end match;
10931036
end setElementVarVisibility;
10941037

10951038
public function setElementVarDirection "
10961039
This function takes a VAR elemets and sets var direction."
10971040
input DAE.Element elt;
1098-
input DAE.VarDirection inDirection;
1099-
output DAE.Element outElt;
1041+
input DAE.VarDirection direction;
1042+
output DAE.Element e = elt;
11001043
algorithm
1101-
outElt := match (elt, inDirection)
1102-
local
1103-
DAE.ComponentRef cr;
1104-
DAE.VarKind kind;
1105-
DAE.VarParallelism prl;
1106-
DAE.Type tp;
1107-
DAE.InstDims dim;
1108-
DAE.ConnectorType ct;
1109-
DAE.VarVisibility prot;
1110-
Option<DAE.Exp> bind;
1111-
Option<DAE.VariableAttributes> dae_var_attr;
1112-
Option<SCode.Comment> comment;
1113-
Absyn.InnerOuter io;
1114-
DAE.ElementSource source "the element origin";
1115-
1116-
case (DAE.VAR(componentRef = cr,
1117-
kind = kind,
1118-
parallelism = prl,
1119-
protection = prot,
1120-
ty = tp,
1121-
binding = bind,
1122-
dims = dim,
1123-
connectorType = ct,
1124-
source = source,
1125-
variableAttributesOption = dae_var_attr,
1126-
comment = comment,
1127-
innerOuter=io),_)
1128-
then
1129-
DAE.VAR(cr,kind,inDirection,prl,prot,tp,bind,dim,ct,source,dae_var_attr,comment,io);
1130-
else elt;
1044+
e := match e
1045+
case DAE.VAR()
1046+
algorithm
1047+
e.direction := direction;
1048+
then e;
1049+
else e;
11311050
end match;
11321051
end setElementVarDirection;
11331052

11341053
public function setElementVarBinding
11351054
"Sets the binding of a VAR DAE.Element."
1136-
input DAE.Element inElement;
1137-
input Option<DAE.Exp> inBinding;
1138-
output DAE.Element outElement;
1055+
input DAE.Element elt;
1056+
input Option<DAE.Exp> binding;
1057+
output DAE.Element e := elt;
11391058
algorithm
1140-
outElement := match(inElement, inBinding)
1141-
local
1142-
DAE.ComponentRef cr;
1143-
DAE.VarKind vk;
1144-
DAE.VarDirection vd;
1145-
DAE.VarParallelism vp;
1146-
DAE.VarVisibility vv;
1147-
DAE.Type ty;
1148-
DAE.InstDims dims;
1149-
DAE.ConnectorType ct;
1150-
DAE.ElementSource src;
1151-
Option<DAE.VariableAttributes> va;
1152-
Option<SCode.Comment> cmt;
1153-
Absyn.InnerOuter io;
1154-
1155-
case (DAE.VAR(cr, vk, vd, vp, vv, ty, _, dims, ct, src, va, cmt, io),_)
1156-
then DAE.VAR(cr, vk, vd, vp, vv, ty, inBinding, dims, ct, src, va, cmt, io);
1157-
1158-
else inElement;
1059+
e := match e
1060+
case DAE.VAR()
1061+
algorithm
1062+
e.binding := binding;
1063+
then e;
1064+
else e;
11591065
end match;
11601066
end setElementVarBinding;
11611067

0 commit comments

Comments
 (0)