summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFred Hornsey <hornseyf@objectcomputing.com>2018-11-30 18:29:43 -0600
committerFred Hornsey <hornseyf@objectcomputing.com>2018-11-30 18:29:43 -0600
commit35a0a8f64120cf179d589aec9c7919a3d0de51e9 (patch)
tree0062914f1ae543a87847efb204e8a0ed5861fe3c
parent7e492b143685e4704f3698c8888139dc5f03f068 (diff)
downloadATCD-35a0a8f64120cf179d589aec9c7919a3d0de51e9.tar.gz
Remove Delegating Constructor from tao_idl
-rw-r--r--TAO/TAO_IDL/docs/annotations.md46
-rw-r--r--TAO/TAO_IDL/include/utl_identifier.h4
-rw-r--r--TAO/TAO_IDL/util/utl_identifier.cpp89
3 files changed, 95 insertions, 44 deletions
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
@@ -82,6 +82,51 @@ 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;
if (*s == '_')
@@ -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 *