Skip to content

Commit

Permalink
- Fix bootstrapping (seriously, we needed this feature? so much work...)
Browse files Browse the repository at this point in the history
  + Now we support codegenration for if-expressions returning tuples (comes from match-expression optimizations)
- Enabled SusanTest.mos full test since tail-recursion makes it run fine
- T_TUPLE is no longer simplified into a MetaModelica type
- We can now handle code-generation for tuple-expressions (creates an anonymous record)


git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@12991 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
sjoelund committed Sep 20, 2012
1 parent 2781393 commit a702cff
Show file tree
Hide file tree
Showing 13 changed files with 97 additions and 365 deletions.
9 changes: 5 additions & 4 deletions Compiler/BackEnd/BackendDAEUtil.mo
Expand Up @@ -84,6 +84,7 @@ protected import Matching;
protected import OnRelaxation;
protected import SCode;
protected import System;
protected import Types;
protected import Util;
protected import Values;

Expand Down Expand Up @@ -190,8 +191,8 @@ algorithm
eqnstr = BackendDump.equationStr(eqn);
t1 = Expression.typeof(e1);
t2 = Expression.typeof(e2);
t1str = ExpressionDump.typeString(t1);
t2str = ExpressionDump.typeString(t2);
t1str = Types.unparseType(t1);
t2str = Types.unparseType(t2);
tstr = stringAppendList({t1str," != ", t2str});
Error.addSourceMessage(Error.EQUATION_TYPE_MISMATCH_ERROR, {eqnstr,tstr}, DAEUtil.getElementSourceFileInfo(source));
then ();
Expand All @@ -200,8 +201,8 @@ algorithm
eqnstr = BackendDump.equationStr(eqn);
t1 = Expression.typeof(e1);
t2 = ComponentReference.crefLastType(cr);
t1str = ExpressionDump.typeString(t1);
t2str = ExpressionDump.typeString(t2);
t1str = Types.unparseType(t1);
t2str = Types.unparseType(t2);
tstr = stringAppendList({t1str," != ", t2str});
Error.addSourceMessage(Error.EQUATION_TYPE_MISMATCH_ERROR, {eqnstr,tstr}, DAEUtil.getElementSourceFileInfo(source));
then ();
Expand Down
3 changes: 2 additions & 1 deletion Compiler/BackEnd/XMLDump.mo
Expand Up @@ -98,6 +98,7 @@ protected import ExpressionDump;
protected import List;
protected import Print;
protected import Util;
protected import Types;
protected import DAEDump;
protected import ValuesUtil;
protected import ClassInf;
Expand Down Expand Up @@ -1811,7 +1812,7 @@ algorithm
then ();
case (DAE.CAST(ty = tp,exp = e))
equation
str = ExpressionDump.typeString(tp);
str = Types.unparseType(tp);
dumpStrOpenTag(MathMLApply);
dumpStrOpenTag(MathMLOperator);
Print.printBuf("(");
Expand Down
7 changes: 4 additions & 3 deletions Compiler/FrontEnd/ComponentReference.mo
Expand Up @@ -56,6 +56,7 @@ protected import Global;
protected import List;
protected import Print;
protected import System;
protected import Types;
protected import Util;

