Skip to content

Commit

Permalink
Remove TypeSource from UT/Code/function pointer
Browse files Browse the repository at this point in the history
  • Loading branch information
sjoelund authored and OpenModelica-Hudson committed Jan 25, 2017
1 parent 3662000 commit d828571
Show file tree
Hide file tree
Showing 12 changed files with 56 additions and 56 deletions.
6 changes: 2 additions & 4 deletions Compiler/FrontEnd/DAE.mo
Expand Up @@ -851,7 +851,7 @@ constant Type T_SOURCEINFO_DEFAULT_METARECORD = T_METARECORD(Absyn.QUALIFIED("So
TYPES_VAR("columnNumberEnd", dummyAttrVar, T_INTEGER_DEFAULT, UNBOUND(), NONE()),
TYPES_VAR("lastModification", dummyAttrVar, T_REAL_DEFAULT, UNBOUND(), NONE())
}, true);
constant Type T_SOURCEINFO_DEFAULT = T_METAUNIONTYPE({Absyn.QUALIFIED("SourceInfo",Absyn.IDENT("SOURCEINFO"))},{},true,EVAL_SINGLETON_KNOWN_TYPE(T_SOURCEINFO_DEFAULT_METARECORD),Absyn.IDENT("SourceInfo")::{});
constant Type T_SOURCEINFO_DEFAULT = T_METAUNIONTYPE({Absyn.QUALIFIED("SourceInfo",Absyn.IDENT("SOURCEINFO"))},{},true,EVAL_SINGLETON_KNOWN_TYPE(T_SOURCEINFO_DEFAULT_METARECORD),Absyn.IDENT("SourceInfo"));

// Arrays of unknown dimension, eg. Real[:]
public constant Type T_ARRAY_REAL_NODIM = T_ARRAY(T_REAL_DEFAULT,{DIM_UNKNOWN()});
Expand Down Expand Up @@ -934,7 +934,6 @@ public uniontype Type "models the different front-end and back-end types"
record T_FUNCTION_REFERENCE_FUNC "MetaModelica Function Reference that is a direct reference to a function"
Boolean builtin;
Type functionType "type of the non-boxptr function";
TypeSource source;
end T_FUNCTION_REFERENCE_FUNC;

record T_TUPLE
Expand All @@ -944,7 +943,6 @@ public uniontype Type "models the different front-end and back-end types"

record T_CODE
CodeType ty;
TypeSource source;
end T_CODE;

record T_ANYTYPE
Expand All @@ -970,7 +968,7 @@ public uniontype Type "models the different front-end and back-end types"
list<Type> typeVars;
Boolean knownSingleton "The runtime system (dynload), does not know if the value is a singleton. But optimizations are safe if this is true.";
EvaluateSingletonType singletonType;
TypeSource source;
Absyn.Path path;
end T_METAUNIONTYPE;

record T_METARECORD "MetaModelica Record, used by Uniontypes. added by simbj"
Expand Down
10 changes: 5 additions & 5 deletions Compiler/FrontEnd/InstUtil.mo
Expand Up @@ -334,11 +334,11 @@ algorithm
path2 = Absyn.stripLast(path2);
"OpenModelica" = Absyn.pathLastIdent(path2);
then Util.assoc(name,{
("Expression", DAE.T_CODE(DAE.C_EXPRESSION(),DAE.emptyTypeSource)),
("ExpressionOrModification", DAE.T_CODE(DAE.C_EXPRESSION_OR_MODIFICATION(),DAE.emptyTypeSource)),
("TypeName", DAE.T_CODE(DAE.C_TYPENAME(),DAE.emptyTypeSource)),
("VariableName", DAE.T_CODE(DAE.C_VARIABLENAME(),DAE.emptyTypeSource)),
("VariableNames", DAE.T_CODE(DAE.C_VARIABLENAMES(),DAE.emptyTypeSource))
("Expression", DAE.T_CODE(DAE.C_EXPRESSION())),
("ExpressionOrModification", DAE.T_CODE(DAE.C_EXPRESSION_OR_MODIFICATION())),
("TypeName", DAE.T_CODE(DAE.C_TYPENAME())),
("VariableName", DAE.T_CODE(DAE.C_VARIABLENAME())),
("VariableNames", DAE.T_CODE(DAE.C_VARIABLENAMES()))
});
case (_,false) then ty;
case (_,true) then Types.makeFunctionPolymorphicReference(ty);
Expand Down
3 changes: 1 addition & 2 deletions Compiler/FrontEnd/MetaUtil.mo
Expand Up @@ -317,9 +317,8 @@ algorithm
singletonType := DAE.NOT_SINGLETON();
end if;
typeVarsTypes := list(DAE.T_METAPOLYMORPHIC(tv) for tv in typeVars);
ts := Types.mkTypeSource(SOME(p));
then
SOME(DAE.T_METAUNIONTYPE(paths,typeVarsTypes,b,singletonType,ts));
SOME(DAE.T_METAUNIONTYPE(paths,typeVarsTypes,b,singletonType,p));

