Opened 14 years ago

Last modified 13 years ago

#1559 closed defect (fixed)

Array indexing inside a function

Reported by: asodja Owned by: asodja
Priority: high Milestone:
Component: Instantiation Version: trunk
Keywords: Cc: asodja, Martin Sjölund

Description

In the attachment are three variations of the same function (whithout change of functionality) gives three different errors.

  1. When identifier 'end' is used as index (in example SimpsonTest_1.mo), the following error is printed:
    [SimCodeC.tpl:4220:14-4220:14:writable] Error: Template error: Unknown expression: end
    
  1. When first the value of {{size(vals,1)}} is assigned to a variable (in example SimpsonTest_2.mo) and then the variable is used for indexing is the error:
    [SimpsonTest_2.mo:13:7-14:54:writable] Error: Illegal subscript [3:2:nvals - 1] for dimensions : in component <NO COMPONENT>
    [SimpsonTest_2.mo:13:7-14:54:writable] Error: Variable vals[3:2:nvals - 1] not found in scope SimpsonTest.simpson
    [SimpsonTest_2.mo:13:7-14:54:writable] Error: Illegal subscript [3:2:nvals - 1] for dimensions : in component <NO COMPONENT>
    [SimpsonTest_2.mo:13:7-14:54:writable] Error: Variable vals[3:2:nvals - 1] not found in scope SimpsonTest.simpson
    Error: Error occured while flattening model SimpsonTest
    [SimpsonTest_2.mo:13:7-14:54:writable] Error: Illegal subscript [3:2:nvals - 1] for dimensions : in component <NO COMPONENT>
    [SimpsonTest_2.mo:13:7-14:54:writable] Error: Variable vals[3:2:nvals - 1] not found in scope SimpsonTest.simpson
    [SimpsonTest_2.mo:13:7-14:54:writable] Error: Illegal subscript [3:2:nvals - 1] for dimensions : in component <NO COMPONENT>
    [SimpsonTest_2.mo:13:7-14:54:writable] Error: Variable vals[3:2:nvals - 1] not found in scope SimpsonTest.simpson
    Error: Tried to use function .SimpsonTest.simpson, but it was not instantiated.
    [SimpsonTest_2.mo:13:7-14:54:writable] Error: Illegal subscript [3:2:nvals - 1] for dimensions : in component <NO COMPONENT>
    [SimpsonTest_2.mo:13:7-14:54:writable] Error: Variable vals[3:2:nvals - 1] not found in scope SimpsonTest.simpson
    [SimpsonTest_2.mo:13:7-14:54:writable] Error: Illegal subscript [3:2:nvals - 1] for dimensions : in component <NO COMPONENT>
    [SimpsonTest_2.mo:13:7-14:54:writable] Error: Variable vals[3:2:nvals - 1] not found in scope SimpsonTest.simpson
    Error: Tried to use function .SimpsonTest.simpson, but it was not instantiated.
    
  1. When a call to {{size(vals,1)}} is insert directly in array subscripts (example SimpsonTest_3.mo), the error is:
    Error: Error building simulator. Buildlog: gcc -I"/home/anton/openmodelica/trunk/build/include/omc"  -O0 -falign-functions -march=native -mfpmath=sse  -c -o SimpsonTest_simpson.o SimpsonTest_simpson.c
    SimpsonTest_simpson.c: In function ‘_SimpsonTest_simpson’:
    SimpsonTest_simpson.c:23: error: ‘sum_rettype’ undeclared (first use in this function)
    SimpsonTest_simpson.c:23: error: (Each undeclared identifier is reported only once
    SimpsonTest_simpson.c:23: error: for each function it appears in.)
    SimpsonTest_simpson.c:23: error: expected ‘;’ before ‘tmp7’
    SimpsonTest_simpson.c:27: error: expected ‘;’ before ‘tmp11’
    SimpsonTest_simpson.c:30: error: expected ‘;’ before ‘tmp14’
    SimpsonTest_simpson.c:41: error: expected expression before ‘,’ token
    SimpsonTest_simpson.c:42: error: expected expression before ‘)’ token
    SimpsonTest_simpson.c:44: error: ‘tmp7’ undeclared (first use in this function)
    SimpsonTest_simpson.c:45: error: expected expression before ‘,’ token
    SimpsonTest_simpson.c:46: error: expected expression before ‘)’ token
    SimpsonTest_simpson.c:48: error: ‘tmp11’ undeclared (first use in this function)
    SimpsonTest_simpson.c:56: error: ‘tmp14’ undeclared (first use in this function)
    make: *** [SimpsonTest_simpson] Error 1
    

Attachments (3)

SimpsonTest_1.mo (655 bytes ) - added by asodja 14 years ago.
SimpsonTest_2.mo (707 bytes ) - added by asodja 14 years ago.
SimpsonTest_3.mo (680 bytes ) - added by asodja 14 years ago.

Download all attachments as: .zip

Change History (5)

by asodja, 14 years ago

Attachment: SimpsonTest_3.mo added

comment:1 by Martin Sjölund, 13 years ago

The first test should be fixed by removing DAE.END (replace with size(cr,dim)). This works for more cases, and can be constant evaluated for as many cases as DAE.END could handle before...

comment:2 by Martin Sjölund, 13 years ago

Some fixes in r9406

comment:3 by Martin Sjölund, 13 years ago

Number 2 is not a bug at all. It comes from nvars being defined and nvals being used.

comment:4 by Martin Sjölund, 13 years ago

Code generation fixed in r9442.

Note: See TracTickets for help on using tickets.