Skip to content

Commit

Permalink
Fixes for bug #1272:
Browse files Browse the repository at this point in the history
- Fixed several checkModel issues with parameters without bindings.
- Removed dummy dimensions phase from CevalScript that was introduced in r6142.
- Disabled "unbound parameter"-warning when doing checkModel, because we can't
  know whether a parameter would have been given a binding when instantiated or
  not.
- Cleaned up the handling of dimensions a bit:
  - Renamed DAE.DIM_NONE to DAE.DIM_UNKNOWN and DAE.DIM_SUBSCRIPT to DAE.DIM_EXP, 
    to better tell what they represent.
  - Use DAE.DIM_UNKNOWN instead of previously used
    DAE.DIM_SUBSCRIPT(DAE.WHOLEDIM) (a subscript is not a dimensions).
- Updated tests Modelica.Math and Modelica.Blocks in libraries/msl31, and
  enabled Modelica.Blocks.Continuous.StateSpace in Modelica.Blocks.


git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@6157 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
perost committed Sep 21, 2010
1 parent 7708223 commit 141c705
Show file tree
Hide file tree
Showing 16 changed files with 370 additions and 499 deletions.
2 changes: 1 addition & 1 deletion Compiler/Builtin.mo
Expand Up @@ -58,7 +58,7 @@ protected import Values;
// Predefined DAE.Types
// Real arrays
protected constant DAE.Type T_REAL_ARRAY_DEFAULT =
(DAE.T_ARRAY(DAE.DIM_NONE, DAE.T_REAL_DEFAULT), NONE);
(DAE.T_ARRAY(DAE.DIM_UNKNOWN, DAE.T_REAL_DEFAULT), NONE);
protected constant DAE.Type T_REAL_ARRAY_1_DEFAULT =
(DAE.T_ARRAY(DAE.DIM_INTEGER(1), DAE.T_REAL_DEFAULT), NONE);
protected constant DAE.Type T_REAL_ARRAY_2_DEFAULT =
Expand Down
9 changes: 2 additions & 7 deletions Compiler/Ceval.mo
Expand Up @@ -1779,7 +1779,7 @@ algorithm
equation
(cache,attr,tp,bind,_,_,_,_,_) = Lookup.lookupVar(cache,env, cr) "If dimensions known, always ceval" ;
true = Types.dimensionsKnown(tp);
sizelst = Types.getDimensionSizes(tp);
(sizelst as (_ :: _)) = Types.getDimensionSizes(tp);
(cache,Values.INTEGER(dim),st_1) = ceval(cache, env, dim, impl, st, NONE, msg);
dim_1 = dim - 1;
v = listNth(sizelst, dim_1);
Expand Down Expand Up @@ -4756,12 +4756,7 @@ algorithm
list<DAE.Exp> exps;
Env.Cache cache;
case (cache,env,{},_,_,msg) then (cache,{});
case (cache,env,{exp},impl,st,msg)
equation
(cache,v,_) = ceval(cache,env, exp, impl, st, NONE, msg);
then
(cache,{v});
case (cache,env,(exp :: exps),impl,st,msg)
case (cache,env,(exp :: exps ),impl,st,msg)
equation
(cache,v,_) = ceval(cache,env, exp, impl, st, NONE, msg);
(cache,vs) = cevalList(cache,env, exps, impl, st, msg);
Expand Down
246 changes: 0 additions & 246 deletions Compiler/CevalScript.mo
Expand Up @@ -3408,8 +3408,6 @@ algorithm
//UnitParserExt.commit();

// instantiate the partial class nomally as it works during checkModel.
p_1 = insertDummyDimensions(p_1, className);

(cache, env, _, dae) = Inst.instantiateClass(inCache, InnerOuter.emptyInstHierarchy, p_1, className);
dae = DAEUtil.transformationsBeforeBackend(dae);
// adrpo: do not store instantiated class as we don't use it later!
Expand Down Expand Up @@ -3449,8 +3447,6 @@ algorithm
//UnitAbsynBuilder.registerUnits(ptot);
//UnitParserExt.commit();

p_1 = insertDummyDimensions(p_1, className);

(cache, env, _, dae) =
Inst.instantiateClass(inCache, InnerOuter.emptyInstHierarchy, p_1, className);
dae = DAEUtil.transformationsBeforeBackend(dae);
Expand Down Expand Up @@ -3489,8 +3485,6 @@ algorithm
//UnitAbsynBuilder.registerUnits(ptot);
//UnitParserExt.commit();

p_1 = insertDummyDimensions(p_1, className);

(cache, env, _, dae) =
Inst.instantiateFunctionImplicit(inCache, InnerOuter.emptyInstHierarchy, p_1, className);

Expand All @@ -3517,246 +3511,6 @@ algorithm
end matchcontinue;
end checkModel;