else NONE();
end match;
Expand Down
2 changes: 1 addition & 1 deletion Compiler/FrontEnd/Patternm.mo
Expand Up @@ -326,7 +326,7 @@ algorithm
(cache,pattern) = elabPatternCall(cache,env,Absyn.crefToPath(fcr),fargs,utPath,info,lhs);
then (cache,pattern);

case (cache,_,lhs as Absyn.CALL(fcr,fargs),DAE.T_METAUNIONTYPE(source = {utPath}),_,_)
case (cache,_,lhs as Absyn.CALL(fcr,fargs),DAE.T_METAUNIONTYPE(path = utPath),_,_)
equation
(cache,pattern) = elabPatternCall(cache,env,Absyn.crefToPath(fcr),fargs,utPath,info,lhs);
then (cache,pattern);
Expand Down
8 changes: 4 additions & 4 deletions Compiler/FrontEnd/Static.mo
Expand Up @@ -2126,10 +2126,10 @@ protected function elabCodeType
algorithm
outType := match inCode
case Absyn.C_TYPENAME()
then DAE.T_CODE(DAE.C_TYPENAME(),DAE.emptyTypeSource);
then DAE.T_CODE(DAE.C_TYPENAME());

case Absyn.C_VARIABLENAME()
then DAE.T_CODE(DAE.C_VARIABLENAME(),DAE.emptyTypeSource);
then DAE.T_CODE(DAE.C_VARIABLENAME());

case Absyn.C_EQUATIONSECTION()
then DAE.T_COMPLEX(ClassInf.UNKNOWN(Absyn.IDENT("EquationSection")),{},NONE(),DAE.emptyTypeSource);
Expand Down Expand Up @@ -10221,7 +10221,7 @@ algorithm
InstTypes.PolymorphicBindings polymorphicBindings;
String s1,s2,s3,s4,s5;

case (cache, env, e, DAE.FUNCARG(name=id,ty = vt as DAE.T_CODE(ct,_),par=pr), _, slots, _, true, _, _, polymorphicBindings,_,pre,_,_,_)
case (cache, env, e, DAE.FUNCARG(name=id,ty = vt as DAE.T_CODE(ct),par=pr), _, slots, _, true, _, _, polymorphicBindings,_,pre,_,_,_)
equation
e_1 = elabCodeExp(e,cache,env,ct,st,info);
slots_1 = fillSlot(DAE.FUNCARG(id,vt,DAE.C_VAR(),pr,NONE()), e_1, {}, slots,pre,info);
Expand Down Expand Up @@ -10735,7 +10735,7 @@ algorithm
t := Types.makeFunctionPolymorphicReference(t);
c := Absyn.pathToCref(fpath);
expCref := ComponentReference.toExpCref(c);
exp := Expression.makeCrefExp(expCref,DAE.T_FUNCTION_REFERENCE_FUNC(isBuiltinFnOrInlineBuiltin,origt,{fpath}));
exp := Expression.makeCrefExp(expCref,DAE.T_FUNCTION_REFERENCE_FUNC(isBuiltinFnOrInlineBuiltin,origt));
// This is not done by lookup - only elabCall. So we should do it here.
(cache,Util.SUCCESS()) := instantiateDaeFunction(cache,env,path,isBuiltinFn,NONE(),true);
then
Expand Down
65 changes: 32 additions & 33 deletions Compiler/FrontEnd/Types.mo
Expand Up @@ -1204,16 +1204,16 @@ algorithm
case Values.NORETCALL() then DAE.T_NORETCALL_DEFAULT;

