source: tests/tuplearray.cfa @ 81e768d

Last change on this file since 81e768d was 81e768d, checked in by Michael Brooks <mlbrooks@…>, 3 weeks ago

Fix #276; add support for c-array parameters using dependent lengths.

Without this fix, declarations like

void f( int m, int n, float[m][n] );

would either

  • generate bad C code, with unmangled variable names appearing in the function definition, or
  • refuse to resolve a valid-c call of such a function.

tests/array-collections/c-dependent: add direct tests of such cases
tests/tuplearray: activate and expand cases which were blocked on #276
tests/array: activate case fm5y, which was blocked on #276; [noise] adjust source line numbers in .expect
tests/typedefRedef: expand coverage of "error, an array detail is different" cases; [noise] adjust source line numbers in .expect
tests/functions: [noise] adjust .expect to have resolved array sizes (extra casts) in the diffed code dump

The fix is:

  • (ResolvExpr/ResolveTypeof?, ResolvExpr/Resolver?) Resolve the dimension expressions, where they were missed.
  • (ResolvExpr/Resolver?) Prevent dimension expressions that are bound to other parameters from escaping in the function's type, to where they are out of scope. In the f example above, redact the type shown to callers from void (*)(int, int, float[m][n]) to void (*)(int, int, float[][*]).
  • (ResolvExpr/Unify?) Relax the matching rules for such a type, when used at a call site, letting the patameters wildcard type match with the concrete type in scope at the caller's side.
  • (Validate/ReplaceTypedef?) Apply the former, stricter matching rules to the one place where they are still needed: detecting inconsistent typedefs.
  • Property mode set to 100644
File size: 823 bytes
Line 
1#include <fstream.hfa>
2
3[void] bar1( size_t size, [10] [int,int] f ) {
4        for ( i; size ) f[i] = [1, 2];
5}
6[void] bar2( * [int,int] f );
7
8[void] bar3( [][10] [int,int] f );
9[void] bar4( [const *] [int,int] f );
10[void] bar5( [const 3] [int,int] f );
11//[void] bar6( [static 3] [int,int] f );
12[void] bar7( [3] [int,int] f );
13
14[void] bar8( [3][10] [int,int] f );
15[void] bar9( [3]* [int,int] f );
16
17[void] bar10( * [3] [int,int] f );
18
19[void] bar11( [3][10] [int,int] f );
20[void] bar12( * [3][10] [int,int] f );
21
22[void] foo1( [10] [int,int] f ) {
23        for ( i; 10 ) f[i] = [1, 2];
24}
25[void] foo2( size_t size, [size] [int,int] f ) {
26        for ( i; size ) f[i] = [2, 4];
27}
28
29int main() {
30        [10] [int,int] arr;
31//      [int,int] arr[10];      // unimplemented
32
33        foo1( arr );
34        for ( i; 10 ) sout | arr[i];
35
36        foo2( 10, arr );
37        for ( i; 10 ) sout | arr[i];
38}
Note: See TracBrowser for help on using the repository browser.