Skip to content

Commit

Permalink
- Added more error messages for metarecord calls (and make the checks…
Browse files Browse the repository at this point in the history
… in a separate function)

git-svn-id: https://openmodelica.org/svn/OpenModelica/branches/sjoelund-functiontree@6452 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
sjoelund committed Oct 19, 2010
1 parent e66fa26 commit 9c4413c
Show file tree
Hide file tree
Showing 3 changed files with 121 additions and 35 deletions.
8 changes: 6 additions & 2 deletions Compiler/Error.mo
Expand Up @@ -230,6 +230,7 @@ public constant ErrorID GENERATECODE_INVARS_HAS_FUNCTION_PTR=142;
public constant ErrorID LOOKUP_COMP_FOUND_TYPE=143;
public constant ErrorID DUPLICATE_ELEMENTS_NOT_SYNTACTICALLY_IDENTICAL=144;
public constant ErrorID GENERIC_INST_FUNCTION=145;
public constant ErrorID WRONG_NO_OF_ARGS=146;

public constant ErrorID UNBOUND_PARAMETER_WITH_START_VALUE_WARNING=499;
public constant ErrorID UNBOUND_PARAMETER_WARNING=500;
Expand Down Expand Up @@ -273,6 +274,7 @@ public constant ErrorID META_UNSOLVED_POLYMORPHIC_BINDINGS=5010;
public constant ErrorID META_RECORD_FOUND_FAILURE=5011;
public constant ErrorID META_INVALID_PATTERN=5012;
public constant ErrorID META_MATCH_INPUT_OUTPUT_NON_CREF=5013;
public constant ErrorID META_MATCH_GENERAL_FAILURE=5014;

protected constant list<tuple<Integer, MessageType, Severity, String>> errorTable=
{(SYNTAX_ERROR,SYNTAX(),ERROR(),"Syntax error near: %s"),
Expand Down Expand Up @@ -444,6 +446,7 @@ protected constant list<tuple<Integer, MessageType, Severity, String>> errorTabl
"Operand of %s in component %s must be builtin-type in %s"),
(WRONG_TYPE_OR_NO_OF_ARGS,TRANSLATION(),ERROR(),
"Wrong type or wrong number of arguments to %s (in component %s)"),
(WRONG_NO_OF_ARGS,TRANSLATION(),ERROR(),"Wrong number of arguments to %s"),
(DIFFERENT_DIM_SIZE_IN_ARGUMENTS,TRANSLATION(),ERROR(),
"Different dimension sizes in arguments to %s in component %s"),
(DER_APPLIED_TO_CONST,TRANSLATION(),ERROR(),
Expand Down Expand Up @@ -615,9 +618,10 @@ protected constant list<tuple<Integer, MessageType, Severity, String>> errorTabl
(NON_INSTANTIATED_FUNCTION,SYMBOLIC(),ERROR(),"Tried to use function %s, but it was not instantiated."),
(GENERIC_INST_FUNCTION,TRANSLATION(),ERROR(),"Failed to instantiate function %s in scope %s"),
(META_UNSOLVED_POLYMORPHIC_BINDINGS,TRANSLATION(),ERROR(),"Could not solve the polymorphism in the function call\n Input bindings: %s\n Solved bindings: %s\n Unsolved bindings: %s"),
(META_RECORD_FOUND_FAILURE,TRANSLATION(),ERROR(),"Found %s with type %s, but failed to elaborate the call."),
(META_RECORD_FOUND_FAILURE,TRANSLATION(),ERROR(),"In metarecord call %s: %s"),
(META_INVALID_PATTERN,TRANSLATION(),ERROR(),"Invalid pattern: %s"),
(META_MATCH_INPUT_OUTPUT_NON_CREF,TRANSLATION(),ERROR(),"Only component references are valid as %s of a match expression. Got %s.")
(META_MATCH_INPUT_OUTPUT_NON_CREF,TRANSLATION(),ERROR(),"Only component references are valid as %s of a match expression. Got %s."),
(META_MATCH_GENERAL_FAILURE,TRANSLATION(),ERROR(),"Failed to elaborate match expression %s := %s")

};

