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);
240 ACE_OS::strcat (idl_global
->local_escapes (), s
);
241 ACE_OS::strcat (idl_global
->local_escapes (), " ");
246 idl_global
->anon_type_diagnostic (
247 IDL_GlobalData::ANON_TYPE_ERROR
);
249 else if (av
[i
][2] == 'w')
251 idl_global
->anon_type_diagnostic (
252 IDL_GlobalData::ANON_TYPE_WARNING
);
254 else if (av
[i
][2] == 's')
256 idl_global
->anon_type_diagnostic (
257 IDL_GlobalData::ANON_TYPE_SILENT
);
265 // Temp directory for the IDL compiler to keep its files.
267 if ((av
[i
][2] == '\0') && (i
< ac
- 1))
269 idl_global
->append_idl_flag (av
[i
+ 1]);
270 idl_global
->temp_dir (av
[i
+ 1]);
282 if (av
[i
][2] == '\0')
286 idl_global
->append_idl_flag (av
[i
+ 1]);
288 ACE_CString arg
= av
[i
];
291 DRV_cpp_putarg (arg
.c_str ());
292 idl_global
->add_include_path (arg
.substr (2).c_str (), false);
302 ACE_CString
arg (av
[i
], 2);
305 idl_global
->add_include_path (arg
.substr (2).c_str (), false);
306 DRV_cpp_putarg (arg
.c_str ());
311 if (av
[i
][2] != '\0')
315 idl_global
->set_compile_flags (idl_global
->compile_flags () |
316 IDL_CF_ONLY_PREPROC
);
319 if (av
[i
][2] != '\0')
323 idl_global
->print_version ();
326 if (av
[i
][2] == '\0')
348 ACE_TEXT ("IDL: Incorrect use of -W option\n")
350 idl_global
->parse_args_exit (1);
356 DRV_prep_cpp_arg (s
+ 2);
363 be_util::prep_be_arg (s
+ 2);
371 if (av
[i
][2] == '\0')
393 idl_global
->set_cpp_location (s
+ 2);
394 DRV_cpp_new_location (s
+ 2);
400 ACE_TEXT ("IDL: I don't understand")
401 ACE_TEXT (" the '-Y' option\n")
403 idl_global
->parse_args_exit (1);
411 ACE_TEXT ("IDL: I dont' understand the use of")
412 ACE_TEXT (" %s with the '-Y' option\n"),
413 ACE_TEXT_CHAR_TO_TCHAR (s
)
415 idl_global
->parse_args_exit (1);
420 if (av
[i
][2] != '\0')
424 idl_global
->dump_ast ();
427 if (av
[i
][2] != '\0')
431 idl_global
->set_compile_flags (idl_global
->compile_flags ()
432 | IDL_CF_INFORMATIVE
);
435 if (av
[i
][2] != '\0')
439 idl_global
->set_compile_flags (idl_global
->compile_flags ()
440 | IDL_CF_NOWARNINGS
);
443 // If identifiers in the same scope differ only by case...
446 // ...report an error.
447 idl_global
->case_diff_error (true);
449 else if (av
[i
][2] == 'w')
451 // ...report a warning (default for now)
452 idl_global
->case_diff_error (false);
461 case 'u': // Old Help Option
462 if (av
[i
][2] != '\0')
466 idl_global
->print_help ();
469 case 'h': // Short Help Option, else let be_global process it
470 if (av
[i
][2] == '\0') {
471 idl_global
->print_help ();
473 be_global
->parse_args (i
, av
);
477 case '-': // -- or Long Options
478 if (av
[i
][2] == '\0')
480 just_files
= true; // Treat the following arguments as files
484 process_long_option(ac
, av
, i
);
489 be_global
->parse_args (i
, av
);
490 } // End of switch (av[i][1])
491 } // End of IF (av[i][0] == '-')
494 DRV_push_file (av
[i
]);
497 if (idl_global
->parse_args_exit_
) return; // Catch Exits
498 } // End of FOR (i = 1; i < ac; i++)
500 be_util::arg_post_proc ();
502 // Make sure the output directory is valid.
503 if (idl_global
->temp_dir () == 0)
505 ACE_TCHAR tmpdir
[MAXPATHLEN
+ 1];
507 if (ACE::get_temp_dir (tmpdir
, MAXPATHLEN
) == -1)
509 ACE_ERROR ((LM_ERROR
,
510 ACE_TEXT ("Temporary path too long, ")
511 ACE_TEXT ("defaulting to current directory\n")));
513 ACE_OS::strcpy (tmpdir
, ACE_TEXT ("."));
517 if (ACE_OS::access (tmpdir
, F_OK
) == -1
518 || ACE_OS::access (tmpdir
, R_OK
) == -1
519 || ACE_OS::access (tmpdir
, W_OK
) == -1)
521 if (ACE_OS::access (tmpdir
, F_OK
| R_OK
| W_OK
) == -1)
526 ACE_TEXT ("Can't access temporary directory (%s),")
527 ACE_TEXT (" using current directory for temp files.\n"),
531 ACE_OS::strcpy (tmpdir
, ACE_TEXT ("."));
533 if (ACE_OS::access (tmpdir
, F_OK
) == -1
534 || ACE_OS::access (tmpdir
, R_OK
) == -1
535 || ACE_OS::access (tmpdir
, W_OK
) == -1)
537 if (ACE_OS::access (tmpdir
, F_OK
| R_OK
| W_OK
) == -1)
540 ACE_ERROR ((LM_ERROR
,
541 "Error: Can't access temporary directory %s\n",
548 idl_global
->temp_dir (ACE_TEXT_ALWAYS_CHAR (tmpdir
));
551 DRV_cpp_post_init ();
558 ACE_TEXT ("These are the valid IDL versions this compiler will accept:\n")
560 for (int v
= 1; v
< IDL_VERSION_COUNT
; v
++)
562 ACE_DEBUG ((LM_INFO
, ACE_TEXT ("%C\n"),
563 IdlVersion (static_cast<SpecificIdlVersion
>(v
)).to_string ()
569 process_long_option(long ac
, char **av
, long &i
)
571 const char *long_option
= av
[i
] + 2;
572 bool no_more_args
= i
+ 1 >= ac
;
573 if (!ACE_OS::strcmp (long_option
, "idl-version"))
575 bool invalid_version
= no_more_args
;
578 ACE_ERROR ((LM_ERROR
,
579 ACE_TEXT ("--idl-version is missing a required argument, ")
580 ACE_TEXT ("the IDL version to use.\n")
585 idl_global
->idl_version_
.from_string (av
[++i
]);
586 invalid_version
= !idl_global
->idl_version_
.is_valid ();
589 ACE_ERROR ((LM_ERROR
,
590 ACE_TEXT ("\"%C\" is not a valid IDL version supported\n"),
597 print_idl_versions ();
598 idl_global
->parse_args_exit (1);
601 else if (!ACE_OS::strcmp (long_option
, "syntax-only"))
603 idl_global
->syntax_only_
= true;
605 else if (!ACE_OS::strcmp (long_option
, "default-idl-version"))
607 ACE_DEBUG ((LM_INFO
, ACE_TEXT ("%C\n"),
608 idl_global
->default_idl_version_
.to_string ()));
609 idl_global
->parse_args_exit (0);
611 else if (!ACE_OS::strcmp (long_option
, "list-idl-versions"))
613 print_idl_versions ();
614 idl_global
->parse_args_exit (0);
616 else if (!ACE_OS::strcmp (long_option
, "help"))
618 idl_global
->print_help ();
620 else if (!ACE_OS::strcmp (long_option
, "bison-trace"))
624 else if (!ACE_OS::strcmp (long_option
, "version"))
626 idl_global
->print_version ();
628 else if (!ACE_OS::strcmp (long_option
, "dump-builtins"))
630 idl_global
->dump_builtins_
= true;
631 idl_global
->dump_ast ();
633 else if (!ACE_OS::strcmp (long_option
, "just-dump-builtins"))
635 // Don't use dump_ast because we need to dump before parsing any files.
636 idl_global
->dump_builtins_
= true;
637 idl_global
->just_dump_builtins_
= true;
639 else if (!ACE_OS::strcmp (long_option
, "dump"))
641 idl_global
->dump_ast ();
643 else if (!ACE_OS::strcmp (long_option
, "unknown-annotations"))
645 bool invalid_argument
= no_more_args
;
648 ACE_ERROR ((LM_ERROR
,
649 ACE_TEXT ("--unknown-annotations is missing its required argument.")
655 if (!ACE_OS::strcmp (av
[i
], "warn-once"))
657 idl_global
->unknown_annotations_
=
658 IDL_GlobalData::UNKNOWN_ANNOTATIONS_WARN_ONCE
;
660 else if (!ACE_OS::strcmp (av
[i
], "warn-all"))
662 idl_global
->unknown_annotations_
=
663 IDL_GlobalData::UNKNOWN_ANNOTATIONS_WARN_ALL
;
665 else if (!ACE_OS::strcmp (av
[i
], "error"))
667 idl_global
->unknown_annotations_
=
668 IDL_GlobalData::UNKNOWN_ANNOTATIONS_ERROR
;
670 else if (!ACE_OS::strcmp (av
[i
], "ignore"))
672 idl_global
->unknown_annotations_
=
673 IDL_GlobalData::UNKNOWN_ANNOTATIONS_IGNORE
;
677 invalid_argument
= true;
678 ACE_ERROR ((LM_ERROR
,
679 ACE_TEXT ("\"%C\" is not a valid argument.\n"),
684 if (invalid_argument
)
686 ACE_ERROR ((LM_ERROR
,
687 ACE_TEXT ("Use either \"warn-once\", \"warn-all\", ")
688 ACE_TEXT ("\"error\" or \"ignore\".\n"),
691 idl_global
->parse_args_exit (1);
696 be_global
->parse_args (i
, av
);