Skip to content

Commit

Permalink
Fix for bug #1523:
Browse files Browse the repository at this point in the history
- {} is no longer allowed in Modelica code, since it's not allowed by the
  specification.
- Added test case mofiles/EmptyArray and updated the test suit.


git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@9014 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
perost committed May 16, 2011
1 parent 61e5592 commit 935d00f
Show file tree
Hide file tree
Showing 4 changed files with 190 additions and 142 deletions.
57 changes: 33 additions & 24 deletions Compiler/FrontEnd/Static.mo
Expand Up @@ -515,14 +515,14 @@ algorithm
then
(cache, e_1, prop, st_1);

// Part of the MetaModelica extension. This eliminates elab_array failed failtraces when using the empty list. sjoelund
case (cache,env,Absyn.ARRAY({}),impl,st,doVect,pre,info,_)
equation
true = RTOpts.acceptMetaModelicaGrammar();
(cache,exp,prop,st) = elabExp(cache,env,Absyn.LIST({}),impl,st,doVect,pre,info);
then (cache,exp,prop,st);
// Part of the MetaModelica extension. This eliminates elab_array failed failtraces when using the empty list. sjoelund
case (cache,env,Absyn.ARRAY({}),impl,st,doVect,pre,info,_)
equation
true = RTOpts.acceptMetaModelicaGrammar();
(cache,exp,prop,st) = elabExp(cache,env,Absyn.LIST({}),impl,st,doVect,pre,info);
then (cache,exp,prop,st);

// array expressions, e.g. {1,2,3}
// array expressions, e.g. {1,2,3}
case (cache,env,Absyn.ARRAY(arrayExp = es),impl,st,doVect,pre,info,_)
equation
(cache,es_1,props,_) = elabExpList(cache, env, es, impl, st, doVect, pre, info);
Expand Down Expand Up @@ -2115,35 +2115,44 @@ protected function elabArray
All types of an array should be equivalent. However, mixed Integer and Real
elements are allowed in an array and in that case the Integer elements
are converted to Real elements."
input list<DAE.Exp> expl;
input list<DAE.Properties> props;
input Prefix.Prefix pre;
input Absyn.Info info;
output list<DAE.Exp> outExpExpLst;
input list<DAE.Exp> inExpl;
input list<DAE.Properties> inProps;
input Prefix.Prefix inPrefix;
input Absyn.Info inInfo;
output list<DAE.Exp> outExpLst;
output DAE.Properties outProperties;
algorithm
(outExpExpLst,outProperties):=
matchcontinue (expl,props,pre,info)
(outExpLst,outProperties):=
matchcontinue (inExpl, inProps, inPrefix, inInfo)
local
list<DAE.Exp> expl_1,expl_2;
list<DAE.Exp> expl;
DAE.Properties prop;
DAE.Type t;
DAE.Const c;
list<DAE.Type> types;

case (expl,props,pre,info) /* impl array contains mixed Integer and Real types */
// Empty array constructors are not allowed in Modelica.
case ({}, _, _, _)
equation
t = elabArrayHasMixedIntReals(props);
c = elabArrayConst(props);
types = Util.listMap(props, Types.getPropType);
expl_1 = elabArrayReal2(expl, types, t);
Error.addSourceMessage(Error.EMPTY_ARRAY, {}, inInfo);
then
(expl_1,DAE.PROP(t,c));
case (expl,props,pre,info)
fail();

// impl array contains mixed Integer and Real types
case (inExpl as _ :: _, _, _, _)
equation
t = elabArrayHasMixedIntReals(inProps);
c = elabArrayConst(inProps);
types = Util.listMap(inProps, Types.getPropType);
expl = elabArrayReal2(inExpl, types, t);
then
(expl, DAE.PROP(t, c));

case (inExpl as _ :: _, _, _, _)
equation
(expl_1,prop) = elabArray2(expl,props,pre,info);
(expl, prop) = elabArray2(inExpl, inProps, inPrefix, inInfo);
then
(expl_1,prop);
(expl, prop);
end matchcontinue;
end elabArray;

Expand Down
3 changes: 3 additions & 0 deletions Compiler/Util/Error.mo
Expand Up @@ -292,6 +292,7 @@ public constant ErrorID INVALID_REDECLARE=178;
public constant ErrorID INVALID_TYPE_PREFIX=179;
public constant ErrorID LINEAR_SYSTEM_INVALID=180;
public constant ErrorID LINEAR_SYSTEM_SINGULAR=181;
public constant ErrorID EMPTY_ARRAY=182;

public constant ErrorID UNBOUND_PARAMETER_WITH_START_VALUE_WARNING=499;
public constant ErrorID UNBOUND_PARAMETER_WARNING=500;
Expand Down Expand Up @@ -764,6 +765,8 @@ protected constant list<tuple<Integer, MessageType, Severity, String>> errorTabl
"Redeclaration of %s is not allowed."),
(INVALID_TYPE_PREFIX,TRANSLATION(),ERROR(),
"Invalid type prefix '%s' on variable %s, due to existing type prefix '%s'."),
(EMPTY_ARRAY,TRANSLATION(),ERROR(),
"Array constructor may not be empty."),
(MATCHCONTINUE_TO_MATCH_OPTIMIZATION,TRANSLATION(),NOTIFICATION(),"This matchcontinue expression has no overlapping patterns and should be using match instead of matchcontinue."),
(META_DEAD_CODE,TRANSLATION(),NOTIFICATION(),"Dead code elimination: %s."),
(META_UNUSED_DECL,TRANSLATION(),NOTIFICATION(),"Unused local variable: %s."),
Expand Down
16 changes: 14 additions & 2 deletions c_runtime/linearize.cpp
Expand Up @@ -94,8 +94,20 @@ int linearize()
}
strD = array2string(matrixD,size_Outputs,size_Inputs);

strX = array2string(globalData->states,1,size_A);
strU = array2string(globalData->inputVars,1,size_Inputs);
// The empty array {} is not valid modelica, so we need to put something
// inside the curly braces for x0 and u0. {for i in in 1:0} will create an
// empty array if needed.
if(size_A) {
strX = array2string(globalData->states,1,size_A);
} else {
strX = "i for i in 1:0";
}

if(size_Inputs) {
strU = array2string(globalData->inputVars,1,size_Inputs);
} else {
strU = "i for i in 1:0";
}

delete [] matrixA;
delete [] matrixB;
Expand Down

0 comments on commit 935d00f

Please sign in to comment.