Changes to attempt to silence bcc64x
[ACE_TAO.git] / TAO / TAO_IDL / fe / fe_init.cpp
blobdd8e162edbd7f256ed9575315ff54edab3dfb1ec
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"
67 #include "utl_scoped_name.h"
68 #include "utl_identifier.h"
69 #include "global_extern.h"
70 #include "fe_extern.h"
72 #include "ast_module.h"
73 #include "ast_predefined_type.h"
74 #include "ast_generator.h"
75 #include "ast_root.h"
77 const size_t LOCAL_ESCAPES_BUFFER_SIZE = 1024;
79 // Populate the global scope with all predefined entities.
80 void
81 fe_populate_global_scope ()
83 // No need to create a scoped name for the basic types, the
84 // AST_PredefinedType constructor will do that.
86 AST_PredefinedType *pdt = nullptr;
87 AST_Root *root =
88 dynamic_cast<AST_Root*> (idl_global->root ());
90 Identifier void_id ("void");
91 UTL_ScopedName void_name (&void_id, nullptr);
93 pdt =
94 idl_global->gen ()->create_predefined_type (
95 AST_PredefinedType::PT_void,
96 &void_name);
98 root->fe_add_predefined_type (pdt);
100 /// Put this prefix in force while we're creating the
101 /// CORBA module and its contents.
102 char *prefix = ACE::strnew ("omg.org");
103 idl_global->pragma_prefixes ().push (prefix);
105 Identifier corba_id ("CORBA");
106 UTL_ScopedName sn (&corba_id, nullptr);
108 AST_Module *m =
109 idl_global->gen ()->create_module (root, &sn);
111 root->fe_add_module (m);
112 idl_global->corba_module (m);
114 pdt =
115 idl_global->gen ()->create_predefined_type (
116 AST_PredefinedType::PT_long,
117 nullptr);
119 m->fe_add_predefined_type (pdt);
121 pdt =
122 idl_global->gen ()->create_predefined_type (
123 AST_PredefinedType::PT_ulong,
124 nullptr);
126 m->fe_add_predefined_type (pdt);
128 pdt =
129 idl_global->gen ()->create_predefined_type (
130 AST_PredefinedType::PT_longlong,
131 nullptr);
133 m->fe_add_predefined_type(pdt);
135 pdt =
136 idl_global->gen ()->create_predefined_type (
137 AST_PredefinedType::PT_ulonglong,
138 nullptr);
140 m->fe_add_predefined_type (pdt);
142 pdt =
143 idl_global->gen ()->create_predefined_type (
144 AST_PredefinedType::PT_short,
145 nullptr);
147 m->fe_add_predefined_type (pdt);
149 pdt =
150 idl_global->gen ()->create_predefined_type (
151 AST_PredefinedType::PT_ushort,
152 nullptr);
154 m->fe_add_predefined_type (pdt);
156 pdt =
157 idl_global->gen ()->create_predefined_type (
158 AST_PredefinedType::PT_float,
159 nullptr);
161 m->fe_add_predefined_type (pdt);
163 pdt =
164 idl_global->gen ()->create_predefined_type (
165 AST_PredefinedType::PT_double,
166 nullptr);
168 m->fe_add_predefined_type (pdt);
170 pdt =
171 idl_global->gen ()->create_predefined_type (
172 AST_PredefinedType::PT_longdouble,
173 nullptr);
175 m->fe_add_predefined_type (pdt);
177 pdt =
178 idl_global->gen ()->create_predefined_type (
179 AST_PredefinedType::PT_char,
180 nullptr);
182 m->fe_add_predefined_type (pdt);
184 pdt =
185 idl_global->gen ()->create_predefined_type (
186 AST_PredefinedType::PT_wchar,
187 nullptr);
189 m->fe_add_predefined_type (pdt);
191 pdt =
192 idl_global->gen ()->create_predefined_type (
193 AST_PredefinedType::PT_octet,
194 nullptr);
196 m->fe_add_predefined_type (pdt);
198 pdt =
199 idl_global->gen ()->create_predefined_type (
200 AST_PredefinedType::PT_any,
201 nullptr);
203 m->fe_add_predefined_type (pdt);
205 pdt =
206 idl_global->gen ()->create_predefined_type (
207 AST_PredefinedType::PT_boolean,
208 nullptr);
210 m->fe_add_predefined_type (pdt);
212 m->fe_add_predefined_type (idl_global->gen ()->create_predefined_type (
213 AST_PredefinedType::PT_uint8, nullptr));
215 m->fe_add_predefined_type (idl_global->gen ()->create_predefined_type (
216 AST_PredefinedType::PT_int8, nullptr));
218 Identifier Object_id ("Object");
219 UTL_ScopedName Object_name (&Object_id, nullptr);
221 pdt =
222 idl_global->gen ()->create_predefined_type (
223 AST_PredefinedType::PT_object,
224 &Object_name);
226 m->fe_add_predefined_type (pdt);
228 // Add these to make all keywords protected even in different spellings
230 Identifier ValueBase_id ("ValueBase");
231 UTL_ScopedName ValueBase_name (&ValueBase_id, nullptr);
233 pdt =
234 idl_global->gen ()->create_predefined_type (
235 AST_PredefinedType::PT_value,
236 &ValueBase_name);
238 m->fe_add_predefined_type (pdt);
240 Identifier AbstractBase_id ("AbstractBase");
241 UTL_ScopedName AbstractBase_name (&AbstractBase_id, nullptr);
243 pdt =
244 idl_global->gen ()->create_predefined_type (
245 AST_PredefinedType::PT_abstract,
246 &AbstractBase_name);
248 m->fe_add_predefined_type (pdt);
250 Identifier TypeCode_id ("TypeCode");
251 UTL_ScopedName TypeCode_name (&TypeCode_id, nullptr);
253 pdt =
254 idl_global->gen ()->create_predefined_type (
255 AST_PredefinedType::PT_pseudo,
256 &TypeCode_name);
258 m->fe_add_predefined_type (pdt);
260 char *trash = nullptr;
261 idl_global->pragma_prefixes ().pop (trash);
262 ACE::strdelete (trash);
265 // Populate idl_global's hash map with upper case versions of
266 // all the IDL keywords
267 void
268 fe_populate_idl_keywords ()
270 static const char *keywords[] =
272 "ABSTRACT",
273 "ALIAS",
274 "ANY",
275 "ATTRIBUTE",
276 "BOOLEAN",
277 "CASE",
278 "CHAR",
279 "COMPONENT",
280 "CONNECTOR",
281 "CONST",
282 "CONSUMES",
283 "CONTEXT",
284 "CUSTOM",
285 "DEFAULT",
286 "DOUBLE",
287 "EMITS",
288 "EXCEPTION",
289 "ENUM",
290 "EVENTTYPE",
291 "FACTORY",
292 "FALSE",
293 "FINDER",
294 "FIXED",
295 "FLOAT",
296 "GETRAISES",
297 "HOME",
298 "IMPORT",
299 "IN",
300 "INOUT",
301 "INTERFACE",
302 "LOCAL",
303 "LONG",
304 "MIRRORPORT",
305 "MODULE",
306 "MULTIPLE",
307 "NATIVE",
308 "OBJECT",
309 "OCTET",
310 "ONEWAY",
311 "OUT",
312 "PORT",
313 "PORTTYPE",
314 "PRIMARYKEY",
315 "PRIVATE",
316 "PROVIDES",
317 "PUBLIC",
318 "PUBLISHES",
319 "RAISES",
320 "READONLY",
321 "SEQUENCE",
322 "SETRAISES",
323 "SHORT",
324 "STRING",
325 "STRUCT",
326 "SUPPORTS",
327 "SWITCH",
328 "TRUE",
329 "TRUNCATABLE",
330 "TYPEDEF",
331 "TYPEID",
332 "TYPEPREFIX",
333 "UNION",
334 "UNSIGNED",
335 "USES",
336 "VALUEBASE",
337 "VALUETYPE",
338 "VOID",
339 "WCHAR",
340 "WSTRING"
343 ACE_Hash_Map_Manager<ACE_CString, int, ACE_Null_Mutex> &map =
344 idl_global->idl_keywords ();
346 u_long length = sizeof (keywords) / sizeof (char *);
347 ACE_CString ext_id;
348 int int_id = 0;
350 for (u_long i = 0; i < length; ++i)
352 ext_id.set (keywords[i],
353 false);
354 (void) map.bind (ext_id,
355 int_id);
359 // FE initialization
360 void
361 FE_init ()
363 // Initialize FE global data object.
364 ACE_NEW (idl_global,
365 IDL_GlobalData);
367 // Initialize some of its data.
368 idl_global->set_root (nullptr);
369 idl_global->set_gen (nullptr);
370 idl_global->set_err (FE_new_UTL_Error ());
371 idl_global->set_err_count (0);
372 idl_global->set_indent (FE_new_UTL_Indenter ());
373 idl_global->set_filename (nullptr);
374 idl_global->set_main_filename (nullptr);
375 idl_global->set_real_filename (nullptr);
376 idl_global->set_stripped_filename (nullptr);
377 idl_global->set_import (true);
378 idl_global->set_in_main_file (false);
379 idl_global->set_lineno (-1);
380 idl_global->set_prog_name (nullptr);
382 char local_escapes[LOCAL_ESCAPES_BUFFER_SIZE];
383 ACE_OS::memset (&local_escapes,
385 LOCAL_ESCAPES_BUFFER_SIZE);
387 idl_global->set_local_escapes (local_escapes);
388 idl_global->set_compile_flags (0);
389 idl_global->set_include_file_names (nullptr);
390 idl_global->set_n_include_file_names (0);
391 idl_global->set_parse_state (IDL_GlobalData::PS_NoState);
392 idl_global->preserve_cpp_keywords (false);
394 // Put an empty prefix on the stack for the global scope.
395 idl_global->pragma_prefixes ().push (ACE::strnew (""));
398 void
399 FE_populate ()
401 AST_Root *r = nullptr;
403 // Check that the BE init created a generator object
404 if (idl_global->gen () == nullptr)
406 ACE_ERROR ((
407 LM_ERROR,
408 ACE_TEXT ("IDL: idl_global->gen() not initialized, exiting\n")
411 throw Bailout ();
414 // Create a global root for the AST. Note that the AST root has no name.
415 Identifier root_id ("");
416 UTL_ScopedName root_name (&root_id, nullptr);
417 r = idl_global->gen ()->create_root (&root_name);
418 idl_global->set_root (r);
420 if (r == nullptr)
422 ACE_ERROR ((
423 LM_ERROR,
424 ACE_TEXT ("IDL: FE init failed to create AST root, exiting\n")
427 throw Bailout ();
430 // Push it on the stack
431 idl_global->scopes ().push (idl_global->root ());
433 // Populate it with nodes for predefined types.
434 fe_populate_global_scope ();
436 // Set flag to indicate we are processing the main file now.
437 idl_global->set_in_main_file (true);
439 // Populate the IDL keyword container, for checking local identifiers.
440 fe_populate_idl_keywords ();
443 void
444 FE_extract_env_include_paths (ACE_Unbounded_Queue<ACE_CString> &list)
446 ACE_Env_Value<char*> incl_paths (ACE_TEXT ("INCLUDE"),
447 (char *) nullptr);
448 const char *aggr_str = incl_paths;
450 if (aggr_str != nullptr)
452 char separator;
453 #if defined (ACE_WIN32)
454 separator = ';';
455 #else
456 separator = ':';
457 #endif
458 ACE_CString aggr_cstr (aggr_str);
459 ACE_CString::size_type pos;
463 pos = aggr_cstr.find (separator);
464 list.enqueue_tail (aggr_cstr.substr (0, pos));
465 aggr_cstr = aggr_cstr.substr (pos + 1);
466 } while (pos != ACE_CString::npos);
470 // Store include paths from the environment variable, if any.
471 void
472 FE_store_env_include_paths ()
474 ACE_Unbounded_Queue<ACE_CString> list;
475 FE_extract_env_include_paths (list);
477 ACE_CString *path_tmp = nullptr;
478 for (ACE_Unbounded_Queue_Iterator<ACE_CString>iter (list);
479 !iter.done (); iter.advance ())
481 if (iter.next (path_tmp) != 0)
483 idl_global->add_include_path (path_tmp->fast_rep (), false);
488 const char *
489 FE_get_cpp_loc_from_env ()
491 const char *cpp_loc = nullptr;
493 // See if TAO_IDL_PREPROCESSOR is defined.
494 ACE_Env_Value<char*> preprocessor (ACE_TEXT ("TAO_IDL_PREPROCESSOR"),
495 (char *) nullptr);
497 // Set cpp_loc to the built in location, unless it has been overriden by
498 // environment variables.
499 if (preprocessor != 0)
501 cpp_loc = preprocessor;
503 else
505 // Check for the deprecated CPP_LOCATION environment variable
506 ACE_Env_Value<char*> cpp_path (ACE_TEXT ("CPP_LOCATION"),
507 (char *) nullptr);
509 if (cpp_path != 0)
511 ACE_ERROR ((LM_WARNING,
512 "WARNING: The environment variable "
513 "CPP_LOCATION has been deprecated.\n"
514 " Please use TAO_IDL_PREPROCESSOR "
515 "instead.\n"));
517 cpp_loc = cpp_path;
519 else
521 cpp_loc = idl_global->cpp_location ();
525 return cpp_loc;
528 const char *
529 FE_get_cpp_args_from_env ()
531 const char *cpp_args = nullptr;
533 // Added some customizable preprocessor options
534 ACE_Env_Value<char*> args1 (ACE_TEXT ("TAO_IDL_PREPROCESSOR_ARGS"),
535 (char *) nullptr);
537 if (args1 != 0)
539 cpp_args = args1;
541 else
543 // Check for the deprecated TAO_IDL_DEFAULT_CPP_FLAGS environment
544 // variable.
545 ACE_Env_Value<char*> args2 (ACE_TEXT ("TAO_IDL_DEFAULT_CPP_FLAGS"),
546 (char *) nullptr);
548 if (args2 != 0)
550 ACE_ERROR ((LM_WARNING,
551 "Warning: The environment variable "
552 "TAO_IDL_DEFAULT_CPP_FLAGS has been "
553 "deprecated.\n"
554 " Please use "
555 "TAO_IDL_PREPROCESSOR_ARGS instead.\n"));
557 cpp_args = args2;
561 return cpp_args;