From 4fddc6fe14b0990a2298da131823356fc18fe546 Mon Sep 17 00:00:00 2001 From: Peter Aronsson Date: Wed, 3 Jan 2007 12:58:42 +0000 Subject: [PATCH] Added error message for not-yet-supported features in algorithms (when clause, while-clause, etc) git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@2651 f25d12d1-65f4-0310-ae8a-bbce733d8d8e --- Compiler/DAELow.mo | 77 ++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 74 insertions(+), 3 deletions(-) diff --git a/Compiler/DAELow.mo b/Compiler/DAELow.mo index 701ccedaedf..49cb9145048 100644 --- a/Compiler/DAELow.mo +++ b/Compiler/DAELow.mo @@ -4141,19 +4141,90 @@ algorithm Exp.Type tp; Exp.ComponentRef cr; Exp.Exp e; + list expl; + list stmts; + Algorithm.Else elsebranch; + list inputs,inputs1,inputs2,inputs3,outputs,outputs1,outputs2; + list crefs; + // a := expr; case (vars,Algorithm.ASSIGN(type_ = tp,componentRef = cr,exp = e)) equation inputs = statesAndVarsExp(e, vars); then (inputs,{Exp.CREF(cr,tp)}); - case (_,_) + // (a,b,c) := foo(...) + case (vars,Algorithm.TUPLE_ASSIGN(tp,expl,e)) equation - print("lower_statement_input_outputs finished yet\n"); + inputs = statesAndVarsExp(e,vars); + crefs = Util.listFlatten(Util.listMap(expl,Exp.getCrefFromExp)); + outputs = Util.listMap1(crefs,Exp.makeCrefExp,Exp.OTHER()); then - fail(); + (inputs,outputs); + // v := expr where v is array. + case (vars,Algorithm.ASSIGN_ARR(tp,cr,e)) + equation + inputs = statesAndVarsExp(e,vars); + then (inputs,{Exp.CREF(cr,tp)}); + + case(vars,Algorithm.IF(e,stmts,elsebranch)) + equation + (inputs1,outputs1) = lowerAlgorithmInputsOutputs(vars,Algorithm.ALGORITHM(stmts)); + (inputs2,outputs2) = lowerElseAlgorithmInputsOutputs(vars,elsebranch); + inputs3 = statesAndVarsExp(e,vars); + inputs = Util.listListUnionP({inputs1, inputs2,inputs3}, Exp.expEqual); + outputs = Util.listUnionP(outputs1, outputs2, Exp.expEqual); + then (inputs,outputs); + + // Features not yet supported. + case(vars,Algorithm.FOR(type_=_)) + equation + Error.addMessage(Error.INTERNAL_ERROR,{"For statements in algorithms not supported yet. Suggested workaround: place for statement in a Modelica function"}); + then fail(); + case(vars,Algorithm.WHILE(exp=_)) + equation + Error.addMessage(Error.INTERNAL_ERROR,{"While statements in algorithms not supported yet. Suggested workaround: place while statement in a Modelica function"}); + then fail(); + case(vars,Algorithm.WHEN(exp=_)) + equation + Error.addMessage(Error.INTERNAL_ERROR,{"When statements in algorithms not supported yet. Suggested workaround: If possible, use when in equation section instead"}); + then fail(); + case(vars,Algorithm.ASSERT(exp1 = _)) + equation + Error.addMessage(Error.INTERNAL_ERROR,{"assert statements in algorithms not supported yet. Suggested workaround: If possible, use assert in equation section instead"}); + then fail(); end matchcontinue; end lowerStatementInputsOutputs; +protected function lowerElseAlgorithmInputsOutputs "Helper function to lowerStatementInputsOutputs" + input Variables vars; + input Algorithm.Else elseBranch; + output list inputs; + output list outputs; +algorithm + (inputs,outputs):= + matchcontinue (vars,elseBranch) + local + list stmts; + list inputs1,inputs2,inputs3,outputs1,outputs2; + Exp.Exp e; + case(vars,Algorithm.NOELSE()) then ({},{}); + + case(vars,Algorithm.ELSEIF(e,stmts,elseBranch)) + equation + (inputs1, outputs1) = lowerElseAlgorithmInputsOutputs(vars,elseBranch); + (inputs2, outputs2) = lowerAlgorithmInputsOutputs(vars,Algorithm.ALGORITHM(stmts)); + inputs3 = statesAndVarsExp(e,vars); + inputs = Util.listListUnionP({inputs1, inputs2, inputs3}, Exp.expEqual); + outputs = Util.listUnionP(outputs1, outputs2, Exp.expEqual); + then (inputs,outputs); + + case(vars,Algorithm.ELSE(stmts)) + equation + (inputs, outputs) = lowerAlgorithmInputsOutputs(vars,Algorithm.ALGORITHM(stmts)); + then (inputs,outputs); + end matchcontinue; +end lowerElseAlgorithmInputsOutputs; + protected function statesAndVarsExp "function: statesAndVarsExp This function investigates an expression and returns as subexpressions