Skip to content

Commit

Permalink
- Collected all function kind restrictions(normal, external, operator…
Browse files Browse the repository at this point in the history
…) in to one restriction with its own attributes.

  R_FUNCTION() -> R_FUNCTION(FunctionRestriction), FunctionRestriction(FR_NORMAL_FUNCTION, FR_EXTERNAL_FUNCTION, FR_OPERATOR_FUNCTION, FR_RECORD_CONSTRUCTOR)
  This will also help for more compact function handling when the ParModelica parallel and kernel functions are added.  
+ Added FR_RECORD_CONSTRUCTOR restriction to SCode so that we can handle record constructors differently. 

git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@11169 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
mahge committed Feb 22, 2012
1 parent 999ea70 commit b4830e5
Show file tree
Hide file tree
Showing 21 changed files with 293 additions and 221 deletions.
30 changes: 25 additions & 5 deletions Compiler/FrontEnd/Absyn.mo
Expand Up @@ -1020,9 +1020,10 @@ uniontype Restriction "These constructors each correspond to a different kind of
record R_EXP_CONNECTOR "expandable connector class" end R_EXP_CONNECTOR;
record R_TYPE end R_TYPE;
record R_PACKAGE end R_PACKAGE;
record R_FUNCTION end R_FUNCTION;
record R_FUNCTION
FunctionRestriction functionRestriction;
end R_FUNCTION;
record R_OPERATOR "an operator" end R_OPERATOR;
record R_OPERATOR_FUNCTION "an operator function" end R_OPERATOR_FUNCTION;
record R_OPERATOR_RECORD "an operator record" end R_OPERATOR_RECORD;
record R_ENUMERATION end R_ENUMERATION;
record R_PREDEFINED_INTEGER end R_PREDEFINED_INTEGER;
Expand All @@ -1041,6 +1042,12 @@ uniontype Restriction "These constructors each correspond to a different kind of
record R_UNKNOWN "Helper restriction" end R_UNKNOWN; /* added by simbj */
end Restriction;

public
uniontype FunctionRestriction
record FR_NORMAL_FUNCTION "a normal function" end FR_NORMAL_FUNCTION;
record FR_OPERATOR_FUNCTION "an operator function" end FR_OPERATOR_FUNCTION;
end FunctionRestriction;

public
uniontype Annotation "An Annotation is a class_modification.
- Annotation"
Expand Down Expand Up @@ -4091,7 +4098,8 @@ algorithm
case R_EXP_CONNECTOR() then "EXPANDABLE CONNECTOR";
case R_TYPE() then "TYPE";
case R_PACKAGE() then "PACKAGE";
case R_FUNCTION() then "FUNCTION";
case R_FUNCTION(FR_NORMAL_FUNCTION()) then "FUNCTION";
case R_FUNCTION(FR_OPERATOR_FUNCTION()) then "OPERATOR FUNCTION";
case R_PREDEFINED_INTEGER() then "PREDEFINED_INT";
case R_PREDEFINED_REAL() then "PREDEFINED_REAL";
case R_PREDEFINED_STRING() then "PREDEFINED_STRING";
Expand Down Expand Up @@ -4286,6 +4294,17 @@ algorithm
end matchcontinue;
end isPackageRestriction;

public function isFunctionRestriction "function isFunctionRestriction
checks if restriction is a function or not"
input Restriction inRestriction;
output Boolean outBoolean;
algorithm
outBoolean := matchcontinue (inRestriction)
case (R_FUNCTION(_)) then true;
case (_) then false;
end matchcontinue;
end isFunctionRestriction;

public function subscriptEqual "
Author BZ, 2009-01
Check if two subscripts are equal.
Expand Down Expand Up @@ -5505,10 +5524,11 @@ algorithm
list<String> typeVars;
list<ClassPart> classParts;
list<ElementItem> elts;
case CLASS(name,partialPrefix,finalPrefix,encapsulatedPrefix,R_FUNCTION(),PARTS(typeVars,classParts,_),info)
FunctionRestriction funcRest;
case CLASS(name,partialPrefix,finalPrefix,encapsulatedPrefix,R_FUNCTION(funcRest),PARTS(typeVars,classParts,_),info)
equation
(elts as _::_) = List.fold(listReverse(classParts),getFunctionInterfaceParts,{});
then CLASS(name,partialPrefix,finalPrefix,encapsulatedPrefix,R_FUNCTION(),PARTS(typeVars,PUBLIC(elts)::{},NONE()),info);
then CLASS(name,partialPrefix,finalPrefix,encapsulatedPrefix,R_FUNCTION(funcRest),PARTS(typeVars,PUBLIC(elts)::{},NONE()),info);
end match;
end getFunctionInterface;

