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 created 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 Identifier
Object_id ("Object");
214 UTL_ScopedName
Object_name (&Object_id
, 0);
217 idl_global
->gen ()->create_predefined_type (
218 AST_PredefinedType::PT_object
,
221 m
->fe_add_predefined_type (pdt
);
223 // Add these to make all keywords protected even in different spellings
225 Identifier
ValueBase_id ("ValueBase");
226 UTL_ScopedName
ValueBase_name (&ValueBase_id
, 0);
229 idl_global
->gen ()->create_predefined_type (
230 AST_PredefinedType::PT_value
,
233 m
->fe_add_predefined_type (pdt
);
235 Identifier
AbstractBase_id ("AbstractBase");
236 UTL_ScopedName
AbstractBase_name (&AbstractBase_id
, 0);
239 idl_global
->gen ()->create_predefined_type (
240 AST_PredefinedType::PT_abstract
,
243 m
->fe_add_predefined_type (pdt
);
245 Identifier
TypeCode_id ("TypeCode");
246 UTL_ScopedName
TypeCode_name (&TypeCode_id
, 0);
249 idl_global
->gen ()->create_predefined_type (
250 AST_PredefinedType::PT_pseudo
,
253 m
->fe_add_predefined_type (pdt
);
256 idl_global
->pragma_prefixes ().pop (trash
);
257 ACE::strdelete (trash
);
260 // Populate idl_global's hash map with upper case versions of
261 // all the IDL keywords
263 fe_populate_idl_keywords (void)
265 static const char *keywords
[] =
338 ACE_Hash_Map_Manager
<ACE_CString
, int, ACE_Null_Mutex
> &map
=
339 idl_global
->idl_keywords ();
341 u_long length
= sizeof (keywords
) / sizeof (char *);
345 for (u_long i
= 0; i
< length
; ++i
)
347 ext_id
.set (keywords
[i
],
349 (void) map
.bind (ext_id
,
358 // Initialize FE global data object.
362 // Initialize some of its data.
363 idl_global
->set_root (0);
364 idl_global
->set_gen (0);
365 idl_global
->set_err (FE_new_UTL_Error ());
366 idl_global
->set_err_count (0);
367 idl_global
->set_indent (FE_new_UTL_Indenter ());
368 idl_global
->set_filename (0);
369 idl_global
->set_main_filename (0);
370 idl_global
->set_real_filename (0);
371 idl_global
->set_stripped_filename (0);
372 idl_global
->set_import (true);
373 idl_global
->set_in_main_file (false);
374 idl_global
->set_lineno (-1);
375 idl_global
->set_prog_name (0);
377 char local_escapes
[LOCAL_ESCAPES_BUFFER_SIZE
];
378 ACE_OS::memset (&local_escapes
,
380 LOCAL_ESCAPES_BUFFER_SIZE
);
382 idl_global
->set_local_escapes (local_escapes
);
383 idl_global
->set_compile_flags (0);
384 idl_global
->set_include_file_names (0);
385 idl_global
->set_n_include_file_names (0);
386 idl_global
->set_parse_state (IDL_GlobalData::PS_NoState
);
387 idl_global
->preserve_cpp_keywords (false);
389 // Put an empty prefix on the stack for the global scope.
390 idl_global
->pragma_prefixes ().push (ACE::strnew (""));
398 // Check that the BE init created a generator object
399 if (idl_global
->gen () == 0)
403 ACE_TEXT ("IDL: idl_global->gen() not initialized, exiting\n")
409 // Create a global root for the AST. Note that the AST root has no name.
410 Identifier
root_id ("");
411 UTL_ScopedName
root_name (&root_id
, 0);
412 r
= idl_global
->gen ()->create_root (&root_name
);
413 idl_global
->set_root (r
);
419 ACE_TEXT ("IDL: FE init failed to create AST root, exiting\n")
425 // Push it on the stack
426 idl_global
->scopes ().push (idl_global
->root ());
428 // Populate it with nodes for predefined types.
429 fe_populate_global_scope ();
431 // Set flag to indicate we are processing the main file now.
432 idl_global
->set_in_main_file (true);
434 // Populate the IDL keyword container, for checking local identifiers.
435 fe_populate_idl_keywords ();
439 FE_extract_env_include_paths (ACE_Unbounded_Queue
<ACE_CString
> &list
)
441 ACE_Env_Value
<char*> incl_paths (ACE_TEXT ("INCLUDE"),
443 const char *aggr_str
= incl_paths
;
448 #if defined (ACE_WIN32)
453 ACE_CString
aggr_cstr (aggr_str
);
454 ACE_CString::size_type pos
;
458 pos
= aggr_cstr
.find (separator
);
459 list
.enqueue_tail (aggr_cstr
.substr (0, pos
));
460 aggr_cstr
= aggr_cstr
.substr (pos
+ 1);
461 } while (pos
!= ACE_CString::npos
);
465 // Store include paths from the environment variable, if any.
467 FE_store_env_include_paths (void)
469 ACE_Unbounded_Queue
<ACE_CString
> list
;
470 FE_extract_env_include_paths (list
);
472 ACE_CString
*path_tmp
= 0;
473 for (ACE_Unbounded_Queue_Iterator
<ACE_CString
>iter (list
);
474 !iter
.done (); iter
.advance ())
476 if (iter
.next (path_tmp
) != 0)
478 idl_global
->add_include_path (path_tmp
->fast_rep (), false);
484 FE_get_cpp_loc_from_env (void)
486 const char *cpp_loc
= 0;
488 // See if TAO_IDL_PREPROCESSOR is defined.
489 ACE_Env_Value
<char*> preprocessor (ACE_TEXT ("TAO_IDL_PREPROCESSOR"),
492 // Set cpp_loc to the built in location, unless it has been overriden by
493 // environment variables.
494 if (preprocessor
!= 0)
496 cpp_loc
= preprocessor
;
500 // Check for the deprecated CPP_LOCATION environment variable
501 ACE_Env_Value
<char*> cpp_path (ACE_TEXT ("CPP_LOCATION"),
506 ACE_ERROR ((LM_WARNING
,
507 "WARNING: The environment variable "
508 "CPP_LOCATION has been deprecated.\n"
509 " Please use TAO_IDL_PREPROCESSOR "
516 cpp_loc
= idl_global
->cpp_location ();
524 FE_get_cpp_args_from_env (void)
526 const char *cpp_args
= 0;
528 // Added some customizable preprocessor options
529 ACE_Env_Value
<char*> args1 (ACE_TEXT ("TAO_IDL_PREPROCESSOR_ARGS"),
538 // Check for the deprecated TAO_IDL_DEFAULT_CPP_FLAGS environment
540 ACE_Env_Value
<char*> args2 (ACE_TEXT ("TAO_IDL_DEFAULT_CPP_FLAGS"),
545 ACE_ERROR ((LM_WARNING
,
546 "Warning: The environment variable "
547 "TAO_IDL_DEFAULT_CPP_FLAGS has been "
550 "TAO_IDL_PREPROCESSOR_ARGS instead.\n"));