5 Copyright 1992, 1993, 1994 Sun Microsystems, Inc. Printed in the United
6 States of America. All Rights Reserved.
8 This product is protected by copyright and distributed under the following
9 license restricting its use.
11 The Interface Definition Language Compiler Front End (CFE) is made
12 available for your use provided that you include this license and copyright
13 notice on all media and documentation and the software program in which
14 this product is incorporated in whole or part. You may copy and extend
15 functionality (but may not remove functionality) of the Interface
16 Definition Language CFE without charge, but you are not authorized to
17 license or distribute it to anyone else except as part of a product or
18 program developed by you or with the express written consent of Sun
19 Microsystems, Inc. ("Sun").
21 The names of Sun Microsystems, Inc. and any of its subsidiaries or
22 affiliates may not be used in advertising or publicity pertaining to
23 distribution of Interface Definition Language CFE as permitted herein.
25 This license is effective until terminated by Sun for failure to comply
26 with this license. Upon termination, you shall destroy or return all code
27 and documentation for the Interface Definition Language CFE.
29 INTERFACE DEFINITION LANGUAGE CFE IS PROVIDED AS IS WITH NO WARRANTIES OF
30 ANY KIND INCLUDING THE WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS
31 FOR A PARTICULAR PURPOSE, NONINFRINGEMENT, OR ARISING FROM A COURSE OF
32 DEALING, USAGE OR TRADE PRACTICE.
34 INTERFACE DEFINITION LANGUAGE CFE IS PROVIDED WITH NO SUPPORT AND WITHOUT
35 ANY OBLIGATION ON THE PART OF Sun OR ANY OF ITS SUBSIDIARIES OR AFFILIATES
36 TO ASSIST IN ITS USE, CORRECTION, MODIFICATION OR ENHANCEMENT.
38 SUN OR ANY OF ITS SUBSIDIARIES OR AFFILIATES SHALL HAVE NO LIABILITY WITH
39 RESPECT TO THE INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY
40 INTERFACE DEFINITION LANGUAGE CFE OR ANY PART THEREOF.
42 IN NO EVENT WILL SUN OR ANY OF ITS SUBSIDIARIES OR AFFILIATES BE LIABLE FOR
43 ANY LOST REVENUE OR PROFITS OR OTHER SPECIAL, INDIRECT AND CONSEQUENTIAL
44 DAMAGES, EVEN IF SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
46 Use, duplication, or disclosure by the government is subject to
47 restrictions as set forth in subparagraph (c)(1)(ii) of the Rights in
48 Technical Data and Computer Software clause at DFARS 252.227-7013 and FAR
51 Sun, Sun Microsystems and the Sun logo are trademarks or registered
52 trademarks of Sun Microsystems, Inc.
56 Mountain View, California 94043
60 SunOS, SunSoft, Sun, Solaris, Sun Microsystems or the Sun logo are
61 trademarks or registered trademarks of Sun Microsystems, Inc.
65 #include "ace/Env_Value_T.h"
68 #include "utl_scoped_name.h"
69 #include "utl_identifier.h"
70 #include "global_extern.h"
71 #include "fe_extern.h"
73 #include "ast_module.h"
74 #include "ast_predefined_type.h"
75 #include "ast_generator.h"
78 const size_t LOCAL_ESCAPES_BUFFER_SIZE
= 1024;
80 // Populate the global scope with all predefined entities.
82 fe_populate_global_scope (void)
84 // No need to create a scoped name for the basic types, the
85 // AST_PredefinedType constructor will do that.
87 AST_PredefinedType
*pdt
= 0;
89 dynamic_cast<AST_Root
*> (idl_global
->root ());
91 Identifier
void_id ("void");
92 UTL_ScopedName
void_name (&void_id
, 0);
95 idl_global
->gen ()->create_predefined_type (
96 AST_PredefinedType::PT_void
,
99 root
->fe_add_predefined_type (pdt
);
101 /// Put this prefix in force while we're creating the
102 /// CORBA module and its contents.
103 char *prefix
= ACE::strnew ("omg.org");
104 idl_global
->pragma_prefixes ().push (prefix
);
106 Identifier
corba_id ("CORBA");
107 UTL_ScopedName
sn (&corba_id
, 0);
110 idl_global
->gen ()->create_module (root
, &sn
);
112 root
->fe_add_module (m
);
113 idl_global
->corba_module (m
);
116 idl_global
->gen ()->create_predefined_type (
117 AST_PredefinedType::PT_long
,
120 m
->fe_add_predefined_type (pdt
);
123 idl_global
->gen ()->create_predefined_type (
124 AST_PredefinedType::PT_ulong
,
127 m
->fe_add_predefined_type (pdt
);
130 idl_global
->gen ()->create_predefined_type (
131 AST_PredefinedType::PT_longlong
,
134 m
->fe_add_predefined_type(pdt
);
137 idl_global
->gen ()->create_predefined_type (
138 AST_PredefinedType::PT_ulonglong
,
141 m
->fe_add_predefined_type (pdt
);
144 idl_global
->gen ()->create_predefined_type (
145 AST_PredefinedType::PT_short
,
148 m
->fe_add_predefined_type (pdt
);
151 idl_global
->gen ()->create_predefined_type (
152 AST_PredefinedType::PT_ushort
,
155 m
->fe_add_predefined_type (pdt
);
158 idl_global
->gen ()->create_predefined_type (
159 AST_PredefinedType::PT_float
,
162 m
->fe_add_predefined_type (pdt
);
165 idl_global
->gen ()->create_predefined_type (
166 AST_PredefinedType::PT_double
,
169 m
->fe_add_predefined_type (pdt
);
172 idl_global
->gen ()->create_predefined_type (
173 AST_PredefinedType::PT_longdouble
,
176 m
->fe_add_predefined_type (pdt
);
179 idl_global
->gen ()->create_predefined_type (
180 AST_PredefinedType::PT_char
,
183 m
->fe_add_predefined_type (pdt
);
186 idl_global
->gen ()->create_predefined_type (
187 AST_PredefinedType::PT_wchar
,
190 m
->fe_add_predefined_type (pdt
);
193 idl_global
->gen ()->create_predefined_type (
194 AST_PredefinedType::PT_octet
,
197 m
->fe_add_predefined_type (pdt
);
200 idl_global
->gen ()->create_predefined_type (
201 AST_PredefinedType::PT_any
,
204 m
->fe_add_predefined_type (pdt
);
207 idl_global
->gen ()->create_predefined_type (
208 AST_PredefinedType::PT_boolean
,
211 m
->fe_add_predefined_type (pdt
);
213 m
->fe_add_predefined_type (idl_global
->gen ()->create_predefined_type (
214 AST_PredefinedType::PT_uint8
, 0));
216 m
->fe_add_predefined_type (idl_global
->gen ()->create_predefined_type (
217 AST_PredefinedType::PT_int8
, 0));
219 Identifier
Object_id ("Object");
220 UTL_ScopedName
Object_name (&Object_id
, 0);
223 idl_global
->gen ()->create_predefined_type (
224 AST_PredefinedType::PT_object
,
227 m
->fe_add_predefined_type (pdt
);
229 // Add these to make all keywords protected even in different spellings
231 Identifier
ValueBase_id ("ValueBase");
232 UTL_ScopedName
ValueBase_name (&ValueBase_id
, 0);
235 idl_global
->gen ()->create_predefined_type (
236 AST_PredefinedType::PT_value
,
239 m
->fe_add_predefined_type (pdt
);
241 Identifier
AbstractBase_id ("AbstractBase");
242 UTL_ScopedName
AbstractBase_name (&AbstractBase_id
, 0);
245 idl_global
->gen ()->create_predefined_type (
246 AST_PredefinedType::PT_abstract
,
249 m
->fe_add_predefined_type (pdt
);
251 Identifier
TypeCode_id ("TypeCode");
252 UTL_ScopedName
TypeCode_name (&TypeCode_id
, 0);
255 idl_global
->gen ()->create_predefined_type (
256 AST_PredefinedType::PT_pseudo
,
259 m
->fe_add_predefined_type (pdt
);
262 idl_global
->pragma_prefixes ().pop (trash
);
263 ACE::strdelete (trash
);
266 // Populate idl_global's hash map with upper case versions of
267 // all the IDL keywords
269 fe_populate_idl_keywords (void)
271 static const char *keywords
[] =
344 ACE_Hash_Map_Manager
<ACE_CString
, int, ACE_Null_Mutex
> &map
=
345 idl_global
->idl_keywords ();
347 u_long length
= sizeof (keywords
) / sizeof (char *);
351 for (u_long i
= 0; i
< length
; ++i
)
353 ext_id
.set (keywords
[i
],
355 (void) map
.bind (ext_id
,
364 // Initialize FE global data object.
368 // Initialize some of its data.
369 idl_global
->set_root (0);
370 idl_global
->set_gen (0);
371 idl_global
->set_err (FE_new_UTL_Error ());
372 idl_global
->set_err_count (0);
373 idl_global
->set_indent (FE_new_UTL_Indenter ());
374 idl_global
->set_filename (0);
375 idl_global
->set_main_filename (0);
376 idl_global
->set_real_filename (0);
377 idl_global
->set_stripped_filename (0);
378 idl_global
->set_import (true);
379 idl_global
->set_in_main_file (false);
380 idl_global
->set_lineno (-1);
381 idl_global
->set_prog_name (0);
383 char local_escapes
[LOCAL_ESCAPES_BUFFER_SIZE
];
384 ACE_OS::memset (&local_escapes
,
386 LOCAL_ESCAPES_BUFFER_SIZE
);
388 idl_global
->set_local_escapes (local_escapes
);
389 idl_global
->set_compile_flags (0);
390 idl_global
->set_include_file_names (0);
391 idl_global
->set_n_include_file_names (0);
392 idl_global
->set_parse_state (IDL_GlobalData::PS_NoState
);
393 idl_global
->preserve_cpp_keywords (false);
395 // Put an empty prefix on the stack for the global scope.
396 idl_global
->pragma_prefixes ().push (ACE::strnew (""));
404 // Check that the BE init created a generator object
405 if (idl_global
->gen () == 0)
409 ACE_TEXT ("IDL: idl_global->gen() not initialized, exiting\n")
415 // Create a global root for the AST. Note that the AST root has no name.
416 Identifier
root_id ("");
417 UTL_ScopedName
root_name (&root_id
, 0);
418 r
= idl_global
->gen ()->create_root (&root_name
);
419 idl_global
->set_root (r
);
425 ACE_TEXT ("IDL: FE init failed to create AST root, exiting\n")
431 // Push it on the stack
432 idl_global
->scopes ().push (idl_global
->root ());
434 // Populate it with nodes for predefined types.
435 fe_populate_global_scope ();
437 // Set flag to indicate we are processing the main file now.
438 idl_global
->set_in_main_file (true);
440 // Populate the IDL keyword container, for checking local identifiers.
441 fe_populate_idl_keywords ();
445 FE_extract_env_include_paths (ACE_Unbounded_Queue
<ACE_CString
> &list
)
447 ACE_Env_Value
<char*> incl_paths (ACE_TEXT ("INCLUDE"),
449 const char *aggr_str
= incl_paths
;
454 #if defined (ACE_WIN32)
459 ACE_CString
aggr_cstr (aggr_str
);
460 ACE_CString::size_type pos
;
464 pos
= aggr_cstr
.find (separator
);
465 list
.enqueue_tail (aggr_cstr
.substr (0, pos
));
466 aggr_cstr
= aggr_cstr
.substr (pos
+ 1);
467 } while (pos
!= ACE_CString::npos
);
471 // Store include paths from the environment variable, if any.
473 FE_store_env_include_paths (void)
475 ACE_Unbounded_Queue
<ACE_CString
> list
;
476 FE_extract_env_include_paths (list
);
478 ACE_CString
*path_tmp
= 0;
479 for (ACE_Unbounded_Queue_Iterator
<ACE_CString
>iter (list
);
480 !iter
.done (); iter
.advance ())
482 if (iter
.next (path_tmp
) != 0)
484 idl_global
->add_include_path (path_tmp
->fast_rep (), false);
490 FE_get_cpp_loc_from_env (void)
492 const char *cpp_loc
= 0;
494 // See if TAO_IDL_PREPROCESSOR is defined.
495 ACE_Env_Value
<char*> preprocessor (ACE_TEXT ("TAO_IDL_PREPROCESSOR"),
498 // Set cpp_loc to the built in location, unless it has been overriden by
499 // environment variables.
500 if (preprocessor
!= 0)
502 cpp_loc
= preprocessor
;
506 // Check for the deprecated CPP_LOCATION environment variable
507 ACE_Env_Value
<char*> cpp_path (ACE_TEXT ("CPP_LOCATION"),
512 ACE_ERROR ((LM_WARNING
,
513 "WARNING: The environment variable "
514 "CPP_LOCATION has been deprecated.\n"
515 " Please use TAO_IDL_PREPROCESSOR "
522 cpp_loc
= idl_global
->cpp_location ();
530 FE_get_cpp_args_from_env (void)
532 const char *cpp_args
= 0;
534 // Added some customizable preprocessor options
535 ACE_Env_Value
<char*> args1 (ACE_TEXT ("TAO_IDL_PREPROCESSOR_ARGS"),
544 // Check for the deprecated TAO_IDL_DEFAULT_CPP_FLAGS environment
546 ACE_Env_Value
<char*> args2 (ACE_TEXT ("TAO_IDL_DEFAULT_CPP_FLAGS"),
551 ACE_ERROR ((LM_WARNING
,
552 "Warning: The environment variable "
553 "TAO_IDL_DEFAULT_CPP_FLAGS has been "
556 "TAO_IDL_PREPROCESSOR_ARGS instead.\n"));