Merge pull request #1551 from DOCGroup/plm_jira_333
[ACE_TAO.git] / TAO / TAO_IDL / fe / fe_init.cpp
blob65425c5402a65521647ed9ee678fa2ecaa00ecb0
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 created 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 Identifier Object_id ("Object");
214 UTL_ScopedName Object_name (&Object_id, 0);
216 pdt =
217 idl_global->gen ()->create_predefined_type (
218 AST_PredefinedType::PT_object,
219 &Object_name);
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);
228 pdt =
229 idl_global->gen ()->create_predefined_type (
230 AST_PredefinedType::PT_value,
231 &ValueBase_name);
233 m->fe_add_predefined_type (pdt);
235 Identifier AbstractBase_id ("AbstractBase");
236 UTL_ScopedName AbstractBase_name (&AbstractBase_id, 0);
238 pdt =
239 idl_global->gen ()->create_predefined_type (
240 AST_PredefinedType::PT_abstract,
241 &AbstractBase_name);
243 m->fe_add_predefined_type (pdt);
245 Identifier TypeCode_id ("TypeCode");
246 UTL_ScopedName TypeCode_name (&TypeCode_id, 0);
248 pdt =
249 idl_global->gen ()->create_predefined_type (
250 AST_PredefinedType::PT_pseudo,
251 &TypeCode_name);
253 m->fe_add_predefined_type (pdt);
255 char *trash = 0;
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
262 void
263 fe_populate_idl_keywords (void)
265 static const char *keywords[] =
267 "ABSTRACT",
268 "ALIAS",
269 "ANY",
270 "ATTRIBUTE",
271 "BOOLEAN",
272 "CASE",
273 "CHAR",
274 "COMPONENT",
275 "CONNECTOR",
276 "CONST",
277 "CONSUMES",
278 "CONTEXT",
279 "CUSTOM",
280 "DEFAULT",
281 "DOUBLE",
282 "EMITS",
283 "EXCEPTION",
284 "ENUM",
285 "EVENTTYPE",
286 "FACTORY",
287 "FALSE",
288 "FINDER",
289 "FIXED",
290 "FLOAT",
291 "GETRAISES",
292 "HOME",
293 "IMPORT",
294 "IN",
295 "INOUT",
296 "INTERFACE",
297 "LOCAL",
298 "LONG",
299 "MIRRORPORT",
300 "MODULE",
301 "MULTIPLE",
302 "NATIVE",
303 "OBJECT",
304 "OCTET",
305 "ONEWAY",
306 "OUT",
307 "PORT",
308 "PORTTYPE",
309 "PRIMARYKEY",
310 "PRIVATE",
311 "PROVIDES",
312 "PUBLIC",
313 "PUBLISHES",
314 "RAISES",
315 "READONLY",
316 "SEQUENCE",
317 "SETRAISES",
318 "SHORT",
319 "STRING",
320 "STRUCT",
321 "SUPPORTS",
322 "SWITCH",
323 "TRUE",
324 "TRUNCATABLE",
325 "TYPEDEF",
326 "TYPEID",
327 "TYPEPREFIX",
328 "UNION",
329 "UNSIGNED",
330 "USES",
331 "VALUEBASE",
332 "VALUETYPE",
333 "VOID",
334 "WCHAR",
335 "WSTRING"
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 *);
342 ACE_CString ext_id;
343 int int_id = 0;
345 for (u_long i = 0; i < length; ++i)
347 ext_id.set (keywords[i],
348 false);
349 (void) map.bind (ext_id,
350 int_id);
354 // FE initialization
355 void
356 FE_init (void)
358 // Initialize FE global data object.
359 ACE_NEW (idl_global,
360 IDL_GlobalData);
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 (""));
393 void
394 FE_populate (void)
396 AST_Root *r = 0;
398 // Check that the BE init created a generator object
399 if (idl_global->gen () == 0)
401 ACE_ERROR ((
402 LM_ERROR,
403 ACE_TEXT ("IDL: idl_global->gen() not initialized, exiting\n")
406 throw Bailout ();
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);
415 if (r == 0)
417 ACE_ERROR ((
418 LM_ERROR,
419 ACE_TEXT ("IDL: FE init failed to create AST root, exiting\n")
422 throw Bailout ();
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 ();
438 void
439 FE_extract_env_include_paths (ACE_Unbounded_Queue<ACE_CString> &list)
441 ACE_Env_Value<char*> incl_paths (ACE_TEXT ("INCLUDE"),
442 (char *) 0);
443 const char *aggr_str = incl_paths;
445 if (aggr_str != 0)
447 char separator;
448 #if defined (ACE_WIN32)
449 separator = ';';
450 #else
451 separator = ':';
452 #endif
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.
466 void
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);
483 const char *
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"),
490 (char *) 0);
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;
498 else
500 // Check for the deprecated CPP_LOCATION environment variable
501 ACE_Env_Value<char*> cpp_path (ACE_TEXT ("CPP_LOCATION"),
502 (char *) 0);
504 if (cpp_path != 0)
506 ACE_ERROR ((LM_WARNING,
507 "WARNING: The environment variable "
508 "CPP_LOCATION has been deprecated.\n"
509 " Please use TAO_IDL_PREPROCESSOR "
510 "instead.\n"));
512 cpp_loc = cpp_path;
514 else
516 cpp_loc = idl_global->cpp_location ();
520 return cpp_loc;
523 const char *
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"),
530 (char *) 0);
532 if (args1 != 0)
534 cpp_args = args1;
536 else
538 // Check for the deprecated TAO_IDL_DEFAULT_CPP_FLAGS environment
539 // variable.
540 ACE_Env_Value<char*> args2 (ACE_TEXT ("TAO_IDL_DEFAULT_CPP_FLAGS"),
541 (char *) 0);
543 if (args2 != 0)
545 ACE_ERROR ((LM_WARNING,
546 "Warning: The environment variable "
547 "TAO_IDL_DEFAULT_CPP_FLAGS has been "
548 "deprecated.\n"
549 " Please use "
550 "TAO_IDL_PREPROCESSOR_ARGS instead.\n"));
552 cpp_args = args2;
556 return cpp_args;