Skip to content

Commit

Permalink
- BaseHashTable.mo: print also key string in case of an error
Browse files Browse the repository at this point in the history
- Util.mo: add function consN to concate n times an ellement

git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@12193 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
Jens Frenkel committed Jun 23, 2012
1 parent 35225bb commit 4649fe6
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 1 deletion.
6 changes: 5 additions & 1 deletion Compiler/Util/BaseHashTable.mo
Expand Up @@ -137,6 +137,8 @@ algorithm
Value value;
FuncsTuple fntpl;
FuncHash hashFunc;
FuncKeyString keystrFunc;
String s;

// Adding when not existing previously
case ((v as (key,value)),(hashTable as (hashvec,varr,bsize,n,fntpl as (hashFunc,_,_,_))))
Expand All @@ -159,12 +161,14 @@ algorithm
varr_1 = valueArraySetnth(varr, indx, newv);
then ((hashvec,varr_1,bsize,n,fntpl));

case ((v as (key,value)),(hashTable as (hashvec,varr,bsize,n,(hashFunc,_,_,_))))
case ((v as (key,value)),(hashTable as (hashvec,varr,bsize,n,(hashFunc,_,keystrFunc,_))))
equation
print("- BaseHashTable.add failed: ");
print("bsize: ");
print(intString(bsize));
print(" key: ");
s = keystrFunc(key);
print(s +& " Hash: ");
hval = hashFunc(key,bsize);
print(intString(hval));
print("\n");
Expand Down
33 changes: 33 additions & 0 deletions Compiler/Util/List.mo
Expand Up @@ -545,6 +545,39 @@ algorithm
end match;
end consOnBool;

public function consN
"concate n time inElement to the list:
n = 5, inElement=1, list={1,2} -> list={1,1,1,1,1,1,2}"
input Integer size;
input ElementType inElement;
input list<ElementType> inList;
output list<ElementType> outList;
algorithm
outList := matchcontinue(size,inElement,inList)
case(0,_,_) then inList;
case(_,_,_)
equation
true = intGt(size,0);
then
consN_impl(size,inElement,inList);
else then inList;
end matchcontinue;
end consN;

protected function consN_impl
"concate n time inElement to the list:
n = 5, inElement=1, list={1,2} -> list={1,1,1,1,1,1,2}"
input Integer size;
input ElementType inElement;
input list<ElementType> inList;
output list<ElementType> outList;
algorithm
outList := match(size,inElement,inList)
case(0,_,_) then inList;
else then consN(size-1,inElement,inElement::inList);
end match;
end consN_impl;

public function appendNoCopy
"This function handles special cases such as empty lists so it does not copy
if any of the arguments are empty lists."
Expand Down

0 comments on commit 4649fe6

Please sign in to comment.