blob: bde15b53493c0ad6ae592e82aa1df2cc6972e356 [file]
# Copyright 2019 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
[$default byte_order: "LittleEndian"]
[(cpp) namespace: "emboss::test"]
struct BasicConditional:
0 [+1] UInt x
if x == 0:
1 [+1] UInt xc
struct NegativeConditional:
0 [+1] UInt x
if x != 0:
1 [+1] UInt xc
struct ConditionalAndUnconditionalOverlappingFinalField:
0 [+1] UInt x
if x == 0:
1 [+1] UInt xc
1 [+1] UInt z
struct ConditionalBasicConditionalFieldFirst:
if x == 0:
0 [+1] UInt xc
1 [+1] UInt x
struct ConditionalAndDynamicLocation:
0 [+1] UInt x
2 [+1] UInt y
if x == 0:
y [+1] UInt xc
struct ConditionUsesMinInt:
0 [+1] Int x
if x - 0x7fff_ffff_ffff_ff80 == -0x8000_0000_0000_0000:
1 [+1] UInt xc
struct NestedConditional:
0 [+1] UInt x
if x == 0:
1 [+1] UInt xc
if xc == 0:
2 [+1] UInt xcc
struct CorrectNestedConditional:
0 [+1] UInt x
if x == 0:
1 [+1] UInt xc
if x == 0 && xc == 0:
2 [+1] UInt xcc
struct AlwaysFalseCondition:
0 [+1] UInt x
if false:
1 [+1] UInt xc
struct OnlyAlwaysFalseCondition:
if false:
0 [+1] UInt xc
struct EmptyStruct:
-- Empty structure.
struct AlwaysFalseConditionDynamicSize:
0 [+1] UInt x
x [+1] UInt y
if false:
1 [+1] UInt xc
struct ConditionDoesNotContributeToSize:
0 [+1] UInt x
if x == 0:
1 [+1] UInt xc
2 [+1] UInt y
enum OnOff:
OFF = 0
ON = 1
struct EnumCondition:
0 [+1] OnOff x
if x == OnOff.ON:
1 [+1] UInt xc
if x > OnOff.OFF:
1 [+1] UInt xc2
struct NegativeEnumCondition:
0 [+1] OnOff x
if x != OnOff.ON:
1 [+1] UInt xc
struct LessThanCondition:
0 [+1] UInt x
if x < 5:
1 [+1] UInt xc
struct LessThanOrEqualCondition:
0 [+1] UInt x
if x <= 5:
1 [+1] UInt xc
struct GreaterThanOrEqualCondition:
0 [+1] UInt x
if x >= 5:
1 [+1] UInt xc
struct GreaterThanCondition:
0 [+1] UInt x
if x > 5:
1 [+1] UInt xc
struct RangeCondition:
0 [+1] UInt x
1 [+1] UInt y
if 5 < x <= y < 10:
2 [+1] UInt xc
struct ReverseRangeCondition:
0 [+1] UInt x
1 [+1] UInt y
if 10 > y >= x > 5:
2 [+1] UInt xc
struct AndCondition:
0 [+1] UInt x
1 [+1] UInt y
if x == 5 && y == 5:
2 [+1] UInt xc
struct OrCondition:
0 [+1] UInt x
1 [+1] UInt y
if x == 5 || y == 5:
2 [+1] UInt xc
struct ChoiceCondition:
0 [+1] enum field:
USE_X = 1
USE_Y = 2
1 [+1] UInt x
2 [+1] UInt y
if (field == Field.USE_X ? x : y) == 5:
3 [+1] UInt xyc
struct ContainsBits:
0 [+1] bits:
7 [+1] UInt has_top
0 [+1] UInt has_bottom
struct ContainsContainsBits:
0 [+1] ContainsBits condition
# TODO(bolms): allow Flags to be used as booleans in conditions.
if condition.has_top == 1:
1 [+1] UInt top
struct ConditionalInline:
0 [+1] UInt payload_id
if payload_id == 0:
1 [+3] struct type_0:
0 [+1] UInt a
1 [+1] UInt b
2 [+1] UInt c
if payload_id == 1:
1 [+3] struct type_1:
0 [+1] UInt a
1 [+1] UInt b
2 [+1] UInt c
struct ConditionalAnonymous:
0 [+1] UInt x
if x > 10:
1 [+1] bits:
0 [+1] UInt low
if low == 1:
3 [+2] UInt mid
7 [+1] UInt high
struct ConditionalOnFlag:
0 [+1] bits:
0 [+1] Flag enabled
if enabled:
1 [+1] UInt value
struct ResidualConditionalDiscriminant:
# `tag` is itself conditional, and is the discriminant for `a`/`b` (it is
# the first conjunct of their existence conditions). Every arm carries a
# residual (`outer == 1`), so when `outer != 1` the message is valid even
# though `tag` is absent -- and on a buffer too short to hold `tag`, reading
# the discriminant is Unknown. Ok() must not reject such a message.
0 [+1] UInt outer
if outer == 1:
1 [+1] UInt tag
if tag == 0 && outer == 1:
2 [+1] UInt a
if tag == 1 && outer == 1:
2 [+1] UInt b
struct BareConditionalDiscriminant:
# Like `ResidualConditionalDiscriminant`, but `a`/`b` reference the
# conditional discriminant `tag` without re-guarding `outer == 1`. Here an
# out-of-bounds `tag` leaves has_a()/has_b() Unknown, so Ok() correctly
# reports the message as invalid.
0 [+1] UInt outer
if outer == 1:
1 [+1] UInt tag
if tag == 0:
2 [+1] UInt a
if tag == 1:
2 [+1] UInt b
struct DominatedBareDiscriminant:
# Like `BareConditionalDiscriminant`, plus an always-present `tail` field
# that dominates the structure size. When `outer != 1`, `tag` is absent and
# has_a()/has_b() are Unknown, but `tail` keeps the size Known so
# IsComplete() is true. Ok() must still be false: a/b's existence is
# indeterminate.
0 [+1] UInt outer
if outer == 1:
1 [+1] UInt tag
if tag == 0:
2 [+1] UInt a
if tag == 1:
2 [+1] UInt b
3 [+1] UInt tail
struct DisjunctionConditionalDiscriminant:
# Disjunction arms (`tag == 0 || tag == 1`) on a conditional discriminant,
# each carrying a residual. Like `ResidualConditionalDiscriminant`, a
# message with `outer != 1` is valid even though `tag` is absent.
0 [+1] UInt outer
if outer == 1:
1 [+1] UInt tag
if (tag == 0 || tag == 1) && outer == 1:
2 [+1] UInt a
if (tag == 2 || tag == 3) && outer == 1:
2 [+1] UInt b
struct SingleEntryConditionalDiscriminant:
# A single residual arm on a conditional discriminant. When `outer != 1`,
# `tag` is absent and the message must still be Ok().
0 [+1] UInt outer
if outer == 1:
1 [+1] UInt tag
if tag == 0 && outer == 1:
2 [+1] UInt a
struct EnumConditionalDiscriminant:
# Conditional discriminant of enum type, with residual arms. When
# `outer != OnOff.ON`, `tag` is absent and the message must still be Ok().
0 [+1] OnOff outer
if outer == OnOff.ON:
1 [+1] OnOff tag
if tag == OnOff.OFF && outer == OnOff.ON:
2 [+1] UInt a
if tag == OnOff.ON && outer == OnOff.ON:
2 [+1] UInt b