Expand Down
16 changes: 11 additions & 5 deletions Compiler/InstSection.mo
Expand Up @@ -2526,7 +2526,7 @@ algorithm
case (cache,env,ih,pre,alg as SCode.ALG_ASSIGN(value = Absyn.MATCHEXP(matchTy=_)),source,initial_,impl,unrollForLoops)
equation
true = RTOpts.acceptMetaModelicaGrammar();
(cache,stmt) = createMatchStatement(cache,env,ih,pre,alg,impl);
(cache,stmt) = createMatchStatement(cache,env,ih,pre,alg,impl,Error.getNumErrorMessages());
then (cache,{stmt});

case (cache,env,ih,pre,SCode.ALG_ASSIGN(assignComponent = left, value = right, comment = comment, info = info),source,initial_,impl,unrollForLoops)
Expand Down Expand Up @@ -3019,10 +3019,11 @@ protected function createMatchStatement
input Prefix pre;
input SCode.Statement alg;
input Boolean inBoolean;
input Integer numError;
output Env.Cache outCache;
output DAE.Statement outStmt;
algorithm
(outCache,outStmt,dae) := matchcontinue (cache,env,ih,pre,alg,inBoolean)
(outCache,outStmt,dae) := matchcontinue (cache,env,ih,pre,alg,inBoolean,numError)
local
DAE.Properties cprop,eprop;
DAE.Statement stmt;
Expand All @@ -3039,9 +3040,10 @@ algorithm
list<Absyn.Exp> expl;
Absyn.Info info;
DAE.ElementSource source;
String str1,str2;

// (v1,v2,..,vn)|v|_ := matchcontinue(...). Part of MetaModelica extension. KS
case (localCache,localEnv,ih,localPre,SCode.ALG_ASSIGN(assignComponent = exp, value = e as Absyn.MATCHEXP(matchTy=_), info = info),impl)
case (localCache,localEnv,ih,localPre,SCode.ALG_ASSIGN(assignComponent = exp, value = e as Absyn.MATCHEXP(matchTy=_), info = info),impl,numError)
equation
expl = MetaUtil.extractListFromTuple(exp, 0);
(localCache,e) = Patternm.matchMain(e,expl,localCache,localEnv,info);
Expand All @@ -3055,10 +3057,14 @@ algorithm
then
(localCache,stmt);

case (_,_,_,_,_,_)
case (_,_,_,_,SCode.ALG_ASSIGN(assignComponent = exp, value = e as Absyn.MATCHEXP(matchTy=_), info = info),_,numError)
equation
Debug.fprintln("matchcase", "- InstSection.createMatchStatement failed");
true = numError == Error.getNumErrorMessages();
str1 = Dump.printExpStr(exp);
str2 = Dump.printExpStr(e);
Error.addSourceMessage(Error.META_MATCH_GENERAL_FAILURE, {str1,str2}, info);
then fail();

end matchcontinue;
end createMatchStatement;

