2 * @file ast_visitor_reifying.cpp
6 //=============================================================================
8 #include "ast_visitor_reifying.h"
9 #include "ast_visitor_context.h"
10 #include "ast_generator.h"
12 #include "ast_interface.h"
13 #include "ast_valuetype.h"
14 #include "ast_valuebox.h"
15 #include "ast_eventtype.h"
16 #include "ast_connector.h"
18 #include "ast_exception.h"
19 #include "ast_typedef.h"
20 #include "ast_array.h"
21 #include "ast_sequence.h"
22 #include "ast_union.h"
24 #include "ast_predefined_type.h"
25 #include "ast_string.h"
26 #include "ast_constant.h"
27 #include "ast_native.h"
28 #include "ast_param_holder.h"
29 #include "ast_template_module.h"
31 #include "utl_identifier.h"
32 #include "utl_exprlist.h"
33 #include "utl_strlist.h"
34 #include "utl_string.h"
35 #include "nr_extern.h"
37 ast_visitor_reifying::ast_visitor_reifying (
38 ast_visitor_context
*ctx
)
45 ast_visitor_reifying::~ast_visitor_reifying (void)
50 ast_visitor_reifying::reified_node (void) const
52 return this->reified_node_
;
55 int ast_visitor_reifying::visit_decl (AST_Decl
*)
61 ast_visitor_reifying::visit_scope (UTL_Scope
*)
67 ast_visitor_reifying::visit_type (AST_Type
*)
73 ast_visitor_reifying::visit_module (AST_Module
*)
79 ast_visitor_reifying::visit_interface_fwd (AST_InterfaceFwd
*)
85 ast_visitor_reifying::visit_valuebox (AST_ValueBox
*node
)
87 this->check_and_store (node
);
92 ast_visitor_reifying::visit_valuetype_fwd (AST_ValueTypeFwd
*)
98 ast_visitor_reifying::visit_eventtype_fwd (AST_EventTypeFwd
*)
104 ast_visitor_reifying::visit_component_fwd (AST_ComponentFwd
*)
110 ast_visitor_reifying::visit_template_module (AST_Template_Module
*)
116 ast_visitor_reifying::visit_template_module_inst (AST_Template_Module_Inst
*)
122 ast_visitor_reifying::visit_template_module_ref (AST_Template_Module_Ref
*)
128 ast_visitor_reifying::visit_porttype (AST_PortType
*node
)
130 this->check_and_store (node
);
135 ast_visitor_reifying::visit_provides (AST_Provides
*)
141 ast_visitor_reifying::visit_uses (AST_Uses
*)
147 ast_visitor_reifying::visit_publishes (AST_Publishes
*)
153 ast_visitor_reifying::visit_emits (AST_Emits
*)
159 ast_visitor_reifying::visit_consumes (AST_Consumes
*)
165 ast_visitor_reifying::visit_extended_port (AST_Extended_Port
*)
171 ast_visitor_reifying::visit_mirror_port (AST_Mirror_Port
*)
177 ast_visitor_reifying::visit_connector (AST_Connector
*node
)
179 this->check_and_store (node
);
184 ast_visitor_reifying::visit_home (AST_Home
*node
)
186 this->check_and_store (node
);
191 ast_visitor_reifying::visit_factory (AST_Factory
*)
197 ast_visitor_reifying::visit_finder (AST_Finder
*)
203 ast_visitor_reifying::visit_structure (AST_Structure
*node
)
205 this->check_and_store (node
);
210 ast_visitor_reifying::visit_structure_fwd (AST_StructureFwd
*)
216 ast_visitor_reifying::visit_expression (AST_Expression
*)
222 ast_visitor_reifying::visit_enum (AST_Enum
*node
)
224 this->check_and_store (node
);
229 ast_visitor_reifying::visit_operation (AST_Operation
*)
235 ast_visitor_reifying::visit_field (AST_Field
*)
241 ast_visitor_reifying::visit_argument (AST_Argument
*)
247 ast_visitor_reifying::visit_attribute (AST_Attribute
*)
253 ast_visitor_reifying::visit_union (AST_Union
*node
)
255 this->check_and_store (node
);
260 ast_visitor_reifying::visit_union_fwd (AST_UnionFwd
*)
266 ast_visitor_reifying::visit_union_branch (AST_UnionBranch
*)
272 ast_visitor_reifying::visit_union_label (AST_UnionLabel
*)
278 ast_visitor_reifying::visit_enum_val (AST_EnumVal
*)
284 ast_visitor_reifying::visit_root (AST_Root
*)
290 ast_visitor_reifying::visit_native (AST_Native
*node
)
292 this->check_and_store (node
);
297 ast_visitor_reifying::visit_interface (AST_Interface
*node
)
299 this->check_and_store (node
);
304 ast_visitor_reifying::visit_valuetype (AST_ValueType
*node
)
306 this->check_and_store (node
);
311 ast_visitor_reifying::visit_eventtype (AST_EventType
*node
)
313 this->check_and_store (node
);
318 ast_visitor_reifying::visit_component (AST_Component
*node
)
320 this->check_and_store (node
);
325 ast_visitor_reifying::visit_exception (AST_Exception
*node
)
327 this->check_and_store (node
);
332 ast_visitor_reifying::visit_typedef (AST_Typedef
*node
)
334 this->check_and_store (node
);
339 ast_visitor_reifying::visit_array (AST_Array
*node
)
341 AST_Type
*bt
= node
->base_type ();
343 if (bt
->ast_accept (this) != 0)
345 ACE_ERROR_RETURN ((LM_ERROR
,
346 ACE_TEXT ("ast_visitor_reifying::")
347 ACE_TEXT ("visit_array - ")
348 ACE_TEXT ("visit of base type failed\n")),
352 bt
= dynamic_cast<AST_Type
*> (this->reified_node_
);
354 AST_Expression
**dims
= node
->dims ();
355 AST_Expression
*v
= 0;
356 UTL_ExprList
*v_list
= 0;
358 for (ACE_CDR::ULong i
= 0; i
< node
->n_dims (); ++i
)
360 AST_Param_Holder
*ph
= dims
[i
]->param_holder ();
364 if (this->visit_param_holder (ph
) != 0)
373 ACE_ERROR_RETURN ((LM_ERROR
,
374 ACE_TEXT ("ast_visitor_reifying::")
375 ACE_TEXT ("visit_array - ")
376 ACE_TEXT ("visit_param_holder() ")
377 ACE_TEXT ("failed\n")),
381 AST_Constant
*c
= dynamic_cast<AST_Constant
*> (this->reified_node_
);
384 AST_Expression (c
->constant_value (),
385 AST_Expression::EV_ulong
),
391 AST_Expression (dims
[i
],
392 AST_Expression::EV_ulong
),
396 UTL_ExprList
*el
= 0;
411 UTL_ScopedName
sn (node
->local_name (), 0);
414 idl_global
->gen ()->create_array (&sn
,
420 // No need to add this new node to any scope - it's anonymous
421 // and owned by the node that references it.
430 arr
->set_base_type (bt
);
431 this->reified_node_
= arr
;
437 ast_visitor_reifying::visit_sequence (AST_Sequence
*node
)
439 AST_Type
*bt
= node
->base_type ();
441 if (bt
->ast_accept (this) != 0)
443 ACE_ERROR_RETURN ((LM_ERROR
,
444 ACE_TEXT ("ast_visitor_reifying::")
445 ACE_TEXT ("visit_sequence - ")
446 ACE_TEXT ("visit of base type failed\n")),
450 bt
= dynamic_cast<AST_Type
*> (this->reified_node_
);
452 AST_Expression
*v
= node
->max_size ();
453 AST_Param_Holder
*ph
= v
->param_holder ();
457 if (this->visit_param_holder (ph
) != 0)
459 ACE_ERROR_RETURN ((LM_ERROR
,
460 ACE_TEXT ("ast_visitor_reifying::")
461 ACE_TEXT ("visit_sequence - ")
462 ACE_TEXT ("visit_param_holder() ")
463 ACE_TEXT ("failed\n")),
467 AST_Constant
*c
= dynamic_cast<AST_Constant
*> (this->reified_node_
);
469 v
= c
->constant_value ();
472 AST_Expression
*bound
=
473 idl_global
->gen ()->create_expr (v
,
474 AST_Expression::EV_ulong
);
475 Identifier
id ("sequence");
476 UTL_ScopedName
sn (&id
, 0);
478 this->reified_node_
=
479 idl_global
->gen ()->create_sequence (bound
,
485 // No need to add this new node to any scope - it's anonymous
486 // and owned by the node that references it.
492 ast_visitor_reifying::visit_predefined_type (AST_PredefinedType
*node
)
494 this->reified_node_
= node
;
499 ast_visitor_reifying::visit_string (AST_String
*node
)
501 AST_Expression
*b
= node
->max_size ();
502 AST_Param_Holder
*ph
= b
->param_holder ();
506 if (this->visit_param_holder (ph
) != 0)
508 ACE_ERROR_RETURN ((LM_ERROR
,
509 ACE_TEXT ("ast_visitor_reifying::")
510 ACE_TEXT ("visit_string - ")
511 ACE_TEXT ("visit_param_holder() ")
512 ACE_TEXT ("failed\n")),
516 AST_Constant
*c
= dynamic_cast<AST_Constant
*> (this->reified_node_
);
518 b
= c
->constant_value ();
520 else if (b
->ev ()->u
.ulval
== 0)
522 this->reified_node_
= node
;
526 AST_Expression
*bound
= 0;
527 ACE_NEW_RETURN (bound
,
529 AST_Expression::EV_ulong
),
532 Identifier
id ("string");
533 UTL_ScopedName
sn (&id
, 0);
535 ACE_NEW_RETURN (this->reified_node_
,
536 AST_String (AST_Decl::NT_string
,
546 ast_visitor_reifying::visit_constant (AST_Constant
*node
)
548 // AFAICT, this is called only on the member constant of a param
549 // holder, in which case nothing further is needed.
550 this->reified_node_
= node
;
555 ast_visitor_reifying::visit_param_holder (AST_Param_Holder
*node
)
558 FE_Utils::T_ARGLIST
const *t_args
=
559 this->ctx_
->template_args ();
561 for (FE_Utils::T_PARAMLIST_INFO::ITERATOR
iter (
562 *this->ctx_
->template_params ());
564 iter
.advance (), ++i
)
566 FE_Utils::T_Param_Info
*item
= 0;
569 ACE_CString
name (item
->name_
);
571 /// The param holder's info->name_ may be the same as the
572 /// node's local name, but if the node comes from an
573 /// alias, info->name_ will be the name of the alias's
574 /// referenced template module parameter, while the local
575 /// name will be that of the corresponding alias param
576 /// name, which is what we want.
577 if (name
== node
->local_name ()->get_string ())
579 AST_Decl
**ret_ptr
= 0;
581 if (t_args
->get (ret_ptr
, i
) == 0)
583 AST_Decl
*candidate
= *ret_ptr
;
585 return candidate
->ast_accept (this);
589 ACE_ERROR_RETURN ((LM_ERROR
,
590 ACE_TEXT ("ast_visitor_reifying::")
591 ACE_TEXT ("visit_param_holder() - access of ")
592 ACE_TEXT ("current template arglist failed - ")
593 ACE_TEXT ("param=%C scope=%C index=%d\n"),
594 item
->name_
.c_str (),
595 ScopeAsDecl (idl_global
->scopes ().top ())->full_name (),
602 ACE_ERROR_RETURN ((LM_ERROR
,
603 ACE_TEXT ("ast_visitor_reifying::")
604 ACE_TEXT ("visit_param_holder() - no match for ")
605 ACE_TEXT ("template param %C in %C\n"),
606 node
->local_name ()->get_string (),
607 ScopeAsDecl (idl_global
->scopes ().top ())->full_name ()),
612 ast_visitor_reifying::check_and_store (AST_Decl
*node
)
614 UTL_ScopedName
*tmpl_tail
=
615 this->template_module_rel_name (node
);
620 idl_global
->scopes ().top ()->lookup_by_name (
625 this->reified_node_
= d
;
627 tmpl_tail
->destroy ();
633 this->reified_node_
= node
;
638 ast_visitor_reifying::template_module_rel_name (AST_Decl
*d
)
641 ACE_CString
name (d
->full_name ());
645 if (dynamic_cast<AST_Template_Module
*> (tmp
) != 0)
647 ACE_CString
head (tmp
->local_name ()->get_string ());
649 ACE_CString::size_type start
= name
.find (head
) + 2;
651 ACE_CString
tail (name
.substr (start
+ head
.length ()));
653 return FE_Utils::string_to_scoped_name (tail
.c_str ());
656 tmp
= ScopeAsDecl (tmp
->defined_in ());