Opened 18 years ago

Last modified 18 years ago

#114 closed defect (fixed)

function translation error.

Reported by: Adrian Pop Owned by: Adrian Pop
Priority: critical Milestone:
Component: Version:
Keywords: Cc: Adrian Pop, Adrian Pop

Description


Change History (2)

comment:1 by Adrian Pop, 18 years ago

The function below translates wrongly. The script:
loadFile("function-test.mo");
z:=CalcTrapezium(1,1,1,1,0.5,0.5,4,1,0.5);

gives this error (tmp8 is declared twice):

$ ../build/bin/omc function-test.mos
CalcTrapezium.c: In function `_CalcTrapezium':
CalcTrapezium.c:40: error: redeclaration of 'tmp8' with no linkage
CalcTrapezium.c:38: error: previous declaration of 'tmp8' was here
CalcTrapezium.c: In function `_CalcTrapezium':
CalcTrapezium.c:46: error: redeclaration of 'tmp8' with no linkage
CalcTrapezium.c:44: error: previous declaration of 'tmp8' was here
#|Execution failed!
Execution failed!

function-test.mo:


function CalcTrapezium Incomplete!!

input Real acc1;
input Real acc2;
input Real dec1;
input Real dec2;
input Real pv_acc;
input Real pv_dec;
input Real adv;
input Real vel;
input Real period;
output Real[3] data;

protected

Real accCount;
Real decCount;
Real remaining;
Real tAcc1;
Real tAcc2;
Real tDec1;
Real tDec2;
Real accVal;
Real decVal;
Real nextVal;

algorithm

accCount := 0;
decCount := 0;
remaining := adv;
tAcc1 := vel*pv_acc/acc1;
tAcc2 := vel*(1-pv_acc)/acc2;
tDec1 := vel*(1-pv_dec)/dec1;
tDec2 := vel*pv_dec/dec2;
accVal := 0;
decVal := if (decCount+1)*period <= tDec2 then (decCount+1)*period*dec2

else if (decCount+1)*period <= tDec2+tDec1 then (vel*pv_dec)+

((decCount+1)*period-tDec2)*dec1

else vel;

nextVal := if accVal <= decVal then accVal else decVal;
while remaining >= nextVal*period loop

if accVal <= decVal then

accCount := accCount+1;
remaining := remaining-(accVal*period);
accVal := if accCount*period <= tAcc1 then accCount*period*acc1

else if accCount*period <= tAcc1+tAcc2 then

(vel*pv_acc)+((accCount*period)-tAcc1)*acc2

else vel;

else

decCount := decCount+1;
remaining := remaining-(decVal*period);
decVal := if (decCount+1)*period <= tDec2 then (decCount+1)

*period*dec2

else if (decCount+1)*period <= tDec2+tDec1 then

(vel*pv_dec)+((decCount+1)*period-tDec2)*dec1

else vel;

decVal := decVal+1;

end if;
nextVal := if accVal <= decVal then accVal else decVal;

end while;
data[1] := accCount;
data[2] := decCount;
data[3] := remaining;

end CalcTrapezium;

comment:2 by Adrian Pop, 18 years ago

Fixed in revision 2737.
The numbering of temporary variables was wrong in Codegen.generateElse.

Note: See TracTickets for help on using tickets.