protected function insertDummyDimensions
"When checkModel is used to check a model there might be arrays whose
dimensions would normally be determined by modifications. To be able to check
a model we therefore insert dummy dimensions into the model, so that we can
instantiate it. This function goes through the list of classes and tries to
find the class that we want to check, and inserts dummy dimensions into it."
input list<SCode.Class> inClasses;
input Absyn.Path className;
output list<SCode.Class> outClasses;
algorithm
outClasses := matchcontinue(inClasses, className)
local
SCode.Class c;
list<SCode.Class> cl;
String cl_name;
Absyn.Path p;
// Class found, insert dummy dimensions.
case (c :: cl, Absyn.IDENT(cl_name))
equation
true = stringEqual(SCode.className(c), cl_name);
c = insertDummyDimensionsInClassDef(c);
then
c :: cl;
// Package found, continue searching in the package.
case (c :: cl, Absyn.QUALIFIED(name = cl_name, path = p))
equation
true = stringEqual(SCode.className(c), cl_name);
c = insertDummyDimensionsInPackage(c, p);
then
c :: cl;
// No match, check the rest of the classes.
case (c :: cl, _)
equation
cl = insertDummyDimensions(cl, className);
then
c :: cl;
end matchcontinue;
end insertDummyDimensions;

protected function insertDummyDimensionsInPackage
"Helper function to insertDummyDimensions. Extracts the parts of a package and
searches them with insertDummyDimensionsInPackage2."
input SCode.Class inPackage;
input Absyn.Path packageName;
output SCode.Class outPackage;
algorithm
outPackage := matchcontinue(inPackage, packageName)
local
SCode.Ident n;
Boolean pp;
Boolean ep;
SCode.Restriction r;
Absyn.Info i;
list<SCode.Element> el;
list<SCode.Equation> nel, iel;
list<SCode.AlgorithmSection> nal, ial;
Option<Absyn.ExternalDecl> ed;
list<SCode.Annotation> al;
Option<SCode.Comment> c;
case (SCode.CLASS(
name = n,
partialPrefix = pp,
encapsulatedPrefix = ep,
restriction = r,
classDef = SCode.PARTS(
elementLst = el,
normalEquationLst = nel,
initialEquationLst = iel,
normalAlgorithmLst = nal,
initialAlgorithmLst = ial,
externalDecl = ed,
annotationLst = al,
comment = c),
info = i), _)
equation
el = insertDummyDimensionsInPackage2(el, packageName);
then
SCode.CLASS(n, pp, ep, r, SCode.PARTS(el, nel, iel, nal, ial, ed, al, c), i);
case (_, _) then inPackage;
end matchcontinue;
end insertDummyDimensionsInPackage;

protected function insertDummyDimensionsInPackage2
"Helper function to insertDummyDimensionsInPackage. Searches class definitions
in a package for the class we want to check."
input list<SCode.Element> inClasses;
input Absyn.Path className;
output list<SCode.Element> outClasses;
algorithm
outClasses := matchcontinue(inClasses, className)
local
SCode.Element c;
list<SCode.Element> cl;
SCode.Ident n;
String cl_name;
Absyn.Path p;
Boolean fp, rp;
SCode.Class cd;
Option<Absyn.ConstrainClass> cc;
// Package found, continue searching in package.
case (SCode.CLASSDEF(name = n, finalPrefix = fp, replaceablePrefix = rp,
classDef = cd, cc = cc) :: cl, Absyn.QUALIFIED(name = cl_name, path = p))
equation
true = stringEqual(n, cl_name);
cd = insertDummyDimensionsInPackage(cd, p);
then
SCode.CLASSDEF(n, fp, rp, cd, cc) :: cl;
// Class found, insert dummy dimensions.
case (SCode.CLASSDEF(name = n, finalPrefix = fp, replaceablePrefix = rp,
classDef = cd, cc = cc) :: cl, Absyn.IDENT(name = cl_name))
equation
true = stringEqual(n, cl_name);
cd = insertDummyDimensionsInClassDef(cd);
then
SCode.CLASSDEF(n, fp, rp, cd, cc) :: cl;
// No match, continue searching the rest of the class definitions.
case (c :: cl, _)
equation
cl = insertDummyDimensionsInPackage2(cl, className);
then
c :: cl;
end matchcontinue;
end insertDummyDimensionsInPackage2;

protected function insertDummyDimensionsInClassDef
"Helper function to insertDummyDimensions. Inserts dummy dimensions into a
class definition."
input SCode.Class inClass;
output SCode.Class outClass;
algorithm
outClass := matchcontinue(inClass)
local
SCode.Ident n;
Boolean pp;
Boolean ep;
SCode.Restriction r;
SCode.ClassDef cd;
Absyn.Info i;
case SCode.CLASS(name = n, partialPrefix = pp, encapsulatedPrefix = ep,
restriction = r, classDef = cd, info = i)
equation
cd = insertDummyDimensionsInElements(cd);
then
SCode.CLASS(n, pp, ep, r, cd, i);
end matchcontinue;
end insertDummyDimensionsInClassDef;

