From f34da7a658ccfa94718480b02d84abf5f27a4fed Mon Sep 17 00:00:00 2001 From: Fred Hornsey Date: Wed, 28 Nov 2018 18:17:40 -0600 Subject: tao_idl: Access Annotations From Typedef Chains --- TAO/TAO_IDL/ast/ast_decl.cpp | 11 +++++++++++ TAO/TAO_IDL/ast/ast_typedef.cpp | 39 ++++++++++++++++++++++++++++++++++++++- TAO/TAO_IDL/include/ast_decl.h | 7 +++++++ TAO/TAO_IDL/include/ast_typedef.h | 10 ++++++++++ 4 files changed, 66 insertions(+), 1 deletion(-) diff --git a/TAO/TAO_IDL/ast/ast_decl.cpp b/TAO/TAO_IDL/ast/ast_decl.cpp index 6dea30ae484..e12813d44f0 100644 --- a/TAO/TAO_IDL/ast/ast_decl.cpp +++ b/TAO/TAO_IDL/ast/ast_decl.cpp @@ -1662,3 +1662,14 @@ AST_Decl::should_be_dumped () const bool is_builtin = builtin (); return !is_builtin || (is_builtin && idl_global->dump_builtins_); } + +AST_Annotation_Appls & +AST_Decl::annotations () +{ + if (!annotation_appls_) + { + annotation_appls_ = new AST_Annotation_Appls; + } + + return *annotation_appls_; +} diff --git a/TAO/TAO_IDL/ast/ast_typedef.cpp b/TAO/TAO_IDL/ast/ast_typedef.cpp index b539c8d53dc..760bf9b55c7 100644 --- a/TAO/TAO_IDL/ast/ast_typedef.cpp +++ b/TAO/TAO_IDL/ast/ast_typedef.cpp @@ -89,12 +89,17 @@ AST_Typedef::AST_Typedef (AST_Type *bt, n), AST_Field (AST_Decl::NT_typedef, bt, - n) + n), + cached_annotations_ (0) { } AST_Typedef::~AST_Typedef (void) { + if (!cached_annotations_) + { + delete cached_annotations_; + } } // Given a typedef node, traverse the chain of base types until they are no @@ -193,3 +198,35 @@ AST_Typedef::destroy (void) } IMPL_NARROW_FROM_DECL(AST_Typedef) + +AST_Annotation_Appls & +AST_Typedef::annotations () +{ + if (!cached_annotations_) + { + cached_annotations_ = new AST_Annotation_Appls; + + if (base_type ()) + { + AST_Annotation_Appls &next = base_type ()->annotations (); + for (size_t i = 0; i < next.size (); i++) + { + cached_annotations_->push_back (next[i]); + } + } + + /* + * Done after so it's easier for later annotations to override + * older ones. + */ + if (annotation_appls ()) { + AST_Annotation_Appls &appls = *annotation_appls (); + for (size_t i = 0; i < appls.size (); i++) + { + cached_annotations_->push_back (appls[i]); + } + } + } + + return *cached_annotations_; +} diff --git a/TAO/TAO_IDL/include/ast_decl.h b/TAO/TAO_IDL/include/ast_decl.h index b38dd61d0da..787dc029c20 100644 --- a/TAO/TAO_IDL/include/ast_decl.h +++ b/TAO/TAO_IDL/include/ast_decl.h @@ -384,6 +384,13 @@ public: */ virtual bool should_be_dumped () const; + /** + * Get Annotation Vector Reference. + * If this is a typedef, it includes recursively acquired annotations from + * the possible chain of direct typedefs. + */ + virtual AST_Annotation_Appls &annotations (); + protected: // These are not private because they're used by // be_predefined_type' constructor and can be called diff --git a/TAO/TAO_IDL/include/ast_typedef.h b/TAO/TAO_IDL/include/ast_typedef.h index b14fef60d63..ea1f28cba3b 100644 --- a/TAO/TAO_IDL/include/ast_typedef.h +++ b/TAO/TAO_IDL/include/ast_typedef.h @@ -118,9 +118,19 @@ public: virtual bool dump_annotations_inline () const { return true; } + /** + * Recursively acquired annotations from typedefs. + */ + virtual AST_Annotation_Appls &annotations (); + protected: virtual int compute_size_type (void); // Compute the size type if it is unknown. + + /** + * Cache of Recursively acquired annotations from typedefs. + */ + AST_Annotation_Appls *cached_annotations_; }; #endif // _AST_TYPEDEF_AST_TYPEDEF_HH -- cgit v1.2.1