Skip to content

Commit

Permalink
- Added Builtin stringEqual
Browse files Browse the repository at this point in the history
- Fixed some old RML syntax
- Made some proper error messages for Patternm.mo instead of INTERNAL_ERROR


git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@6967 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
sjoelund committed Nov 11, 2010
1 parent 4672844 commit 0d7a07d
Show file tree
Hide file tree
Showing 15 changed files with 268 additions and 266 deletions.
2 changes: 1 addition & 1 deletion Compiler/Algorithm.mo
Expand Up @@ -620,7 +620,7 @@ algorithm
then DAE.STMT_REINIT(var_1,val_1,source);

case (_,_,prop1,prop2,source) equation
Error.addSourceMessage(Error.INTERNAL_ERROR(),{"reinit called with wrong args"},DAEUtil.getElementSourceFileInfo(source));
Error.addSourceMessage(Error.INTERNAL_ERROR,{"reinit called with wrong args"},DAEUtil.getElementSourceFileInfo(source));
then fail();

// TODO: Add checks for reinit here. 1. First argument must be variable. 2. Expressions must be real.
Expand Down
1 change: 1 addition & 0 deletions Compiler/Builtin.mo
Expand Up @@ -3010,6 +3010,7 @@ algorithm
env = Env.extendFrameT(env, "stringAppend", stringString2string);
env = Env.extendFrameT(env, "stringUpdateStringChar", stringStringInteger2string);
env = Env.extendFrameT(env, "stringEq", stringString2boolean);
env = Env.extendFrameT(env, "stringEqual", stringString2boolean);
env = Env.extendFrameT(env, "stringCompare", stringString2int);
env = Env.extendFrameT(env, "stringHash", string2int);
env = Env.extendFrameT(env, "stringHashDjb2", string2int);
Expand Down
1 change: 0 additions & 1 deletion Compiler/DAEUtil.mo
Expand Up @@ -2218,7 +2218,6 @@ algorithm
local
DAE.Exp e;
list<DAE.ComponentRef> crefs1,crefs2;
DAE.ElementSource source "the element origin";
case({},_) then {};
case(e::inExps,source)
equation
Expand Down
9 changes: 8 additions & 1 deletion Compiler/Error.mo
Expand Up @@ -285,6 +285,10 @@ public constant ErrorID META_NONE_CREF=5017;
public constant ErrorID META_INVALID_PATTERN_NAMED_FIELD=5018;
public constant ErrorID META_INVALID_LOCAL_ELEMENT=5019;
public constant ErrorID META_INVALID_COMPLEX_TYPE=5020;
public constant ErrorID META_DECONSTRUCTOR_NOT_PART_OF_UNIONTYPE=5021;
public constant ErrorID META_TYPE_MISMATCH_PATTERN=5022;
public constant ErrorID META_DECONSTRUCTOR_NOT_RECORD=5023;


protected constant list<tuple<Integer, MessageType, Severity, String>> errorTable=
{(SYNTAX_ERROR,SYNTAX(),ERROR(),"Syntax error near: %s"),
Expand Down Expand Up @@ -643,7 +647,10 @@ protected constant list<tuple<Integer, MessageType, Severity, String>> errorTabl
(META_NONE_CREF,TRANSLATION(),ERROR(),"NONE is not acceptable syntax. Use NONE() instead."),
(META_INVALID_PATTERN_NAMED_FIELD,TRANSLATION(),ERROR(),"Invalid named fields: %s"),
(META_INVALID_LOCAL_ELEMENT,TRANSLATION(),ERROR(),"Only components are allowed in local declarations, got: %s"),
(META_INVALID_COMPLEX_TYPE,TRANSLATION(),ERROR(),"Invalid complex type name: %s<...>")
(META_INVALID_COMPLEX_TYPE,TRANSLATION(),ERROR(),"Invalid complex type name: %s<...>"),
(META_DECONSTRUCTOR_NOT_PART_OF_UNIONTYPE,TRANSLATION(),ERROR(),"%s is not part of uniontype %s"),
(META_TYPE_MISMATCH_PATTERN,TRANSLATION(),ERROR(),"Type mismatch in pattern\nactual type:\n %s\nexpected type:\n %s"),
(META_DECONSTRUCTOR_NOT_RECORD,TRANSLATION(),ERROR(),"Call pattern is not a record deconstructor %s")

};

Expand Down
12 changes: 5 additions & 7 deletions Compiler/Inst.mo
Expand Up @@ -3784,6 +3784,7 @@ algorithm
re,prot,inst_dims,impl,_,graph,instSingleCref,info,stopInst)
equation
true = RTOpts.acceptMetaModelicaGrammar();
false = listMember(Absyn.pathString(cn), {"tuple","array","Option","list"});
cns = Absyn.pathString(cn);
Error.addSourceMessage(Error.META_INVALID_COMPLEX_TYPE, {cns}, info);
then fail();
Expand Down Expand Up @@ -6409,15 +6410,13 @@ protected function checkMultiplyDeclared
algorithm
alreadyDeclared := matchcontinue(cache,env,mod,prefix,csets,ciState,compTuple,instDims,impl)
local
list<Env.Frame> env,env_1,env2,env2_1,cenv,compenv;
DAE.Mod mod;
list<Env.Frame> env_1,env2,env2_1,cenv,compenv;
String n,n2;
Boolean finalPrefix,repl,prot;
SCode.Element oldElt;
DAE.Mod oldMod;
tuple<SCode.Element,DAE.Mod> newComp;
Env.InstStatus instStatus;
Boolean alreadyDeclared;
SCode.Class oldClass,newClass;

