+/* Interface to specify diagnostic kind overrides. Returns the
+ previous setting, or DK_UNSPECIFIED if the parameters are out of
+ range. */
+diagnostic_t
+diagnostic_classify_diagnostic (diagnostic_context *context,
+ int option_index,
+ diagnostic_t new_kind,
+ location_t where)
+{
+ diagnostic_t old_kind;
+
+ if (option_index <= 0
+ || option_index >= context->n_opts
+ || new_kind >= DK_LAST_DIAGNOSTIC_KIND)
+ return DK_UNSPECIFIED;
+
+ old_kind = context->classify_diagnostic[option_index];
+
+ /* Handle pragmas separately, since we need to keep track of *where*
+ the pragmas were. */
+ if (where != UNKNOWN_LOCATION)
+ {
+ int i;
+
+ for (i = context->n_classification_history - 1; i >= 0; i --)
+ if (context->classification_history[i].option == option_index)
+ {
+ old_kind = context->classification_history[i].kind;
+ break;
+ }
+
+ i = context->n_classification_history;
+ context->classification_history =
+ (diagnostic_classification_change_t *) xrealloc (context->classification_history, (i + 1)
+ * sizeof (diagnostic_classification_change_t));
+ context->classification_history[i].location = where;
+ context->classification_history[i].option = option_index;
+ context->classification_history[i].kind = new_kind;
+ context->n_classification_history ++;
+ }
+ else
+ context->classify_diagnostic[option_index] = new_kind;
+
+ return old_kind;
+}
+
+/* Save all diagnostic classifications in a stack. */
+void
+diagnostic_push_diagnostics (diagnostic_context *context, location_t where ATTRIBUTE_UNUSED)
+{
+ context->push_list = (int *) xrealloc (context->push_list, (context->n_push + 1) * sizeof (int));
+ context->push_list[context->n_push ++] = context->n_classification_history;
+}
+
+/* Restore the topmost classification set off the stack. If the stack
+ is empty, revert to the state based on command line parameters. */
+void
+diagnostic_pop_diagnostics (diagnostic_context *context, location_t where)
+{
+ int jump_to;
+ int i;
+
+ if (context->n_push)
+ jump_to = context->push_list [-- context->n_push];
+ else
+ jump_to = 0;
+
+ i = context->n_classification_history;
+ context->classification_history =
+ (diagnostic_classification_change_t *) xrealloc (context->classification_history, (i + 1)
+ * sizeof (diagnostic_classification_change_t));
+ context->classification_history[i].location = where;
+ context->classification_history[i].option = jump_to;
+ context->classification_history[i].kind = DK_POP;
+ context->n_classification_history ++;
+}
+