From 35a0a8f64120cf179d589aec9c7919a3d0de51e9 Mon Sep 17 00:00:00 2001 From: Fred Hornsey Date: Fri, 30 Nov 2018 18:29:43 -0600 Subject: Remove Delegating Constructor from tao_idl --- TAO/TAO_IDL/docs/annotations.md | 46 +++++++++++++++++++ TAO/TAO_IDL/include/utl_identifier.h | 4 +- TAO/TAO_IDL/util/utl_identifier.cpp | 89 +++++++++++++++++++----------------- 3 files changed, 95 insertions(+), 44 deletions(-) create mode 100644 TAO/TAO_IDL/docs/annotations.md diff --git a/TAO/TAO_IDL/docs/annotations.md b/TAO/TAO_IDL/docs/annotations.md new file mode 100644 index 00000000000..0da490d92be --- /dev/null +++ b/TAO/TAO_IDL/docs/annotations.md @@ -0,0 +1,46 @@ +# Implementing Annotations + +**How to use the internal API to implement built-in annotations in `tao_idl` or a +compiler that uses `tao_idl`.** + +## Annotations + +Annotations are a feature of IDLv4 that allows IDL authors to pass hints to the +IDL compiler that can change compiler behavior and code generation. They are +similar to `#pragmas`, but more powerful because they are integrated with IDL +and are more expressive. In the latest IDL specification as of writing, version +4.2, they are described in section 7.4.15.1. + +Annotations exist in other languages like, Python, Java, and C#, although in +the former they are called attributes and have a significantly different +syntax. Like Python and Java, annotations can appear front of declarations and +look like function calls preceded by an `@` symbol. Unlike Python and Java, +though they "may be applied to any IDL constructs or sub-constructs", but the +OMG has not clarified this as of IDL 4.2. What this means though is that +annotations can be applied more places than the other languages allow. + +In `tao_idl`, here is an example of how annotations may be used: +``` +enum Urgency { + SUPPLEMENTARY, + @default_literal INFORMATIVE, + CRITICAL +}; + +@range(min=0,max=24) +typedef Hours short; + +@extensibility(FINAL) +struct Report { + @key + unsigned long index; + + @default(12) + Hours expiration; + + Urgency urgency; + + string message; +}; +``` + diff --git a/TAO/TAO_IDL/include/utl_identifier.h b/TAO/TAO_IDL/include/utl_identifier.h index 209807e168b..e6ce80ead3f 100644 --- a/TAO/TAO_IDL/include/utl_identifier.h +++ b/TAO/TAO_IDL/include/utl_identifier.h @@ -93,9 +93,11 @@ public: const char *get_string () const; ///} - void replace_string (const char * s); + void replace_string (const char *s); // Replace the underlying string and free the old one. + void preprocess_and_replace_string (const char *s); + bool compare (Identifier *other); // Compare with other Identifier. diff --git a/TAO/TAO_IDL/util/utl_identifier.cpp b/TAO/TAO_IDL/util/utl_identifier.cpp index 6fd20d68458..8f3929d0c8f 100644 --- a/TAO/TAO_IDL/util/utl_identifier.cpp +++ b/TAO/TAO_IDL/util/utl_identifier.cpp @@ -81,6 +81,51 @@ Identifier::Identifier (void) Identifier::Identifier (const char *s) : pv_string (0), escaped_ (false) +{ + preprocess_and_replace_string (s); +} + +Identifier::Identifier (const Identifier &other) + : pv_string (0), + escaped_ (other.escaped ()) +{ + replace_string (other.get_string ()); +} + +Identifier::~Identifier (void) +{ + if (this->pv_string != 0) + { + ACE::strdelete (this->pv_string); + } +} + +// Operations. + +char * +Identifier::get_string (void) +{ + return this->pv_string; +} + +const char * +Identifier::get_string (void) const +{ + return this->pv_string; +} + +void +Identifier::replace_string (const char * s) +{ + if (pv_string) + { + delete [] this->pv_string; + } + this->pv_string = s ? ACE::strnew (s) : 0; +} + +void +Identifier::preprocess_and_replace_string (const char * s) { bool shift = false; @@ -128,49 +173,7 @@ Identifier::Identifier (const char *s) } } - if (shift) - { - this->pv_string = ACE::strnew (s + 1); - } - else - { - this->pv_string = ACE::strnew (s); - } -} - -Identifier::Identifier (const Identifier &other) - : Identifier (other.get_string ()) -{ -} - -Identifier::~Identifier (void) -{ - if (this->pv_string != 0) - { - ACE::strdelete (this->pv_string); - this->pv_string = 0; - } -} - -// Operations. - -char * -Identifier::get_string (void) -{ - return this->pv_string; -} - -const char * -Identifier::get_string (void) const -{ - return this->pv_string; -} - -void -Identifier::replace_string (const char * s) -{ - delete [] this->pv_string; - this->pv_string = ACE::strnew (s); + replace_string (shift ? s + 1 : s); } // Compare two Identifier * -- cgit v1.2.1