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"
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
,
19 AST_Component
*managed_component
,
20 AST_Type
*primary_key
,
23 AST_Interface
**supports_flat
,
27 AST_Decl (AST_Decl::NT_home
,
29 AST_Type (AST_Decl::NT_home
,
31 UTL_Scope (AST_Decl::NT_home
),
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
);
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 ()
64 AST_Home::look_in_inherited (UTL_ScopedName
*e
,
67 AST_Decl
*d
= nullptr;
69 if (this->pd_base_home
!= nullptr)
72 this->pd_base_home
->lookup_by_name (e
, full_def_only
);
78 // Look through supported interface list.
80 AST_Home::look_in_supported (UTL_ScopedName
*e
,
83 AST_Decl
*d
= nullptr;
84 AST_Type
**is
= nullptr;
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,
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 ();
104 if ((*is
)->node_type () == AST_Decl::NT_param_holder
)
109 AST_Interface
*i
= dynamic_cast<AST_Interface
*> (*is
);
111 d
= (i
)->lookup_by_name_r (e
, full_def_only
);
123 AST_Home::special_lookup (UTL_ScopedName
*e
,
125 AST_Decl
*&/*final_parent_decl*/)
127 AST_Decl
*d
= this->look_in_inherited (e
, full_def_only
);
131 d
= this->look_in_supported (e
, full_def_only
);
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.
147 AST_Home::supports () const
150 this->pd_base_home
== nullptr
152 : this->inherits () + 1;
156 AST_Home::n_supports () const
158 return this->n_inherits ();
162 AST_Home::managed_component () const
164 return this->pd_managed_component
;
168 AST_Home::primary_key () const
170 return this->pd_primary_key
;
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 ();
180 AST_Decl
*d
= src_iter
.item ();
182 Identifier
*local_id
= nullptr;
184 Identifier (d
->local_name ()->get_string ()));
185 UTL_ScopedName
*last_segment
= nullptr;
186 ACE_NEW (last_segment
,
187 UTL_ScopedName (local_id
,
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
;
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 ();
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");
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);
265 AST_Home::fe_add_factory (AST_Factory
*f
)
267 return dynamic_cast<AST_Factory
*> (this->fe_add_decl (f
));
271 AST_Home::fe_add_finder (AST_Finder
*f
)
273 return dynamic_cast<AST_Finder
*> (this->fe_add_decl (f
));