+/* Copyright (C) 2008, 2009 Free Software Foundation, Inc.
+
+This file is part of GCC.
+
+GCC is free software; you can redistribute it and/or modify it under
+the terms of the GNU General Public License as published by the Free
+Software Foundation; either version 3, or (at your option) any later
+version.
+
+GCC is distributed in the hope that it will be useful, but WITHOUT ANY
+WARRANTY; without even the implied warranty of MERCHANTABILITY or
+FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+for more details.
+
+You should have received a copy of the GNU General Public License
+along with GCC; see the file COPYING3. If not see
+<http://www.gnu.org/licenses/>. */
+
#include "config.h"
#include "system.h"
#include "coretypes.h"
} gfc_cpp_macro_queue;
static gfc_cpp_macro_queue *cpp_define_queue, *cpp_undefine_queue;
-struct
+struct gfc_cpp_option_data
{
/* Argument of -cpp, implied by SPEC;
if NULL, preprocessing disabled. */
static void cb_ident (cpp_reader *, source_location, const cpp_string *);
static void cb_used_define (cpp_reader *, source_location, cpp_hashnode *);
static void cb_used_undef (cpp_reader *, source_location, cpp_hashnode *);
+static bool cb_cpp_error (cpp_reader *, int, int, location_t, unsigned int,
+ const char *, va_list *)
+ ATTRIBUTE_GCC_DIAG(6,0);
void pp_dir_change (cpp_reader *, const char *);
static int dump_macro (cpp_reader *, cpp_hashnode *, void *);
cpp_define (pfile, "_LANGUAGE_FORTRAN=1");
if (gfc_option.flag_openmp)
- cpp_define (pfile, "_OPENMP=200505");
+ cpp_define (pfile, "_OPENMP=200805");
/* More builtins that might be useful, but are not documented
gfc_cpp_option.working_directory = value;
break;
+ case OPT_idirafter:
+ gfc_cpp_add_include_path_after (xstrdup(arg), true);
+ break;
+
case OPT_imultilib:
gfc_cpp_option.multilib = arg;
break;
cpp_option->cplusplus_comments = 0;
cpp_option->pedantic = pedantic;
- cpp_option->inhibit_warnings = inhibit_warnings;
cpp_option->dollars_in_ident = gfc_option.flag_dollar_ok;
cpp_option->discard_comments = gfc_cpp_option.discard_comments;
cpp_post_options (cpp_in);
- /* If an error has occurred in cpplib, note it so we fail immediately. */
- errorcount += cpp_errors (cpp_in);
-
gfc_cpp_register_include_paths ();
}
cb->line_change = cb_line_change;
cb->ident = cb_ident;
cb->def_pragma = cb_def_pragma;
+ cb->error = cb_cpp_error;
if (gfc_cpp_option.dump_includes)
cb->include = cb_include;
{
int i;
+ if (gfc_option.flag_preprocessed)
+ return;
+
cpp_change_file (cpp_in, LC_RENAME, _("<built-in>"));
if (!gfc_cpp_option.no_predefined)
cpp_define_builtins (cpp_in);
pp_dir_change (cpp_in, get_src_pwd ());
}
-try
+gfc_try
gfc_cpp_preprocess (const char *source_file)
{
if (!gfc_cpp_enabled ())
cpp_forall_identifiers (cpp_in, dump_macro, NULL);
}
+ putc ('\n', print.outf);
+
if (!gfc_cpp_preprocess_only ()
|| (gfc_cpp_preprocess_only () && gfc_cpp_option.output_filename))
fclose (print.outf);
{
/* CHAIN sets cpp_dir->sysp which differs from 0 if PATH is a system
include path. Fortran does not define any system include paths. */
- int chain = 0;
int cxx_aware = 0;
- add_path (path, chain, cxx_aware, user_supplied);
+ add_path (path, BRACKET, cxx_aware, user_supplied);
+}
+
+void
+gfc_cpp_add_include_path_after (char *path, bool user_supplied)
+{
+ int cxx_aware = 0;
+ add_path (path, AFTER, cxx_aware, user_supplied);
}
void
cpp_define_queue = q;
}
+/* Callback from cpp_error for PFILE to print diagnostics from the
+ preprocessor. The diagnostic is of type LEVEL, with REASON set
+ to the reason code if LEVEL is represents a warning, at location
+ LOCATION, with column number possibly overridden by COLUMN_OVERRIDE
+ if not zero; MSG is the translated message and AP the arguments.
+ Returns true if a diagnostic was emitted, false otherwise. */
+
+static bool
+cb_cpp_error (cpp_reader *pfile ATTRIBUTE_UNUSED, int level, int reason,
+ location_t location, unsigned int column_override,
+ const char *msg, va_list *ap)
+{
+ diagnostic_info diagnostic;
+ diagnostic_t dlevel;
+ int save_warn_system_headers = warn_system_headers;
+ bool ret;
+
+ switch (level)
+ {
+ case CPP_DL_WARNING_SYSHDR:
+ warn_system_headers = 1;
+ /* Fall through. */
+ case CPP_DL_WARNING:
+ dlevel = DK_WARNING;
+ break;
+ case CPP_DL_PEDWARN:
+ dlevel = DK_PEDWARN;
+ break;
+ case CPP_DL_ERROR:
+ dlevel = DK_ERROR;
+ break;
+ case CPP_DL_ICE:
+ dlevel = DK_ICE;
+ break;
+ case CPP_DL_NOTE:
+ dlevel = DK_NOTE;
+ break;
+ case CPP_DL_FATAL:
+ dlevel = DK_FATAL;
+ break;
+ default:
+ gcc_unreachable ();
+ }
+ diagnostic_set_info_translated (&diagnostic, msg, ap,
+ location, dlevel);
+ if (column_override)
+ diagnostic_override_column (&diagnostic, column_override);
+ if (reason == CPP_W_WARNING_DIRECTIVE)
+ diagnostic_override_option_index (&diagnostic, OPT_Wcpp);
+ ret = report_diagnostic (&diagnostic);
+ if (level == CPP_DL_WARNING_SYSHDR)
+ warn_system_headers = save_warn_system_headers;
+ return ret;
+}
/* Callback called when -fworking-director and -E to emit working
directory in cpp output file. */
}
cpp_undefine_queue = NULL;
}
-
-