Skip to content

Commit

Permalink
- Merged Flow and Stream in SCode and DAE into ConnectorType.
Browse files Browse the repository at this point in the history
git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@12432 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
perost committed Aug 6, 2012
1 parent fe7aeda commit f6276e9
Show file tree
Hide file tree
Showing 48 changed files with 918 additions and 1,222 deletions.
3 changes: 1 addition & 2 deletions Compiler/BackEnd/BackendDAE.mo
Expand Up @@ -105,8 +105,7 @@ uniontype Var "- Variables"
.DAE.ElementSource source "origin of variable" ;
Option< .DAE.VariableAttributes> values "values ; values on builtin attributes" ;
Option<SCode.Comment> comment "comment ; this contains the comment and annotation from Absyn" ;
.DAE.Flow flowPrefix "flow ; if the variable is a flow" ;
.DAE.Stream streamPrefix "stream ; if the variable is a stream variable. Modelica 3.1 specs" ;
.DAE.ConnectorType connectorType "flow, stream, unspecified or not connector.";
end VAR;
end Var;

Expand Down
82 changes: 37 additions & 45 deletions Compiler/BackEnd/BackendDAECreate.mo
Expand Up @@ -539,8 +539,7 @@ algorithm
DAE.VarDirection dir;
DAE.VarParallelism prl;
BackendDAE.Type tp;
DAE.Flow flowPrefix;
DAE.Stream streamPrefix;
DAE.ConnectorType ct;
DAE.ElementSource source "origin of equation";
Option<DAE.VariableAttributes> dae_var_attr;
Option<SCode.Comment> comment;
Expand All @@ -556,21 +555,20 @@ algorithm
protection = protection,
ty = t,
dims = dims,
flowPrefix = flowPrefix,
streamPrefix = streamPrefix,
connectorType = ct,
source = source,
variableAttributesOption = dae_var_attr,
absynCommentOption = comment),_)
equation
(kind_1,states) = lowerVarkind(kind, t, name, dir, flowPrefix, streamPrefix, istates, dae_var_attr);
(kind_1,states) = lowerVarkind(kind, t, name, dir, ct, istates, dae_var_attr);
tp = lowerType(t);
b = DAEUtil.boolVarVisibility(protection);
dae_var_attr = DAEUtil.setProtectedAttr(dae_var_attr,b);
dae_var_attr = setMinMaxFromEnumeration(t,dae_var_attr);
_ = BackendVariable.getMinMaxAsserts(dae_var_attr,name,source,kind_1,tp);
_ = BackendVariable.getNominalAssert(dae_var_attr,name,source,kind_1,tp);
then
(BackendDAE.VAR(name,kind_1,dir,prl,tp,NONE(),NONE(),dims,-1,source,dae_var_attr,comment,flowPrefix,streamPrefix), states);
(BackendDAE.VAR(name,kind_1,dir,prl,tp,NONE(),NONE(),dims,-1,source,dae_var_attr,comment,ct), states);
end match;
end lowerDynamicVar;

Expand All @@ -590,8 +588,7 @@ algorithm
DAE.VarDirection dir;
DAE.VarParallelism prl;
BackendDAE.Type tp;
DAE.Flow flowPrefix;
DAE.Stream streamPrefix;
DAE.ConnectorType ct;
DAE.ElementSource source "origin of equation";
Option<DAE.VariableAttributes> dae_var_attr;
Option<SCode.Comment> comment;
Expand All @@ -608,13 +605,12 @@ algorithm
ty = t,
binding = bind,
dims = dims,
flowPrefix = flowPrefix,
streamPrefix = streamPrefix,
connectorType = ct,
source = source,
variableAttributesOption = dae_var_attr,
absynCommentOption = comment))
equation
kind_1 = lowerKnownVarkind(kind, name, dir, flowPrefix);
kind_1 = lowerKnownVarkind(kind, name, dir, ct);
bind = fixParameterStartBinding(bind,dae_var_attr,kind_1);
tp = lowerType(t);
b = DAEUtil.boolVarVisibility(protection);
Expand All @@ -623,7 +619,7 @@ algorithm
_ = BackendVariable.getMinMaxAsserts(dae_var_attr,name,source,kind_1,tp);
_ = BackendVariable.getNominalAssert(dae_var_attr,name,source,kind_1,tp);
then
BackendDAE.VAR(name,kind_1,dir,prl,tp,bind,NONE(),dims,-1,source,dae_var_attr,comment,flowPrefix,streamPrefix);
BackendDAE.VAR(name,kind_1,dir,prl,tp,bind,NONE(),dims,-1,source,dae_var_attr,comment,ct);