case (_,_,_,_,_,_,_,_,_) equation /*print(" dupe check setting ");*/ ErrorExt.setCheckpoint("checkMultiplyDeclared"); then fail();
Expand Down Expand Up @@ -6581,15 +6580,15 @@ algorithm
// add a warning and let it continue!
s1 = SCode.unparseElementStr(oldElt);
s2 = SCode.unparseElementStr(newElt);
Error.addMessageOrSourceMessage(Error.DUPLICATE_ELEMENTS_NOT_SYNTACTICALLY_IDENTICAL(),{s1,s2}, aInfo);
Error.addMessageOrSourceMessage(Error.DUPLICATE_ELEMENTS_NOT_SYNTACTICALLY_IDENTICAL,{s1,s2}, aInfo);
then ();

// fail baby and add a source message!
case (cache, env, (oldElt as SCode.COMPONENT(info=aInfo),oldMod),(newElt,newMod))
equation
s1 = SCode.unparseElementStr(oldElt);
s2 = SCode.unparseElementStr(newElt);
Error.addMessageOrSourceMessage(Error.DUPLICATE_ELEMENTS_NOT_IDENTICAL(),{s1,s2}, aInfo);
Error.addMessageOrSourceMessage(Error.DUPLICATE_ELEMENTS_NOT_IDENTICAL,{s1,s2}, aInfo);
//print(" *** error message added *** \n");
then fail();
end matchcontinue;
Expand Down Expand Up @@ -6637,7 +6636,7 @@ algorithm
equation
s1 = SCode.printClassStr(oldCl);
s2 = SCode.printClassStr(newCl);
Error.addMessage(Error.DUPLICATE_CLASSES_NOT_EQUIVALENT(),{s1,s2});
Error.addMessage(Error.DUPLICATE_CLASSES_NOT_EQUIVALENT,{s1,s2});
//print(" *** error message added *** \n");
then fail();
end matchcontinue;
Expand Down Expand Up @@ -13654,7 +13653,6 @@ algorithm
Absyn.ComponentRef c1,c2;
list<Absyn.ComponentRef> cl1,cl2;
Env.Env env,compenv,cenv;
Env.Cache cache;
Integer i1,i2;
list<Absyn.Subscript> ad;
SCode.Accessibility acc;
Expand Down
6 changes: 3 additions & 3 deletions Compiler/InstSection.mo
Expand Up @@ -566,7 +566,7 @@ algorithm
equation
true = OptManager.getOption("checkModel");
(cache, _,props,_) = Static.elabExpList(cache,env, conditions, impl,NONE(),true,pre,info);
(DAE.PROP((DAE.T_BOOL(_),_),DAE.C_PARAM)) = Types.propsAnd(props);
(DAE.PROP((DAE.T_BOOL(_),_),DAE.C_PARAM())) = Types.propsAnd(props);
b = Util.selectList({true}, tb, fb);
(cache,env_1,ih,dae,csets_1,ci_state_1,graph) = Inst.instList(cache,env,ih, mod, pre, csets, ci_state, instEEquation, b, impl, Inst.alwaysUnroll, graph);
then
Expand Down Expand Up @@ -716,7 +716,7 @@ algorithm
case (cache, env, ih, mod, pre, csets, ci_state, SCode.EQ_FOR(index = i, range = e, eEquationLst = el,info=info), initial_, impl, graph)
equation
true = OptManager.getOption("checkModel");
(cache, e_1, DAE.PROP(type_ = (DAE.T_ARRAY(arrayType = id_t), _), constFlag = cnst as DAE.C_PARAM), _) =
(cache, e_1, DAE.PROP(type_ = (DAE.T_ARRAY(arrayType = id_t), _), constFlag = cnst as DAE.C_PARAM()), _) =
Static.elabExp(cache, env, e, impl,NONE(), true, pre,info);
env_1 = addForLoopScope(env, i, id_t, SCode.VAR(), SOME(cnst));
v = Values.ARRAY({Values.INTEGER(1)}, {1});
Expand Down Expand Up @@ -1848,7 +1848,7 @@ algorithm
// true = containsWhenStatements(sl);
str = Dump.unparseAlgorithmStr(0,
SCode.statementToAlgorithmItem(SCode.ALG_FOR(inIterators, sl,NONE(),info)));
Error.addSourceMessage(Error.UNROLL_LOOP_CONTAINING_WHEN(), {str}, info);
Error.addSourceMessage(Error.UNROLL_LOOP_CONTAINING_WHEN, {str}, info);
Debug.fprintln("failtrace", "- InstSection.unrollForLoop failed on: " +& str);
then
fail();
Expand Down
5 changes: 3 additions & 2 deletions Compiler/Interactive.mo
Expand Up @@ -6904,6 +6904,7 @@ algorithm
Absyn.Modification mod;
Absyn.ComponentRef class_,ident,subident;
Absyn.Program p;
list<Absyn.ElementArg> elementArgLst;

