Skip to content

Commit

Permalink
- checks for bug #1972 in InstSection.mo with helpers in SCode.mo and…
Browse files Browse the repository at this point in the history
… Absyn.mo

  make the way we check the when equations and when statements more uniform.
  added testsuite/simulation/modelica/initialization/filterBlock1.mos back
  to test the error reporting for #1972.

- unify SCodeEnv.Env with Env.Env
  a lot of changes to adapt to the changes in Env.Env
  new packages starting with F* that mirror the functionality
  in SCodeFlatten, SCodeEnv, SCodeDependency, etc.
  Not used yet, but will be used in the old Inst.mo

- removed some unused code, correct indentation for some functions, etc.

- let's see if I didn't break any tests.


git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@14246 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
adrpo committed Dec 5, 2012
1 parent c18a4bd commit a42d5e2
Show file tree
Hide file tree
Showing 30 changed files with 11,518 additions and 1,343 deletions.
60 changes: 56 additions & 4 deletions Compiler/FrontEnd/Absyn.mo
Original file line number Diff line number Diff line change
Expand Up @@ -1120,14 +1120,15 @@ protected import Error;
public constant TimeStamp dummyTimeStamp = TIMESTAMP(0.0,0.0);

public constant Info dummyInfo = INFO("",false,0,0,0,0,dummyTimeStamp);
public constant TimeStamp newTimeStamp = TIMESTAMP(0.0,1.0);

public function getNewTimeStamp "Function: getNewTimeStamp
generate a new timestamp with edittime>buildtime.
"
public function getNewTimeStamp
"function: getNewTimeStamp
generate a new timestamp with edittime>buildtime."
output TimeStamp ts;
annotation(__OpenModelica_EarlyInline = true);
algorithm
ts := TIMESTAMP(0.0,1.0);
ts := newTimeStamp;
end getNewTimeStamp;

public function setTimeStampBool ""
Expand Down Expand Up @@ -5820,4 +5821,55 @@ algorithm
end matchcontinue;
end pathSetLastIdent;

public function expContainsInitial
"@author:
returns true if expression contains initial()"
input Exp inExp;
output Boolean hasInitial;
algorithm
hasInitial := matchcontinue(inExp)
local Boolean b;
case (_)
equation
((_, b)) = traverseExp(inExp, isInitialTraverseHelper, false);
then
b;
else then false;
end matchcontinue;
end expContainsInitial;

protected function isInitialTraverseHelper
"@author:
returns true if expression is initial()"
input tuple<Exp, Boolean> inExpBooleanTpl;
output tuple<Exp, Boolean> outExpBooleanTpl;
algorithm
outExpBooleanTpl := match(inExpBooleanTpl)
local Exp e; Boolean b;

// make sure we don't have not initial()
case ((UNARY(NOT(), e) , b)) then inExpBooleanTpl;
// we have initial
case ((e , b))
equation
b = isInitial(e);
then ((e, b));
else inExpBooleanTpl;
end match;
end isInitialTraverseHelper;

public function isInitial
"@author:
returns true if expression is initial()"
input Exp inExp;
output Boolean hasReinit;
algorithm
hasReinit := match(inExp)
local Exp e; Boolean b;
case (CALL(function_ = CREF_IDENT("initial", _))) then true;
case (CALL(function_ = CREF_FULLYQUALIFIED(CREF_IDENT("initial", _)))) then true;
else then false;
end match;
end isInitial;

end Absyn;
17 changes: 8 additions & 9 deletions Compiler/FrontEnd/AbsynDep.mo
Original file line number Diff line number Diff line change
Expand Up @@ -52,16 +52,16 @@ encapsulated package AbsynDep
getUsesTransitive(depends,class) -> avltree of used classes under transitive closure

getUsedBy(depends,class) => avltree of classes that uses the class (e.g as component)
"

public uniontype Depends " dependency information (uses/usedBy) for classes"
record DEPENDS
AvlTree uses "the uses information, maps a class to the classes that are used in this class";
AvlTree usedBy "the usedby information, maps a class to the classes that uses this class(e.g. as a component)";
/*NOTE: the AvlTree is a "generic" datatype, defined at the bottom of the file */

end DEPENDS;
end Depends;
public uniontype Depends " dependency information (uses/usedBy) for classes"
record DEPENDS
AvlTree uses "the uses information, maps a class to the classes that are used in this class";
AvlTree usedBy "the usedby information, maps a class to the classes that uses this class(e.g. as a component)";
/*NOTE: the AvlTree is a "generic" datatype, defined at the bottom of the file */
end DEPENDS;
end Depends;


