Commit b4a93904 by Neil Booth

c-common.h (enum c_language_kind): Emphasize that clk_c is 0.

	* c-common.h (enum c_language_kind): Emphasize that clk_c is 0.
	* c-opts.c (parse_option): Rename find_opt.
	(set_std_c99): New function.
	(COMMAND_LINE_OPTIONS): Handle -remap and -o.  Remove OPT_std_bad.
	(missing_arg): Remove OPT_std_bad.  Handle -o.
	(c_common_decode_option): Handle input and output file names,
	-o and -remap.	Clean up -std= handling.
	* cppinit.c (COMMAND_LINE_OPTIONS): Remove OPT_o and OPT_remap.
	(cpp_handle_option): Similarly.  Don't handle filenames.

From-SVN: r56197
parent 982f35d6
...@@ -238,8 +238,7 @@ extern GTY(()) tree c_global_trees[CTI_MAX]; ...@@ -238,8 +238,7 @@ extern GTY(()) tree c_global_trees[CTI_MAX];
typedef enum c_language_kind typedef enum c_language_kind
{ {
clk_c, /* A dialect of C: K&R C, ANSI/ISO C89, C2000, clk_c = 0, /* A dialect of C: K&R C, ANSI/ISO C89, C2000, etc. */
etc. */
clk_cplusplus /* ANSI/ISO C++ */ clk_cplusplus /* ANSI/ISO C++ */
} }
c_language_kind; c_language_kind;
......
...@@ -34,7 +34,7 @@ Software Foundation, 59 Temple Place - Suite 330, Boston, MA ...@@ -34,7 +34,7 @@ Software Foundation, 59 Temple Place - Suite 330, Boston, MA
static cpp_options *cpp_opts; static cpp_options *cpp_opts;
static void missing_arg PARAMS ((size_t)); static void missing_arg PARAMS ((size_t));
static size_t parse_option PARAMS ((const char *, int)); static size_t find_opt PARAMS ((const char *, int));
static void set_Wimplicit PARAMS ((int)); static void set_Wimplicit PARAMS ((int));
static void complain_wrong_lang PARAMS ((size_t)); static void complain_wrong_lang PARAMS ((size_t));
static void write_langs PARAMS ((char *, int)); static void write_langs PARAMS ((char *, int));
...@@ -42,6 +42,7 @@ static void print_help PARAMS ((void)); ...@@ -42,6 +42,7 @@ static void print_help PARAMS ((void));
static void handle_OPT_d PARAMS ((const char *)); static void handle_OPT_d PARAMS ((const char *));
static void set_std_cxx98 PARAMS ((int)); static void set_std_cxx98 PARAMS ((int));
static void set_std_c89 PARAMS ((int, int)); static void set_std_c89 PARAMS ((int, int));
static void set_std_c99 PARAMS ((int));
#define CL_C_ONLY (1 << 0) /* Only C. */ #define CL_C_ONLY (1 << 0) /* Only C. */
#define CL_OBJC_ONLY (1 << 1) /* Only ObjC. */ #define CL_OBJC_ONLY (1 << 1) /* Only ObjC. */
...@@ -216,10 +217,11 @@ static void set_std_c89 PARAMS ((int, int)); ...@@ -216,10 +217,11 @@ static void set_std_c89 PARAMS ((int, int));
OPT("lang-objc", CL_ALL, OPT_lang_objc) \ OPT("lang-objc", CL_ALL, OPT_lang_objc) \
OPT("nostdinc", CL_ALL, OPT_nostdinc) \ OPT("nostdinc", CL_ALL, OPT_nostdinc) \
OPT("nostdinc++", CL_ALL, OPT_nostdincplusplus) \ OPT("nostdinc++", CL_ALL, OPT_nostdincplusplus) \
OPT("o", CL_ALL | CL_ARG, OPT_o) \
OPT("pedantic", CL_ALL, OPT_pedantic) \ OPT("pedantic", CL_ALL, OPT_pedantic) \
OPT("pedantic-errors", CL_ALL, OPT_pedantic_errors) \ OPT("pedantic-errors", CL_ALL, OPT_pedantic_errors) \
OPT("print-objc-runtime-info", CL_OBJC, OPT_print_objc_runtime_info) \ OPT("print-objc-runtime-info", CL_OBJC, OPT_print_objc_runtime_info) \
OPT("std=", CL_ALL | CL_JOINED, OPT_std_bad) \ OPT("remap", CL_ALL, OPT_remap) \
OPT("std=c++98", CL_CXX, OPT_std_cplusplus98) \ OPT("std=c++98", CL_CXX, OPT_std_cplusplus98) \
OPT("std=c89", CL_C, OPT_std_c89) \ OPT("std=c89", CL_C, OPT_std_c89) \
OPT("std=c99", CL_C, OPT_std_c99) \ OPT("std=c99", CL_C, OPT_std_c99) \
...@@ -294,7 +296,6 @@ missing_arg (opt_index) ...@@ -294,7 +296,6 @@ missing_arg (opt_index)
case OPT_fname_mangling: case OPT_fname_mangling:
case OPT_ftabstop: case OPT_ftabstop:
case OPT_ftemplate_depth: case OPT_ftemplate_depth:
case OPT_std_bad:
default: default:
error ("missing argument to \"-%s\"", cl_options[opt_index].opt_text); error ("missing argument to \"-%s\"", cl_options[opt_index].opt_text);
break; break;
...@@ -302,6 +303,10 @@ missing_arg (opt_index) ...@@ -302,6 +303,10 @@ missing_arg (opt_index)
case OPT_fconstant_string_class: case OPT_fconstant_string_class:
error ("no class name specified with -fconstant-string-class="); error ("no class name specified with -fconstant-string-class=");
break; break;
case OPT_o:
error ("missing filename after \"-%s\"", cl_options[opt_index].opt_text);
break;
} }
} }
...@@ -314,7 +319,7 @@ missing_arg (opt_index) ...@@ -314,7 +319,7 @@ missing_arg (opt_index)
and -pedantic-errors. Also, some options are only accepted by some and -pedantic-errors. Also, some options are only accepted by some
languages. */ languages. */
static size_t static size_t
parse_option (input, lang_flag) find_opt (input, lang_flag)
const char *input; const char *input;
int lang_flag; int lang_flag;
{ {
...@@ -435,32 +440,32 @@ c_common_decode_option (argc, argv) ...@@ -435,32 +440,32 @@ c_common_decode_option (argc, argv)
int argc; int argc;
char **argv; char **argv;
{ {
static int lang_flags[] = {CL_C_ONLY, CL_C, CL_CXX_ONLY, CL_CXX};
size_t opt_index; size_t opt_index;
const char *opt, *arg = 0; const char *opt, *arg = 0;
char *dup = 0; char *dup = 0;
bool on = true; bool on = true;
int result, lang_flag; int result;
const struct cl_option *option; const struct cl_option *option;
enum opt_code code; enum opt_code code;
result = cpp_handle_option (parse_in, argc, argv);
opt = argv[0]; opt = argv[0];
/* Until handling CPP stuff, ignore non-switches. */ /* Interpret "-" or a non-switch as a file name. */
if (opt[0] != '-' || opt[1] == '\0') if (opt[0] != '-' || opt[1] == '\0')
return result;
switch (c_language)
{ {
case clk_c: lang_flag = (flag_objc if (!cpp_opts->in_fname)
? CL_C cpp_opts->in_fname = opt;
: CL_C_ONLY); else if (!cpp_opts->out_fname)
break; cpp_opts->out_fname = opt;
case clk_cplusplus: lang_flag = (flag_objc else
? CL_CXX {
: CL_CXX_ONLY); error ("too many filenames given. Type %s --help for usage",
break; progname);
default: abort (); return argc;
}
return 1;
} }
/* Drop the "no-" from negative switches. */ /* Drop the "no-" from negative switches. */
...@@ -477,8 +482,10 @@ c_common_decode_option (argc, argv) ...@@ -477,8 +482,10 @@ c_common_decode_option (argc, argv)
on = false; on = false;
} }
result = cpp_handle_option (parse_in, argc, argv);
/* Skip over '-'. */ /* Skip over '-'. */
opt_index = parse_option (opt + 1, lang_flag); opt_index = find_opt (opt + 1, lang_flags[(c_language << 1) + flag_objc]);
if (opt_index == N_OPTS) if (opt_index == N_OPTS)
goto done; goto done;
...@@ -1102,6 +1109,16 @@ c_common_decode_option (argc, argv) ...@@ -1102,6 +1109,16 @@ c_common_decode_option (argc, argv)
cpp_opts->no_standard_cplusplus_includes = 1; cpp_opts->no_standard_cplusplus_includes = 1;
break; break;
case OPT_o:
if (!cpp_opts->out_fname)
cpp_opts->out_fname = arg;
else
{
error ("output filename specified twice");
result = argc;
}
break;
/* We need to handle the -pedantic switches here, rather than in /* We need to handle the -pedantic switches here, rather than in
c_common_post_options, so that a subsequent -Wno-endif-labels c_common_post_options, so that a subsequent -Wno-endif-labels
is not overridden. */ is not overridden. */
...@@ -1117,29 +1134,19 @@ c_common_decode_option (argc, argv) ...@@ -1117,29 +1134,19 @@ c_common_decode_option (argc, argv)
print_struct_values = 1; print_struct_values = 1;
break; break;
case OPT_std_bad: case OPT_remap:
error ("unknown standard \"%s\"", arg); cpp_opts->remap = 1;
break; break;
/* Language standards. We currently recognize:
-std=iso9899:1990 same as -ansi
-std=iso9899:199409 ISO C as modified in amend. 1
-std=iso9899:1999 ISO C 99
-std=c89 same as -std=iso9899:1990
-std=c99 same as -std=iso9899:1999
-std=gnu89 default, iso9899:1990 + gnu extensions
-std=gnu99 iso9899:1999 + gnu extensions
*/
case OPT_std_cplusplus98: case OPT_std_cplusplus98:
case OPT_std_gnuplusplus98: case OPT_std_gnuplusplus98:
set_std_cxx98 (code == OPT_std_cplusplus98); set_std_cxx98 (code == OPT_std_cplusplus98 /* ISO */);
break; break;
case OPT_std_iso9899_199409:
case OPT_std_c89: case OPT_std_c89:
case OPT_std_iso9899_1990: case OPT_std_iso9899_1990:
set_std_c89 (code == OPT_std_iso9899_199409, true); case OPT_std_iso9899_199409:
set_std_c89 (code == OPT_std_iso9899_199409 /* c94 */, true /* ISO */);
break; break;
case OPT_std_gnu89: case OPT_std_gnu89:
...@@ -1150,25 +1157,12 @@ c_common_decode_option (argc, argv) ...@@ -1150,25 +1157,12 @@ c_common_decode_option (argc, argv)
case OPT_std_c9x: case OPT_std_c9x:
case OPT_std_iso9899_1999: case OPT_std_iso9899_1999:
case OPT_std_iso9899_199x: case OPT_std_iso9899_199x:
cpp_set_lang (parse_in, CLK_STDC99); set_std_c99 (true /* ISO */);
flag_writable_strings = 0;
flag_no_asm = 1;
flag_no_nonansi_builtin = 1;
flag_noniso_default_format_attributes = 0;
flag_isoc99 = 1;
flag_isoc94 = 1;
flag_iso = 1;
break; break;
case OPT_std_gnu99: case OPT_std_gnu99:
case OPT_std_gnu9x: case OPT_std_gnu9x:
cpp_set_lang (parse_in, CLK_GNUC99); set_std_c99 (false /* ISO */);
flag_writable_strings = 0;
flag_no_asm = 0;
flag_no_nonansi_builtin = 0;
flag_noniso_default_format_attributes = 1;
flag_isoc99 = 1;
flag_isoc94 = 1;
break; break;
case OPT_trigraphs: case OPT_trigraphs:
...@@ -1246,7 +1240,7 @@ c_common_post_options () ...@@ -1246,7 +1240,7 @@ c_common_post_options ()
} }
/* Set the C 89 standard (with 1994 amendments if C94, without GNU /* Set the C 89 standard (with 1994 amendments if C94, without GNU
extensions if ISO). */ extensions if ISO). There is no concept of gnu94. */
static void static void
set_std_c89 (c94, iso) set_std_c89 (c94, iso)
int c94, iso; int c94, iso;
...@@ -1262,6 +1256,21 @@ set_std_c89 (c94, iso) ...@@ -1262,6 +1256,21 @@ set_std_c89 (c94, iso)
flag_writable_strings = 0; flag_writable_strings = 0;
} }
/* Set the C 99 standard (without GNU extensions if ISO). */
static void
set_std_c99 (iso)
int iso;
{
cpp_set_lang (parse_in, iso ? CLK_STDC99: CLK_GNUC99);
flag_no_asm = iso;
flag_no_nonansi_builtin = iso;
flag_noniso_default_format_attributes = !iso;
flag_iso = iso;
flag_isoc99 = 1;
flag_isoc94 = 1;
flag_writable_strings = 0;
}
/* Set the C++ 98 standard (without GNU extensions if ISO). */ /* Set the C++ 98 standard (without GNU extensions if ISO). */
static void static void
set_std_cxx98 (iso) set_std_cxx98 (iso)
......
...@@ -1151,9 +1151,7 @@ new_pending_directive (pend, text, handler) ...@@ -1151,9 +1151,7 @@ new_pending_directive (pend, text, handler)
DEF_OPT("iprefix", no_pth, OPT_iprefix) \ DEF_OPT("iprefix", no_pth, OPT_iprefix) \
DEF_OPT("isystem", no_dir, OPT_isystem) \ DEF_OPT("isystem", no_dir, OPT_isystem) \
DEF_OPT("iwithprefix", no_dir, OPT_iwithprefix) \ DEF_OPT("iwithprefix", no_dir, OPT_iwithprefix) \
DEF_OPT("iwithprefixbefore", no_dir, OPT_iwithprefixbefore) \ DEF_OPT("iwithprefixbefore", no_dir, OPT_iwithprefixbefore)
DEF_OPT("o", no_fil, OPT_o) \
DEF_OPT("remap", 0, OPT_remap)
#define DEF_OPT(text, msg, code) code, #define DEF_OPT(text, msg, code) code,
enum opt_code enum opt_code
...@@ -1256,19 +1254,6 @@ cpp_handle_option (pfile, argc, argv) ...@@ -1256,19 +1254,6 @@ cpp_handle_option (pfile, argc, argv)
int i = 0; int i = 0;
struct cpp_pending *pend = CPP_OPTION (pfile, pending); struct cpp_pending *pend = CPP_OPTION (pfile, pending);
/* Interpret "-" or a non-option as a file name. */
if (argv[i][0] != '-' || argv[i][1] == '\0')
{
if (CPP_OPTION (pfile, in_fname) == NULL)
CPP_OPTION (pfile, in_fname) = argv[i];
else if (CPP_OPTION (pfile, out_fname) == NULL)
CPP_OPTION (pfile, out_fname) = argv[i];
else
cpp_error (pfile, DL_ERROR,
"too many filenames. Type %s --help for usage info",
progname);
}
else
{ {
enum opt_code opt_code; enum opt_code opt_code;
int opt_index; int opt_index;
...@@ -1303,22 +1288,10 @@ cpp_handle_option (pfile, argc, argv) ...@@ -1303,22 +1288,10 @@ cpp_handle_option (pfile, argc, argv)
case OPT_D: case OPT_D:
new_pending_directive (pend, arg, cpp_define); new_pending_directive (pend, arg, cpp_define);
break; break;
case OPT_remap:
CPP_OPTION (pfile, remap) = 1;
break;
case OPT_iprefix: case OPT_iprefix:
CPP_OPTION (pfile, include_prefix) = arg; CPP_OPTION (pfile, include_prefix) = arg;
CPP_OPTION (pfile, include_prefix_len) = strlen (arg); CPP_OPTION (pfile, include_prefix_len) = strlen (arg);
break; break;
case OPT_o:
if (CPP_OPTION (pfile, out_fname) == NULL)
CPP_OPTION (pfile, out_fname) = arg;
else
{
cpp_error (pfile, DL_ERROR, "output filename specified twice");
return argc;
}
break;
case OPT_MG: case OPT_MG:
CPP_OPTION (pfile, print_deps_missing_files) = 1; CPP_OPTION (pfile, print_deps_missing_files) = 1;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment