Commit f9a0e96c by Zack Weinberg Committed by Zack Weinberg

cppexp.c, [...]: Eradicate all traces of code dependent on traditional,…

cppexp.c, [...]: Eradicate all traces of code dependent on traditional, lang_chill, or lang_fortran.

	* cppexp.c, cpphash.c, cpphash.h, cppinit.c, cpplex.c,
	cpplib.c, cpplib.h: Eradicate all traces of code dependent on
	traditional, lang_chill, or lang_fortran.

	* cppfiles.c: #undef strcmp to suppress warning about macros
	used without arguments.
	(_cpp_execute_include): Use f, not fname, in "No include path"
	error.
	(_cpp_pop_file_buffer): New function.
	* cpplib.c: Don't include <sys/mman.h>.
	(cpp_push_buffer): Set line_base and lineno in new buffer.
	(cpp_pop_buffer): Use _cpp_pop_file_buffer.

	* cpplex.c: Move all prototypes and structure declarations to the
	top of the file.  Properly parenthesise some macro arguments.
	(cpp_scan_line): New function.
	(special_symbol [case T_INCLUDE_DEPTH]): Use pfile->include_depth,
	don't need to walk up the stack counting.

From-SVN: r35003
parent d55bb5be
2000-07-12 Zack Weinberg <zack@wolery.cumb.org>
* cppexp.c, cpphash.c, cpphash.h, cppinit.c, cpplex.c,
cpplib.c, cpplib.h: Eradicate all traces of code dependent on
traditional, lang_chill, or lang_fortran.
* cppfiles.c: #undef strcmp to suppress warning about macros
used without arguments.
(_cpp_execute_include): Use f, not fname, in "No include path"
error.
(_cpp_pop_file_buffer): New function.
* cpplib.c: Don't include <sys/mman.h>.
(cpp_push_buffer): Set line_base and lineno in new buffer.
(cpp_pop_buffer): Use _cpp_pop_file_buffer.
* cpplex.c: Move all prototypes and structure declarations to the
top of the file. Properly parenthesise some macro arguments.
(cpp_scan_line): New function.
(special_symbol [case T_INCLUDE_DEPTH]): Use pfile->include_depth,
don't need to walk up the stack counting.
2000-07-12 Kaveh R. Ghazi <ghazi@caip.rutgers.edu>
* c-common.c (combine_strings): Emit a pedantic warning when a
......
......@@ -298,7 +298,7 @@ parse_charconst (pfile, tok)
SYNTAX_ERROR ("empty character constant");
else if (num_chars > max_chars)
SYNTAX_ERROR ("character constant too long");
else if (num_chars != 1 && ! CPP_TRADITIONAL (pfile))
else if (num_chars != 1)
cpp_warning (pfile, "multi-character character constant");
/* If char type is signed, sign-extend the constant. */
......
......@@ -43,6 +43,10 @@ Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
# define O_BINARY 0
#endif
/* Suppress warning about function macros used w/o arguments in traditional
C. It is unlikely that glibc's strcmp macro helps this file at all. */
#undef strcmp
static struct file_name_map *read_name_map
PARAMS ((cpp_reader *, const char *));
static char *read_filename_string PARAMS ((int, FILE *));
......@@ -423,7 +427,7 @@ _cpp_execute_include (pfile, f, len, no_reinclude, search_start, angle_brackets)
if (!search_start)
{
cpp_error (pfile, "No include path in which to find %s", fname);
cpp_error (pfile, "No include path in which to find %s", f);
return;
}
......@@ -762,6 +766,44 @@ read_with_read (fp, fd, size)
return offset;
}
/* Do appropriate cleanup when a file buffer is popped off the input
stack. */
void
_cpp_pop_file_buffer (pfile, buf)
cpp_reader *pfile;
cpp_buffer *buf;
{
struct include_file *inc = buf->inc;
if (pfile->system_include_depth)
pfile->system_include_depth--;
if (pfile->include_depth)
pfile->include_depth--;
if (pfile->potential_control_macro)
{
if (inc->cmacro != NEVER_REREAD)
inc->cmacro = pfile->potential_control_macro;
pfile->potential_control_macro = 0;
}
pfile->input_stack_listing_current = 0;
/* Discard file buffer. XXX Would be better to cache these instead
of the file descriptors. */
#ifdef HAVE_MMAP_FILE
if (buf->mapped)
munmap ((caddr_t) buf->buf, buf->rlimit - buf->buf);
else
#endif
free ((PTR) buf->buf);
/* If the file will not be included again, close it. */
if (DO_NOT_REREAD (inc))
{
close (inc->fd);
inc->fd = -1;
}
}
/* The file_name_map structure holds a mapping of file names for a
particular directory. This mapping is read from the file named
FILE_NAME_MAP_FILE in that directory. Such a file can be used to
......
......@@ -502,34 +502,33 @@ save_expansion (pfile, first, first_param, info)
ntokens = len = 0;
for (token = first; token->type != CPP_EOF; token++)
{
const char *msg;
if (token->type == CPP_PASTE)
{
/* Token-paste ##, but is a normal token if traditional. */
if (! CPP_TRADITIONAL (pfile))
/* Token-paste ##, can appear in both object-like and
function-like macros, but not at the ends. Constraint
6.10.3.3.1 */
if (token == first || token[1].type == CPP_EOF)
{
msg = "\"##\" cannot appear at either end of a macro expansion";
/* Constraint 6.10.3.3.1 */
if (token == first || token[1].type == CPP_EOF)
goto error;
continue;
cpp_error_with_line (pfile, token->line, token->col,
"'##' cannot appear at either end of a macro expansion");
return 0;
}
continue;
}
else if (token->type == CPP_HASH)
{
/* Stringifying #, but is a normal character if traditional,
or in object-like macros. Constraint 6.10.3.2.1. */
if (info->paramc >= 0 && ! CPP_TRADITIONAL (pfile))
/* Stringifying #, but a normal character in object-like
macros. Must come before a parameter name. Constraint
6.10.3.2.1. */
if (info->paramc >= 0)
{
if (token[1].type == CPP_NAME
&& find_param (first_param, token + 1))
continue;
if (! CPP_OPTION (pfile, lang_asm))
{
msg = "'#' is not followed by a macro parameter";
error:
cpp_error_with_line (pfile, token->line, token->col, msg);
cpp_error_with_line (pfile, token->line, token->col,
"'#' is not followed by a macro parameter");
return 0;
}
}
......@@ -583,7 +582,7 @@ save_expansion (pfile, first, first_param, info)
dest->val.aux = param_no - 1;
dest->type = CPP_MACRO_ARG;
if (token[-1].type == CPP_HASH && ! CPP_TRADITIONAL (pfile))
if (token[-1].type == CPP_HASH)
dest->flags = token[-1].flags | STRINGIFY_ARG;
else
dest->flags = token->flags; /* Particularly PREV_WHITE. */
......@@ -591,17 +590,12 @@ save_expansion (pfile, first, first_param, info)
continue;
case CPP_PASTE:
if (! CPP_TRADITIONAL (pfile))
{
dest[-1].flags |= PASTE_LEFT;
continue;
}
break;
dest[-1].flags |= PASTE_LEFT;
continue;
case CPP_HASH:
/* Stringifying #. Constraint 6.10.3.2.1 */
if (list->paramc >= 0 && ! CPP_TRADITIONAL (pfile)
&& token[1].type == CPP_NAME
if (list->paramc >= 0 && token[1].type == CPP_NAME
&& find_param (first_param, token + 1))
continue;
break;
......
......@@ -194,7 +194,6 @@ extern unsigned char _cpp_IStable[256];
#define CPP_PREV_BUFFER(BUFFER) ((BUFFER)->prev)
#define CPP_PRINT_DEPS(PFILE) CPP_OPTION (PFILE, print_deps)
#define CPP_TRADITIONAL(PFILE) CPP_OPTION (PFILE, traditional)
#define CPP_IN_SYSTEM_HEADER(PFILE) \
(CPP_BUFFER (PFILE) && CPP_BUFFER (PFILE)->inc \
&& CPP_BUFFER (PFILE)->inc->sysp)
......@@ -228,6 +227,7 @@ extern void _cpp_report_missing_guards PARAMS ((cpp_reader *));
extern void _cpp_init_includes PARAMS ((cpp_reader *));
extern void _cpp_cleanup_includes PARAMS ((cpp_reader *));
extern const char *_cpp_fake_include PARAMS ((cpp_reader *, const char *));
extern void _cpp_pop_file_buffer PARAMS ((cpp_reader *, cpp_buffer *));
/* In cppexp.c */
extern int _cpp_parse_expr PARAMS ((cpp_reader *));
......
......@@ -571,12 +571,7 @@ initialize_builtins (pfile)
}
else
{
cpp_hashnode *hp;
if (b->type == T_STDC && CPP_TRADITIONAL (pfile))
continue;
hp = cpp_lookup (pfile, b->name, b->len);
cpp_hashnode *hp = cpp_lookup (pfile, b->name, b->len);
hp->type = b->type;
}
}
......@@ -762,22 +757,12 @@ cpp_start_read (pfile, print, fname)
return 0;
}
/* Chill should not be used with -trigraphs. */
if (CPP_OPTION (pfile, chill) && CPP_OPTION (pfile, trigraphs))
{
cpp_warning (pfile, "-lang-chill and -trigraphs are mutually exclusive");
CPP_OPTION (pfile, trigraphs) = 0;
}
/* -Wtraditional is not useful in C++ mode. */
if (CPP_OPTION (pfile, cplusplus))
CPP_OPTION (pfile, warn_traditional) = 0;
/* Do not warn about illegal token pasting if -traditional,
-lang-fortran, or -lang-asm. */
if (CPP_OPTION (pfile, traditional)
|| CPP_OPTION (pfile, lang_fortran)
|| CPP_OPTION (pfile, lang_asm))
/* Do not warn about illegal token pasting if -lang-asm. */
if (CPP_OPTION (pfile, lang_asm))
CPP_OPTION (pfile, warn_paste) = 0;
/* Set this if it hasn't been set already. */
......@@ -1028,8 +1013,6 @@ new_pending_directive (pend, text, handler)
DEF_OPT("lang-c", 0, OPT_lang_c) \
DEF_OPT("lang-c++", 0, OPT_lang_cplusplus) \
DEF_OPT("lang-c89", 0, OPT_lang_c89) \
DEF_OPT("lang-chill", 0, OPT_lang_chill) \
DEF_OPT("lang-fortran", 0, OPT_lang_fortran) \
DEF_OPT("lang-objc", 0, OPT_lang_objc) \
DEF_OPT("lang-objc++", 0, OPT_lang_objcplusplus) \
DEF_OPT("nostdinc", 0, OPT_nostdinc) \
......@@ -1048,7 +1031,6 @@ new_pending_directive (pend, text, handler)
DEF_OPT("std=iso9899:199409", 0, OPT_std_iso9899_199409) \
DEF_OPT("std=iso9899:1999", 0, OPT_std_iso9899_1999) \
DEF_OPT("std=iso9899:199x", 0, OPT_std_iso9899_199x) \
DEF_OPT("traditional", 0, OPT_traditional) \
DEF_OPT("trigraphs", 0, OPT_trigraphs) \
DEF_OPT("v", 0, OPT_v) \
DEF_OPT("w", 0, OPT_w)
......@@ -1267,13 +1249,6 @@ handle_option (pfile, argc, argv)
case OPT_pedantic:
CPP_OPTION (pfile, pedantic) = 1;
break;
case OPT_traditional:
CPP_OPTION (pfile, traditional) = 1;
CPP_OPTION (pfile, cplusplus_comments) = 0;
CPP_OPTION (pfile, trigraphs) = 0;
CPP_OPTION (pfile, digraphs) = 0;
CPP_OPTION (pfile, warn_trigraphs) = 0;
break;
case OPT_trigraphs:
CPP_OPTION (pfile, trigraphs) = 1;
break;
......@@ -1321,18 +1296,6 @@ handle_option (pfile, argc, argv)
CPP_OPTION (pfile, dollars_in_ident) = 0;
new_pending_directive (pend, "__ASSEMBLER__", cpp_define);
break;
case OPT_lang_fortran:
CPP_OPTION (pfile, lang_fortran) = 1;
CPP_OPTION (pfile, traditional) = 1;
CPP_OPTION (pfile, cplusplus_comments) = 0;
new_pending_directive (pend, "_LANGUAGE_FORTRAN", cpp_define);
break;
case OPT_lang_chill:
CPP_OPTION (pfile, objc) = 0;
CPP_OPTION (pfile, cplusplus) = 0;
CPP_OPTION (pfile, chill) = 1;
CPP_OPTION (pfile, traditional) = 1;
break;
case OPT_nostdinc:
/* -nostdinc causes no default include directories.
You must specify all include-file directories with -I. */
......@@ -1721,18 +1684,15 @@ Switches:\n\
fputs (_("\
-pedantic Issue all warnings demanded by strict ISO C\n\
-pedantic-errors Issue -pedantic warnings as errors instead\n\
-traditional Follow K&R pre-processor behaviour\n\
-trigraphs Support ISO C trigraphs\n\
-lang-c Assume that the input sources are in C\n\
-lang-c89 Assume that the input sources are in C89\n\
-lang-c++ Assume that the input sources are in C++\n\
"), stdout);
fputs (_("\
-lang-c++ Assume that the input sources are in C++\n\
-lang-objc Assume that the input sources are in ObjectiveC\n\
-lang-objc++ Assume that the input sources are in ObjectiveC++\n\
-lang-asm Assume that the input sources are in assembler\n\
-lang-fortran Assume that the input sources are in Fortran\n\
-lang-chill Assume that the input sources are in Chill\n\
"), stdout);
fputs (_("\
-std=<std name> Specify the conformance standard; one of:\n\
......@@ -1746,9 +1706,8 @@ Switches:\n\
"), stdout);
fputs (_("\
-Wno-comment{s} Do not warn about comments\n\
-Wtraditional Warn if a macro argument is/would be turned into\n\
a string if -traditional is specified\n\
-Wno-traditional Do not warn about stringification\n\
-Wtraditional Warn about features not present in traditional C\n\
-Wno-traditional Do not warn about traditional C\n\
-Wundef Warn if an undefined macro is used by #if\n\
-Wno-undef Do not warn about testing undefined macros\n\
-Wimport Warn about the use of the #import directive\n\
......
......@@ -28,10 +28,6 @@ Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
#include "obstack.h"
#include "symcat.h"
#ifdef HAVE_MMAP_FILE
# include <sys/mman.h>
#endif
/* Stack of conditionals currently in progress
(including both successful and failing conditionals). */
......@@ -168,9 +164,6 @@ _cpp_check_directive (pfile, token, bol)
if (!bol && dtable[i].origin == KANDR && CPP_WTRADITIONAL (pfile))
cpp_warning (pfile, "traditional C ignores #%s with the # indented",
dtable[i].name);
if (!bol && CPP_TRADITIONAL (pfile))
return 0;
/* Issue -pedantic warnings for extended directives. */
if (CPP_PEDANTIC (pfile) && dtable[i].origin == EXTENSION)
......@@ -212,10 +205,7 @@ _cpp_check_linemarker (pfile, token, bol)
if (!bol && CPP_WTRADITIONAL (pfile))
cpp_warning (pfile, "traditional C ignores #%s with the # indented",
dtable[T_LINE].name);
if (!bol && CPP_TRADITIONAL (pfile))
return 0;
return &dtable[T_LINE];
}
......@@ -977,15 +967,12 @@ parse_ifdef (pfile, name)
const cpp_token *token = _cpp_get_token (pfile);
type = token->type;
if (!CPP_TRADITIONAL (pfile))
{
if (type == CPP_EOF)
cpp_pedwarn (pfile, "#%s with no argument", name);
else if (type != CPP_NAME)
cpp_pedwarn (pfile, "#%s with invalid argument", name);
else if (_cpp_get_token (pfile)->type != CPP_EOF)
cpp_pedwarn (pfile, "garbage at end of #%s", name);
}
if (type == CPP_EOF)
cpp_pedwarn (pfile, "#%s with no argument", name);
else if (type != CPP_NAME)
cpp_pedwarn (pfile, "#%s with invalid argument", name);
else if (_cpp_get_token (pfile)->type != CPP_EOF)
cpp_pedwarn (pfile, "garbage at end of #%s", name);
if (type == CPP_NAME)
node = token->val.node;
......@@ -995,7 +982,7 @@ parse_ifdef (pfile, name)
node->name);
node = 0;
}
return node;
}
......@@ -1527,9 +1514,10 @@ cpp_push_buffer (pfile, buffer, length)
new = xobnew (pfile->buffer_ob, cpp_buffer);
memset (new, 0, sizeof (cpp_buffer));
new->buf = new->cur = buffer;
new->line_base = new->buf = new->cur = buffer;
new->rlimit = buffer + length;
new->prev = buf;
new->lineno = 1;
CPP_BUFFER (pfile) = new;
return new;
......@@ -1542,34 +1530,8 @@ cpp_pop_buffer (pfile)
cpp_buffer *buf = CPP_BUFFER (pfile);
unwind_if_stack (pfile, buf);
#ifdef HAVE_MMAP_FILE
if (buf->mapped)
munmap ((caddr_t) buf->buf, buf->rlimit - buf->buf);
else
#endif
if (buf->inc)
free ((PTR) buf->buf);
if (buf->inc)
{
if (pfile->system_include_depth)
pfile->system_include_depth--;
if (pfile->include_depth)
pfile->include_depth--;
if (pfile->potential_control_macro)
{
if (buf->inc->cmacro != NEVER_REREAD)
buf->inc->cmacro = pfile->potential_control_macro;
pfile->potential_control_macro = 0;
}
pfile->input_stack_listing_current = 0;
/* If the file will not be included again, then close it. */
if (DO_NOT_REREAD (buf->inc))
{
close (buf->inc->fd);
buf->inc->fd = -1;
}
}
_cpp_pop_file_buffer (pfile, buf);
CPP_BUFFER (pfile) = CPP_PREV_BUFFER (buf);
obstack_free (pfile->buffer_ob, buf);
......
......@@ -314,15 +314,6 @@ struct cpp_options
likely to be in comments). */
unsigned char lang_asm;
/* Nonzero means this is Fortran, and we don't know where the
comments are, so permit unbalanced ' strings. Unlike lang_asm,
this does not ignore unrecognized directives. */
unsigned char lang_fortran;
/* Nonzero means handle CHILL comment syntax and output CHILL string
delimiters for __DATE__ etc. */
unsigned char chill;
/* Nonzero means don't copy comments into the output file. */
unsigned char discard_comments;
......@@ -366,9 +357,8 @@ struct cpp_options
/* Nonzero means warn if #import is used. */
unsigned char warn_import;
/* Nonzero means warn if a macro argument is (or would be)
stringified with -traditional, and warn about directives
with the # indented from the beginning of the line. */
/* Nonzero means warn about various incompatibilities with
traditional C. */
unsigned char warn_traditional;
/* Nonzero means warn if ## is applied to two tokens that cannot be
......@@ -396,9 +386,6 @@ struct cpp_options
/* Zero means dollar signs are punctuation. */
unsigned char dollars_in_ident;
/* Nonzero means try to imitate old fashioned non-ISO preprocessor. */
unsigned char traditional;
/* Nonzero means warn if undefined identifiers are evaluated in an #if. */
unsigned char warn_undef;
......@@ -701,6 +688,7 @@ extern cpp_buffer *cpp_push_buffer PARAMS ((cpp_reader *,
extern cpp_buffer *cpp_pop_buffer PARAMS ((cpp_reader *));
extern void cpp_scan_buffer PARAMS ((cpp_reader *, cpp_printer *));
extern void cpp_scan_buffer_nooutput PARAMS ((cpp_reader *));
extern void cpp_scan_line PARAMS ((cpp_reader *));
extern int cpp_ideq PARAMS ((const cpp_token *,
const char *));
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment