Commit 71b7be38 by Zack Weinberg Committed by Zack Weinberg

stringpool.c (set_identifier): New function.

	* stringpool.c (set_identifier): New function.
	* tree.h: Prototype it.

	* c-parse.in: Kill D_YES. If compiled for objc, call
	save_and_forget_protocol_qualifiers from init_reswords.
	* objc/objc-act.c (remember_protocol_qualifiers,
	forget_protocol_qualifiers): Don't diddle C_IS_RESERVED_WORD.
	Swap out the non-keyword IDENTIFIER_NODEs for keyword ones, or
	vice versa.
	(save_and_forget_protocol_qualifiers): New function.
	* c-lex.h: Prototype save_and_forget_protocol_qualifiers.

From-SVN: r40170
parent 5aa709ad
2001-03-01 Zack Weinberg <zackw@stanford.edu>
* stringpool.c (set_identifier): New function.
* tree.h: Prototype it.
* c-parse.in: Kill D_YES. If compiled for objc, call
save_and_forget_protocol_qualifiers from init_reswords.
* objc/objc-act.c (remember_protocol_qualifiers,
forget_protocol_qualifiers): Don't diddle C_IS_RESERVED_WORD.
Swap out the non-keyword IDENTIFIER_NODEs for keyword ones, or
vice versa.
(save_and_forget_protocol_qualifiers): New function.
* c-lex.h: Prototype save_and_forget_protocol_qualifiers.
2001-03-01 Diego Novillo <dnovillo@redhat.com>
* c-semantics.c (prune_unused_decls): Return error_mark_node
......
......@@ -27,6 +27,7 @@ extern void position_after_white_space PARAMS ((void));
extern int c_lex PARAMS ((tree *));
extern const char *init_c_lex PARAMS ((const char *));
extern void save_and_forget_protocol_qualifiers PARAMS ((void));
extern void forget_protocol_qualifiers PARAMS ((void));
extern void remember_protocol_qualifiers PARAMS ((void));
extern tree is_class_name PARAMS ((tree));
......
......@@ -2878,7 +2878,6 @@ struct resword
#define D_EXT 0x04 /* GCC extension */
#define D_EXT89 0x08 /* GCC extension incorporated in C99 */
#define D_OBJC 0x10 /* Objective C only */
#define D_YES 0x20 /* always starts disabled */
static const struct resword reswords[] =
{
......@@ -2971,12 +2970,12 @@ ifobjc
{ "@public", RID_AT_PUBLIC, D_OBJC },
{ "@selector", RID_AT_SELECTOR, D_OBJC },
{ "id", RID_ID, D_OBJC },
{ "bycopy", RID_BYCOPY, D_OBJC|D_YES },
{ "byref", RID_BYREF, D_OBJC|D_YES },
{ "in", RID_IN, D_OBJC|D_YES },
{ "inout", RID_INOUT, D_OBJC|D_YES },
{ "oneway", RID_ONEWAY, D_OBJC|D_YES },
{ "out", RID_OUT, D_OBJC|D_YES },
{ "bycopy", RID_BYCOPY, D_OBJC },
{ "byref", RID_BYREF, D_OBJC },
{ "in", RID_IN, D_OBJC },
{ "inout", RID_INOUT, D_OBJC },
{ "oneway", RID_ONEWAY, D_OBJC },
{ "out", RID_OUT, D_OBJC },
end ifobjc
};
#define N_reswords (sizeof reswords / sizeof (struct resword))
......@@ -3138,14 +3137,12 @@ init_reswords ()
id = get_identifier (reswords[i].word);
C_RID_CODE (id) = reswords[i].rid;
C_IS_RESERVED_WORD (id) = 1;
ridpointers [(int) reswords[i].rid] = id;
/* Objective C does tricky things with enabling and disabling
keywords. So these we must not elide in the test above, but
wait and not mark them reserved now. */
if (! (reswords[i].disable & D_YES))
C_IS_RESERVED_WORD (id) = 1;
}
ifobjc
save_and_forget_protocol_qualifiers ();
end ifobjc
}
const char *
......
......@@ -8590,25 +8590,45 @@ lookup_objc_ivar (id)
return 0;
}
/* Parser callbacks. */
/* Parser callbacks.
Some ObjC keywords are reserved only in a particular context:
in out inout bycopy byref oneway.
We have to save and restore the IDENTIFIER_NODEs that describe
them as keywords, when appropriate. */
#define N_PQ 6
static tree saved_pq[N_PQ];
static tree saved_not_pq[N_PQ];
static const char *const pq_strings[N_PQ] = {
"bycopy", "byref", "in", "inout", "oneway", "out"
};
void
save_and_forget_protocol_qualifiers ()
{
int i;
for (i = 0; i < N_PQ; i++)
saved_pq[i] = set_identifier (pq_strings[i], NULL_TREE);
ggc_add_tree_root (saved_pq, N_PQ);
ggc_add_tree_root (saved_not_pq, N_PQ);
}
void
forget_protocol_qualifiers ()
{
C_IS_RESERVED_WORD (ridpointers[(int) RID_IN]) = 0;
C_IS_RESERVED_WORD (ridpointers[(int) RID_OUT]) = 0;
C_IS_RESERVED_WORD (ridpointers[(int) RID_INOUT]) = 0;
C_IS_RESERVED_WORD (ridpointers[(int) RID_BYCOPY]) = 0;
C_IS_RESERVED_WORD (ridpointers[(int) RID_BYREF]) = 0;
C_IS_RESERVED_WORD (ridpointers[(int) RID_ONEWAY]) = 0;
int i;
for (i = 0; i < N_PQ; i++)
{
set_identifier (pq_strings[i], saved_not_pq[i]);
saved_not_pq[i] = NULL_TREE;
}
}
void
remember_protocol_qualifiers ()
{
C_IS_RESERVED_WORD (ridpointers[(int) RID_IN]) = 1;
C_IS_RESERVED_WORD (ridpointers[(int) RID_OUT]) = 1;
C_IS_RESERVED_WORD (ridpointers[(int) RID_INOUT]) = 1;
C_IS_RESERVED_WORD (ridpointers[(int) RID_BYCOPY]) = 1;
C_IS_RESERVED_WORD (ridpointers[(int) RID_BYREF]) = 1;
C_IS_RESERVED_WORD (ridpointers[(int) RID_ONEWAY]) = 1;
int i;
for (i = 0; i < N_PQ; i++)
saved_not_pq[i] = set_identifier (pq_strings[i], saved_pq[i]);
}
......@@ -340,6 +340,25 @@ maybe_get_identifier (text)
return NULL_TREE;
}
/* Look up an identifier with the name TEXT, replace its identifier
node with NODE, and return the old identifier node. This is used
by languages which need to enable and disable keywords based on
context; e.g. see remember_protocol_qualifiers in objc/objc-act.c. */
tree
set_identifier (text, node)
const char *text;
tree node;
{
struct str_header *str;
tree old;
size_t length = strlen (text);
str = alloc_string (text, length, INSERT);
old = str->data; /* might be null */
str->data = node;
return old;
}
/* Report some basic statistics about the string pool. */
void
......
......@@ -1922,6 +1922,13 @@ extern tree get_identifier PARAMS ((const char *));
extern tree maybe_get_identifier PARAMS ((const char *));
/* Look up an identifier with the name TEXT, replace its identifier
node with NODE, and return the old identifier node. This is used
by languages which need to enable and disable keywords based on
context; e.g. see remember_protocol_qualifiers in objc/objc-act.c. */
extern tree set_identifier PARAMS ((const char *, tree));
/* Construct various types of nodes. */
#define build_int_2(LO,HI) \
......
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