public import Absyn;
Expand Down Expand Up @@ -99,7 +99,6 @@ algorithm
end matchcontinue;
end dumpAvlTreeKeys;


protected function printKeyValueTupleStr "print key/value tuple as key -> value to string"
input tuple<AvlKey,AvlValue> tpl;
output String str;
Expand Down
136 changes: 108 additions & 28 deletions Compiler/FrontEnd/Builtin.mo
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,6 @@ protected constant DAE.Var objectiveVar = DAE.TYPES_VAR("objective",
DAE.ATTR(SCode.POTENTIAL(),SCode.NON_PARALLEL(),SCode.VAR(),Absyn.INPUT(),Absyn.NOT_INNER_OUTER(), SCode.PUBLIC()),
DAE.T_REAL_DEFAULT,DAE.UNBOUND(),NONE()) "- The `objective\' variable" ;



protected constant DAE.Type stringIntInt2string =
DAE.T_FUNCTION(
Expand Down Expand Up @@ -478,11 +477,51 @@ protected constant DAE.Type realrealreal2real =
DAE.FUNCTION_ATTRIBUTES_BUILTIN,
DAE.emptyTypeSource);

public function variableIsBuiltin "Returns true if cref is a builtin variable.
Currently only 'time' is a builtin variable.
"
input DAE.ComponentRef cref;
output Boolean b;
protected constant SCode.Element timeComp =
SCode.COMPONENT(
"time",
SCode.defaultPrefixes,
SCode.ATTR({}, SCode.POTENTIAL(), SCode.NON_PARALLEL(), SCode.VAR(), Absyn.INPUT()),
Absyn.TPATH(Absyn.IDENT("Real"), NONE()), SCode.NOMOD(),
NONE(), NONE(), Absyn.dummyInfo);

protected constant SCode.Element startTimeComp =
SCode.COMPONENT(
"startTime",
SCode.defaultPrefixes,
SCode.ATTR({}, SCode.POTENTIAL(), SCode.NON_PARALLEL(), SCode.VAR(), Absyn.INPUT()),
Absyn.TPATH(Absyn.IDENT("Real"), NONE()), SCode.NOMOD(),
NONE(), NONE(), Absyn.dummyInfo);

protected constant SCode.Element finalTimeComp =
SCode.COMPONENT(
"finalTime",
SCode.defaultPrefixes,
SCode.ATTR({}, SCode.POTENTIAL(), SCode.NON_PARALLEL(), SCode.VAR(), Absyn.INPUT()),
Absyn.TPATH(Absyn.IDENT("Real"), NONE()), SCode.NOMOD(),
NONE(), NONE(), Absyn.dummyInfo);

protected constant SCode.Element objectiveIntegrandComp =
SCode.COMPONENT(
"objectiveIntegrand",
SCode.defaultPrefixes,
SCode.ATTR({}, SCode.POTENTIAL(), SCode.NON_PARALLEL(), SCode.VAR(), Absyn.INPUT()),
Absyn.TPATH(Absyn.IDENT("Real"), NONE()), SCode.NOMOD(),
NONE(), NONE(), Absyn.dummyInfo);

protected constant SCode.Element objectiveVarComp =
SCode.COMPONENT(
"objectiveVar",
SCode.defaultPrefixes,
SCode.ATTR({}, SCode.POTENTIAL(), SCode.NON_PARALLEL(), SCode.VAR(), Absyn.INPUT()),
Absyn.TPATH(Absyn.IDENT("Real"), NONE()), SCode.NOMOD(),
NONE(), NONE(), Absyn.dummyInfo);

public function variableIsBuiltin
"Returns true if cref is a builtin variable.
Currently only 'time' is a builtin variable."
input DAE.ComponentRef cref;
output Boolean b;
algorithm
b := match (cref)
case(DAE.CREF_IDENT(ident="time")) then true;
Expand Down Expand Up @@ -557,7 +596,7 @@ val array_array2int
"
output list<Env.Frame> env;
algorithm
env := Env.newEnvironment() "Debug.fprint (\"insttr\",\"Creating initial env.\\n\") &" ;
env := Env.newEnvironment(NONE());
env := Env.extendFrameC(env, rlType);
env := Env.extendFrameC(env, intType);
env := Env.extendFrameC(env, strType);
Expand All @@ -572,8 +611,8 @@ algorithm
env := Env.extendFrameC(env, uncertaintyType);
end simpleInitialEnv;

