Skip to content

Commit

Permalink
Support 3 Small IDL4 Features
Browse files Browse the repository at this point in the history
- Empty structs
- `octet` and `wchar` 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`.
  • Loading branch information
iguessthislldo committed Jun 9, 2024
1 parent 7d35ea7 commit 9df4eb9
Show file tree
Hide file tree
Showing 18 changed files with 2,436 additions and 2,289 deletions.
7 changes: 7 additions & 0 deletions TAO/NEWS
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
USER VISIBLE CHANGES BETWEEN TAO-4.0.0 and TAO-4.0.1
====================================================

- Add support in TAO_IDL for the following IDL v4 features:
- Empty structs
- `octet` and `wchar` 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`.

USER VISIBLE CHANGES BETWEEN TAO-3.1.4 and TAO-4.0.0
====================================================

Expand Down
2 changes: 2 additions & 0 deletions TAO/TAO_IDL/be/be_union.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -234,10 +234,12 @@ be_union::gen_empty_default_label ()
return (n_labels < 2);

case AST_PredefinedType::PT_char:
case AST_PredefinedType::PT_octet:
return (n_labels <= ACE_OCTET_MAX);

case AST_PredefinedType::PT_short:
case AST_PredefinedType::PT_ushort:
case AST_PredefinedType::PT_wchar:
return (n_labels <= ACE_UINT16_MAX);

case AST_PredefinedType::PT_long:
Expand Down
1 change: 1 addition & 0 deletions TAO/TAO_IDL/be/be_union_branch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ be_union_branch::gen_default_label_value (TAO_OutStream *os,
*os << dv.u.short_val;
break;
case AST_Expression::EV_ushort:
case AST_Expression::EV_wchar:
*os << dv.u.ushort_val;
break;
case AST_Expression::EV_long:
Expand Down
15 changes: 9 additions & 6 deletions TAO/TAO_IDL/be/be_visitor_structure/cdr_op_cs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,9 @@ be_visitor_structure_cdr_op_cs::visit_structure (be_structure *node)
<< "TAO_OutputCDR &strm," << be_nl
<< "const " << node->name () << " &_tao_aggregate)" << be_uidt
<< be_uidt_nl
<< "{" << be_idt_nl;
<< "{" << be_idt_nl
<< "ACE_UNUSED_ARG(strm);" << be_nl
<< "ACE_UNUSED_ARG(_tao_aggregate);" << be_nl;

be_visitor_context new_ctx (*this->ctx_);
be_visitor_cdr_op_field_decl field_decl (&new_ctx);
Expand All @@ -81,7 +83,7 @@ be_visitor_structure_cdr_op_cs::visit_structure (be_structure *node)
-1);
}

*os << ";" << be_uidt << be_uidt_nl
*os << "true;" << be_uidt << be_uidt_nl
<< "}" << be_nl_2;

// Set the substate as generating code for the input operator.
Expand All @@ -104,7 +106,9 @@ be_visitor_structure_cdr_op_cs::visit_structure (be_structure *node)
}

*os << ")" << be_uidt << be_uidt_nl
<< "{" << be_idt_nl;
<< "{" << be_idt_nl
<< "ACE_UNUSED_ARG(strm);" << be_nl
<< "ACE_UNUSED_ARG(_tao_aggregate);" << be_nl;

if (node->is_local ())
{
Expand Down Expand Up @@ -135,7 +139,7 @@ be_visitor_structure_cdr_op_cs::visit_structure (be_structure *node)
-1);
}

*os << ";" << be_uidt << be_uidt;
*os << "true;" << be_uidt << be_uidt;
}

