@@ -5478,22 +5478,20 @@ algorithm
5478
5478
Env.Cache cache;
5479
5479
DAE.DAElist dae;
5480
5480
5481
- /* use elab_call_args to also try vectorized calls */
5481
+ // Replace der of constant Real, Integer or array of Real/Integer by zero(s)
5482
5482
case (cache,env,{exp},_,impl)
5483
5483
local
5484
- DAE.Type ety,restype,ty;
5485
- DAE.Exp ee1;
5486
- String es1,es2,es3;
5487
- list<String> ls;
5484
+ DAE.Type ety,ty;
5485
+ list<Option<Integer>> dims;
5488
5486
equation
5489
- (_,ee1,DAE.PROP(ety,c),_,dae) = elabExp(cache,env, exp, impl, NONE,false);
5490
- false = Types.isRealOrSubTypeReal(ety);
5491
- ls = Util.listMap({exp}, Dump.printExpStr);
5492
- es1 = Util.stringDelimitList(ls, ", ");
5493
- es3 = Types.unparseType(ety);
5494
- Error.addMessage(Error.DERIVATIVE_NON_REAL, {es1,es1,es3});
5487
+ (_,_,DAE.PROP(ety,c),_,_) = elabExp(cache, env, exp, impl, NONE,false);
5488
+ failure(equality(c=DAE.C_VAR));
5489
+ dims = Types.getRealOrIntegerDimensions(ety);
5490
+ (e,ty) = DAEUtil.makeZeroExpression(dims);
5495
5491
then
5496
- fail();
5492
+ (cache,e,DAE.PROP(ty,DAE.C_CONST),DAE.DAE({}, DAE.AVLTREENODE(NONE, 0, NONE, NONE)));
5493
+
5494
+ /* use elab_call_args to also try vectorized calls */
5497
5495
case (cache,env,{exp},_,impl)
5498
5496
local
5499
5497
DAE.Type ety,restype,ty;
@@ -5503,60 +5501,32 @@ algorithm
5503
5501
(_,ee1,DAE.PROP(ety,c),_,_) = elabExp(cache, env, exp, impl, NONE,true);
5504
5502
ety = Types.arrayElementType(ety);
5505
5503
true = Types.isRealOrSubTypeReal(ety);
5506
- (cache,e,(prop as DAE.PROP(ty,DAE.C_VAR() )),dae) = elabCallArgs(cache,env, Absyn.IDENT("der"), {exp}, {}, impl, NONE);
5504
+ (cache,e,(prop as DAE.PROP(ty,_ )),dae) = elabCallArgs(cache,env, Absyn.IDENT("der"), {exp}, {}, impl, NONE);
5507
5505
then
5508
5506
(cache,e,prop,dae);
5509
5507
5510
- case(cache,env,expl,_,impl)
5508
+ case (cache,env,{exp},_,impl)
5509
+ local
5510
+ DAE.Type ety;
5511
+ String es3;
5511
5512
equation
5512
- setUniqueErrorMessageForDer(cache,env,expl,impl);
5513
- then
5514
- fail();
5513
+ (_,_,DAE.PROP(ety,_),_,_) = elabExp(cache,env, exp, impl, NONE,false);
5514
+ false = Types.isRealOrSubTypeReal(ety);
5515
+ s = Dump.printExpStr(exp);
5516
+ es3 = Types.unparseType(ety);
5517
+ Error.addMessage(Error.DERIVATIVE_NON_REAL, {s,s,es3});
5518
+ then
5519
+ fail();
5520
+ case (cache,env,expl,_,_)
5521
+ equation
5522
+ lst = Util.listMap(expl, Dump.printExpStr);
5523
+ s = Util.stringDelimitList(lst, ", ");
5524
+ s = Util.stringAppendList({"der(",s,")"});
5525
+ Error.addMessage(Error.WRONG_TYPE_OR_NO_OF_ARGS, {s});
5526
+ then fail();
5515
5527
end matchcontinue;
5516
5528
end elabBuiltinDer;
5517
5529
5518
- protected function setUniqueErrorMessageForDer "
5519
- Author: BZ, 2009-02
5520
- Function to set correct error message for der.
5521
- (if we have an error with constant arguments to der() then do not give Error.WRONG_TYPE_OR_NO_OF_ARGS
5522
- "
5523
- input Env.Cache cache;
5524
- input Env.Env env;
5525
- input list<Absyn.Exp> expl;
5526
- input Boolean impl;
5527
- algorithm _ := matchcontinue(cache,env,expl,impl)
5528
- local
5529
- Absyn.Exp exp;
5530
- list<Ident> lst;
5531
- Ident s;
5532
- case (cache,env,{(exp as Absyn.CREF(componentRef = _))},impl)
5533
- equation
5534
- failure((cache,_,DAE.PROP(_,DAE.C_VAR),_,_) = elabExp(cache,env, exp, impl, NONE,true));
5535
- lst = Util.listMap({exp}, Dump.printExpStr);
5536
- s = Util.stringDelimitList(lst, ", ");
5537
- s = Util.stringAppendList({"der(",s,")'.\n"});
5538
- Error.addMessage(Error.DER_APPLIED_TO_CONST, {s});
5539
- then ();
5540
- case (cache,env,{exp},impl)
5541
- equation
5542
- (_,_,DAE.PROP(_,DAE.C_CONST),_,_) = elabExp(cache,env, exp, impl, NONE,true);
5543
- lst = Util.listMap({exp}, Dump.printExpStr);
5544
- s = Util.stringDelimitList(lst, ", ");
5545
- s = Util.stringAppendList({"der(",s,")'.\n"});
5546
- Error.addMessage(Error.DER_APPLIED_TO_CONST, {s});
5547
- then ();
5548
- /*
5549
- case (cache,env,expl,_)
5550
- equation
5551
- lst = Util.listMap(expl, Dump.printExpStr);
5552
- s = Util.stringDelimitList(lst, ", ");
5553
- s = Util.stringAppendList({"der(",s,")'.\n"});
5554
- Error.addMessage(Error.WRONG_TYPE_OR_NO_OF_ARGS, {s});
5555
- then ();
5556
- */
5557
- end matchcontinue;
5558
- end setUniqueErrorMessageForDer;
5559
-
5560
5530
protected function elabBuiltinSample "function: elabBuiltinSample
5561
5531
author: PA
5562
5532
0 commit comments