// do not make this public. instead use the function below.
Expand Down Expand Up @@ -626,7 +627,7 @@ algorithm
str = s +& Util.if_(stringLength(str_1) > 0, "["+& str_1 +& "}" , "");
// this printing way will be useful when adressin the 'crefEqual' bug.
// str = ComponentReference.printComponentRef2Str(s, subs);
str2 = ExpressionDump.typeString(ty);
str2 = Types.unparseType(ty);
str = stringAppendList({str," [",str2,"]"});
then
str;
Expand All @@ -635,7 +636,7 @@ algorithm
equation
true = Config.modelicaOutput();
str = printComponentRef2Str(s, subs);
str2 = ExpressionDump.typeString(ty);
str2 = Types.unparseType(ty);
strrest = debugPrintComponentRefTypeStr(cr);
str = stringAppendList({str," [",str2,"] ", "__", strrest});
then
Expand All @@ -645,7 +646,7 @@ algorithm
equation
false = Config.modelicaOutput();
str = printComponentRef2Str(s, subs);
str2 = ExpressionDump.typeString(ty);
str2 = Types.unparseType(ty);
strrest = debugPrintComponentRefTypeStr(cr);
str = stringAppendList({str," [",str2,"] ", ".", strrest});
then
Expand Down
8 changes: 4 additions & 4 deletions Compiler/FrontEnd/Expression.mo
Expand Up @@ -1776,7 +1776,7 @@ algorithm
equation
tys = List.map(exps, typeof);
then
DAE.T_METATYPE(DAE.T_TUPLE(tys, DAE.emptyTypeSource), DAE.emptyTypeSource) ;
DAE.T_TUPLE(tys, DAE.emptyTypeSource);
case (DAE.META_OPTION(_))then DAE.T_METATYPE(DAE.T_NONE_DEFAULT, DAE.emptyTypeSource);
case (DAE.METARECORDCALL(path=p, index = i))
equation
Expand Down Expand Up @@ -2495,9 +2495,9 @@ algorithm
tExisting = ComponentReference.crefLastType(cref);
failure(equality(tGiven = tExisting)); // false = valueEq(tGiven, tExisting);
Debug.traceln("Warning: Expression.makeCrefExp: given type DAE.CREF.ty: " +&
ExpressionDump.typeString(tGiven) +&
Types.unparseType(tGiven) +&
" is different from existing DAE.CREF.componentRef.ty: " +&
ExpressionDump.typeString(tExisting));
Types.unparseType(tExisting));
e = DAE.CREF(cref, tGiven);
then
e;
Expand Down Expand Up @@ -6075,7 +6075,7 @@ algorithm
equation
//print(" verify subvars: " +& s1 +& " and " +& s2 +& " to go: " +& intString(listLength(vars1)) +& " , " +& intString(listLength(vars2)) +& "\n");
true = stringEq(s1,s2);
//print(" types: " +& ExpressionDump.typeString(t1) +& " and " +& ExpressionDump.typeString(t2) +& "\n");
//print(" types: " +& Types.unparseType(t1) +& " and " +& Types.unparseType(t2) +& "\n");
true = equalTypes(t1,t2);
//print(s1 +& " and " +& s2 +& " EQUAL \n\n");
then
Expand Down
116 changes: 18 additions & 98 deletions Compiler/FrontEnd/ExpressionDump.mo
Expand Up @@ -98,64 +98,6 @@ algorithm
end match;
end subscriptString;

public function typeString "function typeString
Converts a type into a String"
input Type inType;
output String outString;
algorithm
outString := matchcontinue (inType)
local
list<Ident> ss;
Type t;
DAE.Dimensions dims;
String s1,ts,res,s;
list<Var> vars;
ClassInf.State ci;

case DAE.T_INTEGER(varLst = _) then "T_INT";
case DAE.T_REAL(varLst = _) then "T_REAL";
case DAE.T_BOOL(varLst = _) then "T_BOOL";
case DAE.T_STRING(varLst = _) then "T_STRING";
case DAE.T_ENUMERATION(path = _) then "T_ENUMERATION";
case DAE.T_UNKNOWN(source = _) then "T_UNKNOWN";
case DAE.T_ANYTYPE(source = _) then "T_ANYTYPE";

case (DAE.T_ARRAY(ty = t,dims = dims))
equation
ss = List.map(dims, dimensionString);
s1 = Util.stringDelimitListNonEmptyElts(ss, ", ");
ts = typeString(t);
res = stringAppendList({"/tp:",ts,"[",s1,"]/"});
then
res;

case(DAE.T_COMPLEX(varLst=vars,complexClassType=ci))
equation
s = "DAE.T_COMPLEX(" +& typeVarsStr(vars) +& "):" +& ClassInf.printStateStr(ci);
then s;

case(DAE.T_SUBTYPE_BASIC(varLst=vars,complexClassType=ci, complexType = t))
equation
s = "DAE.T_SUBTYPE_BASIC(" +& typeVarsStr(vars) +& "):" +& ClassInf.printStateStr(ci) +&
" extending basic type: " +& typeString(t);
then s;

case (DAE.T_METATYPE(ty = _)) then "T_METATYPE";
case (DAE.T_METABOXED(ty = _)) then "T_METABOXED";
case (DAE.T_NORETCALL(source = _)) then "T_NORETCALL";
case (DAE.T_FUNCTION_REFERENCE_VAR(functionType = _)) then "T_FUNCTION_REFERENCE_VAR";
case (DAE.T_FUNCTION_REFERENCE_FUNC(builtin=_)) then "T_FUNCTION_REFERENCE_FUNC";

else
equation
ts = Types.printTypeStr(inType);
s = "ExpressionDump.typeString failed on type: " +& ts;
Error.addMessage(Error.INTERNAL_ERROR,{s});
s = "#" +& s +& "#";
then s;
end matchcontinue;
end typeString;

public function binopSymbol "
function: binopSymbol
Return a string representation of the Operator."
Expand Down Expand Up @@ -258,49 +200,49 @@ algorithm