case (_)
equation
Expand Down Expand Up @@ -717,8 +713,7 @@ protected function lowerVarkind
Type,
DAE.ComponentRef,
DAE.VarDirection, /* input/output/bidir */
DAE.Flow,
DAE.Stream,
DAE.ConnectorType,
BackendDAE.BinTree /* states */)
outputs VarKind
NOTE: Fails for not states that are not algebraic
Expand All @@ -727,78 +722,77 @@ protected function lowerVarkind
input DAE.Type inType;
input DAE.ComponentRef inComponentRef;
input DAE.VarDirection inVarDirection;
input DAE.Flow inFlow;
input DAE.Stream inStream;
input DAE.ConnectorType inConnectorType;
input BackendDAE.BinTree inStates;
input Option<DAE.VariableAttributes> daeAttr;
output BackendDAE.VarKind outVarKind;
output BackendDAE.BinTree outBinTree;
algorithm
(outVarKind,outBinTree) := matchcontinue (inVarKind,inType,inComponentRef,inVarDirection,inFlow,inStream,inStates,daeAttr)
(outVarKind,outBinTree) := matchcontinue (inVarKind,inType,inComponentRef,inVarDirection,inConnectorType,inStates,daeAttr)
local
BackendDAE.BinTree states;
// States appear differentiated among equations
case (DAE.VARIABLE(),_,_,_,_,_,_,_)
case (DAE.VARIABLE(),_,_,_,_,_,_)
equation
_ = BackendDAEUtil.treeGet(inStates, inComponentRef);
then
(BackendDAE.STATE(),inStates);
// Or states have StateSelect.always
case (DAE.VARIABLE(),_,_,_,_,_,_,SOME(DAE.VAR_ATTR_REAL(stateSelectOption = SOME(DAE.ALWAYS()))))
case (DAE.VARIABLE(),_,_,_,_,_,SOME(DAE.VAR_ATTR_REAL(stateSelectOption = SOME(DAE.ALWAYS()))))
equation
states = BackendDAEUtil.treeAdd(inStates, inComponentRef, 0);
then (BackendDAE.STATE(),states);
// Or states have StateSelect.prefer
case (DAE.VARIABLE(),_,_,_,_,_,_,SOME(DAE.VAR_ATTR_REAL(stateSelectOption = SOME(DAE.PREFER()))))
case (DAE.VARIABLE(),_,_,_,_,_,SOME(DAE.VAR_ATTR_REAL(stateSelectOption = SOME(DAE.PREFER()))))
equation
states = BackendDAEUtil.treeAdd(inStates, inComponentRef, 0);
then (BackendDAE.STATE(),states);

case (DAE.VARIABLE(),DAE.T_BOOL(varLst = _),_,_,_,_,_,_)
case (DAE.VARIABLE(),DAE.T_BOOL(varLst = _),_,_,_,_,_)
equation
failure(BackendVariable.topLevelInput(inComponentRef, inVarDirection, inFlow));
failure(BackendVariable.topLevelInput(inComponentRef, inVarDirection, inConnectorType));
then
(BackendDAE.DISCRETE(),inStates);

case (DAE.DISCRETE(),DAE.T_BOOL(varLst = _),_,_,_,_,_,_)
case (DAE.DISCRETE(),DAE.T_BOOL(varLst = _),_,_,_,_,_)
equation
failure(BackendVariable.topLevelInput(inComponentRef, inVarDirection, inFlow));
failure(BackendVariable.topLevelInput(inComponentRef, inVarDirection, inConnectorType));
then
(BackendDAE.DISCRETE(),inStates);

case (DAE.VARIABLE(),DAE.T_INTEGER(varLst = _),_,_,_,_,_,_)
case (DAE.VARIABLE(),DAE.T_INTEGER(varLst = _),_,_,_,_,_)
equation
failure(BackendVariable.topLevelInput(inComponentRef, inVarDirection, inFlow));
failure(BackendVariable.topLevelInput(inComponentRef, inVarDirection, inConnectorType));
then
(BackendDAE.DISCRETE(),inStates);

case (DAE.DISCRETE(),DAE.T_INTEGER(varLst = _),_,_,_,_,_,_)
case (DAE.DISCRETE(),DAE.T_INTEGER(varLst = _),_,_,_,_,_)
equation
failure(BackendVariable.topLevelInput(inComponentRef, inVarDirection, inFlow));
failure(BackendVariable.topLevelInput(inComponentRef, inVarDirection, inConnectorType));
then
(BackendDAE.DISCRETE(),inStates);

