Skip to content

Commit

Permalink
Fixed for new instantiation:
Browse files Browse the repository at this point in the history
- Fixed support for StateSelect.
- Forbid subscripted function calls.
- Added missing listReverse in List.findMap*.


git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@18470 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
perost committed Dec 12, 2013
1 parent 278ccf6 commit 803137e
Show file tree
Hide file tree
Showing 7 changed files with 167 additions and 84 deletions.
3 changes: 3 additions & 0 deletions Compiler/FrontEnd/DAEDump.mo
Original file line number Diff line number Diff line change
Expand Up @@ -2881,6 +2881,9 @@ algorithm
then
name +& dim_str;

case DAE.T_SUBTYPE_BASIC(complexType = ty as DAE.T_SUBTYPE_BASIC(complexType = _))
then unparseType(ty);

case DAE.T_SUBTYPE_BASIC(complexType = bc_tp) then Types.unparseType(bc_tp);
else Types.unparseType(tp);
end matchcontinue;
Expand Down
22 changes: 18 additions & 4 deletions Compiler/FrontEnd/NFBuiltin.mo
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ encapsulated package NFBuiltin
"

public import Absyn;
public import DAE;
public import SCode;

// Default parts of the declarations for builtin elements and types:
Expand Down Expand Up @@ -185,7 +186,7 @@ public constant list<SCode.Element> BUILTIN_REAL_ATTRIBUTES = {

public constant SCode.Element BUILTIN_REAL = SCode.CLASS("Real",
SCode.defaultPrefixes, SCode.NOT_ENCAPSULATED(), SCode.NOT_PARTIAL(), SCode.R_TYPE(),
SCode.PARTS(BUILTIN_REAL_ATTRIBUTES, {}, {}, {}, {}, {}, {}, NONE()),
SCode.PARTS({}, {}, {}, {}, {}, {}, {}, NONE()),
SCode.noComment,Absyn.dummyInfo);


Expand All @@ -199,7 +200,7 @@ public constant list<SCode.Element> BUILTIN_INTEGER_ATTRIBUTES = {

public constant SCode.Element BUILTIN_INTEGER = SCode.CLASS("Integer",
SCode.defaultPrefixes, SCode.NOT_ENCAPSULATED(), SCode.NOT_PARTIAL(), SCode.R_TYPE(),
SCode.PARTS(BUILTIN_INTEGER_ATTRIBUTES, {}, {}, {}, {}, {}, {}, NONE()),
SCode.PARTS({}, {}, {}, {}, {}, {}, {}, NONE()),
SCode.noComment,Absyn.dummyInfo);


Expand All @@ -211,7 +212,7 @@ public constant list<SCode.Element> BUILTIN_BOOLEAN_ATTRIBUTES = {

public constant SCode.Element BUILTIN_BOOLEAN = SCode.CLASS("Boolean",
SCode.defaultPrefixes, SCode.NOT_ENCAPSULATED(), SCode.NOT_PARTIAL(), SCode.R_TYPE(),
SCode.PARTS(BUILTIN_BOOLEAN_ATTRIBUTES, {}, {}, {}, {}, {}, {}, NONE()),
SCode.PARTS({}, {}, {}, {}, {}, {}, {}, NONE()),
SCode.noComment,Absyn.dummyInfo);


Expand All @@ -222,13 +223,26 @@ public constant list<SCode.Element> BUILTIN_STRING_ATTRIBUTES = {

public constant SCode.Element BUILTIN_STRING = SCode.CLASS("String",
SCode.defaultPrefixes, SCode.NOT_ENCAPSULATED(), SCode.NOT_PARTIAL(), SCode.R_TYPE(),
SCode.PARTS(BUILTIN_STRING_ATTRIBUTES, {}, {}, {}, {}, {}, {}, NONE()),
SCode.PARTS({}, {}, {}, {}, {}, {}, {}, NONE()),
SCode.noComment,Absyn.dummyInfo);


public constant SCode.Element BUILTIN_STATESELECT = SCode.CLASS("StateSelect",
SCode.defaultPrefixes, SCode.NOT_ENCAPSULATED(), SCode.NOT_PARTIAL(), SCode.R_TYPE(),
SCode.PARTS({}, {}, {}, {}, {}, {}, {}, NONE()),
SCode.noComment, Absyn.dummyInfo);

// Builtin variable time:
public constant SCode.Element BUILTIN_TIME = SCode.COMPONENT("time", SCode.defaultPrefixes,
SCode.ATTR({}, SCode.POTENTIAL(), SCode.NON_PARALLEL(), SCode.VAR(), Absyn.INPUT()),
Absyn.TPATH(Absyn.IDENT("Real"), NONE()), SCode.NOMOD(), SCode.noComment, NONE(), Absyn.dummyInfo);


public constant DAE.Type BUILTIN_TYPE_STATE_SELECT = DAE.T_ENUMERATION(
NONE(),
Absyn.IDENT("StateSelect"),
{"never", "avoid", "default", "prefer", "always"}, {}, {},
DAE.emptyTypeSource
);

end NFBuiltin;
100 changes: 72 additions & 28 deletions Compiler/FrontEnd/NFInst.mo
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ encapsulated package NFInst
public import Absyn;
public import NFConnect2;
public import DAE;
public import NFBuiltin;
public import NFInstPrefix;
public import NFInstTypes;
public import HashTablePathToFunction;
Expand Down Expand Up @@ -143,8 +144,6 @@ algorithm
(cls, _, _, (constants, functions)) = instClassEntryNoMod(inClassPath, top_cls,
env, NFInstPrefix.makeEmptyPrefix(inClassPath), (constants, functions));

//builtin_el = instBuiltinElements((constants, functions));

//print(NFInstDump.modelStr(name, cls)); print("\n");

/*********************************************************************/
Expand Down Expand Up @@ -313,13 +312,23 @@ algorithm

// A builtin type (only builtin types can be PARTS).
case (_, SCode.CLASS(name = name, restriction = SCode.R_TYPE(),
classDef = SCode.PARTS(elementLst = _)), _, _, _, _, _, globals)
classDef = SCode.PARTS(elementLst = {})), _, _, _, _, _, globals)
equation
(vars, globals) = instBasicTypeAttributes(inClassMod, name, globals);
ty = instBasicType(name, vars);
then
(NFInstTypes.BASIC_TYPE(inTypePath), ty, NFInstTypes.NO_PREFIXES(), globals);

case (_, SCode.CLASS(name = name, restriction = SCode.R_TYPE(),
classDef = SCode.PARTS(elementLst = el)), _, _, _, _, _, globals)
equation
cdef = makeDerivedTypeClassDef(el);
scls = SCode.setElementClassDefinition(cdef, inElement);
(cls, ty, prefs, globals) = instClassEntry_impl(inTypePath, scls,
inEntry, inClassMod, inPrefixes, inEnv, inPrefix, globals);
then
(cls, ty, prefs, globals);

// A class with parts, instantiate all elements in it.
case (_, SCode.CLASS(name = name, restriction = res,
classDef = cdef as SCode.PARTS(elementLst = el), info = info), _,
Expand Down Expand Up @@ -409,6 +418,21 @@ algorithm
end match;
end instClassEntry_impl;

protected function makeDerivedTypeClassDef
input list<SCode.Element> inElements;
output SCode.ClassDef outClassDef;
algorithm
outClassDef := match(inElements)
local
Absyn.Path path;
SCode.Mod mod;

case ({SCode.EXTENDS(baseClassPath = path, modifications = mod)})
then SCode.DERIVED(Absyn.TPATH(path, NONE()), mod, SCode.defaultVarAttr);

end match;
end makeDerivedTypeClassDef;

protected function instClassExtends
input SCode.Element inClassExtends;
input Modifier inMod;
Expand Down Expand Up @@ -612,6 +636,7 @@ algorithm
case ("Integer", _, _) then getBasicTypeAttrTypeInt(inAttributeName);
case ("Boolean", _, _) then getBasicTypeAttrTypeBool(inAttributeName);
case ("String", _, _) then getBasicTypeAttrTypeString(inAttributeName);
case ("StateSelect", _, _) then getBasicTypeAttrTypeStateSelect(inAttributeName);
else
equation
Error.addSourceMessage(Error.MISSING_MODIFIED_ELEMENT,
Expand Down Expand Up @@ -673,6 +698,24 @@ algorithm
end match;
end getBasicTypeAttrTypeString;

protected function getBasicTypeAttrTypeStateSelect
input String inAttributeName;
output DAE.Type outType;
algorithm
outType := match(inAttributeName)
case "quantity" then DAE.T_STRING_DEFAULT;
case "min" then NFBuiltin.BUILTIN_TYPE_STATE_SELECT;
case "max" then NFBuiltin.BUILTIN_TYPE_STATE_SELECT;
case "start" then NFBuiltin.BUILTIN_TYPE_STATE_SELECT;
case "fixed" then DAE.T_BOOL_DEFAULT;
case "never" then NFBuiltin.BUILTIN_TYPE_STATE_SELECT;
case "avoid" then NFBuiltin.BUILTIN_TYPE_STATE_SELECT;
case "default" then NFBuiltin.BUILTIN_TYPE_STATE_SELECT;
case "prefer" then NFBuiltin.BUILTIN_TYPE_STATE_SELECT;
case "always" then NFBuiltin.BUILTIN_TYPE_STATE_SELECT;
end match;
end getBasicTypeAttrTypeStateSelect;

protected function instElementList
input list<SCode.Element> inElements;
input list<Modifier> inExtendsMods;
Expand Down Expand Up @@ -1235,26 +1278,6 @@ algorithm
end match;
end hasSpecialExtends;

//protected function instBuiltinElements
// input Globals inGlobals;
// output Class outElements;
//algorithm
// outElements := matchcontinue(inGlobals)
// local
// Class stateselect_cls;
//
// case (_)
// equation
// (stateselect_cls, _, _, _) = instClassItem(Absyn.IDENT("StateSelect"),
// NFLookup.BUILTIN_STATESELECT, NFInstTypes.NOMOD(),
// NFInstTypes.NO_PREFIXES(), {}, NFInstTypes.EMPTY_PREFIX(NONE()),
// inGlobals);
// then
// stateselect_cls;
//
// end matchcontinue;
//end instBuiltinElements;
//
protected function instBinding
input Binding inBinding;
input Integer inCompDimensions;
Expand Down Expand Up @@ -2187,9 +2210,9 @@ algorithm
SCode.Element elem;

// Builting names should not be prefixed.
case (_, Absyn.IDENT(name_str), _, _, _)
case (_, _, _, _, _)
equation
_ = NFLookup.lookupBuiltinSimpleName(name_str);
(_, _) = NFLookup.lookupBuiltinName(inCrefPath, inEnv);
then
(inCref, inGlobals);

Expand Down Expand Up @@ -2627,10 +2650,10 @@ algorithm

case (_, _, _, _)
equation
path = Absyn.crefToPath(inName);
path = instFunctionName(inName, inInfo);
(entry, env) = NFLookup.lookupFunctionName(path, inEnv, inInfo);
is_builtin = NFEnv.entryHasBuiltinOrigin(entry);
path = instFunctionName(path, is_builtin, inEnv);
path = prefixFunctionName(path, is_builtin, inEnv);
(cls, ty, (consts, functions)) =
instFunctionEntry(path, entry, is_builtin, env, inGlobals);
is_record = Types.isRecord(ty);
Expand All @@ -2650,6 +2673,27 @@ algorithm
end instFunction;

protected function instFunctionName
input Absyn.ComponentRef inName;
input Absyn.Info inInfo;
output Absyn.Path outName;
algorithm
outName := matchcontinue(inName, inInfo)
local
String name;

case (_, _) then Absyn.crefToPath(inName);

else
equation
name = Dump.printComponentRefStr(inName);
Error.addSourceMessage(Error.SUBSCRIPTED_FUNCTION_CALL, {name}, inInfo);
then
fail();

end matchcontinue;
end instFunctionName;

protected function prefixFunctionName
input Absyn.Path inPath;
input Boolean inBuiltin;
input Env inEnv;
Expand All @@ -2659,7 +2703,7 @@ algorithm
case (_, true, _) then inPath; // Don't prefix builtin functions.
else prefixPath(inPath, inEnv);
end match;
end instFunctionName;
end prefixFunctionName;

protected function instFunctionEntry
input Absyn.Path inPath;
Expand Down

0 comments on commit 803137e

Please sign in to comment.