Expand Down
132 changes: 104 additions & 28 deletions Compiler/Static.mo
Expand Up @@ -8582,10 +8582,10 @@ algorithm
Option<Interactive.InteractiveSymbolTable> st;
list<DAE.Type> typelist,ktypelist,tys;
list<DAE.Dimension> vect_dims;
DAE.Exp call_exp;
DAE.Exp call_exp,daeExp;
list<Ident> t_lst;
Ident fn_str,types_str,scope,pre_str;
String s,name,argStr,id;
String s,name,argStr,id,args_str;
Env.Cache cache;
DAE.ExpType tp;
SCode.Mod mod;
Expand Down Expand Up @@ -8735,35 +8735,12 @@ algorithm
false = Util.getStatefulBoolean(stopElab);
(cache,t as (DAE.T_METARECORD(utPath=utPath,index=index,fields=vars),SOME(fqPath)),env_1) = Lookup.lookupType(cache, env, fn, false);
Util.setStatefulBoolean(stopElab,true);
//(cache,c,env_1) = Lookup.lookupClass(cache, env, fn, false);
// (_, _, _, _, (DAE.T_COMPLEX(complexClassType = ClassInf.META_RECORD(_), complexVarLst = vars),_), _, _, _) = Inst.instClass(cache,env_1,DAE.NOMOD(),Prefix.NOPRE(), Connect.emptySet,c,{},false,Inst.INNER_CALL(), ConnectionGraph.EMPTY);
fieldNames = Util.listMap(vars, Types.getVarName);
tys = Util.listMap(vars, Types.getVarType);
fargs = Util.listThreadTuple(fieldNames, tys);
slots = makeEmptySlots(fargs);
(cache,args_1,newslots,constlist,_) = elabInputArgs(cache,env, args, nargs, slots, true /*checkTypes*/ ,impl,{},pre,info);
const = Util.listReduce(constlist, Types.constAnd);
tyconst = elabConsts(t, const);
t = (DAE.T_UNIONTYPE({}),SOME(utPath));
prop = getProperties(t, tyconst);
true = Util.listFold(newslots, slotAnd, true);
//(cache,newslots2) = fillDefaultSlots(cache,newslots, c, env, impl,pre,info);
args_2 = expListFromSlots(newslots);
(cache,call_exp,prop,status) = elabCallArgsMetarecord(cache,env,t,args,nargs,impl,stopElab,st,pre,info);
then
(cache,DAE.METARECORDCALL(fqPath,args_2,fieldNames,index),prop,Util.SUCCESS());
/* ------ */
(cache,call_exp,prop,status);

/* MetaRecord failure */
/* ..Other functions */
case (cache,env,fn,args,nargs,impl,stopElab,st,pre,info)
equation
true = RTOpts.acceptMetaModelicaGrammar();
true = Util.getStatefulBoolean(stopElab);
(cache,t as (DAE.T_METARECORD(index=_),SOME(fn_1)),env_1) = Lookup.lookupType(cache, env, fn, false);
types_str = Types.unparseType(t);
fn_str = Absyn.pathString(fn_1);
Error.addSourceMessage(Error.META_RECORD_FOUND_FAILURE,{fn_str,types_str},info);
then (cache,DAE.ICONST(0),DAE.PROP((DAE.T_NOTYPE(),NONE()),DAE.C_VAR),Util.FAILURE());
case (cache,env,fn,args,nargs,impl,stopElab,st,pre,info) /* ..Other functions */
local
DAE.ExpType tp;
DAE.Exp callExp;
Expand Down Expand Up @@ -8865,6 +8842,105 @@ algorithm
end matchcontinue;
end elabCallArgs2;

protected function elabCallArgsMetarecord
input Env.Cache cache;
input Env.Env inEnv;
input DAE.Type inType;
input list<Absyn.Exp> inAbsynExpLst;
input list<Absyn.NamedArg> inAbsynNamedArgLst;
input Boolean inBoolean;
input Util.StatefulBoolean stopElab;
input Option<Interactive.InteractiveSymbolTable> inInteractiveInteractiveSymbolTableOption;
input Prefix inPrefix;
input Absyn.Info info;
output Env.Cache outCache;
output DAE.Exp outExp;
output DAE.Properties outProperties;
output Util.Status status;
algorithm
(outCache,outExp,outProperties,status) :=
matchcontinue (cache,inEnv,inType,inAbsynExpLst,inAbsynNamedArgLst,inBoolean,stopElab,inInteractiveInteractiveSymbolTableOption,inPrefix,info)
local
DAE.Type t,outtype,restype,functype,tp1;
list<tuple<Ident, DAE.Type>> fargs;
list<Env.Frame> env_1,env_2,env;
list<Slot> slots,newslots,newslots2,slots2;
list<DAE.Exp> args_1,args_2,args1;
list<DAE.Const> constlist;
DAE.Const const;
DAE.TupleConst tyconst;
DAE.Properties prop,prop_1;
SCode.Class cl;
Absyn.Path fn,fn_1,fqPath,utPath;
list<Absyn.Exp> args;
list<Absyn.NamedArg> nargs, translatedNArgs;
Boolean impl,tuple_,builtin;
DAE.InlineType inline;
Option<Interactive.InteractiveSymbolTable> st;
list<DAE.Type> typelist,ktypelist,tys;
list<DAE.Dimension> vect_dims;
DAE.Exp call_exp,daeExp;
list<Ident> t_lst;
Ident fn_str,types_str,scope,pre_str;
String s,name,argStr,id,args_str,str;
Env.Cache cache;
DAE.ExpType tp;
SCode.Mod mod;
DAE.Mod tmod;
SCode.Class cl;
Option<Absyn.Modification> absynOptMod;
ClassInf.State complexClassType;
DAE.DAElist dae,dae1,dae2,dae3,dae4,outDae;
Prefix pre;
SCode.Class c;
SCode.Restriction re;
Integer index;
list<String> fieldNames;
list<DAE.Var> vars;

