| 513 | | // if-equation |
| 514 | | // if the condition is constant this case will select the correct branch and remove the if-equation |
| 515 | | case (cache,env,ih,mod,pre,csets,ci_state,SCode.EQ_IF(condition = conditions,thenBranch = tb,elseBranch = fb,info=info),SCode.NON_INITIAL(),impl,graph) |
| 516 | | equation |
| 517 | | (cache, expl1,props,_) = Static.elabExpList(cache,env, conditions, impl,NONE(),true,pre,info); |
| 518 | | DAE.PROP(DAE.T_BOOL(varLst = _),cnst) = Types.propsAnd(props); |
| 519 | | true = Types.isParameterOrConstant(cnst); |
| 520 | | (cache,valList,_) = Ceval.cevalList(cache, env, expl1, impl, NONE(), Ceval.NO_MSG()); |
| 521 | | // check if valList contains Values.EMPTY() |
| 522 | | containsEmpty = ValuesUtil.containsEmpty(valList); |
| 523 | | generateNoConstantBindingError(containsEmpty, info); |
| 524 | | blist = List.map(valList,ValuesUtil.valueBool); |
| 525 | | b = Util.selectList(blist, tb, fb); |
| 526 | | (cache,env_1,ih,dae,csets_1,ci_state_1,graph) = Inst.instList(cache, env, ih, mod, pre, csets, ci_state, instEEquation, b, impl, Inst.alwaysUnroll, graph); |
| 527 | | then |
| 528 | | (cache,env_1,ih,dae,csets_1,ci_state_1,graph); |
| 529 | | |
| 530 | | // if-equation |
| 531 | | // If we are doing checkModel we might get an if-equation whose condition is |
| 532 | | // a parameter without a binding, and which DAEUtil.ifEqToExpr can't handle. |
| 533 | | // If the model would have been instantiated one of the branches would have |
| 534 | | // been chosen, so this case therefore chooses one of the branches. |
| 535 | | case (cache,env,ih,mod,pre,csets,ci_state,SCode.EQ_IF(condition = conditions,thenBranch = tb,elseBranch = fb,info=info),SCode.NON_INITIAL(),impl,graph) |
| | 513 | // if equation |
| | 514 | case (cache,env,ih,mod,pre,csets,ci_state,SCode.EQ_IF(condition = conditions,thenBranch = tb,elseBranch = fb,info = info),SCode.NON_INITIAL(),impl,graph) |
| 537 | | true = Flags.getConfigBool(Flags.CHECK_MODEL); |
| 538 | | (cache, _,props,_) = Static.elabExpList(cache,env, conditions, impl,NONE(),true,pre,info); |
| 539 | | DAE.PROP(DAE.T_BOOL(varLst = _),DAE.C_PARAM()) = Types.propsAnd(props); |
| 540 | | b = Util.selectList({true}, tb, fb); |
| 541 | | (cache,env_1,ih,dae,csets_1,ci_state_1,graph) = Inst.instList(cache, env, ih, mod, pre, csets, ci_state, instEEquation, b, impl, Inst.alwaysUnroll, graph); |
| 542 | | then |
| 543 | | (cache,env_1,ih,dae,csets_1,ci_state_1,graph); |
| 544 | | |
| 545 | | // initial if-equation |
| 546 | | // if the condition is constant this case will select the correct branch and remove the initial if-equation |
| 547 | | case (cache,env,ih,mod,pre,csets,ci_state,SCode.EQ_IF(condition = conditions,thenBranch = tb,elseBranch = fb,info=info),SCode.INITIAL(),impl,graph) |
| 548 | | equation |
| | 516 | print("EQ_IF: " +& Dump.printExpStr(Absyn.TUPLE(conditions)) +& "\n"); |
| 551 | | (cache,valList,_) = Ceval.cevalList(cache, env, expl1, impl, NONE(), Ceval.NO_MSG()); |
| 552 | | blist = List.map(valList,ValuesUtil.valueBool); |
| 553 | | b = Util.selectList(blist, tb, fb); |
| 554 | | (cache,env_1,ih,dae,csets_1,ci_state_1,graph) = Inst.instList(cache,env,ih, mod, pre, csets, ci_state, instEInitialEquation, b, impl, Inst.alwaysUnroll, graph); |
| 555 | | then |
| 556 | | (cache,env_1,ih,dae,csets_1,ci_state_1,graph); |
| 557 | | |
| 558 | | // if equation when condition is not constant |
| 559 | | case (cache,env,ih,mod,pre,csets,ci_state,SCode.EQ_IF(condition = conditions,thenBranch = tb,elseBranch = fb,info = info),SCode.NON_INITIAL(),impl,graph) |
| 560 | | equation |
| 561 | | (cache, expl1,props,_) = Static.elabExpList(cache,env, conditions, impl,NONE(),true,pre,info); |
| 562 | | DAE.PROP(DAE.T_BOOL(varLst = _),DAE.C_VAR()) = Types.propsAnd(props); |
| 563 | | (cache,expl1) = PrefixUtil.prefixExpList(cache, env, ih, expl1, pre); |
| | 544 | // if-equation |
| | 545 | // If we are doing checkModel we might get an if-equation whose condition is |
| | 546 | // a parameter without a binding, and which DAEUtil.ifEqToExpr can't handle. |
| | 547 | // If the model would have been instantiated one of the branches would have |
| | 548 | // been chosen, so this case therefore chooses one of the branches. |
| | 549 | case (cache,env,ih,mod,pre,csets,ci_state,SCode.EQ_IF(condition = conditions,thenBranch = tb,elseBranch = fb,info=info),SCode.NON_INITIAL(),impl,graph) |
| | 550 | equation |
| | 551 | true = Flags.getConfigBool(Flags.CHECK_MODEL); |
| | 552 | (cache, _,props,_) = Static.elabExpList(cache,env, conditions, impl,NONE(),true,pre,info); |
| | 553 | DAE.PROP(DAE.T_BOOL(varLst = _),DAE.C_PARAM()) = Types.propsAnd(props); |
| | 554 | b = Util.selectList({true}, tb, fb); |
| | 555 | (cache,env_1,ih,dae,csets_1,ci_state_1,graph) = Inst.instList(cache, env, ih, mod, pre, csets, ci_state, instEEquation, b, impl, Inst.alwaysUnroll, graph); |
| | 556 | then |
| | 557 | (cache,env_1,ih,dae,csets_1,ci_state_1,graph); |
| | 558 | |
| | 2916 | protected function makeIfEquation "Selects branches and creates the elements associated with the if-equation" |
| | 2917 | input Env.Cache inCache; |
| | 2918 | input Env.Env inEnv; |
| | 2919 | input Boolean impl; |
| | 2920 | input InstanceHierarchy ih; |
| | 2921 | input Prefix.Prefix pre; |
| | 2922 | input list<DAE.Properties> props; |
| | 2923 | input Boolean isInitial; |
| | 2924 | input list<DAE.Exp> exps; |
| | 2925 | input list<list<DAE.Element>> tbs; |
| | 2926 | input list<DAE.Element> fb; |
| | 2927 | input list<DAE.Exp> accExp; |
| | 2928 | input list<list<DAE.Element>> accTb; |
| | 2929 | input DAE.ElementSource source; |
| | 2930 | output Env.Cache outCache; |
| | 2931 | output DAE.DAElist dae; |
| | 2932 | algorithm |
| | 2933 | (outCache,dae) := matchcontinue (inCache,inEnv,impl,ih,pre,props,isInitial,exps,tbs,fb,accExp,accTb,source) |
| | 2934 | local |
| | 2935 | DAE.Exp exp; |
| | 2936 | list<DAE.Element> tb,elts; |
| | 2937 | list<list<DAE.Element>> restTb; |
| | 2938 | list<DAE.Exp> restExp,exps; |
| | 2939 | list<DAE.Properties> restProp; |
| | 2940 | DAE.Properties prop; |
| | 2941 | Env.Cache cache; |
| | 2942 | Boolean b; |
| | 2943 | Option<Values.Value> containsEmpty; |
| | 2944 | DAE.Const cnst; |
| | 2945 | list<Values.Value> valList; |
| | 2946 | list<Boolean> blist; |
| | 2947 | case (cache,inEnv,impl,ih,pre,props,isInitial,exps,tbs,fb,accExp,accTb,source) |
| | 2948 | equation |
| | 2949 | DAE.PROP(_,cnst) = Types.propsAnd(props); |
| | 2950 | true = Types.isParameterOrConstant(cnst); |
| | 2951 | print("Exps to eval: " +& ExpressionDump.printExpStr(DAE.TUPLE(exps)) +& "\n"); |
| | 2952 | (cache,valList,_) = Ceval.cevalList(cache, inEnv, exps, impl, NONE(), Ceval.NO_MSG()); |
| | 2953 | print("evaled: " +& ValuesUtil.valString(Values.TUPLE(valList)) +& "\n"); |
| | 2954 | // check if valList contains Values.EMPTY() |
| | 2955 | containsEmpty = ValuesUtil.containsEmpty(valList); |
| | 2956 | generateNoConstantBindingError(containsEmpty, DAEUtil.getElementSourceFileInfo(source)); |
| | 2957 | blist = List.map(valList,ValuesUtil.valueBool); |
| | 2958 | elts = Util.selectList(blist, tbs, fb); |
| | 2959 | then (cache,DAE.DAE(elts)); |
| | 2960 | case (cache,inEnv,impl,ih,pre,props,isInitial,exps,tbs,fb,accExp,accTb,source) |
| | 2961 | equation |
| | 2962 | DAE.PROP(_,DAE.C_VAR()) = Types.propsAnd(props); |
| | 2963 | (cache,exps) = PrefixUtil.prefixExpList(cache, inEnv, ih, exps, pre); |
| | 2964 | print("Exps to not eval: " +& ExpressionDump.printExpStr(DAE.TUPLE(exps)) +& "\n"); |
| | 2965 | elts = makeIfEquation2(isInitial,exps,tbs,fb,source); |
| | 2966 | then (cache,DAE.DAE(elts)); |
| | 2967 | // TODO: Use something smarter? Sadly does not work properly... |
| | 2968 | /* |
| | 2969 | case (cache,inEnv,impl,ih,pre,prop::restProp,isInitial,exp::restExp,tb::restTb,fb,accExp,accTb,source) |
| | 2970 | equation |
| | 2971 | true = Types.isParameterOrConstant(Types.propAllConst(prop)); |
| | 2972 | (cache,Values.BOOL(b),_) = Ceval.ceval(cache,inEnv,exp,impl,NONE(),Ceval.NO_MSG()); |
| | 2973 | (cache,dae) = makeIfEquation(cache,inEnv,impl,ih,pre,Util.if_(b,{},restProp),isInitial,Util.if_(b,{},restExp),Util.if_(b,{},restTb),Util.if_(b,tb,fb),accExp,accTb,source); |
| | 2974 | then (cache,dae); |
| | 2975 | case (cache,inEnv,impl,ih,pre,prop::restProp,isInitial,exp::restExp,tb::restTb,fb,accExp,accTb,source) |
| | 2976 | equation |
| | 2977 | false = Types.isConstant(Types.propAllConst(prop)); |
| | 2978 | (cache,dae) = makeIfEquation(cache,inEnv,impl,ih,pre,restProp,isInitial,restExp,restTb,fb,exp::accExp,tb::accTb,source); |
| | 2979 | then (cache,dae); |
| | 2980 | case (cache,inEnv,impl,ih,pre,{},isInitial,{},{},fb,accExp,accTb,source) |
| | 2981 | equation |
| | 2982 | (cache,exps) = PrefixUtil.prefixExpList(cache, inEnv, ih, listReverse(accExp), pre); |
| | 2983 | elts = makeIfEquation2(isInitial,exps,listReverse(accTb),fb,source); |
| | 2984 | then (cache,DAE.DAE(elts)); |
| | 2985 | */ |
| | 2986 | end matchcontinue; |
| | 2987 | end makeIfEquation; |
| | 2988 | |
| | 2989 | protected function makeIfEquation2 |
| | 2990 | input Boolean isInitial; |
| | 2991 | input list<DAE.Exp> exps; |
| | 2992 | input list<list<DAE.Element>> tbs; |
| | 2993 | input list<DAE.Element> fb; |
| | 2994 | input DAE.ElementSource source; |
| | 2995 | output list<DAE.Element> outElements; |
| | 2996 | algorithm |
| | 2997 | outElements := matchcontinue (isInitial,exps,tbs,fb,source) |
| | 2998 | case (_,{},_,fb,source) |
| | 2999 | then fb; |
| | 3000 | case (false,exps,tbs,fb,source) |
| | 3001 | then DAE.IF_EQUATION(exps,tbs,fb,source)::{}; |
| | 3002 | case (true,exps,tbs,fb,source) |
| | 3003 | then DAE.INITIAL_IF_EQUATION(exps,tbs,fb,source)::{}; |
| | 3004 | end matchcontinue; |
| | 3005 | end makeIfEquation2; |
| | 3006 | |