diff options
author | zack <zack@138bc75d-0d04-0410-961f-82ee72b054a4> | 2000-07-19 20:18:08 +0000 |
---|---|---|
committer | zack <zack@138bc75d-0d04-0410-961f-82ee72b054a4> | 2000-07-19 20:18:08 +0000 |
commit | 316744619de1b120399985e6b8f5ae475da07ed4 (patch) | |
tree | fb27fc4ef85133963af7127518d36e07b5e1d021 /gcc/cppinit.c | |
parent | 91d4291d407bed3bc47e9dca4af564a601e1c0b2 (diff) | |
download | gcc-316744619de1b120399985e6b8f5ae475da07ed4.tar.gz |
* cpplib.h (TTYPE_TABLE): Move CPP_MIN and CPP_MAX into block
of operators allowed in #if and having an _EQ variant. Add
CPP_MIN_EQ, CPP_MAX_EQ, and CPP_DEFINED.
(cpp_token flags): Add NAMED_OP.
(enum node_type): Add T_OPERATOR.
(struct cpp_hashnode): Add code slot to value union.
* cpphash.h (spec_nodes): Remove n_defined.
* cpplex.c (lex_line): Convert T_OPERATOR nodes to their proper types.
(spell_token, can_paste, maybe_paste_with_next): Handle named operators.
(is_macro_disabled): Tweak error messages.
* cpplib.c (get_define_node): Disallow all named operators as
macro names. Tweak error messages.
(_cpp_init_stacks): Don't set up spec_nodes->n_defined.
* cppinit.c (builtin_array): Add entries for the named operators.
* cppexp.c (lex): Check for CPP_DEFINED token.
(priority table): Add entries for CPP_MIN and CPP_MAX.
(_cpp_parse_expr): Handle CPP_MIN and CPP_MAX.
testsuite:
* gcc.dg/cpp/directiv.c, gcc.dg/cpp/macsyntx.c,
gcc.dg/cpp/undef1.c: Tweak error regexps.
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@35137 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'gcc/cppinit.c')
-rw-r--r-- | gcc/cppinit.c | 45 |
1 files changed, 37 insertions, 8 deletions
diff --git a/gcc/cppinit.c b/gcc/cppinit.c index a58f459b8ba..5f5c6201423 100644 --- a/gcc/cppinit.c +++ b/gcc/cppinit.c @@ -491,26 +491,33 @@ cpp_cleanup (pfile) /* This structure defines one built-in macro. A node of type TYPE will be entered in the macro hash table under the name NAME, with value - VALUE (if any). Two values are not compile time constants, so we tag + VALUE (if any). If TYPE is T_OPERATOR, the CODE field is used instead. + + Two values are not compile time constants, so we tag them in the FLAGS field instead: VERS value is the global version_string, quoted ULP value is the global user_label_prefix + + Also, macros with CPLUS set in the flags field are entered only for C++. */ struct builtin { const U_CHAR *name; const char *value; - unsigned short type; + unsigned char code; + unsigned char type; unsigned short flags; unsigned int len; }; -#define VERS 0x01 -#define ULP 0x02 - -#define B(n, t) { U n, 0, t, 0, sizeof n - 1 } -#define C(n, v) { U n, v, T_MACRO, 0, sizeof n - 1 } -#define X(n, f) { U n, 0, T_MACRO, f, sizeof n - 1 } +#define VERS 0x01 +#define ULP 0x02 +#define CPLUS 0x04 + +#define B(n, t) { U n, 0, 0, t, 0, sizeof n - 1 } +#define C(n, v) { U n, v, 0, T_MACRO, 0, sizeof n - 1 } +#define X(n, f) { U n, 0, 0, T_MACRO, f, sizeof n - 1 } +#define O(n, c, f) { U n, 0, c, T_OPERATOR, f, sizeof n - 1 } static const struct builtin builtin_array[] = { B("__TIME__", T_TIME), @@ -534,6 +541,23 @@ static const struct builtin builtin_array[] = #ifndef NO_BUILTIN_WCHAR_TYPE C("__WCHAR_TYPE__", WCHAR_TYPE), #endif + + /* Named operators known to the preprocessor. These cannot be #defined + and always have their stated meaning. They are treated like normal + string tokens except for the type code and the meaning. Most of them + are only for C++ (but see iso646.h). */ + O("defined", CPP_DEFINED, 0), + O("and", CPP_AND_AND, CPLUS), + O("and_eq", CPP_AND_EQ, CPLUS), + O("bitand", CPP_AND, CPLUS), + O("bitor", CPP_OR, CPLUS), + O("compl", CPP_COMPL, CPLUS), + O("not", CPP_NOT, CPLUS), + O("not_eq", CPP_NOT_EQ, CPLUS), + O("or", CPP_OR_OR, CPLUS), + O("or_eq", CPP_OR_EQ, CPLUS), + O("xor", CPP_XOR, CPLUS), + O("xor_eq", CPP_XOR_EQ, CPLUS), }; #undef B #undef C @@ -550,6 +574,9 @@ initialize_builtins (pfile) const struct builtin *b; for(b = builtin_array; b < builtin_array_end; b++) { + if (b->flags & CPLUS && ! CPP_OPTION (pfile, cplusplus)) + continue; + if (b->type == T_MACRO) { const char *val; @@ -578,6 +605,8 @@ initialize_builtins (pfile) { cpp_hashnode *hp = cpp_lookup (pfile, b->name, b->len); hp->type = b->type; + if (b->type == T_OPERATOR) + hp->value.code = b->code; } } } |