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 "idl_narrow.h"
71 #include "ast_annotation_appls.h"
73 #include "ace/os_include/sys/os_types.h"
74 #include "ace/SString.h"
75 #include "ace/Vector_T.h"
77 // This is for AIX w/IBM C++
85 * This class is needed (only for g++) to get around a bug in g++ which
86 * causes virtual operations to not be looked up correctly if an operation
87 * is defined in more than one virtual public base class. This class makes
88 * the hierarchy rooted in a single class, thereby eliminating the situation
89 * that causes the bug to appear
91 class TAO_IDL_FE_Export COMMON_Base
94 COMMON_Base (bool local
= false,
95 bool abstract
= false);
97 virtual ~COMMON_Base (void);
100 // A no-op, overridden in the child classes.
101 virtual void destroy (void);
103 // Accessor needs to get overridden for a few types.
104 virtual bool is_local (void);
105 void is_local (bool val
);
107 bool is_abstract (void) const;
108 void is_abstract (bool val
);
116 * AST_Decl is the base class for almost all AST nodes.
118 * AST_* classes that do not inherit from AST_Decl include AST_Expression and
119 * AST_Union_Label. AST_Decls have a node type (a value from the enum
120 * AST_Decl::NodeType) and a name (a UTL_ScopedName). The node type may be
121 * useful for BEs to be able to distinguish the real type of a node given only
122 * a superclass. Additionally AST_Decl nodes record the scope of definition,
123 * the file name and line number where they were defined, whether this was
124 * defined by the compiler, whether this is the main file or an #include'd
125 * file, among other things.
127 class TAO_IDL_FE_Export AST_Decl
: public virtual COMMON_Base
130 // Enum defining the different kinds of AST nodes.
132 NT_module
// Denotes a module
133 , NT_root
// Denotes the root of AST
134 , NT_interface
// Denotes an interface
135 , NT_interface_fwd
// Fwd declared interface
136 , NT_valuetype
// Denotes a valuetype
137 , NT_valuetype_fwd
// Fwd declared valuetype
138 , NT_const
// Denotes a constant
139 , NT_except
// Denotes an exception
140 , NT_attr
// Denotes an attribute
141 , NT_op
// Denotes an operation
142 , NT_argument
// Denotes an op. argument
143 , NT_union
// Denotes a union
144 , NT_union_fwd
// Fwd declared union
145 , NT_union_branch
// Denotes a union branch
146 , NT_struct
// Denotes a structure
147 , NT_struct_fwd
// Fwd declared struct
148 , NT_field
// Denotes a field in structure
149 , NT_enum
// Denotes an enumeration
150 , NT_enum_val
// Denotes an enum. value
151 , NT_string
// Denotes an IDL string
152 , NT_wstring
// Denotes an IDL wstring
153 , NT_array
// Denotes an IDL array
154 , NT_sequence
// Denotes an IDL sequence
155 , NT_typedef
// Denotes a typedef
156 , NT_pre_defined
// Denotes a predefined type
157 , NT_native
// Denotes a native type
158 // dependent on the programming
160 , NT_factory
// Denotes a OBV or home factory construct
161 , NT_finder
// Denotes a home finder construct
162 , NT_component
// Denotes a CORBA component
163 , NT_component_fwd
// Denotes a forward declared component
164 , NT_home
// Denotes a CORBA component home
165 , NT_eventtype
// Denotes a CCM event source or sink
166 , NT_eventtype_fwd
// Denotes a forward declared CCM event
167 , NT_valuebox
// Denotes a value box
168 , NT_type
// Template interface parameter
169 , NT_fixed
// Denotes (unsupported) fixed type
170 , NT_porttype
// Denotes a port type
171 , NT_provides
// Denotes a facet
172 , NT_uses
// Denotes a receptacle
173 , NT_publishes
// Denotes an event source
174 , NT_emits
// Denotes a one-to-one event source
175 , NT_consumes
// Denotes an event sink
176 , NT_ext_port
// Denotes an extended port
177 , NT_mirror_port
// Denotes a mirror port
178 , NT_connector
// Denotes a CCM connector
179 , NT_param_holder
// Denotes a template param placeholder
180 , NT_annotation_decl
// The declaration of an annotation
181 , NT_annotation_appl
// Application of an annotation to an IDL element
182 , NT_annotation_member
// Value Inside an Annotation
185 AST_Decl (NodeType type
,
187 bool anonymous
= false);
190 * A sort of copy constructor that creates a copy of the AST_Decl for a new
192 * The new name must be calculated before hand.
193 * This was created for Annotation Applications and Extended Structs.
196 UTL_ScopedName
*name
,
199 virtual ~AST_Decl (void);
202 virtual void destroy (void);
204 // If this decl has been found, some types need to be
205 // moved onto their true definitions etc. Defaults to
207 virtual AST_Decl
*adjust_found (bool ignore_fwd
, bool full_def_only
);
209 // Is this decl a forward declared type (default false)
210 virtual bool is_fwd (void);
214 bool imported (void);
215 void set_imported (bool is_it
);
217 bool in_main_file (void);
218 void set_in_main_file (bool is_it
);
220 UTL_Scope
*defined_in (void);
221 void set_defined_in (UTL_Scope
*);
223 NodeType
node_type (void);
226 void set_line (long l
);
228 ACE_CString
& file_name (void);
229 void set_file_name (ACE_CString s
);
231 UTL_ScopedName
*name (void);
233 UTL_ScopedName
*compute_name (const char *prefix
,
235 // Variation of the <name>. Computes scoped name string, applying
236 // prefix and suffix to the local name component.
238 void set_name (UTL_ScopedName
*n
);
240 Identifier
*local_name (void);
241 void local_name (Identifier
*id
);
243 Identifier
*compute_local_name (const char *prefix
,
245 // Apply prefix and suffix to the local name and return.
247 virtual const char *full_name (void);
248 // Return the stringified full name.
250 virtual const char *flat_name (void);
251 // Return the flattened full scoped name.
253 const char *repoID (void);
254 void repoID (char *value
);
255 // Accessors for the repository ID.
257 const char *prefix (void);
258 void prefix (const char *value
);
259 // Accessors for the repository ID prefix.
261 const char *version (void);
262 void version (char *value
);
263 // Accessors for the version_ member.
265 bool anonymous (void) const;
266 void anonymous (bool val
);
267 // Accessors for the anonymous_ member.
269 bool typeid_set (void) const;
270 void typeid_set (bool val
);
271 // Accessors for the typeid_set_ member.
273 void set_id_with_typeid (char *value
);
274 // Called by a 'typeId' declaration.
276 void set_prefix_with_typeprefix (const char *value
);
277 // Called by a 'type_prefix' declaration.
279 // If there is _cxx_ in the beginning, we will remove that and keep
280 // a copy of the original name. TAO IDL's front end adds _cxx_
281 // prefix to the all the reserved keywords. But when we invoke the
282 // operation remotely, we should be sending only the name with out
284 Identifier
*original_local_name (void);
285 void original_local_name (Identifier
*);
287 // To be overridden by the subclasses interface, struct, union, and
288 // the corresponding forward declaration classes.
289 virtual bool is_defined (void);
293 DEF_NARROW_FROM_DECL(AST_Decl
);
296 virtual void dump (ACE_OSTREAM_TYPE
&o
);
299 virtual int ast_accept (ast_visitor
*visitor
);
303 // Return TRUE if "this" has "s" as an ancestor.
304 bool has_ancestor (AST_Decl
*s
);
306 // Return TRUE if "this" is a child of "s".
307 bool is_child (AST_Decl
*s
);
309 bool is_nested (void);
310 // Determines if we are inside of a nested scope or not.
312 UTL_ScopedName
*last_referenced_as (void) const;
313 void last_referenced_as (UTL_ScopedName
*n
);
315 // Accessors for the prefix_scope_ member.
316 UTL_Scope
*prefix_scope (void);
317 void prefix_scope (UTL_Scope
*s
);
319 // Useful for GIOP to know if a wstring is being marshaled.
320 virtual int contains_wstring (void);
321 void contains_wstring (int val
);
323 // Additional checks when we think we have caught an IDL
324 // masking scope error in a lookup, which starts simply with
325 // a comparison of names in a scope masking queue.
326 bool masking_checks (AST_Decl
*mod
);
328 // Accessors for the member.
329 bool in_tmpl_mod_not_aliased (void) const;
330 void in_tmpl_mod_not_aliased (bool val
);
332 /// Set and get annotations for this IDL element
334 void annotation_appls (const AST_Annotation_Appls
&annotations
);
335 AST_Annotation_Appls
&annotation_appls ();
339 * Dump Annotations AST
341 * By default print each annotation on its own line. If print_inline is true,
342 * it prints them with spaces separating them instead.
344 void dump_annotations (ACE_OSTREAM_TYPE
&o
, bool print_inline
= false);
347 * Dump Object with Annotations
349 void dump_with_annotations (ACE_OSTREAM_TYPE
&o
, bool inline_annotations
= false);
352 * Dump AST Object to Stream
354 * Uses dump_annotations() before dumping if an object has annotations and is
357 friend ACE_OSTREAM_TYPE
&
358 operator<< (ACE_OSTREAM_TYPE
&o
, AST_Decl
&d
);
361 * Returns true if annotations are valid to use on this
363 virtual bool annotatable () const;
366 * Return true if annotations are dumped inline when using <<
368 virtual bool dump_annotations_inline () const;
371 * Return true if annotations are dumped at all when using <<
373 virtual bool auto_dump_annotations () const;
376 * True if defined using idl_global->eval()
378 virtual bool builtin () const;
381 * True if the node should be dumped
383 virtual bool should_be_dumped () const;
386 * Get Annotation Vector
387 * If this is a typedef, it includes recursively acquired annotations from
388 * the possible chain of direct typedefs.
390 virtual AST_Annotation_Appls
&annotations ();
393 * Should AMI visit this node?
395 virtual bool ami_visit ();
398 // These are not private because they're used by
399 // be_predefined_type' constructor and can be called
406 // Flattened fully scoped name.
408 int contains_wstring_
;
409 // If we are a scope, do we contain a wstring at some level?
411 void dump_i (ACE_OSTREAM_TYPE
&o
, const char *s
) const ;
413 void compute_repoID (void);
414 // Computes the repoID.
416 void compute_full_name (void);
417 // Computes the stringified scoped name.
419 void compute_flat_name (void);
420 // Compute the flattened fully scoped name.
422 const char *node_type_to_string (NodeType nt
);
423 // Convert a NodeType to a string for dumping.
425 /// Annotations applied to this IDL element
426 AST_Annotation_Appls
*annotation_appls_
;
429 * True if defined using idl_global->eval()
439 bool pd_in_main_file
;
440 // Defined in main file?
442 UTL_Scope
*pd_defined_in
;
445 NodeType pd_node_type
;
446 // What kind of node.
451 ACE_CString pd_file_name
;
452 // What file defined in.
454 UTL_ScopedName
*pd_name
;
456 Identifier
*pd_local_name
;
459 Identifier
*pd_original_local_name
;
460 // _cxx_ removed if any.
463 // Our full scoped name.
466 // The repository ID prefix.
469 // Set by #pragma version.
472 // Are we an anonymous (no repo ID) type?
475 // Has our repo id been set by a typeId declaration?
477 UTL_ScopedName
*last_referenced_as_
;
478 // Temporary holder of the most recent way we were reference.
479 // The top level component of this is added to pd_name_referenced.
481 // The scope in which our prefix, if any, was assigned.
482 UTL_Scope
*prefix_scope_
;
484 bool in_tmpl_mod_not_aliased_
;
485 // false by default - if true, we can't be referenced.
487 void compute_full_name (UTL_ScopedName
*n
);
488 // Compute the full name of an AST node.
490 void set_prefix_with_typeprefix_r (const char *value
,
491 UTL_Scope
*appeared_in
);
492 // Non-top-level version of set_prefix_with_typeprefix.
495 typedef ACE_Vector
<AST_Decl
*> AST_Decls
;
497 #endif // _AST_DECL_AST_DECL_HH