case Values.CODE(A=Absyn.C_TYPENAME())
then DAE.T_CODE(DAE.C_TYPENAME(), {});
then DAE.T_CODE(DAE.C_TYPENAME());

case Values.CODE(A=Absyn.C_VARIABLENAME())
then DAE.T_CODE(DAE.C_VARIABLENAME(), {});
then DAE.T_CODE(DAE.C_VARIABLENAME());

case Values.CODE(A=Absyn.C_EXPRESSION())
then DAE.T_CODE(DAE.C_EXPRESSION(), {});
then DAE.T_CODE(DAE.C_EXPRESSION());

case Values.CODE(A=Absyn.C_MODIFICATION())
then DAE.T_CODE(DAE.C_MODIFICATION(), {});
then DAE.T_CODE(DAE.C_MODIFICATION());

case (v)
equation
Expand Down Expand Up @@ -1589,19 +1589,19 @@ algorithm
case (DAE.T_METARECORD(path=p1),DAE.T_METARECORD(path=p2))
then Absyn.pathEqual(p1,p2);

case (DAE.T_METAUNIONTYPE(source = {p1}),DAE.T_METARECORD(utPath=p2))
case (DAE.T_METAUNIONTYPE(path = p1),DAE.T_METARECORD(utPath=p2))
then if Absyn.pathEqual(p1,p2) then subtypeTypelist(inType1.typeVars,inType2.typeVars,requireRecordNamesEqual) else false;

// If the record is the only one in the uniontype, of course their types match
case (DAE.T_METARECORD(knownSingleton=b1,utPath = p1),DAE.T_METAUNIONTYPE(knownSingleton=b2,source={p2}))
case (DAE.T_METARECORD(knownSingleton=b1,utPath = p1),DAE.T_METAUNIONTYPE(knownSingleton=b2,path=p2))
then if Absyn.pathEqual(p1,p2) and (b1 or b2) /*Values.mo loses knownSingleton information */ then subtypeTypelist(inType1.typeVars,inType2.typeVars,requireRecordNamesEqual) else false;

// <uniontype> = <uniontype>
case (DAE.T_METAUNIONTYPE(source = {p1}), DAE.T_METAUNIONTYPE(source = {p2}))
case (DAE.T_METAUNIONTYPE(path = p1), DAE.T_METAUNIONTYPE(path = p2))
then if Absyn.pathEqual(p1,p2) then subtypeTypelist(inType1.typeVars,inType2.typeVars,requireRecordNamesEqual) else false;
case (DAE.T_METAUNIONTYPE(source = {p1}), DAE.T_COMPLEX(complexClassType=ClassInf.META_UNIONTYPE(_), source = {p2}))
case (DAE.T_METAUNIONTYPE(path = p1), DAE.T_COMPLEX(complexClassType=ClassInf.META_UNIONTYPE(_), source = {p2}))
then Absyn.pathEqual(p1,p2); // TODO: Remove?
case(DAE.T_COMPLEX(complexClassType=ClassInf.META_UNIONTYPE(_), source = {p2}), DAE.T_METAUNIONTYPE(source = {p1}))
case(DAE.T_COMPLEX(complexClassType=ClassInf.META_UNIONTYPE(_), source = {p2}), DAE.T_METAUNIONTYPE(path = p1))
then Absyn.pathEqual(p1,p2); // TODO: Remove?

case (DAE.T_CODE(ty = c1),DAE.T_CODE(ty = c2)) then valueEq(c1,c2);
Expand Down Expand Up @@ -2281,9 +2281,9 @@ algorithm
res;

// MetaModelica uniontype
case (DAE.T_METAUNIONTYPE(source = {p}))
case DAE.T_METAUNIONTYPE()
equation
res = Absyn.pathStringNoQual(p);
res = Absyn.pathStringNoQual(inType.path);
then if listEmpty(inType.typeVars) then res else (res+"<"+stringDelimitList(list(unparseType(tv) for tv in inType.typeVars), ",")+">");

// MetaModelica uniontype (but we know which record in the UT it is)
Expand All @@ -2296,9 +2296,9 @@ algorithm
res = stringAppendList({"metarecord ",str,"\n",vstr,"end ", str, ";"});
then res;
*/
case DAE.T_METARECORD(path=p)
case DAE.T_METARECORD()
equation
res = Absyn.pathStringNoQual(p);
res = Absyn.pathStringNoQual(inType.path);
then if listEmpty(inType.typeVars) then res else (res+"<"+stringDelimitList(list(unparseType(tv) for tv in inType.typeVars), ",")+">");

// MetaModelica boxed type
Expand Down Expand Up @@ -2567,18 +2567,17 @@ algorithm
str;
case (t as DAE.T_METAUNIONTYPE())
equation
{path} = t.source;
s1 = Absyn.pathStringNoQual(path);
s1 = Absyn.pathStringNoQual(t.path);
str = "#" + s1 + "#";
then
str;

// Code
case (DAE.T_CODE(DAE.C_EXPRESSION(),_)) then "$Code(Expression)";
case (DAE.T_CODE(DAE.C_EXPRESSION_OR_MODIFICATION(),_)) then "$Code(ExpressionOrModification)";
case (DAE.T_CODE(DAE.C_TYPENAME(),_)) then "$Code(TypeName)";
case (DAE.T_CODE(DAE.C_VARIABLENAME(),_)) then "$Code(VariableName)";
case (DAE.T_CODE(DAE.C_VARIABLENAMES(),_)) then "$Code(VariableName[:])";
case (DAE.T_CODE(DAE.C_EXPRESSION())) then "$Code(Expression)";
case (DAE.T_CODE(DAE.C_EXPRESSION_OR_MODIFICATION())) then "$Code(ExpressionOrModification)";
case (DAE.T_CODE(DAE.C_TYPENAME())) then "$Code(TypeName)";
case (DAE.T_CODE(DAE.C_VARIABLENAME())) then "$Code(VariableName)";
case (DAE.T_CODE(DAE.C_VARIABLENAMES())) then "$Code(VariableName[:])";

// All the other ones we don't handle
else
Expand Down Expand Up @@ -5750,15 +5749,15 @@ algorithm
tp = superType(t1,t2);
then DAE.T_METAARRAY(tp);

case (t1 as DAE.T_METAUNIONTYPE(source = {path1}), DAE.T_METARECORD(utPath=path2))
case (t1 as DAE.T_METAUNIONTYPE(path = path1), DAE.T_METARECORD(utPath=path2))
equation
true = Absyn.pathEqual(path1,path2);
then t1;

case (DAE.T_METARECORD(knownSingleton=false,utPath = path1), DAE.T_METARECORD(knownSingleton=false,utPath=path2))
equation
true = Absyn.pathEqual(path1,path2);
then DAE.T_METAUNIONTYPE({},inType1.typeVars,false,DAE.NOT_SINGLETON(),{path1});
then DAE.T_METAUNIONTYPE({},inType1.typeVars,false,DAE.NOT_SINGLETON(),path1);

case (DAE.T_INTEGER(),DAE.T_REAL())
then DAE.T_REAL_DEFAULT;
Expand Down Expand Up @@ -6068,7 +6067,7 @@ algorithm
equation
tys = List.map3(tys, fixPolymorphicRestype2, prefix, bindings, info);
tys = List.map(tys, boxIfUnboxedType);
then DAE.T_METAUNIONTYPE(ty.paths,tys,ty.knownSingleton,ty.singletonType,ty.source);
then DAE.T_METAUNIONTYPE(ty.paths,tys,ty.knownSingleton,ty.singletonType,ty.path);

case (DAE.T_METATUPLE(types = tys),_,_,_)
equation
Expand Down Expand Up @@ -6790,9 +6789,9 @@ algorithm
case (DAE.T_TUPLE(types = tList1),DAE.T_TUPLE(types = tList2))
then subtypePolymorphicList(tList1,tList2,envPath,inBindings);