case (class_,ident,subident,p)
equation
Expand All @@ -6913,8 +6914,8 @@ algorithm
comps = getComponentsInClass(cdef);
compelts = Util.listMap(comps, getComponentitemsInElement);
compelts_1 = Util.listFlatten(compelts);
{Absyn.COMPONENTITEM(Absyn.COMPONENT(_,_,SOME(Absyn.CLASSMOD(mod,_))),_,_)} = Util.listSelect1(compelts_1, name, componentitemNamed);
mod = getModificationValue(mod, subident);
{Absyn.COMPONENTITEM(component=Absyn.COMPONENT(modification=SOME(Absyn.CLASSMOD(elementArgLst=elementArgLst))))} = Util.listSelect1(compelts_1, name, componentitemNamed);
mod = getModificationValue(elementArgLst, subident);
res = Dump.unparseModificationStr(mod);
then
res;
Expand Down
19 changes: 9 additions & 10 deletions Compiler/Patternm.mo
Expand Up @@ -2668,8 +2668,8 @@ algorithm
case (cache,env,_,_,info,lhs)
equation
s = Dump.printExpStr(lhs);
s = "Pattern had different number of elements: " +& s;
Error.addSourceMessage(Error.INTERNAL_ERROR, {s}, info);
s = "pattern " +& s;
Error.addSourceMessage(Error.WRONG_NO_OF_ARGS, {s}, info);
then fail();
end match;
end elabPatternTuple;
Expand Down Expand Up @@ -2717,9 +2717,8 @@ algorithm
case (cache,env,callPath,_,_,info,lhs)
equation
failure((_,_,_) = Lookup.lookupType(cache, env, callPath, NONE()));
s = Dump.printExpStr(lhs);
s = "Call pattern is not a record deconstructor: " +& s;
Error.addSourceMessage(Error.INTERNAL_ERROR, {s}, info);
s = Absyn.pathString(callPath);
Error.addSourceMessage(Error.META_DECONSTRUCTOR_NOT_RECORD, {s}, info);
then fail();
end matchcontinue;
end elabPatternCall;
Expand Down Expand Up @@ -2750,8 +2749,7 @@ algorithm
equation
s1 = Types.unparseType(ty1);
s2 = Types.unparseType(ty2);
str = "Patternm.validPatternType failed: " +& s1 +& ", " +& s2;
Error.addSourceMessage(Error.INTERNAL_ERROR, {str}, info);
Error.addSourceMessage(Error.META_TYPE_MISMATCH_PATTERN, {s1,s2}, info);
then fail();
end matchcontinue;
end validPatternType;
Expand All @@ -2764,15 +2762,16 @@ protected function validUniontype
algorithm
_ := matchcontinue (path1,path2,info,lhs)
local
String str;
String s1,s2;
case (path1,path2,_,_)
equation
true = Absyn.pathEqual(path1,path2);
then ();
else
equation
str = "Deconstructor " +& Dump.printExpStr(lhs) +& " is not part of uniontype " +& Absyn.pathString(path2);
Error.addSourceMessage(Error.INTERNAL_ERROR, {str}, info);
s1 = Absyn.pathString(path1);
s2 = Absyn.pathString(path2);
Error.addSourceMessage(Error.META_DECONSTRUCTOR_NOT_PART_OF_UNIONTYPE, {s1,s2}, info);
then fail();
end matchcontinue;
end validUniontype;
Expand Down
5 changes: 3 additions & 2 deletions Compiler/SCode.mo
Expand Up @@ -1710,7 +1710,7 @@ protected function classDefEqual
list<Equation> ieqns1,ieqns2;
list<AlgorithmSection> algs1,algs2;
list<AlgorithmSection> ialgs1,ialgs2;
list<Boolean> blst1,blst2,blst3,blst4,blst5,blst6,blst;
list<Boolean> blst0,blst1,blst2,blst3,blst4,blst5,blst6,blst;
Absyn.ElementAttributes attr1,attr2;
Absyn.TypeSpec tySpec1, tySpec2;
Absyn.Path p1, p2;
Expand Down Expand Up @@ -1761,7 +1761,8 @@ protected function classDefEqual
b2 = modEqual(mod1,mod2);
// adrpo: ignore annotations!
// blst6 = Util.listThreadMap(anns1,anns2,annotationEqual);
blst = Util.listFlatten({{b1,b2},blst1,blst2,blst3,blst4,blst5/*,blst6*/});
blst0 = {b1,b2};
blst = Util.listFlatten({blst0,blst1,blst2,blst3,blst4,blst5/*,blst6*/});
equal = Util.boolAndList(blst);
then
equal;
Expand Down

0 comments on commit 0d7a07d

Please sign in to comment.