case (DAE.VARIABLE(),DAE.T_ENUMERATION(names = _),_,_,_,_,_,_)
case (DAE.VARIABLE(),DAE.T_ENUMERATION(names = _),_,_,_,_,_)
equation
failure(BackendVariable.topLevelInput(inComponentRef, inVarDirection, inFlow));
failure(BackendVariable.topLevelInput(inComponentRef, inVarDirection, inConnectorType));
then
(BackendDAE.DISCRETE(),inStates);

case (DAE.DISCRETE(),DAE.T_ENUMERATION(names = _),_,_,_,_,_,_)
case (DAE.DISCRETE(),DAE.T_ENUMERATION(names = _),_,_,_,_,_)
equation
failure(BackendVariable.topLevelInput(inComponentRef, inVarDirection, inFlow));
failure(BackendVariable.topLevelInput(inComponentRef, inVarDirection, inConnectorType));
then
(BackendDAE.DISCRETE(),inStates);

case (DAE.VARIABLE(),_,_,_,_,_,_,_)
case (DAE.VARIABLE(),_,_,_,_,_,_)
equation
failure(BackendVariable.topLevelInput(inComponentRef, inVarDirection, inFlow));
failure(BackendVariable.topLevelInput(inComponentRef, inVarDirection, inConnectorType));
then
(BackendDAE.VARIABLE(),inStates);

case (DAE.DISCRETE(),_,_,_,_,_,_,_)
case (DAE.DISCRETE(),_,_,_,_,_,_)
equation
failure(BackendVariable.topLevelInput(inComponentRef, inVarDirection, inFlow));
failure(BackendVariable.topLevelInput(inComponentRef, inVarDirection, inConnectorType));
then
(BackendDAE.DISCRETE(),inStates);
end matchcontinue;
Expand All @@ -811,16 +805,16 @@ protected function lowerKnownVarkind
input DAE.VarKind inVarKind;
input DAE.ComponentRef inComponentRef;
input DAE.VarDirection inVarDirection;
input DAE.Flow inFlow;
input DAE.ConnectorType inConnectorType;
output BackendDAE.VarKind outVarKind;
algorithm
outVarKind := matchcontinue (inVarKind,inComponentRef,inVarDirection,inFlow)
outVarKind := matchcontinue (inVarKind,inComponentRef,inVarDirection,inConnectorType)

case (DAE.PARAM(),_,_,_) then BackendDAE.PARAM();
case (DAE.CONST(),_,_,_) then BackendDAE.CONST();
case (DAE.VARIABLE(),_,_,_)
equation
BackendVariable.topLevelInput(inComponentRef,inVarDirection,inFlow);
BackendVariable.topLevelInput(inComponentRef,inVarDirection,inConnectorType);
then
BackendDAE.VARIABLE();
// adrpo: topLevelInput might fail!
Expand Down Expand Up @@ -870,8 +864,7 @@ algorithm
DAE.VarDirection dir;
DAE.VarParallelism prl;
BackendDAE.Type tp;
DAE.Flow flowPrefix;
DAE.Stream streamPrefix;
DAE.ConnectorType ct;
DAE.ElementSource source;
Option<DAE.VariableAttributes> dae_var_attr;
Option<SCode.Comment> comment;
Expand All @@ -884,16 +877,15 @@ algorithm
ty = t,
binding = bind,
dims = dims,
flowPrefix = flowPrefix,
streamPrefix = streamPrefix,
connectorType = ct,
source = source,
variableAttributesOption = dae_var_attr,
absynCommentOption = comment))
equation
kind_1 = lowerExtObjVarkind(t);
tp = lowerType(t);
then
BackendDAE.VAR(name,kind_1,dir,prl,tp,bind,NONE(),dims,-1,source,dae_var_attr,comment,flowPrefix,streamPrefix);
BackendDAE.VAR(name,kind_1,dir,prl,tp,bind,NONE(),dims,-1,source,dae_var_attr,comment,ct);
end match;
end lowerExtObjVar;

Expand Down Expand Up @@ -1748,7 +1740,7 @@ algorithm
vars_1 = BackendVariable.addVar(BackendDAE.VAR(cref_, BackendDAE.STATE(),DAE.BIDIR(),DAE.NON_PARALLEL(),DAE.T_REAL_DEFAULT,NONE(),NONE(),{},-1,
DAE.emptyElementSource,
SOME(DAE.VAR_ATTR_REAL(NONE(),NONE(),NONE(),(NONE(),NONE()),NONE(),SOME(DAE.BCONST(true)),NONE(),NONE(),NONE(),NONE(),NONE(),NONE(),NONE())),
NONE(),DAE.NON_CONNECTOR(),DAE.NON_STREAM()), vars);
NONE(),DAE.NON_CONNECTOR()), vars);
exp = Expression.crefExp(cref_);
then
/*
Expand Down

0 comments on commit f6276e9

Please sign in to comment.