6 Copyright 1992, 1993, 1994 Sun Microsystems, Inc. Printed in the United
7 States of America. All Rights Reserved.
9 This product is protected by copyright and distributed under the following
10 license restricting its use.
12 The Interface Definition Language Compiler Front End (CFE) is made
13 available for your use provided that you include this license and copyright
14 notice on all media and documentation and the software program in which
15 this product is incorporated in whole or part. You may copy and extend
16 functionality (but may not remove functionality) of the Interface
17 Definition Language CFE without charge, but you are not authorized to
18 license or distribute it to anyone else except as part of a product or
19 program developed by you or with the express written consent of Sun
20 Microsystems, Inc. ("Sun").
22 The names of Sun Microsystems, Inc. and any of its subsidiaries or
23 affiliates may not be used in advertising or publicity pertaining to
24 distribution of Interface Definition Language CFE as permitted herein.
26 This license is effective until terminated by Sun for failure to comply
27 with this license. Upon termination, you shall destroy or return all code
28 and documentation for the Interface Definition Language CFE.
30 INTERFACE DEFINITION LANGUAGE CFE IS PROVIDED AS IS WITH NO WARRANTIES OF
31 ANY KIND INCLUDING THE WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS
32 FOR A PARTICULAR PURPOSE, NONINFRINGEMENT, OR ARISING FROM A COURSE OF
33 DEALING, USAGE OR TRADE PRACTICE.
35 INTERFACE DEFINITION LANGUAGE CFE IS PROVIDED WITH NO SUPPORT AND WITHOUT
36 ANY OBLIGATION ON THE PART OF Sun OR ANY OF ITS SUBSIDIARIES OR AFFILIATES
37 TO ASSIST IN ITS USE, CORRECTION, MODIFICATION OR ENHANCEMENT.
39 SUN OR ANY OF ITS SUBSIDIARIES OR AFFILIATES SHALL HAVE NO LIABILITY WITH
40 RESPECT TO THE INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY
41 INTERFACE DEFINITION LANGUAGE CFE OR ANY PART THEREOF.
43 IN NO EVENT WILL SUN OR ANY OF ITS SUBSIDIARIES OR AFFILIATES BE LIABLE FOR
44 ANY LOST REVENUE OR PROFITS OR OTHER SPECIAL, INDIRECT AND CONSEQUENTIAL
45 DAMAGES, EVEN IF SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
47 Use, duplication, or disclosure by the government is subject to
48 restrictions as set forth in subparagraph (c)(1)(ii) of the Rights in
49 Technical Data and Computer Software clause at DFARS 252.227-7013 and FAR
52 Sun, Sun Microsystems and the Sun logo are trademarks or registered
53 trademarks of Sun Microsystems, Inc.
57 Mountain View, California 94043
61 SunOS, SunSoft, Sun, Solaris, Sun Microsystems or the Sun logo are
62 trademarks or registered trademarks of Sun Microsystems, Inc.
66 #ifndef _AST_DECL_AST_DECL_HH
67 #define _AST_DECL_AST_DECL_HH
69 #include "utl_scoped_name.h"
70 #include "ast_annotation_appls.h"
72 #include "ace/os_include/sys/os_types.h"
73 #include "ace/SString.h"
74 #include "ace/Vector_T.h"
82 * This class is needed (only for g++) to get around a bug in g++ which
83 * causes virtual operations to not be looked up correctly if an operation
84 * is defined in more than one virtual public base class. This class makes
85 * the hierarchy rooted in a single class, thereby eliminating the situation
86 * that causes the bug to appear
88 class TAO_IDL_FE_Export COMMON_Base
91 COMMON_Base (bool local
= false,
92 bool abstract
= false);
94 virtual ~COMMON_Base ();
97 // A no-op, overridden in the child classes.
98 virtual void destroy ();
100 // Accessor needs to get overridden for a few types.
101 virtual bool is_local ();
102 void is_local (bool val
);
104 bool is_abstract () const;
105 void is_abstract (bool val
);
113 * AST_Decl is the base class for almost all AST nodes.
115 * AST_* classes that do not inherit from AST_Decl include AST_Expression and
116 * AST_Union_Label. AST_Decls have a node type (a value from the enum
117 * AST_Decl::NodeType) and a name (a UTL_ScopedName). The node type may be
118 * useful for BEs to be able to distinguish the real type of a node given only
119 * a superclass. Additionally AST_Decl nodes record the scope of definition,
120 * the file name and line number where they were defined, whether this was
121 * defined by the compiler, whether this is the main file or an #include'd
122 * file, among other things.
124 class TAO_IDL_FE_Export AST_Decl
: public virtual COMMON_Base
127 // Enum defining the different kinds of AST nodes.
129 NT_module
// Denotes a module
130 , NT_root
// Denotes the root of AST
131 , NT_interface
// Denotes an interface
132 , NT_interface_fwd
// Fwd declared interface
133 , NT_valuetype
// Denotes a valuetype
134 , NT_valuetype_fwd
// Fwd declared valuetype
135 , NT_const
// Denotes a constant
136 , NT_except
// Denotes an exception
137 , NT_attr
// Denotes an attribute
138 , NT_op
// Denotes an operation
139 , NT_argument
// Denotes an op. argument
140 , NT_union
// Denotes a union
141 , NT_union_fwd
// Fwd declared union
142 , NT_union_branch
// Denotes a union branch
143 , NT_struct
// Denotes a structure
144 , NT_struct_fwd
// Fwd declared struct
145 , NT_field
// Denotes a field in structure
146 , NT_enum
// Denotes an enumeration
147 , NT_enum_val
// Denotes an enum. value
148 , NT_string
// Denotes an IDL string
149 , NT_wstring
// Denotes an IDL wstring
150 , NT_array
// Denotes an IDL array
151 , NT_sequence
// Denotes an IDL sequence
152 , NT_map
// Denotes an IDL map
153 , NT_typedef
// Denotes a typedef
154 , NT_pre_defined
// Denotes a predefined type
155 , NT_native
// Denotes a native type
156 // dependent on the programming
158 , NT_factory
// Denotes a OBV or home factory construct
159 , NT_finder
// Denotes a home finder construct
160 , NT_component
// Denotes a CORBA component
161 , NT_component_fwd
// Denotes a forward declared component
162 , NT_home
// Denotes a CORBA component home
163 , NT_eventtype
// Denotes a CCM event source or sink
164 , NT_eventtype_fwd
// Denotes a forward declared CCM event
165 , NT_valuebox
// Denotes a value box
166 , NT_type
// Template interface parameter
167 , NT_fixed
// Denotes (unsupported) fixed type
168 , NT_porttype
// Denotes a port type
169 , NT_provides
// Denotes a facet
170 , NT_uses
// Denotes a receptacle
171 , NT_publishes
// Denotes an event source
172 , NT_emits
// Denotes a one-to-one event source
173 , NT_consumes
// Denotes an event sink
174 , NT_ext_port
// Denotes an extended port
175 , NT_mirror_port
// Denotes a mirror port
176 , NT_connector
// Denotes a CCM connector
177 , NT_param_holder
// Denotes a template param placeholder
178 , NT_annotation_decl
// The declaration of an annotation
179 , NT_annotation_appl
// Application of an annotation to an IDL element
180 , NT_annotation_member
// Value Inside an Annotation
183 AST_Decl (NodeType type
,
185 bool anonymous
= false);
188 * A sort of copy constructor that creates a copy of the AST_Decl for a new
190 * The new name must be calculated before hand.
191 * This was created for Annotation Applications and Extended Structs.
194 UTL_ScopedName
*name
,
197 virtual ~AST_Decl ();
200 virtual void destroy ();
202 // If this decl has been found, some types need to be
203 // moved onto their true definitions etc. Defaults to
205 virtual AST_Decl
*adjust_found (bool ignore_fwd
, bool full_def_only
);
207 // Is this decl a forward declared type (default false)
208 virtual bool is_fwd ();
213 void set_imported (bool is_it
);
215 bool in_main_file ();
216 void set_in_main_file (bool is_it
);
218 UTL_Scope
*defined_in ();
219 void set_defined_in (UTL_Scope
*);
221 NodeType
node_type ();
224 void set_line (long l
);
226 ACE_CString
& file_name ();
227 void set_file_name (ACE_CString s
);
229 UTL_ScopedName
*name ();
231 UTL_ScopedName
*compute_name (const char *prefix
,
233 // Variation of the <name>. Computes scoped name string, applying
234 // prefix and suffix to the local name component.
236 void set_name (UTL_ScopedName
*n
);
238 Identifier
*local_name () const;
239 void local_name (Identifier
*id
);
241 Identifier
*compute_local_name (const char *prefix
,
243 // Apply prefix and suffix to the local name and return.
245 virtual const char *full_name ();
246 // Return the stringified full name.
248 virtual const char *flat_name ();
249 // Return the flattened full scoped name.
251 const char *repoID ();
252 void repoID (char *value
);
253 // Accessors for the repository ID.
255 const char *prefix ();
256 void prefix (const char *value
);
257 // Accessors for the repository ID prefix.
259 const char *version ();
260 void version (char *value
);
261 // Accessors for the version_ member.
263 bool anonymous () const;
264 void anonymous (bool val
);
265 // Accessors for the anonymous_ member.
267 bool typeid_set () const;
268 void typeid_set (bool val
);
269 // Accessors for the typeid_set_ member.
271 void set_id_with_typeid (char *value
);
272 // Called by a 'typeId' declaration.
274 void set_prefix_with_typeprefix (const char *value
);
275 // Called by a 'type_prefix' declaration.
277 // If there is _cxx_ in the beginning, we will remove that and keep
278 // a copy of the original name. TAO IDL's front end adds _cxx_
279 // prefix to the all the reserved keywords. But when we invoke the
280 // operation remotely, we should be sending only the name with out
282 Identifier
*original_local_name ();
283 void original_local_name (Identifier
*);
285 // To be overridden by the subclasses interface, struct, union, and
286 // the corresponding forward declaration classes.
287 virtual bool is_defined ();
290 virtual void dump (ACE_OSTREAM_TYPE
&o
);
293 virtual int ast_accept (ast_visitor
*visitor
);
297 // Return TRUE if "this" has "s" as an ancestor.
298 bool has_ancestor (AST_Decl
*s
);
300 // Return TRUE if "this" is a child of "s".
301 bool is_child (AST_Decl
*s
);
304 // Determines if we are inside of a nested scope or not.
306 UTL_ScopedName
*last_referenced_as () const;
307 void last_referenced_as (UTL_ScopedName
*n
);
309 // Accessors for the prefix_scope_ member.
310 UTL_Scope
*prefix_scope ();
311 void prefix_scope (UTL_Scope
*s
);
313 // Useful for GIOP to know if a wstring is being marshaled.
314 virtual int contains_wstring ();
315 void contains_wstring (int val
);
317 // Additional checks when we think we have caught an IDL
318 // masking scope error in a lookup, which starts simply with
319 // a comparison of names in a scope masking queue.
320 bool masking_checks (AST_Decl
*mod
);
322 // Accessors for the member.
323 bool in_tmpl_mod_not_aliased () const;
324 void in_tmpl_mod_not_aliased (bool val
);
326 /// Set and get annotations for this IDL element
328 void annotation_appls (const AST_Annotation_Appls
&annotations
);
329 AST_Annotation_Appls
&annotation_appls ();
333 * Dump Annotations AST
335 * By default print each annotation on its own line. If print_inline is true,
336 * it prints them with spaces separating them instead.
338 void dump_annotations (ACE_OSTREAM_TYPE
&o
, bool print_inline
= false);
341 * Dump Object with Annotations
343 void dump_with_annotations (ACE_OSTREAM_TYPE
&o
, bool inline_annotations
= false);
346 * Dump AST Object to Stream
348 * Uses dump_annotations() before dumping if an object has annotations and is
351 friend ACE_OSTREAM_TYPE
&
352 operator<< (ACE_OSTREAM_TYPE
&o
, AST_Decl
&d
);
355 * Returns true if annotations are valid to use on this
357 virtual bool annotatable () const;
360 * Return true if annotations are dumped inline when using <<
362 virtual bool dump_annotations_inline () const;
365 * Return true if annotations are dumped at all when using <<
367 virtual bool auto_dump_annotations () const;
370 * True if defined using idl_global->eval()
372 virtual bool builtin () const;
375 * True if the node should be dumped
377 virtual bool should_be_dumped () const;
380 * Get Annotation Vector
381 * If this is a typedef, it includes recursively acquired annotations from
382 * the possible chain of direct typedefs.
384 virtual AST_Annotation_Appls
&annotations ();
387 * Should AMI visit this node?
389 virtual bool ami_visit ();
392 // These are not private because they're used by
393 // be_predefined_type' constructor and can be called
400 // Flattened fully scoped name.
402 int contains_wstring_
;
403 // If we are a scope, do we contain a wstring at some level?
405 void dump_i (ACE_OSTREAM_TYPE
&o
, const char *s
) const ;
407 void compute_repoID ();
408 // Computes the repoID.
410 void compute_full_name ();
411 // Computes the stringified scoped name.
413 void compute_flat_name ();
414 // Compute the flattened fully scoped name.
416 const char *node_type_to_string (NodeType nt
);
417 // Convert a NodeType to a string for dumping.
419 /// Annotations applied to this IDL element
420 AST_Annotation_Appls
*annotation_appls_
;
423 * True if defined using idl_global->eval()
433 bool pd_in_main_file
;
434 // Defined in main file?
436 UTL_Scope
*pd_defined_in
;
439 NodeType pd_node_type
;
440 // What kind of node.
445 ACE_CString pd_file_name
;
446 // What file defined in.
448 UTL_ScopedName
*pd_name
;
450 Identifier
*pd_local_name
;
453 Identifier
*pd_original_local_name
;
454 // _cxx_ removed if any.
457 // Our full scoped name.
460 // The repository ID prefix.
463 // Set by #pragma version.
466 // Are we an anonymous (no repo ID) type?
469 // Has our repo id been set by a typeId declaration?
471 UTL_ScopedName
*last_referenced_as_
;
472 // Temporary holder of the most recent way we were reference.
473 // The top level component of this is added to pd_name_referenced.
475 // The scope in which our prefix, if any, was assigned.
476 UTL_Scope
*prefix_scope_
;
478 bool in_tmpl_mod_not_aliased_
;
479 // false by default - if true, we can't be referenced.
481 void compute_full_name (UTL_ScopedName
*n
);
482 // Compute the full name of an AST node.
484 void set_prefix_with_typeprefix_r (const char *value
,
485 UTL_Scope
*appeared_in
);
486 // Non-top-level version of set_prefix_with_typeprefix.
489 typedef ACE_Vector
<AST_Decl
*> AST_Decls
;
491 #endif // _AST_DECL_AST_DECL_HH