public function initialEnv "function: initialEnv

public function initialEnv
"function: initialEnv
The initial environment where instantiation takes place is built
up using this function. It creates an empty environment and adds
all the built-in definitions to it.
Expand All @@ -583,8 +622,7 @@ public function initialEnv "function: initialEnv
- fill
- cat
These operators are catched in the elabBuiltinHandler, along with all
others.
"
others."
input Env.Cache inCache;
output Env.Cache outCache;
output list<Env.Frame> env;
Expand All @@ -599,28 +637,70 @@ algorithm
case (cache) equation
env = Env.getCachedInitialEnv(cache);
then (cache,env);

// if no cached version found create initial env.
case (cache) equation
env = Env.openScope(Env.emptyEnv, SCode.NOT_ENCAPSULATED(), NONE(), NONE());
env = Env.extendFrameC(env, rlType);
env = Env.extendFrameC(env, intType);
env = Env.extendFrameC(env, strType);
env = Env.extendFrameC(env, boolType);
env = Env.extendFrameC(env, enumType);
env = Env.extendFrameC(env, ExternalObjectType);
env = Env.extendFrameC(env, realType);
env = Env.extendFrameC(env, integerType);
env = Env.extendFrameC(env, stringType);
env = Env.extendFrameC(env, booleanType);
env = Env.extendFrameC(env, stateSelectType);
env = Env.extendFrameC(env, uncertaintyType);
env = Env.extendFrameV(env, timeVar, NONE(), Env.VAR_UNTYPED(), {}) "see also variableIsBuiltin";
env = Env.extendFrameCBuiltin(env, rlType);
env = Env.extendFrameCBuiltin(env, intType);
env = Env.extendFrameCBuiltin(env, strType);
env = Env.extendFrameCBuiltin(env, boolType);
env = Env.extendFrameCBuiltin(env, enumType);
env = Env.extendFrameCBuiltin(env, ExternalObjectType);
env = Env.extendFrameCBuiltin(env, realType);
env = Env.extendFrameCBuiltin(env, integerType);
env = Env.extendFrameCBuiltin(env, stringType);
env = Env.extendFrameCBuiltin(env, booleanType);
env = Env.extendFrameCBuiltin(env, stateSelectType);
env = Env.extendFrameCBuiltin(env, uncertaintyType);
env = Env.extendFrameV(
env,
timeVar,
timeComp,
DAE.NOMOD(),
Env.VAR_UNTYPED(),
{});

//If Optimica add the startTime,finalTime,objectiveIntegrand and objective "builtin" variables.
env = Util.if_(Config.acceptOptimicaGrammar(), Env.extendFrameV(env, objectiveVar, NONE(), Env.VAR_UNTYPED(), {}), env);
env = Util.if_(Config.acceptOptimicaGrammar(), Env.extendFrameV(env, objectiveIntegrandVar, NONE(), Env.VAR_UNTYPED(), {}), env);
env = Util.if_(Config.acceptOptimicaGrammar(), Env.extendFrameV(env, startTimeVar, NONE(), Env.VAR_UNTYPED(), {}), env);
env = Util.if_(Config.acceptOptimicaGrammar(), Env.extendFrameV(env, finalTimeVar, NONE(), Env.VAR_UNTYPED(), {}), env);
env = Util.if_(Config.acceptOptimicaGrammar(),
Env.extendFrameV(
env,
objectiveVar,
objectiveVarComp,
DAE.NOMOD(),
Env.VAR_UNTYPED(),
{}),
env);

env = Util.if_(Config.acceptOptimicaGrammar(),
Env.extendFrameV(
env,
objectiveIntegrandVar,
objectiveIntegrandComp,
DAE.NOMOD(),
Env.VAR_UNTYPED(),
{}),
env);

env = Util.if_(Config.acceptOptimicaGrammar(),
Env.extendFrameV(
env,
startTimeVar,
startTimeComp,
DAE.NOMOD(),
Env.VAR_UNTYPED(),
{}),
env);

env = Util.if_(Config.acceptOptimicaGrammar(),
Env.extendFrameV(
env,
finalTimeVar,
finalTimeComp,
DAE.NOMOD(),
Env.VAR_UNTYPED(),
{}),
env);

