Skip to content

Commit

Permalink
- fix for SimCodeUtil.getUnrolledArrayIndex()
Browse files Browse the repository at this point in the history
  • Loading branch information
vwaurich authored and OpenModelica-Hudson committed Nov 25, 2015
1 parent fe52534 commit 72f90e7
Showing 1 changed file with 14 additions and 10 deletions.
24 changes: 14 additions & 10 deletions Compiler/SimCode/SimCodeUtil.mo
Expand Up @@ -6369,33 +6369,37 @@ public function simVarString
algorithm
s := match(inVar)
local
Boolean isProtected;
Integer i;
DAE.ComponentRef name, name2;
Option<DAE.Exp> init;
Option<DAE.ComponentRef> arrCref;
Option<Integer> variable_index;
SimCodeVar.AliasVariable aliasvar;
String s1, s2, s3;
String s1, s2, s3, sProt;
list<String> numArrayElement;
case (SimCodeVar.SIMVAR(name= name, aliasvar = SimCodeVar.NOALIAS(), index = i, initialValue=init, arrayCref=arrCref,variable_index=variable_index, numArrayElement=numArrayElement))
case (SimCodeVar.SIMVAR(name= name, aliasvar = SimCodeVar.NOALIAS(), index = i, initialValue=init, arrayCref=arrCref,variable_index=variable_index, numArrayElement=numArrayElement, isProtected=isProtected))
equation
s1 = ComponentReference.printComponentRefStr(name);
if Util.isSome(arrCref) then s3 = " \tarrCref:"+ComponentReference.printComponentRefStr(Util.getOption(arrCref)); else s3="\tno arrCref"; end if;
s = "index: "+intString(i)+": "+s1+" (no alias) "+" initial: "+ExpressionDump.printOptExpStr(init) + s3 + " index:("+printVarIndx(variable_index)+")" +" [" + stringDelimitList(numArrayElement,",")+"] ";
sProt = if isProtected then " protected " else "";
s = "index: "+intString(i)+": "+s1+" (no alias) "+sProt+" initial: "+ExpressionDump.printOptExpStr(init) + s3 + " index:("+printVarIndx(variable_index)+")" +" [" + stringDelimitList(numArrayElement,",")+"] ";
then s;
case (SimCodeVar.SIMVAR(name= name, aliasvar = SimCodeVar.ALIAS(varName = name2), arrayCref=arrCref,variable_index=variable_index, numArrayElement=numArrayElement))
case (SimCodeVar.SIMVAR(name= name, aliasvar = SimCodeVar.ALIAS(varName = name2), arrayCref=arrCref,variable_index=variable_index, numArrayElement=numArrayElement, isProtected=isProtected))
equation
s1 = ComponentReference.printComponentRefStr(name);
s2 = ComponentReference.printComponentRefStr(name2);
sProt = if isProtected then " protected "else "";
if Util.isSome(arrCref) then s3 = " arrCref:"+ComponentReference.printComponentRefStr(Util.getOption(arrCref)); else s3=""; end if;
s = "index: "+printVarIndx(variable_index) +": "+s1+" (alias: "+s2+s3+") "+" [" + stringDelimitList(numArrayElement,",")+"] ";
s = "index: "+printVarIndx(variable_index) +": "+s1+" (alias: "+s2+s3+") "+sProt+" [" + stringDelimitList(numArrayElement,",")+"] ";
then s;
case (SimCodeVar.SIMVAR(name= name, aliasvar = SimCodeVar.NEGATEDALIAS(varName = name2), arrayCref=arrCref,variable_index=variable_index, numArrayElement=numArrayElement))
case (SimCodeVar.SIMVAR(name= name, aliasvar = SimCodeVar.NEGATEDALIAS(varName = name2), arrayCref=arrCref,variable_index=variable_index, numArrayElement=numArrayElement, isProtected=isProtected))
equation
s1 = ComponentReference.printComponentRefStr(name);
s2 = ComponentReference.printComponentRefStr(name2);
sProt = if isProtected then " protected "else "";
if Util.isSome(arrCref) then s3 = " arrCref:"+ComponentReference.printComponentRefStr(Util.getOption(arrCref)); else s3=""; end if;
s = "index:("+printVarIndx(variable_index)+")"+s1+" (negated alias: "+s2+s3+") "+" [" + stringDelimitList(numArrayElement,",")+"] ";
s = "index:("+printVarIndx(variable_index)+")"+s1+" (negated alias: "+s2+s3+") "+sProt+" [" + stringDelimitList(numArrayElement,",")+"] ";
then s;
end match;
end simVarString;
Expand Down Expand Up @@ -9807,8 +9811,8 @@ algorithm
arrayDimensions = List.map(List.lastN(numArrayElement,listLength(arraySubscripts)), stringInt);
varIndices = arrayCreate(List.fold(arrayDimensions, intMul, 1), 0);
end if;
//print("Num of array elements {" + stringDelimitList(List.map(arrayDimensions, intString), ",") + "} : " + intString(listLength(arraySubscripts)) + "\n");
((arrayIndex,_,_)) = List.fold(listReverse(arraySubscripts), getUnrolledArrayIndex, (0, 1, listReverse(arrayDimensions)));
//print("Num of array elements {" + stringDelimitList(List.map(arrayDimensions, intString), ",") + "} : " + intString(listLength(arraySubscripts)) + "arraySubs "+ExpressionDump.printSubscriptLstStr(arraySubscripts) + "arrayDimensions[ "+stringDelimitList(List.map(arrayDimensions,intString),",")+"]\n");
((arrayIndex,_,_)) = List.fold(arraySubscripts, getUnrolledArrayIndex, (0, 1, arrayDimensions));
arrayIndex = arrayIndex + 1;
//print("VarIndices: " + intString(arrayLength(varIndices)) + " arrayIndex: " + intString(arrayIndex) + " varIndex: " + intString(varIdx) + "\n");
varIndices = arrayUpdate(varIndices, arrayIndex, varIdx);
Expand Down Expand Up @@ -11639,7 +11643,7 @@ algorithm
case (_, _, "Cpp") equation
valueReference = getVarIndexByMapping(inSimCode.varToArrayIndexMapping, inSimVar.name, "-1");
if stringEqual(valueReference, "-1") then
Error.addInternalError("invalid return value from getVarIndexByMapping", sourceInfo());
Error.addInternalError("invalid return value from getVarIndexByMapping for "+simVarString(inSimVar), sourceInfo());
end if;
then valueReference;
case (SimCodeVar.SIMVAR(aliasvar = SimCodeVar.ALIAS(varName = cref)), _, _) then
Expand Down

0 comments on commit 72f90e7

Please sign in to comment.