Skip to content

Commit

Permalink
NFInst improvements.
Browse files Browse the repository at this point in the history
- Simplify builtin type handling by storing the actual type in
  Class.PARTIAL_BUILTIN/INSTANCED_BUILTIN instead of the name.
  • Loading branch information
perost authored and OpenModelica-Hudson committed Jan 24, 2017
1 parent fac34e1 commit 507cdb3
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 38 deletions.
5 changes: 3 additions & 2 deletions Compiler/NFFrontEnd/NFClass.mo
Expand Up @@ -37,6 +37,7 @@ import NFInstNode.InstNode;
import NFMod.Modifier;
import NFStatement.Statement;
import SCode.Element;
import Type = NFType;
import Array;
import Error;

Expand Down Expand Up @@ -109,12 +110,12 @@ uniontype Class
end INSTANCED_CLASS;

record PARTIAL_BUILTIN
String name;
Type ty;
Modifier modifier;
end PARTIAL_BUILTIN;

record INSTANCED_BUILTIN
String name;
Type ty;
list<Modifier> attributes;
end INSTANCED_BUILTIN;

Expand Down
2 changes: 0 additions & 2 deletions Compiler/NFFrontEnd/NFFlatten.mo
Expand Up @@ -546,8 +546,6 @@ algorithm

end flattenWhenEquation;



function flattenStatement
input Statement alg;
input output list<DAE.Statement> stmts = {};
Expand Down
7 changes: 4 additions & 3 deletions Compiler/NFFrontEnd/NFInst.mo
Expand Up @@ -52,6 +52,7 @@ import NFMod.Modifier;
import NFMod.ModifierScope;
import NFEquation.Equation;
import NFStatement.Statement;
import Type = NFType;

protected
import Array;
Expand Down Expand Up @@ -717,7 +718,7 @@ protected
list<Modifier> type_mods, inst_type_mods;
Binding binding;
InstNode n, cur_scope, par;
String name;
Type ty;
algorithm
() := match InstNode.getClass(node)
// A normal class.
Expand Down Expand Up @@ -752,7 +753,7 @@ algorithm
// Clone the node, since each component needs a unique type.
node := InstNode.clone(node);
c := InstNode.getClass(node);
Class.PARTIAL_BUILTIN(name = name, modifier = mod) := c;
Class.PARTIAL_BUILTIN(ty = ty, modifier = mod) := c;

// Merge any outer modifiers on the class with the class' own modifier.
type_mod := Modifier.merge(modifier, mod);
Expand Down Expand Up @@ -780,7 +781,7 @@ algorithm
end for;
end if;

c := Class.INSTANCED_BUILTIN(name, inst_type_mods);
c := Class.INSTANCED_BUILTIN(ty, inst_type_mods);
node := InstNode.updateClass(c, node);
then
();
Expand Down
10 changes: 5 additions & 5 deletions Compiler/NFFrontEnd/NFLookup.mo
Expand Up @@ -47,23 +47,23 @@ import NFInstNode.InstNode;
import NFLookupState.LookupState;
import NFMod.Modifier;
import NFPrefix.Prefix;
import NFType;
import Type = NFType;

constant NFInst.InstNode REAL_TYPE = NFInstNode.CLASS_NODE("Real",
NFBuiltin.BUILTIN_REAL,
listArray({NFClass.PARTIAL_BUILTIN("Real", Modifier.NOMOD())}),
listArray({NFClass.PARTIAL_BUILTIN(Type.REAL(), Modifier.NOMOD())}),
NFInstNode.EMPTY_NODE(), NFInstNode.NORMAL_CLASS());
constant NFInst.InstNode INT_TYPE = NFInstNode.CLASS_NODE("Integer",
NFBuiltin.BUILTIN_INTEGER,
listArray({NFClass.PARTIAL_BUILTIN("Integer", Modifier.NOMOD())}),
listArray({NFClass.PARTIAL_BUILTIN(Type.INTEGER(), Modifier.NOMOD())}),
NFInstNode.EMPTY_NODE(), NFInstNode.NORMAL_CLASS());
constant NFInst.InstNode BOOL_TYPE = NFInstNode.CLASS_NODE("Boolean",
NFBuiltin.BUILTIN_BOOLEAN,
listArray({NFClass.PARTIAL_BUILTIN("Boolean", Modifier.NOMOD())}),
listArray({NFClass.PARTIAL_BUILTIN(Type.BOOLEAN(), Modifier.NOMOD())}),
NFInstNode.EMPTY_NODE(), NFInstNode.NORMAL_CLASS());
constant NFInst.InstNode STRING_TYPE = NFInstNode.CLASS_NODE("String",
NFBuiltin.BUILTIN_STRING,
listArray({NFClass.PARTIAL_BUILTIN("String", Modifier.NOMOD())}),
listArray({NFClass.PARTIAL_BUILTIN(Type.STRING(), Modifier.NOMOD())}),
NFInstNode.EMPTY_NODE(), NFInstNode.NORMAL_CLASS());

constant NFInstNode.InstNode BUILTIN_TIME =
Expand Down
28 changes: 2 additions & 26 deletions Compiler/NFFrontEnd/NFTyping.mo
Expand Up @@ -100,11 +100,10 @@ algorithm

case Class.INSTANCED_BUILTIN()
algorithm
ty := makeBuiltinType(cls, scope);
cls.attributes := typeTypeAttributes(cls.attributes, ty, scope);
cls.attributes := typeTypeAttributes(cls.attributes, cls.ty, scope);
classNode := InstNode.updateClass(cls, classNode);
then
ty;
cls.ty;

else
algorithm
Expand Down Expand Up @@ -612,29 +611,6 @@ end typeStatement;
// ty := Type.COMPLEX();
//end makeComplexType;

function makeBuiltinType
input Class classInst;
input InstNode scope;
output Type ty;
algorithm
ty := match classInst
local
String name;

case Class.INSTANCED_BUILTIN(name = name)
then
match name
case "Real" then Type.REAL();
case "Integer" then Type.INTEGER();
case "Boolean" then Type.BOOLEAN();
case "String" then Type.STRING();
else Type.UNKNOWN();
end match;

else Type.UNKNOWN();
end match;
end makeBuiltinType;

function typeTypeAttributes
input output list<Modifier> attributes;
input Type ty;
Expand Down

0 comments on commit 507cdb3

Please sign in to comment.