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 ()
36 FE_Utils::T_PARAMLIST_INFO
*
37 AST_Template_Module::template_params () 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
);
58 AST_Decl
**item
= nullptr;
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
= nullptr;
70 (void) this->template_params_
->get (param
, slot
);
72 if (!this->match_one_param (param
, d
))
74 UTL_ScopedName
*n
= d
->name ();
75 const char *s
= nullptr;
79 AST_Constant
*c
= dynamic_cast<AST_Constant
*> (d
);
80 s
= AST_Expression::exprtype_to_string (c
->et ());
87 idl_global
->err ()->mismatched_template_param (s
);
97 AST_Template_Module::match_param_refs (UTL_StrList
*refs
,
98 UTL_Scope
*decl_scope
)
100 UTL_Scope
*s
= decl_scope
;
101 AST_Template_Module
*enclosing
= nullptr;
103 while (enclosing
== nullptr && s
!= nullptr)
105 enclosing
= dynamic_cast<AST_Template_Module
*> (s
);
106 s
= ScopeAsDecl (s
)->defined_in ();
109 if (enclosing
== nullptr)
111 ACE_ERROR_RETURN ((LM_ERROR
,
112 ACE_TEXT ("AST_Template_Module::")
113 ACE_TEXT ("match_param_refs - ")
114 ACE_TEXT ("enclosing template ")
115 ACE_TEXT ("module scope not found\n")),
119 for (UTL_StrlistActiveIterator
i (refs
);
123 FE_Utils::T_Param_Info
*enclosing_param
=
124 enclosing
->find_param (i
.item ());
126 if (enclosing_param
== nullptr)
128 // Enclosing param not found
132 if (!this->match_param_by_type (enclosing_param
))
134 // Referenced param type not matched to enclosiong param.
143 AST_Template_Module::destroy ()
145 delete this->template_params_
;
146 this->template_params_
= nullptr;
148 this->AST_Module::destroy ();
152 AST_Template_Module::ast_accept (ast_visitor
*visitor
)
154 return visitor
->visit_template_module (this);
157 AST_Template_Module_Ref
*
158 AST_Template_Module::fe_add_template_module_ref (
159 AST_Template_Module_Ref
*m
)
161 return dynamic_cast<AST_Template_Module_Ref
*> (this->fe_add_ref_decl (m
));
165 AST_Template_Module::dump (ACE_OSTREAM_TYPE
& /* o */)
170 AST_Template_Module::match_one_param (FE_Utils::T_Param_Info
*param
,
173 if (param
->type_
== AST_Decl::NT_type
)
178 if (d
->node_type () == AST_Decl::NT_typedef
)
180 AST_Typedef
*td
= dynamic_cast<AST_Typedef
*> (d
);
181 d
= td
->primitive_base_type ();
184 AST_Decl::NodeType other_type
= d
->node_type ();
186 if (other_type
== AST_Decl::NT_const
)
188 AST_Constant
*c
= dynamic_cast<AST_Constant
*> (d
);
190 AST_Expression
*ex
= c
->constant_value ();
192 AST_Expression::AST_ExprValue
*ev
=
193 ex
->check_and_coerce (param
->const_type_
,
194 param
->enum_const_type_decl_
);
198 idl_global
->err ()->coercion_error (ex
,
202 bool retval
= (ev
!= nullptr);
208 return (param
->type_
== other_type
);
211 FE_Utils::T_Param_Info
*
212 AST_Template_Module::find_param (UTL_String
*name
)
214 for (FE_Utils::T_PARAMLIST_INFO::CONST_ITERATOR
i (
215 *this->template_params_
);
219 FE_Utils::T_Param_Info
*param
= nullptr;
222 if (param
->name_
== name
->get_string ())
232 AST_Template_Module::match_param_by_type (
233 FE_Utils::T_Param_Info
*param
)
235 for (FE_Utils::T_PARAMLIST_INFO::CONST_ITERATOR
i (
236 *this->template_params_
);
240 FE_Utils::T_Param_Info
*my_param
= nullptr;
243 if (param
->type_
== my_param
->type_
)
245 if (param
->type_
== AST_Decl::NT_const
)
247 if (param
->const_type_
== my_param
->const_type_
)
249 if (param
->const_type_
== AST_Expression::EV_enum
)
251 if (param
->enum_const_type_decl_
252 == my_param
->enum_const_type_decl_
)
270 idl_global
->err ()->mismatched_template_param (
271 param
->name_
.c_str ());