Skip to content

Commit

Permalink
-Fixed some bugs with wrong type in component references
Browse files Browse the repository at this point in the history
git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@5149 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
Peter Aronsson committed Mar 15, 2010
1 parent 58b2938 commit 4a45461
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 5 deletions.
8 changes: 4 additions & 4 deletions Compiler/Exp.mo
Expand Up @@ -254,7 +254,7 @@ algorithm
case (Absyn.FULLYQUALIFIED(p)) then pathToCref(p);
case Absyn.QUALIFIED(name = i,path = p)
equation
c = pathToCref(p);
c = pathToCref(p);
then
DAE.CREF_QUAL(i,DAE.ET_OTHER(),{},c);
end matchcontinue;
Expand Down Expand Up @@ -8022,7 +8022,7 @@ algorithm
String name,id;
list<Subscript> ssl;
equation
true = containWholeDim(cr);
false = crefHasScalarSubscripts(cr);
name = printComponentRefStr(cr);
false = Util.stringContainsChar(name,"$");
id = Util.stringAppendList({"$",id});
Expand Down Expand Up @@ -11119,14 +11119,14 @@ end crefSetLastType;
public function crefTypeConsiderSubs "Function: crefTypeConsiderSubs
Author: PA
Function for extracting the type out of a componentReference and consider the influence of the last subscript list.
For exampele. If the last cref type is Real[3,3] and the subscript list is {Exp.INDEX(1)}, the type becomes Real[3], i.e
For exampel. If the last cref type is Real[3,3] and the last subscript list is {Exp.INDEX(1)}, the type becomes Real[3], i.e
one dimension is lifted.
See also, crefType.
"
input ComponentRef cr;
output Type res;
algorithm
res := unliftArrayTypeWithSubs(crefLastSubs(cr),crefType(cr));
res := unliftArrayTypeWithSubs(crefLastSubs(cr),crefLastType(cr));
end crefTypeConsiderSubs;

public function crefType "Function: crefType
Expand Down
4 changes: 3 additions & 1 deletion Compiler/Inst.mo
Expand Up @@ -12271,8 +12271,10 @@ algorithm
then fail();

case(Values.RECORD(p, (v as Values.ARRAY(valueLst = arrVals))::vals, n::names, index),cr,source)
local DAE.ExpType tp;
equation
cr2 = Exp.crefAppend(cr,DAE.CREF_IDENT(n,DAE.ET_OTHER,{}));
tp = ValuesUtil.valueExpType(v);
cr2 = Exp.crefAppend(cr,DAE.CREF_IDENT(n,tp,{}));
eqns = assignComplexConstantConstruct(Values.RECORD(p,vals,names,index),cr,source);
eqnsArray = assignComplexConstantConstructToArray(arrVals,cr2,source,1);
eqns = listAppend(eqns,eqnsArray);
Expand Down
42 changes: 42 additions & 0 deletions Compiler/ValuesUtil.mo
Expand Up @@ -54,6 +54,7 @@ protected import Print;
protected import System;
protected import Util;
protected import RTOpts;
protected import ClassInf;

public function typeConvert "function: typeConvert
Apply type conversion on a list of Values"
Expand Down Expand Up @@ -91,6 +92,47 @@ algorithm
end matchcontinue;
end typeConvert;

public function valueExpType "creates a DAE.ExpType from a Value"
input Value inValue;
output DAE.ExpType tp;
algorithm
tp := matchcontinue(inValue)
local Absyn.Path path; Integer indx; list<String> nameLst; DAE.ExpType eltTp;
list<Option<Integer>> dimsOpt;
list<Values.Value> valLst;
list<DAE.ExpType> eltTps;
list<DAE.ExpVar> varLst;
list<Integer> dims;

case(Values.INTEGER(_)) then DAE.ET_INT();
case(Values.REAL(_)) then DAE.ET_REAL();
case(Values.BOOL(_)) then DAE.ET_BOOL();
case(Values.STRING(_)) then DAE.ET_STRING();
case(Values.ENUM(indx,path,nameLst)) then DAE.ET_ENUMERATION(SOME(indx),path,nameLst,{});
case(Values.ARRAY(valLst,dims)) equation
eltTp=valueExpType(Util.listFirst(valLst));
dimsOpt = Util.listMap(dims,Util.makeOption);
then DAE.ET_ARRAY(eltTp,dimsOpt);

case(Values.RECORD(path,valLst,nameLst,indx)) equation
eltTps = Util.listMap(valLst,valueExpType);
varLst = Util.listThreadMap(eltTps,nameLst,valueExpTypeExpVar);
then DAE.ET_COMPLEX(path,varLst,ClassInf.RECORD(path));

case(inValue) equation
print("valueExpType on "+&valString(inValue) +& " not implemented yet\n");
then fail();
end matchcontinue;
end valueExpType;

protected function valueExpTypeExpVar "help function to valueExpType"
input DAE.ExpType etp;
input String name;
output DAE.ExpVar expVar;
algorithm
expVar := DAE.COMPLEX_VAR(name,etp);
end valueExpTypeExpVar;

public function isZero "Returns true if value is zero"
input Value inValue;
output Boolean isZero;
Expand Down

0 comments on commit 4a45461

Please sign in to comment.