Skip to content
This repository has been archived by the owner on May 18, 2019. It is now read-only.

Commit

Permalink
NFInst improvements.
Browse files Browse the repository at this point in the history
- Handle wildcard crefs in NFInst.instCref.
- Renamed Type.ANY_TYPE to POLYMORPHIC, and added Type.ANY that's type
  compatible with any other type (used for wildcards).
- Fixed scope when instantiating inherited sections.

Belonging to [master]:
  - #2041
  - OpenModelica/OpenModelica-testsuite#789
  • Loading branch information
perost authored and OpenModelica-Hudson committed Nov 21, 2017
1 parent 9ec3abd commit 0790acf
Show file tree
Hide file tree
Showing 8 changed files with 40 additions and 26 deletions.
2 changes: 1 addition & 1 deletion Compiler/NFFrontEnd/NFBuiltin.mo
Expand Up @@ -117,7 +117,7 @@ end Elements;
// modifiers and illegal in other cases).
constant InstNode ANYTYPE_NODE = InstNode.CLASS_NODE("polymorphic",
Elements.ANY, Visibility.PUBLIC,
Pointer.createImmutable(Class.PARTIAL_BUILTIN(Type.ANY_TYPE("unknown"), NFClassTree.EMPTY,
Pointer.createImmutable(Class.PARTIAL_BUILTIN(Type.POLYMORPHIC(""), NFClassTree.EMPTY,
Modifier.NOMOD(), Restriction.TYPE())),
arrayCreate(NFInstNode.NUMBER_OF_CACHES, NFInstNode.CachedData.NO_CACHE()),
InstNode.EMPTY_NODE(), InstNodeType.BUILTIN_CLASS());
Expand Down
2 changes: 1 addition & 1 deletion Compiler/NFFrontEnd/NFClass.mo
Expand Up @@ -355,7 +355,7 @@ uniontype Class
case PARTIAL_BUILTIN() then cls.ty;
case INSTANCED_BUILTIN()
then match cls.ty
case Type.ANY_TYPE("unknown") then Type.ANY_TYPE(InstNode.name(clsNode));
case Type.POLYMORPHIC("") then Type.POLYMORPHIC(InstNode.name(clsNode));
else cls.ty;
end match;
else Type.UNKNOWN();
Expand Down
22 changes: 11 additions & 11 deletions Compiler/NFFrontEnd/NFClassTree.mo
Expand Up @@ -953,6 +953,17 @@ public
end match;
end enumerateComponents2;

function getExtends
input ClassTree tree;
output array<InstNode> exts;
algorithm
exts := match tree
case PARTIAL_TREE() then tree.exts;
case EXPANDED_TREE() then tree.exts;
case INSTANTIATED_TREE() then tree.exts;
end match;
end getExtends;

protected

function instExtendsComps
Expand All @@ -972,17 +983,6 @@ public
end if;
end instExtendsComps;

function getExtends
input ClassTree tree;
output array<InstNode> exts;
algorithm
exts := match tree
case PARTIAL_TREE() then tree.exts;
case EXPANDED_TREE() then tree.exts;
case INSTANTIATED_TREE() then tree.exts;
end match;
end getExtends;

function getDuplicates
input ClassTree tree;
output DuplicateTree.Tree duplicates;
Expand Down
2 changes: 1 addition & 1 deletion Compiler/NFFrontEnd/NFFunction.mo
Expand Up @@ -1048,7 +1048,7 @@ protected
case Type.CLOCK() then true;
case Type.ENUMERATION() then true;
case Type.ENUMERATION_ANY() then true;
case Type.ANY_TYPE() then true;
case Type.POLYMORPHIC() then true;
case Type.ARRAY() then isValidParamType(ty.elementType);
case Type.COMPLEX() then isValidParamState(ty.cls);
end match;
Expand Down
12 changes: 9 additions & 3 deletions Compiler/NFFrontEnd/NFInst.mo
Expand Up @@ -1173,8 +1173,9 @@ algorithm
case Class.EXPANDED_CLASS(elements = cls_tree)
algorithm
// Instantiate expressions in the extends nodes.
sections := ClassTree.foldExtends(cls_tree,
function instExpressions(scope = scope), sections);
for ext in ClassTree.getExtends(cls_tree) loop
sections := instExpressions(ext, ext, sections);
end for;

// Instantiate expressions in the local components.
ClassTree.applyLocalComponents(cls_tree,
Expand Down Expand Up @@ -1463,7 +1464,12 @@ protected
Type ty;
Component comp;
algorithm
(cref, found_scope) := Lookup.lookupComponent(absynCref, scope, info);
(cref, found_scope) := match absynCref
case Absyn.ComponentRef.WILD() then (ComponentRef.WILD(), scope);
case Absyn.ComponentRef.ALLWILD() then (ComponentRef.WILD(), scope);
else Lookup.lookupComponent(absynCref, scope, info);
end match;

cref := instCrefSubscripts(cref, scope, info);

crefExp := match cref
Expand Down
17 changes: 11 additions & 6 deletions Compiler/NFFrontEnd/NFType.mo
Expand Up @@ -40,10 +40,6 @@ public
import Subscript = NFSubscript;
import ComplexType = NFComplexType;

record ANY_TYPE
String b;
end ANY_TYPE;

record INTEGER
end INTEGER;

Expand Down Expand Up @@ -97,6 +93,13 @@ public
Type ty;
end METABOXED;

record POLYMORPHIC
String name;
end POLYMORPHIC;

record ANY
end ANY;

// TODO: Fix constants in uniontypes and use these wherever applicable to
// speed up comparisons using referenceEq.
//constant Type INTEGER_DEFAULT = NFType.INTEGER();
Expand Down Expand Up @@ -406,13 +409,14 @@ public
"(" + stringDelimitList(ty.literals, ", ") + ")";
case Type.ENUMERATION_ANY() then "enumeration(:)";
case Type.CLOCK() then "Clock";
case Type.ANY_TYPE() then "Any";
case Type.ARRAY() then toString(ty.elementType) + "[" + stringDelimitList(List.map(ty.dimensions, Dimension.toString), ", ") + "]";
case Type.TUPLE() then "(" + stringDelimitList(List.map(ty.types, toString), ", ") + ")";
case Type.FUNCTION() then "function( output " + toString(ty.resultType) + " )";
case Type.NORETCALL() then "()";
case Type.UNKNOWN() then "unknown()";
case Type.COMPLEX() then InstNode.name(ty.cls);
case Type.POLYMORPHIC() then "<" + ty.name + ">";
case Type.ANY() then "$ANY$";
else
algorithm
assert(false, getInstanceName() + " got unknown type: " + anyString(ty));
Expand Down Expand Up @@ -454,7 +458,8 @@ public
case Type.COMPLEX()
// TODO: Use proper ClassInf.State here.
then DAE.Type.T_COMPLEX(ClassInf.MODEL(Absyn.IDENT(InstNode.name(ty.cls))), {}, NONE());
case Type.ANY_TYPE() then DAE.T_METAPOLYMORPHIC(ty.b);
case Type.POLYMORPHIC() then DAE.T_METAPOLYMORPHIC(ty.name);
case Type.ANY() then DAE.T_ANYTYPE(NONE());
else
algorithm
assert(false, getInstanceName() + " got unknown type: " + anyString(ty));
Expand Down
7 changes: 5 additions & 2 deletions Compiler/NFFrontEnd/NFTypeCheck.mo
Expand Up @@ -1689,20 +1689,23 @@ algorithm
then (actualType,
if allowUnknown then MatchKind.UNKNOWN_EXPECTED else MatchKind.NOT_COMPATIBLE);

case (_, Type.ANY_TYPE())
case (_, Type.POLYMORPHIC())
algorithm
expression := Expression.BOX(expression);
// matchKind := MatchKind.GENERIC(expectedType.b,actualType);
then
(Type.METABOXED(actualType), MatchKind.GENERIC);

case (Type.ANY_TYPE(), _)
case (Type.POLYMORPHIC(), _)
algorithm
// expression := Expression.UNBOX(expression, Expression.typeOf(expression));
// matchKind := MatchKind.GENERIC(expectedType.b,actualType);
then
(expectedType, MatchKind.GENERIC);

// Expected type is any, any actual type matches.
case (_, Type.ANY()) then (expectedType, MatchKind.EXACT);

// Anything else is not compatible.
else (Type.UNKNOWN(), MatchKind.NOT_COMPATIBLE);
end match;
Expand Down
2 changes: 1 addition & 1 deletion Compiler/NFFrontEnd/NFTyping.mo
Expand Up @@ -1208,7 +1208,7 @@ algorithm
then (cref, Type.UNKNOWN(), Variability.CONTINUOUS);

case ComponentRef.WILD()
then (cref, Type.UNKNOWN(), Variability.CONTINUOUS);
then (cref, Type.ANY(), Variability.CONTINUOUS);

else
algorithm
Expand Down

0 comments on commit 0790acf

Please sign in to comment.