Skip to content
This repository was archived by the owner on May 18, 2019. It is now read-only.

Commit b9e79ec

Browse files
Jan ŠilarOpenModelica-Hudson
authored andcommitted
PDEModelica
- bugfix - improved error reports - cleaning
1 parent aab2f92 commit b9e79ec

File tree

2 files changed

+104
-75
lines changed

2 files changed

+104
-75
lines changed

Compiler/FrontEnd/InstUtil.mo

Lines changed: 68 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -8376,77 +8376,101 @@ algorithm
83768376
list<DAE.SubMod> subModLst;
83778377
Option<DAE.EqMod> binding;
83788378
DAE.SourceInfo info;
8379-
Integer N;
8379+
Integer N = -1;
83808380
DAE.ComponentRef dcr;
8381+
DAE.SubMod domainSubMod;
83818382
case(SCode.ATTR(isField=Absyn.NONFIELD()),_)
83828383
//TODO: check that the domain attribute (modifier) is not present.
83838384
then
83848385
(inDims,inMod,NONE());
83858386
case(SCode.ATTR(isField=Absyn.FIELD()),DAE.MOD(finalPrefix = finalPrefix, eachPrefix = eachPrefix, subModLst = subModLst, binding = binding, info = info))
83868387
equation
8387-
// DAE.MOD(finalPrefix = finalPrefix, eachPrefix = eachPrefix, subModLst = subModLst, eqModOption = eqModOption) = inMod;
8388+
//find the domain modifier:
8389+
(domainSubMod, subModLst) = List.findAndRemove(subModLst, findDomainSubMod);
8390+
dcr = getQualDcr(domainSubMod, inInfo);
83888391
//get N from the domain and remove domain from the subModLst:
8389-
(N, subModLst, SOME(dcr)) = List.fold30(subModLst,domainSearchFunDAE,-1,{},NONE());
8392+
(N, dcr) = getNDcr(dcr);
83908393
if (N == -1) then Error.addSourceMessageAndFail(Error.PDEModelica_ERROR,
8391-
{"Domain of the field variable '", name, "' not found."}, inInfo);
8394+
{"Domain of the field variable '" + name + "' not found."}, inInfo);
83928395
end if;
83938396
subModLst = listReverse(subModLst);
83948397
subModLst = List.map(subModLst,addEach);
83958398
outMod = DAE.MOD(finalPrefix, eachPrefix, subModLst, binding, info);
83968399
dim_f = DAE.DIM_INTEGER(N);
83978400
then
83988401
(dim_f::inDims, outMod, SOME((Absyn.CREF_IDENT(name, {}),dcr)));
8402+
case(_,DAE.NOMOD())
8403+
equation
8404+
Error.addSourceMessageAndFail(Error.PDEModelica_ERROR,
8405+
{"Field variable '" + name + "' has no domain modifier."}, inInfo);
8406+
then
8407+
(inDims,inMod,NONE());
83998408
end match;
84008409
end elabField;
84018410

8402-
protected function domainSearchFunDAE
8403-
"fold function to find domain modifier in modifiers list"
8404-
//TODO: simplify this function, perhaps not use fold
8411+
protected function findDomainSubMod
84058412
input DAE.SubMod subMod;
8406-
input Integer inN;
8407-
input list<DAE.SubMod> inSubModLst;
8408-
input Option<DAE.ComponentRef> inCrOpt;
8409-
output Integer outN;
8410-
output list<DAE.SubMod> outSubModLst;
8411-
output Option<DAE.ComponentRef> outCrOpt;
8412-
8413-
algorithm
8414-
(outSubModLst,outN,outCrOpt) := matchcontinue subMod
8415-
local
8416-
DAE.Mod mod;
8417-
list<DAE.SubMod> subModLst;
8418-
Option<DAE.EqMod> eqModOption;
8419-
// list<Values.Value> values;
8420-
// list<String> names;
8421-
list<DAE.Var> varLst;
8422-
Integer N;
8423-
DAE.ComponentRef cr;
8413+
output Boolean isDomain;
8414+
algorithm
8415+
isDomain := matchcontinue subMod
8416+
local
8417+
DAE.Mod mod;
8418+
case DAE.NAMEMOD(ident="domain") then true;
8419+
else false;
8420+
end matchcontinue;
8421+
end findDomainSubMod;
8422+
8423+
protected function getQualDcr
8424+
input DAE.SubMod domainSubMod;
8425+
input SourceInfo inInfo;
8426+
output DAE.ComponentRef dcr;
8427+
algorithm
8428+
dcr := match domainSubMod
8429+
local
8430+
DAE.ComponentRef cr;
84248431
case DAE.NAMEMOD(ident="domain", mod=DAE.MOD(binding=SOME(
8425-
DAE.TYPED(
8426-
modifierAsExp=DAE.CREF(
8427-
componentRef = cr,
8428-
ty=DAE.T_COMPLEX(
8429-
complexClassType=ClassInf.RECORD(
8430-
path=Absyn.FULLYQUALIFIED(
8431-
path=Absyn.IDENT(name="DomainLineSegment1D")
8432-
)
8433-
)
8432+
DAE.TYPED(
8433+
modifierAsExp=DAE.CREF(
8434+
componentRef = cr,
8435+
ty=DAE.T_COMPLEX(
8436+
complexClassType=ClassInf.RECORD(
8437+
path=Absyn.FULLYQUALIFIED(
8438+
path=Absyn.IDENT(name="DomainLineSegment1D")
84348439
)
84358440
)
84368441
)
8437-
)))
8438-
equation
8439-
DAE.CREF_IDENT(identType = DAE.T_COMPLEX(varLst = varLst)) = cr;
8440-
N = List.findSome(varLst,findN);
8441-
then (inSubModLst,N,SOME(cr));
8442-
case DAE.NAMEMOD(ident="domain")
8442+
)
8443+
)
8444+
)))
8445+
then cr;
8446+
case _
84438447
equation
8444-
print("cant find N in the domain");
8448+
Error.addSourceMessageAndFail(Error.PDEModelica_ERROR,
8449+
{"The domain type is wrong.\n"}, inInfo);
84458450
then
84468451
fail();
8447-
else (subMod::inSubModLst,inN,inCrOpt);
8448-
end matchcontinue;
8449-
end domainSearchFunDAE;
8452+
end match;
8453+
end getQualDcr;
8454+
8455+
protected function getNDcr
8456+
input DAE.ComponentRef dcr;
8457+
output Integer outN;
8458+
output DAE.ComponentRef outCrOpt;
8459+
algorithm
8460+
(outN,outCrOpt) := matchcontinue dcr
8461+
local
8462+
DAE.ComponentRef cr1;
8463+
list<DAE.Var> varLst;
8464+
Integer N;
8465+
case DAE.CREF_QUAL(componentRef = cr1)
8466+
then getNDcr(cr1);
8467+
case DAE.CREF_IDENT(identType = DAE.T_COMPLEX(varLst = varLst))
8468+
equation
8469+
N = List.findSome(varLst,findN);
8470+
then (N,dcr);
8471+
end matchcontinue;
8472+
end getNDcr;
8473+
84508474

