Skip to content

Commit

Permalink
- listDelete is using zero-based indexing instead of one-based indexi…
Browse files Browse the repository at this point in the history
…ng as it should use. List.delete is added as a workaround.

  - for now, List.delete should be used instead of listDelete
  - I will push my fix to listDelete as soon as the rml stuff is gone


git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@21791 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
lochel committed Aug 7, 2014
1 parent 27aed16 commit e11cec6
Show file tree
Hide file tree
Showing 8 changed files with 38 additions and 24 deletions.
2 changes: 1 addition & 1 deletion Compiler/BackEnd/EvaluateFunctions.mo
Expand Up @@ -995,7 +995,7 @@ algorithm
// assemble the path-name
s = Absyn.pathString(path);
chars = stringListStringChar(s);
chars = listDelete(chars,0);
chars = List.delete(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 @@ -803,8 +803,8 @@ algorithm
case({},_,_,_,_,_)
equation
//completed
hs_i_lstTmp = listDelete(hs_i_lstIn,0);
a_i_lstTmp = listDelete(a_i_lstIn,0);
hs_i_lstTmp = List.delete(hs_i_lstIn,1);
a_i_lstTmp = List.delete(a_i_lstIn,1);
hs_i_lstTmp = listReverse(hs_i_lstTmp);
a_i_lstTmp = listReverse(a_i_lstTmp);
then
Expand Down Expand Up @@ -997,8 +997,8 @@ algorithm
case({},_,_,_,_)
// completed
equation
h_i_lstTmp = listDelete(h_i_lstIn,0);
r_i_lstTmp = listDelete(r_i_lstIn,0);
h_i_lstTmp = List.delete(h_i_lstIn, 1);
r_i_lstTmp = List.delete(r_i_lstIn, 1);
h_i_lstTmp = listReverse(h_i_lstTmp);
r_i_lstTmp = listReverse(r_i_lstTmp);
then
Expand Down Expand Up @@ -1194,7 +1194,7 @@ algorithm
str1 = "$xa"+&intString(tornSysIdx)+&intString(iValue);
_ = "$g"+&intString(tornSysIdx)+&intString(iValue);
tVarCRef = listGet(tVarCRefLstIn,iValue);
tVarCRefLst1 = listDelete(tVarCRefLstIn,iValue-1);
tVarCRefLst1 = List.delete(tVarCRefLstIn,iValue);
replTmp = BackendVarTransform.emptyReplacementsSized(size);
replTmp = replaceTVarWithReal(tVarCRef,1.0,replTmp);
replTmp = List.fold1(tVarCRefLst1,replaceTVarWithReal,0.0,replTmp);
Expand Down Expand Up @@ -1525,7 +1525,7 @@ algorithm
vars = BackendVariable.listVar(varLstIn);
vars = BackendVariable.removeCref(cref,vars);
varLst = BackendVariable.varList(vars);
eqLst = listDelete(eqLstIn, eqIdx-1);
eqLst = List.delete(eqLstIn, eqIdx);
repl = BackendVarTransform.addReplacement(replIn,cref,constExp,NONE());
then
(eqLst,varLst,repl,true);
Expand Down Expand Up @@ -1590,7 +1590,7 @@ algorithm
true = BackendVariable.existsVar(cref1,vars,false);
vars = BackendVariable.removeCref(cref1,vars);
varLst = BackendVariable.varList(vars);
eqLst = listDelete(eqLstIn, eqIdx-1);
eqLst = List.delete(eqLstIn, eqIdx);
newExp = DAE.RCONST(0.0);
repl = BackendVarTransform.addReplacement(replIn,cref1,newExp,NONE());
then
Expand All @@ -1604,7 +1604,7 @@ algorithm
true = BackendVariable.existsVar(cref1,vars,false);
vars = BackendVariable.removeCref(cref1,vars);
varLst = BackendVariable.varList(vars);
eqLst = listDelete(eqLstIn, eqIdx-1);
eqLst = List.delete(eqLstIn, eqIdx);
newExp = DAE.RCONST(0.0);
repl = BackendVarTransform.addReplacement(replIn,cref1,newExp,NONE());
then
Expand Down Expand Up @@ -1645,7 +1645,7 @@ algorithm
true = BackendVariable.existsVar(cref1,vars,false);
vars = BackendVariable.removeCref(cref1,vars);
varLst = BackendVariable.varList(vars);
eqLst = listDelete(eqLstIn, eqIdx-1);
eqLst = List.delete(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 @@ -1658,7 +1658,7 @@ algorithm
true = BackendVariable.existsVar(cref2,vars,false);
vars = BackendVariable.removeCref(cref2,vars);
varLst = BackendVariable.varList(vars);
eqLst = listDelete(eqLstIn, eqIdx-1);
eqLst = List.delete(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 @@ -1700,7 +1700,7 @@ algorithm
//print("checkForPosAlias: replace "+&ComponentReference.printComponentRefStr(cref1)+&" with "+&ExpressionDump.printExpStr(exp2)+&"\n");
vars = BackendVariable.removeCref(cref1,vars);
varLst = BackendVariable.varList(vars);
eqLst = listDelete(eqLstIn, eqIdx-1);
eqLst = List.delete(eqLstIn, eqIdx);
repl = BackendVarTransform.addReplacement(replIn,cref1,exp2,NONE());
then
(eqLst,varLst,repl,true);
Expand All @@ -1712,7 +1712,7 @@ algorithm
//print("checkForPosAlias: replace "+&ComponentReference.printComponentRefStr(cref2)+&" with "+&ExpressionDump.printExpStr(exp1)+&"\n");
vars = BackendVariable.removeCref(cref2,vars);
varLst = BackendVariable.varList(vars);
eqLst = listDelete(eqLstIn, eqIdx-1);
eqLst = List.delete(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 @@ -1053,7 +1053,7 @@ algorithm
varTpl = listGet(varLstIn,varIdx);
(var,_) = varTpl;
true = List.isMemberOnTrue(var,eventVarLst,intEq);
varLst = listDelete(varLstIn,varIdx-1);
varLst = List.delete(varLstIn,varIdx);
varLst = removeEventVars(eventVarLst,varLst,varIdx);
then
varLst;
Expand Down Expand Up @@ -3360,7 +3360,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 := listDelete(oneChildren,listLength(oneChildren)-1); // remove the empty startValue {}
oneChildren := List.delete(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 @@ -2456,8 +2456,8 @@ algorithm
equation
(v::{},i::{}) = BackendVariable.getVar(cr,vars);
p = List.position(i, vindxs);
ilst = listDelete(vindxs,p);
vlst = listDelete(inVarLst,p);
ilst = List.delete(vindxs, p+1);
vlst = List.delete(inVarLst, p+1);
_ = arrayUpdate(vararray,index,SOME(v));
then
sortVarsforOrder1(rest,index+1,vlst,ilst,vararray,vars);
Expand Down
6 changes: 3 additions & 3 deletions Compiler/BackEnd/ResolveLoops.mo
Expand Up @@ -1740,9 +1740,9 @@ protected
list<Integer> path;
Integer last;
algorithm
path := listDelete(pathIn,0);
last := intSub(listLength(path),1);
path := listDelete(path,last);
path := List.delete(pathIn, 1);
last := listLength(path);
path := List.delete(path, last);
loopsOut := List.map1(closingPaths,listAppend,path);
end connectPaths;

Expand Down
5 changes: 4 additions & 1 deletion Compiler/FrontEnd/MetaModelicaBuiltin.mo
Expand Up @@ -635,9 +635,12 @@ end listHead;

function listDelete<A> "O(index)"
input List<A> inLst;
input Integer index;
input Integer index "zero-based index (TODO: make it a 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>
</html>"));
end listDelete;

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

Expand Down
15 changes: 13 additions & 2 deletions Compiler/Util/List.mo
Expand Up @@ -7262,10 +7262,11 @@ end threadMapFold_tail;
public function position
"Takes a value and a list, and returns the position of the first list element
that whose value is equal to the given value. The index starts at zero.
Example: position(2, {0, 1, 2, 3}) => 2"
Example: position(2, {0, 1, 2, 3}) => 2
TODO: make the index start at one"
input ElementType inElement;
input list<ElementType> inList;
output Integer outPosition;
output Integer outPosition "zero-based index" ;
algorithm
outPosition := position_impl(inElement, inList, 0);
end position;
Expand Down Expand Up @@ -8650,6 +8651,16 @@ 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 Down

0 comments on commit e11cec6

Please sign in to comment.