cpplex.c (parse_name): Might have to glue a CPP_OTHER token before the name.

* cpplex.c (parse_name): Might have to glue a CPP_OTHER token
	before the name.
	(lex_line): Glue @ onto the beginning of identifiers and
	string constants, in Objective-C mode.
	(output_token, spell_token): Handle CPP_OSTRING.
	(can_paste, maybe_paste_with_next): Handle pasting @ onto the
	beginning of a NAME or a STRING, in objc mode.

	* cpplib.c (get_define_node): Do not permit identifiers that
	begin with @ to be #defined.
	* cppmacro.c (CAN_PASTE_AFTER): Add CPP_OTHER.
	* cpplib.h (TTYPE_TABLE): Add CPP_OSTRING.

	* c-lang.c, objc/objc-act.c (build_objc_string): Delete.
	* c-tree.h (build_objc_string): Delete prototype.
	* objc/objc-tree.def: Delete OBJC_STRING_CST.
	* c-lex.c (yylex): Use build_string for all three kinds of strings.

	* gcc.dg/cpp/20000625-2.c: Don't expect a warning on line 4.

From-SVN: r35470
This commit is contained in:
Zack Weinberg 2000-08-04 01:30:06 +00:00
parent d31772ca70
commit ba89d661ac
13 changed files with 145 additions and 103 deletions

View File