Expand Down
30 changes: 17 additions & 13 deletions Compiler/FrontEnd/Ceval.mo
Expand Up @@ -1313,6 +1313,7 @@ algorithm
DAE.Function func;
SCode.Restriction res;
Interactive.SymbolTable syt;
Absyn.FunctionRestriction funcRest;

// try function interpretation
case (cache,env, DAE.CALL(path = funcpath, attr = DAE.CALL_ATTR(builtin = false)), vallst, impl, st, msg)
Expand Down Expand Up @@ -1351,7 +1352,7 @@ algorithm
Debug.fprintln(Flags.DYN_LOAD, "CALL: [func from file] check if is in CF list: " +& Absyn.pathString(funcpath));

(true, funcHandle, buildTime, fOld) = Static.isFunctionInCflist(cflist, funcpath);
Absyn.CLASS(_,_,_,_,Absyn.R_FUNCTION(),_,Absyn.INFO(fileName = fNew)) = Interactive.getPathedClassInProgram(funcpath, p);
Absyn.CLASS(_,_,_,_,Absyn.R_FUNCTION(funcRest),_,Absyn.INFO(fileName = fNew)) = Interactive.getPathedClassInProgram(funcpath, p);
// see if the build time from the class is the same as the build time from the compiled functions list
false = stringEq(fNew,""); // see if the WE have a file or not!
false = Static.needToRebuild(fNew,fOld,buildTime); // we don't need to rebuild!
Expand All @@ -1374,7 +1375,7 @@ algorithm
Debug.fprintln(Flags.DYN_LOAD, "CALL: [func from buffer] check if is in CF list: " +& Absyn.pathString(funcpath));

(true, funcHandle, buildTime, fOld) = Static.isFunctionInCflist(cflist, funcpath);
Absyn.CLASS(_,_,_,_,Absyn.R_FUNCTION(),_,Absyn.INFO(fileName = fNew, buildTimes= Absyn.TIMESTAMP(build,_))) = Interactive.getPathedClassInProgram(funcpath, p);
Absyn.CLASS(_,_,_,_,Absyn.R_FUNCTION(funcRest),_,Absyn.INFO(fileName = fNew, buildTimes= Absyn.TIMESTAMP(build,_))) = Interactive.getPathedClassInProgram(funcpath, p);
// note, this should only work for classes that have no file name!
true = stringEq(fNew,""); // see that we don't have a file!

Expand Down Expand Up @@ -1418,15 +1419,15 @@ algorithm
System.freeLibrary(libHandle, print_debug);
buildTime = System.getCurrentTime();
// update the build time in the class!
Absyn.CLASS(name,ppref,fpref,epref,Absyn.R_FUNCTION(),body,info) = Interactive.getPathedClassInProgram(funcpath, p);
Absyn.CLASS(name,ppref,fpref,epref,Absyn.R_FUNCTION(funcRest),body,info) = Interactive.getPathedClassInProgram(funcpath, p);

info = Absyn.setBuildTimeInInfo(buildTime,info);
ts = Absyn.setTimeStampBuild(ts, buildTime);
w = Interactive.buildWithin(funcpath);

Debug.fprintln(Flags.DYN_LOAD, "Updating build time for function path: " +& Absyn.pathString(funcpath) +& " within: " +& Dump.unparseWithin(0, w) +& "\n");

p = Interactive.updateProgram(Absyn.PROGRAM({Absyn.CLASS(name,ppref,fpref,epref,Absyn.R_FUNCTION(),body,info)},w,ts), p);
p = Interactive.updateProgram(Absyn.PROGRAM({Absyn.CLASS(name,ppref,fpref,epref,Absyn.R_FUNCTION(funcRest),body,info)},w,ts), p);
f = Absyn.getFileNameFromInfo(info);

