return true;
}
+/* Return whether ENUM_ARG is OK for the language given by
+ LANG_MASK. */
+
+static bool
+enum_arg_ok_for_language (const struct cl_enum_arg *enum_arg,
+ unsigned int lang_mask)
+{
+ return (lang_mask & CL_DRIVER) || !(enum_arg->flags & CL_ENUM_DRIVER_ONLY);
+}
+
+/* Look up ARG in ENUM_ARGS for language LANG_MASK, returning true and
+ storing the value in *VALUE if found, and returning false without
+ modifying *VALUE if not found. */
+
+static bool
+enum_arg_to_value (const struct cl_enum_arg *enum_args,
+ const char *arg, int *value, unsigned int lang_mask)
+{
+ unsigned int i;
+
+ for (i = 0; enum_args[i].arg != NULL; i++)
+ if (strcmp (arg, enum_args[i].arg) == 0
+ && enum_arg_ok_for_language (&enum_args[i], lang_mask))
+ {
+ *value = enum_args[i].value;
+ return true;
+ }
+
+ return false;
+}
+
+/* Look of VALUE in ENUM_ARGS for language LANG_MASK and store the
+ corresponding string in *ARGP, returning true if the found string
+ was marked as canonical, false otherwise. If VALUE is not found
+ (which may be the case for uninitialized values if the relevant
+ option has not been passed), set *ARGP to NULL and return
+ false. */
+
+bool
+enum_value_to_arg (const struct cl_enum_arg *enum_args,
+ const char **argp, int value, unsigned int lang_mask)
+{
+ unsigned int i;
+
+ for (i = 0; enum_args[i].arg != NULL; i++)
+ if (enum_args[i].value == value
+ && (enum_args[i].flags & CL_ENUM_CANONICAL)
+ && enum_arg_ok_for_language (&enum_args[i], lang_mask))
+ {
+ *argp = enum_args[i].arg;
+ return true;
+ }
+
+ for (i = 0; enum_args[i].arg != NULL; i++)
+ if (enum_args[i].value == value
+ && enum_arg_ok_for_language (&enum_args[i], lang_mask))
+ {
+ *argp = enum_args[i].arg;
+ return false;
+ }
+
+ *argp = NULL;
+ return false;
+}
/* Fill in the canonical option part of *DECODED with an option
described by OPT_INDEX, ARG and VALUE. */
errors |= CL_ERR_UINT_ARG;
}
+ /* If the switch takes an enumerated argument, convert it. */
+ if (arg && (option->var_type == CLVC_ENUM))
+ {
+ const struct cl_enum *e = &cl_enums[option->var_enum];
+
+ gcc_assert (value == 1);
+ if (enum_arg_to_value (e->values, arg, &value, lang_mask))
+ {
+ const char *carg = NULL;
+
+ if (enum_value_to_arg (e->values, &carg, value, lang_mask))
+ arg = carg;
+ gcc_assert (carg != NULL);
+ }
+ else
+ errors |= CL_ERR_ENUM_ARG;
+ }
+
done:
decoded->opt_index = opt_index;
decoded->arg = arg;
return;
}
+ if (decoded->errors & CL_ERR_ENUM_ARG)
+ {
+ const struct cl_enum *e = &cl_enums[option->var_enum];
+ unsigned int i;
+ size_t len;
+ char *s, *p;
+
+ if (e->unknown_error)
+ error_at (loc, e->unknown_error, decoded->arg);
+ else
+ error_at (loc, "unrecognized argument in option %qs", opt);
+
+ len = 0;
+ for (i = 0; e->values[i].arg != NULL; i++)
+ len += strlen (e->values[i].arg) + 1;
+
+ s = XALLOCAVEC (char, len);
+ p = s;
+ for (i = 0; e->values[i].arg != NULL; i++)
+ {
+ size_t arglen = strlen (e->values[i].arg);
+ memcpy (p, e->values[i].arg, arglen);
+ p[arglen] = ' ';
+ p += arglen + 1;
+ }
+ p[-1] = 0;
+ inform (loc, "valid arguments to %qs are: %s", option->opt_text, s);
+ return;
+ }
+
gcc_assert (!decoded->errors);
if (!handle_option (opts, opts_set, decoded, lang_mask, DK_UNSPECIFIED,
if (set_flag_var)
*(const char **) set_flag_var = "";
break;
+
+ case CLVC_ENUM:
+ {
+ const struct cl_enum *e = &cl_enums[option->var_enum];
+
+ e->set (flag_var, value);
+ if (set_flag_var)
+ e->set (set_flag_var, 1);
+ }
+ break;
+
+ case CLVC_DEFER:
+ {
+ VEC(cl_deferred_option,heap) *vec
+ = (VEC(cl_deferred_option,heap) *) *(void **) flag_var;
+ cl_deferred_option *p;
+
+ p = VEC_safe_push (cl_deferred_option, heap, vec, NULL);
+ p->opt_index = opt_index;
+ p->arg = arg;
+ p->value = value;
+ *(void **) flag_var = vec;
+ if (set_flag_var)
+ *(void **) set_flag_var = vec;
+ }
+ break;
}
if ((diagnostic_t) kind != DK_UNSPECIFIED
return NULL;
return (void *)(((char *) opts) + option->flag_var_offset);
}
+
+/* Return 1 if option OPT_IDX is enabled in OPTS, 0 if it is disabled,
+ or -1 if it isn't a simple on-off switch. */
+
+int
+option_enabled (int opt_idx, void *opts)
+{
+ const struct cl_option *option = &(cl_options[opt_idx]);
+ struct gcc_options *optsg = (struct gcc_options *) opts;
+ void *flag_var = option_flag_var (opt_idx, optsg);
+
+ if (flag_var)
+ switch (option->var_type)
+ {
+ case CLVC_BOOLEAN:
+ return *(int *) flag_var != 0;
+
+ case CLVC_EQUAL:
+ return *(int *) flag_var == option->var_value;
+
+ case CLVC_BIT_CLEAR:
+ return (*(int *) flag_var & option->var_value) == 0;
+
+ case CLVC_BIT_SET:
+ return (*(int *) flag_var & option->var_value) != 0;
+
+ case CLVC_STRING:
+ case CLVC_ENUM:
+ case CLVC_DEFER:
+ break;
+ }
+ return -1;
+}
+
+/* Fill STATE with the current state of option OPTION in OPTS. Return
+ true if there is some state to store. */
+
+bool
+get_option_state (struct gcc_options *opts, int option,
+ struct cl_option_state *state)
+{
+ void *flag_var = option_flag_var (option, opts);
+
+ if (flag_var == 0)
+ return false;
+
+ switch (cl_options[option].var_type)
+ {
+ case CLVC_BOOLEAN:
+ case CLVC_EQUAL:
+ state->data = flag_var;
+ state->size = sizeof (int);
+ break;
+
+ case CLVC_BIT_CLEAR:
+ case CLVC_BIT_SET:
+ state->ch = option_enabled (option, opts);
+ state->data = &state->ch;
+ state->size = 1;
+ break;
+
+ case CLVC_STRING:
+ state->data = *(const char **) flag_var;
+ if (state->data == 0)
+ state->data = "";
+ state->size = strlen ((const char *) state->data) + 1;
+ break;
+
+ case CLVC_ENUM:
+ state->data = flag_var;
+ state->size = cl_enums[cl_options[option].var_enum].var_size;
+ break;
+
+ case CLVC_DEFER:
+ return false;
+ }
+ return true;
+}
+
+/* Set a warning option OPT_INDEX (language mask LANG_MASK, option
+ handlers HANDLERS) to have diagnostic kind KIND for option
+ structures OPTS and OPTS_SET and diagnostic context DC (possibly
+ NULL), at location LOC (UNKNOWN_LOCATION for -Werror=). If IMPLY,
+ the warning option in question is implied at this point. This is
+ used by -Werror= and #pragma GCC diagnostic. */
+
+void
+control_warning_option (unsigned int opt_index, int kind, bool imply,
+ location_t loc, unsigned int lang_mask,
+ const struct cl_option_handlers *handlers,
+ struct gcc_options *opts,
+ struct gcc_options *opts_set,
+ diagnostic_context *dc)
+{
+ if (cl_options[opt_index].alias_target != N_OPTS)
+ opt_index = cl_options[opt_index].alias_target;
+ if (opt_index == OPT_SPECIAL_ignore)
+ return;
+ if (dc)
+ diagnostic_classify_diagnostic (dc, opt_index, (diagnostic_t) kind, loc);
+ if (imply)
+ {
+ /* -Werror=foo implies -Wfoo. */
+ if (cl_options[opt_index].var_type == CLVC_BOOLEAN)
+ handle_generated_option (opts, opts_set,
+ opt_index, NULL, 1, lang_mask,
+ kind, loc, handlers, dc);
+ }
+}