Skip to content

Commit

Permalink
- Fix iterator typing in for equations for SCodeInst.
Browse files Browse the repository at this point in the history
git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@11919 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
perost committed May 15, 2012
1 parent 1335932 commit 2395631
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 12 deletions.
18 changes: 15 additions & 3 deletions Compiler/FrontEnd/InstUtil.mo
Expand Up @@ -147,7 +147,8 @@ algorithm
equation
ty = arrayElementType(ty);
then
DAE.T_SUBTYPE_BASIC(state, {}, ty, ec, src);
ty;
//DAE.T_SUBTYPE_BASIC(state, {}, ty, ec, src);

else inType;
end match;
Expand Down Expand Up @@ -516,6 +517,16 @@ algorithm
outDimension := InstTypes.UNTYPED_DIMENSION(inDimension, false);
end wrapDimension;

public function makeIterator
input Absyn.Path inName;
input DAE.Type inType;
input Absyn.Info inInfo;
output Component outIterator;
algorithm
outIterator := InstTypes.TYPED_COMPONENT(inName, inType,
InstTypes.NO_DAE_PREFIXES(), InstTypes.UNBOUND(), inInfo);
end makeIterator;

public function mergePrefixesFromComponent
"Merges a component's prefixes with the given prefixes, with the component's
prefixes having priority."
Expand Down Expand Up @@ -1536,7 +1547,7 @@ algorithm
DAE.Type ty1, ty2;
DAE.ComponentRef cref1, cref2;
Connect.Face face1, face2;
String index, res, eql_str;
String index, res, eql_str, range_str;
String exp_str1, exp_str2, ty_str1, ty_str2, face_str1, face_str2;
list<Equation> eql;

Expand Down Expand Up @@ -1564,7 +1575,8 @@ algorithm
range = exp1, body = eql))
equation
ty_str1 = Types.unparseType(ty1);
res = "for {" +& ty_str1 +& "} " +& index +& " loop\n ";
range_str = ExpressionDump.printExpStr(exp1);
res = "for {" +& ty_str1 +& "} " +& index +& " in " +& range_str +& " loop\n ";
eql_str = stringDelimitList(List.map(eql, printEquation), "\n");
res = res +& eql_str +& "\n end for;\n";
then
Expand Down
7 changes: 4 additions & 3 deletions Compiler/FrontEnd/SCodeInst.mo
Expand Up @@ -1027,21 +1027,22 @@ protected function addDimensionsFromType
output list<DAE.Dimension> outDimensions;
output Integer outAddedDims;
algorithm
(outDimensions, outAddedDims) := match(inDimensions, inType)
(outDimensions, outAddedDims) := matchcontinue(inDimensions, inType)
local
list<DAE.Dimension> dims;
Integer added_dims;

case (_, DAE.T_ARRAY(dims = dims))
case (_, _)
equation
dims = Types.getDimensions(inType);
added_dims = listLength(dims);
dims = listAppend(inDimensions, dims);
then
(dims, added_dims);

else (inDimensions, 0);

end match;
end matchcontinue;
end addDimensionsFromType;

protected function instExpList
Expand Down
17 changes: 11 additions & 6 deletions Compiler/FrontEnd/Typing.mo
Expand Up @@ -975,26 +975,29 @@ algorithm
DAE.Type ty;
list<tuple<DAE.Exp, list<Equation>>> branches;
list<Equation> acc_el;
Absyn.Path iter_name;
Component iter;

case (InstTypes.EQUALITY_EQUATION(lhs, rhs, info), st, acc_el)
equation
(rhs, _, _) = typeExp(rhs, NO_EVAL(), st);
(lhs, _, _) = typeExp(lhs, NO_EVAL(), st);
(rhs, _, _) = typeExp(rhs, EVAL_CONST(), st);
(lhs, _, _) = typeExp(lhs, EVAL_CONST(), st);
then
InstTypes.EQUALITY_EQUATION(lhs, rhs, info) :: acc_el;

case (InstTypes.CONNECT_EQUATION(cref1, _, cref2, _, prefix, info), st, acc_el)
equation
acc_el = typeConnection(cref1, cref2, prefix, st, info, acc_el);
//(cref1, face1) = lookupConnector(cref1, prefix, st, info);
//(cref2, face2) = lookupConnector(cref2, prefix, st, info);
then
acc_el;

case (InstTypes.FOR_EQUATION(index, _, exp1, eql, info), st, acc_el)
equation
(exp1, ty, _) = typeExp(exp1, EVAL_CONST_PARAM(), st);
ty = rangeToIteratorType(ty, exp1, info);
iter_name = Absyn.IDENT(index);
iter = InstUtil.makeIterator(iter_name, ty, info);
st = InstSymbolTable.addIterator(iter_name, iter, st);
eql = typeEquations(eql, st);
then
InstTypes.FOR_EQUATION(index, ty, exp1, eql, info) :: acc_el;
Expand All @@ -1011,15 +1014,17 @@ algorithm
then
InstTypes.WHEN_EQUATION(branches, info) :: acc_el;

// TODO: Remove equation if condition = false.
// TODO: Remove equation if condition = false. Actually, that should only be
// done if all conditions are false, due to non-expansion. Individual
// asserts can be removed during expansion.
case (InstTypes.ASSERT_EQUATION(exp1, exp2, info), st, acc_el)
equation
(exp1, _, _) = typeExp(exp1, EVAL_CONST(), st);
(exp2, _, _) = typeExp(exp2, EVAL_CONST(), st);
then
InstTypes.ASSERT_EQUATION(exp1, exp2, info) :: acc_el;

// TODO: Remove equation if condition = false.
// TODO: Remove equation if condition = false. See asserts above.
case (InstTypes.TERMINATE_EQUATION(exp1, info), st, acc_el)
equation
(exp1, _, _) = typeExp(exp1, EVAL_CONST(), st);
Expand Down

0 comments on commit 2395631

Please sign in to comment.