Commit 5dfa4da1 by Zack Weinberg Committed by Zack Weinberg

cpplib.c (special_symbol): Rewrite.

1999-02-08 23:25 -0500  Zack Weinberg  <zack@midnite.ec.rhno.columbia.edu>
	* cpplib.c (special_symbol): Rewrite.  Don't copy things
	  multiple times.  Handle __STDC__ specially.  T_CONST
	  indicates a constant /string/.  Don't handle T_*_TYPE and
	  T_SPEC_DEFINED.  Use cpp_buf_line_and_col instead of
	  adjust_position.  Determine the file buffer only if needed.
	  (initialize_builtins): Handle __SIZE_TYPE__,
	  __PTRDIFF_TYPE__, __WCHAR_TYPE__, __USER_LABEL_PREFIX__, and
	  __REGISTER_PREFIX__ with T_CONST special hashtab entries.
	  Don't provide __OBJC__; the driver does that.	 Provide
	  __STDC_VERSION__, using T_CONST.  Use T_STDC for
	  __STDC__.  Give install the length of all symbols defined.
	  (eval_if_expression): Drop code to insert and remove the
	  "defined" special symbol.
	* cpplib.h: Remove SELF_DIR_DUMMY (no longer used).  Remove
	  T_*_TYPE and T_SPEC_DEFINED from enum node_type; add T_STDC.
	* cpphash.c (install): Drop the `ivalue' parameter.  Constify
	  the `value' parameter.  All callers changed.
	* cpphash.h (install): Change prototype to match.
	  (union hashval): Remove `ival' member.
	* cppexp.c (cpp_lex): Handle `defined' here.

