Skip to content

Commit

Permalink
- Use Error.addSourceMessage instead of Error.addMessage when printin…
Browse files Browse the repository at this point in the history
…g inStream

  and actualStream elaboration errors.
- Turned on stream connector balance checks by default, because models using
  stream should follow Modelica 3 rules anyway.
- Added Modelica.Utilities.Files.list to libraries/msl31/Modelica.Utilities test
  case.
- Added a couple of stream test cases.


git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@6965 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
perost committed Nov 11, 2010
1 parent b294d0d commit 82d3448
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 35 deletions.
32 changes: 9 additions & 23 deletions Compiler/ConnectUtil.mo
Expand Up @@ -2339,29 +2339,15 @@ public function checkConnectorBalance
input list<DAE.Var> inVars;
input Absyn.Path path;
input Absyn.Info info;
algorithm
_ := matchcontinue(inVars, path, info)
local
Integer potentials, flows, streams;

// Only do balance checking if the checkconnect debug flag is set.
case (_, _, _)
equation
false = RTOpts.debugFlag("checkconnect");
then
();

else
equation
(potentials, flows, streams) = countConnectorVars(inVars);
checkConnectorBalance2(potentials, flows, streams, path, info);
//print(Absyn.pathString(path) +& " has:\n\t" +&
// intString(potentials) +& " potential variables\n\t" +&
// intString(flows) +& " flow variables\n\t" +&
// intString(streams) +& " stream variables\n\n");
then
();
end matchcontinue;
Integer potentials, flows, streams;
algorithm
(potentials, flows, streams) := countConnectorVars(inVars);
checkConnectorBalance2(potentials, flows, streams, path, info);
//print(Absyn.pathString(path) +& " has:\n\t" +&
// intString(potentials) +& " potential variables\n\t" +&
// intString(flows) +& " flow variables\n\t" +&
// intString(streams) +& " stream variables\n\n");
end checkConnectorBalance;

protected function checkConnectorBalance2
Expand All @@ -2378,7 +2364,7 @@ algorithm
// The connector is balanced.
case (_, _, _, _, _)
equation
true = intEq(inPotentialVars, inFlowVars);
true = intEq(inPotentialVars, inFlowVars) or not RTOpts.debugFlag("checkconnect");
true = Util.if_(intEq(inStreamVars, 0), true, intEq(inFlowVars, 1));
then
();
Expand Down
2 changes: 1 addition & 1 deletion Compiler/Error.mo
Expand Up @@ -514,7 +514,7 @@ protected constant list<tuple<Integer, MessageType, Severity, String>> errorTabl
(PACKAGE_VARIABLE_NOT_CONSTANT, TRANSLATION(),ERROR(),"Variable %s in package %s is not constant"),
(RECURSIVE_DEFINITION,TRANSLATION(),ERROR(),"Class %s has a recursive definition, i.e. contains an instance of itself"),
(NON_STREAM_OPERAND_IN_STREAM_OPERATOR, TRANSLATION(), ERROR(),
"Operand %s to operator %s in component %s is not a stream variable."),
"Operand %s to operator %s is not a stream variable."),
(UNBALANCED_CONNECTOR, TRANSLATION(), WARNING(),
"Connector %s is not balanced: %s"),
(UNBOUND_PARAMETER_WARNING,TRANSLATION(),WARNING(),
Expand Down
20 changes: 9 additions & 11 deletions Compiler/Static.mo
Expand Up @@ -3855,7 +3855,7 @@ algorithm
elabExp(cache, env, exp, impl, NONE(), true, pre, info);
exp_2 :: _ = Expression.flattenArrayExpToList(exp_1);
(tp, _) = Types.flattenArrayType(tp);
validateBuiltinStreamOperator(cache, env, exp_2, tp, "inStream", pre);
validateBuiltinStreamOperator(cache, env, exp_2, tp, "inStream", info);
t = Types.elabType(tp);
exp_2 = makeBuiltinCall("inStream", {exp_1}, t);
then
Expand Down Expand Up @@ -3895,7 +3895,7 @@ algorithm
elabExp(cache, env, exp, impl, NONE(), true, pre, info);
exp_2 :: _ = Expression.flattenArrayExpToList(exp_1);
(tp, _) = Types.flattenArrayType(tp);
validateBuiltinStreamOperator(cache, env, exp_2, tp, "actualStream", pre);
validateBuiltinStreamOperator(cache, env, exp_2, tp, "actualStream", info);
t = Types.elabType(tp);
exp_2 = makeBuiltinCall("actualStream", {exp_1}, t);
then
Expand All @@ -3909,12 +3909,12 @@ protected function validateBuiltinStreamOperator
input DAE.Exp inOperand;
input DAE.Type inType;
input String inOperator;
input Prefix.Prefix inPrefix;
input Absyn.Info inInfo;
algorithm
_ := matchcontinue(inCache, inEnv, inOperand, inType, inOperator, inPrefix)
_ := matchcontinue(inCache, inEnv, inOperand, inType, inOperator, inInfo)
local
DAE.ComponentRef cr;
String pre_str, op_str;
String op_str;
// Operand is a stream variable, ok!
case (_, _, DAE.CREF(componentRef = cr), _, _, _)
equation
Expand All @@ -3928,19 +3928,17 @@ algorithm
(_, DAE.ATTR(streamPrefix = false), _, _, _, _, _, _, _) =
Lookup.lookupVar(inCache, inEnv, cr);
op_str = ComponentReference.printComponentRefStr(cr);
pre_str = PrefixUtil.printPrefixStr3(inPrefix);
Error.addMessage(Error.NON_STREAM_OPERAND_IN_STREAM_OPERATOR,
{op_str, inOperator, pre_str});
Error.addSourceMessage(Error.NON_STREAM_OPERAND_IN_STREAM_OPERATOR,
{op_str, inOperator}, inInfo);
then
fail();
// Operand is not even a component reference, error!
case (_, _, _, _, _, _)
equation
false = Expression.isCref(inOperand);
op_str = ExpressionDump.printExpStr(inOperand);
pre_str = PrefixUtil.printPrefixStr3(inPrefix);
Error.addMessage(Error.NON_STREAM_OPERAND_IN_STREAM_OPERATOR,
{op_str, inOperator, pre_str});
Error.addSourceMessage(Error.NON_STREAM_OPERAND_IN_STREAM_OPERATOR,
{op_str, inOperator}, inInfo);
then
fail();
end matchcontinue;
Expand Down

0 comments on commit 82d3448

Please sign in to comment.