Ben Olmstead | c0d7784 | 2019-07-31 17:34:05 -0700 | [diff] [blame] | 1 | # Copyright 2019 Google LLC |
| 2 | # |
| 3 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | # you may not use this file except in compliance with the License. |
| 5 | # You may obtain a copy of the License at |
| 6 | # |
| 7 | # https://www.apache.org/licenses/LICENSE-2.0 |
| 8 | # |
| 9 | # Unless required by applicable law or agreed to in writing, software |
| 10 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | # See the License for the specific language governing permissions and |
| 13 | # limitations under the License. |
| 14 | |
| 15 | [$default byte_order: "LittleEndian"] |
| 16 | [(cpp) namespace: "emboss::test"] |
| 17 | |
| 18 | |
| 19 | struct RequiresIntegers: |
| 20 | [requires: zero_through_nine <= ten_through_twenty - 10] |
| 21 | |
| 22 | 0 [+1] UInt zero_through_nine [requires: 0 <= this <= 9] |
| 23 | |
| 24 | 1 [+1] Int ten_through_twenty [requires: 10 <= this <= 20] |
| 25 | |
| 26 | 2 [+1] UInt disjoint |
| 27 | [requires: 0 <= this <= 5 || 15 <= this <= 20] |
| 28 | |
| 29 | let ztn_plus_ttt = zero_through_nine + ten_through_twenty |
| 30 | [requires: 10 <= this <= 19] |
| 31 | |
| 32 | let alias_of_zero_through_nine = zero_through_nine |
| 33 | [requires: 2 <= this <= 7] |
| 34 | |
| 35 | let zero_through_nine_plus_five = zero_through_nine + 5 |
| 36 | [requires: 5 <= this <= 10] |
| 37 | |
| 38 | |
| 39 | struct RequiresBools: |
| 40 | [requires: a || b] |
| 41 | |
| 42 | 0 [+1] bits: |
| 43 | 0 [+1] Flag a |
| 44 | 1 [+1] Flag b |
| 45 | 2 [+1] Flag must_be_true |
| 46 | [requires: this] |
| 47 | 3 [+1] Flag must_be_false |
| 48 | [requires: this == false] |
| 49 | |
| 50 | let b_must_be_false = b == false |
| 51 | [requires: this] |
| 52 | |
| 53 | let alias_of_a_must_be_true = a |
| 54 | [requires: this] |
| 55 | |
| 56 | |
| 57 | struct RequiresEnums: |
| 58 | [requires: a == Enum.EN0 || b == Enum.EN0] |
| 59 | |
| 60 | enum Enum: |
| 61 | EN0 = 0 |
| 62 | EN1 = 1 |
| 63 | EN2 = 2 |
| 64 | EN3 = 3 |
| 65 | |
| 66 | 0 [+1] Enum a |
| 67 | 1 [+1] Enum b |
| 68 | 2 [+1] Enum c |
| 69 | [requires: this == Enum.EN0 || this == Enum.EN1] |
| 70 | |
| 71 | let filtered_a = a == Enum.EN0 ? Enum.EN1 : a |
| 72 | [requires: this == Enum.EN1] |
| 73 | |
| 74 | let alias_of_a = a |
| 75 | [requires: this == Enum.EN1] |
| 76 | |
| 77 | |
| 78 | struct RequiresWithOptionalFields: |
| 79 | [requires: a || b] |
| 80 | 0 [+1] bits: |
| 81 | 0 [+1] Flag a |
| 82 | 1 [+1] Flag b_exists |
| 83 | if b_exists: |
| 84 | 2 [+1] Flag b |
| 85 | if b_exists: |
| 86 | 2 [+1] Flag b_true |
| 87 | [requires: this] |
Ben Olmstead | b740c4f | 2021-09-03 20:53:53 +0000 | [diff] [blame] | 88 | |
| 89 | |
| 90 | struct RequiresInArrayElements: |
| 91 | struct Element: |
| 92 | 0 [+1] UInt:8 x [requires: 0 <= this <= 10] |
| 93 | |
| 94 | 0 [+4] Element[] xs |