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 18enum Product: 19 VERSION_1 = 0 20 VERSION_2 = 10 21 VERSION_X = 23 22 23 24enum MessageId: 25 AXIS = 0 26 CONFIG = 1 27 28 29struct MultiVersion(product: Product): 30 0 [+1] MessageId message_id 31 if message_id == MessageId.AXIS: 32 1 [+12] Axes(product == Product.VERSION_X ? 3 : 2) axes 33 34 if message_id == MessageId.CONFIG: 35 1 [+4] Config config 36 37 if product == Product.VERSION_X && message_id == MessageId.CONFIG: 38 1 [+8] ConfigVX() config_vx 39 40 41struct Axes(axes: UInt:4): 42 0 [+axes*4] Axis(AxisType.GENERIC)[] values 43 if axes > 0: 44 0 [+4] Axis(AxisType.X_AXIS) x 45 46 if axes > 1: 47 4 [+4] Axis(AxisType.Y_AXIS) y 48 49 if axes > 2: 50 8 [+4] Axis(AxisType.Z_AXIS) z 51 52 let axis_count_plus_one = axes+1 53 54 55struct AxisPair(axis_type_a_parameter: AxisType, axis_type_b_parameter: AxisType): 56 0 [+4] Axis(axis_type_a) axis_a 57 4 [+4] Axis(axis_type_b) axis_b 58 let axis_type_a = axis_type_a_parameter 59 let axis_type_b = axis_type_b_parameter 60 61 62struct AxesEnvelope: 63 0 [+1] UInt:8 axis_count 64 1 [+axis_count*4] Axes(axis_count) axes 65 66 67enum AxisType: 68 GENERIC = -1 69 X_AXIS = 1 70 Y_AXIS = 2 71 Z_AXIS = 3 72 73 74struct Axis(axis_type_parameter: AxisType): 75 0 [+4] UInt:32 value 76 if axis_type == AxisType.X_AXIS: 77 0 [+4] UInt:32 x 78 79 if axis_type == AxisType.Y_AXIS: 80 0 [+4] UInt:32 y 81 82 if axis_type == AxisType.Z_AXIS: 83 0 [+4] UInt:32 z 84 85 let axis_type = axis_type_parameter 86 87 88bits Config(): 89 31 [+1] Flag power 90 91 92struct ConfigVX: 93 0 [+4] bits: 94 31 [+1] Flag power 95 96 4 [+4] UInt gain 97 98 99struct StructWithUnusedParameter(x: UInt:8): 100 0 [+1] UInt y 101 102# StructContainingStructWithUnusedParameter is used to ensure that a struct is 103# not Ok() if it does not have its parameters, even if it does not directly use 104# those parameters. 105 106 107struct StructContainingStructWithUnusedParameter: 108 0 [+1] StructWithUnusedParameter(x) swup 109 1 [+1] UInt x 110 111struct BiasedValue(bias: UInt:8): 112 0 [+1] UInt raw_value 113 let value = raw_value+bias 114 115struct VirtualFirstFieldWithParam(param: UInt:8): 116 # Regression test: virtual fields did not have `public:` annotations, causing 117 # them to pick up the `private:` annotation from the parameter accessor when 118 # they were first in the struct. 119 let value = x 120 0 [+1] UInt x 121 122struct ConstVirtualFirstFieldWithParam(param: UInt:8): 123 # Regression test: see VirtualFirstFieldWithParam 124 let value = 10 125 0 [+1] UInt x 126 127struct SizedArrayOfBiasedValues: 128 0 [+1] UInt element_count (ec) 129 1 [+1] UInt bias 130 2 [+ec] BiasedValue(bias)[] values 131