case (DAE.T_METAUNIONTYPE(source = {path1}),DAE.T_METAUNIONTYPE(source = {path2}))
case (DAE.T_METAUNIONTYPE(),DAE.T_METAUNIONTYPE())
equation
true = Absyn.pathEqual(path1,path2);
true = Absyn.pathEqual(actual.path, expected.path);
then subtypePolymorphicList(actual.typeVars, expected.typeVars, envPath, inBindings);

case (DAE.T_COMPLEX(complexClassType = ClassInf.EXTERNAL_OBJ(path1)),DAE.T_COMPLEX(complexClassType = ClassInf.EXTERNAL_OBJ(path2)))
Expand Down Expand Up @@ -8055,7 +8054,7 @@ algorithm
local
Boolean b;
Absyn.Path p;
case DAE.T_METARECORD(utPath=p,knownSingleton=b) then DAE.T_METAUNIONTYPE({},inTy.typeVars,b,if b then DAE.EVAL_SINGLETON_KNOWN_TYPE(inTy) else DAE.NOT_SINGLETON(),{p});
case DAE.T_METARECORD(utPath=p,knownSingleton=b) then DAE.T_METAUNIONTYPE({},inTy.typeVars,b,if b then DAE.EVAL_SINGLETON_KNOWN_TYPE(inTy) else DAE.NOT_SINGLETON(),p);
else inTy;
end match;
end getUniontypeIfMetarecord;
Expand All @@ -8074,7 +8073,7 @@ protected function getUniontypeIfMetarecordTraverse
output Integer odummy = dummy;
algorithm
oty := match ty
case DAE.T_METARECORD() then DAE.T_METAUNIONTYPE({},ty.typeVars,ty.knownSingleton,if ty.knownSingleton then DAE.EVAL_SINGLETON_KNOWN_TYPE(ty) else DAE.NOT_SINGLETON(),{ty.utPath});
case DAE.T_METARECORD() then DAE.T_METAUNIONTYPE({},ty.typeVars,ty.knownSingleton,if ty.knownSingleton then DAE.EVAL_SINGLETON_KNOWN_TYPE(ty) else DAE.NOT_SINGLETON(),ty.utPath);
else ty;
end match;
end getUniontypeIfMetarecordTraverse;
Expand Down Expand Up @@ -8482,9 +8481,9 @@ algorithm
outCompatible := inType1.name == name;
then inType1;

case DAE.T_METAUNIONTYPE(source = {p1})
case DAE.T_METAUNIONTYPE(path = p1)
algorithm
DAE.T_METAUNIONTYPE(source = {p2}) := inType2;
DAE.T_METAUNIONTYPE(path = p2) := inType2;
outCompatible := Absyn.pathEqual(p1, p2);
then inType1;

Expand Down Expand Up @@ -8602,15 +8601,15 @@ algorithm
// instead of UNIONTYPE(Absyn.Path), but e.g. a function returning an
// Absyn.PATH has the type UNIONTYPE(Absyn.PATH). So we'll just pretend that
// metarecords actually have uniontype type.
case (DAE.T_METARECORD(), DAE.T_METAUNIONTYPE(source = {path}))
case (DAE.T_METARECORD(), DAE.T_METAUNIONTYPE())
algorithm
outCompatible := Absyn.pathEqual(ty1.utPath, path);
outCompatible := Absyn.pathEqual(ty1.utPath, ty2.path);
then
ty2;

case (DAE.T_METAUNIONTYPE(source = {path}), DAE.T_METARECORD())
case (DAE.T_METAUNIONTYPE(), DAE.T_METARECORD())
algorithm
outCompatible := Absyn.pathEqual(path, ty2.utPath);
outCompatible := Absyn.pathEqual(ty1.path, ty2.utPath);
then
ty1;

