#include "c-pragma.h"
#include "langhooks.h"
#include "hosthooks.h"
+#include "diagnostic.h"
/* This is a list of flag variables that must match exactly, and their
names for the error message. The possible values for *flag_var must
cpp_write_pch_state (parse_in, pch_outfile);
timevar_pop (TV_PCH_CPP_SAVE);
- if (fseek (pch_outfile, 0, SEEK_SET) != 0
+ if (global_dc->pch_save (pch_outfile) < 0
+ || fseek (pch_outfile, 0, SEEK_SET) != 0
|| fwrite (get_ident (), IDENT_LENGTH, 1, pch_outfile) != 1)
fatal_error (input_location, "cannot write %s: %m", pch_file);
linemap_line_start (line_table, saved_loc.line, 0);
timevar_pop (TV_PCH_CPP_RESTORE);
+
+ if (global_dc->pch_restore (f) < 0)
+ fatal_error (input_location, "cannot read %s: %m", name);
+
fclose (f);
if (cpp_result != 0)
m_push_list.release ();
}
+/* Save the diagnostic_option_classifier state to F for PCH
+ output. Returns 0 on success, -1 on error. */
+
+int
+diagnostic_option_classifier::pch_save (FILE *f)
+{
+ unsigned int lengths[2] = { m_classification_history.length (),
+ m_push_list.length () };
+ if (fwrite (lengths, sizeof (lengths), 1, f) != 1
+ || fwrite (m_classification_history.address (),
+ sizeof (diagnostic_classification_change_t),
+ lengths[0], f) != lengths[0]
+ || fwrite (m_push_list.address (), sizeof (int),
+ lengths[1], f) != lengths[1])
+ return -1;
+ return 0;
+}
+
+/* Read the diagnostic_option_classifier state from F for PCH
+ read. Returns 0 on success, -1 on error. */
+
+int
+diagnostic_option_classifier::pch_restore (FILE *f)
+{
+ unsigned int lengths[2];
+ if (fread (lengths, sizeof (lengths), 1, f) != 1)
+ return -1;
+ gcc_checking_assert (m_classification_history.is_empty ());
+ gcc_checking_assert (m_push_list.is_empty ());
+ m_classification_history.safe_grow (lengths[0]);
+ m_push_list.safe_grow (lengths[1]);
+ if (fread (m_classification_history.address (),
+ sizeof (diagnostic_classification_change_t),
+ lengths[0], f) != lengths[0]
+ || fread (m_push_list.address (), sizeof (int),
+ lengths[1], f) != lengths[1])
+ return -1;
+ return 0;
+}
+
/* Save all diagnostic classifications in a stack. */
void
diagnostic_t
update_effective_level_from_pragmas (diagnostic_info *diagnostic) const;
+ int pch_save (FILE *);
+ int pch_restore (FILE *);
+
private:
/* Each time a diagnostic's classification is changed with a pragma,
we record the change and the location of the change in an array of
const char *, const char *, va_list *,
diagnostic_t) ATTRIBUTE_GCC_DIAG(7,0);
+ int
+ pch_save (FILE *f)
+ {
+ return m_option_classifier.pch_save (f);
+ }
+
+ int
+ pch_restore (FILE *f)
+ {
+ return m_option_classifier.pch_restore (f);
+ }
+
private:
void error_recursion () ATTRIBUTE_NORETURN;