From e649f5e23ca6610d990bb5e3b5eb93ba8e7857be Mon Sep 17 00:00:00 2001 From: parsons Date: Mon, 30 Nov 2009 20:05:44 +0000 Subject: ChangeLogTag: Mon Nov 30 20:00:07 UTC 2009 Jeff Parsons --- modules/TAO/ChangeLog | 20 ++++ modules/TAO/TAO_IDL/ast/ast_template_module.cpp | 87 +++++++++++++++++ modules/TAO/TAO_IDL/fe/idl.yy | 102 +++++++++++++++++++- modules/TAO/TAO_IDL/fe/y.tab.cpp | 110 ++++++++++++++++++---- modules/TAO/TAO_IDL/include/ast_template_module.h | 6 ++ modules/TAO/TAO_IDL/include/idl_global.h | 3 + modules/TAO/TAO_IDL/util/utl_err.cpp | 6 ++ 7 files changed, 311 insertions(+), 23 deletions(-) diff --git a/modules/TAO/ChangeLog b/modules/TAO/ChangeLog index 10977372b5b..fbd0a59fb97 100644 --- a/modules/TAO/ChangeLog +++ b/modules/TAO/ChangeLog @@ -1,3 +1,23 @@ +Mon Nov 30 20:04:13 UTC 2009 Jeff Parsons + + * TAO_IDL/includ/idl_global.h: + * TAO_IDL/util/utl_err.cpp: + + Added new parse states for instantiated template modules, + with corresponding error messages. + + * TAO_IDL/include/ast_template_module.h: + * TAO_IDL/ast/ast_template_module.cpp: + + Added methods to check the arglist of an instantiated + template modules against the formal parameters. + + * TAO_IDL/fe/y.tab.cpp: + * TAO_IDL/fe/idl.yy: + + Added semantic actions for creation of instantiated + template module. + Mon Nov 30 17:30:44 UTC 2009 Jeff Parsons * TAO_IDL/fe/idl.yy: diff --git a/modules/TAO/TAO_IDL/ast/ast_template_module.cpp b/modules/TAO/TAO_IDL/ast/ast_template_module.cpp index bf463c545d7..c48267095f8 100644 --- a/modules/TAO/TAO_IDL/ast/ast_template_module.cpp +++ b/modules/TAO/TAO_IDL/ast/ast_template_module.cpp @@ -1,8 +1,12 @@ // $Id$ #include "ast_template_module.h" +#include "ast_constant.h" #include "ast_visitor.h" +#include "utl_err.h" +#include "global_extern.h" + AST_Template_Module::AST_Template_Module ( UTL_ScopedName *n, FE_Utils::T_PARAMLIST_INFO *template_params) @@ -28,6 +32,49 @@ AST_Template_Module::template_params (void) const return this->template_params_; } +bool +AST_Template_Module::match_arg_names (FE_Utils::T_ARGLIST *args) +{ + if (args->size () != this->template_params_->size ()) + { + idl_global->err ()->error1 (UTL_Error::EIDL_T_ARG_LENGTH, + this); + return false; + } + + size_t slot = 0UL; + + for (FE_Utils::T_ARGLIST::CONST_ITERATOR i (*args); + !i.done (); + i.advance ()) + { + AST_Decl **item = 0; + i.next (item); + AST_Decl *d = *item; + + if (d->node_type () == AST_Decl::NT_typedef) + { + AST_Typedef *td = + AST_Typedef::narrow_from_decl (d); + + d = td->primitive_base_type (); + } + + FE_Utils::T_Param_Info *param = 0; + (void) this->template_params_->get (param, slot); + + if (! this->match_param_type (param, d)) + { + idl_global->err ()->mismatched_template_param ( + d->name ()); + + return false; + } + } + + return true; +} + void AST_Template_Module::destroy (void) { @@ -48,6 +95,46 @@ AST_Template_Module::dump (ACE_OSTREAM_TYPE & /* o */) { } +bool +AST_Template_Module::match_param_type (FE_Utils::T_Param_Info *param, + AST_Decl *d) +{ + if (param->type_ == AST_Decl::NT_type) + { + return true; + } + + if (d->node_type () == AST_Decl::NT_typedef) + { + AST_Typedef *td = AST_Typedef::narrow_from_decl (d); + d = td->primitive_base_type (); + } + + AST_Decl::NodeType other_type = d->node_type (); + + if (other_type == AST_Decl::NT_const) + { + AST_Constant *c = + AST_Constant::narrow_from_decl (d); + + AST_Expression *ex = c->constant_value (); + + AST_Expression::AST_ExprValue *ev = + ex->check_and_coerce (param->const_type_, + param->enum_const_type_decl_); + + if (ev == 0) + { + idl_global->err ()->coercion_error (ex, + param->const_type_); + } + + return (ev != 0); + } + + return (param->type_ == other_type); +} + IMPL_NARROW_FROM_DECL (AST_Template_Module) IMPL_NARROW_FROM_SCOPE (AST_Template_Module) diff --git a/modules/TAO/TAO_IDL/fe/idl.yy b/modules/TAO/TAO_IDL/fe/idl.yy index b74c9a4704a..72db8990a63 100644 --- a/modules/TAO/TAO_IDL/fe/idl.yy +++ b/modules/TAO/TAO_IDL/fe/idl.yy @@ -697,12 +697,11 @@ template_module_inst UTL_ScopedName *sn = $1; AST_Template_Module *ref = 0; AST_Decl *d = s->lookup_by_name (sn, true); - bool so_far_so_good = true; if (d == 0) { idl_global->err ()->lookup_error (sn); - so_far_so_good = false; + return 1; } else { @@ -711,17 +710,68 @@ template_module_inst if (ref == 0) { idl_global->err ()->template_module_expected (d); - so_far_so_good = false; + return 1; } } + + idl_global->set_parse_state ( + IDL_GlobalData::PS_InstModuleSeen); } at_least_one_actual_parameter '>' { // at_least_one_actual_parameter '>' + idl_global->set_parse_state ( + IDL_GlobalData::PS_InstModuleArgsSeen); } id { // id + idl_global->set_parse_state ( + IDL_GlobalData::PS_InstModuleIDSeen); + + UTL_Scope *s = idl_global->scopes ().top_non_null (); + UTL_ScopedName *sn = $1; + AST_Template_Module *ref = 0; + AST_Decl *d = s->lookup_by_name (sn, true); + + if (d == 0) + { + idl_global->err ()->lookup_error (sn); + return 1; + } + else + { + ref = AST_Template_Module::narrow_from_decl (d); + + if (ref == 0) + { + idl_global->err ()->template_module_expected (d); + return 1; + } + } + + sn->destroy (); + delete sn; + sn = 0; + $1 = 0; + + if (! ref->match_arg_names ($3)) + { + return 1; + } + + ACE_NEW_RETURN (sn, + UTL_ScopedName ($5, + 0), + 1); + + AST_Template_Module_Inst *tmi = + idl_global->gen ()->create_template_module_inst ( + sn, + ref, + $3); + + s->add_to_scope (tmi); } ; @@ -6427,7 +6477,51 @@ actual_parameter // a constant and look up the type to add to the template // arg list. AST_Expression *ex = $1; - $$ = 0; + UTL_ScopedName *sn = ex->n (); + AST_Decl *d = 0; + UTL_Scope *s = idl_global->scopes ().top_non_null (); + + if (sn != 0) + { + d = s->lookup_by_name (sn, true); + + if (d == 0) + { + idl_global->err ()->lookup_error (sn); + return 1; + } + else + { + AST_Decl::NodeType nt = d->node_type (); + + if (nt == AST_Decl::NT_enum_val) + { + $1->evaluate ( + AST_Expression::EK_const); + + $$ = + idl_global->gen ()->create_constant ( + $1->ev ()->et, + $1, + sn); + } + else + { + $$ = d; + } + } + } + else + { + $1->evaluate ( + AST_Expression::EK_const); + + $$ = + idl_global->gen ()->create_constant ( + $1->ev ()->et, + $1, + 0); + } } ; diff --git a/modules/TAO/TAO_IDL/fe/y.tab.cpp b/modules/TAO/TAO_IDL/fe/y.tab.cpp index 837ab674f88..a371712af02 100644 --- a/modules/TAO/TAO_IDL/fe/y.tab.cpp +++ b/modules/TAO/TAO_IDL/fe/y.tab.cpp @@ -3026,16 +3026,36 @@ tao_yyreduce: { // template_module_inst : template_module_header + idl_global->set_parse_state ( + IDL_GlobalData::PS_InstModuleSeen); + } + break; + + case 62: + + { +// at_least_one_actual_parameter '>' + idl_global->set_parse_state ( + IDL_GlobalData::PS_InstModuleArgsSeen); + } + break; + + case 63: + + { +// id + idl_global->set_parse_state ( + IDL_GlobalData::PS_InstModuleIDSeen); + UTL_Scope *s = idl_global->scopes ().top_non_null (); - UTL_ScopedName *sn = (tao_yyvsp[(1) - (1)].idlist); + UTL_ScopedName *sn = (tao_yyvsp[(1) - (5)].idlist); AST_Template_Module *ref = 0; AST_Decl *d = s->lookup_by_name (sn, true); - bool so_far_so_good = true; if (d == 0) { idl_global->err ()->lookup_error (sn); - so_far_so_good = false; + return 1; } else { @@ -3044,23 +3064,31 @@ tao_yyreduce: if (ref == 0) { idl_global->err ()->template_module_expected (d); - so_far_so_good = false; + return 1; } } - } - break; - - case 62: - - { -// at_least_one_actual_parameter '>' - } - break; - - case 63: - - { -// id + + sn->destroy (); + delete sn; + sn = 0; + + if (! ref->match_arg_names ((tao_yyvsp[(1) - (3)].alval))) + { + return 1; + } + + ACE_NEW_RETURN (sn, + UTL_ScopedName ((tao_yyvsp[(1) - (1)].idval), + 0), + 1); + + AST_Template_Module_Inst *tmi = + idl_global->gen ()->create_template_module_inst ( + sn, + ref, + (tao_yyvsp[(1) - (3)].alval)); + + s->add_to_scope (tmi); } break; @@ -9326,7 +9354,51 @@ tao_yyreduce: // a constant and look up the type to add to the template // arg list. AST_Expression *ex = (tao_yyvsp[(1) - (1)].exval); - (tao_yyval.dcval) = 0; + UTL_ScopedName *sn = ex->n (); + AST_Decl *d = 0; + UTL_Scope *s = idl_global->scopes ().top_non_null (); + + if (sn != 0) + { + d = s->lookup_by_name (sn, true); + + if (d == 0) + { + idl_global->err ()->lookup_error (sn); + return 1; + } + else + { + AST_Decl::NodeType nt = d->node_type (); + + if (nt == AST_Decl::NT_enum_val) + { + (tao_yyvsp[(1) - (1)].exval)->evaluate ( + AST_Expression::EK_const); + + (tao_yyval.dcval) = + idl_global->gen ()->create_constant ( + (tao_yyvsp[(1) - (1)].exval)->ev ()->et, + (tao_yyvsp[(1) - (1)].exval), + sn); + } + else + { + (tao_yyval.dcval) = d; + } + } + } + else + { + (tao_yyvsp[(1) - (1)].exval)->evaluate ( + AST_Expression::EK_const); + + (tao_yyval.dcval) = + idl_global->gen ()->create_constant ( + (tao_yyvsp[(1) - (1)].exval)->ev ()->et, + (tao_yyvsp[(1) - (1)].exval), + 0); + } } break; diff --git a/modules/TAO/TAO_IDL/include/ast_template_module.h b/modules/TAO/TAO_IDL/include/ast_template_module.h index 6ce9ed3a74d..a4ad44c69bd 100644 --- a/modules/TAO/TAO_IDL/include/ast_template_module.h +++ b/modules/TAO/TAO_IDL/include/ast_template_module.h @@ -21,6 +21,8 @@ public: FE_Utils::T_PARAMLIST_INFO const * template_params (void) const; + + bool match_arg_names (FE_Utils::T_ARGLIST *args); // Narrowing. DEF_NARROW_FROM_DECL (AST_Template_Module); @@ -37,6 +39,10 @@ public: protected: FE_Utils::T_PARAMLIST_INFO * template_params_; + +private: + bool match_param_type (FE_Utils::T_Param_Info *param, + AST_Decl *d); }; #endif // AST_TEMPLATE_MODULE_H diff --git a/modules/TAO/TAO_IDL/include/idl_global.h b/modules/TAO/TAO_IDL/include/idl_global.h index 491c767bd62..dfa1697f078 100644 --- a/modules/TAO/TAO_IDL/include/idl_global.h +++ b/modules/TAO/TAO_IDL/include/idl_global.h @@ -148,6 +148,9 @@ public: , PS_TmplModuleSqSeen // '{' seen for template module , PS_TmplModuleQsSeen // '}' seen for template module , PS_TmplModuleBodySeen // Seen a template module body + , PS_InstModuleSeen // Seen MODULE keyword + reference + , PS_InstModuleArgsSeen // Seen template args + , PS_InstModuleIDSeen // Seen instantiated module ID , PS_ValueTypeSeen // Seen a VALUETYPE keyword , PS_ValueTypeForwardSeen // Forward valuetype decl seen , PS_ValueTypeIDSeen // Seen the valuetype ID diff --git a/modules/TAO/TAO_IDL/util/utl_err.cpp b/modules/TAO/TAO_IDL/util/utl_err.cpp index 03d5999c4b2..9a3dd6601da 100644 --- a/modules/TAO/TAO_IDL/util/utl_err.cpp +++ b/modules/TAO/TAO_IDL/util/utl_err.cpp @@ -398,6 +398,12 @@ parse_state_to_error_message (IDL_GlobalData::ParseState ps) return "Illegal syntax or missing type following '}' in template module"; case IDL_GlobalData::PS_TmplModuleBodySeen: return "Illegal syntax following template module body statement(s)"; + case IDL_GlobalData::PS_InstModuleSeen: + return "Illegal syntax following following '<' of module instantiation"; + case IDL_GlobalData::PS_InstModuleArgsSeen: + return "Illegal syntax following following template args"; + case IDL_GlobalData::PS_InstModuleIDSeen: + return "Illegal syntax following following instantiated module identifier"; case IDL_GlobalData::PS_ValueTypeSeen: return "Missing interface identifier following VALUETYPE keyword"; case IDL_GlobalData::PS_ValueTypeForwardSeen: -- cgit v1.2.1