syt = Interactive.SYMBOLTABLE(
Expand Down Expand Up @@ -1519,9 +1520,11 @@ protected
Option<String> lan;
Option<Absyn.ComponentRef> out;
list<Absyn.Exp> args;
SCode.FunctionRestriction funcRest;
algorithm
(outCache,cdef,env_1) := Lookup.lookupClass(inCache,env, funcpath, false);
SCode.CLASS(name=fid,restriction = SCode.R_EXT_FUNCTION(), classDef=SCode.PARTS(externalDecl=extdecl)) := cdef;
SCode.CLASS(name=fid,restriction = SCode.R_FUNCTION(funcRest), classDef=SCode.PARTS(externalDecl=extdecl)) := cdef;
SCode.FR_EXTERNAL_FUNCTION() := funcRest;
SOME(SCode.EXTERNALDECL(SOME(id),lan,out,args,_)) := extdecl;
isKnownExternalFunc(fid, id);
res := cevalKnownExternalFuncs2(fid, id, vals, msg);
Expand Down Expand Up @@ -1562,20 +1565,21 @@ algorithm
SCode.Mod mod;
Absyn.Exp lib;

// All functions can be evaluated.
case (SCode.CLASS(restriction = SCode.R_FUNCTION())) then ();

// But only some external functions.
case (SCode.CLASS(restriction = SCode.R_EXT_FUNCTION(),
classDef = SCode.PARTS(externalDecl = SOME(SCode.EXTERNALDECL(
funcName = SOME(fid),
annotation_ = SOME(SCode.ANNOTATION(mod)))))))
//only some external functions.
case (SCode.CLASS(restriction = SCode.R_FUNCTION(SCode.FR_EXTERNAL_FUNCTION()),
classDef = SCode.PARTS(externalDecl = SOME(SCode.EXTERNALDECL(
funcName = SOME(fid),
annotation_ = SOME(SCode.ANNOTATION(mod)))))))
equation
SCode.MOD(binding = SOME((lib, _))) = Mod.getUnelabedSubMod(mod, "Library");
true = checkLibraryUsage("Lapack", lib);
isCevaluableFunction2(fid);
then
();

// All other functions can be evaluated.
case (SCode.CLASS(restriction = SCode.R_FUNCTION(_))) then ();

end match;
end isCevaluableFunction;

Expand Down
8 changes: 3 additions & 5 deletions Compiler/FrontEnd/ClassInf.mo
Expand Up @@ -393,9 +393,7 @@ algorithm
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(),p) then FUNCTION(p);
case (SCode.R_EXT_FUNCTION(),p) then FUNCTION(p);
case (SCode.R_OPERATOR_FUNCTION(),p) then FUNCTION(p);
case (SCode.R_FUNCTION(_),p) then FUNCTION(p);
case (SCode.R_OPERATOR(),p) then RECORD(p);
case (SCode.R_ENUMERATION(),p) then ENUMERATION(p);
case (SCode.R_PREDEFINED_INTEGER(),p) then TYPE_INTEGER(p);
Expand Down Expand Up @@ -554,8 +552,8 @@ algorithm
case (PACKAGE(path = p),SCode.R_PACKAGE()) then ();
case (HAS_RESTRICTIONS(path = p,hasEquations=false,hasConstraints=false,hasAlgorithms=false),SCode.R_PACKAGE()) then ();

