diff options
author | Zack Weinberg <zack@midnite.ec.rhno.columbia.edu> | 1999-02-08 20:27:27 +0000 |
---|---|---|
committer | Zack Weinberg <zack@gcc.gnu.org> | 1999-02-08 20:27:27 +0000 |
commit | 5dfa4da1309462fbefced93c213c28a5417eabdb (patch) | |
tree | c079b4e9cc9eae1f223a405bc08b6a1cd358fb74 /gcc/cppexp.c | |
parent | 1c6c21c8a84cd07a513ebbf13e18325ea1bb1f18 (diff) | |
download | gcc-5dfa4da1309462fbefced93c213c28a5417eabdb.zip gcc-5dfa4da1309462fbefced93c213c28a5417eabdb.tar.gz gcc-5dfa4da1309462fbefced93c213c28a5417eabdb.tar.bz2 |
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
Diffstat (limited to 'gcc/cppexp.c')
-rw-r--r-- | gcc/cppexp.c | 50 |
1 files changed, 46 insertions, 4 deletions
diff --git a/gcc/cppexp.c b/gcc/cppexp.c index 09c1a05..093412e 100644 --- a/gcc/cppexp.c +++ b/gcc/cppexp.c @@ -1,5 +1,5 @@ /* 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: |