case (cache,env,t as (DAE.T_METARECORD(fields=vars),SOME(fqPath)),args,nargs,impl,stopElab,st,pre,info)
equation
false = listLength(vars) == listLength(args) + listLength(nargs);
fn_str = Absyn.pathString(fqPath);
Error.addSourceMessage(Error.WRONG_NO_OF_ARGS,{fn_str},info);
then (cache,DAE.ICONST(0),DAE.PROP((DAE.T_NOTYPE(),NONE()),DAE.C_VAR),Util.FAILURE());

case (cache,env,t as (DAE.T_METARECORD(index=index,utPath=utPath,fields=vars),SOME(fqPath)),args,nargs,impl,stopElab,st,pre,info)
equation
fieldNames = Util.listMap(vars, Types.getVarName);
tys = Util.listMap(vars, Types.getVarType);
fargs = Util.listThreadTuple(fieldNames, tys);
slots = makeEmptySlots(fargs);
(cache,args_1,newslots,constlist,_) = elabInputArgs(cache,env, args, nargs, slots, true ,impl, {}, pre, info);
const = Util.listReduce(constlist, Types.constAnd);
tyconst = elabConsts(t, const);
t = (DAE.T_UNIONTYPE({}),SOME(utPath));
prop = getProperties(t, tyconst);
true = Util.listFold(newslots, slotAnd, true);
args_2 = expListFromSlots(newslots);
then
(cache,DAE.METARECORDCALL(fqPath,args_2,fieldNames,index),prop,Util.SUCCESS());

/* MetaRecord failure */
case (cache,env,(DAE.T_METARECORD(utPath=utPath,index=index,fields=vars),SOME(fqPath)),args,nargs,impl,stopElab,st,pre,info)
equation
(cache,daeExp,prop,_) = elabExp(cache,env,Absyn.TUPLE(args),false,st,false,pre,info);
tys = Util.listMap(vars, Types.getVarType);
str = "Failed to match types: Got " +& Types.unparseType(Types.getPropType(prop)) +& " but expected " +& Types.unparseType((DAE.T_TUPLE(tys),NONE()));
fn_str = Absyn.pathString(fqPath);
Error.addSourceMessage(Error.META_RECORD_FOUND_FAILURE,{fn_str,str},info);
then (cache,DAE.ICONST(0),DAE.PROP((DAE.T_NOTYPE(),NONE()),DAE.C_VAR),Util.FAILURE());

/* MetaRecord failure (args). */
case (cache,env,(_,SOME(fqPath)),args,nargs,impl,stopElab,st,pre,info)
equation
args_str = "Failed to elaborate arguments " +& Dump.printExpStr(Absyn.TUPLE(args));
fn_str = Absyn.pathString(fqPath);
Error.addSourceMessage(Error.META_RECORD_FOUND_FAILURE,{fn_str,args_str},info);
then (cache,DAE.ICONST(0),DAE.PROP((DAE.T_NOTYPE(),NONE()),DAE.C_VAR),Util.FAILURE());
end matchcontinue;
end elabCallArgsMetarecord;

protected function instantiateDaeFunction "help function to elabCallArgs. Instantiates the function as a dae and adds it to the
functiontree of a newly created dae"
input Env.Cache inCache;
Expand Down

0 comments on commit 9c4413c

Please sign in to comment.