Commit cb97d97d by Neil Booth Committed by Neil Booth

c-lex.c (c_lex): Peek a token ahead for a string to concatenate...

	* c-lex.c (c_lex): Peek a token ahead for a string to concatenate,
	using combine_strings to do the concatenation.
	* c-parse.in: Replace uses of the string non-terminal with STRING.
	Don't attempt string concatenation.
	(OBJC_STRING): New terminal.
	(string): Remove non-terminal.
	(_yylex): Call combine_strings on function names.  Generate
	OBJC_STRING terminals; don't pass '@' on to yacc.
	* c-typeck.c (simple_asm_stmt): Don't concatenate strings here.
	(build_asm_stmt): Similarly.
cp:
	* parse.y: Replace uses of the string non-terminal with STRING.
	Don't perform string concatentaion here.
	(string): Remove non-terminal.
	* semantics.c (finish_asm_stmt): Don't concatenate strings here.

From-SVN: r47792
parent 18d6067b
2001-12-08 Neil Booth <neil@daikokuya.demon.co.uk>
* c-lex.c (c_lex): Peek a token ahead for a string to concatenate,
using combine_strings to do the concatenation.
* c-parse.in: Replace uses of the string non-terminal with STRING.
Don't attempt string concatenation.
(OBJC_STRING): New terminal.
(string): Remove non-terminal.
(_yylex): Call combine_strings on function names. Generate
OBJC_STRING terminals; don't pass '@' on to yacc.
* c-typeck.c (simple_asm_stmt): Don't concatenate strings here.
(build_asm_stmt): Similarly.
2001-12-08 Kaveh R. Ghazi <ghazi@caip.rutgers.edu> 2001-12-08 Kaveh R. Ghazi <ghazi@caip.rutgers.edu>
* rtlanal.c (get_jump_table_offset): Delete unused variable. * rtlanal.c (get_jump_table_offset): Delete unused variable.
......
...@@ -762,6 +762,7 @@ c_lex (value) ...@@ -762,6 +762,7 @@ c_lex (value)
tree *value; tree *value;
{ {
const cpp_token *tok; const cpp_token *tok;
enum cpp_ttype result;
retry: retry:
timevar_push (TV_CPP); timevar_push (TV_CPP);
...@@ -776,7 +777,9 @@ c_lex (value) ...@@ -776,7 +777,9 @@ c_lex (value)
lineno = src_lineno; lineno = src_lineno;
*value = NULL_TREE; *value = NULL_TREE;
switch (tok->type) result = tok->type;
switch (result)
{ {
case CPP_OPEN_BRACE: indent_level++; break; case CPP_OPEN_BRACE: indent_level++; break;
case CPP_CLOSE_BRACE: indent_level--; break; case CPP_CLOSE_BRACE: indent_level--; break;
...@@ -804,8 +807,48 @@ c_lex (value) ...@@ -804,8 +807,48 @@ c_lex (value)
case CPP_STRING: case CPP_STRING:
case CPP_WSTRING: case CPP_WSTRING:
*value = lex_string ((const char *)tok->val.str.text, {
tok->val.str.len, tok->type == CPP_WSTRING); tree full_str = NULL_TREE;
do
{
/* Translate escape sequences in this string, then append it. */
tree str = lex_string ((const char *) tok->val.str.text,
tok->val.str.len,
tok->type == CPP_WSTRING);
if (full_str && c_language == clk_c && warn_traditional
&& !in_system_header)
{
static int last_lineno;
static const char *last_input_filename;
if (lineno != last_lineno || !last_input_filename
|| strcmp (last_input_filename, input_filename))
{
warning ("traditional C rejects string concatenation");
last_lineno = lineno;
last_input_filename = input_filename;
}
}
full_str = chainon (full_str, str);
/* Wide and non-wide give a wide result. */
if (tok->type == CPP_WSTRING)
result = CPP_WSTRING;
/* Look ahead for another string token. */
do
tok = cpp_get_token (parse_in);
while (tok->type == CPP_PADDING);
}
while (tok->type == CPP_STRING || tok->type == CPP_WSTRING);
_cpp_backup_tokens (parse_in, 1);
*value = combine_strings (full_str);
}
break; break;
/* These tokens should not be visible outside cpplib. */ /* These tokens should not be visible outside cpplib. */
...@@ -817,7 +860,7 @@ c_lex (value) ...@@ -817,7 +860,7 @@ c_lex (value)
default: break; default: break;
} }
return tok->type; return result;
} }
#define ERROR(msgid) do { error(msgid); goto syntax_error; } while(0) #define ERROR(msgid) do { error(msgid); goto syntax_error; } while(0)
......
...@@ -99,9 +99,8 @@ end ifobjc ...@@ -99,9 +99,8 @@ end ifobjc
yylval is the node for the constant. */ yylval is the node for the constant. */
%token CONSTANT %token CONSTANT
/* String constants in raw form. /* String constants as arrays of the appropriate character type. */
yylval is a STRING_CST node. */ %token STRING OBJC_STRING
%token STRING
/* "...", used for functions with variable arglists. */ /* "...", used for functions with variable arglists. */
%token ELLIPSIS %token ELLIPSIS
...@@ -151,7 +150,7 @@ end ifobjc ...@@ -151,7 +150,7 @@ end ifobjc
%type <ttype> BREAK CONTINUE RETURN GOTO ASM_KEYWORD SIZEOF TYPEOF ALIGNOF %type <ttype> BREAK CONTINUE RETURN GOTO ASM_KEYWORD SIZEOF TYPEOF ALIGNOF
%type <ttype> identifier IDENTIFIER TYPENAME CONSTANT expr nonnull_exprlist exprlist %type <ttype> identifier IDENTIFIER TYPENAME CONSTANT expr nonnull_exprlist exprlist
%type <ttype> expr_no_commas cast_expr unary_expr primary string STRING %type <ttype> expr_no_commas cast_expr unary_expr primary STRING
%type <ttype> declspecs_nosc_nots_nosa_noea declspecs_nosc_nots_nosa_ea %type <ttype> declspecs_nosc_nots_nosa_noea declspecs_nosc_nots_nosa_ea
%type <ttype> declspecs_nosc_nots_sa_noea declspecs_nosc_nots_sa_ea %type <ttype> declspecs_nosc_nots_sa_noea declspecs_nosc_nots_sa_ea
%type <ttype> declspecs_nosc_ts_nosa_noea declspecs_nosc_ts_nosa_ea %type <ttype> declspecs_nosc_ts_nosa_noea declspecs_nosc_ts_nosa_ea
...@@ -204,6 +203,8 @@ end ifobjc ...@@ -204,6 +203,8 @@ end ifobjc
%type <lineno> save_lineno %type <lineno> save_lineno
ifobjc ifobjc
%token OBJC_STRING
/* the Objective-C nonterminals */ /* the Objective-C nonterminals */
%type <ttype> ivar_decl_list ivar_decls ivar_decl ivars ivar_declarator %type <ttype> ivar_decl_list ivar_decls ivar_decl ivars ivar_declarator
...@@ -214,7 +215,7 @@ ifobjc ...@@ -214,7 +215,7 @@ ifobjc
%type <ttype> selectorarg keywordnamelist keywordname objcencodeexpr %type <ttype> selectorarg keywordnamelist keywordname objcencodeexpr
%type <ttype> objc_string non_empty_protocolrefs protocolrefs identifier_list objcprotocolexpr %type <ttype> objc_string non_empty_protocolrefs protocolrefs identifier_list objcprotocolexpr
%type <ttype> CLASSNAME OBJECTNAME %type <ttype> CLASSNAME OBJECTNAME OBJC_STRING
end ifobjc end ifobjc
%{ %{
...@@ -618,8 +619,8 @@ primary: ...@@ -618,8 +619,8 @@ primary:
$$ = build_external_ref ($1, yychar == '('); $$ = build_external_ref ($1, yychar == '(');
} }
| CONSTANT | CONSTANT
| string | STRING
{ $$ = combine_strings ($1); } { $$ = $1; }
| VAR_FUNC_NAME | VAR_FUNC_NAME
{ $$ = fname_decl (C_RID_CODE ($$), $$); } { $$ = fname_decl (C_RID_CODE ($$), $$); }
| '(' typename ')' '{' | '(' typename ')' '{'
...@@ -709,37 +710,13 @@ ifobjc ...@@ -709,37 +710,13 @@ ifobjc
end ifobjc end ifobjc
; ;
/* Produces a STRING_CST with perhaps more STRING_CSTs chained onto it. */
string:
STRING
| string STRING
{
ifc
static int last_lineno = 0;
static const char *last_input_filename = 0;
end ifc
$$ = chainon ($1, $2);
ifc
if (warn_traditional && !in_system_header
&& (lineno != last_lineno || !last_input_filename ||
strcmp (last_input_filename, input_filename)))
{
warning ("traditional C rejects string concatenation");
last_lineno = lineno;
last_input_filename = input_filename;
}
end ifc
}
;
ifobjc ifobjc
/* Produces an STRING_CST with perhaps more STRING_CSTs chained /* Chains ObjC string objects together. */
onto it, which is to be read as an ObjC string object. */
objc_string: objc_string:
'@' STRING OBJC_STRING
{ $$ = $2; } { $$ = $1; }
| objc_string '@' STRING | objc_string OBJC_STRING
{ $$ = chainon ($1, $3); } { $$ = chainon ($1, $2); }
; ;
end ifobjc end ifobjc
...@@ -1372,10 +1349,8 @@ notype_initdecls: ...@@ -1372,10 +1349,8 @@ notype_initdecls:
maybeasm: maybeasm:
/* empty */ /* empty */
{ $$ = NULL_TREE; } { $$ = NULL_TREE; }
| ASM_KEYWORD '(' string ')' | ASM_KEYWORD '(' STRING ')'
{ if (TREE_CHAIN ($3)) $3 = combine_strings ($3); { $$ = $3; }
$$ = $3;
}
; ;
initdcl: initdcl:
...@@ -2433,10 +2408,10 @@ asm_operand: ...@@ -2433,10 +2408,10 @@ asm_operand:
; ;
asm_clobbers: asm_clobbers:
string STRING
{ $$ = tree_cons (NULL_TREE, combine_strings ($1), NULL_TREE); } { $$ = tree_cons (NULL_TREE, $1, NULL_TREE); }
| asm_clobbers ',' string | asm_clobbers ',' STRING
{ $$ = tree_cons (NULL_TREE, combine_strings ($3), $1); } { $$ = tree_cons (NULL_TREE, $3, $1); }
; ;
/* This is what appears inside the parens in a function declarator. /* This is what appears inside the parens in a function declarator.
...@@ -3578,7 +3553,8 @@ end ifobjc ...@@ -3578,7 +3553,8 @@ end ifobjc
to string constants. */ to string constants. */
const char *name = fname_string (rid_code); const char *name = fname_string (rid_code);
yylval.ttype = build_string (strlen (name) + 1, name); yylval.ttype
= combine_strings (build_string (strlen (name) + 1, name));
last_token = CPP_STRING; /* so yyerror won't choke */ last_token = CPP_STRING; /* so yyerror won't choke */
return STRING; return STRING;
} }
...@@ -3695,23 +3671,16 @@ _yylex () ...@@ -3695,23 +3671,16 @@ _yylex ()
special significance. */ special significance. */
case CPP_ATSIGN: case CPP_ATSIGN:
ifobjc ifobjc
{ last_token = c_lex (&yylval.ttype);
tree after_at;
enum cpp_ttype after_at_type;
after_at_type = c_lex (&after_at); if (last_token == CPP_NAME
&& C_IS_RESERVED_WORD (yylval.ttype)
&& OBJC_IS_AT_KEYWORD (C_RID_CODE (yylval.ttype)))
return rid_to_yy [(int) C_RID_CODE (yylval.ttype)];
else if (last_token == CPP_STRING || last_token == CPP_WSTRING)
return OBJC_STRING;
if (after_at_type == CPP_NAME /* Fall through... */
&& C_IS_RESERVED_WORD (after_at)
&& OBJC_IS_AT_KEYWORD (C_RID_CODE (after_at)))
{
yylval.ttype = after_at;
last_token = after_at_type;
return rid_to_yy [(int) C_RID_CODE (after_at)];
}
_cpp_backup_tokens (parse_in, 1);
return '@';
}
end ifobjc end ifobjc
/* These tokens are C++ specific (and will not be generated /* These tokens are C++ specific (and will not be generated
......
...@@ -6832,8 +6832,6 @@ simple_asm_stmt (expr) ...@@ -6832,8 +6832,6 @@ simple_asm_stmt (expr)
{ {
tree stmt; tree stmt;
if (TREE_CHAIN (expr))
expr = combine_strings (expr);
stmt = add_stmt (build_stmt (ASM_STMT, NULL_TREE, expr, stmt = add_stmt (build_stmt (ASM_STMT, NULL_TREE, expr,
NULL_TREE, NULL_TREE, NULL_TREE, NULL_TREE,
NULL_TREE)); NULL_TREE));
...@@ -6858,8 +6856,6 @@ build_asm_stmt (cv_qualifier, string, outputs, inputs, clobbers) ...@@ -6858,8 +6856,6 @@ build_asm_stmt (cv_qualifier, string, outputs, inputs, clobbers)
{ {
tree tail; tree tail;
if (TREE_CHAIN (string))
string = combine_strings (string);
if (TREE_CODE (string) != STRING_CST) if (TREE_CODE (string) != STRING_CST)
{ {
error ("asm template is not a string constant"); error ("asm template is not a string constant");
......
2001-12-08 Neil Booth <neil@daikokuya.demon.co.uk>
* parse.y: Replace uses of the string non-terminal with STRING.
Don't perform string concatentaion here.
(string): Remove non-terminal.
* semantics.c (finish_asm_stmt): Don't concatenate strings here.
2001-12-05 Jason Merrill <jason@redhat.com> 2001-12-05 Jason Merrill <jason@redhat.com>
* cp-lang.c (LANG_HOOKS_TREE_INLINING_START_INLINING): Define. * cp-lang.c (LANG_HOOKS_TREE_INLINING_START_INLINING): Define.
......
...@@ -259,8 +259,7 @@ cp_parse_init () ...@@ -259,8 +259,7 @@ cp_parse_init ()
yylval contains an IDENTIFIER_NODE which indicates which one. */ yylval contains an IDENTIFIER_NODE which indicates which one. */
%token VAR_FUNC_NAME %token VAR_FUNC_NAME
/* String constants in raw form. /* String constants as arrays of a suitable type. */
yylval is a STRING_CST node. */
%token STRING %token STRING
/* "...", used for functions with variable arglists. */ /* "...", used for functions with variable arglists. */
...@@ -329,7 +328,7 @@ cp_parse_init () ...@@ -329,7 +328,7 @@ cp_parse_init ()
%type <ttype> PFUNCNAME maybe_identifier %type <ttype> PFUNCNAME maybe_identifier
%type <ttype> paren_expr_or_null nontrivial_exprlist SELFNAME %type <ttype> paren_expr_or_null nontrivial_exprlist SELFNAME
%type <ttype> expr_no_commas expr_no_comma_rangle %type <ttype> expr_no_commas expr_no_comma_rangle
%type <ttype> cast_expr unary_expr primary string STRING %type <ttype> cast_expr unary_expr primary STRING
%type <ttype> reserved_declspecs boolean.literal %type <ttype> reserved_declspecs boolean.literal
%type <ttype> reserved_typespecquals %type <ttype> reserved_typespecquals
%type <ttype> SCSPEC TYPESPEC CV_QUALIFIER maybe_cv_qualifier %type <ttype> SCSPEC TYPESPEC CV_QUALIFIER maybe_cv_qualifier
...@@ -497,9 +496,8 @@ extdef: ...@@ -497,9 +496,8 @@ extdef:
{ do_pending_inlines (); } { do_pending_inlines (); }
| template_def | template_def
{ do_pending_inlines (); } { do_pending_inlines (); }
| asm_keyword '(' string ')' ';' | asm_keyword '(' STRING ')' ';'
{ if (TREE_CHAIN ($3)) $3 = combine_strings ($3); { assemble_asm ($3); }
assemble_asm ($3); }
| extern_lang_string '{' extdefs_opt '}' | extern_lang_string '{' extdefs_opt '}'
{ pop_lang_context (); } { pop_lang_context (); }
| extern_lang_string .hush_warning fndef .warning_ok eat_saved_input | extern_lang_string .hush_warning fndef .warning_ok eat_saved_input
...@@ -1547,9 +1545,8 @@ primary: ...@@ -1547,9 +1545,8 @@ primary:
} }
| CONSTANT | CONSTANT
| boolean.literal | boolean.literal
| string | STRING
{ {
$$ = combine_strings ($$);
/* combine_strings doesn't set up TYPE_MAIN_VARIANT of /* combine_strings doesn't set up TYPE_MAIN_VARIANT of
a const array the way we want, so fix it. */ a const array the way we want, so fix it. */
if (flag_const_strings) if (flag_const_strings)
...@@ -1751,13 +1748,6 @@ boolean.literal: ...@@ -1751,13 +1748,6 @@ boolean.literal:
{ $$ = boolean_false_node; } { $$ = boolean_false_node; }
; ;
/* Produces a STRING_CST with perhaps more STRING_CSTs chained onto it. */
string:
STRING
| string STRING
{ $$ = chainon ($$, $2); }
;
nodecls: nodecls:
/* empty */ /* empty */
{ {
...@@ -2041,8 +2031,8 @@ nomods_initdecls: ...@@ -2041,8 +2031,8 @@ nomods_initdecls:
maybeasm: maybeasm:
/* empty */ /* empty */
{ $$ = NULL_TREE; } { $$ = NULL_TREE; }
| asm_keyword '(' string ')' | asm_keyword '(' STRING ')'
{ if (TREE_CHAIN ($3)) $3 = combine_strings ($3); $$ = $3; } { $$ = $3; }
; ;
initdcl: initdcl:
...@@ -3439,27 +3429,27 @@ simple_stmt: ...@@ -3439,27 +3429,27 @@ simple_stmt:
{ $$ = finish_return_stmt (NULL_TREE); } { $$ = finish_return_stmt (NULL_TREE); }
| RETURN_KEYWORD expr ';' | RETURN_KEYWORD expr ';'
{ $$ = finish_return_stmt ($2); } { $$ = finish_return_stmt ($2); }
| asm_keyword maybe_cv_qualifier '(' string ')' ';' | asm_keyword maybe_cv_qualifier '(' STRING ')' ';'
{ $$ = finish_asm_stmt ($2, $4, NULL_TREE, NULL_TREE, { $$ = finish_asm_stmt ($2, $4, NULL_TREE, NULL_TREE,
NULL_TREE); NULL_TREE);
ASM_INPUT_P ($$) = 1; } ASM_INPUT_P ($$) = 1; }
/* This is the case with just output operands. */ /* This is the case with just output operands. */
| asm_keyword maybe_cv_qualifier '(' string ':' asm_operands ')' ';' | asm_keyword maybe_cv_qualifier '(' STRING ':' asm_operands ')' ';'
{ $$ = finish_asm_stmt ($2, $4, $6, NULL_TREE, NULL_TREE); } { $$ = finish_asm_stmt ($2, $4, $6, NULL_TREE, NULL_TREE); }
/* This is the case with input operands as well. */ /* This is the case with input operands as well. */
| asm_keyword maybe_cv_qualifier '(' string ':' asm_operands ':' | asm_keyword maybe_cv_qualifier '(' STRING ':' asm_operands ':'
asm_operands ')' ';' asm_operands ')' ';'
{ $$ = finish_asm_stmt ($2, $4, $6, $8, NULL_TREE); } { $$ = finish_asm_stmt ($2, $4, $6, $8, NULL_TREE); }
| asm_keyword maybe_cv_qualifier '(' string SCOPE asm_operands ')' ';' | asm_keyword maybe_cv_qualifier '(' STRING SCOPE asm_operands ')' ';'
{ $$ = finish_asm_stmt ($2, $4, NULL_TREE, $6, NULL_TREE); } { $$ = finish_asm_stmt ($2, $4, NULL_TREE, $6, NULL_TREE); }
/* This is the case with clobbered registers as well. */ /* This is the case with clobbered registers as well. */
| asm_keyword maybe_cv_qualifier '(' string ':' asm_operands ':' | asm_keyword maybe_cv_qualifier '(' STRING ':' asm_operands ':'
asm_operands ':' asm_clobbers ')' ';' asm_operands ':' asm_clobbers ')' ';'
{ $$ = finish_asm_stmt ($2, $4, $6, $8, $10); } { $$ = finish_asm_stmt ($2, $4, $6, $8, $10); }
| asm_keyword maybe_cv_qualifier '(' string SCOPE asm_operands ':' | asm_keyword maybe_cv_qualifier '(' STRING SCOPE asm_operands ':'
asm_clobbers ')' ';' asm_clobbers ')' ';'
{ $$ = finish_asm_stmt ($2, $4, NULL_TREE, $6, $8); } { $$ = finish_asm_stmt ($2, $4, NULL_TREE, $6, $8); }
| asm_keyword maybe_cv_qualifier '(' string ':' asm_operands SCOPE | asm_keyword maybe_cv_qualifier '(' STRING ':' asm_operands SCOPE
asm_clobbers ')' ';' asm_clobbers ')' ';'
{ $$ = finish_asm_stmt ($2, $4, $6, NULL_TREE, $8); } { $$ = finish_asm_stmt ($2, $4, $6, NULL_TREE, $8); }
| GOTO '*' expr ';' | GOTO '*' expr ';'
...@@ -3614,10 +3604,10 @@ asm_operand: ...@@ -3614,10 +3604,10 @@ asm_operand:
; ;
asm_clobbers: asm_clobbers:
string STRING
{ $$ = tree_cons (NULL_TREE, combine_strings ($1), NULL_TREE);} { $$ = tree_cons (NULL_TREE, $1, NULL_TREE);}
| asm_clobbers ',' string | asm_clobbers ',' STRING
{ $$ = tree_cons (NULL_TREE, combine_strings ($3), $1); } { $$ = tree_cons (NULL_TREE, $3, $1); }
; ;
/* This is what appears inside the parens in a function declarator. /* This is what appears inside the parens in a function declarator.
......
...@@ -883,9 +883,6 @@ finish_asm_stmt (cv_qualifier, string, output_operands, ...@@ -883,9 +883,6 @@ finish_asm_stmt (cv_qualifier, string, output_operands,
tree r; tree r;
tree t; tree t;
if (TREE_CHAIN (string))
string = combine_strings (string);
if (cv_qualifier != NULL_TREE if (cv_qualifier != NULL_TREE
&& cv_qualifier != ridpointers[(int) RID_VOLATILE]) && cv_qualifier != ridpointers[(int) RID_VOLATILE])
{ {
......
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