Skip to content

Commit

Permalink
- Update types of subcomponents in complex types in Typing.typeElement.
Browse files Browse the repository at this point in the history
git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@12954 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
perost committed Sep 17, 2012
1 parent dfbe18a commit 0d86332
Show file tree
Hide file tree
Showing 3 changed files with 85 additions and 8 deletions.
25 changes: 23 additions & 2 deletions Compiler/FrontEnd/InstUtil.mo
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ algorithm
end match;
end makeClass;

protected function makeDaeVarsFromElement
public function makeDaeVarsFromElement
input Element inElement;
input list<DAE.Var> inAccumVars;
output list<DAE.Var> outVars;
Expand Down Expand Up @@ -415,7 +415,28 @@ algorithm

end match;
end setComponentName;


public function setTypedComponentType
input Component inComponent;
input DAE.Type inType;
output Component outComponent;
algorithm
outComponent := match(inComponent, inType)
local
Absyn.Path name;
DaePrefixes dprefs;
Binding binding;
Absyn.Info info;
Option<Component> p;

case (InstTypes.TYPED_COMPONENT(name, _, p, dprefs, binding, info), _)
then InstTypes.TYPED_COMPONENT(name, inType, p, dprefs, binding, info);

else inComponent;

end match;
end setTypedComponentType;

public function setComponentParamType
input Component inComponent;
input ParamType inParamType;
Expand Down
22 changes: 22 additions & 0 deletions Compiler/FrontEnd/Types.mo
Original file line number Diff line number Diff line change
Expand Up @@ -1847,6 +1847,28 @@ algorithm
end match;
end arrayElementType;

public function setArrayElementType
input Type inType;
input Type inBaseType;
output Type outType;
algorithm
outType := match(inType, inBaseType)
local
DAE.Type ty;
DAE.Dimensions dims;
DAE.TypeSource src;

case (DAE.T_ARRAY(ty, dims, src), _)
equation
ty = setArrayElementType(ty, inBaseType);
then
DAE.T_ARRAY(ty, dims, src);

else inBaseType;

end match;
end setArrayElementType;

public function unparseEqMod
"prints eqmod to a string"
input EqMod eq;
Expand Down
46 changes: 40 additions & 6 deletions Compiler/FrontEnd/Typing.mo
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ public import InstTypes;
public import SCode;

protected import BaseHashTable;
protected import ClassInf;
protected import ComponentReference;
protected import ConnectCheck;
protected import ConnectUtil2;
Expand Down Expand Up @@ -154,12 +155,7 @@ algorithm
comp = InstSymbolTable.lookupName(name, st);
(comp, st) = typeComponent(comp, inParent, inContext, st);
(cls, st) = typeClass2(cls, SOME(comp), inContext, st);
/*-------------------------------------------------------------------*/
// TODO: Complex components should have their types updated with the
// typed class, so that the subcomponents types are correct in the
// complex type. Otherwise the connection checking won't work with
// nested connectors.
/*-------------------------------------------------------------------*/
(comp, st) = updateComplexComponentType(comp, cls, st);
then
(InstTypes.ELEMENT(comp, cls), st);

Expand Down Expand Up @@ -595,6 +591,44 @@ algorithm
end match;
end typeBinding;

protected function updateComplexComponentType
input Component inComponent;
input Class inClass;
input SymbolTable inSymbolTable;
output Component outComponent;
output SymbolTable outSymbolTable;
algorithm
(outComponent, outSymbolTable) :=
match(inComponent, inClass, inSymbolTable)
local
ClassInf.State state;
DAE.EqualityConstraint ec;
DAE.TypeSource ty_src;
list<DAE.Var> vars;
list<Element> elems;
SymbolTable st;
DAE.Type base_ty, ty;
Component comp;

// Complex base type, update the vars in the type.
case (InstTypes.TYPED_COMPONENT(ty = ty),
InstTypes.COMPLEX_CLASS(components = elems), st)
equation
DAE.T_COMPLEX(state, _, ec, ty_src) = Types.arrayElementType(ty);
vars = List.accumulateMap(elems, InstUtil.makeDaeVarsFromElement);
vars = listReverse(vars);
base_ty = DAE.T_COMPLEX(state, vars, ec, ty_src);
ty = Types.setArrayElementType(ty, base_ty);
comp = InstUtil.setTypedComponentType(inComponent, ty);
st = InstSymbolTable.updateComponent(comp, st);
then
(comp, st);

else (inComponent, inSymbolTable);

end match;
end updateComplexComponentType;

protected function typeExpList
input list<DAE.Exp> inExpList;
input EvalPolicy inEvalPolicy;
Expand Down

0 comments on commit 0d86332

Please sign in to comment.