Skip to content

Commit

Permalink
- Removed function List.delete, since it was just an rml workaround
Browse files Browse the repository at this point in the history
- Changed listDelete to work with one-based index (mm:#1623)


git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@22955 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
lochel committed Oct 26, 2014
1 parent 6690dc7 commit 76df8c9
Show file tree
Hide file tree
Showing 10 changed files with 36 additions and 49 deletions.
2 changes: 1 addition & 1 deletion Compiler/BackEnd/EvaluateFunctions.mo
Expand Up @@ -1001,7 +1001,7 @@ algorithm
// assemble the path-name
s = Absyn.pathString(path);
chars = stringListStringChar(s);
chars = List.delete(chars, 1);
chars = listDelete(chars, 1);
s = stringCharListString(chars);
path = Absyn.stringPath(s+&"_eval"+&intString(idx));
// update the type
Expand Down
24 changes: 12 additions & 12 deletions Compiler/BackEnd/HpcOmEqSystems.mo
Expand Up @@ -879,8 +879,8 @@ algorithm
case({},_,_,_,_,_)
equation
//completed
hs_i_lstTmp = List.delete(hs_i_lstIn,1);
a_i_lstTmp = List.delete(a_i_lstIn,1);
hs_i_lstTmp = listDelete(hs_i_lstIn,1);
a_i_lstTmp = listDelete(a_i_lstIn,1);
hs_i_lstTmp = listReverse(hs_i_lstTmp);
a_i_lstTmp = listReverse(a_i_lstTmp);
then
Expand Down Expand Up @@ -1073,8 +1073,8 @@ algorithm
case({},_,_,_,_)
// completed
equation
h_i_lstTmp = List.delete(h_i_lstIn, 1);
r_i_lstTmp = List.delete(r_i_lstIn, 1);
h_i_lstTmp = listDelete(h_i_lstIn, 1);
r_i_lstTmp = listDelete(r_i_lstIn, 1);
h_i_lstTmp = listReverse(h_i_lstTmp);
r_i_lstTmp = listReverse(r_i_lstTmp);
then
Expand Down Expand Up @@ -1268,7 +1268,7 @@ algorithm
str1 = "$xa"+&intString(tornSysIdx)+&intString(iValue);
_ = "$g"+&intString(tornSysIdx)+&intString(iValue);
tVarCRef = listGet(tVarCRefLstIn,iValue);
tVarCRefLst1 = List.delete(tVarCRefLstIn,iValue);
tVarCRefLst1 = listDelete(tVarCRefLstIn,iValue);
replTmp = BackendVarTransform.emptyReplacementsSized(size);
replTmp = replaceTVarWithReal(tVarCRef,1.0,replTmp);
replTmp = List.fold1(tVarCRefLst1,replaceTVarWithReal,0.0,replTmp);
Expand Down Expand Up @@ -1599,7 +1599,7 @@ algorithm
vars = BackendVariable.listVar(varLstIn);
vars = BackendVariable.removeCref(cref,vars);
varLst = BackendVariable.varList(vars);
eqLst = List.delete(eqLstIn, eqIdx);
eqLst = listDelete(eqLstIn, eqIdx);
repl = BackendVarTransform.addReplacement(replIn,cref,constExp,NONE());
then
(eqLst,varLst,repl,true);
Expand Down Expand Up @@ -1664,7 +1664,7 @@ algorithm
true = BackendVariable.existsVar(cref1,vars,false);
vars = BackendVariable.removeCref(cref1,vars);
varLst = BackendVariable.varList(vars);
eqLst = List.delete(eqLstIn, eqIdx);
eqLst = listDelete(eqLstIn, eqIdx);
newExp = DAE.RCONST(0.0);
repl = BackendVarTransform.addReplacement(replIn,cref1,newExp,NONE());
then
Expand All @@ -1678,7 +1678,7 @@ algorithm
true = BackendVariable.existsVar(cref1,vars,false);
vars = BackendVariable.removeCref(cref1,vars);
varLst = BackendVariable.varList(vars);
eqLst = List.delete(eqLstIn, eqIdx);
eqLst = listDelete(eqLstIn, eqIdx);
newExp = DAE.RCONST(0.0);
repl = BackendVarTransform.addReplacement(replIn,cref1,newExp,NONE());
then
Expand Down Expand Up @@ -1719,7 +1719,7 @@ algorithm
true = BackendVariable.existsVar(cref1,vars,false);
vars = BackendVariable.removeCref(cref1,vars);
varLst = BackendVariable.varList(vars);
eqLst = List.delete(eqLstIn, eqIdx);
eqLst = listDelete(eqLstIn, eqIdx);
newExp = DAE.UNARY(DAE.UMINUS(DAE.T_REAL_DEFAULT),exp2);
//print("checkForNegAlias: replace "+&ComponentReference.printComponentRefStr(cref2)+&" with "+&ExpressionDump.printExpStr(newExp)+&"\n");
repl = BackendVarTransform.addReplacement(replIn,cref1,newExp,NONE());
Expand All @@ -1732,7 +1732,7 @@ algorithm
true = BackendVariable.existsVar(cref2,vars,false);
vars = BackendVariable.removeCref(cref2,vars);
varLst = BackendVariable.varList(vars);
eqLst = List.delete(eqLstIn, eqIdx);
eqLst = listDelete(eqLstIn, eqIdx);
newExp = DAE.UNARY(DAE.UMINUS(DAE.T_REAL_DEFAULT),exp1);
//print("checkForNegAlias: replace "+&ComponentReference.printComponentRefStr(cref2)+&" with - "+&ExpressionDump.printExpStr(newExp)+&"\n");
repl = BackendVarTransform.addReplacement(replIn,cref2,newExp,NONE());
Expand Down Expand Up @@ -1774,7 +1774,7 @@ algorithm
//print("checkForPosAlias: replace "+&ComponentReference.printComponentRefStr(cref1)+&" with "+&ExpressionDump.printExpStr(exp2)+&"\n");
vars = BackendVariable.removeCref(cref1,vars);
varLst = BackendVariable.varList(vars);
eqLst = List.delete(eqLstIn, eqIdx);
eqLst = listDelete(eqLstIn, eqIdx);
repl = BackendVarTransform.addReplacement(replIn,cref1,exp2,NONE());
then
(eqLst,varLst,repl,true);
Expand All @@ -1786,7 +1786,7 @@ algorithm
//print("checkForPosAlias: replace "+&ComponentReference.printComponentRefStr(cref2)+&" with "+&ExpressionDump.printExpStr(exp1)+&"\n");
vars = BackendVariable.removeCref(cref2,vars);
varLst = BackendVariable.varList(vars);
eqLst = List.delete(eqLstIn, eqIdx);
eqLst = listDelete(eqLstIn, eqIdx);
repl = BackendVarTransform.addReplacement(replIn,cref2,exp1,NONE());
then
(eqLst,varLst,repl,true);
Expand Down
4 changes: 2 additions & 2 deletions Compiler/BackEnd/HpcOmTaskGraph.mo
Expand Up @@ -1096,7 +1096,7 @@ algorithm
varTpl = listGet(varLstIn,varIdx);
(var,_) = varTpl;
true = List.isMemberOnTrue(var,eventVarLst,intEq);
varLst = List.delete(varLstIn,varIdx);
varLst = listDelete(varLstIn,varIdx);
varLst = removeEventVars(eventVarLst,varLst,varIdx);
then
varLst;
Expand Down Expand Up @@ -3384,7 +3384,7 @@ algorithm
TASKGRAPHMETA(inComps = inComps, varCompMapping=varCompMapping, eqCompMapping=eqCompMapping, rootNodes = rootNodes, nodeNames =nodeNames,nodeDescs=nodeDescs, exeCosts = exeCosts, commCosts=commCosts, nodeMark=nodeMark) := graphDataIn;
allTheNodes := List.intRange(arrayLength(graphIn)); // to traverse the node indeces
oneChildren := findOneChildParents(allTheNodes,graphIn,doNotMerge,{{}},0); // paths of nodes with just one successor per node (extended: and endnodes with just one parent node)
oneChildren := List.delete(oneChildren,listLength(oneChildren)); // remove the empty startValue {}
oneChildren := listDelete(oneChildren,listLength(oneChildren)); // remove the empty startValue {}
oneChildren := List.removeOnTrue(1,compareListLengthOnTrue,oneChildren); // remove paths of length 1
//print("oneChildren "+&stringDelimitList(List.map(oneChildren,intLstString),"\n")+&"\n");
(graphOut,graphDataOut) := contractNodesInGraph(oneChildren,graphIn,graphDataIn);
Expand Down
4 changes: 2 additions & 2 deletions Compiler/BackEnd/OnRelaxation.mo
Expand Up @@ -2452,8 +2452,8 @@ algorithm
equation
(v::{},i::{}) = BackendVariable.getVar(cr,vars);
p = List.position(i, vindxs);
ilst = List.delete(vindxs, p+1);
vlst = List.delete(inVarLst, p+1);
ilst = listDelete(vindxs, p+1);
vlst = listDelete(inVarLst, p+1);
_ = arrayUpdate(vararray,index,SOME(v));
then
sortVarsforOrder1(rest,index+1,vlst,ilst,vararray,vars);
Expand Down
4 changes: 2 additions & 2 deletions Compiler/BackEnd/ResolveLoops.mo
Expand Up @@ -1737,9 +1737,9 @@ protected
list<Integer> path;
Integer last;
algorithm
path := List.delete(pathIn, 1);
path := listDelete(pathIn, 1);
last := listLength(path);
path := List.delete(path, last);
path := listDelete(path, last);
loopsOut := List.map1(closingPaths,listAppend,path);
end connectPaths;

Expand Down
4 changes: 2 additions & 2 deletions Compiler/BackEnd/Tearing.mo
Expand Up @@ -1795,9 +1795,9 @@ algorithm
equation
true = intLe(indx, listLength(rowIn));
b = intLe(listGet(rowIn,indx),0);
indx = Util.if_(b,indx-1,indx);
indx = Util.if_(b,indx,indx+1);
newLst = Debug.bcallret2(b,listDelete,rowIn,indx,rowIn);
then deleteNegativeEntries(newLst,indx+1);
then deleteNegativeEntries(newLst,indx);
case(_,_)
equation
true = intGt(index,listLength(rowIn));
Expand Down
4 changes: 2 additions & 2 deletions Compiler/FrontEnd/MetaModelicaBuiltin.mo
Expand Up @@ -635,11 +635,11 @@ end listHead;

function listDelete<A> "O(index)"
input List<A> inLst;
input Integer index "zero-based index (TODO: make it a one-based index)" ;
input Integer index "one-based index" ;
output List<A> outLst;
external "builtin";
annotation(Documentation(info="<html>
<p>listDelete is using a zero-based index. This will be fixed as soon as the rml version is gone. Until then List.delete should be used.</p>
<p>listDelete is using a zero-based index. This will be fixed as soon as the rml version is gone. Until then listDelete should be used.</p>
</html>"));
end listDelete;

Expand Down
2 changes: 1 addition & 1 deletion Compiler/FrontEnd/Static.mo
Expand Up @@ -4349,7 +4349,7 @@ protected
algorithm
types := List.map(inProps, Types.getPropType);
dims := List.map(types, Types.getDimensions);
dims := List.map1(dims, List.delete, dimException);
dims := List.map1(dims, listDelete, dimException);
res := sameDimensions2(dims);
end sameDimensionsExceptionDimX;

Expand Down
14 changes: 2 additions & 12 deletions Compiler/Util/List.mo
Expand Up @@ -8737,16 +8737,6 @@ algorithm
end match;
end select2_tail;

public function delete
"This is a wrapper of the built-in function listDelete as a workaround. It
will be removed as soon as the rml version got removed."
input list<ElementType> lst;
input Integer index "one-based index" ;
output list<ElementType> result;
algorithm
result := listDelete(lst, index-1);
end delete;

public function deleteMember
"Takes a list and a value, and deletes the first occurence of the value in the
list. Example: deleteMember({1, 2, 3, 2}, 2) => {1, 3, 2}"
Expand All @@ -8756,7 +8746,7 @@ public function deleteMember
algorithm
outList := matchcontinue(inList, inElement)

case (_, _) then listDelete(inList, position(inElement, inList));
case (_, _) then listDelete(inList, position(inElement, inList)+1);
else inList;

end matchcontinue;
Expand All @@ -8768,7 +8758,7 @@ public function deleteMemberF
input ElementType inElement;
output list<ElementType> outList;
algorithm
outList := listDelete(inList, position(inElement, inList));
outList := listDelete(inList, position(inElement, inList)+1);
end deleteMemberF;

public function deleteMemberOnTrue
Expand Down
23 changes: 10 additions & 13 deletions SimulationRuntime/c/meta/meta_modelica_builtin.c
Expand Up @@ -515,29 +515,25 @@ modelica_metatype boxptr_listNth(threadData_t *threadData,modelica_metatype lst,
return boxptr_listGet(threadData,lst,mmc_mk_icon(mmc_unbox_integer(i)+1));
}

modelica_metatype boxptr_listDelete(threadData_t *threadData,modelica_metatype lst, modelica_metatype iix)
modelica_metatype boxptr_listDelete(threadData_t *threadData, modelica_metatype lst, modelica_metatype iix)
{
/* TODO: If we assume the index exists we can do this in a much better way */
int ix = mmc_unbox_integer(iix);
modelica_metatype *tmpArr = NULL;
int i = 0;

if (ix < 0) {
if (ix <= 0) {
MMC_THROW_INTERNAL();
}
if (ix == 0) {
if (listEmpty(lst)) {
MMC_THROW_INTERNAL();
}
return MMC_CDR(lst);
}
tmpArr = (modelica_metatype *) GC_malloc(sizeof(modelica_metatype)*(ix)); /* We know the size of the first part of the list (+1 for the element to delete) */

tmpArr = (modelica_metatype *) GC_malloc(sizeof(modelica_metatype)*(ix-1)); /* We know the size of the first part of the list */
if (tmpArr == NULL) {
fprintf(stderr, "%s:%d: malloc failed", __FILE__, __LINE__);
EXIT(1);
}
for (i=0; i<ix; i++) {
if (MMC_NILTEST(lst)) {

for (i=0; i<ix-1; i++) {
if (listEmpty(lst)) {
if (tmpArr) {
GC_free(tmpArr);
}
Expand All @@ -546,13 +542,14 @@ modelica_metatype boxptr_listDelete(threadData_t *threadData,modelica_metatype l
tmpArr[i] = MMC_CAR(lst);
lst = MMC_CDR(lst);
}

if (listEmpty(lst)) {
GC_free(tmpArr);
MMC_THROW_INTERNAL();
}

lst = MMC_CDR(lst);
for (i=ix-1; i>=0; i--) {

for (i=ix-2; i>=0; i--) {
lst = mmc_mk_cons(tmpArr[i], lst);
}
GC_free(tmpArr);
Expand Down

0 comments on commit 76df8c9

Please sign in to comment.