Add more syntax tests for Yul objects

Also move some of them from boost tests.
This commit is contained in:
Alex Beregszaszi 2020-07-21 22:14:45 +01:00
parent e7c99918ed
commit 291c359ee9
37 changed files with 304 additions and 12 deletions

View File

@ -1,12 +0,0 @@
{
datacopy(0, 1, 2)
datasize("")
datasize(0) // This should not be valid.
dataoffset("")
dataoffset(0) // This should not be valid.
}
// ----
// TypeError 3517: (37-39): Unknown data object "".
// TypeError 5859: (54-55): Function expects string literal.
// TypeError 3517: (101-103): Unknown data object "".
// TypeError 5859: (120-121): Function expects string literal.

View File

@ -0,0 +1,7 @@
object "A" {
code {}
object "B" {
code {}
}
}

View File

@ -0,0 +1,18 @@
object "A" {
code {
function f() -> offset, len {
offset := dataoffset("A")
len := datasize("A")
}
let offset, len := f()
codecopy(0, offset, len)
}
data "hello" "hello world text"
object "hello" {
code {}
}
}
// ----
// ParserError 8794: (226-233): Object name "hello" already exists inside the containing object.

View File

@ -0,0 +1,4 @@
code {
}
// ----
// ParserError 4294: (0-4): Expected keyword "object".

View File

@ -0,0 +1,35 @@
object "A" {
code {}
data "1" hex"001122"
object "B" {
code {}
data "2" ""
object "B_C" {
code {}
object "B_C_1" {
code {}
}
object "B_C_2" {
code {}
}
}
}
object "C" {
code {}
}
object "D" {
code {}
object "D_1" {
code {}
}
object "D_2" {
code {}
}
}
}

View File

@ -0,0 +1,8 @@
object "A" {
code {}
data "B" ""
data "B" hex"00"
}
// ----
// ParserError 8794: (45-48): Object name "B" already exists inside the containing object.

View File

@ -0,0 +1,9 @@
object "A" {
code {}
object "A" {
code {}
}
}
// ----
// ParserError 8311: (33-36): Object name cannot be the same as the name of the containing object.

View File

@ -0,0 +1,10 @@
object "A" {
code {}
data "B" ""
object "B" {
code {}
}
}
// ----
// ParserError 8794: (47-50): Object name "B" already exists inside the containing object.

View File

@ -0,0 +1,12 @@
object "A" {
code {}
object "B" {
code {}
}
object "B" {
code {}
}
}
// ----
// ParserError 8794: (64-67): Object name "B" already exists inside the containing object.

View File

@ -0,0 +1,7 @@
object "A" {
code {}
data "A" ""
}
// ----
// ParserError 8311: (31-34): Object name cannot be the same as the name of the containing object.

View File

@ -0,0 +1,9 @@
object "A" {
code {
datacopy(0, dataoffset("3"), datasize("3"))
}
data "1" ""
data "2" hex"0011"
data "3" "hello world this is longer than 32 bytes and should still work"
}
// ----

View File

@ -0,0 +1,9 @@
object "A" {
code {
pop(dataoffset("B"))
pop(datasize("B"))
}
data "B" hex"00"
}
// ----

View File

@ -0,0 +1,6 @@
object "A" {
data "B" ""
code {}
}
// ----
// ParserError 4846: (15-19): Expected keyword "code".

View File

@ -0,0 +1,6 @@
object "A" {
code {}
data hex"11" ""
}
// ----
// ParserError 2314: (30-37): Expected 'StringLiteral' but got 'HexStringLiteral'

View File

@ -0,0 +1,8 @@
object "A" {
code {
}
data "1" hex"0"
data "1" hex"wronghexencoding"
}
// ----
// ParserError 2314: (37-41): Expected 'StringLiteral' but got 'ILLEGAL'

View File

