summaryrefslogtreecommitdiff
path: root/gcc/cppexp.c
diff options
context:
space:
mode:
authorzack <zack@138bc75d-0d04-0410-961f-82ee72b054a4>2000-02-10 23:47:04 +0000
committerzack <zack@138bc75d-0d04-0410-961f-82ee72b054a4>2000-02-10 23:47:04 +0000
commiteb3948d14fb48860754f84cdc8c0d507d89899fa (patch)
tree62eef5d947b8384b8147ec6d6b0b4aecba2485ac /gcc/cppexp.c
parent36cf37bea77749a21754b4de93aa6a3f317605a6 (diff)
downloadgcc-eb3948d14fb48860754f84cdc8c0d507d89899fa.tar.gz
* cppexp.c: Don't include cpphash.h.
(parse_charconst, cpp_lex): Use cpp_defined. (cpp_lex): Use get_directive_token throughout. Remove unnecessary cases from switch. Move assertion-handling code down to OTHER case. (cpp_parse_expr): If we see '+' or '-', check the context to determine if they are unary or binary operators. Streamline the jumps a bit. Do not call skip_rest_of_line. * cpplib.c: Make skip_rest_of_line and cpp_skip_hspace static. Export get_directive_token. Update commentary. (cpp_defined): New function. (do_define): Remove reference to T_PCSTRING. Call free_definition to release memory for old definition, when redefining a macro. (eval_if_expression): Set only_seen_white to 0 before calling cpp_parse_expr. Call skip_rest_of_line after it returns. (cpp_read_check_assertion): Don't preserve a pointer into the token buffer across a call to cpp_get_token. * Makefile.in (cppexp.o): Don't depend on cpphash.h. * cppfiles.c (redundant_include_p): Use cpp_defined. * cpphash.c (free_definition): New function. (delete_macro): Use it. Update commentary. * cpphash.h: Typedef HASHNODE here. Prototype cpp_lookup and free_definition. * cpplib.h: Don't typedef HASHNODE here. Delete T_PCSTRING from enum node_type. Prototype cpp_defined and get_directive_token. Don't prototype cpp_lookup, skip_rest_of_line, or cpp_skip_hspace. * fix-header.c (check_macro_names): Use cpp_defined. (read_scan_file): Set inhibit_warnings and inhibit_errors in the options structure. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@31908 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'gcc/cppexp.c')
-rw-r--r--gcc/cppexp.c111
1 files changed, 42 insertions, 69 deletions
diff --git a/gcc/cppexp.c b/gcc/cppexp.c
index 7f8c9174797..a7db2ce899a 100644
--- a/gcc/cppexp.c
+++ b/gcc/cppexp.c
@@ -27,7 +27,6 @@ Written by Per Bothner 1994. */
#include "config.h"
#include "system.h"
#include "cpplib.h"
-#include "cpphash.h"
#ifdef MULTIBYTE_CHARS
#include <locale.h>
@@ -331,8 +330,8 @@ parse_charconst (pfile, start, end)
/* If char type is signed, sign-extend the constant. */
num_bits = num_chars * width;
- if (cpp_lookup (pfile, (const U_CHAR *)"__CHAR_UNSIGNED__",
- sizeof ("__CHAR_UNSIGNED__")-1)
+ if (cpp_defined (pfile, (const U_CHAR *)"__CHAR_UNSIGNED__",
+ sizeof ("__CHAR_UNSIGNED__")-1)
|| ((result >> (num_bits - 1)) & 1) == 0)
op.value = result & ((unsigned HOST_WIDEST_INT) ~0
>> (HOST_BITS_PER_WIDEST_INT - num_bits));
@@ -377,56 +376,28 @@ cpp_lex (pfile, skip_evaluation)
cpp_reader *pfile;
int skip_evaluation;
{
- U_CHAR c;
struct token *toktab;
enum cpp_token token;
struct operation op;
U_CHAR *tok_start, *tok_end;
- int old_written;
-
- retry:
+ long old_written;
old_written = CPP_WRITTEN (pfile);
- cpp_skip_hspace (pfile);
- c = CPP_BUF_PEEK (CPP_BUFFER (pfile));
- if (c == '#')
- {
- op.op = INT;
- op.value = cpp_read_check_assertion (pfile);
- return op;
- }
-
- if (c == '\n')
- {
- op.op = 0;
- return op;
- }
+ token = get_directive_token (pfile);
- token = cpp_get_token (pfile);
tok_start = pfile->token_buffer + old_written;
tok_end = CPP_PWRITTEN (pfile);
- pfile->limit = tok_start;
+ CPP_SET_WRITTEN (pfile, old_written);
switch (token)
{
case CPP_EOF: /* Should not happen ... */
case CPP_VSPACE:
op.op = 0;
return op;
- case CPP_POP:
- if (CPP_BUFFER (pfile)->fname != NULL)
- {
- op.op = 0;
- return op;
- }
- cpp_pop_buffer (pfile);
- goto retry;
- case CPP_HSPACE:
- case CPP_COMMENT:
- goto retry;
case CPP_NUMBER:
return parse_number (pfile, tok_start, tok_end);
case CPP_STRING:
- cpp_error (pfile, "string constants not allowed in #if expressions");
+ cpp_error (pfile, "string constants are not allowed in #if expressions");
op.op = ERROR;
return op;
case CPP_CHAR:
@@ -445,45 +416,38 @@ cpp_lex (pfile, skip_evaluation)
else
{
int paren = 0, len;
- cpp_buffer *ip = CPP_BUFFER (pfile);
U_CHAR *tok;
- HASHNODE *hp;
- cpp_skip_hspace (pfile);
- if (*ip->cur == '(')
+ pfile->no_macro_expand++;
+ token = get_directive_token (pfile);
+ if (token == CPP_LPAREN)
{
paren++;
- ip->cur++; /* Skip over the paren */
- cpp_skip_hspace (pfile);
+ CPP_SET_WRITTEN (pfile, old_written);
+ token = get_directive_token (pfile);
}
- if (!is_idstart(*ip->cur))
- goto oops;
- if (ip->cur[0] == 'L' && (ip->cur[1] == '\'' || ip->cur[1] == '"'))
+ if (token != CPP_NAME)
goto oops;
- tok = ip->cur;
- while (is_idchar(*ip->cur))
- ++ip->cur;
- len = ip->cur - tok;
- cpp_skip_hspace (pfile);
+
+ tok = pfile->token_buffer + old_written;
+ len = CPP_PWRITTEN (pfile) - tok;
+ if (cpp_defined (pfile, tok, len))
+ op.value = 1;
+
if (paren)
{
- if (*ip->cur != ')')
+ if (get_directive_token (pfile) != CPP_RPAREN)
goto oops;
- ++ip->cur;
- }
- hp = cpp_lookup (pfile, tok, len);
- if (hp != NULL)
- {
- if (hp->type == T_POISON)
- cpp_error (pfile, "attempt to use poisoned `%s'", hp->name);
- else
- op.value = 1;
}
+ CPP_SET_WRITTEN (pfile, old_written);
+ pfile->no_macro_expand--;
}
return op;
oops:
+ CPP_SET_WRITTEN (pfile, old_written);
+ pfile->no_macro_expand--;
cpp_error (pfile, "`defined' without an identifier");
return op;
@@ -501,6 +465,13 @@ cpp_lex (pfile, skip_evaluation)
op.op = toktab->token;
return op;
}
+ else if (tok_start + 1 == tok_end && *tok_start == '#')
+ {
+ CPP_FORWARD (CPP_BUFFER (pfile), -1);
+ op.op = INT;
+ op.value = cpp_read_check_assertion (pfile);
+ return op;
+ }
/* fall through */
default:
op.op = *tok_start;
@@ -736,15 +707,16 @@ cpp_parse_expr (pfile)
cpp_ice (pfile, "cpp_lex returns a NAME");
goto syntax_error;
case INT: case CHAR:
- top->value = op.value;
- top->unsignedp = op.unsignedp;
goto set_value;
case 0:
lprio = 0; goto maybe_reduce;
case '+': case '-':
- /* Is this correct if unary ? FIXME */
- flags = RIGHT_OPERAND_REQUIRED;
- lprio = PLUS_PRIO; rprio = lprio + 1; goto maybe_reduce;
+ if (top->flags & HAVE_VALUE)
+ {
+ lprio = PLUS_PRIO;
+ goto binop;
+ }
+ /* else fall through */
case '!': case '~':
flags = RIGHT_OPERAND_REQUIRED;
rprio = UNARY_PRIO; lprio = rprio + 1; goto maybe_reduce;
@@ -777,10 +749,6 @@ cpp_parse_expr (pfile)
goto maybe_reduce;
case ERROR:
goto syntax_error;
- binop:
- flags = LEFT_OPERAND_REQUIRED|RIGHT_OPERAND_REQUIRED;
- rprio = lprio + 1;
- goto maybe_reduce;
default:
cpp_error (pfile, "invalid character in #if");
goto syntax_error;
@@ -793,9 +761,15 @@ cpp_parse_expr (pfile)
cpp_error (pfile, "syntax error in #if");
goto syntax_error;
}
+ top->value = op.value;
+ top->unsignedp = op.unsignedp;
top->flags |= HAVE_VALUE;
continue;
+ binop:
+ flags = LEFT_OPERAND_REQUIRED|RIGHT_OPERAND_REQUIRED;
+ rprio = lprio + 1;
+
maybe_reduce:
/* Push an operator, and check if we can reduce now. */
while (top->rprio > lprio)
@@ -1065,6 +1039,5 @@ cpp_parse_expr (pfile)
syntax_error:
if (stack != init_stack)
free (stack);
- skip_rest_of_line (pfile);
return 0;
}