@ -1,3 +1,25 @@
2000-08-03 Zack Weinberg <zack@wolery.cumb.org>
* cpplex.c (parse_name): Might have to glue a CPP_OTHER token
before the name.
(lex_line): Glue @ onto the beginning of identifiers and
string constants, in Objective-C mode.
(output_token, spell_token): Handle CPP_OSTRING.
(can_paste, maybe_paste_with_next): Handle pasting @ onto the
beginning of a NAME or a STRING, in objc mode.
* cpplib.c (get_define_node): Do not permit identifiers that
begin with @ to be #defined.
* cppmacro.c (CAN_PASTE_AFTER): Add CPP_OTHER.
* cpplib.h (TTYPE_TABLE): Add CPP_OSTRING.
* c-lang.c, objc/objc-act.c (build_objc_string): Delete.
* c-tree.h (build_objc_string): Delete prototype.
* objc/objc-tree.def: Delete OBJC_STRING_CST.
* c-lex.c (yylex): Use build_string for all three kinds of strings.
* c-parse.in, objc/objc-act.c: Update commentary.
2000-08-03 Mark Mitchell <mark@codesourcery.com>
* extend.texi: Fix typo in last change.
@ -33,8 +55,8 @@ Thu Aug 3 10:05:53 2000 Akiko Matsushita <matusita@sra.co.jp>
2000-08-03 Michael Poole <poole@troilus.org>
* tm.texi (Register Classes): Clarify order of sub-initializers
in REG_CLASS_CONTENTS.
* tm.texi (Register Classes): Clarify order of sub-initializers
in REG_CLASS_CONTENTS.
Thu Aug 3 15:53:03 2000 J"orn Rennecke <amylaar@cygnus.co.uk>
@ -125,7 +147,7 @@ Wed Aug 2 15:59:34 MET DST 2000 Jan Hubicka <jh@suse.cz>
* cppmain.c (cb_define, cb_undef): Don't generate any output
if not done_initializing.
* cpplex.c (maybe_paste_with_next): When the token after a ##
* cpplex.c (maybe_paste_with_next): When the token after a ##
is an omitted rest argument, only delete the token before it
if that token is a comma. Do not warn about bogus token
pastes for , ## rest_arg.
@ -141,7 +163,7 @@ Wed Aug 2 15:59:34 MET DST 2000 Jan Hubicka <jh@suse.cz>
* config/i386/beos-elf.h (INCLUDE_DEFAULTS): Add additional
Be directories to search path.
Remove support for __declspec(dllimport) and __declspec(dllexport).
This is leftover cruft from the earlier BeOS gcc port when BeOS
used Microsoft's PE object file format.
@ -159,15 +181,15 @@ Wed Aug 2 15:59:34 MET DST 2000 Jan Hubicka <jh@suse.cz>
(ASM_OUTPUT_ALIGNED_DECL_COMMON): Remove.
(ASM_OUTPUT_ALIGNED_LOCAL): Remove.
(STRIP_NAME_ENCODING): Remove.
Remove support for obsolete version of BeOS that is no longer
supported by Be.
* configure.in (i*86-*-beospe*): Remove.
* config/i386/beos-pe.h: Remove.
2000-08-01 Jeffrey Oldham <oldham@codesourcery.com>
Mark Mitchell <mark@codesourcery.com>
Mark Mitchell <mark@codesourcery.com>
* Makefile.in (OBJS): Added dce.o.
(ssa.o): Updated target to include ssa.h.
(flow.o): Likewise.
@ -176,7 +198,7 @@ Wed Aug 2 15:59:34 MET DST 2000 Jan Hubicka <jh@suse.cz>
* basic-block.h: Added comments.
(INVALID_BLOCK): Added definition.
(connect_infinite_loops_to_exit): Added declaration.
Moved SSA declarations to ssa.h.
Moved SSA declarations to ssa.h.
* flow.c: Added inclusion of ssa.h.
(struct depth_first_search_dsS, depth_first_search_ds):
Added definitions.
@ -205,9 +227,9 @@ Wed Aug 2 15:59:34 MET DST 2000 Jan Hubicka <jh@suse.cz>
Defined flag_ssa.
(f_options): Added dce entry.
* invoke.texi: Document -fdce. Emphasize experimental status of
-fssa.
-fssa.
* dce: New file.
2000-08-01 Zack Weinberg <zack@wolery.cumb.org>
* cpperror.c (v_message): Split into _cpp_begin_message and
@ -619,7 +641,7 @@ Sun Jul 30 20:27:36 MET DST 2000 Jan Hubicka <jh@suse.cz>
Sun Jul 30 20:25:21 MET DST 2000 Jan Hubicka <jh@suse.cz>
* function.c (assign_stack_local_1, assign_stack_temp_for_type):
* function.c (assign_stack_local_1, assign_stack_temp_for_type):
Do not call gen_mode_alignment when mode is BLKmode.
Sun Jul 30 20:21:54 MET DST 2000 Jan Hubicka <jh@suse.cz>
@ -655,7 +677,7 @@ Sun Jul 30 20:08:37 MET DST 2000 Jan Hubicka <jh@suse.cz>
(c4x_valid_type_attribute_p): Likewise.
* config/c4x/c4x.h (FUNCTION_PROLOGUE, FUNCTION_EPILOGUE): Delete.
(FUNCTION_BLOCK_PROFILER_EXIT): Convert to emit RTL.
2000-07-30 Michael Hayes <m.hayes@elec.canterbury.ac.nz>
* config/c4x/c4x.c (c4x_emit_move_sequence): Use loadqi_big_constant
@ -672,7 +694,7 @@ Sun Jul 30 20:08:37 MET DST 2000 Jan Hubicka <jh@suse.cz>
* config/c4x/c4x.h (ASM_FORMAT_PRIVATE_NAME): Output $ in label.
2000-07-30 Michael Hayes <m.hayes@elec.canterbury.ac.nz>
* config/c4x/c4x.h (IS_XXX_REGNO): Rewrite to avoid unsigned warnings.
2000-07-30 Michael Hayes <m.hayes@elec.canterbury.ac.nz>
@ -699,7 +721,7 @@ Sun Jul 30 20:08:37 MET DST 2000 Jan Hubicka <jh@suse.cz>
(make_equivalent_phi_alternatives_equivalent): Likewise.
(for_each_successor_phi): Likewise.
(convert_from_ssa): Modify phi-node deletion algorithm.
2000-07-29 Andreas Jaeger <aj@suse.de>
* configure.in (mips*-*-linux*): Use mips*el to check for little
@ -771,7 +793,7 @@ Sun Jul 30 20:08:37 MET DST 2000 Jan Hubicka <jh@suse.cz>
(__do_global_ctors): Prototype.
* gcse.c (record_one_set, pre_delete): Remove unused variables.
* rs6000.c (rs6000_maybe_dead): Delete unused prototype.
(print_operand): Initialize variable `t'.
@ -791,7 +813,7 @@ Sun Jul 30 20:08:37 MET DST 2000 Jan Hubicka <jh@suse.cz>
(--with-included-gettext): Likewise.
(--enable-maintainer-mode): New description added.
* extend.texi (-fstrict-prototype): Add missing '.'.
2000-07-27 Jim Wilson <wilson@cygnus.com>
* dwarf2out.c (gen_decl_die): Don't call gen_abstract_function if
@ -860,7 +882,7 @@ Thu Jul 27 09:25:17 2000 Akiko Matsushita <matusita@sra.co.jp>
* pa/x-pa-hpux: Add -D_HIUX_SOURCE to FIXPROTO_DEFINES
for HI-UX/WE2 systems.
2000-07-24 Bruce Korb <bkorb@gnu.org>
* fixincl/fixfixes.c(emit_gnu_type): rewrote to *rely* on GCC
@ -873,9 +895,9 @@ Thu Jul 27 11:54:17 2000 Andrew Cagney <cagney@b1.cygnus.com>
* cpp.texi: Append a trailing full-stop to xrefs where needed.
2000-07-26 Dave Pitts <dpitts@cozx.com>
2000-07-26 Dave Pitts <dpitts@cozx.com>
* i370.c: Remove LONGEXTERNAL ifdef from alias_number. Added hash
* i370.c: Remove LONGEXTERNAL ifdef from alias_number. Added hash
routine constants.
(mvs_hash_alias): New function.
(mvs_add_alias): Change argument spacing.
@ -1037,7 +1059,7 @@ Tue Jul 25 23:08:33 2000 J"orn Rennecke <amylaar@cygnus.co.uk>
UNALIGNED_INT_ASM_OP.
(def_cfa_1): Don't emit def_cfa_register or def_cfa_offset to adjust
a location expression.
(dwarf2out_frame_debug_expr): Lose cfa_old_reg stuff. Don't
(dwarf2out_frame_debug_expr): Lose cfa_old_reg stuff. Don't
assume indirect access if we're saving the CFA address exactly.
* Makefile.in (bootstrap): Move -BstageN/ to the end.
@ -1074,9 +1096,9 @@ Mon Jul 24 02:04:52 2000 Jeffrey A Law (law@cygnus.com)
* c-semantics.c (make_rtl_for_local_static): Use TREE_ASM_WRITTEN
to figure out whether or not a variable has already been emitted.
Sun Jul 23 14:49:12 2000 Jason Eckhardt <jle@cygnus.com>
Sun Jul 23 14:49:12 2000 Jason Eckhardt <jle@cygnus.com>
* config/i860/i860.md (untyped_call expander): Use GEN_CALL
* config/i860/i860.md (untyped_call expander): Use GEN_CALL
instead of gen_call.
Sun Jul 23 11:52:03 2000 George Helffrich (george@gly.bris.ac.uk)

View File

@ -171,15 +171,6 @@ recognize_objc_keyword ()
return 0;
}
tree
build_objc_string (len, str)
int len ATTRIBUTE_UNUSED;
const char *str ATTRIBUTE_UNUSED;
{
abort ();
return NULL_TREE;
}
/* Used by c-typeck.c (build_external_ref), but only for objc. */
tree

View File

@ -2268,25 +2268,19 @@ yylex ()
/* We have read the entire constant.
Construct a STRING_CST for the result. */
yylval.ttype = build_string (p - (token_buffer + 1), token_buffer + 1);
if (wide_flag)
{
yylval.ttype = build_string (p - (token_buffer + 1),
token_buffer + 1);
TREE_TYPE (yylval.ttype) = wchar_array_type_node;
value = STRING;
}
else if (objc_flag)
{
/* Return an Objective-C @"..." constant string object. */
yylval.ttype = build_objc_string (p - (token_buffer + 1),
token_buffer + 1);
TREE_TYPE (yylval.ttype) = char_array_type_node;
value = OBJC_STRING;
}
else
{
yylval.ttype = build_string (p - (token_buffer + 1),
token_buffer + 1);
TREE_TYPE (yylval.ttype) = char_array_type_node;
value = STRING;
}

View File

@ -150,7 +150,7 @@ end ifc
%token CLASSNAME PUBLIC PRIVATE PROTECTED PROTOCOL OBJECTNAME CLASS ALIAS
/* Objective-C string constants in raw form.
yylval is an OBJC_STRING_CST node. */
yylval is an STRING_CST node. */
%token OBJC_STRING
@ -753,8 +753,8 @@ end ifc
;
ifobjc
/* Produces an OBJC_STRING_CST with perhaps more OBJC_STRING_CSTs chained
onto it. */
/* Produces an STRING_CST with perhaps more STRING_CSTs chained
onto it, which is to be read as an ObjC string object. */
objc_string:
OBJC_STRING
| objc_string OBJC_STRING

View File

@ -142,7 +142,6 @@ extern int maybe_objc_comptypes PARAMS ((tree, tree, int));
extern tree maybe_building_objc_message_expr PARAMS ((void));
extern tree maybe_objc_method_name PARAMS ((tree));
extern int recognize_objc_keyword PARAMS ((void));
extern tree build_objc_string PARAMS ((int, const char *));
extern tree lookup_objc_ivar PARAMS ((tree));
/* in c-parse.in */

View File

@ -1008,15 +1008,27 @@ parse_name (pfile, tok, cur, rlimit)
}
len = cur - name;
if (tok->val.node == 0)
if (tok->type == CPP_NAME && tok->val.node == 0)
tok->val.node = _cpp_lookup_with_hash (pfile, name, len, r);
else
{
unsigned int oldlen = tok->val.node->length;
U_CHAR *newname = alloca (oldlen + len);
memcpy (newname, tok->val.node->name, oldlen);
unsigned int oldlen;
U_CHAR *newname;
if (tok->type == CPP_NAME)
oldlen = tok->val.node->length;
else
oldlen = 1;
newname = alloca (oldlen + len);
if (tok->type == CPP_NAME)
memcpy (newname, tok->val.node->name, oldlen);
else
newname[0] = tok->val.aux;
memcpy (newname + oldlen, name, len);
tok->val.node = cpp_lookup (pfile, newname, len + oldlen);
tok->type = CPP_NAME;
}
return cur;
@ -1373,8 +1385,16 @@ lex_line (pfile, list)
case 'S': case 'T': case 'U': case 'V': case 'W': case 'X':
case 'Y': case 'Z':
cur--; /* Backup character. */
cur_token->val.node = 0;
cur_token->type = CPP_NAME; /* Identifier, macro etc. */
/* In Objective C, '@' may begin certain keywords. */
if (CPP_OPTION (pfile, objc) && cur_token[-1].type == CPP_OTHER
&& cur_token[-1].val.aux == '@' && IMMED_TOKEN ())
cur_token--;
else
{
cur_token->val.node = 0;
cur_token->type = CPP_NAME; /* Identifier, macro etc. */
}
continue_name:
cur = parse_name (pfile, cur_token, cur, buffer->rlimit);
@ -1394,12 +1414,21 @@ lex_line (pfile, list)
break;
case '\'':
case '\"':
cur_token->type = c == '\'' ? CPP_CHAR : CPP_STRING;
/* Do we have a wide string? */
cur_token->type = CPP_CHAR;
if (cur_token[-1].type == CPP_NAME && IMMED_TOKEN ()
&& cur_token[-1].val.node == pfile->spec_nodes->n_L)
BACKUP_TOKEN (c == '\'' ? CPP_WCHAR : CPP_WSTRING);
BACKUP_TOKEN (CPP_WCHAR);
goto do_parse_string;
case '\"':
cur_token->type = CPP_STRING;
if (cur_token[-1].type == CPP_NAME && IMMED_TOKEN ()
&& cur_token[-1].val.node == pfile->spec_nodes->n_L)
BACKUP_TOKEN (CPP_WSTRING);
else if (CPP_OPTION (pfile, objc)
&& cur_token[-1].type == CPP_OTHER && IMMED_TOKEN ()
&& cur_token[-1].val.aux == '@')
BACKUP_TOKEN (CPP_OSTRING);
do_parse_string:
/* Here c is one of ' " or >. */
@ -1883,20 +1912,21 @@ output_token (pfile, fp, token, prev, white)
case SPELL_STRING:
{
if (token->type == CPP_WSTRING || token->type == CPP_WCHAR)
putc ('L', fp);
if (token->type == CPP_STRING || token->type == CPP_WSTRING)
putc ('"', fp);
if (token->type == CPP_CHAR || token->type == CPP_WCHAR)
putc ('\'', fp);
int left, right, tag;
switch (token->type)
{
case CPP_STRING: left = '"'; right = '"'; tag = '\0'; break;
case CPP_WSTRING: left = '"'; right = '"'; tag = 'L'; break;
case CPP_OSTRING: left = '"'; right = '"'; tag = '@'; break;
case CPP_CHAR: left = '\''; right = '\''; tag = '\0'; break;
case CPP_WCHAR: left = '\''; right = '\''; tag = 'L'; break;
case CPP_HEADER_NAME: left = '<'; right = '>'; tag = '\0'; break;
default: left = '\0'; right = '\0'; tag = '\0'; break;
}
if (tag) putc (tag, fp);
if (left) putc (left, fp);
fwrite (token->val.str.text, 1, token->val.str.len, fp);
if (token->type == CPP_STRING || token->type == CPP_WSTRING)
putc ('"', fp);
if (token->type == CPP_CHAR || token->type == CPP_WCHAR)
putc ('\'', fp);
if (right) putc (right, fp);
}
break;
@ -1999,21 +2029,22 @@ spell_token (pfile, token, buffer)
case SPELL_STRING:
{
if (token->type == CPP_WSTRING || token->type == CPP_WCHAR)
*buffer++ = 'L';
if (token->type == CPP_STRING || token->type == CPP_WSTRING)
*buffer++ = '"';
if (token->type == CPP_CHAR || token->type == CPP_WCHAR)
*buffer++ = '\'';
int left, right, tag;
switch (token->type)
{
case CPP_STRING: left = '"'; right = '"'; tag = '\0'; break;
case CPP_WSTRING: left = '"'; right = '"'; tag = 'L'; break;
case CPP_OSTRING: left = '"'; right = '"'; tag = '@'; break;
case CPP_CHAR: left = '\''; right = '\''; tag = '\0'; break;
case CPP_WCHAR: left = '\''; right = '\''; tag = 'L'; break;
case CPP_HEADER_NAME: left = '<'; right = '>'; tag = '\0'; break;
default: left = '\0'; right = '\0'; tag = '\0'; break;
}
if (tag) *buffer++ = tag;
if (left) *buffer++ = left;
memcpy (buffer, token->val.str.text, token->val.str.len);
buffer += token->val.str.len;
if (token->type == CPP_STRING || token->type == CPP_WSTRING)
*buffer++ = '"';
if (token->type == CPP_CHAR || token->type == CPP_WCHAR)
*buffer++ = '\'';
if (right) *buffer++ = right;
}
break;
@ -2700,6 +2731,13 @@ can_paste (pfile, token1, token2, digraph)
return CPP_NUMBER;
break;
case CPP_OTHER:
if (CPP_OPTION (pfile, objc) && token1->val.aux == '@')
{
if (b == CPP_NAME) return CPP_NAME;
if (b == CPP_STRING) return CPP_OSTRING;
}
default:
break;
}
@ -2789,7 +2827,8 @@ maybe_paste_with_next (pfile, token)
pasted->val.str.len = end - buf;
}
}
else if (type == CPP_WCHAR || type == CPP_WSTRING)
else if (type == CPP_WCHAR || type == CPP_WSTRING
|| type == CPP_OSTRING)
pasted = duplicate_token (pfile, second);
else
{

View File

@ -242,6 +242,16 @@ get_define_node (pfile)
return 0;
}
/* In Objective C, some keywords begin with '@', but general identifiers
do not, and you're not allowed to #define them. */
if (token->val.node->name[0] == '@')
{
cpp_error_with_line (pfile, token->line, token->col,
"\"%s\" cannot be used as a macro name",
token->val.node->name);
return 0;
}
/* Check for poisoned identifiers now. */
if (token->val.node->type == T_POISON)
{

View File

@ -123,6 +123,7 @@ typedef struct cpp_hashnode cpp_hashnode;
\
TK(CPP_STRING, SPELL_STRING) /* "string" */ \
TK(CPP_WSTRING, SPELL_STRING) /* L"string" */ \
TK(CPP_OSTRING, SPELL_STRING) /* @"string" - Objective C */ \
TK(CPP_HEADER_NAME, SPELL_STRING) /* <stdio.h> in #include */ \
\
TK(CPP_COMMENT, SPELL_STRING) /* Only if output comments. */ \

View File

@ -55,12 +55,14 @@ static cpp_toklist * alloc_macro PARAMS ((cpp_reader *, struct macro_info *));
/* These are all the tokens that can have something pasted after them.
Comma is included in the list only to support the GNU varargs extension
(where you write a ## b and a disappears if b is an empty rest argument). */
(where you write a ## b and a disappears if b is an empty rest argument).
CPP_OTHER is included because of Objective C's use of '@'. */
#define CAN_PASTE_AFTER(type) \
((type) <= CPP_LAST_EQ || (type) == CPP_COLON || (type) == CPP_HASH \
|| (type) == CPP_DEREF || (type) == CPP_DOT || (type) == CPP_NAME \
|| (type) == CPP_INT || (type) == CPP_FLOAT || (type) == CPP_NUMBER \
|| (type) == CPP_MACRO_ARG || (type) == CPP_PLACEMARKER || (type) == CPP_COMMA)
|| (type) == CPP_MACRO_ARG || (type) == CPP_PLACEMARKER \
|| (type) == CPP_COMMA || (type) == CPP_OTHER)
/* Scans for a given token, returning the parameter number if found,
or 0 if not found. Scans from FIRST to TOKEN - 1 or the first

View File

@ -1410,22 +1410,7 @@ my_build_string (len, str)
return a_string;
}
/* Return a newly constructed OBJC_STRING_CST node whose value is
the LEN characters at STR.
The TREE_TYPE is not initialized. */
tree
build_objc_string (len, str)
int len;
const char *str;
{
tree s = build_string (len, str);
TREE_SET_CODE (s, OBJC_STRING_CST);
return s;
}
/* Given a chain of OBJC_STRING_CST's, build a static instance of
/* Given a chain of STRING_CST's, build a static instance of
NXConstanString which points at the concatenation of those strings.
We place the string object in the __string_objects section of the
__OBJC segment. The Objective-C runtime will initialize the isa
@ -1451,7 +1436,6 @@ build_objc_string_object (strings)
add_class_reference (constant_string_id);
/* Combine_strings will work for OBJC_STRING_CST's too. */
string = combine_strings (strings);
TREE_SET_CODE (string, STRING_CST);
length = TREE_STRING_LENGTH (string) - 1;

View File

@ -32,6 +32,3 @@ DEFTREECODE (PROTOCOL_INTERFACE_TYPE, "protocol_interface_type", 't', 0)
DEFTREECODE (KEYWORD_DECL, "keyword_decl", 'd', 0)
DEFTREECODE (INSTANCE_METHOD_DECL, "instance_method_decl", 'd', 0)
DEFTREECODE (CLASS_METHOD_DECL, "class_method_decl", 'd', 0)
/* Objective-C constants. */
DEFTREECODE (OBJC_STRING_CST, "objc_string_cst", 'c', 3)

View File

@ -1,3 +1,7 @@
2000-08-03 Zack Weinberg <zack@wolery.cumb.org>
* gcc.dg/cpp/20000625-2.c: Don't expect a warning on line 4.
Thu Aug 3 01:46:33 2000 Jeffrey A Law (law@cygnus.com)
* gcc.c-torture/compile/20000803-1.c: New test.

View File

@ -2,7 +2,6 @@
/* { dg-do run } */
#define symbol_version(name, version) name##@##version
/* { dg-warning "nothing can be pasted" "" { target *-*-* } 4 } */
#define str(x) xstr(x)
#define xstr(x) #x