@ -0,0 +1,8 @@
object "A" {
code {
}
data "1" hex"wronghexencoding"
data "2" hex"0"
}
// ----
// ParserError 2314: (37-41): Expected 'StringLiteral' but got 'ILLEGAL'

View File

@ -0,0 +1,8 @@
{
datacopy(0, 1, 2)
// datacopy also accepts pretty much anything which can be turned into a number
let x := 0
let s := ""
datacopy(x, "11", s)
}

View File

@ -0,0 +1,10 @@
object "A" {
code {
let x := "B"
pop(dataoffset(x))
}
data "B" hex"00"
}
// ----
// TypeError 9114: (47-57): Function expects direct literals as arguments.

View File

@ -0,0 +1,7 @@
object "A" {
code {
pop(dataoffset(0))
}
}
// ----
// TypeError 5859: (41-42): Function expects string literal.

View File

@ -0,0 +1,8 @@
object "A" {
code {
pop(dataoffset("C"))
}
data "B" ""
}
// ----
// TypeError 3517: (41-44): Unknown data object "C".

View File

@ -0,0 +1,10 @@
object "A" {
code {
let x := "B"
pop(datasize(x))
}
data "B" hex"00"
}
// ----
// TypeError 9114: (47-55): Function expects direct literals as arguments.

View File

@ -0,0 +1,7 @@
object "A" {
code {
pop(datasize(0))
}
}
// ----
// TypeError 5859: (39-40): Function expects string literal.

View File

@ -0,0 +1,8 @@
object "A" {
code {
pop(datasize("C"))
}
data "B" ""
}
// ----
// TypeError 3517: (39-42): Unknown data object "C".

View File

@ -0,0 +1,3 @@
object "A" {
code { }
}

View File

@ -0,0 +1,5 @@
object "A" {
data "tmp" ""
}
// ----
// ParserError 4846: (15-19): Expected keyword "code".

View File

@ -0,0 +1,4 @@
object "A" {
}
// ----
// ParserError 4846: (13-14): Expected keyword "code".

View File

@ -0,0 +1,5 @@
object "" {
}
// ----
// ParserError 3287: (7-9): Object name cannot be empty.
// ParserError 4846: (12-13): Expected keyword "code".

View File

@ -0,0 +1,3 @@
object {
// ----
// ParserError 2314: (7-8): Expected 'StringLiteral' but got '{'

View File

@ -0,0 +1,7 @@
object "A" {
code {}
}
object
// ----
// ParserError 2314: (26-32): Expected end of source but got identifier

View File

@ -0,0 +1,6 @@
object "A" {
code { }
code { }
}
// ----
// ParserError 8143: (26-30): Expected keyword "data" or "object" or "}".

View File

@ -0,0 +1,6 @@
object "A" {
code { }
data "one" ""
data "two" ""
}
// ----

View File

@ -0,0 +1,8 @@
object "A" {
code { }
}
object "B" {
code { }
}
// ----
// ParserError 2314: (26-32): Expected end of source but got identifier

View File

@ -0,0 +1,10 @@
object "outer" {
code { let x := mload(0) }
data "x" "stringdata"
object "inner" {
code { mstore(0, 1) }
object "inner inner" { code {} }
data "innerx" "abc"
data "innery" "def"
}
}

View File

@ -0,0 +1,5 @@
object hex"11" {
code {}
}
// ----
// ParserError 2314: (7-14): Expected 'StringLiteral' but got 'HexStringLiteral'

View File

@ -0,0 +1,11 @@
object "A" {
code {
pop(dataoffset("B"))
pop(datasize("B"))
}
object "B" {
code {}
}
}
// ----

View File

@ -0,0 +1,9 @@
object "A" {
object "B" {
code {}
}
code {}
}
// ----
// ParserError 4846: (15-21): Expected keyword "code".

View File

@ -0,0 +1,8 @@
object "A" {
code {}
object hex"11" {
code {}
}
}
// ----
// ParserError 2314: (32-39): Expected 'StringLiteral' but got 'HexStringLiteral'