case (DAE.ADD(ty = t))
equation
ts = typeString(t);
ts = Types.unparseType(t);
s = stringAppendList({" +<", ts, "> "});
then
s;

case (DAE.SUB(ty = t))
equation
ts = typeString(t);
ts = Types.unparseType(t);
s = stringAppendList({" -<", ts, "> "});
then
s;

case (DAE.MUL(ty = t))
equation
ts = typeString(t);
ts = Types.unparseType(t);
s = stringAppendList({" *<", ts, "> "});
then
s;

case (DAE.DIV(ty = t))
equation
ts = typeString(t);
ts = Types.unparseType(t);
s = stringAppendList({" /<", ts, "> "});
then
s;

case (DAE.POW(ty = t)) then " ^ ";
case (DAE.ADD_ARR(ty = t))
equation
ts = typeString(t);
ts = Types.unparseType(t);
s = stringAppendList({" +<ADD_ARR><", ts, "> "});
then
s;
case (DAE.SUB_ARR(ty = t))
equation
ts = typeString(t);
ts = Types.unparseType(t);
s = stringAppendList({" -<SUB_ARR><", ts, "> "});
then
s;
case (DAE.MUL_ARR(ty = _)) then " *<MUL_ARRAY> ";
case (DAE.DIV_ARR(ty = t))
equation
ts = typeString(t);
ts = Types.unparseType(t);
s = stringAppendList({" /<DIV_ARR><", ts, "> "});
then
s;
Expand Down Expand Up @@ -729,7 +671,7 @@ algorithm

case (DAE.ARRAY(array = es,ty=tp), _, _, _)
equation
// s3 = typeString(tp); // adrpo: not used!
// s3 = Types.unparseType(tp); // adrpo: not used!
s = stringDelimitList(
List.map3(es, printExp2Str, stringDelimiter, opcreffunc, opcallfunc), ",");
s = stringAppendList({"{", s, "}"});
Expand All @@ -746,7 +688,7 @@ algorithm

case (DAE.MATRIX(matrix = lstes,ty=tp), _, _, _)
equation
// s3 = typeString(tp); // adrpo: not used!
// s3 = Types.unparseType(tp); // adrpo: not used!
s = stringDelimitList(List.map1(lstes, printRowStr, stringDelimiter), "},{");
s = stringAppendList({"{{",s,"}}"});
then
Expand Down Expand Up @@ -790,7 +732,7 @@ algorithm

case (DAE.CAST(ty = tp,exp = e), _, _, _)
equation
str = typeString(tp);
str = Types.unparseType(tp);
s = printExp2Str(e, stringDelimiter, opcreffunc, opcallfunc);
res = stringAppendList({"DAE.CAST(",str,", ",s,")"});
then
Expand Down Expand Up @@ -900,7 +842,7 @@ algorithm
case (DAE.SHARED_LITERAL(index=i,ty=et), _, _, _)
equation
s1 = intString(i);
s2 = typeString(et);
s2 = Types.unparseType(et);
s = stringAppendList({"#SHARED_LITERAL_",s1," (",s2,")#"});
then s;

Expand Down Expand Up @@ -1243,7 +1185,7 @@ algorithm

