From ab916faddd16f0165e9cc2551f90699be8efde53 Mon Sep 17 00:00:00 2001 From: Eric Blake Date: Mon, 4 May 2015 09:05:13 -0600 Subject: qapi: Use 'alternate' to replace anonymous union Previous patches have led up to the point where I create the new meta-type "'alternate':'Foo'". See the previous patches for documentation; I intentionally split as much work into earlier patches to minimize the size of this patch, but a lot of it is churn due to testsuite fallout after updating to the new type. Signed-off-by: Eric Blake Reviewed-by: Markus Armbruster Signed-off-by: Markus Armbruster --- tests/qapi-schema/alternate-array.err | 2 +- tests/qapi-schema/alternate-array.json | 5 ++--- tests/qapi-schema/alternate-base.err | 2 +- tests/qapi-schema/alternate-base.json | 5 ++--- tests/qapi-schema/alternate-clash.err | 2 +- tests/qapi-schema/alternate-clash.json | 5 ++--- tests/qapi-schema/alternate-conflict-dict.err | 2 +- tests/qapi-schema/alternate-conflict-dict.json | 5 ++--- tests/qapi-schema/alternate-conflict-string.err | 2 +- tests/qapi-schema/alternate-conflict-string.json | 5 ++--- tests/qapi-schema/alternate-good.json | 5 ++--- tests/qapi-schema/alternate-good.out | 4 ++-- tests/qapi-schema/alternate-nested.err | 2 +- tests/qapi-schema/alternate-nested.json | 10 ++++------ tests/qapi-schema/alternate-unknown.err | 2 +- tests/qapi-schema/alternate-unknown.json | 5 ++--- tests/qapi-schema/flat-union-bad-discriminator.err | 2 +- tests/qapi-schema/flat-union-bad-discriminator.json | 3 ++- tests/qapi-schema/qapi-schema-test.json | 3 +-- tests/qapi-schema/qapi-schema-test.out | 2 +- 20 files changed, 32 insertions(+), 41 deletions(-) (limited to 'tests') diff --git a/tests/qapi-schema/alternate-array.err b/tests/qapi-schema/alternate-array.err index 8d6ccc7..e2a5fc2 100644 --- a/tests/qapi-schema/alternate-array.err +++ b/tests/qapi-schema/alternate-array.err @@ -1 +1 @@ -tests/qapi-schema/alternate-array.json:5: Anonymous union 'MyUnion' member 'two' must not be array type +tests/qapi-schema/alternate-array.json:5: Alternate 'Alt' member 'two' must not be array type diff --git a/tests/qapi-schema/alternate-array.json b/tests/qapi-schema/alternate-array.json index 0da1a64..fc0632f 100644 --- a/tests/qapi-schema/alternate-array.json +++ b/tests/qapi-schema/alternate-array.json @@ -1,8 +1,7 @@ -# we do not allow array branches in anonymous unions +# we do not allow array branches in alternates # TODO: should we support this? { 'type': 'One', 'data': { 'name': 'str' } } -{ 'union': 'MyUnion', - 'discriminator': {}, +{ 'alternate': 'Alt', 'data': { 'one': 'One', 'two': [ 'int' ] } } diff --git a/tests/qapi-schema/alternate-base.err b/tests/qapi-schema/alternate-base.err index a2486b8..4a2566e 100644 --- a/tests/qapi-schema/alternate-base.err +++ b/tests/qapi-schema/alternate-base.err @@ -1 +1 @@ -tests/qapi-schema/alternate-base.json:4: Anonymous union 'MyUnion' must not have a base +tests/qapi-schema/alternate-base.json:4: Alternate 'Alt' must not have a base diff --git a/tests/qapi-schema/alternate-base.json b/tests/qapi-schema/alternate-base.json index dad7f02..66edc89 100644 --- a/tests/qapi-schema/alternate-base.json +++ b/tests/qapi-schema/alternate-base.json @@ -1,7 +1,6 @@ -# we reject anonymous union with base type +# we reject alternate with base type { 'type': 'Base', 'data': { 'string': 'str' } } -{ 'union': 'MyUnion', +{ 'alternate': 'Alt', 'base': 'Base', - 'discriminator': {}, 'data': { 'number': 'int' } } diff --git a/tests/qapi-schema/alternate-clash.err b/tests/qapi-schema/alternate-clash.err index 8949f52..51bea3e 100644 --- a/tests/qapi-schema/alternate-clash.err +++ b/tests/qapi-schema/alternate-clash.err @@ -1 +1 @@ -tests/qapi-schema/alternate-clash.json:2: Anonymous union 'Union1' member 'ONE' clashes with 'one' +tests/qapi-schema/alternate-clash.json:2: Alternate 'Alt1' member 'ONE' clashes with 'one' diff --git a/tests/qapi-schema/alternate-clash.json b/tests/qapi-schema/alternate-clash.json index fa2d27e..3947935 100644 --- a/tests/qapi-schema/alternate-clash.json +++ b/tests/qapi-schema/alternate-clash.json @@ -1,4 +1,3 @@ -# we detect C enum collisions in an anonymous union -{ 'union': 'Union1', - 'discriminator': {}, +# we detect C enum collisions in an alternate +{ 'alternate': 'Alt1', 'data': { 'one': 'str', 'ONE': 'int' } } diff --git a/tests/qapi-schema/alternate-conflict-dict.err b/tests/qapi-schema/alternate-conflict-dict.err index 2d4550c..0f411f4 100644 --- a/tests/qapi-schema/alternate-conflict-dict.err +++ b/tests/qapi-schema/alternate-conflict-dict.err @@ -1 +1 @@ -tests/qapi-schema/alternate-conflict-dict.json:6: Anonymous union 'MyUnion' member 'two' can't be distinguished from member 'one' +tests/qapi-schema/alternate-conflict-dict.json:6: Alternate 'Alt' member 'two' can't be distinguished from member 'one' diff --git a/tests/qapi-schema/alternate-conflict-dict.json b/tests/qapi-schema/alternate-conflict-dict.json index ded302e..fcb3e36 100644 --- a/tests/qapi-schema/alternate-conflict-dict.json +++ b/tests/qapi-schema/alternate-conflict-dict.json @@ -1,9 +1,8 @@ -# we reject anonymous unions with multiple object branches +# we reject alternates with multiple object branches { 'type': 'One', 'data': { 'name': 'str' } } { 'type': 'Two', 'data': { 'value': 'int' } } -{ 'union': 'MyUnion', - 'discriminator': {}, +{ 'alternate': 'Alt', 'data': { 'one': 'One', 'two': 'Two' } } diff --git a/tests/qapi-schema/alternate-conflict-string.err b/tests/qapi-schema/alternate-conflict-string.err index 271ddcd..fc523b0 100644 --- a/tests/qapi-schema/alternate-conflict-string.err +++ b/tests/qapi-schema/alternate-conflict-string.err @@ -1 +1 @@ -tests/qapi-schema/alternate-conflict-string.json:4: Anonymous union 'MyUnion' member 'two' can't be distinguished from member 'one' +tests/qapi-schema/alternate-conflict-string.json:4: Alternate 'Alt' member 'two' can't be distinguished from member 'one' diff --git a/tests/qapi-schema/alternate-conflict-string.json b/tests/qapi-schema/alternate-conflict-string.json index 3834a3d..72f04a8 100644 --- a/tests/qapi-schema/alternate-conflict-string.json +++ b/tests/qapi-schema/alternate-conflict-string.json @@ -1,7 +1,6 @@ -# we reject anonymous unions with multiple string-like branches +# we reject alternates with multiple string-like branches { 'enum': 'Enum', 'data': [ 'hello', 'world' ] } -{ 'union': 'MyUnion', - 'discriminator': {}, +{ 'alternate': 'Alt', 'data': { 'one': 'str', 'two': 'Enum' } } diff --git a/tests/qapi-schema/alternate-good.json b/tests/qapi-schema/alternate-good.json index 73d0993..99d614f 100644 --- a/tests/qapi-schema/alternate-good.json +++ b/tests/qapi-schema/alternate-good.json @@ -1,10 +1,9 @@ -# Working example of anonymous union +# Working example of alternate { 'type': 'Data', 'data': { '*number': 'int', '*name': 'str' } } { 'enum': 'Enum', 'data': [ 'hello', 'world' ] } -{ 'union': 'MyUnion', - 'discriminator': {}, +{ 'alternate': 'Alt', 'data': { 'value': 'int', 'string': 'Enum', 'struct': 'Data' } } diff --git a/tests/qapi-schema/alternate-good.out b/tests/qapi-schema/alternate-good.out index b5117d1..c3a6b77 100644 --- a/tests/qapi-schema/alternate-good.out +++ b/tests/qapi-schema/alternate-good.out @@ -1,6 +1,6 @@ [OrderedDict([('type', 'Data'), ('data', OrderedDict([('*number', 'int'), ('*name', 'str')]))]), OrderedDict([('enum', 'Enum'), ('data', ['hello', 'world'])]), - OrderedDict([('union', 'MyUnion'), ('discriminator', OrderedDict()), ('data', OrderedDict([('value', 'int'), ('string', 'Enum'), ('struct', 'Data')]))])] + OrderedDict([('alternate', 'Alt'), ('data', OrderedDict([('value', 'int'), ('string', 'Enum'), ('struct', 'Data')]))])] [{'enum_name': 'Enum', 'enum_values': ['hello', 'world']}, - {'enum_name': 'MyUnionKind', 'enum_values': None}] + {'enum_name': 'AltKind', 'enum_values': None}] [OrderedDict([('type', 'Data'), ('data', OrderedDict([('*number', 'int'), ('*name', 'str')]))])] diff --git a/tests/qapi-schema/alternate-nested.err b/tests/qapi-schema/alternate-nested.err index 59df96e..00b05c6 100644 --- a/tests/qapi-schema/alternate-nested.err +++ b/tests/qapi-schema/alternate-nested.err @@ -1 +1 @@ -tests/qapi-schema/alternate-nested.json:5: Anonymous union 'Union2' member 'nested' has invalid type 'Union1' +tests/qapi-schema/alternate-nested.json:4: Alternate 'Alt2' member 'nested' has invalid type 'Alt1' diff --git a/tests/qapi-schema/alternate-nested.json b/tests/qapi-schema/alternate-nested.json index ed2b6b7..c4233b9 100644 --- a/tests/qapi-schema/alternate-nested.json +++ b/tests/qapi-schema/alternate-nested.json @@ -1,7 +1,5 @@ -# we reject a nested anonymous union branch -{ 'union': 'Union1', - 'discriminator': {}, +# we reject a nested alternate branch +{ 'alternate': 'Alt1', 'data': { 'name': 'str', 'value': 'int' } } -{ 'union': 'Union2', - 'discriminator': {}, - 'data': { 'nested': 'Union1' } } +{ 'alternate': 'Alt2', + 'data': { 'nested': 'Alt1' } } diff --git a/tests/qapi-schema/alternate-unknown.err b/tests/qapi-schema/alternate-unknown.err index bf8e9ae..7af1b4c 100644 --- a/tests/qapi-schema/alternate-unknown.err +++ b/tests/qapi-schema/alternate-unknown.err @@ -1 +1 @@ -tests/qapi-schema/alternate-unknown.json:2: Anonymous union 'Union' member 'unknown' has invalid type 'MissingType' +tests/qapi-schema/alternate-unknown.json:2: Alternate 'Alt' member 'unknown' has invalid type 'MissingType' diff --git a/tests/qapi-schema/alternate-unknown.json b/tests/qapi-schema/alternate-unknown.json index 0c305c2..ad5c103 100644 --- a/tests/qapi-schema/alternate-unknown.json +++ b/tests/qapi-schema/alternate-unknown.json @@ -1,4 +1,3 @@ -# we reject an anonymous union with unknown type in branch -{ 'union': 'Union', - 'discriminator': {}, +# we reject an alternate with unknown type in branch +{ 'alternate': 'Alt', 'data': { 'unknown': 'MissingType' } } diff --git a/tests/qapi-schema/flat-union-bad-discriminator.err b/tests/qapi-schema/flat-union-bad-discriminator.err index 1661c52..507e2ba 100644 --- a/tests/qapi-schema/flat-union-bad-discriminator.err +++ b/tests/qapi-schema/flat-union-bad-discriminator.err @@ -1 +1 @@ -tests/qapi-schema/flat-union-bad-discriminator.json:10: Flat union 'TestUnion' discriminator must be a string +tests/qapi-schema/flat-union-bad-discriminator.json:11: Flat union 'TestUnion' discriminator must be a string diff --git a/tests/qapi-schema/flat-union-bad-discriminator.json b/tests/qapi-schema/flat-union-bad-discriminator.json index 3ce43e8..982f072 100644 --- a/tests/qapi-schema/flat-union-bad-discriminator.json +++ b/tests/qapi-schema/flat-union-bad-discriminator.json @@ -1,4 +1,5 @@ # we require the discriminator to be a string naming a base-type member +# this tests the old syntax for anonymous unions before we added alternates { 'enum': 'TestEnum', 'data': [ 'value1', 'value2' ] } { 'type': 'TestBase', @@ -9,6 +10,6 @@ 'data': { 'integer': 'int' } } { 'union': 'TestUnion', 'base': 'TestBase', - 'discriminator': [], + 'discriminator': {}, 'data': { 'kind1': 'TestTypeA', 'kind2': 'TestTypeB' } } diff --git a/tests/qapi-schema/qapi-schema-test.json b/tests/qapi-schema/qapi-schema-test.json index e1d35e1..dec8a7c 100644 --- a/tests/qapi-schema/qapi-schema-test.json +++ b/tests/qapi-schema/qapi-schema-test.json @@ -53,8 +53,7 @@ 'discriminator': 'enum1', 'data': { 'value1' : 'UserDefC', 'value2' : 'UserDefB', 'value3' : 'UserDefA' } } -{ 'union': 'UserDefAlternate', - 'discriminator': {}, +{ 'alternate': 'UserDefAlternate', 'data': { 'uda': 'UserDefA', 's': 'str', 'i': 'int' } } # for testing native lists diff --git a/tests/qapi-schema/qapi-schema-test.out b/tests/qapi-schema/qapi-schema-test.out index b55ab8d..313ecf3 100644 --- a/tests/qapi-schema/qapi-schema-test.out +++ b/tests/qapi-schema/qapi-schema-test.out @@ -10,7 +10,7 @@ OrderedDict([('type', 'UserDefUnionBase'), ('data', OrderedDict([('string', 'str'), ('enum1', 'EnumOne')]))]), OrderedDict([('union', 'UserDefFlatUnion'), ('base', 'UserDefUnionBase'), ('discriminator', 'enum1'), ('data', OrderedDict([('value1', 'UserDefA'), ('value2', 'UserDefB'), ('value3', 'UserDefB')]))]), OrderedDict([('union', 'UserDefFlatUnion2'), ('base', 'UserDefUnionBase'), ('discriminator', 'enum1'), ('data', OrderedDict([('value1', 'UserDefC'), ('value2', 'UserDefB'), ('value3', 'UserDefA')]))]), - OrderedDict([('union', 'UserDefAlternate'), ('discriminator', OrderedDict()), ('data', OrderedDict([('uda', 'UserDefA'), ('s', 'str'), ('i', 'int')]))]), + OrderedDict([('alternate', 'UserDefAlternate'), ('data', OrderedDict([('uda', 'UserDefA'), ('s', 'str'), ('i', 'int')]))]), OrderedDict([('union', 'UserDefNativeListUnion'), ('data', OrderedDict([('integer', ['int']), ('s8', ['int8']), ('s16', ['int16']), ('s32', ['int32']), ('s64', ['int64']), ('u8', ['uint8']), ('u16', ['uint16']), ('u32', ['uint32']), ('u64', ['uint64']), ('number', ['number']), ('boolean', ['bool']), ('string', ['str']), ('sizes', ['size'])]))]), OrderedDict([('command', 'user_def_cmd'), ('data', OrderedDict())]), OrderedDict([('command', 'user_def_cmd1'), ('data', OrderedDict([('ud1a', 'UserDefOne')]))]), -- cgit v1.1