diff options
author | parsons <parsons@ae88bc3d-4319-0410-8dbf-d08b4c9d3795> | 2009-07-08 20:29:55 +0000 |
---|---|---|
committer | parsons <parsons@ae88bc3d-4319-0410-8dbf-d08b4c9d3795> | 2009-07-08 20:29:55 +0000 |
commit | 9deabd51cfc8d1108c6ad924d792e7009f7f5482 (patch) | |
tree | 6a79c2e2330c911a3ea8f14b2502b45286d46e3a | |
parent | 8705f1c792bce498f1c5c4c83f4003c0761c0bdb (diff) | |
download | ATCD-9deabd51cfc8d1108c6ad924d792e7009f7f5482.tar.gz |
ChangeLogTag: Wed Jul 8 20:22:56 UTC 2009 Jeff Parsons <j.parsons@vanderbilt.edu>
-rw-r--r-- | modules/TAO/ChangeLog | 28 | ||||
-rw-r--r-- | modules/TAO/TAO_IDL/ast/ast_decl.cpp | 68 | ||||
-rw-r--r-- | modules/TAO/TAO_IDL/ast/ast_template_interface.cpp | 94 | ||||
-rw-r--r-- | modules/TAO/TAO_IDL/ast/ast_typedef.cpp | 9 | ||||
-rw-r--r-- | modules/TAO/TAO_IDL/fe/fe_interface_header.cpp | 71 | ||||
-rw-r--r-- | modules/TAO/TAO_IDL/fe/fe_template_interface_header.cpp | 126 | ||||
-rw-r--r-- | modules/TAO/TAO_IDL/include/ast_decl.h | 3 | ||||
-rw-r--r-- | modules/TAO/TAO_IDL/include/ast_template_interface.h | 14 | ||||
-rw-r--r-- | modules/TAO/TAO_IDL/include/fe_interface_header.h | 2 | ||||
-rw-r--r-- | modules/TAO/TAO_IDL/include/fe_template_interface_header.h | 4 | ||||
-rw-r--r-- | modules/TAO/TAO_IDL/include/utl_err.h | 5 | ||||
-rw-r--r-- | modules/TAO/TAO_IDL/util/utl_err.cpp | 19 |
12 files changed, 400 insertions, 43 deletions
diff --git a/modules/TAO/ChangeLog b/modules/TAO/ChangeLog index 8d525fdcfe7..5d4e10b1170 100644 --- a/modules/TAO/ChangeLog +++ b/modules/TAO/ChangeLog @@ -1,3 +1,31 @@ +Wed Jul 8 20:22:56 UTC 2009 Jeff Parsons <j.parsons@vanderbilt.edu> + + * TAO_IDL/include/fe_template_interface_header.h: + * TAO_IDL/include/ast_decl.h: + * TAO_IDL/include/fe_interface_header.h: + * TAO_IDL/include/ast_template_interface.h: + * TAO_IDL/include/utl_err.h: + * TAO_IDL/ast/ast_template_interface.cpp: + * TAO_IDL/ast/ast_typedef.cpp: + * TAO_IDL/ast/ast_decl.cpp: + * TAO_IDL/fe/fe_template_interface_header.cpp: + * TAO_IDL/fe/fe_interface_header.cpp: + * TAO_IDL/util/utl_err.cpp: + + - Added check for duplicate template parameter ids in + a template interface. + + - Added check for mismatched template parameters (type + and id) between parent and child template interface. + + - Added appropriate error messages for the above errors. + + - Added narrowing, visiting and dumping methods to + AST_Template_Interface. + + - Refactored code in FE_InterfaceHeader to get more + reuse. + Tue Jul 7 21:38:11 UTC 2009 Jeff Parsons <j.parsons@vanderbilt.edu> * TAO_IDL/fe/idl.yy: diff --git a/modules/TAO/TAO_IDL/ast/ast_decl.cpp b/modules/TAO/TAO_IDL/ast/ast_decl.cpp index 144ced58dbb..296d80f9eeb 100644 --- a/modules/TAO/TAO_IDL/ast/ast_decl.cpp +++ b/modules/TAO/TAO_IDL/ast/ast_decl.cpp @@ -728,6 +728,74 @@ AST_Decl::compute_flat_name (void) } } +const char * +AST_Decl::node_type_to_string (NodeType nt) +{ + switch (nt) + { + case NT_module: + return "module"; + case NT_interface: + case NT_interface_fwd: + return "interface"; + case NT_valuetype: + case NT_valuetype_fwd: + case NT_valuebox: + return "valuetype"; + case NT_const: + return "const"; + case NT_except: + return "exception"; + case NT_attr: + return "attribute"; + case NT_union: + case NT_union_fwd: + return "union"; + case NT_struct: + case NT_struct_fwd: + return "struct"; + case NT_enum: + return "enum"; + case NT_string: + return "string"; + case NT_wstring: + return "wstring"; + case NT_array: + return "array"; + case NT_sequence: + return "sequence"; + case NT_typedef: + return "typedef"; + case NT_pre_defined: + return "primitive"; + case NT_native: + return "native"; + case NT_factory: + return "factory"; + case NT_component: + case NT_component_fwd: + return "component"; + case NT_home: + return "home"; + case NT_eventtype: + case NT_eventtype_fwd: + return "eventtype"; + case NT_type: + return "typename"; + case NT_fixed: + return "fixed"; + // No useful output for these. + case NT_enum_val: + case NT_field: + case NT_union_branch: + case NT_op: + case NT_argument: + case NT_root: + default: + return ""; + } +} + // Return TRUE if one of my ancestor scopes is "s" // and FALSE otherwise. bool diff --git a/modules/TAO/TAO_IDL/ast/ast_template_interface.cpp b/modules/TAO/TAO_IDL/ast/ast_template_interface.cpp index 7d89fc222c7..56991db2640 100644 --- a/modules/TAO/TAO_IDL/ast/ast_template_interface.cpp +++ b/modules/TAO/TAO_IDL/ast/ast_template_interface.cpp @@ -1,6 +1,11 @@ // $Id$ #include "ast_template_interface.h" +#include "ast_visitor.h" + +#include "utl_identifier.h" +#include "utl_indenter.h" +#include "global_extern.h" ACE_RCSID (ast, ast_template_interface, @@ -35,8 +40,97 @@ AST_Template_Interface::~AST_Template_Interface (void) { } +FE_Utils::T_PARAMLIST_INFO & +AST_Template_Interface::template_params (void) +{ + return this->template_params_; +} + void AST_Template_Interface::destroy (void) { this->AST_Interface::destroy (); } + +void +AST_Template_Interface::dump (ACE_OSTREAM_TYPE &o) +{ + this->dump_i (o, "interface "); + + this->local_name ()->dump (o); + this->dump_i (o, "<"); + unsigned long index = 0UL; + FE_Utils::T_Param_Info *item = 0; + + for (FE_Utils::T_PARAMLIST_INFO::ITERATOR iter (this->template_params_); + !iter.done (); + iter.advance (), ++index) + { + if (index != 0UL) + { + this->dump_i (o, ", "); + } + + iter.next (item); + + this->dump_i (o, this->node_type_to_string (item->type)); + this->dump_i (o, " "); + this->dump_i (o, item->name.c_str ()); + } + + this->dump_i (o, "> "); + + if (this->pd_n_inherits > 0) + { + this->dump_i (o, ": "); + + for (long i = 0; i < this->pd_n_inherits; ++i) + { + this->pd_inherits[i]->local_name ()->dump (o); + this->dump_i (o, "<"); + + AST_Template_Interface *ti = + AST_Template_Interface::narrow_from_decl (pd_inherits[i]); + index = 0UL; + + for (FE_Utils::T_PARAMLIST_INFO::ITERATOR iter ( + ti->template_params_); + !iter.done (); + iter.advance (), ++index) + { + if (index != 0UL) + { + this->dump_i (o, ","); + } + + iter.next (item); + this->dump_i (o, item->name.c_str ()); + } + + this->dump_i (o, ">"); + + if (i < this->pd_n_inherits - 1) + { + this->dump_i (o, ", "); + } + } + } + + this->dump_i (o, " {\n"); + + UTL_Scope::dump (o); + idl_global->indent ()->skip_to (o); + + this->dump_i (o, "}\n"); +} + +int +AST_Template_Interface::ast_accept (ast_visitor *visitor) +{ + // TODO + return visitor->visit_interface (this); +} + +IMPL_NARROW_FROM_DECL(AST_Template_Interface) +IMPL_NARROW_FROM_SCOPE(AST_Template_Interface) + diff --git a/modules/TAO/TAO_IDL/ast/ast_typedef.cpp b/modules/TAO/TAO_IDL/ast/ast_typedef.cpp index dcc6f2d40d1..e73855a1e5a 100644 --- a/modules/TAO/TAO_IDL/ast/ast_typedef.cpp +++ b/modules/TAO/TAO_IDL/ast/ast_typedef.cpp @@ -168,15 +168,6 @@ AST_Typedef::owns_base_type (bool val) void AST_Typedef::dump (ACE_OSTREAM_TYPE&o) { - if (this->is_local ()) - { - this->dump_i (o, "(local) "); - } - else - { - this->dump_i (o, "(abstract) "); - } - this->dump_i (o, "typedef "); this->pd_base_type->dump (o); this->dump_i (o, " "); diff --git a/modules/TAO/TAO_IDL/fe/fe_interface_header.cpp b/modules/TAO/TAO_IDL/fe/fe_interface_header.cpp index a51b396c79b..26972d69daa 100644 --- a/modules/TAO/TAO_IDL/fe/fe_interface_header.cpp +++ b/modules/TAO/TAO_IDL/fe/fe_interface_header.cpp @@ -243,8 +243,6 @@ FE_InterfaceHeader::compile_inheritance (UTL_NameList *ifaces, AST_Decl *d = 0; UTL_ScopedName *item = 0;; AST_Interface *i = 0; - long j = 0; - long k = 0; int inh_err = 0; // Compute expanded flattened non-repeating list of interfaces @@ -254,8 +252,10 @@ FE_InterfaceHeader::compile_inheritance (UTL_NameList *ifaces, { item = l.item (); + UTL_Scope *s = idl_global->scopes ().top (); + // Check that scope stack is valid. - if (idl_global->scopes ().top () == 0) + if (s == 0) { idl_global->err ()->lookup_error (item); @@ -265,8 +265,6 @@ FE_InterfaceHeader::compile_inheritance (UTL_NameList *ifaces, } // Look it up. - UTL_Scope *s = idl_global->scopes ().top (); - d = s->lookup_by_name (item, true, true, @@ -347,33 +345,7 @@ FE_InterfaceHeader::compile_inheritance (UTL_NameList *ifaces, } // OK, install in interface header. - // First the flat list (all ancestors). - if (this->iused_flat_ > 0) - { - ACE_NEW (this->inherits_flat_, - AST_Interface *[this->iused_flat_]); - - for (j = 0; j < this->iused_flat_; ++j) - { - this->inherits_flat_[j] = this->iseen_flat_[j]; - } - - this->n_inherits_flat_ = iused_flat_; - } - - // Then the list of immediate ancestors. - if (this->iused_ > 0) - { - ACE_NEW (this->inherits_, - AST_Interface *[this->iused_]); - - for (k = 0; k < this->iused_; ++k) - { - this->inherits_[k] = this->iseen_[k]; - } - - this->n_inherits_ = this->iused_; - } + this->install_in_header (); } int @@ -503,6 +475,41 @@ FE_InterfaceHeader::already_seen_flat (AST_Interface *ip) return false; } +void +FE_InterfaceHeader::install_in_header (void) +{ + long j = 0; + long k = 0; + + // First the flat list (all ancestors). + if (this->iused_flat_ > 0) + { + ACE_NEW (this->inherits_flat_, + AST_Interface *[this->iused_flat_]); + + for (j = 0; j < this->iused_flat_; ++j) + { + this->inherits_flat_[j] = this->iseen_flat_[j]; + } + + this->n_inherits_flat_ = iused_flat_; + } + + // Then the list of immediate ancestors. + if (this->iused_ > 0) + { + ACE_NEW (this->inherits_, + AST_Interface *[this->iused_]); + + for (k = 0; k < this->iused_; ++k) + { + this->inherits_[k] = this->iseen_[k]; + } + + this->n_inherits_ = this->iused_; + } +} + // Data accessors. UTL_ScopedName * diff --git a/modules/TAO/TAO_IDL/fe/fe_template_interface_header.cpp b/modules/TAO/TAO_IDL/fe/fe_template_interface_header.cpp index 9a31239a389..0337f33a9f5 100644 --- a/modules/TAO/TAO_IDL/fe/fe_template_interface_header.cpp +++ b/modules/TAO/TAO_IDL/fe/fe_template_interface_header.cpp @@ -1,6 +1,10 @@ // $Id$ #include "fe_template_interface_header.h" +#include "fe_extern.h" +#include "ast_template_interface.h" +#include "utl_err.h" +#include "global_extern.h" FE_Template_InterfaceHeader::FE_Template_InterfaceHeader ( UTL_ScopedName *n, @@ -15,6 +19,11 @@ FE_Template_InterfaceHeader::FE_Template_InterfaceHeader ( parent_info_ (inherited) { this->compile_template_inheritance (); + + if (this->duplicate_param_id ()) + { + idl_global->err ()->duplicate_param_id (this->interface_name_); + } } FE_Template_InterfaceHeader::~FE_Template_InterfaceHeader (void) @@ -32,7 +41,7 @@ FE_Template_InterfaceHeader::destroy (void) // themselves) before we destroy the queue. if (this->parent_info_ != 0) { - for (FE_Utils::T_REFLIST_INFO::ITERATOR i (*this->parent_info_); + for (FE_Utils::T_REFLIST_INFO::CONST_ITERATOR i (*this->parent_info_); !i.done (); i.advance ()) { @@ -64,10 +73,123 @@ FE_Template_InterfaceHeader::compile_template_inheritance (void) return; } - for (FE_Utils::T_REFLIST_INFO::ITERATOR i (*this->parent_info_); + for (FE_Utils::T_REFLIST_INFO::CONST_ITERATOR iter (*this->parent_info_); + !iter.done (); + iter.advance ()) + { + FE_Utils::T_Ref_Info *item = 0; + iter.next (item); + + UTL_Scope *s = idl_global->scopes ().top_non_null (); + AST_Decl *d = s->lookup_by_name (item->name, + true, + true, + true); + + if (d == 0) + { + idl_global->err ()->lookup_error (item->name); + + // Bad IDL, best to avoid a possible crash. + throw Bailout (); + } + + if (d->node_type () == AST_Decl::NT_typedef) + { + d = AST_Typedef::narrow_from_decl (d)->primitive_base_type (); + } + + AST_Template_Interface *i = + AST_Template_Interface::narrow_from_decl (d); + + if (i == 0) + { + idl_global->err ()->error1 (UTL_Error::EIDL_TMPL_IFACE_EXPECTED, + i); + + // Keep going but don't process the bad parent further. + continue; + } + + // Each parent template parameter must match one in the child. + if (! this->match_params (i)) + { + // Keep going but don't process the bad parent further. + continue; + } + + // This part is the same as for a non-template interface. + this->compile_one_inheritance (i); + } + + // Same as for non-template interface. + this->install_in_header (); +} + +bool +FE_Template_InterfaceHeader::match_params (AST_Template_Interface *ti) +{ + for (FE_Utils::T_PARAMLIST_INFO::CONST_ITERATOR i (ti->template_params ()); !i.done (); i.advance ()) { + FE_Utils::T_Param_Info *item = 0; + i.next (item); + + bool one_matched = false; + + for (FE_Utils::T_PARAMLIST_INFO::CONST_ITERATOR j (*this->param_info_); + !j.done (); + j.advance ()) + { + FE_Utils::T_Param_Info *my_item = 0; + j.next (my_item); + + if (item->type == my_item->type + && item->name == my_item->name) + { + one_matched = true; + break; + } + } + + if (! one_matched) + { + idl_global->err ()->error1 (UTL_Error::EIDL_MISMATCHED_T_PARAM, + ti); + return false; + } + } + + return true; +} + +bool +FE_Template_InterfaceHeader::duplicate_param_id (void) +{ + size_t cur_pos = 0UL; + size_t size = this->param_info_->size (); + + for (FE_Utils::T_PARAMLIST_INFO::CONST_ITERATOR i (*this->param_info_); + !i.done (); + i.advance (), ++cur_pos) + { + FE_Utils::T_Param_Info *this_one = 0; + FE_Utils::T_Param_Info *that_one = 0; + + i.next (this_one); + + for (size_t j = cur_pos + 1; j < size; ++j) + { + this->param_info_->get (that_one, j); + + if (this_one->name == that_one->name) + { + return true; + } + } } + + return false; } diff --git a/modules/TAO/TAO_IDL/include/ast_decl.h b/modules/TAO/TAO_IDL/include/ast_decl.h index 6cf3cf560c1..9e6d26f7dfe 100644 --- a/modules/TAO/TAO_IDL/include/ast_decl.h +++ b/modules/TAO/TAO_IDL/include/ast_decl.h @@ -315,6 +315,9 @@ protected: void compute_flat_name (void); // Compute the flattened fully scoped name. + const char *node_type_to_string (NodeType nt); + // Convert a NodeType to a string for dumping. + private: // Data diff --git a/modules/TAO/TAO_IDL/include/ast_template_interface.h b/modules/TAO/TAO_IDL/include/ast_template_interface.h index 316f9d46a69..4f40072408d 100644 --- a/modules/TAO/TAO_IDL/include/ast_template_interface.h +++ b/modules/TAO/TAO_IDL/include/ast_template_interface.h @@ -21,9 +21,23 @@ public: const FE_Utils::T_PARAMLIST_INFO *template_params); virtual ~AST_Template_Interface (void); + + FE_Utils::T_PARAMLIST_INFO &template_params (void); + // Cleanup function. virtual void destroy (void); + // Narrowing. + + DEF_NARROW_FROM_DECL(AST_Template_Interface); + DEF_NARROW_FROM_SCOPE(AST_Template_Interface); + + // AST Dumping. + virtual void dump (ACE_OSTREAM_TYPE &o); + + // Visiting. + virtual int ast_accept (ast_visitor *visitor); + protected: FE_Utils::T_PARAMLIST_INFO template_params_; }; diff --git a/modules/TAO/TAO_IDL/include/fe_interface_header.h b/modules/TAO/TAO_IDL/include/fe_interface_header.h index 60e954a469e..d3d4fa06d12 100644 --- a/modules/TAO/TAO_IDL/include/fe_interface_header.h +++ b/modules/TAO/TAO_IDL/include/fe_interface_header.h @@ -120,6 +120,8 @@ protected: void add_inheritance_flat (AST_Interface *i); bool already_seen (AST_Interface *ip); bool already_seen_flat (AST_Interface *ip); + + void install_in_header (void); // Data. protected: diff --git a/modules/TAO/TAO_IDL/include/fe_template_interface_header.h b/modules/TAO/TAO_IDL/include/fe_template_interface_header.h index 2938f21e699..50f99203c2d 100644 --- a/modules/TAO/TAO_IDL/include/fe_template_interface_header.h +++ b/modules/TAO/TAO_IDL/include/fe_template_interface_header.h @@ -9,6 +9,8 @@ #include "fe_interface_header.h" #include "fe_utils.h" +class AST_Template_Interface; + class TAO_IDL_FE_Export FE_Template_InterfaceHeader : public FE_InterfaceHeader { @@ -32,6 +34,8 @@ protected: protected: void compile_template_inheritance (void); + bool match_params (AST_Template_Interface *ti); + bool duplicate_param_id (void); }; #endif // FE_TEMPLATE_INTERFACE_HEADER_H diff --git a/modules/TAO/TAO_IDL/include/utl_err.h b/modules/TAO/TAO_IDL/include/utl_err.h index 725254ee48a..3d2c5c797df 100644 --- a/modules/TAO/TAO_IDL/include/utl_err.h +++ b/modules/TAO/TAO_IDL/include/utl_err.h @@ -117,6 +117,7 @@ public: EIDL_CONCRETE_VT_EXPECTED, // We got something else.. EIDL_ABSTRACT_EXPECTED, // We got something else.. EIDL_EVENTTYPE_EXPECTED, // We got something else.. + EIDL_TMPL_IFACE_EXPECTED, // We got something else.. EIDL_NAME_CASE_ERROR, // Identifier spellings differ only in case EIDL_NAME_CASE_WARNING, // Same as above, but only a warning EIDL_KEYWORD_ERROR, // Case-insensitive clash with IDL keyword @@ -140,6 +141,8 @@ public: EIDL_TC_SUPPRESSION_WARNING,// -St option used with exception decl EIDL_ILLEGAL_BOXED_TYPE, // Valuetype not allowed for box value type EIDL_ILLEGAL_PRIMARY_KEY, // Primary key doesn't meet spec constraints + EIDL_MISMATCHED_T_PARAM, // Between parent and child tempalte interface + EIDL_DUPLICATE_T_PARAM, // A template interface's param ids must be unique EIDL_OK // No error }; @@ -339,6 +342,8 @@ public: // Valuetype violates a spec-defined constraint on a // valuetype used as a primary key. void illegal_primary_key (AST_Decl *d); + + void duplicate_param_id (UTL_ScopedName *n); }; #endif // _UTL_ERR_UTL_ERR_HH diff --git a/modules/TAO/TAO_IDL/util/utl_err.cpp b/modules/TAO/TAO_IDL/util/utl_err.cpp index 506648e4899..26a9a47923f 100644 --- a/modules/TAO/TAO_IDL/util/utl_err.cpp +++ b/modules/TAO/TAO_IDL/util/utl_err.cpp @@ -165,6 +165,8 @@ error_string (UTL_Error::ErrorCode c) return "abstract type expected: "; case UTL_Error::EIDL_EVENTTYPE_EXPECTED: return "event type expected: "; + case UTL_Error::EIDL_TMPL_IFACE_EXPECTED: + return "template interface expected: "; case UTL_Error::EIDL_EVAL_ERROR: return "expression evaluation error: "; case UTL_Error::EIDL_INCOMPATIBLE_TYPE: @@ -215,6 +217,10 @@ error_string (UTL_Error::ErrorCode c) return "valuetype not allowed as type of boxed value type"; case UTL_Error::EIDL_ILLEGAL_PRIMARY_KEY: return "illegal primary key"; + case UTL_Error::EIDL_MISMATCHED_T_PARAM: + return "mismatched parameter in template interface parent"; + case UTL_Error::EIDL_DUPLICATE_T_PARAM: + return "duplicate template parameter id"; } return 0; @@ -656,6 +662,7 @@ UTL_Error::error1 (UTL_Error::ErrorCode c, idl_error_header (c, idl_global->lineno (), idl_global->filename ()->get_string ()); + ACE_ERROR ((LM_ERROR, " - ")); d->name ()->dump (*ACE_DEFAULT_LOG_STREAM);; ACE_ERROR ((LM_ERROR, "\n")); @@ -1411,3 +1418,15 @@ UTL_Error::illegal_primary_key (AST_Decl *d) idl_global->set_err_count (idl_global->err_count () + 1); } +void +UTL_Error::duplicate_param_id (UTL_ScopedName *n) +{ + idl_error_header (EIDL_DUPLICATE_T_PARAM, + idl_global->lineno (), + idl_global->filename ()->get_string ()); + ACE_ERROR ((LM_ERROR, " - ")); + n->dump (*ACE_DEFAULT_LOG_STREAM); + ACE_ERROR ((LM_ERROR, "\n")); + idl_global->set_err_count (idl_global->err_count () + 1); +} + |