Merge pull request #1844 from jrw972/monterey
[ACE_TAO.git] / TAO / TAO_IDL / ast / ast_component.cpp
blob0e2319a182ffb47d9b0458ee8aa47f7de5ce8cde
1 #include "ast_component.h"
2 #include "ast_attribute.h"
3 #include "ast_provides.h"
4 #include "ast_uses.h"
5 #include "ast_publishes.h"
6 #include "ast_emits.h"
7 #include "ast_consumes.h"
8 #include "ast_mirror_port.h"
9 #include "ast_visitor.h"
10 #include "utl_identifier.h"
11 #include "utl_indenter.h"
12 #include "utl_err.h"
13 #include "global_extern.h"
14 #include "fe_extern.h"
16 AST_Decl::NodeType const
17 AST_Component::NT = AST_Decl::NT_component;
19 AST_Component::AST_Component (UTL_ScopedName *n,
20 AST_Component *base_component,
21 AST_Type **supports,
22 long n_supports,
23 AST_Interface **supports_flat,
24 long n_supports_flat)
25 : COMMON_Base (false,
26 false),
27 AST_Decl (AST_Decl::NT_component,
28 n),
29 AST_Type (AST_Decl::NT_component,
30 n),
31 UTL_Scope (AST_Decl::NT_component),
32 AST_Interface (n,
33 supports,
34 n_supports,
35 supports_flat,
36 n_supports_flat,
37 false,
38 false),
39 pd_base_component (base_component)
41 FE_Utils::tmpl_mod_ref_check (this, base_component);
43 if (!this->imported ())
45 idl_global->component_seen_ = true;
49 AST_Component::~AST_Component (void)
53 void
54 AST_Component::redefine (AST_Interface *from)
56 AST_Component *c = dynamic_cast<AST_Component*> (from);
58 if (c == 0)
60 idl_global->err ()->redef_error (from->local_name ()->get_string (),
61 this->local_name ()->get_string ());
62 return;
65 // Copy over all the base class members.
66 this->AST_Interface::redefine (from);
68 this->pd_base_component = c->pd_base_component;
71 AST_Decl *
72 AST_Component::look_in_inherited (UTL_ScopedName *e,
73 bool full_def_only)
75 AST_Decl *d = 0;
77 if (this->pd_base_component != 0)
79 d =
80 this->pd_base_component->lookup_by_name_r (
82 full_def_only);
85 return d;
88 // Look through supported interface list.
89 AST_Decl *
90 AST_Component::look_in_supported (UTL_ScopedName *e,
91 bool full_def_only)
93 AST_Decl *d = 0;
94 AST_Type **is = 0;
95 long nis = -1;
97 // Can't look in an interface which was not yet defined.
98 if (!this->is_defined ())
100 idl_global->err ()->fwd_decl_lookup (this, e);
101 return 0;
104 // OK, loop through supported interfaces.
106 for (nis = this->n_supports (), is = this->supports ();
107 nis > 0;
108 nis--, is++)
110 if ((*is)->node_type () == AST_Decl::NT_param_holder)
112 continue;
115 AST_Interface *i =
116 dynamic_cast<AST_Interface*> (*is);
118 d = (i)->lookup_by_name_r (e, full_def_only);
120 if (d != 0)
122 break;
126 return d;
129 AST_Component *
130 AST_Component::base_component (void) const
132 return this->pd_base_component;
135 AST_Type **
136 AST_Component::supports (void) const
138 return this->inherits ();
141 long
142 AST_Component::n_supports (void) const
144 return this->n_inherits ();
147 AST_Decl *
148 AST_Component::special_lookup (UTL_ScopedName *e,
149 bool full_def_only,
150 AST_Decl *&/*final_parent_decl*/)
152 AST_Decl *d = this->look_in_inherited (e, full_def_only);
154 if (d == 0)
156 d = this->look_in_supported (e, full_def_only);
159 return d;
162 void
163 AST_Component::destroy (void)
165 this->AST_Interface::destroy ();
168 void
169 AST_Component::dump (ACE_OSTREAM_TYPE &o)
171 this->dump_i (o, "component ");
173 this->local_name ()->dump (o);
175 this->dump_i (o, " ");
177 if (this->pd_base_component != 0)
179 this->dump_i (o, ": ");
180 this->pd_base_component->local_name ()->dump (o);
183 if (this->pd_n_inherits > 0)
185 this->dump_i (o, "supports ");
187 for (long i = 0; i < this->pd_n_inherits; ++i)
189 this->pd_inherits[i]->local_name ()->dump (o);
191 if (i < this->pd_n_inherits - 1)
193 this->dump_i (o, ", ");
198 this->dump_i (o, " {\n");
200 UTL_Scope::dump (o);
201 idl_global->indent ()->skip_to (o);
203 this->dump_i (o, "}");
207 AST_Component::ast_accept (ast_visitor *visitor)
209 return visitor->visit_component (this);
212 AST_Provides *
213 AST_Component::fe_add_provides (AST_Provides *p)
215 return dynamic_cast<AST_Provides*> (this->fe_add_ref_decl (p));
218 AST_Uses *
219 AST_Component::fe_add_uses (AST_Uses *u)
221 return dynamic_cast<AST_Uses*> (this->fe_add_ref_decl (u));
224 AST_Publishes *
225 AST_Component::fe_add_publishes (AST_Publishes *p)
227 return dynamic_cast<AST_Publishes*> (this->fe_add_ref_decl (p));
230 AST_Emits *
231 AST_Component::fe_add_emits (AST_Emits *e)
233 return dynamic_cast<AST_Emits*> (this->fe_add_ref_decl (e));
236 AST_Consumes *
237 AST_Component::fe_add_consumes (AST_Consumes *c)
239 return dynamic_cast<AST_Consumes*> (this->fe_add_ref_decl (c));
242 AST_Extended_Port *
243 AST_Component::fe_add_extended_port (AST_Extended_Port *p)
245 return dynamic_cast<AST_Extended_Port*> (this->fe_add_ref_decl (p));
248 AST_Mirror_Port *
249 AST_Component::fe_add_mirror_port (AST_Mirror_Port *p)
251 return dynamic_cast<AST_Mirror_Port*> (this->fe_add_ref_decl (p));
255 AST_Component::be_add_uses (AST_Uses *i,
256 AST_Uses *ix)
258 // Add it to scope.
259 this->add_to_scope (i,
260 ix);
262 // Add it to set of locally referenced symbols.
263 this->add_to_referenced (i,
264 false,
265 i->local_name (),
266 ix);
268 return 0;
271 IMPL_NARROW_FROM_DECL (AST_Component)
272 IMPL_NARROW_FROM_SCOPE (AST_Component)