mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Add more syntax tests for Yul objects
Also move some of them from boost tests.
This commit is contained in:
parent
e7c99918ed
commit
291c359ee9
@ -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.
|
|
7
test/libyul/yulSyntaxTests/objects/basic_subobject.yul
Normal file
7
test/libyul/yulSyntaxTests/objects/basic_subobject.yul
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
object "A" {
|
||||||
|
code {}
|
||||||
|
|
||||||
|
object "B" {
|
||||||
|
code {}
|
||||||
|
}
|
||||||
|
}
|
18
test/libyul/yulSyntaxTests/objects/code.yul
Normal file
18
test/libyul/yulSyntaxTests/objects/code.yul
Normal 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.
|
@ -0,0 +1,4 @@
|
|||||||
|
code {
|
||||||
|
}
|
||||||
|
// ----
|
||||||
|
// ParserError 4294: (0-4): Expected keyword "object".
|
35
test/libyul/yulSyntaxTests/objects/complex_subobject.yul
Normal file
35
test/libyul/yulSyntaxTests/objects/complex_subobject.yul
Normal 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 {}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -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.
|
@ -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.
|
10
test/libyul/yulSyntaxTests/objects/conflict_object_data.yul
Normal file
10
test/libyul/yulSyntaxTests/objects/conflict_object_data.yul
Normal 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.
|
@ -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.
|
@ -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.
|
9
test/libyul/yulSyntaxTests/objects/data.yul
Normal file
9
test/libyul/yulSyntaxTests/objects/data.yul
Normal 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"
|
||||||
|
}
|
||||||
|
// ----
|
9
test/libyul/yulSyntaxTests/objects/data_access.yul
Normal file
9
test/libyul/yulSyntaxTests/objects/data_access.yul
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
object "A" {
|
||||||
|
code {
|
||||||
|
pop(dataoffset("B"))
|
||||||
|
pop(datasize("B"))
|
||||||
|
}
|
||||||
|
|
||||||
|
data "B" hex"00"
|
||||||
|
}
|
||||||
|
// ----
|
6
test/libyul/yulSyntaxTests/objects/data_first.yul
Normal file
6
test/libyul/yulSyntaxTests/objects/data_first.yul
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
object "A" {
|
||||||
|
data "B" ""
|
||||||
|
code {}
|
||||||
|
}
|
||||||
|
// ----
|
||||||
|
// ParserError 4846: (15-19): Expected keyword "code".
|
6
test/libyul/yulSyntaxTests/objects/data_hex_name.yul
Normal file
6
test/libyul/yulSyntaxTests/objects/data_hex_name.yul
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
object "A" {
|
||||||
|
code {}
|
||||||
|
data hex"11" ""
|
||||||
|
}
|
||||||
|
// ----
|
||||||
|
// ParserError 2314: (30-37): Expected 'StringLiteral' but got 'HexStringLiteral'
|
8
test/libyul/yulSyntaxTests/objects/data_invalid_hex1.yul
Normal file
8
test/libyul/yulSyntaxTests/objects/data_invalid_hex1.yul
Normal 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'
|
8
test/libyul/yulSyntaxTests/objects/data_invalid_hex2.yul
Normal file
8
test/libyul/yulSyntaxTests/objects/data_invalid_hex2.yul
Normal 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'
|
8
test/libyul/yulSyntaxTests/objects/datacopy.yul
Normal file
8
test/libyul/yulSyntaxTests/objects/datacopy.yul
Normal 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)
|
||||||
|
}
|
10
test/libyul/yulSyntaxTests/objects/dataoffset_nonliteral.yul
Normal file
10
test/libyul/yulSyntaxTests/objects/dataoffset_nonliteral.yul
Normal 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.
|
@ -0,0 +1,7 @@
|
|||||||
|
object "A" {
|
||||||
|
code {
|
||||||
|
pop(dataoffset(0))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// ----
|
||||||
|
// TypeError 5859: (41-42): Function expects string literal.
|
@ -0,0 +1,8 @@
|
|||||||
|
object "A" {
|
||||||
|
code {
|
||||||
|
pop(dataoffset("C"))
|
||||||
|
}
|
||||||
|
data "B" ""
|
||||||
|
}
|
||||||
|
// ----
|
||||||
|
// TypeError 3517: (41-44): Unknown data object "C".
|
10
test/libyul/yulSyntaxTests/objects/datasize_nonliteral.yul
Normal file
10
test/libyul/yulSyntaxTests/objects/datasize_nonliteral.yul
Normal 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.
|
@ -0,0 +1,7 @@
|
|||||||
|
object "A" {
|
||||||
|
code {
|
||||||
|
pop(datasize(0))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// ----
|
||||||
|
// TypeError 5859: (39-40): Function expects string literal.
|
8
test/libyul/yulSyntaxTests/objects/datasize_notfound.yul
Normal file
8
test/libyul/yulSyntaxTests/objects/datasize_notfound.yul
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
object "A" {
|
||||||
|
code {
|
||||||
|
pop(datasize("C"))
|
||||||
|
}
|
||||||
|
data "B" ""
|
||||||
|
}
|
||||||
|
// ----
|
||||||
|
// TypeError 3517: (39-42): Unknown data object "C".
|
3
test/libyul/yulSyntaxTests/objects/empty_code.yul
Normal file
3
test/libyul/yulSyntaxTests/objects/empty_code.yul
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
object "A" {
|
||||||
|
code { }
|
||||||
|
}
|
5
test/libyul/yulSyntaxTests/objects/empty_data.yul
Normal file
5
test/libyul/yulSyntaxTests/objects/empty_data.yul
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
object "A" {
|
||||||
|
data "tmp" ""
|
||||||
|
}
|
||||||
|
// ----
|
||||||
|
// ParserError 4846: (15-19): Expected keyword "code".
|
4
test/libyul/yulSyntaxTests/objects/empty_object.yul
Normal file
4
test/libyul/yulSyntaxTests/objects/empty_object.yul
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
object "A" {
|
||||||
|
}
|
||||||
|
// ----
|
||||||
|
// ParserError 4846: (13-14): Expected keyword "code".
|
5
test/libyul/yulSyntaxTests/objects/empty_object_name.yul
Normal file
5
test/libyul/yulSyntaxTests/objects/empty_object_name.yul
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
object "" {
|
||||||
|
}
|
||||||
|
// ----
|
||||||
|
// ParserError 3287: (7-9): Object name cannot be empty.
|
||||||
|
// ParserError 4846: (12-13): Expected keyword "code".
|
3
test/libyul/yulSyntaxTests/objects/incomplete1.yul
Normal file
3
test/libyul/yulSyntaxTests/objects/incomplete1.yul
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
object {
|
||||||
|
// ----
|
||||||
|
// ParserError 2314: (7-8): Expected 'StringLiteral' but got '{'
|
7
test/libyul/yulSyntaxTests/objects/incomplete2.yul
Normal file
7
test/libyul/yulSyntaxTests/objects/incomplete2.yul
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
object "A" {
|
||||||
|
code {}
|
||||||
|
}
|
||||||
|
|
||||||
|
object
|
||||||
|
// ----
|
||||||
|
// ParserError 2314: (26-32): Expected end of source but got identifier
|
6
test/libyul/yulSyntaxTests/objects/multiple_code.yul
Normal file
6
test/libyul/yulSyntaxTests/objects/multiple_code.yul
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
object "A" {
|
||||||
|
code { }
|
||||||
|
code { }
|
||||||
|
}
|
||||||
|
// ----
|
||||||
|
// ParserError 8143: (26-30): Expected keyword "data" or "object" or "}".
|
6
test/libyul/yulSyntaxTests/objects/multiple_data.yul
Normal file
6
test/libyul/yulSyntaxTests/objects/multiple_data.yul
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
object "A" {
|
||||||
|
code { }
|
||||||
|
data "one" ""
|
||||||
|
data "two" ""
|
||||||
|
}
|
||||||
|
// ----
|
@ -0,0 +1,8 @@
|
|||||||
|
object "A" {
|
||||||
|
code { }
|
||||||
|
}
|
||||||
|
object "B" {
|
||||||
|
code { }
|
||||||
|
}
|
||||||
|
// ----
|
||||||
|
// ParserError 2314: (26-32): Expected end of source but got identifier
|
10
test/libyul/yulSyntaxTests/objects/nested_object.yul
Normal file
10
test/libyul/yulSyntaxTests/objects/nested_object.yul
Normal 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"
|
||||||
|
}
|
||||||
|
}
|
5
test/libyul/yulSyntaxTests/objects/object_hex_name.yul
Normal file
5
test/libyul/yulSyntaxTests/objects/object_hex_name.yul
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
object hex"11" {
|
||||||
|
code {}
|
||||||
|
}
|
||||||
|
// ----
|
||||||
|
// ParserError 2314: (7-14): Expected 'StringLiteral' but got 'HexStringLiteral'
|
11
test/libyul/yulSyntaxTests/objects/subobject_access.yul
Normal file
11
test/libyul/yulSyntaxTests/objects/subobject_access.yul
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
object "A" {
|
||||||
|
code {
|
||||||
|
pop(dataoffset("B"))
|
||||||
|
pop(datasize("B"))
|
||||||
|
}
|
||||||
|
|
||||||
|
object "B" {
|
||||||
|
code {}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// ----
|
9
test/libyul/yulSyntaxTests/objects/subobject_first.yul
Normal file
9
test/libyul/yulSyntaxTests/objects/subobject_first.yul
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
object "A" {
|
||||||
|
object "B" {
|
||||||
|
code {}
|
||||||
|
}
|
||||||
|
|
||||||
|
code {}
|
||||||
|
}
|
||||||
|
// ----
|
||||||
|
// ParserError 4846: (15-21): Expected keyword "code".
|
@ -0,0 +1,8 @@
|
|||||||
|
object "A" {
|
||||||
|
code {}
|
||||||
|
object hex"11" {
|
||||||
|
code {}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// ----
|
||||||
|
// ParserError 2314: (32-39): Expected 'StringLiteral' but got 'HexStringLiteral'
|
Loading…
Reference in New Issue
Block a user