From 1d95ccaf016c2c03bb5ad030bc6520230c36682e Mon Sep 17 00:00:00 2001 From: Fred Hornsey Date: Mon, 10 Jun 2024 16:51:01 -0500 Subject: [PATCH] Respond to Review and Fix Typedefs in Union Disc --- TAO/NEWS | 4 +- TAO/TAO_IDL/fe/idl.tab.cpp | 24 ++++++------ TAO/TAO_IDL/fe/idl.ypp | 24 ++++++------ TAO/tests/IDLv4/union_disc/test.idl | 60 +++++++++++++++++++++-------- 4 files changed, 72 insertions(+), 40 deletions(-) diff --git a/TAO/NEWS b/TAO/NEWS index 3973b95ff536a..3e039b95c8a14 100644 --- a/TAO/NEWS +++ b/TAO/NEWS @@ -2,13 +2,15 @@ USER VISIBLE CHANGES BETWEEN TAO-4.0.0 and TAO-4.0.1 ==================================================== - TAO_IDL: - - Support the following IDL v4 features: + - Support the following IDL v4 features (may not work everywhere in TAO): - Empty structs - `octet` and `wchar` union discriminators + - Allow using `typedef`s of `int8` and `uint8` as union discriminators - Allow using empty parentheses in annotation applications to workaround syntax errors when an annotation with no arguments has to be followed by a complete scoped name: `@example_annotation() ::ex::ExampleType` + This is a proposed solution to an IDL spec issue. - Reserve the `bitfield`, `bitmask`, and `bitset` keywords in IDL v4 (these are not implemented yet) - Allow using `map` as an identifier in IDL v3 again diff --git a/TAO/TAO_IDL/fe/idl.tab.cpp b/TAO/TAO_IDL/fe/idl.tab.cpp index fe70b8c71c4c9..de355a5a88122 100644 --- a/TAO/TAO_IDL/fe/idl.tab.cpp +++ b/TAO/TAO_IDL/fe/idl.tab.cpp @@ -5084,7 +5084,7 @@ yyparse (void) { if (idl_global->idl_version_ < IDL_VERSION_4) idl_global->err ()->idl_version_error ( - "Annotations are not allowed in IDL3"); + "Annotations are not allowed in IDL versions before 4"); Identifier *id = (yyvsp[-1].idval); UTL_ScopedName name (id, 0); @@ -5234,7 +5234,7 @@ yyparse (void) { if (idl_global->idl_version_ < IDL_VERSION_4) idl_global->err ()->idl_version_error ( - "Annotations are not allowed in IDL3"); + "Annotations are not allowed in IDL versions before 4"); AST_Annotation_Decl *decl = 0; UTL_ScopedName *name = (yyvsp[0].idlist); @@ -6010,7 +6010,7 @@ yyparse (void) { if (idl_global->idl_version_ < IDL_VERSION_4) idl_global->err ()->idl_version_error ( - "Empty structs are not allowed in IDL3"); + "Empty structs are not allowed in IDL versions before 4"); idl_global->set_parse_state (IDL_GlobalData::PS_StructQsSeen); } @@ -6324,7 +6324,7 @@ yyparse (void) { if ((yyvsp[0].etval) == AST_Expression::EV_wchar && idl_global->idl_version_ < IDL_VERSION_4) idl_global->err ()->idl_version_error ( - "Using wchar as a union discriminator isn't allowed in IDL3"); + "Using wchar as a union discriminator isn't allowed in IDL versions before 4"); (yyval.dcval) = idl_global->scopes ().bottom ()->lookup_primitive_type ((yyvsp[0].etval)); } @@ -6336,7 +6336,7 @@ yyparse (void) { if (idl_global->idl_version_ < IDL_VERSION_4) idl_global->err ()->idl_version_error ( - "Using octet as a union discriminator isn't allowed in IDL3"); + "Using octet as a union discriminator isn't allowed in IDL versions before 4"); (yyval.dcval) = idl_global->scopes ().bottom ()->lookup_primitive_type ((yyvsp[0].etval)); } @@ -6366,8 +6366,7 @@ yyparse (void) * typedef's to arrive at the base type at the end of the * chain. */ - d = - s->lookup_by_name ((yyvsp[0].idlist)); + d = s->lookup_by_name ((yyvsp[0].idlist)); if (s != 0 && d != 0) { @@ -6392,6 +6391,8 @@ yyparse (void) case AST_PredefinedType::PT_ulonglong: case AST_PredefinedType::PT_short: case AST_PredefinedType::PT_ushort: + case AST_PredefinedType::PT_int8: + case AST_PredefinedType::PT_uint8: case AST_PredefinedType::PT_char: case AST_PredefinedType::PT_boolean: (yyval.dcval) = p; @@ -6399,11 +6400,10 @@ yyparse (void) break; case AST_PredefinedType::PT_wchar: case AST_PredefinedType::PT_octet: - /* octets and wchars are not allowed */ - idl_global->err ()->error0 ( - UTL_Error::EIDL_DISC_TYPE - ); - (yyval.dcval) = 0; + if (idl_global->idl_version_ < IDL_VERSION_4) + idl_global->err ()->idl_version_error ( + "Using octet or wchar as a union discriminator isn't allowed in IDL versions before 4"); + (yyval.dcval) = p; found = true; break; default: diff --git a/TAO/TAO_IDL/fe/idl.ypp b/TAO/TAO_IDL/fe/idl.ypp index 6444926eb9187..04662cac902d3 100644 --- a/TAO/TAO_IDL/fe/idl.ypp +++ b/TAO/TAO_IDL/fe/idl.ypp @@ -2370,7 +2370,7 @@ annotation_dcl { if (idl_global->idl_version_ < IDL_VERSION_4) idl_global->err ()->idl_version_error ( - "Annotations are not allowed in IDL3"); + "Annotations are not allowed in IDL versions before 4"); Identifier *id = $2; UTL_ScopedName name (id, 0); @@ -2516,7 +2516,7 @@ annotation_appl { if (idl_global->idl_version_ < IDL_VERSION_4) idl_global->err ()->idl_version_error ( - "Annotations are not allowed in IDL3"); + "Annotations are not allowed in IDL versions before 4"); AST_Annotation_Decl *decl = 0; UTL_ScopedName *name = $2; @@ -3174,7 +3174,7 @@ struct_body { if (idl_global->idl_version_ < IDL_VERSION_4) idl_global->err ()->idl_version_error ( - "Empty structs are not allowed in IDL3"); + "Empty structs are not allowed in IDL versions before 4"); idl_global->set_parse_state (IDL_GlobalData::PS_StructQsSeen); } @@ -3436,7 +3436,7 @@ switch_type_spec : { if ($1 == AST_Expression::EV_wchar && idl_global->idl_version_ < IDL_VERSION_4) idl_global->err ()->idl_version_error ( - "Using wchar as a union discriminator isn't allowed in IDL3"); + "Using wchar as a union discriminator isn't allowed in IDL versions before 4"); $$ = idl_global->scopes ().bottom ()->lookup_primitive_type ($1); } @@ -3444,7 +3444,7 @@ switch_type_spec : { if (idl_global->idl_version_ < IDL_VERSION_4) idl_global->err ()->idl_version_error ( - "Using octet as a union discriminator isn't allowed in IDL3"); + "Using octet as a union discriminator isn't allowed in IDL versions before 4"); $$ = idl_global->scopes ().bottom ()->lookup_primitive_type ($1); } @@ -3467,8 +3467,7 @@ switch_type_spec : * typedef's to arrive at the base type at the end of the * chain. */ - d = - s->lookup_by_name ($1); + d = s->lookup_by_name ($1); if (s != 0 && d != 0) { @@ -3493,6 +3492,8 @@ switch_type_spec : case AST_PredefinedType::PT_ulonglong: case AST_PredefinedType::PT_short: case AST_PredefinedType::PT_ushort: + case AST_PredefinedType::PT_int8: + case AST_PredefinedType::PT_uint8: case AST_PredefinedType::PT_char: case AST_PredefinedType::PT_boolean: $$ = p; @@ -3500,11 +3501,10 @@ switch_type_spec : break; case AST_PredefinedType::PT_wchar: case AST_PredefinedType::PT_octet: - /* octets and wchars are not allowed */ - idl_global->err ()->error0 ( - UTL_Error::EIDL_DISC_TYPE - ); - $$ = 0; + if (idl_global->idl_version_ < IDL_VERSION_4) + idl_global->err ()->idl_version_error ( + "Using octet or wchar as a union discriminator isn't allowed in IDL versions before 4"); + $$ = p; found = true; break; default: diff --git a/TAO/tests/IDLv4/union_disc/test.idl b/TAO/tests/IDLv4/union_disc/test.idl index 8da1d160088c3..92c34251c9c4e 100644 --- a/TAO/tests/IDLv4/union_disc/test.idl +++ b/TAO/tests/IDLv4/union_disc/test.idl @@ -1,21 +1,51 @@ -union WcharUnion switch (wchar) { +typedef wchar wchar_t; +const wchar wchar_const = L'u'; +union WcharUnion switch (wchar_t) { +/* TODO: https://github.com/DOCGroup/ACE_TAO/issues/1284 +case L'\u0': + boolean b; +*/ case L'i': int32 i32; -case L'u': +case wchar_const: uint32 u32; -default: - string str; +/* TODO: https://github.com/DOCGroup/ACE_TAO/issues/1284 +case L'\uffff': + string s; +*/ }; -union OctetUnion switch (octet) { -case 1: - boolean b; -case 8: - int8 i8; -case 16: - int8 i16; -case 32: - int32 i32; -default: - string str; +typedef octet octet_t; +const octet octet_const = 1; +union OctetUnion switch (octet_t) { +case 0: + octet a; +case octet_const: + octet b; +case 255: + octet c; +}; + +typedef uint8 uint8_t; +const uint8 uint8_const = 1; +union Uint8Union switch (uint8_t) { +case 0: + uint8 a; +case uint8_const: + uint8 b; +case 255: + uint8 c; +}; + +typedef int8 int8_t; +const int8 int8_const = 1; +union Int8Union switch (int8_t) { +case -128: + int8 a; +case 0: + int8 b; +case int8_const: + int8 c; +case 127: + int8 d; };