Update NEWS files for next release
[ACE_TAO.git] / TAO / TAO_IDL / ast / ast_home.cpp
blobe4a5bd8c72a1d2a0c0347ec301255f4ff4ab7cc0
1 #include "ast_home.h"
2 #include "ast_component.h"
3 #include "ast_valuetype.h"
4 #include "ast_param_holder.h"
5 #include "ast_operation.h"
6 #include "ast_finder.h"
7 #include "ast_visitor.h"
9 #include "utl_identifier.h"
10 #include "utl_indenter.h"
11 #include "utl_err.h"
12 #include "global_extern.h"
14 AST_Decl::NodeType const
15 AST_Home::NT = AST_Decl::NT_home;
17 AST_Home::AST_Home (UTL_ScopedName *n,
18 AST_Home *base_home,
19 AST_Component *managed_component,
20 AST_Type *primary_key,
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_home,
28 n),
29 AST_Type (AST_Decl::NT_home,
30 n),
31 UTL_Scope (AST_Decl::NT_home),
32 AST_Interface (n,
33 supports,
34 n_supports,
35 supports_flat,
36 n_supports_flat,
37 false,
38 false),
39 pd_base_home (base_home),
40 pd_managed_component (managed_component),
41 pd_primary_key (primary_key),
42 owns_primary_key_ (false)
44 FE_Utils::tmpl_mod_ref_check (this, base_home);
46 AST_ValueType *pk = dynamic_cast<AST_ValueType*> (primary_key);
48 if (pk != nullptr)
50 idl_global->primary_keys ().enqueue_tail (pk);
52 else if (primary_key != nullptr)
54 // If we are here, it's a param holder and we must destroy it.
55 this->owns_primary_key_ = true;
59 AST_Home::~AST_Home ()
63 AST_Decl *
64 AST_Home::look_in_inherited (UTL_ScopedName *e,
65 bool full_def_only)
67 AST_Decl *d = nullptr;
69 if (this->pd_base_home != nullptr)
71 d =
72 this->pd_base_home->lookup_by_name (e, full_def_only);
75 return d;
78 // Look through supported interface list.
79 AST_Decl *
80 AST_Home::look_in_supported (UTL_ScopedName *e,
81 bool full_def_only)
83 AST_Decl *d = nullptr;
84 AST_Type **is = nullptr;
85 long nis = -1;
87 // Can't look in an interface which was not yet defined.
88 if (!this->is_defined ())
90 idl_global->err ()->fwd_decl_lookup (this,
91 e);
92 return nullptr;
95 // OK, loop through supported interfaces.
97 // (Don't leave the inheritance hierarchy, no module or global ...)
98 // Find all and report ambiguous results as error.
100 for (nis = this->n_supports (), is = this->supports ();
101 nis > 0;
102 nis--, is++)
104 if ((*is)->node_type () == AST_Decl::NT_param_holder)
106 continue;
109 AST_Interface *i = dynamic_cast<AST_Interface*> (*is);
111 d = (i)->lookup_by_name_r (e, full_def_only);
113 if (d != nullptr)
115 break;
119 return d;
122 AST_Decl *
123 AST_Home::special_lookup (UTL_ScopedName *e,
124 bool full_def_only,
125 AST_Decl *&/*final_parent_decl*/)
127 AST_Decl *d = this->look_in_inherited (e, full_def_only);
129 if (d == nullptr)
131 d = this->look_in_supported (e, full_def_only);
134 return d;
137 AST_Home *
138 AST_Home::base_home () const
140 return this->pd_base_home;
143 // These next two look ugly, but it is to keep from having to
144 // create separate visitors for homes in the back end.
146 AST_Type **
147 AST_Home::supports () const
149 return
150 this->pd_base_home == nullptr
151 ? this->inherits ()
152 : this->inherits () + 1;
155 long
156 AST_Home::n_supports () const
158 return this->n_inherits ();
161 AST_Component *
162 AST_Home::managed_component () const
164 return this->pd_managed_component;
167 AST_Type *
168 AST_Home::primary_key () const
170 return this->pd_primary_key;
173 void
174 AST_Home::transfer_scope_elements (AST_Interface *dst)
176 for (UTL_ScopeActiveIterator src_iter (this, UTL_Scope::IK_decls);
177 ! src_iter.is_done ();
178 src_iter.next ())
180 AST_Decl *d = src_iter.item ();
182 Identifier *local_id = nullptr;
183 ACE_NEW (local_id,
184 Identifier (d->local_name ()->get_string ()));
185 UTL_ScopedName *last_segment = nullptr;
186 ACE_NEW (last_segment,
187 UTL_ScopedName (local_id,
188 nullptr));
189 UTL_ScopedName *full_name =
190 static_cast<UTL_ScopedName *> (dst->name ()->copy ());
191 full_name->nconc (last_segment);
193 d->set_name (full_name);
194 dst->add_to_scope (d);
195 d->set_defined_in (dst);
198 // Zero decls so that they are not cleaned twice.
199 long const end = this->pd_decls_used;
200 for (long i = 0; i < end; ++i)
202 this->pd_decls[i] = nullptr;
203 --this->pd_decls_used;
207 void
208 AST_Home::destroy ()
210 // If it's a param holder, it was created on the fly.
211 if (owns_primary_key_)
213 this->pd_primary_key->destroy ();
214 delete this->pd_primary_key;
215 this->pd_primary_key = nullptr;
218 this->AST_Interface::destroy ();
221 void
222 AST_Home::dump (ACE_OSTREAM_TYPE &o)
224 this->dump_i (o, "home ");
226 this->local_name ()->dump (o);
228 this->dump_i (o, " ");
230 if (this->pd_base_home != nullptr)
232 this->dump_i (o, ": ");
233 this->pd_base_home->local_name ()->dump (o);
236 if (this->pd_managed_component != nullptr)
238 this->dump_i (o, "\n");
239 this->dump_i (o, "manages ");
240 this->pd_managed_component->local_name ()->dump (o);
243 if (this->pd_primary_key != nullptr)
245 this->dump_i (o, "\n");
246 this->dump_i (o, "primary key ");
247 this->pd_primary_key->local_name ()->dump (o);
250 this->dump_i (o, " {\n");
252 UTL_Scope::dump (o);
253 idl_global->indent ()->skip_to (o);
255 this->dump_i (o, "}");
259 AST_Home::ast_accept (ast_visitor *visitor)
261 return visitor->visit_home (this);
264 AST_Factory *
265 AST_Home::fe_add_factory (AST_Factory *f)
267 return dynamic_cast<AST_Factory*> (this->fe_add_decl (f));
270 AST_Finder *
271 AST_Home::fe_add_finder (AST_Finder *f)
273 return dynamic_cast<AST_Finder*> (this->fe_add_decl (f));