Merge pull request #1844 from jrw972/monterey
[ACE_TAO.git] / TAO / TAO_IDL / fe / fe_component_header.cpp
blobbf9a73f838e5d9dc9c45fd97f07ca2e90450c7f2
1 #include "fe_component_header.h"
3 #include "fe_extern.h"
4 #include "global_extern.h"
5 #include "nr_extern.h"
7 #include "utl_err.h"
8 #include "utl_namelist.h"
10 #include "ast_component.h"
11 #include "ast_module.h"
12 #include "ast_param_holder.h"
14 FE_ComponentHeader::FE_ComponentHeader (UTL_ScopedName *n,
15 UTL_ScopedName *base_component,
16 UTL_NameList *supports,
17 bool /* compile_now */)
18 : FE_InterfaceHeader (n,
19 supports,
20 false,
21 false,
22 false),
23 base_component_ (0)
25 this->compile_inheritance (base_component);
26 this->compile_supports (supports);
29 FE_ComponentHeader::~FE_ComponentHeader (void)
33 AST_Component *
34 FE_ComponentHeader::base_component (void) const
36 return this->base_component_;
39 AST_Type **
40 FE_ComponentHeader::supports (void) const
42 return this->inherits_;
45 long
46 FE_ComponentHeader::n_supports (void) const
48 return this->n_inherits_;
51 AST_Interface **
52 FE_ComponentHeader::supports_flat (void) const
54 return this->inherits_flat_;
57 long
58 FE_ComponentHeader::n_supports_flat (void) const
60 return this->n_inherits_flat_;
63 void
64 FE_ComponentHeader::compile_inheritance (UTL_ScopedName *base_component)
66 // If there is a base component, look up the decl and assign our member.
67 // We also inherit its supported interfaces.
68 if (base_component == 0)
70 return;
73 UTL_Scope *s = idl_global->scopes ().top_non_null ();
74 AST_Decl *d = s->lookup_by_name (base_component,
75 true);
77 if (d == 0)
79 idl_global->err ()->lookup_error (base_component);
81 // This is probably the result of bad IDL.
82 // We will crash if we continue from here.
83 throw Bailout ();
86 if (d->node_type () == AST_Decl::NT_typedef)
88 d = dynamic_cast<AST_Typedef*> (d)->primitive_base_type ();
91 this->base_component_ = dynamic_cast<AST_Component*> (d);
93 if (this->base_component_ == 0)
95 idl_global->err ()->error1 (UTL_Error::EIDL_ILLEGAL_USE,
96 d);
98 else if (!this->base_component_->is_defined ())
100 idl_global->err ()->inheritance_fwd_error (
101 this->name (),
102 this->base_component_
104 this->base_component_ = 0;
108 void
109 FE_ComponentHeader::compile_supports (UTL_NameList *supports)
111 if (supports == 0)
113 return;
116 AST_Decl *d = 0;
117 UTL_ScopedName *item = 0;
118 AST_Interface *iface = 0;
119 AST_Type *t = 0;
120 long j = 0;
121 long k = 0;
123 // Compute expanded flattened non-repeating list of interfaces
124 // which this one inherits from.
126 for (UTL_NamelistActiveIterator l (supports); !l.is_done (); l.next ())
128 item = l.item ();
130 // Check that scope stack is valid.
131 if (idl_global->scopes ().top () == 0)
133 idl_global->err ()->lookup_error (item);
135 // This is probably the result of bad IDL.
136 // We will crash if we continue from here.
137 throw Bailout ();
140 // Look it up.
141 UTL_Scope *s = idl_global->scopes ().top ();
143 d = s->lookup_by_name (item, true);
145 if (d == 0)
147 AST_Decl *sad = ScopeAsDecl (s);
149 if (sad->node_type () == AST_Decl::NT_module)
151 AST_Module *m = dynamic_cast<AST_Module*> (sad);
153 d = m->look_in_prev_mods_local (item->last_component ());
157 // Not found?
158 if (d == 0)
160 idl_global->err ()->lookup_error (item);
162 // This is probably the result of bad IDL.
163 // We will crash if we continue from here.
164 throw Bailout ();
167 // Remove typedefs, if any.
168 if (d->node_type () == AST_Decl::NT_typedef)
170 d = dynamic_cast<AST_Typedef*> (d)->primitive_base_type ();
173 AST_Decl::NodeType nt = d->node_type ();
174 t = dynamic_cast<AST_Type*> (d);
176 if (nt == AST_Decl::NT_interface)
178 iface = dynamic_cast<AST_Interface*> (d);
180 // Undefined interface?
181 if (!iface->is_defined ())
183 idl_global->err ()->inheritance_fwd_error (
184 this->interface_name_,
185 iface);
187 continue;
190 // Local interface? (illegal for components to support).
191 if (iface->is_local ())
193 idl_global->err ()->unconstrained_interface_expected (
194 this->name (),
195 iface->name ());
197 continue;
200 else if (nt == AST_Decl::NT_param_holder)
202 AST_Param_Holder *ph =
203 dynamic_cast<AST_Param_Holder*> (d);
205 nt = ph->info ()->type_;
207 if (nt != AST_Decl::NT_type
208 && nt != AST_Decl::NT_interface)
210 idl_global->err ()->mismatched_template_param (
211 ph->info ()->name_.c_str ());
213 continue;
216 else
218 idl_global->err ()->interface_expected (d);
219 continue;
222 // OK, see if we have to add this to the list of interfaces
223 // inherited from.
224 this->compile_one_inheritance (t);
227 // OK, install in interface header.
228 // First the flat list (all ancestors).
229 if (this->iused_flat_ > 0)
231 ACE_NEW (this->inherits_flat_,
232 AST_Interface *[this->iused_flat_]);
234 for (j = 0; j < this->iused_flat_; ++j)
236 this->inherits_flat_[j] = this->iseen_flat_[j];
239 this->n_inherits_flat_ = this->iused_flat_;
242 // Then the list of immediate ancestors.
243 if (this->iused_ > 0)
245 ACE_NEW (this->inherits_,
246 AST_Type *[this->iused_]);
248 for (k = 0; k < this->iused_; ++k)
250 this->inherits_[k] = this->iseen_[k];
253 this->n_inherits_ = this->iused_;