Skip to content

Commit

Permalink
- Added balance check for connectors extending a basic type.
Browse files Browse the repository at this point in the history
git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@10257 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
perost committed Oct 31, 2011
1 parent 5e34f0d commit fcf2915
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 1 deletion.
43 changes: 43 additions & 0 deletions Compiler/FrontEnd/ConnectUtil.mo
Expand Up @@ -3121,6 +3121,49 @@ algorithm
end matchcontinue;
end sizeOfVariable2;

public function checkShortConnectorDef
"Checks a short connector definition that has extended a basic type, i.e.
connector C = Real;."
input ClassInf.State inState;
input SCode.Attributes inAttributes;
input Absyn.Info inInfo;
output Boolean isValid;
algorithm
isValid := matchcontinue(inState, inAttributes, inInfo)
local
Absyn.Path class_path;
Integer pv, fv, sv;
SCode.Flow f;
SCode.Stream s;
Boolean bf, bs;

// Extended from bidirectional basic type, which means that it can't be
// balanced.
case (ClassInf.CONNECTOR(path = class_path),
SCode.ATTR(flowPrefix = f, streamPrefix = s, direction = Absyn.BIDIR()), _)
equation
// The connector might be either flow, stream or neither.
// This will set either fv, sv, or pv to 1, and the rest to 0, and
// checkConnectorBalance2 will then be called to provide the appropriate
// error message (or might actually succeed if +std=2.x or 1.x).
bf = SCode.flowBool(f);
bs = SCode.streamBool(s);
fv = Util.if_(bf, 1, 0);
sv = Util.if_(bs, 1, 0);
pv = Util.if_(bf or bs, 0, 1);
checkConnectorBalance2(pv, fv, sv, class_path, inInfo);
then
true;

// Previous case failed, not a valid connector.
case (ClassInf.CONNECTOR(path = _),
SCode.ATTR(direction = Absyn.BIDIR()), _) then false;

// All other cases are ok.
else true;
end matchcontinue;
end checkShortConnectorDef;

public function printSetsStr
"Prints a Sets to a String."
input Sets inSets;
Expand Down
7 changes: 6 additions & 1 deletion Compiler/FrontEnd/Inst.mo
Expand Up @@ -3420,7 +3420,7 @@ algorithm
list<SCode.Equation> eqs,initeqs,eqs2,initeqs2,eqs_1,initeqs_1,expandableEqs, expandableEqsInit;
list<SCode.AlgorithmSection> alg,initalg,alg2,initalg2,alg_1,initalg_1;
SCode.Restriction re,r;
Boolean impl;
Boolean impl, valid_connector;
SCode.Visibility vis;
SCode.Encapsulated enc2;
SCode.Partial partialPrefix;
Expand Down Expand Up @@ -3724,6 +3724,11 @@ algorithm
// if is a basic type or derived from it, follow the normal path
true = checkDerivedRestriction(re, r, cn2);

// If it's a connector, check that it's valid.
valid_connector = ConnectUtil.checkShortConnectorDef(ci_state, DA, info);
Util.setStatefulBoolean(stopInst, not valid_connector);
true = valid_connector;

cenv_2 = Env.openScope(cenv, enc2, SOME(cn2), Env.classInfToScopeType(ci_state));
new_ci_state = ClassInf.start(r, Env.getEnvName(cenv_2));

Expand Down

0 comments on commit fcf2915

Please sign in to comment.