*os << be_uidt_nl << "}" << be_nl;
Expand All @@ -157,8 +161,7 @@ be_visitor_structure_cdr_op_cs::post_process (be_decl *bd)
{
TAO_OutStream *os = this->ctx_->stream ();

if (!this->last_node (bd)
&& bd->node_type () != AST_Decl::NT_enum_val)
if (bd->node_type () != AST_Decl::NT_enum_val)
{
switch (this->ctx_->sub_state ())
{
Expand Down
3 changes: 3 additions & 0 deletions TAO/TAO_IDL/be/be_visitor_union/cdr_op_cs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ namespace {
case AST_Expression::EV_int8:
tmp_suffix = "int8";
break;
case AST_Expression::EV_octet:
tmp_suffix = "octet";
break;
default:
break;
}
Expand Down
1 change: 1 addition & 0 deletions TAO/TAO_IDL/be/be_visitor_union/discriminant_ci.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@ be_visitor_union_discriminant_ci::visit_predefined_type (
*os << dv.u.short_val;
break;
case AST_Expression::EV_ushort:
case AST_Expression::EV_wchar:
*os << dv.u.ushort_val;
break;
case AST_Expression::EV_long:
Expand Down
2 changes: 1 addition & 1 deletion TAO/TAO_IDL/fe/fe_lookup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
unsigned int
TAO_IDL_CPP_Keyword_Table::hash (const char *str, unsigned int len)
{
static const unsigned char asso_values[] =
static constexpr unsigned char asso_values[] =
{
252, 252, 252, 252, 252, 252, 252, 252, 252, 252,
252, 252, 252, 252, 252, 252, 252, 252, 252, 252,
Expand Down
4,513 changes: 2,280 additions & 2,233 deletions TAO/TAO_IDL/fe/idl.tab.cpp

Large diffs are not rendered by default.

83 changes: 43 additions & 40 deletions TAO/TAO_IDL/fe/idl.ypp
Original file line number Diff line number Diff line change
Expand Up @@ -2365,10 +2365,8 @@ annotation_dcl
: IDL_ANNOTATION_DECL defining_id '{'
{
if (idl_global->idl_version_ < IDL_VERSION_4)
{
idl_global->err ()->idl_version_error (
"Annotations are an IDL4 feature");
}
idl_global->err ()->idl_version_error (
"Annotations are not allowed in IDL3");

Identifier *id = $2;
UTL_ScopedName name (id, 0);
Expand Down Expand Up @@ -2513,10 +2511,8 @@ annotation_appl
: IDL_ANNOTATION_SYMBOL scoped_name
{
if (idl_global->idl_version_ < IDL_VERSION_4)
{
idl_global->err ()->idl_version_error (
"Annotations are an IDL4 feature");
}
idl_global->err ()->idl_version_error (
"Annotations are not allowed in IDL3");

AST_Annotation_Decl *decl = 0;
UTL_ScopedName *name = $2;
Expand Down Expand Up @@ -2622,6 +2618,10 @@ annotation_appl_params
{
$$ = $1;
}
| %empty
{
$$ = 0;
}
;

named_annotation_appl_params
Expand Down Expand Up @@ -3153,14 +3153,8 @@ struct_type
{
idl_global->set_parse_state (IDL_GlobalData::PS_StructSqSeen);
}
at_least_one_member
{
idl_global->set_parse_state (IDL_GlobalData::PS_StructBodySeen);
}
'}'
struct_body
{
idl_global->set_parse_state (IDL_GlobalData::PS_StructQsSeen);

/*
* Done with this struct. Pop its scope off the scopes stack.
*/
Expand All @@ -3171,7 +3165,28 @@ struct_type
}
;

at_least_one_member : member members ;
struct_body
: '}'
{
if (idl_global->idl_version_ < IDL_VERSION_4)
idl_global->err ()->idl_version_error (
"Empty structs are not allowed in IDL3");

idl_global->set_parse_state (IDL_GlobalData::PS_StructQsSeen);
}
| struct_body_with_members
;

struct_body_with_members
: member members
{
idl_global->set_parse_state (IDL_GlobalData::PS_StructBodySeen);
}
'}'
{
idl_global->set_parse_state (IDL_GlobalData::PS_StructQsSeen);
}
;

members
: members member
Expand Down Expand Up @@ -3411,39 +3426,27 @@ union_type
switch_type_spec :
integer_type
{
$$ =
idl_global->scopes ().bottom ()->lookup_primitive_type (
$1
);
$$ = idl_global->scopes ().bottom ()->lookup_primitive_type ($1);
}
| char_type
{
/* wchars are not allowed. */
if ($1 == AST_Expression::EV_wchar)
{
idl_global->err ()->error0 (UTL_Error::EIDL_DISC_TYPE);
}
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");

$$ =
idl_global->scopes ().bottom ()->lookup_primitive_type (
$1
);
$$ = idl_global->scopes ().bottom ()->lookup_primitive_type ($1);
}
| octet_type
{
/* octets are not allowed. */
idl_global->err ()->error0 (UTL_Error::EIDL_DISC_TYPE);
$$ =
idl_global->scopes ().bottom ()->lookup_primitive_type (
$1
);
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");

$$ = idl_global->scopes ().bottom ()->lookup_primitive_type ($1);
}
| boolean_type
{
$$ =
idl_global->scopes ().bottom ()->lookup_primitive_type (
$1
);
$$ = idl_global->scopes ().bottom ()->lookup_primitive_type ($1);
}
| enum_type
| scoped_name
Expand Down Expand Up @@ -3895,7 +3898,7 @@ enumerator :
}
;

map_type_spec
map_type_spec
: map_head
'>'
{
Expand Down
14 changes: 7 additions & 7 deletions TAO/TAO_IDL/fe/idl.yy.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#line 1 "fe/idl.yy.cpp"
#line 2 "fe/idl.yy.cpp"

#line 3 "fe/idl.yy.cpp"
#line 4 "fe/idl.yy.cpp"

#define YY_INT_ALIGNED short int

Expand Down Expand Up @@ -288,7 +288,7 @@

/* C99 systems have <inttypes.h>. Non-C99 systems may or may not. */

#if defined (__STDC_VERSION__) && __STDC_VERSION__ >= 199901L
#if defined (__STDC_VERSION__) && __STDC_VERSION__ >= 199901L || defined (__HP_aCC)

/* C99 says to define __STDC_LIMIT_MACROS before including stdint.h,
* if you want the limit (max/min) macros for int types.
Expand Down Expand Up @@ -1450,9 +1450,9 @@ static AST_Decl * idl_find_node (const char *);
#undef ECHO
#endif

#line 1455 "fe/idl.yy.cpp"
#line 1456 "fe/idl.yy.cpp"
/* SO we don't choke on files that use \r\n */
#line 1457 "fe/idl.yy.cpp"
#line 1458 "fe/idl.yy.cpp"

#define INITIAL 0

Expand Down Expand Up @@ -1681,7 +1681,7 @@ YY_DECL
#line 123 "fe/idl.ll"


#line 1686 "fe/idl.yy.cpp"
#line 1687 "fe/idl.yy.cpp"

while ( /*CONSTCOND*/1 ) /* loops until end-of-file is reached */
{
Expand Down Expand Up @@ -2588,7 +2588,7 @@ YY_RULE_SETUP
#line 492 "fe/idl.ll"
ECHO;
YY_BREAK
#line 2593 "fe/idl.yy.cpp"
#line 2594 "fe/idl.yy.cpp"
case YY_STATE_EOF(INITIAL):
yyterminate();

Expand Down
10 changes: 9 additions & 1 deletion TAO/tao/idl_features.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@
# define TAO_IDL_HAS_ANNOTATIONS TAO_IDL_IDL_VERSION >= 0x40000
#endif

#ifndef TAO_IDL_HAS_EMPTY_ANNOTATION_PARAMS
# define TAO_IDL_HAS_EMPTY_ANNOTATION_PARAMS TAO_IDL_IDL_VERSION >= 0x40000
#endif

#ifndef TAO_IDL_HAS_ANONYMOUS_TYPES
# define TAO_IDL_HAS_ANONYMOUS_TYPES TAO_IDL_IDL_VERSION >= 0x40000
#endif
Expand All @@ -57,13 +61,17 @@
#endif

#ifndef TAO_IDL_HAS_OCTET_AND_WCHAR_UNION_DISCS
# define TAO_IDL_HAS_OCTET_AND_WCHAR_UNION_DISCS 0
# define TAO_IDL_HAS_OCTET_AND_WCHAR_UNION_DISCS TAO_IDL_IDL_VERSION >= 0x40000
#endif

#ifndef TAO_IDL_HAS_STRUCT_INHERITANCE
# define TAO_IDL_HAS_STRUCT_INHERITANCE 0
#endif

#ifndef TAO_IDL_HAS_EMPTY_STRUCTS
# define TAO_IDL_HAS_EMPTY_STRUCTS TAO_IDL_IDL_VERSION >= 0x40000
#endif

#ifndef TAO_IDL_HAS_MAP
# define TAO_IDL_HAS_MAP TAO_IDL_IDL_VERSION >= 0x40000
#endif
Expand Down
14 changes: 13 additions & 1 deletion TAO/tests/IDLv4/annotations/annotation_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -354,6 +354,18 @@ annotation_tests ()
t.assert_annotation_appl (module1, 0, test_annotation_1);
} catch (Failed const &) {}

try {
Annotation_Test t ("Empty Annotation Application Before Fully Scopped Type");
AST_Field *member = t.run (
"typedef uint32 fully_scopped_type;\n"
"struct empty_annotation_before_fully_scopped_type {\n"
" @test_annotation_1() ::fully_scopped_type member;\n"
"};\n"
).assert_node<AST_Field> ("::empty_annotation_before_fully_scopped_type::member");
t.assert_annotation_appl_count (member, 1);
t.assert_annotation_appl (member, 0, test_annotation_1);
} catch (Failed const &) {}

try {
Annotation_Test t ("Struct Annotation Application");
AST_Decl *struct1 = t.run (
Expand Down Expand Up @@ -1097,7 +1109,7 @@ annotation_tests ()
}
}
}
} catch (Failed const &) {}
} catch (Failed const &) {}

// Done, Print Overall Results
Annotation_Test::results ();
Expand Down
5 changes: 5 additions & 0 deletions TAO/tests/IDLv4/structs/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
/testC.cpp
/testC.h
/testC.inl
/testS.cpp
/testS.h
6 changes: 6 additions & 0 deletions TAO/tests/IDLv4/structs/IDLv4_structs.mpc
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
project: taoexe {
idlflags += --idl-version 4
IDL_Files {
test.idl
}
}
17 changes: 17 additions & 0 deletions TAO/tests/IDLv4/structs/test.idl
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
struct EmptyStruct {
};

struct StructWithEmptyStruct {
EmptyStruct empty;
};

#include __TAO_IDL_FEATURES
#if TAO_IDL_HAS_STRUCT_INHERITANCE
struct Derived1 : EmptyStruct {
int16 member1;
};

struct Derived2 : Derived1 {
int32 member2;
};
#endif
5 changes: 5 additions & 0 deletions TAO/tests/IDLv4/union_disc/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
/testC.cpp
/testC.h
/testC.inl
/testS.cpp
/testS.h
Loading

0 comments on commit 9df4eb9

Please sign in to comment.