forked from alex-eg/sex
read every trailing array bound as a dimension
[m 1 2] lost its second index, and [int 2 3] came out int 2 x[3]. Each index now subscripts what the one before it gave, and [int 2 3] declares what it indexes, int[2][3]. An inline struct's fields, once more than one bound was looked for, were taken for one; their shape tells them apart.
This commit is contained in:
@@ -735,7 +735,32 @@
|
||||
(test-assert "after a qualified name too"
|
||||
(emits? (in-fn "(var b [mytype const N])") "mytype const b[N]"))
|
||||
(test-assert "but a qualifier alone still waits for the type"
|
||||
(emits? "(typedef mytype int) (struct s ((a [const mytype])))" "const mytype a[]")))
|
||||
(emits? "(typedef mytype int) (struct s ((a [const mytype])))" "const mytype a[]"))
|
||||
;; [m 1 2] is m[1][2], so [int 2 3] declares what it indexes. A
|
||||
;; second bound was taken for the last word of the element type
|
||||
(test-assert "every trailing bound is a dimension"
|
||||
(emits? (in-fn "(var m [int 2 3])") "int m[2][3];"))
|
||||
(test-assert "however many there are"
|
||||
(emits? (in-fn "(var c [u8 2 3 4])") "u8 c[2][3][4];"))
|
||||
(test-assert "named ones too"
|
||||
(emits? "(define N 2) (struct s ((a [* char N 3])))" "char * a[N][3]"))
|
||||
;; a list after a tag's keyword is the aggregate's body
|
||||
(test-assert "an inline aggregate's fields are not one"
|
||||
(emits? "(struct s ((a [struct ((x int)) 2 3])))" "a[2][3]"))
|
||||
(test-assert "but an expression after a tag is"
|
||||
(emits? "(define N 2) (struct t ((z int))) (struct s ((a [struct t (* 2 N)])))"
|
||||
"struct t a[2 * N]")))
|
||||
|
||||
;; ...and an index after the first was dropped
|
||||
(test-group "subscripts"
|
||||
(test-assert "each index subscripts what the one before it gave"
|
||||
(emits? (in-fn "(var m [int 2 3]) (= [m 1 2] a)") "m[1][2] = a;"))
|
||||
(test-assert "which is an element to inference"
|
||||
(emits? (in-fn "(var m [int 2 3]) (var e _ [m 1 2])") "int e = m[1][2];"))
|
||||
(test-assert "and an expression to sizeof"
|
||||
(emits? (in-fn "(var m [int 2 3]) (var n size-t (sizeof [m 1 1]))") "sizeof(m[1][1])"))
|
||||
(test-assert "nested by hand it is the same"
|
||||
(emits? (in-fn "(var m [int 2 3]) (= [[m 1] 2] a)") "m[1][2] = a;")))
|
||||
|
||||
;; `sizeof' takes a type or an expression, and `(* x)' is either.
|
||||
;; What is in scope says which: a name C alone knows is a type
|
||||
|
||||
Reference in New Issue
Block a user