Skip to content

Commit

Permalink
Removed operator record restriction. Now operator records are special…
Browse files Browse the repository at this point in the history
… cases of record restrictions.

saveTotalSCode should work now for models containing operator records.

git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@17876 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
mahge committed Oct 24, 2013
1 parent 1a0d508 commit da38ee7
Show file tree
Hide file tree
Showing 15 changed files with 63 additions and 63 deletions.
11 changes: 6 additions & 5 deletions Compiler/FrontEnd/ClassInf.mo
Original file line number Diff line number Diff line change
Expand Up @@ -402,15 +402,15 @@ algorithm
case (SCode.R_CLASS(),p) then UNKNOWN(p);
case (SCode.R_OPTIMIZATION(),p) then OPTIMIZATION(p);
case (SCode.R_MODEL(),p) then MODEL(p);
case (SCode.R_RECORD(),p) then RECORD(p);
case (SCode.R_RECORD(_),p) then RECORD(p);
case (SCode.R_BLOCK(),p) then BLOCK(p);
case (SCode.R_CONNECTOR(isExpandable),p) then CONNECTOR(p,isExpandable);
case (SCode.R_TYPE(),p) then TYPE(p);
case (SCode.R_PACKAGE(),p) then PACKAGE(p);
case (SCode.R_FUNCTION(SCode.FR_NORMAL_FUNCTION(isImpure)),p) then FUNCTION(p, isImpure);
case (SCode.R_FUNCTION(SCode.FR_EXTERNAL_FUNCTION(isImpure)),p) then FUNCTION(p, isImpure);
case (SCode.R_FUNCTION(_),p) then FUNCTION(p, false);
case (SCode.R_OPERATOR(),p) then RECORD(p);
case (SCode.R_OPERATOR(),p) then FUNCTION(p, false);
case (SCode.R_ENUMERATION(),p) then ENUMERATION(p);
case (SCode.R_PREDEFINED_INTEGER(),p) then TYPE_INTEGER(p);
case (SCode.R_PREDEFINED_REAL(),p) then TYPE_REAL(p);
Expand Down Expand Up @@ -538,9 +538,9 @@ algorithm
case (MODEL(path = p),SCode.R_MODEL()) then ();


case (RECORD(path = p),SCode.R_RECORD()) then ();
case (RECORD(path = p),SCode.R_RECORD(_)) then ();
case (RECORD(path = p),SCode.R_CONNECTOR(_)) then ();
case (HAS_RESTRICTIONS(path = p,hasEquations=false,hasConstraints=false,hasAlgorithms=false),SCode.R_RECORD()) then ();
case (HAS_RESTRICTIONS(path = p,hasEquations=false,hasConstraints=false,hasAlgorithms=false),SCode.R_RECORD(_)) then ();

case (BLOCK(path = p),SCode.R_BLOCK()) then ();
case (MODEL(path = p),SCode.R_MODEL()) then ();
Expand Down Expand Up @@ -745,7 +745,8 @@ algorithm
case UNKNOWN(p) then (SCode.R_CLASS(),p);
case OPTIMIZATION(p) then (SCode.R_OPTIMIZATION(),p);
case MODEL(p) then (SCode.R_MODEL(),p);
case RECORD(p) then (SCode.R_RECORD(),p);
// mahge: TODO ClassInf.RECORD should contain isOperator.
case RECORD(p) then (SCode.R_RECORD(false),p);
case BLOCK(p) then (SCode.R_BLOCK(),p) ;
case CONNECTOR(p,isExpandable) then (SCode.R_CONNECTOR(isExpandable),p);
case TYPE(p) then (SCode.R_TYPE(),p);
Expand Down
4 changes: 2 additions & 2 deletions Compiler/FrontEnd/Inst.mo
Original file line number Diff line number Diff line change
Expand Up @@ -2284,8 +2284,8 @@ algorithm
false = valueEq(SCode.R_MODEL(), re);
false = valueEq(SCode.R_PACKAGE(), re);
false = SCode.isFunctionRestriction(re);
false = valueEq(SCode.R_RECORD(), re);
false = valueEq(SCode.R_OPERATOR_RECORD(), re);
false = valueEq(SCode.R_RECORD(true), re);
false = valueEq(SCode.R_RECORD(false), re);
// no components and at least one extends!