env = Env.extendFrameT(env, "cardinality", anyNonExpandableConnector2int);
env = Env.extendFrameT(env, "cardinality", anyExpandableConnector2int);
Expand Down
37 changes: 30 additions & 7 deletions Compiler/FrontEnd/CevalFunction.mo
Original file line number Diff line number Diff line change
Expand Up @@ -1605,7 +1605,18 @@ algorithm
var = makeFunctionVariable(inName, ty, binding);
(cache, record_env, st) =
makeRecordEnvironment(inType, inOptValue, cache, st);
env = Env.extendFrameV(inEnv, var, NONE(), Env.VAR_TYPED(), record_env);
env = Env.extendFrameV(
inEnv,
var,
SCode.COMPONENT(
inName,
SCode.defaultPrefixes,
SCode.ATTR({}, SCode.POTENTIAL(), SCode.NON_PARALLEL(), SCode.VAR(), Absyn.BIDIR()),
Absyn.TPATH(Absyn.IDENT(""), NONE()), SCode.NOMOD(),
NONE(), NONE(), Absyn.dummyInfo),
DAE.NOMOD(),
Env.VAR_TYPED(),
record_env);
then
(cache, env, st);

Expand All @@ -1616,9 +1627,21 @@ algorithm
(cache, ty, st) =
appendDimensions(inType, inOptValue, inDims, inCache, inEnv, inST);
var = makeFunctionVariable(inName, ty, binding);
env = Env.extendFrameV(inEnv, var, NONE(), Env.VAR_TYPED(), {});
env = Env.extendFrameV(
inEnv,
var,
SCode.COMPONENT(
inName,
SCode.defaultPrefixes,
SCode.ATTR({}, SCode.POTENTIAL(), SCode.NON_PARALLEL(), SCode.VAR(), Absyn.BIDIR()),
Absyn.TPATH(Absyn.IDENT(""), NONE()), SCode.NOMOD(),
NONE(), NONE(), Absyn.dummyInfo),
DAE.NOMOD(),
Env.VAR_TYPED(),
{});
then
(cache, env, st);

end matchcontinue;
end extendEnvWithVar;

Expand Down Expand Up @@ -1670,7 +1693,7 @@ algorithm

case (DAE.T_COMPLEX(complexClassType = ClassInf.RECORD(path = _),varLst = var_lst), _, _, st)
equation
env = Env.newEnvironment();
env = Env.newEnvironment(NONE());
vals = getRecordValues(inOptValue, inRecordType);
((cache, env, st)) = List.threadFold(var_lst, vals,
extendEnvWithRecordVar, (inCache, env, st));
Expand Down Expand Up @@ -1879,7 +1902,7 @@ algorithm
case (cr as DAE.CREF_IDENT(ident = id, subscriptLst = {}, identType = ety as
DAE.T_COMPLEX(complexClassType = ClassInf.RECORD(path = _))), _, _, _, st)
equation
(_, var, _, inst_status, env) =
(_, var, _, _, inst_status, env) =
Lookup.lookupIdentLocal(inCache, inEnv, id);
(cache, env, st) = assignRecord(ety, inNewValue, inCache, env, st);
var = updateRecordBinding(var, inNewValue);
Expand Down Expand Up @@ -1911,7 +1934,7 @@ algorithm
case (cr as DAE.CREF_QUAL(ident = id, subscriptLst = {},
componentRef = cr_rest), _, _, _, st)
equation
(_, var, _, inst_status, env) =
(_, var, _, _, inst_status, env) =
Lookup.lookupIdentLocal(inCache, inEnv, id);
(cache, env, st) = assignVariable(cr_rest, inNewValue, inCache, env, st);
comp_id = ComponentReference.crefFirstIdent(cr_rest);
Expand Down Expand Up @@ -2428,7 +2451,7 @@ algorithm
DAE.T_COMPLEX(complexClassType = ClassInf.RECORD(path = p),
varLst = vars), _)
equation
(_, _, _, _, env) =
(_, _, _, _, _, env) =
Lookup.lookupIdentLocal(Env.emptyCache(), inEnv, id);
vals = List.map1(vars, getRecordComponentValue, env);
var_names = List.map(vars, Types.getVarName);
Expand Down Expand Up @@ -2462,7 +2485,7 @@ algorithm
// A non-record variable.
case (DAE.TYPES_VAR(name = id, ty = ty), _)
equation
(_, DAE.TYPES_VAR(binding = binding), _, _, _) =
(_, DAE.TYPES_VAR(binding = binding), _, _, _, _) =
Lookup.lookupIdentLocal(Env.emptyCache(), inEnv, id);
val = getBindingOrDefault(binding, ty);
then
Expand Down

0 comments on commit a42d5e2

Please sign in to comment.