case (DAE.CAST(ty = ty,exp = e))
equation
tystr = typeString(ty);
tystr = Types.unparseType(ty);
ct = dumpExpGraphviz(e);
then
Graphviz.LNODE("CAST",{tystr},{},{ct});
Expand Down Expand Up @@ -1354,7 +1296,7 @@ algorithm
equation
gen_str = genStringNTime(" |", level);
s = /*ComponentReference.printComponentRefStr*/ComponentReference.debugPrintComponentRefTypeStr(c);
tpStr= typeString(ty);
tpStr= Types.unparseType(ty);
res_str = stringAppendList({gen_str,"CREF ",s," CREFTYPE:",tpStr,"\n"});
then
res_str;
Expand All @@ -1366,7 +1308,7 @@ algorithm
new_level2 = level + 1;
sym = debugBinopSymbol(op);
tp = Expression.typeof(exp);
str = typeString(tp);
str = Types.unparseType(tp);
lt = dumpExpStr(e1, new_level1);
rt = dumpExpStr(e2, new_level2);
res_str = stringAppendList({gen_str,"BINARY ",sym," ",str,"\n",lt,rt,""});
Expand All @@ -1379,7 +1321,7 @@ algorithm
new_level1 = level + 1;
sym = unaryopSymbol(op);
ct = dumpExpStr(e, new_level1);
str = "expType:"+&typeString(Expression.typeof(e))+&" optype:"+&typeString(Expression.typeofOp(op))+&"\n";
str = "expType:"+&Types.unparseType(Expression.typeof(e))+&" optype:"+&Types.unparseType(Expression.typeofOp(op))+&"\n";
res_str = stringAppendList({gen_str,"UNARY ",sym," ",str,"\n",ct,""});
then
res_str;
Expand Down Expand Up @@ -1460,7 +1402,7 @@ algorithm
nodes = List.map1(es, dumpExpStr, new_level1);
nodes_1 = stringAppendList(nodes);
s = boolString(b);
tpStr = typeString(tp);
tpStr = Types.unparseType(tp);
res_str = stringAppendList({gen_str,"ARRAY scalar:",s," tp: ",tpStr,"\n",nodes_1});
then
res_str;
Expand Down Expand Up @@ -1512,7 +1454,7 @@ algorithm
equation
gen_str = genStringNTime(" |", level);
new_level1 = level + 1;
tystr = typeString(ty);
tystr = Types.unparseType(ty);
ct = dumpExpStr(e, new_level1);
res_str = stringAppendList({gen_str,"CAST ","\n",ct,""});
then
Expand Down Expand Up @@ -1648,31 +1590,9 @@ protected
Type ty;
algorithm
ty := Expression.typeof(inExp);
str := typeString(ty);
str := Types.unparseType(ty);
end typeOfString;

protected function typeVarsStr "help function to typeString"
input list<Var> vars;
output String s;
algorithm
s := stringDelimitList(List.map(vars,typeVarString),",");
end typeVarsStr;

protected function typeVarString "help function to typeVarsStr"
input Var v;
output String s;
algorithm
s := match (v)
local
String name; Type ty;

case(DAE.TYPES_VAR(name = name,ty = ty))
equation
s = name +& ":" +& typeString(ty);
then s;
end match;
end typeVarString;

public function debugPrintComponentRefExp "
This function takes an DAE.Exp and tries to print ComponentReferences.
Uses debugPrint.ComponentRefTypeStr, which gives type information to stdout.
Expand Down
4 changes: 2 additions & 2 deletions Compiler/FrontEnd/Patternm.mo
Expand Up @@ -610,7 +610,7 @@ algorithm
case DAE.PAT_CONS(head,tail) then patternStr(head) +& "::" +& patternStr(tail);

case DAE.PAT_CONSTANT(exp=exp) then ExpressionDump.printExpStr(exp);
// case DAE.PAT_CONSTANT(SOME(et),exp) then "(" +& ExpressionDump.typeString(et) +& ")" +& ExpressionDump.printExpStr(exp);
// case DAE.PAT_CONSTANT(SOME(et),exp) then "(" +& Types.unparseType(et) +& ")" +& ExpressionDump.printExpStr(exp);
case DAE.PAT_AS(id=id,pat=pat) then id +& " as " +& patternStr(pat);
case DAE.PAT_AS_FUNC_PTR(id, pat) then id +& " as " +& patternStr(pat);
else
Expand Down Expand Up @@ -720,7 +720,7 @@ algorithm
(optPatternMatrix,numNonEmptyColumns) = removeWildPatternColumnsFromMatrix(patternMatrix,{},0);
tpl = findPatternToConvertToSwitch(optPatternMatrix,0,numNonEmptyColumns,info);
(_,ty,_) = tpl;
str = ExpressionDump.typeString(ty);
str = Types.unparseType(ty);
Error.assertionOrAddSourceMessage(not Flags.isSet(Flags.PATTERNM_ALL_INFO),Error.MATCH_TO_SWITCH_OPTIMIZATION, {str}, info);
then DAE.MATCH(SOME(tpl));
else DAE.MATCH(NONE());
Expand Down
2 changes: 1 addition & 1 deletion Compiler/FrontEnd/Static.mo
Expand Up @@ -576,7 +576,7 @@ algorithm
equation
Absyn.IFEXP(ifExp = e1,trueBranch = e2,elseBranch = e3) = Absyn.canonIfExp(e);
(cache,e1_1,prop1,st_1) = elabExp(cache,env, e1, impl, st,doVect,pre,info) "if expressions";
(cache,e_1,prop,st_2) = elabIfExp(cache,env,e1_1,prop1,e2,e3,impl,st,doVect,pre,info);
(cache,e_1,prop,st_2) = elabIfExp(cache,env,e1_1,prop1,e2,e3,impl,st_1,doVect,pre,info);
then
(cache,e_1,prop,st_2);

Expand Down

0 comments on commit a702cff

Please sign in to comment.