1 #include "fe_component_header.h"
4 #include "global_extern.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
,
25 this->compile_inheritance (base_component
);
26 this->compile_supports (supports
);
29 FE_ComponentHeader::~FE_ComponentHeader (void)
34 FE_ComponentHeader::base_component (void) const
36 return this->base_component_
;
40 FE_ComponentHeader::supports (void) const
42 return this->inherits_
;
46 FE_ComponentHeader::n_supports (void) const
48 return this->n_inherits_
;
52 FE_ComponentHeader::supports_flat (void) const
54 return this->inherits_flat_
;
58 FE_ComponentHeader::n_supports_flat (void) const
60 return this->n_inherits_flat_
;
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)
73 UTL_Scope
*s
= idl_global
->scopes ().top_non_null ();
74 AST_Decl
*d
= s
->lookup_by_name (base_component
,
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.
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
,
98 else if (!this->base_component_
->is_defined ())
100 idl_global
->err ()->inheritance_fwd_error (
102 this->base_component_
104 this->base_component_
= 0;
109 FE_ComponentHeader::compile_supports (UTL_NameList
*supports
)
117 UTL_ScopedName
*item
= 0;
118 AST_Interface
*iface
= 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 ())
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.
141 UTL_Scope
*s
= idl_global
->scopes ().top ();
143 d
= s
->lookup_by_name (item
, true);
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 ());
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.
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_
,
190 // Local interface? (illegal for components to support).
191 if (iface
->is_local ())
193 idl_global
->err ()->unconstrained_interface_expected (
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 ());
218 idl_global
->err ()->interface_expected (d
);
222 // OK, see if we have to add this to the list of interfaces
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_
;