Ticket #1736: InstSection.2.patch

File InstSection.2.patch, 21.2 KB (added by Martin Sjölund, 12 years ago)
  • Compiler/FrontEnd/Ceval.mo

     
    853853  end matchcontinue;
    854854end cevalIfConstant;
    855855
     856public function cevalListIfConstantOrParam
     857  "This function constant evaluates an expression if the expression is constant,
     858   or if the expression is a call of parameter constness whose return type
     859   contains unknown dimensions (in which case we need to determine the size of
     860   those dimensions)."
     861  input Env.Cache inCache;
     862  input Env.Env inEnv;
     863  input list<DAE.Exp> inExps;
     864  input list<DAE.Const> inConst;
     865  input Boolean impl;
     866  input Msg msg;
     867  input list<DAE.Exp> acc;
     868  output Env.Cache outCache;
     869  output list<DAE.Exp> outExps;
     870algorithm
     871  (outCache, outExps) := match (inCache, inEnv, inExps, inConst, impl, msg, acc)
     872    local
     873      list<DAE.Exp> exps;
     874      DAE.Exp exp;
     875      DAE.Const const;
     876      list<DAE.Const> consts;
     877      Env.Cache cache;
     878      Env.Env env;
     879      Values.Value val;
     880    case (cache,env,exp::exps,DAE.C_VAR()::consts,impl,msg,acc)
     881      equation
     882        (cache,exps) = cevalListIfConstantOrParam(cache, env, exps, consts, impl, msg, exp::acc);
     883      then (cache,exps);
     884    case (cache,env,exp::exps,_::consts,impl,msg,acc)
     885      equation
     886        (cache,val,_) = ceval(cache, env, exp, impl, NONE(), msg);
     887        exp = ValuesUtil.valueExp(val);
     888        (cache,exps) = cevalListIfConstantOrParam(cache, env, exps, consts, impl, msg, exp::acc);
     889      then (cache,exps);
     890    case (cache,_,{},{},_,_,acc) then (cache,listReverse(acc));
     891  end match;
     892end cevalListIfConstantOrParam;
     893
    856894protected function cevalWholedimRetCall
    857895  "Helper function to cevalIfConstant. Determines the size of any unknown
    858896   dimensions in a function calls return type."
  • Compiler/FrontEnd/InstSection.mo

     
    452452      DAE.ComponentRef cr_,cr1_,cr2_;
    453453      DAE.Type t;
    454454      DAE.Properties tprop1,tprop2;
     455      Boolean unreachable;
    455456      Real priority;
    456457      DAE.Exp exp;
    457458      Option<Values.Value> containsEmpty;
     
    510511        Error.addSourceMessage(Error.TUPLE_ASSIGN_FUNCALL_ONLY,{s},info);
    511512      then fail();*/
    512513
    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)
     514    // 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)
    536516      equation
    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
    549517        (cache, expl1,props,_) = Static.elabExpList(cache,env, conditions, impl,NONE(),true,pre,info);
    550518        DAE.PROP(DAE.T_BOOL(varLst = _),_) = Types.propsAnd(props);
    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);
     519        (cache,expl1) = Ceval.cevalListIfConstantOrParam(cache, env, expl1, List.map(props,Types.propAllConst), impl, Ceval.MSG(info), {});
     520        (cache,expl1) = PrefixUtil.prefixExpList(cache, inEnv, ih, expl1, pre);
    564521       
    565522        // set the source of this element
    566523        source = DAEUtil.createElementSource(info, Env.getEnvPath(env), PrefixUtil.prefixToCrefOpt(pre), NONE(), NONE());
    567524       
    568         (cache,env_1,ih,daeLLst,_,ci_state_1,graph) = instIfTrueBranches(cache, env,ih, mod, pre, csets, ci_state, tb, false, impl, graph);
    569         (cache,env_2,ih,DAE.DAE(daeElts2),_,ci_state_2,graph) = Inst.instList(cache,env_1,ih, mod, pre, csets, ci_state, instEEquation, fb, impl, Inst.alwaysUnroll, graph) "There are no connections inside if-clauses." ;
    570         dae = DAE.DAE({DAE.IF_EQUATION(expl1,daeLLst,daeElts2,source)});
     525        (cache,env_1,ih,daeLLst,unreachable,csets,ci_state_1,graph) = instIfTrueBranches(cache, env,ih, mod, pre, csets, ci_state, expl1, false, tb, false, impl, graph);
     526        (fb,_) = SCode.traverseEEquationsList(fb, (replaceConnectWithLegalEquation,unreachable));
     527        (cache,env_2,ih,DAE.DAE(daeElts2),csets,ci_state_2,graph) = Inst.instList(cache,env_1,ih, mod, pre, csets, ci_state, instEEquation, fb, impl, Inst.alwaysUnroll, graph) "There are no connections inside if-clauses." ;
     528        (cache,dae) = makeIfEquation(cache,env,impl,ih,pre,false,expl1,daeLLst,daeElts2,{},{},source);
    571529      then
    572530        (cache,env_1,ih,dae,csets,ci_state_1,graph);
    573531
    574     // initial if equation  when condition is not constant
     532    // initial if equation
    575533    case (cache,env,ih,mod,pre,csets,ci_state,SCode.EQ_IF(condition = conditions,thenBranch = tb,elseBranch = fb, info = info),SCode.INITIAL(),impl,graph)
    576534      equation
    577535        (cache, expl1,props,_) = Static.elabExpList(cache,env, conditions, impl,NONE(),true,pre,info);
    578         DAE.PROP(DAE.T_BOOL(varLst = _),DAE.C_VAR()) = Types.propsAnd(props);
    579         (cache,expl1) = PrefixUtil.prefixExpList(cache, env, ih, expl1, pre);
     536        DAE.PROP(DAE.T_BOOL(varLst = _),_) = Types.propsAnd(props);
     537        (cache,expl1) = Ceval.cevalListIfConstantOrParam(cache, env, expl1, List.map(props,Types.propAllConst), impl, Ceval.MSG(info), {});
     538        (cache,expl1) = PrefixUtil.prefixExpList(cache, inEnv, ih, expl1, pre);
    580539
    581540        // set the source of this element
    582541        source = DAEUtil.createElementSource(info, Env.getEnvPath(env), PrefixUtil.prefixToCrefOpt(pre), NONE(), NONE());
    583542       
    584         (cache,env_1,ih,daeLLst,_,ci_state_1,graph) = instIfTrueBranches(cache,env,ih, mod, pre, csets, ci_state, tb, true, impl, graph);
    585         (cache,env_2,ih,DAE.DAE(daeElts2),_,ci_state_2,graph) = Inst.instList(cache,env_1,ih, mod, pre, csets, ci_state, instEInitialEquation, fb, impl, Inst.alwaysUnroll, graph) "There are no connections inside if-clauses." ;
    586         dae = DAE.DAE({DAE.INITIAL_IF_EQUATION(expl1,daeLLst,daeElts2,source)});
     543        (cache,env_1,ih,daeLLst,unreachable,csets,ci_state_1,graph) = instIfTrueBranches(cache,env,ih, mod, pre, csets, ci_state, expl1, false, tb, true, impl, graph);
     544        (fb,_) = SCode.traverseEEquationsList(fb, (replaceConnectWithLegalEquation,unreachable));
     545        (cache,env_2,ih,DAE.DAE(daeElts2),csets,ci_state_2,graph) = Inst.instList(cache,env_1,ih, mod, pre, csets, ci_state, instEInitialEquation, fb, impl, Inst.alwaysUnroll, graph) "There are no connections inside if-clauses." ;
     546        (cache,dae) = makeIfEquation(cache,env,impl,ih,pre,true,expl1,daeLLst,daeElts2,{},{},source);
    587547      then
    588548        (cache,env_1,ih,dae,csets,ci_state_1,graph);
    589549
     550    // if-equation
     551    // If we are doing checkModel we might get an if-equation whose condition is
     552    // a parameter without a binding, and which DAEUtil.ifEqToExpr can't handle.
     553    // If the model would have been instantiated one of the branches would have
     554    // been chosen, so this case therefore chooses one of the branches.
     555    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)
     556      equation
     557        true = Flags.getConfigBool(Flags.CHECK_MODEL);
     558        (cache, _,props,_) = Static.elabExpList(cache,env, conditions, impl,NONE(),true,pre,info);
     559        DAE.PROP(DAE.T_BOOL(varLst = _),DAE.C_PARAM()) = Types.propsAnd(props);
     560        b = Util.selectList({true}, tb, fb);
     561        (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);
     562      then
     563        (cache,env_1,ih,dae,csets_1,ci_state_1,graph);
     564
    590565    // when equation statement, modelica 1.1
    591566    //  When statements are instantiated by evaluating the conditional expression.
    592567    case (cache,env,ih,mod,pre,csets,ci_state, eq as SCode.EQ_WHEN(condition = e,eEquationLst = el,elseBranches = ((ee,eel) :: eex),info=info),(initial_ as SCode.NON_INITIAL()),impl,graph)
     
    28742849end rangeExpression;
    28752850
    28762851protected function instIfTrueBranches
    2877 "Author: BZ, 2008-09
    2878  Initialise a list of if-equations,
    2879  if, elseif-1 ... elseif-n."
     2852  "Initialise a list of if-equations, if, elseif-1 ... elseif-n."
    28802853  input Env.Cache inCache;
    28812854  input Env.Env inEnv;
    28822855  input InstanceHierarchy inIH;
     
    28842857  input Prefix.Prefix inPrefix;
    28852858  input Connect.Sets inSets;
    28862859  input ClassInf.State inState;
     2860  input list<DAE.Exp> inConds;
     2861  input Boolean unreachable;
    28872862  input list<list<SCode.EEquation>> inTypeALst;
    28882863  input Boolean IE;
    28892864  input Boolean inBoolean;
     
    28922867  output Env.Env outEnv;
    28932868  output InstanceHierarchy outIH;
    28942869  output list<list<DAE.Element>> outDaeLst;
     2870  output Boolean outUnreachable;
    28952871  output Connect.Sets outSets;
    28962872  output ClassInf.State outState;
    28972873  output ConnectionGraph.ConnectionGraph outGraph;
    28982874algorithm
    2899   (outCache,outEnv,outIH,outDaeLst,outSets,outState,outGraph):=
    2900   matchcontinue (inCache,inEnv,inIH,inMod,inPrefix,inSets,inState,inTypeALst,IE,inBoolean,inGraph)
     2875  (outCache,outEnv,outIH,outDaeLst,outUnreachable,outSets,outState,outGraph):=
     2876  matchcontinue (inCache,inEnv,inIH,inMod,inPrefix,inSets,inState,inConds,unreachable,inTypeALst,IE,inBoolean,inGraph)
    29012877    local
    29022878      list<Env.Frame> env,env_1,env_2;
    29032879      DAE.Mod mod;
     
    29092885      list<list<SCode.EEquation>> es;
    29102886      list<SCode.EEquation> e;
    29112887      Env.Cache cache;
    2912       ConnectionGraph.ConnectionGraph graph;
     2888      ConnectionGraph.ConnectionGraph graph,graph2;
    29132889      InstanceHierarchy ih;
    29142890      list<DAE.Element> elts;
     2891      DAE.Exp exp;
     2892      list<DAE.Exp> restExp;
     2893      Integer i;
    29152894
    2916     case (cache,env,ih,mod,pre,csets,ci_state,{},_,impl,graph)
     2895    case (cache,env,ih,mod,pre,csets,ci_state,{},unreachable,{},_,impl,graph)
    29172896      then
    2918         (cache,env,ih,{},csets,ci_state,graph);
    2919     case (cache,env,ih,mod,pre,csets,ci_state,(e :: es),false,impl,graph)
     2897        (cache,env,ih,{},unreachable,csets,ci_state,graph);
     2898
     2899    case (cache,env,ih,mod,pre,csets,ci_state,exp::restExp,unreachable,e::es,IE,impl,graph)
    29202900      equation
     2901        true = Expression.isFalse(exp) or unreachable;
     2902        // Remove connections since they are evil
     2903        (e,_) = SCode.traverseEEquationsList(e,(replaceConnectWithLegalEquation,true));
    29212904        (cache,env_1,ih,DAE.DAE(elts),csets_1,ci_state_1,graph) =
    2922            Inst.instList(cache, env, ih, mod, pre, csets, ci_state, instEEquation, e, impl, Inst.alwaysUnroll, graph);
    2923         (cache,env_2,ih,llb,csets_2,ci_state_2,graph) =
    2924            instIfTrueBranches(cache, env_1, ih, mod, pre, csets_1, ci_state_1,  es, false, impl, graph);
     2905           Inst.instList(cache, env, ih, mod, pre, csets, ci_state, Util.if_(IE,instEInitialEquation,instEEquation), e, impl, Inst.alwaysUnroll, graph);
     2906        // Discard this connection graph since it is invalid; should not be needed since all connections were removed, but let's be safe
     2907        (cache,env_2,ih,llb,unreachable,csets_2,ci_state_2,graph) =
     2908           instIfTrueBranches(cache, env_1, ih, mod, pre, csets_1, ci_state_1, restExp, unreachable, es, IE, impl, graph);
    29252909      then
    2926         (cache,env_2,ih,elts::llb,csets_2,ci_state_2,graph);
     2910        (cache,env_2,ih,elts::llb,unreachable,csets_2,ci_state_2,graph);
    29272911
    2928     case (cache,env,ih,mod,pre,csets,ci_state,(e :: es),true,impl,graph)
     2912    case (cache,env,ih,mod,pre,csets,ci_state,DAE.BCONST(true)::restExp,false,e::es,IE,impl,graph)
    29292913      equation
    29302914        (cache,env_1,ih,DAE.DAE(elts),csets_1,ci_state_1,graph) =
    2931            Inst.instList(cache, env, ih, mod, pre, csets, ci_state, instEInitialEquation, e, impl, Inst.alwaysUnroll, graph);
    2932         (cache,env_2,ih,llb,csets_2,ci_state_2,graph) =
    2933            instIfTrueBranches(cache, env_1, ih, mod, pre, csets_1, ci_state_1,  es, true, impl, graph);
     2915           Inst.instList(cache, env, ih, mod, pre, csets, ci_state, Util.if_(IE,instEInitialEquation,instEEquation), e, impl, Inst.alwaysUnroll, graph);
     2916        (cache,env_2,ih,llb,unreachable,csets_2,ci_state_2,graph) =
     2917           instIfTrueBranches(cache, env_1, ih, mod, pre, csets_1, ci_state_1, restExp, true, es, IE, impl, graph);
    29342918      then
    2935         (cache,env_2,ih,elts::llb,csets_2,ci_state_2,graph);
     2919        (cache,env_2,ih,elts::llb,unreachable,csets_2,ci_state_2,graph);
    29362920
    2937     case (cache,env,ih,mod,pre,csets,ci_state,(e :: es),_,impl,graph)
     2921    case (cache,env,ih,mod,pre,csets,ci_state,exp::restExp,false,e::es,IE,impl,graph)
    29382922      equation
     2923        // Remove connections since they are evil
     2924        (e,(_,i)) = SCode.traverseEEquationsList(e,(findConnectInNonParamIfError,0));
     2925        (cache,env_1,ih,DAE.DAE(elts),csets_1,ci_state_1,graph) =
     2926           Inst.instList(cache, env, ih, mod, pre, csets, ci_state, Util.if_(IE,instEInitialEquation,instEEquation), e, impl, Inst.alwaysUnroll, graph);
     2927        (cache,env_2,ih,llb,unreachable,csets_2,ci_state_2,graph) =
     2928           instIfTrueBranches(cache, env_1, ih, mod, pre, csets_1, ci_state_1, restExp, unreachable, es, IE, impl, graph);
     2929      then
     2930        (cache,env_2,ih,elts::llb,unreachable,csets_2,ci_state_2,graph);
     2931
     2932    case (cache,env,ih,mod,pre,csets,ci_state,_,_,(e :: es),_,impl,graph)
     2933      equation
    29392934        true = Flags.isSet(Flags.FAILTRACE);
    29402935        Debug.fprintln(Flags.FAILTRACE, "InstSection.instIfTrueBranches failed on equations: " +&
    29412936                       stringDelimitList(List.map(e, SCodeDump.equationStr), "\n"));
     
    29442939  end matchcontinue;
    29452940end instIfTrueBranches;
    29462941
     2942protected function replaceConnectWithLegalEquation
     2943  "Replaces connections with a legal terminate equation"
     2944  input tuple<SCode.EEquation, Boolean> inTuple;
     2945  output tuple<SCode.EEquation, Boolean> outTuple;
     2946algorithm
     2947  outTuple := match inTuple
     2948    local
     2949      Absyn.Info info;
     2950    case ((SCode.EQ_CONNECT(info=info),true))
     2951      then ((SCode.EQ_TERMINATE(Absyn.STRING("Connection removed from type checking since branch was false"),NONE(),info),true));
     2952    else inTuple;
     2953  end match;
     2954end replaceConnectWithLegalEquation;
     2955
     2956protected function findConnectInNonParamIfError
     2957  "Replaces connections with a legal terminate equation"
     2958  input tuple<SCode.EEquation, Integer> inTuple;
     2959  output tuple<SCode.EEquation, Integer> outTuple;
     2960algorithm
     2961  outTuple := match inTuple
     2962    local
     2963      Absyn.Info info;
     2964    case ((SCode.EQ_CONNECT(info=info),_))
     2965      equation
     2966        Error.addSourceMessage(Error.INTERNAL_ERROR,{"Connections are not allowed in if-branches that cannot be evaluated at runtime"},info);
     2967      then fail();
     2968    else inTuple;
     2969  end match;
     2970end findConnectInNonParamIfError;
     2971
     2972protected function makeIfEquation "Selects branches and creates the elements associated with the if-equation"
     2973  input Env.Cache inCache;
     2974  input Env.Env inEnv;
     2975  input Boolean impl;
     2976  input InstanceHierarchy ih;
     2977  input Prefix.Prefix pre;
     2978  input Boolean isInitial;
     2979  input list<DAE.Exp> exps;
     2980  input list<list<DAE.Element>> tbs;
     2981  input list<DAE.Element> fb;
     2982  input list<DAE.Exp> accExp;
     2983  input list<list<DAE.Element>> accTb;
     2984  input DAE.ElementSource source;
     2985  output Env.Cache outCache;
     2986  output DAE.DAElist dae;
     2987algorithm
     2988  (outCache,dae) := matchcontinue (inCache,inEnv,impl,ih,pre,isInitial,exps,tbs,fb,accExp,accTb,source)
     2989    local
     2990      DAE.Exp exp;
     2991      list<DAE.Element> tb,elts;
     2992      list<list<DAE.Element>> restTb;
     2993      list<DAE.Exp> restExp,exps;
     2994      list<DAE.Properties> restProp;
     2995      DAE.Properties prop;
     2996      Env.Cache cache;
     2997      Boolean b;
     2998      Option<Values.Value> containsEmpty;
     2999      DAE.Const cnst;
     3000      list<Values.Value> valList;
     3001      list<Boolean> blist;
     3002    case (cache,inEnv,impl,ih,pre,isInitial,DAE.BCONST(false)::restExp,_::restTb,fb,accExp,accTb,source)
     3003      equation
     3004        (cache,dae) = makeIfEquation(cache,inEnv,impl,ih,pre,isInitial,restExp,restTb,fb,accExp,accTb,source);
     3005      then (cache,dae);
     3006    case (cache,inEnv,impl,ih,pre,isInitial,DAE.BCONST(true)::restExp,tb::_,_,accExp,accTb,source)
     3007      equation
     3008        elts = makeIfEquation2(isInitial,listReverse(accExp),listReverse(accTb),tb,source);
     3009      then (cache,DAE.DAE(elts));
     3010    case (cache,inEnv,impl,ih,pre,isInitial,exp::restExp,tb::restTb,fb,accExp,accTb,source)
     3011      equation
     3012        (cache,dae) = makeIfEquation(cache,inEnv,impl,ih,pre,isInitial,restExp,restTb,fb,exp::accExp,tb::accTb,source);
     3013      then (cache,dae);
     3014    case (cache,inEnv,impl,ih,pre,isInitial,{},{},fb,accExp,accTb,source)
     3015      equation
     3016        elts = makeIfEquation2(isInitial,listReverse(accExp),listReverse(accTb),fb,source);
     3017      then (cache,DAE.DAE(elts));
     3018  end matchcontinue;
     3019end makeIfEquation;
     3020
     3021protected function makeIfEquation2
     3022  input Boolean isInitial;
     3023  input list<DAE.Exp> exps;
     3024  input list<list<DAE.Element>> tbs;
     3025  input list<DAE.Element> fb;
     3026  input DAE.ElementSource source;
     3027  output list<DAE.Element> outElements;
     3028algorithm
     3029  outElements := matchcontinue (isInitial,exps,tbs,fb,source)
     3030    case (_,{},_,fb,source)
     3031      then fb;
     3032    case (false,exps,tbs,fb,source)
     3033      then DAE.IF_EQUATION(exps,tbs,fb,source)::{};
     3034    case (true,exps,tbs,fb,source)
     3035      then DAE.INITIAL_IF_EQUATION(exps,tbs,fb,source)::{};
     3036  end matchcontinue;
     3037end makeIfEquation2;
     3038
    29473039protected function instElseIfs
    29483040"function: instElseIfs
    29493041  This function helps instStatement to handle elseif parts."
  • Compiler/FrontEnd/Expression.mo

     
    57235723  end match;
    57245724end isZero;
    57255725
     5726public function isFalse
     5727"function: isFalse
     5728  Returns true if an expression is constant
     5729  and has the value false, otherwise false"
     5730  input DAE.Exp inExp;
     5731  output Boolean outBoolean;
     5732algorithm
     5733  outBoolean := match (inExp)
     5734    local
     5735      Boolean b;
     5736    case (DAE.BCONST(b)) then not b;
     5737    else false;
     5738  end match;
     5739end isFalse;
     5740
     5741public function isTrue
     5742"function: isTrue
     5743  Returns true if an expression is constant
     5744  and has the value false, otherwise false"
     5745  input DAE.Exp inExp;
     5746  output Boolean outBoolean;
     5747algorithm
     5748  outBoolean := match (inExp)
     5749    local
     5750      Boolean b;
     5751    case (DAE.BCONST(b)) then b;
     5752    else false;
     5753  end match;
     5754end isTrue;
     5755
    57265756public function isPositiveOrZero
    57275757  "Returns true if an expression is known to be >= 0"
    57285758  input DAE.Exp inExp;