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 // drv_args.cpp - Argument parsing for IDL compiler main driver
69 #include "idl_defines.h"
70 #include "global_extern.h"
71 #include "drv_extern.h"
72 #include "fe_extern.h"
74 #include "be_global.h"
75 #include "be_extern.h"
78 #include "ace/OS_NS_stdio.h"
79 #include "ace/OS_NS_stdlib.h"
80 #include "ace/OS_NS_unistd.h"
81 #include "ace/os_include/os_ctype.h"
82 #include "ace/Lib_Find.h"
84 extern long DRV_nfiles
;
85 extern char *DRV_files
[];
87 void process_long_option(long ac
, char **av
, long &i
);
89 // Push a file into the list of files to be processed
91 DRV_push_file (const char *s
)
93 // If filenames come from the command line, there is no
94 // need to duplicate the string, but some backends have
95 // an option to recurse over a directory and add all
96 // IDL files found. In this latter case we have to
97 // duplicate the file name string.
98 DRV_files
[DRV_nfiles
++] = ACE::strnew (s
);
101 // Prepare a CPP argument
103 DRV_prep_cpp_arg (char *s
)
105 std::string
instr (s
);
107 newarg
.reserve (512);
109 for (std::string::size_type pos
= instr
.find_first_of (',');
110 pos
!= std::string::npos
;
111 instr
= instr
.substr (pos
+ 1), pos
= instr
.find_first_of (','))
113 newarg
.append (instr
.substr (0, pos
));
116 DRV_cpp_putarg (newarg
.c_str ());
119 // Print a usage message and exit.
123 ACE_DEBUG ((LM_DEBUG
,
124 ACE_TEXT ("%C: usage: %C [[flag|file] ...] [-- file ...]\n"),
125 idl_global
->prog_name (),
126 idl_global
->prog_name ()));
128 ACE_DEBUG ((LM_DEBUG
,
129 ACE_TEXT ("Legal flags:\n")
130 ACE_TEXT (" -h | --help | -u\tPrint this list and exit successfully\n")
131 ACE_TEXT (" -A...\t\t\tlocal implementation-specific escape\n")
132 ACE_TEXT (" -Cw\t\t\tWarning if identifier spellings differ ")
133 ACE_TEXT ("only in case (default is error)\n")
134 ACE_TEXT (" -Ce\t\t\tError if identifier spellings differ ")
135 ACE_TEXT ("only in case (default)\n")
136 ACE_TEXT (" -ae\t\t\tError if anonymous type is seen ")
137 ACE_TEXT ("(default)\n")
138 ACE_TEXT (" -aw\t\t\tWarning if anonymous type is seen ")
139 ACE_TEXT ("(default is error)\n")
140 ACE_TEXT (" -as\t\t\tSilences the anonymous type diagnostic ")
141 ACE_TEXT ("(default is error)\n")
142 ACE_TEXT (" -d | --dump\t\tPrints a dump of the AST and exits\n")
143 ACE_TEXT (" -Dname[=value]\t\tdefines name for preprocessor\n")
144 ACE_TEXT (" -E\t\t\truns preprocessor only, prints on stdout\n")
145 ACE_TEXT (" -Idir\t\t\tincludes dir in search path for preprocessor\n")
146 ACE_TEXT (" -t\t\t\tTemporary directory to be used")
147 ACE_TEXT (" by the IDL compiler.\n")
148 ACE_TEXT (" -Uname\t\t\tundefines name for preprocessor\n")
149 ACE_TEXT (" -v\t\t\ttraces compilation stages\n")
150 ACE_TEXT (" -V | --version\t\tprints version info then exits\n")
151 ACE_TEXT (" -w\t\t\tsuppresses IDL compiler warning messages\n")
152 ACE_TEXT (" -Wp,<arg1,...,argn>\tpasses args to preprocessor\n")
153 ACE_TEXT (" -Yp,path\t\tdefines location of preprocessor\n")
154 ACE_TEXT (" --idl-version VERSION\tSet the version of IDL to use\n")
155 ACE_TEXT (" --default-idl-version\tPrint the default IDL version and exit\n")
156 ACE_TEXT (" --list-idl-versions\tPrint IDL versions supported and exit\n")
157 ACE_TEXT (" --syntax-only\t\tJust check the syntax, do not create files\n")
158 ACE_TEXT (" --bison-trace\t\tEnable Bison Tracing (sets yydebug to 1)\n")
159 ACE_TEXT (" --dump-builtins\tDump the compiler and user defined IDL.\n")
160 ACE_TEXT (" --just-dump-builtins\tJust dump the compiler defined IDL and exit.\n")
161 ACE_TEXT (" --unknown-annotations ARG\t")
162 ACE_TEXT ("Set reaction to unknown annotations. ARG must be one of the following:\n")
163 ACE_TEXT ("\t\t\t\twarn-once\tThe default, warn once per unique local name\n")
164 ACE_TEXT ("\t\t\t\twarn-all\tWarn for all unknown annotations\n")
165 ACE_TEXT ("\t\t\t\terror\t\tCauses the process to exit with a failed return status\n")
166 ACE_TEXT ("\t\t\t\tignore\t\tDon't report unknown annotations\n")
172 #define UNKNOWN_OPTION \
175 ACE_TEXT ("IDL: I don't understand") \
176 ACE_TEXT (" the '%s' option\n"), \
177 ACE_TEXT_CHAR_TO_TCHAR (av[i]) \
179 idl_global->parse_args_exit (1); \
182 // Parse arguments on command line
184 DRV_parse_args (long ac
, char **av
)
190 // After -- process all arguments as files
191 bool just_files
= false;
193 FE_store_env_include_paths ();
195 idl_global
->set_prog_name (av
[0]);
197 for (i
= 1; i
< ac
; i
++)
199 if (!just_files
&& av
[i
][0] == '-')
201 idl_global
->append_idl_flag (av
[i
]);
206 // One or more letters expected after the dash.
209 ACE_TEXT ("IDL: Space between dash and option ")
210 ACE_TEXT ("letters not allowed\n")
212 idl_global
->parse_args_exit (1);
216 if (av
[i
][2] == '\0')
227 ACE_TEXT ("IDL: incorrect use of ")
228 ACE_TEXT ("the -A option\n")
230 idl_global
->parse_args_exit (1);
239 ACE_OS::strcat (idl_global
->local_escapes (), s
);
240 ACE_OS::strcat (idl_global
->local_escapes (), " ");
245 idl_global
->anon_type_diagnostic (
246 IDL_GlobalData::ANON_TYPE_ERROR
);
248 else if (av
[i
][2] == 'w')
250 idl_global
->anon_type_diagnostic (
251 IDL_GlobalData::ANON_TYPE_WARNING
);
253 else if (av
[i
][2] == 's')
255 idl_global
->anon_type_diagnostic (
256 IDL_GlobalData::ANON_TYPE_SILENT
);
264 // Temp directory for the IDL compiler to keep its files.
266 if ((av
[i
][2] == '\0') && (i
< ac
- 1))
268 idl_global
->append_idl_flag (av
[i
+ 1]);
269 idl_global
->temp_dir (av
[i
+ 1]);
281 if (av
[i
][2] == '\0')
285 idl_global
->append_idl_flag (av
[i
+ 1]);
287 ACE_CString arg
= av
[i
];
290 DRV_cpp_putarg (arg
.c_str ());
291 idl_global
->add_include_path (arg
.substr (2).c_str (), false);
301 ACE_CString
arg (av
[i
], 2);
304 idl_global
->add_include_path (arg
.substr (2).c_str (), false);
305 DRV_cpp_putarg (arg
.c_str ());
310 if (av
[i
][2] != '\0')
314 idl_global
->set_compile_flags (idl_global
->compile_flags () |
315 IDL_CF_ONLY_PREPROC
);
318 if (av
[i
][2] != '\0')
322 idl_global
->print_version ();
325 if (av
[i
][2] == '\0')
347 ACE_TEXT ("IDL: Incorrect use of -W option\n")
349 idl_global
->parse_args_exit (1);
355 DRV_prep_cpp_arg (s
+ 2);
362 be_util::prep_be_arg (s
+ 2);
370 if (av
[i
][2] == '\0')
392 idl_global
->set_cpp_location (s
+ 2);
393 DRV_cpp_new_location (s
+ 2);
399 ACE_TEXT ("IDL: I don't understand")
400 ACE_TEXT (" the '-Y' option\n")
402 idl_global
->parse_args_exit (1);
410 ACE_TEXT ("IDL: I dont' understand the use of")
411 ACE_TEXT (" %s with the '-Y' option\n"),
412 ACE_TEXT_CHAR_TO_TCHAR (s
)
414 idl_global
->parse_args_exit (1);
419 if (av
[i
][2] != '\0')
423 idl_global
->dump_ast ();
426 if (av
[i
][2] != '\0')
430 idl_global
->set_compile_flags (idl_global
->compile_flags ()
431 | IDL_CF_INFORMATIVE
);
434 if (av
[i
][2] != '\0')
438 idl_global
->set_compile_flags (idl_global
->compile_flags ()
439 | IDL_CF_NOWARNINGS
);
442 // If identifiers in the same scope differ only by case...
445 // ...report an error.
446 idl_global
->case_diff_error (true);
448 else if (av
[i
][2] == 'w')
450 // ...report a warning (default for now)
451 idl_global
->case_diff_error (false);
460 case 'u': // Old Help Option
461 if (av
[i
][2] != '\0')
465 idl_global
->print_help ();
468 case 'h': // Short Help Option, else let be_global process it
469 if (av
[i
][2] == '\0') {
470 idl_global
->print_help ();
472 be_global
->parse_args (i
, av
);
476 case '-': // -- or Long Options
477 if (av
[i
][2] == '\0')
479 just_files
= true; // Treat the following arguments as files
483 process_long_option(ac
, av
, i
);
488 be_global
->parse_args (i
, av
);
489 } // End of switch (av[i][1])
490 } // End of IF (av[i][0] == '-')
493 DRV_push_file (av
[i
]);
496 if (idl_global
->parse_args_exit_
) return; // Catch Exits
497 } // End of FOR (i = 1; i < ac; i++)
499 be_util::arg_post_proc ();
501 // Make sure the output directory is valid.
502 if (idl_global
->temp_dir () == nullptr)
504 ACE_TCHAR tmpdir
[MAXPATHLEN
+ 1];
506 if (ACE::get_temp_dir (tmpdir
, MAXPATHLEN
) == -1)
508 ACE_ERROR ((LM_ERROR
,
509 ACE_TEXT ("Temporary path too long, ")
510 ACE_TEXT ("defaulting to current directory\n")));
512 ACE_OS::strcpy (tmpdir
, ACE_TEXT ("."));
516 if (ACE_OS::access (tmpdir
, F_OK
) == -1
517 || ACE_OS::access (tmpdir
, R_OK
) == -1
518 || ACE_OS::access (tmpdir
, W_OK
) == -1)
520 if (ACE_OS::access (tmpdir
, F_OK
| R_OK
| W_OK
) == -1)
525 ACE_TEXT ("Can't access temporary directory (%s),")
526 ACE_TEXT (" using current directory for temp files.\n"),
530 ACE_OS::strcpy (tmpdir
, ACE_TEXT ("."));
532 if (ACE_OS::access (tmpdir
, F_OK
) == -1
533 || ACE_OS::access (tmpdir
, R_OK
) == -1
534 || ACE_OS::access (tmpdir
, W_OK
) == -1)
536 if (ACE_OS::access (tmpdir
, F_OK
| R_OK
| W_OK
) == -1)
539 ACE_ERROR ((LM_ERROR
,
540 "Error: Can't access temporary directory %s\n",
547 idl_global
->temp_dir (ACE_TEXT_ALWAYS_CHAR (tmpdir
));
550 DRV_cpp_post_init ();
557 ACE_TEXT ("These are the valid IDL versions this compiler will accept:\n")
559 for (int v
= 1; v
< IDL_VERSION_COUNT
; v
++)
561 ACE_DEBUG ((LM_INFO
, ACE_TEXT ("%C\n"),
562 IdlVersion (static_cast<SpecificIdlVersion
>(v
)).to_string ()
568 process_long_option(long ac
, char **av
, long &i
)
570 const char *long_option
= av
[i
] + 2;
571 bool no_more_args
= i
+ 1 >= ac
;
572 if (!ACE_OS::strcmp (long_option
, "idl-version"))
574 bool invalid_version
= no_more_args
;
577 ACE_ERROR ((LM_ERROR
,
578 ACE_TEXT ("--idl-version is missing a required argument, ")
579 ACE_TEXT ("the IDL version to use.\n")
584 idl_global
->idl_version_
.from_string (av
[++i
]);
585 invalid_version
= !idl_global
->idl_version_
.is_valid ();
588 ACE_ERROR ((LM_ERROR
,
589 ACE_TEXT ("\"%C\" is not a valid IDL version supported\n"),
596 print_idl_versions ();
597 idl_global
->parse_args_exit (1);
600 else if (!ACE_OS::strcmp (long_option
, "syntax-only"))
602 idl_global
->syntax_only_
= true;
604 else if (!ACE_OS::strcmp (long_option
, "default-idl-version"))
606 ACE_DEBUG ((LM_INFO
, ACE_TEXT ("%C\n"),
607 idl_global
->default_idl_version_
.to_string ()));
608 idl_global
->parse_args_exit (0);
610 else if (!ACE_OS::strcmp (long_option
, "list-idl-versions"))
612 print_idl_versions ();
613 idl_global
->parse_args_exit (0);
615 else if (!ACE_OS::strcmp (long_option
, "help"))
617 idl_global
->print_help ();
619 else if (!ACE_OS::strcmp (long_option
, "bison-trace"))
623 else if (!ACE_OS::strcmp (long_option
, "version"))
625 idl_global
->print_version ();
627 else if (!ACE_OS::strcmp (long_option
, "dump-builtins"))
629 idl_global
->dump_builtins_
= true;
630 idl_global
->dump_ast ();
632 else if (!ACE_OS::strcmp (long_option
, "just-dump-builtins"))
634 // Don't use dump_ast because we need to dump before parsing any files.
635 idl_global
->dump_builtins_
= true;
636 idl_global
->just_dump_builtins_
= true;
638 else if (!ACE_OS::strcmp (long_option
, "dump"))
640 idl_global
->dump_ast ();
642 else if (!ACE_OS::strcmp (long_option
, "unknown-annotations"))
644 bool invalid_argument
= no_more_args
;
647 ACE_ERROR ((LM_ERROR
,
648 ACE_TEXT ("--unknown-annotations is missing its required argument.")
654 if (!ACE_OS::strcmp (av
[i
], "warn-once"))
656 idl_global
->unknown_annotations_
=
657 IDL_GlobalData::UNKNOWN_ANNOTATIONS_WARN_ONCE
;
659 else if (!ACE_OS::strcmp (av
[i
], "warn-all"))
661 idl_global
->unknown_annotations_
=
662 IDL_GlobalData::UNKNOWN_ANNOTATIONS_WARN_ALL
;
664 else if (!ACE_OS::strcmp (av
[i
], "error"))
666 idl_global
->unknown_annotations_
=
667 IDL_GlobalData::UNKNOWN_ANNOTATIONS_ERROR
;
669 else if (!ACE_OS::strcmp (av
[i
], "ignore"))
671 idl_global
->unknown_annotations_
=
672 IDL_GlobalData::UNKNOWN_ANNOTATIONS_IGNORE
;
676 invalid_argument
= true;
677 ACE_ERROR ((LM_ERROR
,
678 ACE_TEXT ("\"%C\" is not a valid argument.\n"),
683 if (invalid_argument
)
685 ACE_ERROR ((LM_ERROR
,
686 ACE_TEXT ("Use either \"warn-once\", \"warn-all\", ")
687 ACE_TEXT ("\"error\" or \"ignore\".\n"),
690 idl_global
->parse_args_exit (1);
695 be_global
->parse_args (i
, av
);