aboutsummaryrefslogtreecommitdiffstats
path: root/pkg/compiler/testdata
diff options
context:
space:
mode:
authorDmitry Vyukov <dvyukov@google.com>2019-05-10 18:02:54 +0200
committerDmitry Vyukov <dvyukov@google.com>2019-05-14 19:28:01 +0200
commiteea28fee309680462752ef7709f1a94178dce44d (patch)
tree29caff3a1e370c092522a94a9a231d83a767d20b /pkg/compiler/testdata
parent1886b2a4811a4d9adbfc509505a095848cc655eb (diff)
pkg/compiler: support complex len targets
This change adds compiler support for complex path expressions in len targets. E.g. it allows to refer to a sibling field as len[parent_struct:field:another_field]. See the docs change for details. This is just a compiler change. The feature is not yet supported by the prog package.
Diffstat (limited to 'pkg/compiler/testdata')
-rw-r--r--pkg/compiler/testdata/all.txt27
-rw-r--r--pkg/compiler/testdata/errors.txt5
-rw-r--r--pkg/compiler/testdata/errors2.txt34
3 files changed, 62 insertions, 4 deletions
diff --git a/pkg/compiler/testdata/all.txt b/pkg/compiler/testdata/all.txt
index 49cc1ffb9..7acb47743 100644
--- a/pkg/compiler/testdata/all.txt
+++ b/pkg/compiler/testdata/all.txt
@@ -70,6 +70,33 @@ foo$len_templ(a ptr[in, len_templ1[int8, int16]])
foo$len_var0(a ptr[in, array[string]], b len[a])
foo$len_var1(a ptr[in, array[string]], b ptr[in, len[a, int32]])
+len_expr1 {
+ f11 len_expr2
+}
+
+len_expr2 {
+ f21 len_expr3
+ f22 len_expr4
+ f23 ptr[in, len_expr4]
+ f24 ptr[in, ptr[in, len_expr4]]
+ f25 len[f21:f31, int32]
+}
+
+len_expr3 {
+ f31 int32
+ f32 bytesize[len_expr2:f21, int32]
+ f33 bytesize[len_expr2:f22:f41, int32]
+ f34 bytesize[len_expr1:f11:f22:f41, int32]
+ f35 bytesize[len_expr2:f23:f41, int32]
+ f36 bytesize[len_expr2:f24:f41, int32]
+}
+
+len_expr4 {
+ f41 int32
+}
+
+foo$len_expr(a ptr[in, len_expr1])
+
# Pointer type.
foo$ptr(a ptr[in, int64])
diff --git a/pkg/compiler/testdata/errors.txt b/pkg/compiler/testdata/errors.txt
index e95c3be7d..8c44694bb 100644
--- a/pkg/compiler/testdata/errors.txt
+++ b/pkg/compiler/testdata/errors.txt
@@ -62,7 +62,7 @@ sf2 = "a", "b"
sf2 = "c" ### string flags sf2 redeclared, previously declared at LOCATION
resource r2[r0]: 2
-resource r3[int32:1] ### unexpected ':', only struct fields can be bitfields
+resource r3[int32:1] ### unexpected ':', only struct fields can be bitfields
resource r4[int32[opt]] ### resource base can't be marked as opt
resource r5[non_existent] ### unknown type non_existent
resource r6[int64be] ### int64be can't be resource base (int types can)
@@ -119,6 +119,9 @@ foo$61(a u6) ### u6 can't be syscall argument
foo$62() u6 ### u6 can't be syscall return
foo$63(a int32[1[2]]) ### range argument has subargs
foo$64(a ptr[in, flags[f1[int32], int32]]) ### flags argument has subargs
+foo$65(a int32, b len[1]) ### unexpected int 1 for len target argument of len type, expect identifier
+foo$66(a int32, b len[a:1]) ### unexpected int 1 after colon, expect identifier
+foo$67(x int32[1:2:3, opt]) ### unexpected ':'
opt { ### struct uses reserved name opt
f1 int32
diff --git a/pkg/compiler/testdata/errors2.txt b/pkg/compiler/testdata/errors2.txt
index 77db29197..6b7737ef5 100644
--- a/pkg/compiler/testdata/errors2.txt
+++ b/pkg/compiler/testdata/errors2.txt
@@ -80,8 +80,8 @@ foo$sr0(a ptr[in, use_sr])
# Len target tests.
foo$100(a int32, b len[a])
-foo$101(a len[a]) ### len target a refer to itself
-foo$102(a ptr[in, len[a, int8]]) ### len target a refer to itself
+foo$101(a len[a]) ### len target a refers to itself
+foo$102(a ptr[in, len[a, int8]]) ### len target a refers to itself
foo$103(a int32, b len[c]) ### len target c does not exist
foo$104(a len[parent]) ### len target parent does not exist
foo$105(a ptr[in, int32], b ptr[in, array[len[a, int32]]])
@@ -109,6 +109,15 @@ s6 {
f2 array[int8]
} [size[10]] ### varlen struct s6 has size attribute
+s7 {
+ f1 int32
+ f2 u0
+}
+
+u0 [
+ f len[f1, int32] ### len target f1 does not exist
+]
+
u1 [
f1 ptr[in, array[int8]]
f2 len[f1, int32] ### len target f1 does not exist
@@ -124,7 +133,26 @@ u3 [
foo$200(a ptr[in, s2])
foo$201(a ptr[in, s1])
-foo$202(a u1)
+foo$202(a ptr[in, s7])
+foo$203(a u1)
+
+foo$204(a ptr[in, slen1])
+
+slen1 {
+ f0 len[parent, int32]
+ f1 len[parent:f0, int32] ### parent can't be part of path expressions
+ f2 len[slen21:a, int32] ### len target a does not exist
+ f3 len[f0:parent, int32] ### parent can't be part of path expressions
+ f4 len[slen2:f, int32] ### len path slen2 does not refer to a struct
+ f5 len[slen22:f, int32] ### len path slen22 does not refer to a struct
+ slen2 ptr[in, array[slen2]]
+ slen21 slen2
+ slen22 array[slen2]
+}
+
+slen2 {
+ f int32
+}
# Resource ctor tests.