(cdefelts,extendsclasselts,extendselts as _::_,compelts as {}) = InstUtil.splitElts(els);
Expand Down
6 changes: 3 additions & 3 deletions Compiler/FrontEnd/InstFunction.mo
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,7 @@ algorithm
SCode.Restriction r;
SCode.Partial pPrefix;

case (cache,env,ih,mod,pre,(c as SCode.CLASS(name = n,restriction = SCode.R_RECORD(), partialPrefix = pPrefix)),inst_dims)
case (cache,env,ih,mod,pre,(c as SCode.CLASS(name = n,restriction = SCode.R_RECORD(_), partialPrefix = pPrefix)),inst_dims)
equation
(cache,c,cenv) = Lookup.lookupRecordConstructorClass(cache,env,Absyn.IDENT(n));
(cache,env,ih,{DAE.FUNCTION(fpath,_,ty1,_,_,_,source,_)}) = implicitFunctionInstantiation2(cache,cenv,ih,mod,pre,c,inst_dims,true);
Expand All @@ -335,7 +335,7 @@ algorithm

case (cache,env,ih,mod,pre,(c as SCode.CLASS(name = n,restriction = r,partialPrefix = pPrefix)),inst_dims)
equation
failure(SCode.R_RECORD() = r);
failure(SCode.R_RECORD(_) = r);
true = MetaUtil.strictRMLCheck(Flags.isSet(Flags.RML),c);
(cache,env,ih,funs) = implicitFunctionInstantiation2(cache,env,ih,mod,pre,c,inst_dims,false);
cache = InstUtil.addFunctionsToDAE(cache, funs, pPrefix);
Expand Down Expand Up @@ -903,7 +903,7 @@ algorithm
equation

(_,recordCl,recordEnv) = Lookup.lookupClass(inCache, inEnv, inPath, false);
true = MetaUtil.classHasRestriction(recordCl, SCode.R_RECORD());
true = SCode.isRecord(recordCl);

(cache,_,_,_,_,_,recType,_,_,_) = Inst.instClass(inCache,recordEnv, InnerOuter.emptyInstHierarchy,
UnitAbsynBuilder.emptyInstStore(), DAE.NOMOD(), Prefix.NOPRE(), recordCl,
Expand Down
16 changes: 7 additions & 9 deletions Compiler/FrontEnd/InstUtil.mo
Original file line number Diff line number Diff line change
Expand Up @@ -807,19 +807,19 @@ algorithm
// type -> type
case (SCode.R_TYPE(), SCode.R_TYPE()) then ();
// record -> record
case (SCode.R_RECORD(), SCode.R_RECORD()) then ();
case (SCode.R_RECORD(_), SCode.R_RECORD(_)) then ();
// connector -> type
case (SCode.R_CONNECTOR(_), SCode.R_TYPE()) then ();
// connector -> record
case (SCode.R_CONNECTOR(_), SCode.R_RECORD()) then ();
case (SCode.R_CONNECTOR(_), SCode.R_RECORD(_)) then ();
// connector -> connector
case (SCode.R_CONNECTOR(_), SCode.R_CONNECTOR(_)) then ();
// block -> record
case (SCode.R_BLOCK(), SCode.R_RECORD()) then ();
case (SCode.R_BLOCK(), SCode.R_RECORD(false)) then ();
// block -> block
case (SCode.R_BLOCK(), SCode.R_BLOCK()) then ();
// model -> record
case (SCode.R_MODEL(), SCode.R_RECORD()) then ();
case (SCode.R_MODEL(), SCode.R_RECORD(false)) then ();
// model -> block
case (SCode.R_MODEL(), SCode.R_BLOCK()) then ();
// model -> model
Expand All @@ -831,15 +831,13 @@ algorithm
// class -> model
case (SCode.R_CLASS(), SCode.R_MODEL()) then ();
// class -> record
case (SCode.R_CLASS(), SCode.R_RECORD()) then ();
case (SCode.R_CLASS(), SCode.R_RECORD(_)) then ();
// class -> block
case (SCode.R_CLASS(), SCode.R_BLOCK()) then ();
// class -> class
case (SCode.R_CLASS(), SCode.R_CLASS()) then ();
// operator -> operator
case (SCode.R_OPERATOR(), SCode.R_OPERATOR()) then ();
// operator record
case (SCode.R_OPERATOR_RECORD(), SCode.R_OPERATOR_RECORD()) then ();
end matchcontinue;
end checkExtendsRestrictionMatch;

Expand Down Expand Up @@ -3121,7 +3119,7 @@ algorithm

// add it to the cache if we have a input record component
case (_, _, _, _, _, ClassInf.FUNCTION(path = path), _,
SCode.CLASS(name = name, restriction = SCode.R_RECORD()), _)
SCode.CLASS(name = name, restriction = SCode.R_RECORD(_)), _)
equation
print("Depreciated record constructor used: Inst.addRecordConstructorsToTheCache");

