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 "be_extern.h"
68 #include "idl_defines.h"
69 #include "global_extern.h"
71 #include "fe_extern.h"
74 #include "ast_extern.h"
76 #include "utl_string.h"
77 #include "utl_identifier.h"
79 #include "drv_extern.h"
81 #include "tao/Version.h"
82 #include "ace/Argv_Type_Converter.h"
83 #include "ace/OS_NS_stdio.h"
84 #include "ace/OS_NS_unistd.h"
86 #if !defined (ACE_LACKS_IOSTREAM_TOTALLY)
87 // FUZZ: disable check_for_streams_include
88 # include "ace/streams.h"
89 #endif /* ! ACE_LACKS_IOSTREAM_TOTALLY */
91 extern const ACE_TCHAR
*DRV_arglist
[];
92 extern unsigned long DRV_argcount
;
94 char *DRV_files
[NFILES
];
96 long DRV_file_index
= -1;
101 ACE_DEBUG ((LM_DEBUG
,
103 "TAO_IDL_FE, version %s (Based on Sun IDL FE, version %s)\n",
104 idl_global
->prog_name (),
105 ACE_TEXT (TAO_VERSION
),
106 ACE_TEXT (SUN_IDL_FE_VERSION
)));
112 DRV_init (int &argc
, ACE_TCHAR
*argv
[])
114 // Initialize front end.
117 // Initialize driver private data. DRV_nfiles will be updated
118 // by DRV_parse_args().
122 #if defined (TAO_IDL_PREPROCESSOR)
123 idl_global
->set_cpp_location (TAO_IDL_PREPROCESSOR
);
124 #elif defined (ACE_CC_PREPROCESSOR)
125 idl_global
->set_cpp_location (ACE_CC_PREPROCESSOR
);
127 // Just default to cc
128 idl_global
->set_cpp_location ("cc");
129 #endif /* TAO_IDL_PREPROCESSOR */
131 // Does nothing for IDL compiler, stores -ORB args, initializes
132 // ORB and IFR for IFR loader.
133 return BE_init (argc
, argv
);
139 idl_global
->set_err_count (0);
140 idl_global
->set_filename (0);
141 idl_global
->set_main_filename (0);
142 idl_global
->set_real_filename (0);
143 idl_global
->set_stripped_filename (0);
144 idl_global
->set_lineno (-1);
145 idl_global
->reset_flag_seen ();
151 // In case we got here via an init error or
152 // usage/version option - otherwise it's idempotent.
155 be_global
->destroy ();
163 for (DRV_file_index
= 0;
164 DRV_file_index
< DRV_nfiles
;
167 ACE::strdelete (DRV_files
[DRV_file_index
]);
170 for (unsigned long i
= 0; i
< DRV_argcount
; ++i
)
172 ACE::strdelete (const_cast<ACE_TCHAR
*> (DRV_arglist
[i
]));
177 ** Drive the compilation
181 ** 2. Initialize the BE. This builds an instance of the generator
182 ** 3. Initialize the FE. This builds the global scope
183 ** and populates it with the predefined types
184 ** 4. Invoke FE_yyparse
185 ** 5. Check for errors from FE_yyparse. If any, exit now
186 ** 6. Check for undefined forward declared interfaces. If any, exit now
187 ** 7. Check if asked to dump AST. If so, do.
192 DRV_drive (const char *s
)
194 // Set the name of the IDL file we are parsing. This is useful to
195 // the backend when it generates C++ headers and files.
196 UTL_String
*utl_string
= 0;
198 UTL_String (s
, true));
200 idl_global
->idl_src_file (utl_string
);
203 if (idl_global
->compile_flags () & IDL_CF_INFORMATIVE
)
205 ACE_DEBUG ((LM_DEBUG
,
206 ACE_TEXT("%C: preprocessing %C\n"),
207 idl_global
->prog_name (),
213 if (idl_global
->compile_flags () & IDL_CF_ONLY_PREPROC
)
215 // Go straight to cleanup, process the next file, if any.
221 if (idl_global
->compile_flags () & IDL_CF_INFORMATIVE
)
223 ACE_DEBUG ((LM_DEBUG
,
224 ACE_TEXT("%C: parsing %C\n"),
225 idl_global
->prog_name (),
229 // Return value not used - error count stored in idl_global
230 // and checked below.
231 (void) FE_yyparse ();
233 // This option creates a single IDL file that includes all
234 // input files. The backend outputs their names individually.
235 if (!idl_global
->multi_file_input () &&
236 (idl_global
->compile_flags () & IDL_CF_INFORMATIVE
))
238 // Filename set by FE_yyparse(), so we output it immediately after.
239 ACE_DEBUG ((LM_DEBUG
,
240 ACE_TEXT("processing %C\n"),
241 idl_global
->filename ()->get_string ()));
244 // We must do this as late as possible to make sure any
245 // forward declared structs or unions contained in a
246 // primary key at some level have been fully defined.
247 idl_global
->check_primary_keys ();
249 // If there were any errors, stop.
250 if (idl_global
->err_count () > 0)
252 ACE_ERROR ((LM_ERROR
,
253 ACE_TEXT("%C: %C: found %d error%s\n"),
254 idl_global
->prog_name (),
256 idl_global
->err_count (),
257 (idl_global
->err_count () > 1
261 // Backend will be cleaned up after the exception is caught.
266 if ((idl_global
->compile_flags () & IDL_CF_INFORMATIVE
)
267 && (idl_global
->compile_flags () & IDL_CF_DUMP_AST
))
269 ACE_DEBUG ((LM_DEBUG
,
270 ACE_TEXT("%C: dump %C\n"),
271 idl_global
->prog_name (),
275 if (idl_global
->compile_flags () & IDL_CF_DUMP_AST
)
277 ACE_DEBUG ((LM_DEBUG
,
278 ACE_TEXT ("Dump of AST:\n")));
280 idl_global
->root ()->dump (*ACE_DEFAULT_LOG_STREAM
);
283 if (idl_global
->syntax_only_
)
285 // Set error count for syntax errors
286 throw Bailout (idl_global
->err_count ());
289 // Call the main entry point for the BE.
290 if (idl_global
->compile_flags () & IDL_CF_INFORMATIVE
)
292 ACE_DEBUG ((LM_DEBUG
,
293 ACE_TEXT("%C: BE processing on %C\n"),
294 idl_global
->prog_name (),
298 // Make sure all forward declared structs and unions are defined
299 // before proceeding to code generation.
300 AST_check_fwd_decls ();
302 if (0 == idl_global
->err_count ())
317 ** 1. Initialize compiler driver
318 ** 2. Parse command line args
319 ** 3. Invoke DRV_drive iteratively on each file passed in
323 ACE_TMAIN (int argc
, ACE_TCHAR
*argv
[])
325 ACE_Argv_Type_Converter
atc (argc
, argv
);
328 if (0 != DRV_init (atc
.get_argc (), atc
.get_TCHAR_argv ()))
333 // Give BE chance to set default IDL version using BE_init
334 idl_global
->idl_version_
= idl_global
->default_idl_version_
;
337 DRV_parse_args (atc
.get_argc (), atc
.get_ASCII_argv ());
339 // Print Help Message
340 if (idl_global
->print_help_
)
345 // If a version message is requested, print it
346 if (idl_global
->print_version_
)
351 // If exiting because of arguments, do it now
352 if (idl_global
->parse_args_exit_
)
354 int status
= idl_global
->parse_args_exit_status_
;
357 ACE_ERROR ((LM_ERROR
,
358 ACE_TEXT ("Use \"-h\" or \"--help\" to see valid options.\n")));
360 throw Bailout (status
);
363 AST_Generator
*gen
= be_util::generator_init ();
369 ACE_TEXT ("IDL: DRV_generator_init() failed to create ")
370 ACE_TEXT ("generator, exiting\n")
377 idl_global
->set_gen (gen
);
380 // Initialize AST and load predefined types.
383 // Does various things in various backends.
384 BE_post_init (DRV_files
, DRV_nfiles
);
386 // Dump Builtin IDL AST
387 if (idl_global
->just_dump_builtins_
)
389 ACE_DEBUG ((LM_DEBUG
,
390 ACE_TEXT ("Dump Builtin IDL defined by Compiler:\n")));
391 idl_global
->root ()->dump (*ACE_DEFAULT_LOG_STREAM
);
392 idl_global
->ignore_files_
= true;
395 if (idl_global
->ignore_files_
)
397 throw Bailout (idl_global
->err_count ());
400 // If there are no input files, and we are not using the
401 // directory recursion option, there's no sense going any further.
402 if (0 == DRV_nfiles
&& 0 == idl_global
->recursion_start ())
404 ACE_ERROR ((LM_ERROR
,
405 ACE_TEXT ("IDL: No input files\n")));
410 FILE *output_file
= 0;
412 if (idl_global
->multi_file_input ())
415 ACE_OS::fopen (idl_global
->big_file_name (), "w");
418 for (DRV_file_index
= 0;
419 DRV_file_index
< DRV_nfiles
;
422 if (idl_global
->multi_file_input ())
424 ACE_OS::fprintf (output_file
,
426 DRV_files
[DRV_file_index
]);
430 DRV_drive (DRV_files
[DRV_file_index
]);
434 if (idl_global
->multi_file_input ())
436 ACE_OS::fclose (output_file
);
437 DRV_drive (idl_global
->big_file_name ());
438 ACE_OS::unlink (idl_global
->big_file_name ());
441 catch (const Bailout
&bailout
)
443 if (bailout
.increment_errors_
)
445 // Incrementing here may be redundant, but the error count
446 // is the exit value, and we want to make sure it isn't 0
447 // if there was in fact an error. If a non-zero value is
448 // off by 1, it's not so important.
449 idl_global
->set_err_count (idl_global
->err_count () + 1);
453 idl_global
->set_err_count (bailout
.errors_
);
457 int const retval
= idl_global
->err_count ();