From 94658668ce8f835ff6b81143c6c1a1bdf38fef70 Mon Sep 17 00:00:00 2001 From: parsons Date: Tue, 1 Dec 2009 17:47:40 +0000 Subject: ChangeLogTag: Tue Dec 1 17:39:09 UTC 2009 Jeff Parsons --- modules/TAO/ChangeLog | 19 ++ modules/TAO/TAO_IDL/ast/ast_template_module.cpp | 93 +++++++++- modules/TAO/TAO_IDL/fe/idl.yy | 210 ++++++++++++---------- modules/TAO/TAO_IDL/fe/y.tab.cpp | 71 +++++--- modules/TAO/TAO_IDL/include/ast_template_module.h | 5 + modules/TAO/TAO_IDL/include/utl_scope.h | 7 +- modules/TAO/TAO_IDL/util/utl_scope.cpp | 6 + 7 files changed, 283 insertions(+), 128 deletions(-) diff --git a/modules/TAO/ChangeLog b/modules/TAO/ChangeLog index 6c7af45a6ed..2bd0c1295f6 100644 --- a/modules/TAO/ChangeLog +++ b/modules/TAO/ChangeLog @@ -1,6 +1,25 @@ +Tue Dec 1 17:39:09 UTC 2009 Jeff Parsons + + * TAO_IDL/include/ast_template_module.h: + * TAO_IDL/include/utl_scope.h: + * TAO_IDL/ast/ast_template_module.cpp: + * TAO_IDL/fe/y.tab.cpp: + * TAO_IDL/fe/idl.yy: + * TAO_IDL/util/utl_scope.cpp: + + - Finished matching/error checking code for template + parameter references + - Finished semantic actions for template module aliases + and the associated template parameter references + - Factored ACE_NEW_RETURN macro out of both paths of an + IF block in several production rules dealing with + comma-separated lists + Tue Dec 1 14:46:26 UTC 2009 Jeff Parsons * TAO_IDL/fe/y.tab.cpp: + + Regenrerated and recompiled. Mon Nov 30 23:14:05 UTC 2009 Jeff Parsons diff --git a/modules/TAO/TAO_IDL/ast/ast_template_module.cpp b/modules/TAO/TAO_IDL/ast/ast_template_module.cpp index e4637bbfdf7..906d0d20b8e 100644 --- a/modules/TAO/TAO_IDL/ast/ast_template_module.cpp +++ b/modules/TAO/TAO_IDL/ast/ast_template_module.cpp @@ -1,6 +1,7 @@ // $Id$ #include "ast_template_module.h" +#include "ast_template_module_ref.h" #include "ast_constant.h" #include "ast_visitor.h" @@ -143,6 +144,55 @@ AST_Template_Module::ast_accept (ast_visitor *) return 0;//visitor->visit_template_module (this); } +AST_Template_Module_Ref * +AST_Template_Module::fe_add_template_module_ref ( + AST_Template_Module_Ref *m) +{ + AST_Decl *d = 0; + + // Already defined and cannot be redefined? Or already used? + if ((d = this->lookup_for_add (m, false)) != 0) + { + if (!can_be_redefined (d)) + { + idl_global->err ()->error3 (UTL_Error::EIDL_REDEF, + m, + this, + d); + return 0; + } + + if (this->referenced (d, m->local_name ())) + { + idl_global->err ()->error3 (UTL_Error::EIDL_DEF_USE, + m, + this, + d); + return 0; + } + } + + // Add it to scope. + this->add_to_scope (m); + + // Add it to set of locally referenced symbols. + this->add_to_referenced (m, + false, + m->local_name ()); + + AST_Type *ft = m->field_type (); + UTL_ScopedName *mru = ft->last_referenced_as (); + + if (mru != 0) + { + this->add_to_referenced (ft, + false, + mru->first_component ()); + } + + return m; +} + void AST_Template_Module::dump (ACE_OSTREAM_TYPE & /* o */) { @@ -209,9 +259,48 @@ AST_Template_Module::find_param (UTL_String *name) } bool -match_param_by_type (FE_Utils::T_Param_Info *param) +AST_Template_Module::match_param_by_type ( + FE_Utils::T_Param_Info *param) { - return true; + for (FE_Utils::T_PARAMLIST_INFO::CONST_ITERATOR i ( + *this->template_params_); + !i.done (); + i.advance ()) + { + FE_Utils::T_Param_Info *my_param = 0; + i.next (my_param); + + if (param->type_ == my_param->type_) + { + if (param->type_ == AST_Decl::NT_const) + { + if (param->const_type_ == my_param->const_type_) + { + if (param->const_type_ == AST_Expression::EV_enum) + { + if (param->enum_const_type_decl_ + == my_param->enum_const_type_decl_) + { + return true; + } + } + else + { + return true; + } + } + } + else + { + return true; + } + } + } + + idl_global->err ()->mismatched_template_param ( + param->name_.c_str ()); + + return false; } IMPL_NARROW_FROM_DECL (AST_Template_Module) diff --git a/modules/TAO/TAO_IDL/fe/idl.yy b/modules/TAO/TAO_IDL/fe/idl.yy index 6a7a16b5b51..4685fffe769 100644 --- a/modules/TAO/TAO_IDL/fe/idl.yy +++ b/modules/TAO/TAO_IDL/fe/idl.yy @@ -711,10 +711,30 @@ template_module_ref return 1; } - if (! ref->match_param_refs ($5, s)) + bool refs_match = + ref->match_param_refs ($5, + s); + + if (! refs_match) { - // TODO + // Error message is already output. + return 1; } + + UTL_ScopedName sn ((tao_yyvsp[(8) - (8)].idval), 0); + + AST_Template_Module_Ref *tmr = + idl_global->gen ()->create_template_module_ref ( + &sn, + ref, + $5); + + (void) s->fe_add_template_module_ref (tmr); + + sn.destroy (); + $2->destroy (); + delete $2; + $2 = 0; } ; @@ -1467,7 +1487,7 @@ at_least_one_scoped_name : scoped_name scoped_names { // at_least_one_scoped_name : scoped_name scoped_names - ACE_NEW_RETURN ($$, + ACE_NEW_RETURN ($$, UTL_NameList ($1, $2), 1); @@ -1486,28 +1506,26 @@ scoped_names // scoped_name idl_global->set_parse_state (IDL_GlobalData::PS_ScopedNameSeen); + UTL_NameList *nl = 0; + ACE_NEW_RETURN (nl, + UTL_NameList ($4, + 0), + 1); + if ($1 == 0) { - ACE_NEW_RETURN ($$, - UTL_NameList ($4, - 0), - 1); + $$ = nl; } else { - UTL_NameList *nl = 0; - ACE_NEW_RETURN (nl, - UTL_NameList ($4, - 0), - 1); $1->nconc (nl); - $$ = $1; + $$ = $1; } } | /* EMPTY */ { /* | EMPTY */ - $$ = 0; + $$ = 0; } ; @@ -1543,7 +1561,7 @@ scoped_name UTL_IdList ($3, 0), 1); - ACE_NEW_RETURN ($$, + ACE_NEW_RETURN ($$, UTL_IdList (id, sn), 1); @@ -1571,7 +1589,7 @@ scoped_name 0), 1); $1->nconc (sn); - $$ = $1; + $$ = $1; } ; @@ -2425,28 +2443,26 @@ declarators // declarator idl_global->set_parse_state (IDL_GlobalData::PS_DeclsDeclSeen); + UTL_DeclList *dl = 0; + ACE_NEW_RETURN (dl, + UTL_DeclList ($4, + 0), + 1); + if ($1 == 0) { - ACE_NEW_RETURN ($$, - UTL_DeclList ($4, - 0), - 1); + $$ = dl; } else { - UTL_DeclList *dl = 0; - ACE_NEW_RETURN (dl, - UTL_DeclList ($4, - 0), - 1); $1->nconc (dl); - $$ = $1; + $$ = $1; } } | /* EMPTY */ { /* | EMPTY */ - $$ = 0; + $$ = 0; } ; @@ -2459,7 +2475,7 @@ at_least_one_simple_declarator : simple_declarator simple_declarators { // at_least_one_simple_declarator : simple_declarator simple_declarators - ACE_NEW_RETURN ($$, + ACE_NEW_RETURN ($$, UTL_DeclList ($1, $2), 1); @@ -2478,28 +2494,26 @@ simple_declarators // simple_declarator idl_global->set_parse_state (IDL_GlobalData::PS_DeclsDeclSeen); + UTL_DeclList *dl = 0; + ACE_NEW_RETURN (dl, + UTL_DeclList ($4, + 0), + 1); + if ($1 == 0) { - ACE_NEW_RETURN ($$, - UTL_DeclList ($4, - 0), - 1); + $$ = dl; } else { - UTL_DeclList *dl = 0; - ACE_NEW_RETURN (dl, - UTL_DeclList ($4, - 0), - 1); $1->nconc (dl); - $$ = $1; + $$ = $1; } } | /* EMPTY */ { /* | EMPTY */ - $$ = 0; + $$ = 0; } ; @@ -2512,7 +2526,7 @@ simple_declarator : UTL_ScopedName ($1, 0), 1); - ACE_NEW_RETURN ($$, + ACE_NEW_RETURN ($$, FE_Declarator (sn, FE_Declarator::FD_simple, 0), @@ -2531,7 +2545,7 @@ complex_declarator : 0 ), 1); - ACE_NEW_RETURN ($$, + ACE_NEW_RETURN ($$, FE_Declarator (sn, FE_Declarator::FD_complex, $1), @@ -3152,7 +3166,7 @@ at_least_one_case_label : case_label case_labels { // at_least_one_case_label : case_label case_labels - ACE_NEW_RETURN ($$, + ACE_NEW_RETURN ($$, UTL_LabelList ($1, $2), 1); @@ -3163,28 +3177,26 @@ case_labels : case_labels case_label { // case_labels : case_labels case_label + UTL_LabelList *ll = 0; + ACE_NEW_RETURN (ll, + UTL_LabelList ($2, + 0), + 1); + if ($1 == 0) { - ACE_NEW_RETURN ($$, - UTL_LabelList ($2, - 0), - 1); + $$ = ll; } else { - UTL_LabelList *ll = 0; - ACE_NEW_RETURN (ll, - UTL_LabelList ($2, - 0), - 1); $1->nconc (ll); - $$ = $1; + $$ = $1; } } | /* EMPTY */ { /* | EMPTY */ - $$ = 0; + $$ = 0; } ; @@ -3789,7 +3801,7 @@ at_least_one_array_dim : array_dim array_dims { // at_least_one_array_dim : array_dim array_dims - ACE_NEW_RETURN ($$, + ACE_NEW_RETURN ($$, UTL_ExprList ($1, $2), 1); @@ -3800,28 +3812,26 @@ array_dims : array_dims array_dim { // array_dims : array_dims array_dim + UTL_ExprList *el = 0; + ACE_NEW_RETURN (el, + UTL_ExprList ($2, + 0), + 1); + if ($1 == 0) { - ACE_NEW_RETURN ($$, - UTL_ExprList ($2, - 0), - 1); + $$ = el; } else { - UTL_ExprList *el = 0; - ACE_NEW_RETURN (el, - UTL_ExprList ($2, - 0), - 1); $1->nconc (el); - $$ = $1; + $$ = $1; } } | /* EMPTY */ { /* | EMPTY */ - $$ = 0; + $$ = 0; } ; @@ -4721,7 +4731,7 @@ at_least_one_string_literal : IDL_STRING_LITERAL string_literals { // at_least_one_string_literal : IDL_STRING_LITERAL string_literals - ACE_NEW_RETURN ($$, + ACE_NEW_RETURN ($$, UTL_StrList ($1, $2), 1); @@ -4738,22 +4748,20 @@ string_literals IDL_STRING_LITERAL { // IDL_STRING_LITERAL + UTL_StrList *sl = 0; + ACE_NEW_RETURN (sl, + UTL_StrList ($4, + 0), + 1); + if ($1 == 0) { - ACE_NEW_RETURN ($$, - UTL_StrList ($4, - 0), - 1); + $$ = sl; } else { - UTL_StrList *sl = 0; - ACE_NEW_RETURN (sl, - UTL_StrList ($4, - 0), - 1); $1->nconc (sl); - $$ = $1; + $$ = $1; } } | /* EMPTY */ @@ -4950,9 +4958,10 @@ component_header : */ UTL_ScopedName *n = 0; ACE_NEW_RETURN (n, - UTL_ScopedName ($2, 0), + UTL_ScopedName ($2, + 0), 1); - ACE_NEW_RETURN ($$, + ACE_NEW_RETURN ($$, FE_ComponentHeader (n, $4, $6, @@ -4984,7 +4993,7 @@ component_inheritance_spec scoped_name { // scoped_name - $$ = $3; + $$ = $3; } | /* EMPTY */ { @@ -5141,23 +5150,25 @@ interface_type { // | IDL_OBJECT Identifier *corba_id = 0; + ACE_NEW_RETURN (corba_id, Identifier ("Object"), 1); + UTL_IdList *conc_name = 0; ACE_NEW_RETURN (conc_name, UTL_IdList (corba_id, 0), 1); + ACE_NEW_RETURN (corba_id, Identifier ("CORBA"), 1); - UTL_IdList *corba_name = 0; - ACE_NEW_RETURN (corba_name, + + ACE_NEW_RETURN ($$, UTL_IdList (corba_id, conc_name), 1); - $$ = corba_name; } ; @@ -5491,7 +5502,8 @@ home_header : ACE_NEW_RETURN (n, UTL_ScopedName ($3, 0), 1); - ACE_NEW_RETURN ($$, + + ACE_NEW_RETURN ($$, FE_HomeHeader (n, $5, $7, @@ -5535,7 +5547,7 @@ home_inheritance_spec scoped_name { // scoped_name - $$ = $3; + $$ = $3; } | /* EMPTY */ { @@ -5933,7 +5945,7 @@ event_rest_of_header : // supports_spec idl_global->set_parse_state (IDL_GlobalData::PS_SupportSpecSeen); - ACE_NEW_RETURN ($$, + ACE_NEW_RETURN ($$, FE_EventHeader ( 0, $1, @@ -6204,7 +6216,11 @@ formal_parameter at_least_one_formal_parameter_name : formal_parameter_name formal_parameter_names { - $$ = 0; +// at_least_one_formal_parameter_name : formal_parameter_name formal_parameter_names + ACE_NEW_RETURN ($$, + UTL_StrList ($1, + $2), + 1); } ; @@ -6212,25 +6228,21 @@ formal_parameter_names : formal_parameter_names ',' formal_parameter_name { // formal_parameter_names : formal_parameter_names ',' formal_parameter_name + UTL_StrList *sl = 0; + ACE_NEW_RETURN (sl, + UTL_StrList ($3, + 0), + 1); + if ($1 == 0) { - ACE_NEW_RETURN ($1, - UTL_StrList ($3, - 0), - 1); + $$ = sl; } else { - UTL_StrList *l = 0; - ACE_NEW_RETURN (l, - UTL_StrList ($3, - 0), - 1); - - $1->nconc (l); + $1->nconc (sl); + $$ = $1; } - - $$ = $1; } | /* EMPTY */ { diff --git a/modules/TAO/TAO_IDL/fe/y.tab.cpp b/modules/TAO/TAO_IDL/fe/y.tab.cpp index 0e0888c4039..adb39f58ab1 100644 --- a/modules/TAO/TAO_IDL/fe/y.tab.cpp +++ b/modules/TAO/TAO_IDL/fe/y.tab.cpp @@ -3024,7 +3024,8 @@ tao_yyreduce: IDL_GlobalData::PS_ModuleRefIDSeen); UTL_Scope *s = idl_global->scopes ().top_non_null (); - AST_Decl *d = s->lookup_by_name ((tao_yyvsp[(2) - (8)].idlist), true); + AST_Decl *d = s->lookup_by_name ((tao_yyvsp[(2) - (8)].idlist), + true); if (d == 0) { @@ -3040,11 +3041,31 @@ tao_yyreduce: idl_global->err ()->template_module_expected (d); return 1; } + + bool refs_match = + ref->match_param_refs ((tao_yyvsp[(5) - (8)].slval), + s); - if (! ref->match_param_refs ((tao_yyvsp[(5) - (8)].slval), s)) + if (! refs_match) { - // TODO + // Error message is already output. + return 1; } + + UTL_ScopedName sn ((tao_yyvsp[(8) - (8)].idval), 0); + + AST_Template_Module_Ref *tmr = + idl_global->gen ()->create_template_module_ref ( + &sn, + ref, + (tao_yyvsp[(5) - (8)].slval)); + + (void) s->fe_add_template_module_ref (tmr); + + sn.destroy (); + (tao_yyvsp[(2) - (8)].idlist)->destroy (); + delete (tao_yyvsp[(2) - (8)].idlist); + (tao_yyvsp[(2) - (8)].idlist) = 0; } break; @@ -7452,20 +7473,18 @@ tao_yyreduce: { // IDL_STRING_LITERAL + UTL_StrList *sl = 0; + ACE_NEW_RETURN (sl, + UTL_StrList ((tao_yyvsp[(4) - (4)].sval), + 0), + 1); + if ((tao_yyvsp[(1) - (4)].slval) == 0) { - ACE_NEW_RETURN ((tao_yyval.slval), - UTL_StrList ((tao_yyvsp[(4) - (4)].sval), - 0), - 1); + (tao_yyval.slval) = sl; } else { - UTL_StrList *sl = 0; - ACE_NEW_RETURN (sl, - UTL_StrList ((tao_yyvsp[(4) - (4)].sval), - 0), - 1); (tao_yyvsp[(1) - (4)].slval)->nconc (sl); (tao_yyval.slval) = (tao_yyvsp[(1) - (4)].slval); } @@ -9067,7 +9086,11 @@ tao_yyreduce: case 526: { - (tao_yyval.slval) = 0; +// at_least_one_formal_parameter_name : formal_parameter_name formal_parameter_names + ACE_NEW_RETURN ((tao_yyval.slval), + UTL_StrList ((tao_yyvsp[(1) - (2)].sval), + (tao_yyvsp[(2) - (2)].slval)), + 1); } break; @@ -9075,25 +9098,21 @@ tao_yyreduce: { // formal_parameter_names : formal_parameter_names ',' formal_parameter_name + UTL_StrList *sl = 0; + ACE_NEW_RETURN (sl, + UTL_StrList ((tao_yyvsp[(3) - (3)].sval), + 0), + 1); + if ((tao_yyvsp[(1) - (3)].slval) == 0) { - ACE_NEW_RETURN ((tao_yyvsp[(1) - (3)].slval), - UTL_StrList ((tao_yyvsp[(3) - (3)].sval), - 0), - 1); + (tao_yyval.slval) = sl; } else { - UTL_StrList *l = 0; - ACE_NEW_RETURN (l, - UTL_StrList ((tao_yyvsp[(3) - (3)].sval), - 0), - 1); - - (tao_yyvsp[(1) - (3)].slval)->nconc (l); + (tao_yyvsp[(1) - (3)].slval)->nconc (sl); + (tao_yyval.slval) = (tao_yyvsp[(1) - (3)].slval); } - - (tao_yyval.slval) = (tao_yyvsp[(1) - (3)].slval); } break; diff --git a/modules/TAO/TAO_IDL/include/ast_template_module.h b/modules/TAO/TAO_IDL/include/ast_template_module.h index 9fd0f6ca12e..fce770141f9 100644 --- a/modules/TAO/TAO_IDL/include/ast_template_module.h +++ b/modules/TAO/TAO_IDL/include/ast_template_module.h @@ -41,6 +41,11 @@ public: // Visiting. virtual int ast_accept (ast_visitor *visitor); + // Scope Management Protocol + virtual + AST_Template_Module_Ref *fe_add_template_module_ref ( + AST_Template_Module_Ref *m); + protected: FE_Utils::T_PARAMLIST_INFO * template_params_; diff --git a/modules/TAO/TAO_IDL/include/utl_scope.h b/modules/TAO/TAO_IDL/include/utl_scope.h index 2499d5d0ada..4d94e9b0b0a 100644 --- a/modules/TAO/TAO_IDL/include/utl_scope.h +++ b/modules/TAO/TAO_IDL/include/utl_scope.h @@ -92,6 +92,7 @@ class Identifier; class AST_PredefinedType; class AST_Module; class AST_Template_Module_Inst; +class AST_Template_Module_Ref; class AST_Interface; class AST_InterfaceFwd; class AST_ValueBox; @@ -389,7 +390,11 @@ private: AST_Template_Module_Inst *fe_add_template_module_inst ( AST_Template_Module_Inst *m); - virtual + virtual + AST_Template_Module_Ref *fe_add_template_module_ref ( + AST_Template_Module_Ref *m); + +virtual AST_Interface *fe_add_interface (AST_Interface *i); virtual diff --git a/modules/TAO/TAO_IDL/util/utl_scope.cpp b/modules/TAO/TAO_IDL/util/utl_scope.cpp index 9608384eb4f..0232794a1e4 100644 --- a/modules/TAO/TAO_IDL/util/utl_scope.cpp +++ b/modules/TAO/TAO_IDL/util/utl_scope.cpp @@ -1053,6 +1053,12 @@ UTL_Scope::fe_add_template_module_inst (AST_Template_Module_Inst *) return 0; } +AST_Template_Module_Ref * +UTL_Scope::fe_add_template_module_ref (AST_Template_Module_Ref *) +{ + return 0; +} + AST_Interface * UTL_Scope::fe_add_interface (AST_Interface *) { -- cgit v1.2.1