aboutsummaryrefslogtreecommitdiff
path: root/gcc/cppinit.c
diff options
context:
space:
mode:
authorZack Weinberg <zack@gcc.gnu.org>2000-07-19 20:18:08 +0000
committerZack Weinberg <zack@gcc.gnu.org>2000-07-19 20:18:08 +0000
commit92936ecf1a27517ac0b96c5af6a5ae9664faf3f3 (patch)
treefb27fc4ef85133963af7127518d36e07b5e1d021 /gcc/cppinit.c
parentb86db3ebc22f22aae3f7dddadc90c9b1841ebe1a (diff)
downloadgcc-92936ecf1a27517ac0b96c5af6a5ae9664faf3f3.zip
gcc-92936ecf1a27517ac0b96c5af6a5ae9664faf3f3.tar.gz
gcc-92936ecf1a27517ac0b96c5af6a5ae9664faf3f3.tar.bz2
cpplib.h (TTYPE_TABLE): Move CPP_MIN and CPP_MAX into block of operators allowed in #if...
* 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. From-SVN: r35137
Diffstat (limited to 'gcc/cppinit.c')
-rw-r--r--gcc/cppinit.c45
1 files changed, 37 insertions, 8 deletions
diff --git a/gcc/cppinit.c b/gcc/cppinit.c
index a58f459..5f5c620 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;
}
}
}