From-SVN: r25097
parent 1c6c21c8
1999-02-08 23:25 -0500 Zack Weinberg <zack@midnite.ec.rhno.columbia.edu>
* cpplib.c (special_symbol): Rewrite. Don't copy things
multiple times. Handle __STDC__ specially. T_CONST
indicates a constant /string/. Don't handle T_*_TYPE and
T_SPEC_DEFINED. Use cpp_buf_line_and_col instead of
adjust_position. Determine the file buffer only if needed.
(initialize_builtins): Handle __SIZE_TYPE__,
__PTRDIFF_TYPE__, __WCHAR_TYPE__, __USER_LABEL_PREFIX__, and
__REGISTER_PREFIX__ with T_CONST special hashtab entries.
Don't provide __OBJC__; the driver does that. Provide
__STDC_VERSION__, using T_CONST. Use T_STDC for
__STDC__. Give install the length of all symbols defined.
(eval_if_expression): Drop code to insert and remove the
"defined" special symbol.
* cpplib.h: Remove SELF_DIR_DUMMY (no longer used). Remove
T_*_TYPE and T_SPEC_DEFINED from enum node_type; add T_STDC.
* cpphash.c (install): Drop the `ivalue' parameter. Constify
the `value' parameter. All callers changed.
* cpphash.h (install): Change prototype to match.
(union hashval): Remove `ival' member.
* cppexp.c (cpp_lex): Handle `defined' here.
Mon Feb 8 17:29:42 1999 Jeffrey A Law (law@cygnus.com)
* pa.h (EXTRA_CONSTRAINT): Fix comment.
......
/* Parse C expressions for CCCP.
Copyright (C) 1987, 1992, 1994, 1995, 1997, 1998 Free Software Foundation.
Copyright (C) 1987, 92, 94, 95, 97, 98, 1999 Free Software Foundation.
This program is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by the
......@@ -109,6 +109,8 @@ static long right_shift PARAMS ((cpp_reader *, long, int, unsigned long));
#define HOST_BITS_PER_WIDE_INT (CHAR_BIT * sizeof (HOST_WIDE_INT))
#endif
#define SKIP_WHITE_SPACE(p) do { while (is_hor_space[*p]) p++; } while (0)
struct operation {
short op;
char rprio; /* Priority of op (relative to it right operand). */
......@@ -435,12 +437,52 @@ cpp_lex (pfile, skip_evaluation)
return parse_charconst (pfile, tok_start, tok_end);
case CPP_NAME:
if (CPP_WARN_UNDEF (pfile) && !skip_evaluation)
cpp_warning (pfile, "`%.*s' is not defined",
(int) (tok_end - tok_start), tok_start);
op.op = INT;
op.unsignedp = 0;
op.value = 0;
if (strcmp (tok_start, "defined"))
{
if (CPP_WARN_UNDEF (pfile) && !skip_evaluation)
cpp_warning (pfile, "`%.*s' is not defined",
(int) (tok_end - tok_start), tok_start);
}
else
{
int paren = 0, len;
cpp_buffer *ip = CPP_BUFFER (pfile);
U_CHAR *tok;
SKIP_WHITE_SPACE (ip->cur);
if (*ip->cur == '(')
{
paren++;
ip->cur++; /* Skip over the paren */
SKIP_WHITE_SPACE (ip->cur);
}
if (!is_idstart[*ip->cur])
goto oops;
if (ip->cur[0] == 'L' && (ip->cur[1] == '\'' || ip->cur[1] == '"'))
goto oops;
tok = ip->cur;
while (is_idchar[*ip->cur])
++ip->cur;
len = ip->cur - tok;
SKIP_WHITE_SPACE (ip->cur);
if (paren)
{
if (*ip->cur != ')')
goto oops;
++ip->cur;
}
if (cpp_lookup (pfile, tok, len, -1))
op.value = 1;
}
return op;
oops:
cpp_error (pfile, "`defined' without an identifier");
return op;
case CPP_OTHER:
......
......@@ -131,8 +131,8 @@ delete_macro (hp)
}
/* Install a name in the main hash table, even if it is already there.
name stops with first non alphanumeric, except leading '#'.
caller must check against redefinition if that is desired.
Name stops with first non alphanumeric, except leading '#'.
Caller must check against redefinition if that is desired.
delete_macro () removes things installed by install () in fifo order.
this is important because of the `defined' special symbol used
in #if, and also if pushdef/popdef directives are ever implemented.
......@@ -144,12 +144,11 @@ delete_macro (hp)
Otherwise, compute the hash code. */
HASHNODE *
install (name, len, type, ivalue, value, hash)
install (name, len, type, value, hash)
U_CHAR *name;
int len;
enum node_type type;
int ivalue;
char *value;
const char *value;
int hash;
{
register HASHNODE *hp;
......@@ -177,10 +176,7 @@ install (name, len, type, ivalue, value, hash)
hp->next->prev = hp;
hp->type = type;
hp->length = len;
if (hp->type == T_CONST)
hp->value.ival = ivalue;
else
hp->value.cpval = value;
hp->value.cpval = value;
hp->name = ((U_CHAR *) hp) + sizeof (HASHNODE);
bcopy (name, hp->name, len);
hp->name[len] = 0;
......
......@@ -16,12 +16,12 @@ along with this program; if not, write to the Free Software
Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
/* different kinds of things that can appear in the value field
of a hash node. Actually, this may be useless now. */
union hashval {
int ival;
char *cpval;
DEFINITION *defn;
struct hashnode *aschain; /* for #assert */
of a hash node. */
union hashval
{
const char *cpval; /* some predefined macros */
DEFINITION *defn; /* #define */
struct hashnode *aschain; /* #assert */
};
struct hashnode {
......@@ -49,6 +49,7 @@ typedef struct hashnode HASHNODE;
#define HASHSTEP(old, c) ((old << 2) + c)
#define MAKE_POS(v) (v & 0x7fffffff) /* make number positive */
extern HASHNODE *install PARAMS ((U_CHAR *,int,enum node_type, int,char *,int));
extern HASHNODE *install PARAMS ((U_CHAR *, int, enum node_type,
const char *, int));
extern int hashf PARAMS ((const U_CHAR *, int, int));
extern void delete_macro PARAMS ((HASHNODE *));
......@@ -526,12 +526,7 @@ struct include_hash
redundant_include_p */
char *buf, *limit; /* for file content cache, not yet implemented */
};
/* If a buffer's dir field is SELF_DIR_DUMMY, it means the file was found
via the same directory as the file that #included it. */
#define SELF_DIR_DUMMY ((struct file_name_list *) (~0))
/* Name under which this program was invoked. */
extern char *progname;
......@@ -570,16 +565,11 @@ enum node_type {
T_BASE_FILE, /* `__BASE_FILE__' */
T_INCLUDE_LEVEL, /* `__INCLUDE_LEVEL__' */
T_VERSION, /* `__VERSION__' */
T_SIZE_TYPE, /* `__SIZE_TYPE__' */
T_PTRDIFF_TYPE, /* `__PTRDIFF_TYPE__' */
T_WCHAR_TYPE, /* `__WCHAR_TYPE__' */
T_USER_LABEL_PREFIX_TYPE, /* `__USER_LABEL_PREFIX__' */
T_REGISTER_PREFIX_TYPE, /* `__REGISTER_PREFIX__' */
T_TIME, /* `__TIME__' */
T_CONST, /* Constant value, used by `__STDC__' */
T_STDC, /* `__STDC__' */
T_CONST, /* Constant string, used by `__SIZE_TYPE__' etc */
T_MACRO, /* macro defined by `#define' */
T_DISABLED, /* macro temporarily turned off for rescan */
T_SPEC_DEFINED, /* special `defined' macro for use in #if statements */
T_PCSTRING, /* precompiled string (hashval is KEYDEF *) */
T_UNUSED /* Used for something not defined. */
};
......
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