Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
- The cat() operator now does basic type checking :)


git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@9558 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
sjoelund committed Jul 29, 2011
1 parent 7206d4d commit b0db4ba
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 5 deletions.
10 changes: 7 additions & 3 deletions Compiler/FrontEnd/Static.mo
Expand Up @@ -5372,9 +5372,10 @@ algorithm
Integer dim,num_matrices;
list<DAE.Exp> matrices_1;
list<DAE.Properties> props;
DAE.Type result_type,result_type_1;
DAE.Type result_type,result_type_1,ty;
list<Env.Frame> env;
list<Absyn.Exp> matrices;
list<DAE.Type> tys,tys2;
Boolean impl;
DAE.Properties tp;
list<Ident> lst;
Expand All @@ -5389,11 +5390,14 @@ algorithm
(cache,dim_exp,DAE.PROP((DAE.T_INTEGER(_),_),const1),_) = elabExp(cache,env, dim_aexp, impl,NONE(),true,pre,info);
(cache,Values.INTEGER(dim),_) = Ceval.ceval(cache,env, dim_exp, false,NONE(), Ceval.MSG(info));
(cache,matrices_1,props,_) = elabExpList(cache,env, matrices, impl,NONE(),true,pre,info);
true = sameDimensionsExceptionDimX(props,dim);
tys = Util.listMap(props,Types.getPropType);
ty::tys2 = Util.listMap1(tys,Types.makeNthDimUnknown,dim);
result_type = Util.listFold1(tys2,Types.arraySuperType,info,ty);
matrices_1 = Types.matchTypes(matrices_1,tys,result_type,false);
// true = sameDimensionsExceptionDimX(props,dim);
const2 = elabArrayConst(props);
const = Types.constAnd(const1, const2);
num_matrices = listLength(matrices_1);
(DAE.PROP(type_ = result_type) :: _) = props;
result_type_1 = elabBuiltinCat2(result_type, dim, num_matrices);
etp = Types.elabType(result_type_1);
exp = Expression.makeBuiltinCall("cat", dim_exp :: matrices_1, etp);
Expand Down
68 changes: 67 additions & 1 deletion Compiler/FrontEnd/Types.mo
Expand Up @@ -5582,7 +5582,7 @@ algorithm
exps = matchTypes(exps,tys,expected,printFailtrace);
then
e::exps;
case (e::_,ty::_,expected,_)
case (e::_,ty::_,expected,true)
equation
print("- Types.matchTypes failed for " +& ExpressionDump.printExpStr(e) +& " from " +& unparseType(ty) +& " to " +& unparseType(expected) +& "\n");
then fail();
Expand Down Expand Up @@ -6935,4 +6935,70 @@ algorithm
end matchcontinue;
end varsToValues;

public function makeNthDimUnknown
"Real [3,2,1],3 => Real [3,2,:]"
input Type ty;
input Integer dim;
output Type oty;
algorithm
oty := match (ty,dim)
local
DAE.Dimension ad;
Type ty1;
Option<Absyn.Path> op;
case ((DAE.T_ARRAY(_,ty1),op),1) then ((DAE.T_ARRAY(DAE.DIM_UNKNOWN(),ty1),op));
case ((DAE.T_ARRAY(ad,ty1),op),dim)
equation
ty1 = makeNthDimUnknown(ty1,dim-1);
then ((DAE.T_ARRAY(ad,ty1),op));
end match;
end makeNthDimUnknown;

public function arraySuperType
"Selects the supertype out of two array-types. Integer may be promoted to Real."
input Type ty1;
input Absyn.Info info;
input Type ty2;
output Type ty;
algorithm
ty := matchcontinue (ty1,info,ty2)
local
String str1,str2;
case (ty1,_,ty2)
equation
true = isInteger(arrayElementType(ty1));
true = isReal(arrayElementType(ty2));
((ty1,_)) = traverseType((ty1,-1),replaceIntegerTypeWithReal);
true = subtype(ty1,ty2);
then ty1;
case (ty1,_,ty2)
equation
true = isInteger(arrayElementType(ty2));
true = isReal(arrayElementType(ty1));
((ty2,_)) = traverseType((ty2,-1),replaceIntegerTypeWithReal);
true = subtype(ty1,ty2);
then ty1;
case (ty1,_,ty2)
equation
true = subtype(ty1,ty2);
then ty1;
case (ty1,info,ty2)
equation
str1 = unparseType(ty1);
str2 = unparseType(ty2);
Error.addSourceMessage(Error.ARRAY_TYPE_MISMATCH,{str1,str2},info);
then fail();
end matchcontinue;
end arraySuperType;

protected function replaceIntegerTypeWithReal
input tuple<Type,Integer> tpl;
output tuple<Type,Integer> oty;
algorithm
oty := match tpl
case (((DAE.T_INTEGER(_),_),_)) then ((DAE.T_REAL_DEFAULT,1));
else tpl;
end match;
end replaceIntegerTypeWithReal;

end Types;
2 changes: 2 additions & 0 deletions Compiler/Util/Error.mo
Expand Up @@ -301,6 +301,7 @@ public constant ErrorID FUNCTION_MULTIPLE_ALGORITHM=189;
public constant ErrorID STATEMENT_GENERIC_FAILURE=190;
public constant ErrorID EXTERNAL_NOT_SINGLE_RESULT=191;
public constant ErrorID FUNCTION_UNUSED_INPUT=192;
public constant ErrorID ARRAY_TYPE_MISMATCH=193;

public constant ErrorID UNBOUND_PARAMETER_WITH_START_VALUE_WARNING=499;
public constant ErrorID UNBOUND_PARAMETER_WARNING=500;
Expand Down Expand Up @@ -798,6 +799,7 @@ protected constant list<tuple<Integer, MessageType, Severity, String>> errorTabl
(EXTERNAL_FUNCTION_RESULT_ARRAY_TYPE,TRANSLATION(),ERROR(),"The lhs (result) of the external function declaration has array type (%s), but this is not allowed in the specification. You need to pass it as an input to the function (preferably also with a size()-expression to avoid out-of-bounds errors in the external call)."),
(LINEAR_SYSTEM_INVALID,SYMBOLIC(),ERROR(),"Linear solver (%s) returned invalid input for linear system %s."),
(LINEAR_SYSTEM_SINGULAR,SYMBOLIC(),ERROR(),"When solving linear system %1\n U(%2,%2) = 0.0, which means system is singular for variable %3."),
(ARRAY_TYPE_MISMATCH,TRANSLATION(),ERROR(),"Array types mismatch: %s and %s."),
(FUNCTION_UNUSED_INPUT,SYMBOLIC(),WARNING(),"Unused input variable %s in function %s."),
(FUNCTION_MULTIPLE_ALGORITHM,TRANSLATION(),WARNING(),
"The behaviour of multiple algorithm sections in function %s is not standard Modelica. OpenModelica will execute the sections in the order in which they were declared or inherited (same ordering as inherited input/output arguments, which also are not standardized)."),
Expand Down
1 change: 0 additions & 1 deletion Compiler/Util/Util.mo
Expand Up @@ -5477,7 +5477,6 @@ algorithm
end matchcontinue;
end listReduce_tail;


public function arrayReplaceAtWithFill "
Takes
- an element,
Expand Down

0 comments on commit b0db4ba

Please sign in to comment.