Expand Down Expand Up @@ -3948,7 +3946,7 @@ algorithm
case (cache, _, _, _, cl as SCode.CLASS(name = "String"), _, _) then (cache,{},cl,DAE.NOMOD());
case (cache, _, _, _, cl as SCode.CLASS(name = "Boolean"), _, _) then (cache,{},cl,DAE.NOMOD());

case (cache, _, _, _, cl as SCode.CLASS(restriction = SCode.R_RECORD(),
case (cache, _, _, _, cl as SCode.CLASS(restriction = SCode.R_RECORD(_),
classDef = SCode.PARTS(elementLst = _)), _, _) then (cache,{},cl,DAE.NOMOD());

//------------------------
Expand Down
2 changes: 1 addition & 1 deletion Compiler/FrontEnd/InstVar.mo
Original file line number Diff line number Diff line change
Expand Up @@ -698,7 +698,7 @@ algorithm
// R1 r2(v1=1, v1=2); // <= Here
// end out;
// see testsuit/mofiles/RecordBindings.mo.
case (cache,env,ih,store,ci_state,mod as DAE.MOD(subModLst = subMods, eqModOption = NONE()),pre,n,cl as SCode.CLASS(restriction = SCode.R_RECORD()),attr,pf,dims,idxs,inst_dims,impl,comment,info,graph,csets)
case (cache,env,ih,store,ci_state,mod as DAE.MOD(subModLst = subMods, eqModOption = NONE()),pre,n,cl as SCode.CLASS(restriction = SCode.R_RECORD(_)),attr,pf,dims,idxs,inst_dims,impl,comment,info,graph,csets)
equation
true = ClassInf.isFunction(ci_state);
InstUtil.checkFunctionVar(n, attr, pf, info);
Expand Down
8 changes: 4 additions & 4 deletions Compiler/FrontEnd/Lookup.mo
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ algorithm
(cache,t,env_1);*/

// Record constructors
case (cache,env_1,path,c as SCode.CLASS(name=id,restriction=SCode.R_RECORD()))
case (cache,env_1,path,c as SCode.CLASS(name=id,restriction=SCode.R_RECORD(_)))
equation
(cache,env_1,t) = buildRecordType(cache,env_1,c);
then
Expand Down Expand Up @@ -927,7 +927,7 @@ algorithm
case (cache,env,path)
equation
(cache,c,env_1) = lookupClass(cache,env, path, false);
SCode.CLASS(name = name, restriction=SCode.R_RECORD()) = c;
SCode.CLASS(name = name, restriction=SCode.R_RECORD(_)) = c;
(cache,_,c) = buildRecordConstructorClass(cache,env_1,c);
then
(cache,c,env_1);
Expand Down Expand Up @@ -1855,7 +1855,7 @@ algorithm
fail();

// Record constructor function
case (cache,Env.CLASS((cdef as SCode.CLASS(name=n,restriction=SCode.R_RECORD())),cenv,_),env,id)
case (cache,Env.CLASS((cdef as SCode.CLASS(name=n,restriction=SCode.R_RECORD(_))),cenv,_),env,id)
equation
(cache,env_3,ty) = buildRecordType(cache,env,cdef);
then
Expand Down Expand Up @@ -1936,7 +1936,7 @@ algorithm
// Records, create record constructor function
case (cache,ht,httypes,env,id,_)
equation
Env.CLASS((cdef as SCode.CLASS(name=n,restriction=SCode.R_RECORD())),cenv,_) = Env.avlTreeGet(ht, id);
Env.CLASS((cdef as SCode.CLASS(name=n,restriction=SCode.R_RECORD(_))),cenv,_) = Env.avlTreeGet(ht, id);
(cache,_,ftype) = buildRecordType(cache,env,cdef);
then
(cache,{ftype});
Expand Down
2 changes: 1 addition & 1 deletion Compiler/FrontEnd/NFSCodeCheck.mo
Original file line number Diff line number Diff line change
Expand Up @@ -558,7 +558,7 @@ algorithm
outIsInstantiable := match(inRestriction)
case SCode.R_CLASS() then true;
case SCode.R_MODEL() then true;
case SCode.R_RECORD() then true;
case SCode.R_RECORD(_) then true;
case SCode.R_BLOCK() then true;
case SCode.R_CONNECTOR(isExpandable = _) then true;
case SCode.R_TYPE() then true;
Expand Down
22 changes: 3 additions & 19 deletions Compiler/FrontEnd/NFSCodeDependency.mo
Original file line number Diff line number Diff line change
Expand Up @@ -895,7 +895,7 @@ algorithm
inExtends;

//operators in operator record might be used later.
case (SCode.CLASS(name = name, restriction=SCode.R_OPERATOR(), info = info), _, _, SCode.R_OPERATOR_RECORD())
case (SCode.CLASS(name = name, restriction=SCode.R_OPERATOR(), info = info), _, _, SCode.R_RECORD(true))
equation
analyseClass(Absyn.IDENT(name), inEnv, info);
then
Expand All @@ -912,7 +912,7 @@ algorithm
fail();

//operator functions in operator record might be used later.
case (SCode.CLASS(name = name, restriction=SCode.R_FUNCTION(SCode.FR_OPERATOR_FUNCTION()), info = info), _, _, SCode.R_OPERATOR_RECORD())
case (SCode.CLASS(name = name, restriction=SCode.R_FUNCTION(SCode.FR_OPERATOR_FUNCTION()), info = info), _, _, SCode.R_RECORD(true))
equation
analyseClass(Absyn.IDENT(name), inEnv, info);
then
Expand Down Expand Up @@ -1033,7 +1033,7 @@ protected function markAsUsedOnRestriction2
algorithm
isRestricted := match(inRestriction)
case SCode.R_CONNECTOR(isExpandable = _) then true;
case SCode.R_RECORD() then true;
case SCode.R_RECORD(_) then true;
else false;
end match;
end markAsUsedOnRestriction2;
Expand Down Expand Up @@ -1988,8 +1988,6 @@ algorithm
(cdef, class_env) =
collectUsedClassDef(cdef, enclosing_env, class_frame, inClassName, inAccumPath);

//Fix operator record restriction to record
res = fixRestrictionOfOperatorRecord(res);
cls = SCode.CLASS(name, prefixes, ep, pp, res, cdef, cmt, info);
resolved_item = updateItemEnv(resolved_item, cls, class_env);
basename = name +& NFSCodeEnv.BASE_CLASS_SUFFIX;
Expand All @@ -2010,8 +2008,6 @@ algorithm
enclosing_env = NFSCodeEnv.enterScope(inEnv, name);
(cdef, class_env) =
collectUsedClassDef(cdef, enclosing_env, class_frame, inClassName, inAccumPath);
//Fix operator record restriction to record
res = fixRestrictionOfOperatorRecord(res);
// Add the class to the new environment.
cls = SCode.CLASS(name, prefixes, ep, pp, res, cdef, cmt, info);
item = updateItemEnv(item, cls, class_env);
Expand All @@ -2022,18 +2018,6 @@ algorithm
end match;
end collectUsedClass;

protected function fixRestrictionOfOperatorRecord
input SCode.Restriction inRes;
output SCode.Restriction outRes;
algorithm
outRes := match(inRes)
case (SCode.R_OPERATOR_RECORD())
then SCode.R_RECORD();

else inRes;
end match;
end fixRestrictionOfOperatorRecord;

protected function checkClassUsed
"Given the environment item and definition for a class, returns whether the
class is used or not."
Expand Down
23 changes: 17 additions & 6 deletions Compiler/FrontEnd/SCode.mo
Original file line number Diff line number Diff line change
Expand Up @@ -58,14 +58,14 @@ uniontype Restriction
record R_CLASS end R_CLASS;
record R_OPTIMIZATION end R_OPTIMIZATION;
record R_MODEL end R_MODEL;
record R_RECORD end R_RECORD;
record R_RECORD
Boolean isOperator;
end R_RECORD;
record R_BLOCK end R_BLOCK;
record R_CONNECTOR "a connector"
Boolean isExpandable "is expandable?";
end R_CONNECTOR;
record R_OPERATOR end R_OPERATOR;

record R_OPERATOR_RECORD end R_OPERATOR_RECORD;
record R_TYPE end R_TYPE;
record R_PACKAGE end R_PACKAGE;
record R_FUNCTION
Expand Down Expand Up @@ -933,11 +933,22 @@ public function isRecord
output Boolean outBoolean;
algorithm
outBoolean := matchcontinue (inClass)
case CLASS(restriction = R_RECORD()) then true;
case CLASS(restriction = R_RECORD(_)) then true;
case _ then false;
end matchcontinue;
end isRecord;

public function isOperatorRecord
"Return true if Class is a operator record."
input Element inClass;
output Boolean outBoolean;
algorithm
outBoolean := matchcontinue (inClass)
case CLASS(restriction = R_RECORD(true)) then true;
case _ then false;
end matchcontinue;
end isOperatorRecord;

public function isFunction
"Return true if Class is a function."
input Element inClass;
Expand Down Expand Up @@ -1134,12 +1145,12 @@ algorithm
case (R_CLASS(),R_CLASS()) then true;
case (R_OPTIMIZATION(),R_OPTIMIZATION()) then true;
case (R_MODEL(),R_MODEL()) then true;
case (R_RECORD(),R_RECORD()) then true;
case (R_RECORD(true),R_RECORD(true)) then true; // operator record
case (R_RECORD(false),R_RECORD(false)) then true;
case (R_BLOCK(),R_BLOCK()) then true;
case (R_CONNECTOR(true),R_CONNECTOR(true)) then true; // expandable connectors
case (R_CONNECTOR(false),R_CONNECTOR(false)) then true; // non expandable connectors
case (R_OPERATOR(),R_OPERATOR()) then true; // operator
case (R_OPERATOR_RECORD(),R_OPERATOR_RECORD()) then true; // operator function
case (R_TYPE(),R_TYPE()) then true;
case (R_PACKAGE(),R_PACKAGE()) then true;
case (R_FUNCTION(funcRest1),R_FUNCTION(funcRest2)) then funcRestrictionEqual(funcRest1,funcRest2);
Expand Down
4 changes: 2 additions & 2 deletions Compiler/FrontEnd/SCodeDump.mo
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,8 @@ algorithm
case SCode.R_CLASS() then "CLASS";
case SCode.R_OPTIMIZATION() then "OPTIMIZATION";
case SCode.R_MODEL() then "MODEL";
case SCode.R_RECORD() then "RECORD";
case SCode.R_RECORD(false) then "RECORD";
case SCode.R_RECORD(true) then "OPERATOR_RECORD";
case SCode.R_BLOCK() then "BLOCK";
case SCode.R_CONNECTOR(false) then "CONNECTOR";
case SCode.R_CONNECTOR(true) then "EXPANDABLE_CONNECTOR";
Expand All @@ -106,7 +107,6 @@ algorithm
case SCode.R_FUNCTION(SCode.FR_RECORD_CONSTRUCTOR()) then "RECORD_CONSTRUCTOR";
case SCode.R_FUNCTION(SCode.FR_PARALLEL_FUNCTION()) then "PARALLEL FUNCTION";
case SCode.R_FUNCTION(SCode.FR_KERNEL_FUNCTION()) then "KERNEL_FUNCTION";
case SCode.R_OPERATOR_RECORD() then "OPERATOR_RECORD";
case SCode.R_TYPE() then "TYPE";
case SCode.R_PACKAGE() then "PACKAGE";
case SCode.R_ENUMERATION() then "ENUMERATION";
Expand Down
5 changes: 3 additions & 2 deletions Compiler/FrontEnd/SCodeUtil.mo
Original file line number Diff line number Diff line change
Expand Up @@ -302,14 +302,15 @@ algorithm
case (_,Absyn.R_CLASS()) then SCode.R_CLASS();
case (_,Absyn.R_OPTIMIZATION()) then SCode.R_OPTIMIZATION();
case (_,Absyn.R_MODEL()) then SCode.R_MODEL();
case (_,Absyn.R_RECORD()) then SCode.R_RECORD();
case (_,Absyn.R_RECORD()) then SCode.R_RECORD(false);
case (_,Absyn.R_OPERATOR_RECORD()) then SCode.R_RECORD(true);

case (_,Absyn.R_BLOCK()) then SCode.R_BLOCK();

case (_,Absyn.R_CONNECTOR()) then SCode.R_CONNECTOR(false);
case (_,Absyn.R_EXP_CONNECTOR()) equation System.setHasExpandableConnectors(true); then SCode.R_CONNECTOR(true);

case (_,Absyn.R_OPERATOR()) then SCode.R_OPERATOR();
case (_,Absyn.R_OPERATOR_RECORD()) then SCode.R_OPERATOR_RECORD();

case (_,Absyn.R_TYPE()) then SCode.R_TYPE();
case (_,Absyn.R_PACKAGE()) then SCode.R_PACKAGE();
Expand Down
10 changes: 5 additions & 5 deletions Compiler/FrontEnd/Static.mo
Original file line number Diff line number Diff line change
Expand Up @@ -7216,7 +7216,7 @@ algorithm
equation
(cache,cl as SCode.CLASS(restriction = SCode.R_PACKAGE()),_) =
Lookup.lookupClass(cache, env, Absyn.IDENT("GraphicalAnnotationsProgram____"), false);
(cache,cl as SCode.CLASS(name = name, restriction = SCode.R_RECORD()),env_1) = Lookup.lookupClass(cache, env, fn, false);
(cache,cl as SCode.CLASS(name = name, restriction = SCode.R_RECORD(_)),env_1) = Lookup.lookupClass(cache, env, fn, false);
(cache,cl,env_2) = Lookup.lookupRecordConstructorClass(cache, env_1 /* env */, fn);
(comps,_::names) = SCode.getClassComponents(cl); // remove the fist one as it is the result!
/*
Expand Down Expand Up @@ -7293,7 +7293,7 @@ algorithm
ErrorExt.setCheckpoint("RecordConstructor");

(_,recordCl,recordEnv) = Lookup.lookupClass(cache, env, fn, false);
true = MetaUtil.classHasRestriction(recordCl, SCode.R_RECORD());
true = SCode.isRecord(recordCl);


(cache,func) = InstFunction.getRecordConstructorFunction(cache,env,fn);
Expand Down Expand Up @@ -7326,8 +7326,8 @@ algorithm
then
(cache,expProps);

/* If the default constructor failed look for
overloaded Record constructors (operators), user defined.
/* If the default constructor failed and we have an operator record
look for overloaded Record constructors (operators), user defined.
mahge:TODO move this to a function and call it from above.
avoids uneccesary lookup since we already have a record.*/
case (cache,env,fn,args,nargs,impl,_,st,pre,_)
Expand All @@ -7336,7 +7336,7 @@ algorithm
false = Util.getStatefulBoolean(stopElab);

(cache,recordCl,recordEnv) = Lookup.lookupClass(cache,env,fn, false);
true = MetaUtil.classHasRestriction(recordCl, SCode.R_RECORD());
true = SCode.isOperatorRecord(recordCl);

fn_1 = Absyn.joinPaths(fn,Absyn.IDENT("'constructor'"));
(cache,recordCl,recordEnv) = Lookup.lookupClass(cache,recordEnv,fn_1, false);
Expand Down

0 comments on commit da38ee7

Please sign in to comment.