Merge pull request #1844 from jrw972/monterey
[ACE_TAO.git] / TAO / TAO_IDL / fe / fe_init.cpp
blob4a02d0d66009e76359fa70558efd9e7a403df875
1 /*
3 COPYRIGHT
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
49 52.227-19.
51 Sun, Sun Microsystems and the Sun logo are trademarks or registered
52 trademarks of Sun Microsystems, Inc.
54 SunSoft, Inc.
55 2550 Garcia Avenue
56 Mountain View, California 94043
58 NOTE:
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"
66 #include "ace/UUID.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"
76 #include "ast_root.h"
78 const size_t LOCAL_ESCAPES_BUFFER_SIZE = 1024;
80 // Populate the global scope with all predefined entities.
81 void
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;
88 AST_Root *root =
89 dynamic_cast<AST_Root*> (idl_global->root ());
91 Identifier void_id ("void");
92 UTL_ScopedName void_name (&void_id, 0);
94 pdt =
95 idl_global->gen ()->create_predefined_type (
96 AST_PredefinedType::PT_void,
97 &void_name);
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);
109 AST_Module *m =
110 idl_global->gen ()->create_module (root, &sn);
112 root->fe_add_module (m);
113 idl_global->corba_module (m);
115 pdt =
116 idl_global->gen ()->create_predefined_type (
117 AST_PredefinedType::PT_long,
120 m->fe_add_predefined_type (pdt);
122 pdt =
123 idl_global->gen ()->create_predefined_type (
124 AST_PredefinedType::PT_ulong,
127 m->fe_add_predefined_type (pdt);
129 pdt =
130 idl_global->gen ()->create_predefined_type (
131 AST_PredefinedType::PT_longlong,
134 m->fe_add_predefined_type(pdt);
136 pdt =
137 idl_global->gen ()->create_predefined_type (
138 AST_PredefinedType::PT_ulonglong,
141 m->fe_add_predefined_type (pdt);
143 pdt =
144 idl_global->gen ()->create_predefined_type (
145 AST_PredefinedType::PT_short,
148 m->fe_add_predefined_type (pdt);
150 pdt =
151 idl_global->gen ()->create_predefined_type (
152 AST_PredefinedType::PT_ushort,
155 m->fe_add_predefined_type (pdt);
157 pdt =
158 idl_global->gen ()->create_predefined_type (
159 AST_PredefinedType::PT_float,
162 m->fe_add_predefined_type (pdt);
164 pdt =
165 idl_global->gen ()->create_predefined_type (
166 AST_PredefinedType::PT_double,
169 m->fe_add_predefined_type (pdt);
171 pdt =
172 idl_global->gen ()->create_predefined_type (
173 AST_PredefinedType::PT_longdouble,
176 m->fe_add_predefined_type (pdt);
178 pdt =
179 idl_global->gen ()->create_predefined_type (
180 AST_PredefinedType::PT_char,
183 m->fe_add_predefined_type (pdt);
185 pdt =
186 idl_global->gen ()->create_predefined_type (
187 AST_PredefinedType::PT_wchar,
190 m->fe_add_predefined_type (pdt);
192 pdt =
193 idl_global->gen ()->create_predefined_type (
194 AST_PredefinedType::PT_octet,
197 m->fe_add_predefined_type (pdt);
199 pdt =
200 idl_global->gen ()->create_predefined_type (
201 AST_PredefinedType::PT_any,
204 m->fe_add_predefined_type (pdt);
206 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);
222 pdt =
223 idl_global->gen ()->create_predefined_type (
224 AST_PredefinedType::PT_object,
225 &Object_name);
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);
234 pdt =
235 idl_global->gen ()->create_predefined_type (
236 AST_PredefinedType::PT_value,
237 &ValueBase_name);
239 m->fe_add_predefined_type (pdt);
241 Identifier AbstractBase_id ("AbstractBase");
242 UTL_ScopedName AbstractBase_name (&AbstractBase_id, 0);
244 pdt =
245 idl_global->gen ()->create_predefined_type (
246 AST_PredefinedType::PT_abstract,
247 &AbstractBase_name);
249 m->fe_add_predefined_type (pdt);
251 Identifier TypeCode_id ("TypeCode");
252 UTL_ScopedName TypeCode_name (&TypeCode_id, 0);
254 pdt =
255 idl_global->gen ()->create_predefined_type (
256 AST_PredefinedType::PT_pseudo,
257 &TypeCode_name);
259 m->fe_add_predefined_type (pdt);
261 char *trash = 0;
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
268 void
269 fe_populate_idl_keywords (void)
271 static const char *keywords[] =
273 "ABSTRACT",
274 "ALIAS",
275 "ANY",
276 "ATTRIBUTE",
277 "BOOLEAN",
278 "CASE",
279 "CHAR",
280 "COMPONENT",
281 "CONNECTOR",
282 "CONST",
283 "CONSUMES",
284 "CONTEXT",
285 "CUSTOM",
286 "DEFAULT",
287 "DOUBLE",
288 "EMITS",
289 "EXCEPTION",
290 "ENUM",
291 "EVENTTYPE",
292 "FACTORY",
293 "FALSE",
294 "FINDER",
295 "FIXED",
296 "FLOAT",
297 "GETRAISES",
298 "HOME",
299 "IMPORT",
300 "IN",
301 "INOUT",
302 "INTERFACE",
303 "LOCAL",
304 "LONG",
305 "MIRRORPORT",
306 "MODULE",
307 "MULTIPLE",
308 "NATIVE",
309 "OBJECT",
310 "OCTET",
311 "ONEWAY",
312 "OUT",
313 "PORT",
314 "PORTTYPE",
315 "PRIMARYKEY",
316 "PRIVATE",
317 "PROVIDES",
318 "PUBLIC",
319 "PUBLISHES",
320 "RAISES",
321 "READONLY",
322 "SEQUENCE",
323 "SETRAISES",
324 "SHORT",
325 "STRING",
326 "STRUCT",
327 "SUPPORTS",
328 "SWITCH",
329 "TRUE",
330 "TRUNCATABLE",
331 "TYPEDEF",
332 "TYPEID",
333 "TYPEPREFIX",
334 "UNION",
335 "UNSIGNED",
336 "USES",
337 "VALUEBASE",
338 "VALUETYPE",
339 "VOID",
340 "WCHAR",
341 "WSTRING"
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 *);
348 ACE_CString ext_id;
349 int int_id = 0;
351 for (u_long i = 0; i < length; ++i)
353 ext_id.set (keywords[i],
354 false);
355 (void) map.bind (ext_id,
356 int_id);
360 // FE initialization
361 void
362 FE_init (void)
364 // Initialize FE global data object.
365 ACE_NEW (idl_global,
366 IDL_GlobalData);
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 (""));
399 void
400 FE_populate (void)
402 AST_Root *r = 0;
404 // Check that the BE init created a generator object
405 if (idl_global->gen () == 0)
407 ACE_ERROR ((
408 LM_ERROR,
409 ACE_TEXT ("IDL: idl_global->gen() not initialized, exiting\n")
412 throw Bailout ();
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);
421 if (r == 0)
423 ACE_ERROR ((
424 LM_ERROR,
425 ACE_TEXT ("IDL: FE init failed to create AST root, exiting\n")
428 throw Bailout ();
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 ();
444 void
445 FE_extract_env_include_paths (ACE_Unbounded_Queue<ACE_CString> &list)
447 ACE_Env_Value<char*> incl_paths (ACE_TEXT ("INCLUDE"),
448 (char *) 0);
449 const char *aggr_str = incl_paths;
451 if (aggr_str != 0)
453 char separator;
454 #if defined (ACE_WIN32)
455 separator = ';';
456 #else
457 separator = ':';
458 #endif
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.
472 void
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);
489 const char *
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"),
496 (char *) 0);
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;
504 else
506 // Check for the deprecated CPP_LOCATION environment variable
507 ACE_Env_Value<char*> cpp_path (ACE_TEXT ("CPP_LOCATION"),
508 (char *) 0);
510 if (cpp_path != 0)
512 ACE_ERROR ((LM_WARNING,
513 "WARNING: The environment variable "
514 "CPP_LOCATION has been deprecated.\n"
515 " Please use TAO_IDL_PREPROCESSOR "
516 "instead.\n"));
518 cpp_loc = cpp_path;
520 else
522 cpp_loc = idl_global->cpp_location ();
526 return cpp_loc;
529 const char *
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"),
536 (char *) 0);
538 if (args1 != 0)
540 cpp_args = args1;
542 else
544 // Check for the deprecated TAO_IDL_DEFAULT_CPP_FLAGS environment
545 // variable.
546 ACE_Env_Value<char*> args2 (ACE_TEXT ("TAO_IDL_DEFAULT_CPP_FLAGS"),
547 (char *) 0);
549 if (args2 != 0)
551 ACE_ERROR ((LM_WARNING,
552 "Warning: The environment variable "
553 "TAO_IDL_DEFAULT_CPP_FLAGS has been "
554 "deprecated.\n"
555 " Please use "
556 "TAO_IDL_PREPROCESSOR_ARGS instead.\n"));
558 cpp_args = args2;
562 return cpp_args;