protected function insertDummyDimensionsInElements
"Helper function to insertDummyDimensionsInClassDef. Inserts dummy dimensions
into a class' components."
input SCode.ClassDef inClassDef;
output SCode.ClassDef outClassDef;
algorithm
outClassDef := matchcontinue(inClassDef)
case SCode.PARTS(
elementLst = el,
normalEquationLst = nel,
initialEquationLst = iel,
normalAlgorithmLst = nal,
initialAlgorithmLst = ial,
externalDecl = ed,
annotationLst = al,
comment = c)
local
list<SCode.Element> el;
list<SCode.Equation> nel, iel;
list<SCode.AlgorithmSection> nal, ial;
Option<Absyn.ExternalDecl> ed;
list<SCode.Annotation> al;
Option<SCode.Comment> c;
equation
el = Util.listMap(el, insertDummyDimensionsInComponent);
then
SCode.PARTS(el, nel, iel, nal, ial, ed, al, c);
case _ then inClassDef;
end matchcontinue;
end insertDummyDimensionsInElements;

protected function insertDummyDimensionsInComponent
"Helper function to insertDummyDimensionsInElements. Checks if an element is a
component that is public and without modifications."
input SCode.Element inElement;
output SCode.Element outElement;
algorithm
outElement := matchcontinue(inElement)
case SCode.COMPONENT(
component = n,
innerOuter = io,
finalPrefix = fp,
replaceablePrefix = rp,
protectedPrefix = pp as false,
attributes = a as SCode.ATTR(
arrayDims = ad,
flowPrefix = flp,
streamPrefix = sp,
accesibility = ac,
variability = v,
direction = d),
modifications = m as SCode.NOMOD,
typeSpec = ts,
comment = cmt,
condition = c,
info = i,
cc = cc)
local
SCode.Ident n;
Absyn.InnerOuter io;
Boolean fp, rp, pp, flp, sp;
SCode.Attributes a;
Absyn.ArrayDim ad;
SCode.Accessibility ac;
SCode.Variability v;
Absyn.Direction d;
Absyn.TypeSpec ts;
SCode.Mod m;
Option<SCode.Comment> cmt;
Option<Absyn.Exp> c;
Option<Absyn.Info> i;
Option<Absyn.ConstrainClass> cc;
equation
ad = Util.listMap(ad, replaceWholedimWithDummy);
then
SCode.COMPONENT(n, io, fp, rp, pp,
SCode.ATTR(ad, flp, sp, ac, v, d), ts, m, cmt, c, i, cc);
case _ then inElement;
end matchcontinue;
end insertDummyDimensionsInComponent;

protected function replaceWholedimWithDummy
"Helper function to insertDummyDimensionsInComponent. Checks if a subscript
contains an Absyn.NOSUB, and replaces it with a dummy dimension."
input Absyn.Subscript inSub;
output Absyn.Subscript outSub;
algorithm
outSub := matchcontinue(inSub)
case Absyn.NOSUB then Absyn.SUBSCRIPT(Absyn.INTEGER(3)); // chosen by fair dice roll
case _ then inSub;
end matchcontinue;
end replaceWholedimWithDummy;

protected function selectIfNotEmpty
input String inString;
input String selector " ";
Expand Down
10 changes: 5 additions & 5 deletions Compiler/DAE.mo
Expand Up @@ -764,12 +764,12 @@ uniontype Dimension
Integer size "The size of the enumeration.";
end DIM_ENUM;

record DIM_SUBSCRIPT "Dimension given by a subscript."
Subscript subscript;
end DIM_SUBSCRIPT;
record DIM_EXP "Dimension given by an expression."
Exp exp;
end DIM_EXP;

record DIM_NONE "Dimension with unknown size."
end DIM_NONE;
record DIM_UNKNOWN "Dimension with unknown size."
end DIM_UNKNOWN;
end Dimension;

public
Expand Down
7 changes: 4 additions & 3 deletions Compiler/DAELow.mo
Expand Up @@ -16673,9 +16673,10 @@ algorithm
list<DAE.Subscript> subs;
DAE.Dimension d;
case({}) then {};
case(DAE.DIM_NONE::dims) equation
rangelist = dimensionsToRange(dims);
then {}::rangelist;
case(DAE.DIM_UNKNOWN::dims)
equation
rangelist = dimensionsToRange(dims);
then {}::rangelist;
case(d::dims) equation
i = Exp.dimensionSize(d);
range = Util.listIntRange(i);
Expand Down

0 comments on commit 141c705

Please sign in to comment.