@@ -977,9 +977,6 @@ algorithm
977977 then
978978 Values . BOOL (bval);
979979
980- case ("addInitialState" ,{_,_,_})
981- then Values . BOOL (false );
982-
983980 case ("deleteInitialState" ,{Values . CODE (Absyn . C_TYPENAME (classpath)), Values . STRING (_)})
984981 algorithm
985982 false := Interactive . existClass(classpath, SymbolTable . getAbsyn());
@@ -6642,24 +6639,19 @@ function checkAll
66426639 input output Integer failed;
66436640protected
66446641 Absyn . Program p;
6642+ list< Absyn . Path > rest;
6643+ Absyn . Path className;
6644+ String str, s, smsg;
6645+ Real t1, t2, elapsedTime;
6646+ Absyn . ComponentRef cr;
6647+ Absyn . Class c;
6648+ Boolean f = false ;
66456649algorithm
66466650 p := SymbolTable . getAbsyn();
6647- _ := matchcontinue (inEnv,allClasses,inMsg)
6648- local
6649- list< Absyn . Path > rest;
6650- Absyn . Path className;
6651- Absyn . Msg msg;
6652- FCore . Cache cache;
6653- String str, s, smsg;
6654- FCore . Graph env;
6655- Real t1, t2, elapsedTime;
6656- Absyn . ComponentRef cr;
6657- Absyn . Class c;
6658- Boolean f = false ;
6651+ () := matchcontinue allClasses
6652+ case {} then ();
66596653
6660- case (_,{},_) then ();
6661-
6662- case (env,className::rest,msg)
6654+ case className::rest
66636655 algorithm
66646656 c := InteractiveUtil . getPathedClassInProgram(className, p);
66656657 // filter out partial classes
@@ -6673,7 +6665,7 @@ algorithm
66736665 print("Checking: " + Dump . unparseClassAttributesStr(c) + " " + AbsynUtil . pathString(className) + "... " );
66746666 t1 := clock();
66756667 FlagsUtil . setConfigBool(Flags . CHECK_MODEL , true );
6676- (_,Values . STRING (str)) := checkModel(FCore . emptyCache(), env , className, msg );
6668+ (_,Values . STRING (str)) := checkModel(FCore . emptyCache(), inEnv , className, inMsg );
66776669 FlagsUtil . setConfigBool(Flags . CHECK_MODEL , false );
66786670 t2 := clock();
66796671 elapsedTime := t2 - t1;
@@ -6699,14 +6691,14 @@ algorithm
66996691 (if reportTimes then realString(elapsedTime) + ", " else "" ) +
67006692 AbsynUtil . pathString(className) + " \n " );
67016693 print ("------------------------------------------------------------------------- \n " );
6702- failed := checkAll(inCache, env , rest, msg , reportTimes, failed);
6694+ failed := checkAll(inCache, inEnv , rest, inMsg , reportTimes, failed);
67036695 then ();
67046696
6705- case (env, className::rest,msg)
6697+ case className::rest
67066698 algorithm
67076699 c := InteractiveUtil . getPathedClassInProgram(className, p);
67086700 print("Checking skipped: " + Dump . unparseClassAttributesStr(c) + " " + AbsynUtil . pathString(className) + "... \n " );
6709- failed := checkAll(inCache, env , rest, msg , reportTimes, failed);
6701+ failed := checkAll(inCache, inEnv , rest, inMsg , reportTimes, failed);
67106702 then
67116703 ();
67126704 end matchcontinue;
@@ -6944,23 +6936,15 @@ protected function getNthAlgorithmItem
69446936 input Absyn . Class inClass;
69456937 input Integer inInteger;
69466938 output String outString;
6939+ protected
6940+ list< Absyn . ClassPart > parts;
69476941algorithm
6948- outString := match (inClass)
6949- local
6950- list< Absyn . ClassPart > parts;
6951- String str;
6952- Integer n;
6953- case (Absyn . CLASS (body = Absyn . PARTS (classParts = parts)))
6954- algorithm
6955- str := getNthAlgorithmItemInClassParts(parts,inInteger);
6956- then
6957- str;
6942+ outString := match inClass
6943+ case Absyn . CLASS (body = Absyn . PARTS (classParts = parts))
6944+ then getNthAlgorithmItemInClassParts(parts,inInteger);
69586945 // check also the case model extends X end X;
6959- case (Absyn . CLASS (body = Absyn . CLASS_EXTENDS (parts = parts)))
6960- algorithm
6961- str := getNthAlgorithmItemInClassParts(parts,inInteger);
6962- then
6963- str;
6946+ case Absyn . CLASS (body = Absyn . CLASS_EXTENDS (parts = parts))
6947+ then getNthAlgorithmItemInClassParts(parts,inInteger);
69646948 end match;
69656949end getNthAlgorithmItem;
69666950
@@ -7504,22 +7488,15 @@ protected function getNthInitialEquationItem
75047488 input Absyn . Class inClass;
75057489 input Integer inInteger;
75067490 output String outString;
7491+ protected
7492+ list< Absyn . ClassPart > parts;
75077493algorithm
7508- outString := match (inClass)
7509- local
7510- list< Absyn . ClassPart > parts;
7511- String str;
7512- case (Absyn . CLASS (body = Absyn . PARTS (classParts = parts)))
7513- algorithm
7514- str := getNthInitialEquationItemInClassParts(parts,inInteger);
7515- then
7516- str;
7494+ outString := match inClass
7495+ case Absyn . CLASS (body = Absyn . PARTS (classParts = parts))
7496+ then getNthInitialEquationItemInClassParts(parts,inInteger);
75177497 // check also the case model extends X end X;
7518- case (Absyn . CLASS (body = Absyn . CLASS_EXTENDS (parts = parts)))
7519- algorithm
7520- str := getNthInitialEquationItemInClassParts(parts,inInteger);
7521- then
7522- str;
7498+ case Absyn . CLASS (body = Absyn . CLASS_EXTENDS (parts = parts))
7499+ then getNthInitialEquationItemInClassParts(parts,inInteger);
75237500 end match;
75247501end getNthInitialEquationItem;
75257502
@@ -7529,29 +7506,22 @@ protected function getNthInitialEquationItemInClassParts
75297506 input Integer inInteger;
75307507 output String outString;
75317508algorithm
7532- outString := matchcontinue ( inAbsynClassPartLst)
7509+ outString := matchcontinue inAbsynClassPartLst
75337510 local
75347511 String str;
75357512 list< Absyn . EquationItem > eqs;
75367513 list< Absyn . ClassPart > xs;
75377514 Integer n,c1,newn;
7538- case (Absyn . INITIALEQUATIONS (contents = eqs) :: _)
7539- algorithm
7540- str := getNthEquationItemInEquations(eqs, inInteger);
7541- then
7542- str;
7543- case (Absyn . INITIALEQUATIONS (contents = eqs) :: xs) /* The rule above failed, subtract the number of equations in the first section and try with the rest of the classparts */
7515+ case Absyn . INITIALEQUATIONS (contents = eqs) :: _
7516+ then getNthEquationItemInEquations(eqs, inInteger);
7517+ case Absyn . INITIALEQUATIONS (contents = eqs) :: xs /* The rule above failed, subtract the number of equations in the first section and try with the rest of the classparts */
75447518 algorithm
75457519 c1 := getEquationItemsCountInEquationItems(eqs);
75467520 newn := inInteger - c1;
7547- str := getNthInitialEquationItemInClassParts(xs, newn);
75487521 then
7549- str;
7550- case (_ :: xs)
7551- algorithm
7552- str := getNthInitialEquationItemInClassParts(xs, inInteger);
7553- then
7554- str;
7522+ getNthInitialEquationItemInClassParts(xs, newn);
7523+ case _ :: xs
7524+ then getNthInitialEquationItemInClassParts(xs, inInteger);
75557525 end matchcontinue;
75567526end getNthInitialEquationItemInClassParts;
75577527
@@ -7560,7 +7530,7 @@ protected function getAnnotationCount
75607530 input Absyn . Class inClass;
75617531 output Integer outInteger;
75627532algorithm
7563- outInteger := match ( inClass)
7533+ outInteger := match inClass
75647534 local
75657535 list< Absyn . Annotation > ann;
75667536 Integer count;
@@ -7700,17 +7670,12 @@ public function isShortDefinition
77007670 input Absyn . Program inProgram;
77017671 output Boolean outBoolean;
77027672algorithm
7703- outBoolean:=
7704- matchcontinue (inPath)
7705- local
7706- Absyn . Path path;
7707- case (path)
7708- algorithm
7709- Absyn . CLASS (body = Absyn . DERIVED ()) := InteractiveUtil . getPathedClassInProgram(path, inProgram);
7710- then
7711- true ;
7712- else false ;
7713- end matchcontinue;
7673+ try
7674+ Absyn . CLASS (body = Absyn . DERIVED ()) := InteractiveUtil . getPathedClassInProgram(inPath, inProgram);
7675+ outBoolean := true ;
7676+ else
7677+ outBoolean := false ;
7678+ end try ;
77147679end isShortDefinition;
77157680
77167681protected function isExperiment
@@ -8428,31 +8393,26 @@ protected function addInitialStateWithAnnotation
84288393 input Absyn . Program inProgram;
84298394 output Boolean b;
84308395 output Absyn . Program outProgram;
8396+ protected
8397+ Absyn . Path package_;
8398+ Absyn . Class cdef, newcdef;
8399+ Option < Absyn . Comment > cmt;
84318400algorithm
8432- (b, outProgram) := match (inPath, state, inProgram)
8433- local
8434- Absyn . Path modelpath, package_;
8435- Absyn . Class cdef, newcdef;
8436- Absyn . Program newp, p;
8437- String state_;
8438- Option < Absyn . Comment > cmt;
8439-
8440- case (modelpath, state_,(p as Absyn . PROGRAM ()))
8441- algorithm
8442- cdef := InteractiveUtil . getPathedClassInProgram(modelpath, p);
8443- cmt := SOME (Absyn . COMMENT (SOME (inAnnotation), NONE ()));
8444- newcdef := InteractiveUtil . addToEquation(cdef, Absyn . EQUATIONITEM (Absyn . EQ_NORETCALL (Absyn . CREF_IDENT ("initialState" , {}),
8445- Absyn . FUNCTIONARGS ({Absyn . CREF (Absyn . CREF_IDENT (state_, {}))}, {})), cmt, Absyn . dummyInfo));
8446- if AbsynUtil . pathIsIdent(AbsynUtil . makeNotFullyQualified(modelpath)) then
8447- newp := InteractiveUtil . updateProgram(Absyn . PROGRAM ({newcdef},p. within_), p);
8448- else
8449- package_ := AbsynUtil . stripLast(modelpath);
8450- newp := InteractiveUtil . updateProgram(Absyn . PROGRAM ({newcdef},Absyn . WITHIN (package_)), p);
8451- end if ;
8452- then
8453- (true , newp);
8454- case (_,_,(p as Absyn . PROGRAM ())) then (false , p);
8455- end match;
8401+ try
8402+ cdef := InteractiveUtil . getPathedClassInProgram(inPath, inProgram);
8403+ cmt := SOME (Absyn . COMMENT (SOME (inAnnotation), NONE ()));
8404+ newcdef := InteractiveUtil . addToEquation(cdef, Absyn . EQUATIONITEM (Absyn . EQ_NORETCALL (Absyn . CREF_IDENT ("initialState" , {}),
8405+ Absyn . FUNCTIONARGS ({Absyn . CREF (Absyn . CREF_IDENT (state, {}))}, {})), cmt, Absyn . dummyInfo));
8406+ if AbsynUtil . pathIsIdent(AbsynUtil . makeNotFullyQualified(inPath)) then
8407+ outProgram := InteractiveUtil . updateProgram(Absyn . PROGRAM ({newcdef},inProgram. within_), inProgram);
8408+ else
8409+ package_ := AbsynUtil . stripLast(inPath);
8410+ outProgram := InteractiveUtil . updateProgram(Absyn . PROGRAM ({newcdef},Absyn . WITHIN (package_)), inProgram);
8411+ end if ;
8412+ b := true ;
8413+ else
8414+ b := false ;
8415+ end try ;
84568416end addInitialStateWithAnnotation;
84578417
84588418protected function deleteInitialState
@@ -8507,19 +8467,17 @@ algorithm
85078467 list< Absyn . NamedArg > classAttrs;
85088468 list< Absyn . Annotation > ann;
85098469 /* a class with parts */
8510- case (outClass as Absyn . CLASS (
8511- body = Absyn . PARTS (typeVars = typeVars,classAttrs = classAttrs,classParts = parts,ann= ann,comment = cmt),
8512- info = _))
8470+ case outClass as Absyn . CLASS (
8471+ body = Absyn . PARTS (typeVars = typeVars,classAttrs = classAttrs,classParts = parts,ann= ann,comment = cmt))
85138472 algorithm
85148473 eqlst := InteractiveUtil . getEquationList(parts);
85158474 eqlst_1 := deleteInitialStateInEqlist(eqlst, state);
85168475 parts2 := InteractiveUtil . replaceEquationList(parts, eqlst_1);
85178476 outClass. body := Absyn . PARTS (typeVars,classAttrs,parts2,ann,cmt);
85188477 then outClass;
85198478 /* an extended class with parts: model extends M end M; */
8520- case (outClass as Absyn . CLASS (
8521- body = Absyn . CLASS_EXTENDS (baseClassName = bcname,modifications= modif,parts = parts,ann = ann,comment = cmt)
8522- ))
8479+ case outClass as Absyn . CLASS (
8480+ body = Absyn . CLASS_EXTENDS (baseClassName = bcname,modifications= modif,parts = parts,ann = ann,comment = cmt))
85238481 algorithm
85248482 eqlst := InteractiveUtil . getEquationList(parts);
85258483 eqlst_1 := deleteInitialStateInEqlist(eqlst, state);
@@ -8531,56 +8489,29 @@ end deleteInitialStateInClass;
85318489
85328490protected function deleteInitialStateInEqlist
85338491"Helper function to deleteInitialState."
8534- input list< Absyn . EquationItem > inAbsynEquationItemLst ;
8492+ input list< Absyn . EquationItem > inEqs ;
85358493 input String state;
8536- output list< Absyn . EquationItem > outAbsynEquationItemLst;
8494+ output list< Absyn . EquationItem > outEqs;
8495+ protected
8496+ function is_matching_initial_state
8497+ input Absyn . EquationItem item;
8498+ input String state;
8499+ output Boolean isMatch;
8500+ protected
8501+ Absyn . ComponentRef name;
8502+ list< Absyn . Exp > args;
8503+ algorithm
8504+ isMatch := match item
8505+ case Absyn . EQUATIONITEM (equation_ = Absyn . EQ_NORETCALL (functionName = name, functionArgs = Absyn . FUNCTIONARGS (args = args)))
8506+ guard AbsynUtil . crefEqual(name, Absyn . CREF_IDENT ("initialState" , {}))
8507+ then not listEmpty(args) and state == Dump . printExpStr(listHead(args));
8508+ else false ;
8509+ end match;
8510+ end is_matching_initial_state;
85378511algorithm
8538- outAbsynEquationItemLst := matchcontinue (inAbsynEquationItemLst, state)
8539- local
8540- list< Absyn . EquationItem > res,xs;
8541- String state_;
8542- Absyn . ComponentRef name;
8543- list< Absyn . Exp > expArgs;
8544- list< Absyn . NamedArg > namedArgs;
8545- list< String > args;
8546- Absyn . EquationItem x;
8547-
8548- case ({},_) then {};
8549- case ((Absyn . EQUATIONITEM (equation_ = Absyn . EQ_NORETCALL (name, Absyn . FUNCTIONARGS (expArgs, _))) :: xs), state_)
8550- guard AbsynUtil . crefEqual(name, Absyn . CREF_IDENT ("initialState" , {}))
8551- algorithm
8552- args := List . map(expArgs, Dump . printExpStr);
8553- true := compareInitialStateFuncArgs(args, state_);
8554- then
8555- deleteInitialStateInEqlist(xs, state_);
8556- case ((x :: xs), state_)
8557- algorithm
8558- res := deleteInitialStateInEqlist(xs, state_);
8559- then
8560- (x :: res);
8561- end matchcontinue;
8512+ outEqs := list(e for e guard not is_matching_initial_state(e, state) in inEqs);
85628513end deleteInitialStateInEqlist;
85638514
8564- protected function compareInitialStateFuncArgs
8565- "Helper function to deleteInitialState."
8566- input list< String > args;
8567- input String state;
8568- output Boolean b;
8569- algorithm
8570- b := matchcontinue (args)
8571- local
8572- String state1, state2;
8573-
8574- case ({state1})
8575- guard
8576- stringEq(state1, state)
8577- then
8578- true ;
8579-
8580- else false ;
8581- end matchcontinue;
8582- end compareInitialStateFuncArgs;
8583-
85848515function getComponentInfo
85858516 input Absyn . Element comp;
85868517 input Interactive . GraphicEnvCache inEnv;
@@ -8602,7 +8533,7 @@ algorithm
86028533 Absyn . ArrayDim subs;
86038534 Absyn . ElementSpec spec;
86048535
8605- case Absyn . ELEMENT (specification = spec as Absyn . COMPONENTS (attributes = attr as _ ,typeSpec = Absyn . TPATH (p, _)))
8536+ case Absyn . ELEMENT (specification = spec as Absyn . COMPONENTS (attributes = attr,typeSpec = Absyn . TPATH (p, _)))
86068537 algorithm
86078538 typename := matchcontinue ()
86088539 case ()
0 commit comments