diff options
author | Neil Booth <neil@daikokuya.demon.co.uk> | 2001-12-10 20:08:59 +0000 |
---|---|---|
committer | Neil Booth <neil@gcc.gnu.org> | 2001-12-10 20:08:59 +0000 |
commit | a23c9413df6f956abfda9d7e73e70a7109ae7be7 (patch) | |
tree | 388abb74ae9bdd4ee8004d380c37d8256154a4ec | |
parent | d01f3474229a6b3b89085ff009ba85515c95b285 (diff) | |
download | gcc-a23c9413df6f956abfda9d7e73e70a7109ae7be7.zip gcc-a23c9413df6f956abfda9d7e73e70a7109ae7be7.tar.gz gcc-a23c9413df6f956abfda9d7e73e70a7109ae7be7.tar.bz2 |
c-lex.c, [...]: Revert concatenation changes.
* c-lex.c, c-parse.in, c-typeck.c: Revert concatenation changes.
cp:
* parse.y, semantics.c: Similarly.
From-SVN: r47848
-rw-r--r-- | gcc/ChangeLog | 4 | ||||
-rw-r--r-- | gcc/c-lex.c | 51 | ||||
-rw-r--r-- | gcc/c-parse.in | 107 | ||||
-rw-r--r-- | gcc/c-typeck.c | 37 | ||||
-rw-r--r-- | gcc/cp/ChangeLog | 4 | ||||
-rw-r--r-- | gcc/cp/parse.y | 46 | ||||
-rw-r--r-- | gcc/cp/semantics.c | 3 |
7 files changed, 144 insertions, 108 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 41ae902..d13270b 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,7 @@ +2001-12-10 Neil Booth <neil@daikokuya.demon.co.uk> + + * c-lex.c, c-parse.in, c-typeck.c: Revert concatenation changes. + Mon Dec 10 09:19:11 2001 Richard Kenner <kenner@vlsi1.ultra.nyu.edu> * config/i386/i386.md (leave, leave_rex64): Adjust pattern to match diff --git a/gcc/c-lex.c b/gcc/c-lex.c index 84d64f1..e70be70 100644 --- a/gcc/c-lex.c +++ b/gcc/c-lex.c @@ -762,7 +762,6 @@ c_lex (value) tree *value; { const cpp_token *tok; - enum cpp_ttype result; retry: timevar_push (TV_CPP); @@ -777,9 +776,7 @@ c_lex (value) lineno = src_lineno; *value = NULL_TREE; - result = tok->type; - - switch (result) + switch (tok->type) { case CPP_OPEN_BRACE: indent_level++; break; case CPP_CLOSE_BRACE: indent_level--; break; @@ -807,48 +804,8 @@ c_lex (value) case CPP_STRING: case 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); - } + *value = lex_string ((const char *)tok->val.str.text, + tok->val.str.len, tok->type == CPP_WSTRING); break; /* These tokens should not be visible outside cpplib. */ @@ -860,7 +817,7 @@ c_lex (value) default: break; } - return result; + return tok->type; } #define ERROR(msgid) do { error(msgid); goto syntax_error; } while(0) diff --git a/gcc/c-parse.in b/gcc/c-parse.in index 84d1c02..1602b92 100644 --- a/gcc/c-parse.in +++ b/gcc/c-parse.in @@ -99,8 +99,9 @@ end ifobjc yylval is the node for the constant. */ %token CONSTANT -/* A STRING_CST with type an array of the appropriate character type. */ -%token STRING OBJC_STRING +/* String constants in raw form. + yylval is a STRING_CST node. */ +%token STRING /* "...", used for functions with variable arglists. */ %token ELLIPSIS @@ -150,7 +151,7 @@ end ifobjc %type <ttype> BREAK CONTINUE RETURN GOTO ASM_KEYWORD SIZEOF TYPEOF ALIGNOF %type <ttype> identifier IDENTIFIER TYPENAME CONSTANT expr nonnull_exprlist exprlist -%type <ttype> expr_no_commas cast_expr unary_expr primary STRING +%type <ttype> expr_no_commas cast_expr unary_expr primary string STRING %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_ts_nosa_noea declspecs_nosc_ts_nosa_ea @@ -203,8 +204,6 @@ end ifobjc %type <lineno> save_lineno ifobjc -%token OBJC_STRING - /* the Objective-C nonterminals */ %type <ttype> ivar_decl_list ivar_decls ivar_decl ivars ivar_declarator @@ -215,7 +214,7 @@ ifobjc %type <ttype> selectorarg keywordnamelist keywordname objcencodeexpr %type <ttype> objc_string non_empty_protocolrefs protocolrefs identifier_list objcprotocolexpr -%type <ttype> CLASSNAME OBJECTNAME OBJC_STRING +%type <ttype> CLASSNAME OBJECTNAME end ifobjc %{ @@ -348,8 +347,14 @@ extdef: ifobjc | objcdef end ifobjc - | ASM_KEYWORD '(' STRING ')' ';' - { assemble_asm ($3); } + | ASM_KEYWORD '(' expr ')' ';' + { STRIP_NOPS ($3); + if ((TREE_CODE ($3) == ADDR_EXPR + && TREE_CODE (TREE_OPERAND ($3, 0)) == STRING_CST) + || TREE_CODE ($3) == STRING_CST) + assemble_asm ($3); + else + error ("argument of `asm' is not a constant string"); } | extension extdef { RESTORE_WARN_FLAGS ($1); } ; @@ -613,8 +618,8 @@ primary: $$ = build_external_ref ($1, yychar == '('); } | CONSTANT - | STRING - { $$ = $1; } + | string + { $$ = combine_strings ($1); } | VAR_FUNC_NAME { $$ = fname_decl (C_RID_CODE ($$), $$); } | '(' typename ')' '{' @@ -724,13 +729,37 @@ 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 -/* Chains ObjC string objects together. */ +/* 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 - { $$ = $1; } - | objc_string OBJC_STRING - { $$ = chainon ($1, $2); } + '@' STRING + { $$ = $2; } + | objc_string '@' STRING + { $$ = chainon ($1, $3); } ; end ifobjc @@ -1363,8 +1392,10 @@ notype_initdecls: maybeasm: /* empty */ { $$ = NULL_TREE; } - | ASM_KEYWORD '(' STRING ')' - { $$ = $3; } + | ASM_KEYWORD '(' string ')' + { if (TREE_CHAIN ($3)) $3 = combine_strings ($3); + $$ = $3; + } ; initdcl: @@ -2320,20 +2351,20 @@ stmt: | RETURN expr ';' { stmt_count++; $$ = c_expand_return ($2); } - | ASM_KEYWORD maybe_type_qual '(' STRING ')' ';' + | ASM_KEYWORD maybe_type_qual '(' expr ')' ';' { stmt_count++; $$ = simple_asm_stmt ($4); } /* This is the case with just output operands. */ - | ASM_KEYWORD maybe_type_qual '(' STRING ':' asm_operands ')' ';' + | ASM_KEYWORD maybe_type_qual '(' expr ':' asm_operands ')' ';' { stmt_count++; $$ = build_asm_stmt ($2, $4, $6, NULL_TREE, NULL_TREE); } /* This is the case with input operands as well. */ - | ASM_KEYWORD maybe_type_qual '(' STRING ':' asm_operands ':' + | ASM_KEYWORD maybe_type_qual '(' expr ':' asm_operands ':' asm_operands ')' ';' { stmt_count++; $$ = build_asm_stmt ($2, $4, $6, $8, NULL_TREE); } /* This is the case with clobbered registers as well. */ - | ASM_KEYWORD maybe_type_qual '(' STRING ':' asm_operands ':' + | ASM_KEYWORD maybe_type_qual '(' expr ':' asm_operands ':' asm_operands ':' asm_clobbers ')' ';' { stmt_count++; $$ = build_asm_stmt ($2, $4, $6, $8, $10); } @@ -2422,10 +2453,10 @@ asm_operand: ; asm_clobbers: - STRING - { $$ = tree_cons (NULL_TREE, $1, NULL_TREE); } - | asm_clobbers ',' STRING - { $$ = tree_cons (NULL_TREE, $3, $1); } + string + { $$ = tree_cons (NULL_TREE, combine_strings ($1), NULL_TREE); } + | asm_clobbers ',' string + { $$ = tree_cons (NULL_TREE, combine_strings ($3), $1); } ; /* This is what appears inside the parens in a function declarator. @@ -3572,8 +3603,7 @@ end ifobjc to string constants. */ const char *name = fname_string (rid_code); - yylval.ttype - = combine_strings (build_string (strlen (name) + 1, name)); + yylval.ttype = build_string (strlen (name) + 1, name); last_token = CPP_STRING; /* so yyerror won't choke */ return STRING; } @@ -3690,16 +3720,23 @@ _yylex () special significance. */ case CPP_ATSIGN: ifobjc - last_token = c_lex (&yylval.ttype); + { + tree after_at; + enum cpp_ttype after_at_type; - 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; + after_at_type = c_lex (&after_at); - /* Fall through... */ + if (after_at_type == CPP_NAME + && 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 /* These tokens are C++ specific (and will not be generated diff --git a/gcc/c-typeck.c b/gcc/c-typeck.c index a2a06ba..5677504 100644 --- a/gcc/c-typeck.c +++ b/gcc/c-typeck.c @@ -6820,16 +6820,29 @@ process_init_element (value) /* Build a simple asm-statement, from one string literal. */ tree -simple_asm_stmt (string) - tree string; +simple_asm_stmt (expr) + tree expr; { - tree stmt; + STRIP_NOPS (expr); + + if (TREE_CODE (expr) == ADDR_EXPR) + expr = TREE_OPERAND (expr, 0); - stmt = add_stmt (build_stmt (ASM_STMT, NULL_TREE, string, - NULL_TREE, NULL_TREE, - NULL_TREE)); - ASM_INPUT_P (stmt) = 1; - return stmt; + if (TREE_CODE (expr) == STRING_CST) + { + tree stmt; + + if (TREE_CHAIN (expr)) + expr = combine_strings (expr); + stmt = add_stmt (build_stmt (ASM_STMT, NULL_TREE, expr, + NULL_TREE, NULL_TREE, + NULL_TREE)); + ASM_INPUT_P (stmt) = 1; + return stmt; + } + + error ("argument of `asm' is not a constant string"); + return NULL_TREE; } /* Build an asm-statement, whose components are a CV_QUALIFIER, a @@ -6845,6 +6858,14 @@ build_asm_stmt (cv_qualifier, string, outputs, inputs, clobbers) { tree tail; + if (TREE_CHAIN (string)) + string = combine_strings (string); + if (TREE_CODE (string) != STRING_CST) + { + error ("asm template is not a string constant"); + return NULL_TREE; + } + if (cv_qualifier != NULL_TREE && cv_qualifier != ridpointers[(int) RID_VOLATILE]) { diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index ea344c4..a8c08a2 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,7 @@ +2001-12-10 Neil Booth <neil@daikokuya.demon.co.uk> + + * parse.y, semantics.c: Similarly. + 2001-12-04 Nathan Sidwell <nathan@codesourcery.com> PR g++/87 diff --git a/gcc/cp/parse.y b/gcc/cp/parse.y index e5bedd3..a27f288 100644 --- a/gcc/cp/parse.y +++ b/gcc/cp/parse.y @@ -259,7 +259,8 @@ cp_parse_init () yylval contains an IDENTIFIER_NODE which indicates which one. */ %token VAR_FUNC_NAME -/* String constants as arrays of a suitable type. */ +/* String constants in raw form. + yylval is a STRING_CST node. */ %token STRING /* "...", used for functions with variable arglists. */ @@ -328,7 +329,7 @@ cp_parse_init () %type <ttype> PFUNCNAME maybe_identifier %type <ttype> paren_expr_or_null nontrivial_exprlist SELFNAME %type <ttype> expr_no_commas expr_no_comma_rangle -%type <ttype> cast_expr unary_expr primary STRING +%type <ttype> cast_expr unary_expr primary string STRING %type <ttype> reserved_declspecs boolean.literal %type <ttype> reserved_typespecquals %type <ttype> SCSPEC TYPESPEC CV_QUALIFIER maybe_cv_qualifier @@ -496,8 +497,9 @@ extdef: { do_pending_inlines (); } | template_def { do_pending_inlines (); } - | asm_keyword '(' STRING ')' ';' - { assemble_asm ($3); } + | asm_keyword '(' string ')' ';' + { if (TREE_CHAIN ($3)) $3 = combine_strings ($3); + assemble_asm ($3); } | extern_lang_string '{' extdefs_opt '}' { pop_lang_context (); } | extern_lang_string .hush_warning fndef .warning_ok eat_saved_input @@ -1545,8 +1547,9 @@ primary: } | CONSTANT | boolean.literal - | STRING + | string { + $$ = combine_strings ($$); /* combine_strings doesn't set up TYPE_MAIN_VARIANT of a const array the way we want, so fix it. */ if (flag_const_strings) @@ -1748,6 +1751,13 @@ boolean.literal: { $$ = boolean_false_node; } ; +/* Produces a STRING_CST with perhaps more STRING_CSTs chained onto it. */ +string: + STRING + | string STRING + { $$ = chainon ($$, $2); } + ; + nodecls: /* empty */ { @@ -2031,8 +2041,8 @@ nomods_initdecls: maybeasm: /* empty */ { $$ = NULL_TREE; } - | asm_keyword '(' STRING ')' - { $$ = $3; } + | asm_keyword '(' string ')' + { if (TREE_CHAIN ($3)) $3 = combine_strings ($3); $$ = $3; } ; initdcl: @@ -3429,27 +3439,27 @@ simple_stmt: { $$ = finish_return_stmt (NULL_TREE); } | RETURN_KEYWORD expr ';' { $$ = 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, NULL_TREE); ASM_INPUT_P ($$) = 1; } /* 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); } /* 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 ')' ';' { $$ = 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); } /* 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 ')' ';' { $$ = 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 ')' ';' { $$ = 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 ')' ';' { $$ = finish_asm_stmt ($2, $4, $6, NULL_TREE, $8); } | GOTO '*' expr ';' @@ -3604,10 +3614,10 @@ asm_operand: ; asm_clobbers: - STRING - { $$ = tree_cons (NULL_TREE, $1, NULL_TREE);} - | asm_clobbers ',' STRING - { $$ = tree_cons (NULL_TREE, $3, $1); } + string + { $$ = tree_cons (NULL_TREE, combine_strings ($1), NULL_TREE);} + | asm_clobbers ',' string + { $$ = tree_cons (NULL_TREE, combine_strings ($3), $1); } ; /* This is what appears inside the parens in a function declarator. diff --git a/gcc/cp/semantics.c b/gcc/cp/semantics.c index 776f06f..b0bb25b 100644 --- a/gcc/cp/semantics.c +++ b/gcc/cp/semantics.c @@ -883,6 +883,9 @@ finish_asm_stmt (cv_qualifier, string, output_operands, tree r; tree t; + if (TREE_CHAIN (string)) + string = combine_strings (string); + if (cv_qualifier != NULL_TREE && cv_qualifier != ridpointers[(int) RID_VOLATILE]) { |