1 #include "ast_template_module.h"
2 #include "ast_template_module_ref.h"
3 #include "ast_constant.h"
5 #include "ast_typedef.h"
6 #include "ast_visitor.h"
9 #include "utl_string.h"
10 #include "utl_strlist.h"
11 #include "global_extern.h"
12 #include "nr_extern.h"
14 AST_Decl::NodeType
const
15 AST_Template_Module::NT
= AST_Decl::NT_module
;
17 AST_Template_Module::AST_Template_Module (
19 FE_Utils::T_PARAMLIST_INFO
*template_params
)
22 AST_Decl (AST_Decl::NT_module
,
24 UTL_Scope (AST_Decl::NT_module
),
26 AST_Type (AST_Decl::NT_module
,
28 template_params_ (template_params
)
32 AST_Template_Module::~AST_Template_Module (void)
36 FE_Utils::T_PARAMLIST_INFO
*
37 AST_Template_Module::template_params (void) const
39 return this->template_params_
;
43 AST_Template_Module::match_arg_names (FE_Utils::T_ARGLIST
*args
)
45 if (args
->size () != this->template_params_
->size ())
47 idl_global
->err ()->error1 (UTL_Error::EIDL_T_ARG_LENGTH
,
54 for (FE_Utils::T_ARGLIST::CONST_ITERATOR
i (*args
);
62 if (d
->node_type () == AST_Decl::NT_typedef
)
64 AST_Typedef
*td
= dynamic_cast<AST_Typedef
*> (d
);
66 d
= td
->primitive_base_type ();
69 FE_Utils::T_Param_Info
*param
= 0;
70 (void) this->template_params_
->get (param
, slot
);
73 if (! this->match_one_param (param
, d
))
75 UTL_ScopedName
*n
= d
->name ();
79 AST_Constant
*c
= dynamic_cast<AST_Constant
*> (d
);
81 s
= c
->exprtype_to_string ();
88 idl_global
->err ()->mismatched_template_param (s
);
98 AST_Template_Module::match_param_refs (UTL_StrList
*refs
,
99 UTL_Scope
*decl_scope
)
101 UTL_Scope
*s
= decl_scope
;
102 AST_Template_Module
*enclosing
= 0;
104 while (enclosing
== 0 && s
!= 0)
106 enclosing
= dynamic_cast<AST_Template_Module
*> (s
);
107 s
= ScopeAsDecl (s
)->defined_in ();
112 ACE_ERROR_RETURN ((LM_ERROR
,
113 ACE_TEXT ("AST_Template_Module::")
114 ACE_TEXT ("match_param_refs - ")
115 ACE_TEXT ("enclosing template ")
116 ACE_TEXT ("module scope not found\n")),
120 for (UTL_StrlistActiveIterator
i (refs
);
124 FE_Utils::T_Param_Info
*enclosing_param
=
125 enclosing
->find_param (i
.item ());
127 if (enclosing_param
== 0)
129 // Enclosing param not found
133 if (!this->match_param_by_type (enclosing_param
))
135 // Referenced param type not matched to enclosiong param.
144 AST_Template_Module::destroy (void)
146 delete this->template_params_
;
147 this->template_params_
= 0;
149 this->AST_Module::destroy ();
153 AST_Template_Module::ast_accept (ast_visitor
*visitor
)
155 return visitor
->visit_template_module (this);
158 AST_Template_Module_Ref
*
159 AST_Template_Module::fe_add_template_module_ref (
160 AST_Template_Module_Ref
*m
)
162 return dynamic_cast<AST_Template_Module_Ref
*> (this->fe_add_ref_decl (m
));
166 AST_Template_Module::dump (ACE_OSTREAM_TYPE
& /* o */)
171 AST_Template_Module::match_one_param (FE_Utils::T_Param_Info
*param
,
174 if (param
->type_
== AST_Decl::NT_type
)
179 if (d
->node_type () == AST_Decl::NT_typedef
)
181 AST_Typedef
*td
= dynamic_cast<AST_Typedef
*> (d
);
182 d
= td
->primitive_base_type ();
185 AST_Decl::NodeType other_type
= d
->node_type ();
187 if (other_type
== AST_Decl::NT_const
)
189 AST_Constant
*c
= dynamic_cast<AST_Constant
*> (d
);
191 AST_Expression
*ex
= c
->constant_value ();
193 AST_Expression::AST_ExprValue
*ev
=
194 ex
->check_and_coerce (param
->const_type_
,
195 param
->enum_const_type_decl_
);
199 idl_global
->err ()->coercion_error (ex
,
203 bool retval
= (ev
!= 0);
209 return (param
->type_
== other_type
);
212 FE_Utils::T_Param_Info
*
213 AST_Template_Module::find_param (UTL_String
*name
)
215 for (FE_Utils::T_PARAMLIST_INFO::CONST_ITERATOR
i (
216 *this->template_params_
);
220 FE_Utils::T_Param_Info
*param
= 0;
223 if (param
->name_
== name
->get_string ())
233 AST_Template_Module::match_param_by_type (
234 FE_Utils::T_Param_Info
*param
)
236 for (FE_Utils::T_PARAMLIST_INFO::CONST_ITERATOR
i (
237 *this->template_params_
);
241 FE_Utils::T_Param_Info
*my_param
= 0;
244 if (param
->type_
== my_param
->type_
)
246 if (param
->type_
== AST_Decl::NT_const
)
248 if (param
->const_type_
== my_param
->const_type_
)
250 if (param
->const_type_
== AST_Expression::EV_enum
)
252 if (param
->enum_const_type_decl_
253 == my_param
->enum_const_type_decl_
)
271 idl_global
->err ()->mismatched_template_param (
272 param
->name_
.c_str ());
277 IMPL_NARROW_FROM_DECL (AST_Template_Module
)
278 IMPL_NARROW_FROM_SCOPE (AST_Template_Module
)