case (FUNCTION(path = p),SCode.R_FUNCTION()) then ();
case (HAS_RESTRICTIONS(path = p,hasEquations=false,hasConstraints=false),SCode.R_FUNCTION()) then ();
case (FUNCTION(path = p),SCode.R_FUNCTION(_)) then ();
case (HAS_RESTRICTIONS(path = p,hasEquations=false,hasConstraints=false),SCode.R_FUNCTION(_)) then ();
case (META_TUPLE(p),SCode.R_TYPE()) then ();
case (META_LIST(p),SCode.R_TYPE()) then ();
case (META_OPTION(p),SCode.R_TYPE()) then ();
Expand Down
21 changes: 11 additions & 10 deletions Compiler/FrontEnd/Dump.mo
Expand Up @@ -589,14 +589,14 @@ algorithm
case Absyn.R_TYPE() then "type";
case Absyn.R_UNIONTYPE() then "uniontype";
case Absyn.R_PACKAGE() then "package";
case Absyn.R_FUNCTION() then "function";
case Absyn.R_FUNCTION(Absyn.FR_NORMAL_FUNCTION()) then "function";
case Absyn.R_FUNCTION(Absyn.FR_OPERATOR_FUNCTION()) then "operator function";
case Absyn.R_PREDEFINED_INTEGER() then "Integer";
case Absyn.R_PREDEFINED_REAL() then "Real";
case Absyn.R_PREDEFINED_STRING() then "String";
case Absyn.R_PREDEFINED_BOOLEAN() then "Boolean";
case Absyn.R_METARECORD(index=_) then "metarecord";
case Absyn.R_OPERATOR() then "operator";
case Absyn.R_OPERATOR_FUNCTION() then "operator function";
case Absyn.R_OPERATOR_RECORD() then "operator record";
else "*unknown*";
end match;
Expand Down Expand Up @@ -881,7 +881,8 @@ algorithm
case Absyn.R_TYPE() equation Print.printBuf("Absyn.R_TYPE"); then ();
case Absyn.R_UNIONTYPE() equation Print.printBuf("Absyn.R_UNIONTYPE"); then ();
case Absyn.R_PACKAGE() equation Print.printBuf("Absyn.R_PACKAGE"); then ();
case Absyn.R_FUNCTION() equation Print.printBuf("Absyn.R_FUNCTION"); then ();
case Absyn.R_FUNCTION(Absyn.FR_NORMAL_FUNCTION()) equation Print.printBuf("Absyn.R_FUNCTION(Absyn.FR_NORMAL_FUNCTION)"); then ();
case Absyn.R_FUNCTION(Absyn.FR_OPERATOR_FUNCTION()) equation Print.printBuf("Absyn.R_FUNCTION(Absyn.FR_OPERATOR_FUNCTION)"); then ();
case Absyn.R_ENUMERATION() equation Print.printBuf("Absyn.R_ENUMERATION"); then ();
case Absyn.R_PREDEFINED_INTEGER() equation Print.printBuf("Absyn.R_PREDEFINED_INTEGER"); then ();
case Absyn.R_PREDEFINED_REAL() equation Print.printBuf("Absyn.R_PREDEFINED_REAL"); then ();
Expand Down Expand Up @@ -5716,19 +5717,19 @@ algorithm
Print.printBuf("record Absyn.R_PACKAGE end Absyn.R_PACKAGE;");
then ();

case Absyn.R_FUNCTION()
case Absyn.R_FUNCTION(Absyn.FR_NORMAL_FUNCTION())
equation
Print.printBuf("record Absyn.R_FUNCTION end Absyn.R_FUNCTION;");
Print.printBuf("record Absyn.FR_NORMAL_FUNCTION end Absyn.FR_NORMAL_FUNCTION;");
then ();
case Absyn.R_OPERATOR()

case Absyn.R_FUNCTION(Absyn.FR_OPERATOR_FUNCTION())
equation
Print.printBuf("record Absyn.R_OPERATOR end Absyn.R_OPERATOR;");
Print.printBuf("record Absyn.FR_OPERATOR_FUNCTION end Absyn.FR_OPERATOR_FUNCTION;");
then ();

case Absyn.R_OPERATOR_FUNCTION()
case Absyn.R_OPERATOR()
equation
Print.printBuf("record Absyn.R_OPERATOR_FUNCTION end Absyn.R_OPERATOR_FUNCTION;");
Print.printBuf("record Absyn.R_OPERATOR end Absyn.R_OPERATOR;");
then ();

case Absyn.R_ENUMERATION()
Expand Down
6 changes: 3 additions & 3 deletions Compiler/FrontEnd/Env.mo
Expand Up @@ -2456,9 +2456,9 @@ public function restrictionToScopeType
output Option<ScopeType> outType;
algorithm
outType := matchcontinue(inRestriction)
case SCode.R_FUNCTION() then SOME(FUNCTION_SCOPE());
case SCode.R_EXT_FUNCTION() then SOME(FUNCTION_SCOPE());
case SCode.R_OPERATOR_FUNCTION() then SOME(FUNCTION_SCOPE());
case SCode.R_FUNCTION(_) then SOME(FUNCTION_SCOPE());
// case SCode.R_EXT_FUNCTION() then SOME(FUNCTION_SCOPE());
// case SCode.R_OPERATOR_FUNCTION() then SOME(FUNCTION_SCOPE());
case _ then SOME(CLASS_SCOPE());
end matchcontinue;
end restrictionToScopeType;
Expand Down

0 comments on commit b4830e5

Please sign in to comment.