Expand Down
4 changes: 2 additions & 2 deletions Compiler/Template/CodegenCppCommon.tpl
Expand Up @@ -345,8 +345,8 @@ template daeExpCrefRhs(Exp exp, Context context, Text &preExp, Text &varDecls, S
'<%daeExpCrefRhs2(exp, context, &preExp, &varDecls,simCode , &extraFuncs , &extraFuncsDecl, extraFuncsNamespace, stateDerVectorName, useFlatArrayNotation)%>'
else
daeExpRecordCrefRhs(t, cr, context, &preExp, &varDecls, simCode, &extraFuncs, &extraFuncsDecl, extraFuncsNamespace, stateDerVectorName, useFlatArrayNotation)
case CREF(ty = T_FUNCTION_REFERENCE_FUNC(functionType=t, source={name})) then
functionClosure(underscorePath(name), "", t, t, context, &extraFuncsDecl)
case CREF(ty = T_FUNCTION_REFERENCE_FUNC(functionType=t)) then
functionClosure(underscorePath(crefToPathIgnoreSubs(componentRef)), "", t, t, context, &extraFuncsDecl)
case CREF(componentRef = cr, ty = T_FUNCTION_REFERENCE_VAR(__)) then
crefStr(cr)
else
Expand Down
2 changes: 1 addition & 1 deletion Compiler/Template/DAEDumpTV.mo
Expand Up @@ -1028,7 +1028,7 @@ package DAE
record T_METAUNIONTYPE "MetaModelica Uniontype"
list<Absyn.Path> paths;
Boolean knownSingleton "The runtime system (dynload), does not know if the value is a singleton. But optimizations are safe if this is true.";
TypeSource source;
Absyn.Path path;
end T_METAUNIONTYPE;

record T_METARECORD "MetaModelica Record, used by Uniontypes. added by simbj"
Expand Down
2 changes: 1 addition & 1 deletion Compiler/Template/DAEDumpTpl.tpl
Expand Up @@ -314,7 +314,7 @@ template dumpType(Type ty, Text &attributes)
case T_METALIST(__) then 'list<<%dumpType(ty, attributes)%>>'
case T_METAARRAY(__) then 'array<<%dumpType(ty, attributes)%>>'
case T_METAPOLYMORPHIC(__) then 'polymorphic<<%name%>>'
case T_METAUNIONTYPE(source = {p}) then AbsynDumpTpl.dumpPathNoQual(p)
case T_METAUNIONTYPE(__) then AbsynDumpTpl.dumpPathNoQual(path)
case T_METARECORD(__) then AbsynDumpTpl.dumpPathNoQual(path)
case T_METABOXED(__) then '#<%dumpType(ty, attributes)%>'
case T_METAOPTION(ty = DAE.T_UNKNOWN(__)) then 'Option<Any>'
Expand Down
2 changes: 1 addition & 1 deletion Compiler/Template/ExpressionDumpTV.mo
Expand Up @@ -770,7 +770,7 @@ package DAE
record T_METAUNIONTYPE
list<Absyn.Path> paths;
Boolean knownSingleton;
TypeSource source;
Absyn.Path path;
end T_METAUNIONTYPE;

record T_METARECORD
Expand Down
2 changes: 1 addition & 1 deletion Compiler/Template/ExpressionDumpTpl.tpl
Expand Up @@ -394,7 +394,7 @@ match ty
case T_METAOPTION(__) then
let ty_str = dumpType(ty)
'Option<<%ty_str%>>'
case T_METAUNIONTYPE(source = {p}) then AbsynDumpTpl.dumpPath(p)
case T_METAUNIONTYPE(__) then AbsynDumpTpl.dumpPath(path)
case T_METARECORD(__) then AbsynDumpTpl.dumpPath(path)
case T_METAARRAY(__) then
let ty_str = dumpType(ty)
Expand Down
6 changes: 5 additions & 1 deletion Compiler/Template/SimCodeTV.mo
Expand Up @@ -2044,7 +2044,6 @@ package DAE
record T_FUNCTION_REFERENCE_FUNC "MetaModelica Function Reference that is a direct reference to a function"
Boolean builtin;
Type functionType "type of the non-boxptr function";
TypeSource source;
end T_FUNCTION_REFERENCE_FUNC;

record T_TUPLE
Expand Down Expand Up @@ -3129,6 +3128,11 @@ package ComponentReference
output DAE.ComponentRef outCrefIdent;
end makeUntypedCrefIdent;

function crefToPathIgnoreSubs
input DAE.ComponentRef inComponentRef;
output Absyn.Path outPath;
end crefToPathIgnoreSubs;

end ComponentReference;

package Expression
Expand Down

0 comments on commit d828571

Please sign in to comment.