summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorbothner <bothner@138bc75d-0d04-0410-961f-82ee72b054a4>1995-04-05 20:34:58 +0000
committerbothner <bothner@138bc75d-0d04-0410-961f-82ee72b054a4>1995-04-05 20:34:58 +0000
commitad0e2334a8dbbaec4d046a4929b08571197a8ec8 (patch)
tree3f19a4877af3ab4b37d888910ed26b0c9b498db6
parent55f69bde59bbf1aabfcf87b3c2987435b574a7a2 (diff)
downloadgcc-ad0e2334a8dbbaec4d046a4929b08571197a8ec8.tar.gz
Moved 'high-level' error functions from cpperror.c to cpplib.c.
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@9315 138bc75d-0d04-0410-961f-82ee72b054a4
-rw-r--r--gcc/cpperror.c226
-rw-r--r--gcc/cpplib.c222
2 files changed, 230 insertions, 218 deletions
diff --git a/gcc/cpperror.c b/gcc/cpperror.c
index 982bcc33449..33e2c01188d 100644
--- a/gcc/cpperror.c
+++ b/gcc/cpperror.c
@@ -25,27 +25,6 @@ Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
#include "cpplib.h"
#include <stdio.h>
-/* This defines "errno" properly for VMS, and gives us EACCES. */
-#include <errno.h>
-#ifndef errno
-extern int errno;
-#endif
-
-#ifndef VMS
-#ifndef HAVE_STRERROR
-extern int sys_nerr;
-#if defined(bsd4_4)
-extern const char *const sys_errlist[];
-#else
-extern char *sys_errlist[];
-#endif
-#else /* HAVE_STERRROR */
-char *strerror ();
-#endif
-#else /* VMS */
-char *strerror (int,...);
-#endif
-
/* Print the file names and line numbers of the #include
commands which led to the current file. */
@@ -102,147 +81,25 @@ cpp_print_containing_files (pfile)
}
void
-cpp_print_file_and_line (pfile)
- cpp_reader *pfile;
-{
- cpp_buffer *ip = cpp_file_buffer (pfile);
-
- if (ip != NULL)
- {
- long line, col;
- cpp_buf_line_and_col (ip, &line, &col);
- if (pfile->show_column)
- fprintf (stderr, "%s:%d:%d: ", ip->nominal_fname, line, col);
- else
- fprintf (stderr, "%s:%d: ", ip->nominal_fname, line);
- }
-}
-
-void
-cpp_error (pfile, msg, arg1, arg2, arg3)
- cpp_reader *pfile;
- char *msg;
- char *arg1, *arg2, *arg3;
-{
- cpp_print_containing_files (pfile);
- cpp_print_file_and_line (pfile);
- fprintf (stderr, msg, arg1, arg2, arg3);
- fprintf (stderr, "\n");
- pfile->errors++;
-}
-
-/* Print error message but don't count it. */
-
-void
-cpp_warning (pfile, msg, arg1, arg2, arg3)
- cpp_reader *pfile;
- char *msg;
- char *arg1, *arg2, *arg3;
-{
- if (CPP_OPTIONS (pfile)->inhibit_warnings)
- return;
-
- if (CPP_OPTIONS (pfile)->warnings_are_errors)
- pfile->errors++;
-
- cpp_print_containing_files (pfile);
- cpp_print_file_and_line (pfile);
- fprintf (stderr, "warning: ");
- fprintf (stderr, msg, arg1, arg2, arg3);
- fprintf (stderr, "\n");
-}
-
-void
-cpp_error_with_line (pfile, line, msg, arg1, arg2, arg3)
- cpp_reader *pfile;
- int line;
- char *msg;
- char *arg1, *arg2, *arg3;
-{
- int i;
- cpp_buffer *ip = cpp_file_buffer (pfile);
-
- cpp_print_containing_files (pfile);
-
- if (ip != NULL)
- fprintf (stderr, "%s:%d: ", ip->nominal_fname, line);
-
- fprintf (stderr, msg, arg1, arg2, arg3);
- fprintf (stderr, "\n");
- pfile->errors++;
-}
-
-void
-cpp_warning_with_line (pfile, line, msg, arg1, arg2, arg3)
- cpp_reader *pfile;
- int line;
- char *msg;
- char *arg1, *arg2, *arg3;
-{
- int i;
- cpp_buffer *ip;
-
- if (CPP_OPTIONS (pfile)->inhibit_warnings)
- return;
-
- if (CPP_OPTIONS (pfile)->warnings_are_errors)
- pfile->errors++;
-
- cpp_print_containing_files (pfile);
-
- ip = cpp_file_buffer (pfile);
-
- if (ip != NULL)
- fprintf (stderr, "%s:%d: ", ip->nominal_fname, line);
- fprintf (stderr, "warning: ");
- fprintf (stderr, msg, arg1, arg2, arg3);
- fprintf (stderr, "\n");
-}
-
-/* Print an error message and maybe count it. */
-
-void
-cpp_pedwarn (pfile, msg, arg1, arg2, arg3)
+cpp_file_line_for_message (pfile, filename, line, column)
cpp_reader *pfile;
- char *msg;
- char *arg1, *arg2, *arg3;
-{
- if (CPP_OPTIONS (pfile)->pedantic_errors)
- cpp_error (pfile, msg, arg1, arg2, arg3);
- else
- cpp_warning (pfile, msg, arg1, arg2, arg3);
-}
-
-void
-cpp_pedwarn_with_line (pfile, line, msg, arg1, arg2, arg3)
- cpp_reader *pfile;
- int line;
- char *msg;
- char *arg1, *arg2, *arg3;
+ char *filename;
+ int line, column;
{
- if (CPP_OPTIONS (pfile)->pedantic_errors)
- cpp_error_with_line (pfile, line, msg, arg1, arg2, arg3);
+ if (column > 0)
+ fprintf (stderr, "%s:%d:%d: ", filename, line, column);
else
- cpp_warning_with_line (pfile, line, msg, arg1, arg2, arg3);
+ fprintf (stderr, "%s:%d: ", filename, line);
}
-/* Report a warning (or an error if pedantic_errors)
- giving specified file name and line number, not current. */
-
-void
-cpp_pedwarn_with_file_and_line (pfile, file, line, msg, arg1, arg2, arg3)
+/* IS_ERROR is 1 for error, 0 for warning */
+void cpp_message (pfile, is_error, msg, arg1, arg2, arg3)
+ int is_error;
cpp_reader *pfile;
- char *file;
- int line;
char *msg;
char *arg1, *arg2, *arg3;
{
- if (!CPP_OPTIONS (pfile)->pedantic_errors
- && CPP_OPTIONS (pfile)->inhibit_warnings)
- return;
- if (file != NULL)
- fprintf (stderr, "%s:%d: ", file, line);
- if (CPP_OPTIONS (pfile)->pedantic_errors)
+ if (is_error)
pfile->errors++;
else
fprintf (stderr, "warning: ");
@@ -261,69 +118,6 @@ fatal (str, arg)
}
-/*
- * my_strerror - return the descriptive text associated with an `errno' code.
- */
-
-char *
-my_strerror (errnum)
- int errnum;
-{
- char *result;
-
-#ifndef VMS
-#ifndef HAVE_STRERROR
- result = (char *) ((errnum < sys_nerr) ? sys_errlist[errnum] : 0);
-#else
- result = strerror (errnum);
-#endif
-#else /* VMS */
- /* VAXCRTL's strerror() takes an optional second argument, which only
- matters when the first argument is EVMSERR. However, it's simplest
- just to pass it unconditionally. `vaxc$errno' is declared in
- <errno.h>, and maintained by the library in parallel with `errno'.
- We assume that caller's `errnum' either matches the last setting of
- `errno' by the library or else does not have the value `EVMSERR'. */
-
- result = strerror (errnum, vaxc$errno);
-#endif
-
- if (!result)
- result = "undocumented I/O error";
-
- return result;
-}
-
-/* Error including a message from `errno'. */
-
-void
-cpp_error_from_errno (pfile, name)
- cpp_reader *pfile;
- char *name;
-{
- int i;
- cpp_buffer *ip = cpp_file_buffer (pfile);
-
- cpp_print_containing_files (pfile);
-
- if (ip != NULL)
- fprintf (stderr, "%s:%d: ", ip->nominal_fname, ip->lineno);
-
- fprintf (stderr, "%s: %s\n", name, my_strerror (errno));
-
- pfile->errors++;
-}
-
-void
-cpp_perror_with_name (pfile, name)
- cpp_reader *pfile;
- char *name;
-{
- fprintf (stderr, "%s: ", progname);
- fprintf (stderr, "%s: %s\n", name, my_strerror (errno));
- pfile->errors++;
-}
-
void
cpp_pfatal_with_name (pfile, name)
cpp_reader *pfile;
diff --git a/gcc/cpplib.c b/gcc/cpplib.c
index 78ac53591c6..6589f80650b 100644
--- a/gcc/cpplib.c
+++ b/gcc/cpplib.c
@@ -4723,7 +4723,9 @@ cpp_get_token (pfile)
return CPP_COMMENT;
}
else if (CPP_TRADITIONAL (pfile))
- goto get_next;
+ {
+ return CPP_COMMENT;
+ }
else
{
#if 0
@@ -7289,6 +7291,222 @@ cpp_read_check_assertion (pfile)
CPP_ADJUST_WRITTEN (pfile, - name_length); /* pop */
return result;
}
+
+void
+cpp_print_file_and_line (pfile)
+ cpp_reader *pfile;
+{
+ cpp_buffer *ip = cpp_file_buffer (pfile);
+
+ if (ip != NULL)
+ {
+ long line, col;
+ cpp_buf_line_and_col (ip, &line, &col);
+ cpp_file_line_for_message (pfile, ip->nominal_fname,
+ line, pfile->show_column ? col : -1);
+ }
+}
+
+void
+cpp_error (pfile, msg, arg1, arg2, arg3)
+ cpp_reader *pfile;
+ char *msg;
+ char *arg1, *arg2, *arg3;
+{
+ cpp_print_containing_files (pfile);
+ cpp_print_file_and_line (pfile);
+ cpp_message (pfile, 1, msg, arg1, arg2, arg3);
+}
+
+/* Print error message but don't count it. */
+
+void
+cpp_warning (pfile, msg, arg1, arg2, arg3)
+ cpp_reader *pfile;
+ char *msg;
+ char *arg1, *arg2, *arg3;
+{
+ if (CPP_OPTIONS (pfile)->inhibit_warnings)
+ return;
+
+ if (CPP_OPTIONS (pfile)->warnings_are_errors)
+ pfile->errors++;
+
+ cpp_print_containing_files (pfile);
+ cpp_print_file_and_line (pfile);
+ cpp_message (pfile, 0, msg, arg1, arg2, arg3);
+}
+
+/* Print an error message and maybe count it. */
+
+void
+cpp_pedwarn (pfile, msg, arg1, arg2, arg3)
+ cpp_reader *pfile;
+ char *msg;
+ char *arg1, *arg2, *arg3;
+{
+ if (CPP_OPTIONS (pfile)->pedantic_errors)
+ cpp_error (pfile, msg, arg1, arg2, arg3);
+ else
+ cpp_warning (pfile, msg, arg1, arg2, arg3);
+}
+
+void
+cpp_error_with_line (pfile, line, msg, arg1, arg2, arg3)
+ cpp_reader *pfile;
+ int line;
+ char *msg;
+ char *arg1, *arg2, *arg3;
+{
+ int i;
+ cpp_buffer *ip = cpp_file_buffer (pfile);
+
+ cpp_print_containing_files (pfile);
+
+ if (ip != NULL)
+ cpp_file_line_for_message (pfile, ip->nominal_fname, line, -1);
+
+ cpp_message (pfile, 1, msg, arg1, arg2, arg3);
+}
+
+void
+cpp_warning_with_line (pfile, line, msg, arg1, arg2, arg3)
+ cpp_reader *pfile;
+ int line;
+ char *msg;
+ char *arg1, *arg2, *arg3;
+{
+ int i;
+ cpp_buffer *ip;
+
+ if (CPP_OPTIONS (pfile)->inhibit_warnings)
+ return;
+
+ if (CPP_OPTIONS (pfile)->warnings_are_errors)
+ pfile->errors++;
+
+ cpp_print_containing_files (pfile);
+
+ ip = cpp_file_buffer (pfile);
+
+ if (ip != NULL)
+ cpp_file_line_for_message (pfile, ip->nominal_fname, line, -1);
+
+ cpp_message (pfile, 0, msg, arg1, arg2, arg3);
+}
+
+void
+cpp_pedwarn_with_line (pfile, line, msg, arg1, arg2, arg3)
+ cpp_reader *pfile;
+ int line;
+ char *msg;
+ char *arg1, *arg2, *arg3;
+{
+ if (CPP_OPTIONS (pfile)->pedantic_errors)
+ cpp_error_with_line (pfile, line, msg, arg1, arg2, arg3);
+ else
+ cpp_warning_with_line (pfile, line, msg, arg1, arg2, arg3);
+}
+
+/* Report a warning (or an error if pedantic_errors)
+ giving specified file name and line number, not current. */
+
+void
+cpp_pedwarn_with_file_and_line (pfile, file, line, msg, arg1, arg2, arg3)
+ cpp_reader *pfile;
+ char *file;
+ int line;
+ char *msg;
+ char *arg1, *arg2, *arg3;
+{
+ if (!CPP_OPTIONS (pfile)->pedantic_errors
+ && CPP_OPTIONS (pfile)->inhibit_warnings)
+ return;
+ if (file != NULL)
+ cpp_file_line_for_message (pfile, file, line, -1);
+ cpp_message (pfile, CPP_OPTIONS (pfile)->pedantic_errors,
+ msg, arg1, arg2, arg3);
+}
+
+/* This defines "errno" properly for VMS, and gives us EACCES. */
+#include <errno.h>
+#ifndef errno
+extern int errno;
+#endif
+
+#ifndef VMS
+#ifndef HAVE_STRERROR
+extern int sys_nerr;
+#if defined(bsd4_4)
+extern const char *const sys_errlist[];
+#else
+extern char *sys_errlist[];
+#endif
+#else /* HAVE_STERRROR */
+char *strerror ();
+#endif
+#else /* VMS */
+char *strerror (int,...);
+#endif
+
+/*
+ * my_strerror - return the descriptive text associated with an `errno' code.
+ */
+
+char *
+my_strerror (errnum)
+ int errnum;
+{
+ char *result;
+
+#ifndef VMS
+#ifndef HAVE_STRERROR
+ result = (char *) ((errnum < sys_nerr) ? sys_errlist[errnum] : 0);
+#else
+ result = strerror (errnum);
+#endif
+#else /* VMS */
+ /* VAXCRTL's strerror() takes an optional second argument, which only
+ matters when the first argument is EVMSERR. However, it's simplest
+ just to pass it unconditionally. `vaxc$errno' is declared in
+ <errno.h>, and maintained by the library in parallel with `errno'.
+ We assume that caller's `errnum' either matches the last setting of
+ `errno' by the library or else does not have the value `EVMSERR'. */
+
+ result = strerror (errnum, vaxc$errno);
+#endif
+
+ if (!result)
+ result = "undocumented I/O error";
+
+ return result;
+}
+
+/* Error including a message from `errno'. */
+
+void
+cpp_error_from_errno (pfile, name)
+ cpp_reader *pfile;
+ char *name;
+{
+ int i;
+ cpp_buffer *ip = cpp_file_buffer (pfile);
+
+ cpp_print_containing_files (pfile);
+
+ if (ip != NULL)
+ cpp_file_line_for_message (pfile, ip->nominal_fname, ip->lineno, -1);
+
+ cpp_message (pfile, 1, "%s: %s\n", name, my_strerror (errno));
+}
+
+void
+cpp_perror_with_name (pfile, name)
+ cpp_reader *pfile;
+ char *name;
+{
+ cpp_message (pfile, 1, "%s: %s: %s\n", progname, name, my_strerror (errno));
+}
/* TODO:
* No pre-compiled header file support.
@@ -7306,7 +7524,7 @@ cpp_read_check_assertion (pfile)
*
* Support -dM flag (dump_all_macros).
*
- * -include should be made to returns results incrementally.
+ * -include should be made to return results incrementally.
* (current implementation only works when cpp is used as main program)
*
*/