84518475
protected function findN
84528476
"a map function to find N in domain class modifiers"
@@ -8644,37 +8668,6 @@ algorithm
86448668
end extrapFieldTraverseFun;
86458669

86468670

8647-
8648-
8649-
8650-
/*
8651-
8652-
//TODO: remove never called:
8653-
protected function matchExtrapAndField
8654-
input Absyn.Exp lhs_exp;
8655-
input Absyn.Exp rhs_exp;
8656-
output Absyn.ComponentRef fieldCr;
8657-
protected String s;
8658-
algorithm
8659-
s := "Ahoj";
8660-
fieldCr := match (lhs_exp, rhs_exp)
8661-
local
8662-
Absyn.ComponentRef fcr, fcr_arg;
8663-
case (Absyn.CALL(
8664-
function_ = Absyn.CREF_IDENT(name="extrapolateField", subscripts={}),
8665-
functionArgs = Absyn.FUNCTIONARGS(args = {Absyn.CREF(Absyn.CREF_IDENT())})
8666-
),
8667-
Absyn.CREF(fcr as Absyn.CREF_IDENT())
8668-
)
8669-
then
8670-
fcr;
8671-
case (Absyn.CREF(fcr as Absyn.CREF_IDENT()),Absyn.CALL(function_ = Absyn.CREF_IDENT(name="extrapolateField", subscripts={}), functionArgs = Absyn.FUNCTIONARGS(args = {Absyn.CREF(Absyn.CREF_IDENT())})))
8672-
then
8673-
fcr;
8674-
end match;
8675-
8676-
end matchExtrapAndField;
8677-
*/
86788671
protected function getDomNFields
86798672
input DomainFieldsLst inDomFieldLst;
86808673
input Absyn.ComponentRef inDomainCr;

Compiler/Util/List.mo

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6049,6 +6049,42 @@ algorithm
60496049
fail();
60506050
end find1;
60516051

6052+
public function findAndRemove<T>
6053+
"This function retrieves the first element of a list for which the passed
6054+
function evaluates to true. And returns the list with the element removed."
6055+
input list<T> inList;
6056+
input SelectFunc inFunc;
6057+
output T outElement;
6058+
output list<T> rest;
6059+
6060+
partial function SelectFunc
6061+
input T inElement;
6062+
output Boolean outSelect;
6063+
end SelectFunc;
6064+
protected
6065+
Integer i=0;
6066+
DoubleEndedList<T> delst;
6067+
T t;
6068+
algorithm
6069+
for e in inList loop
6070+
if inFunc(e) then
6071+
outElement := e;
6072+
delst := DoubleEndedList.fromList({});
6073+
rest := inList;
6074+
for i in 1:i loop
6075+
t::rest := rest;
6076+
DoubleEndedList.push_back(delst, t);
6077+
end for;
6078+
_::rest := rest;
6079+
rest := DoubleEndedList.toListAndClear(delst, prependToList=rest);
6080+
return;
6081+
end if;
6082+
i := i + 1;
6083+
end for;
6084+
fail();
6085+
end findAndRemove;
6086+
6087+
60526088
public function findAndRemove1<T, ArgT1>
60536089
"This function retrieves the first element of a list for which the passed
60546090
function evaluates to true. And returns the list with the element removed."

0 commit comments

Comments
 (0)