From 46c2514e82bf5f6ed45ef6ac8b123c9283bf8d6a Mon Sep 17 00:00:00 2001 From: Tom Tromey Date: Thu, 13 Sep 2007 20:18:38 +0000 Subject: [PATCH] c-common.c (fname_as_string): Update. gcc * c-common.c (fname_as_string): Update. * c-parser.c (c_parser) : New field. (c_lex_one_token): Update. Add 'parser' argument. (c_parser_simple_asm_expr): Update. (c_parser_attributes): Update. (c_parser_asm_statement): Update. (c_parser_asm_operands): Update. (c_parser_peek_token): Update. (c_parser_peek_2nd_token): Update. * c-lex.c (c_lex_string_translate): Remove. (c_lex_return_raw_strings): Likewise. (c_lex_with_flags): Added 'lex_flags' argument. (lex_string): Added 'translate' argument. * c-pragma.h (c_lex_with_flags): Update. (c_lex_string_translate, c_lex_return_raw_strings): Remove. (C_LEX_STRING_NO_TRANSLATE): New define. (C_LEX_RAW_STRINGS): Likewise. gcc/cp * parser.c (cp_lexer_new_main): Don't use c_lex_return_raw_strings. (cp_lexer_get_preprocessor_token): Update. Add special case when lexer is NULL. From-SVN: r128479 --- gcc/ChangeLog | 20 ++++++++++++++++++++ gcc/c-common.c | 27 +++++++++++---------------- gcc/c-lex.c | 48 +++++++++--------------------------------------- gcc/c-parser.c | 54 +++++++++++++++++++++++++++++------------------------- gcc/c-pragma.h | 21 ++++++++++----------- gcc/cp/ChangeLog | 7 +++++++ gcc/cp/parser.c | 13 ++++++------- 7 files changed, 92 insertions(+), 98 deletions(-) diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 393dd44..e23de7a 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,23 @@ +2007-09-13 Tom Tromey + + * c-common.c (fname_as_string): Update. + * c-parser.c (c_parser) : New field. + (c_lex_one_token): Update. Add 'parser' argument. + (c_parser_simple_asm_expr): Update. + (c_parser_attributes): Update. + (c_parser_asm_statement): Update. + (c_parser_asm_operands): Update. + (c_parser_peek_token): Update. + (c_parser_peek_2nd_token): Update. + * c-lex.c (c_lex_string_translate): Remove. + (c_lex_return_raw_strings): Likewise. + (c_lex_with_flags): Added 'lex_flags' argument. + (lex_string): Added 'translate' argument. + * c-pragma.h (c_lex_with_flags): Update. + (c_lex_string_translate, c_lex_return_raw_strings): Remove. + (C_LEX_STRING_NO_TRANSLATE): New define. + (C_LEX_RAW_STRINGS): Likewise. + 2007-09-13 Bernd Schmidt From Jie Zhang: diff --git a/gcc/c-common.c b/gcc/c-common.c index f6af052..0f4d695 100644 --- a/gcc/c-common.c +++ b/gcc/c-common.c @@ -756,7 +756,8 @@ fname_as_string (int pretty_p) { const char *name = "top level"; char *namep; - int vrb = 2; + int vrb = 2, len; + cpp_string cstr = { 0, 0 }, strname; if (!pretty_p) { @@ -767,24 +768,18 @@ fname_as_string (int pretty_p) if (current_function_decl) name = lang_hooks.decl_printable_name (current_function_decl, vrb); - if (c_lex_string_translate) - { - int len = strlen (name) + 3; /* Two for '"'s. One for NULL. */ - cpp_string cstr = { 0, 0 }, strname; + len = strlen (name) + 3; /* Two for '"'s. One for NULL. */ - namep = XNEWVEC (char, len); - snprintf (namep, len, "\"%s\"", name); - strname.text = (unsigned char *) namep; - strname.len = len - 1; + namep = XNEWVEC (char, len); + snprintf (namep, len, "\"%s\"", name); + strname.text = (unsigned char *) namep; + strname.len = len - 1; - if (cpp_interpret_string (parse_in, &strname, 1, &cstr, false)) - { - XDELETEVEC (namep); - return (const char *) cstr.text; - } + if (cpp_interpret_string (parse_in, &strname, 1, &cstr, false)) + { + XDELETEVEC (namep); + return (const char *) cstr.text; } - else - namep = xstrdup (name); return namep; } diff --git a/gcc/c-lex.c b/gcc/c-lex.c index 23abaad..5cad260 100644 --- a/gcc/c-lex.c +++ b/gcc/c-lex.c @@ -49,16 +49,6 @@ static splay_tree file_info_tree; int pending_lang_change; /* If we need to switch languages - C++ only */ int c_header_level; /* depth in C headers - C++ only */ -/* If we need to translate characters received. This is tri-state: - 0 means use only the untranslated string; 1 means use only - the translated string; -1 means chain the translated string - to the untranslated one. */ -int c_lex_string_translate = 1; - -/* True if strings should be passed to the caller of c_lex completely - unmolested (no concatenation, no translation). */ -bool c_lex_return_raw_strings = false; - static tree interpret_integer (const cpp_token *, unsigned int); static tree interpret_float (const cpp_token *, unsigned int); static tree interpret_fixed (const cpp_token *, unsigned int); @@ -66,7 +56,7 @@ static enum integer_type_kind narrowest_unsigned_type (unsigned HOST_WIDE_INT, unsigned HOST_WIDE_INT, unsigned int); static enum integer_type_kind narrowest_signed_type (unsigned HOST_WIDE_INT, unsigned HOST_WIDE_INT, unsigned int); -static enum cpp_ttype lex_string (const cpp_token *, tree *, bool); +static enum cpp_ttype lex_string (const cpp_token *, tree *, bool, bool); static tree lex_charconst (const cpp_token *); static void update_header_times (const char *); static int dump_one_header (splay_tree_node, void *); @@ -329,7 +319,8 @@ cb_undef (cpp_reader * ARG_UNUSED (pfile), source_location loc, non-NULL. */ enum cpp_ttype -c_lex_with_flags (tree *value, location_t *loc, unsigned char *cpp_flags) +c_lex_with_flags (tree *value, location_t *loc, unsigned char *cpp_flags, + int lex_flags) { static bool no_more_pch; const cpp_token *tok; @@ -411,7 +402,7 @@ c_lex_with_flags (tree *value, location_t *loc, unsigned char *cpp_flags) case CPP_STRING: case CPP_WSTRING: - type = lex_string (tok, value, true); + type = lex_string (tok, value, true, true); break; case CPP_NAME: @@ -467,9 +458,10 @@ c_lex_with_flags (tree *value, location_t *loc, unsigned char *cpp_flags) case CPP_STRING: case CPP_WSTRING: - if (!c_lex_return_raw_strings) + if ((lex_flags & C_LEX_RAW_STRINGS) == 0) { - type = lex_string (tok, value, false); + type = lex_string (tok, value, false, + (lex_flags & C_LEX_STRING_NO_TRANSLATE) == 0); break; } *value = build_string (tok->val.str.len, (const char *) tok->val.str.text); @@ -890,7 +882,7 @@ interpret_fixed (const cpp_token *token, unsigned int flags) we must arrange to provide. */ static enum cpp_ttype -lex_string (const cpp_token *tok, tree *valp, bool objc_string) +lex_string (const cpp_token *tok, tree *valp, bool objc_string, bool translate) { tree value; bool wide = false; @@ -948,34 +940,12 @@ lex_string (const cpp_token *tok, tree *valp, bool objc_string) warning (OPT_Wtraditional, "traditional C rejects string constant concatenation"); - if ((c_lex_string_translate + if ((translate ? cpp_interpret_string : cpp_interpret_string_notranslate) (parse_in, strs, concats + 1, &istr, wide)) { value = build_string (istr.len, (const char *) istr.text); free (CONST_CAST (unsigned char *, istr.text)); - - if (c_lex_string_translate == -1) - { - int xlated = cpp_interpret_string_notranslate (parse_in, strs, - concats + 1, - &istr, wide); - /* Assume that, if we managed to translate the string above, - then the untranslated parsing will always succeed. */ - gcc_assert (xlated); - - if (TREE_STRING_LENGTH (value) != (int) istr.len - || 0 != strncmp (TREE_STRING_POINTER (value), - (const char *) istr.text, istr.len)) - { - /* Arrange for us to return the untranslated string in - *valp, but to set up the C type of the translated - one. */ - *valp = build_string (istr.len, (const char *) istr.text); - valp = &TREE_CHAIN (*valp); - } - free (CONST_CAST (unsigned char *, istr.text)); - } } else { diff --git a/gcc/c-parser.c b/gcc/c-parser.c index 91ba850..bdf96ca 100644 --- a/gcc/c-parser.c +++ b/gcc/c-parser.c @@ -280,6 +280,8 @@ typedef struct c_parser GTY(()) /* True if we're processing a pragma, and shouldn't automatically consume CPP_PRAGMA_EOL. */ BOOL_BITFIELD in_pragma : 1; + /* True if we want to lex an untranslated string. */ + BOOL_BITFIELD lex_untranslated_string : 1; /* Objective-C specific parser/lexer information. */ BOOL_BITFIELD objc_pq_context : 1; /* The following flag is needed to contextualize Objective-C lexical @@ -303,7 +305,9 @@ c_lex_one_token (c_parser *parser, c_token *token) { timevar_push (TV_LEX); - token->type = c_lex_with_flags (&token->value, &token->location, NULL); + token->type = c_lex_with_flags (&token->value, &token->location, NULL, + (parser->lex_untranslated_string + ? C_LEX_STRING_NO_TRANSLATE : 0)); token->id_kind = C_ID_NONE; token->keyword = RID_MAX; token->pragma_kind = PRAGMA_NONE; @@ -2731,8 +2735,8 @@ c_parser_parameter_declaration (c_parser *parser, tree attrs) string-literal ??? At present, following the old parser, the caller needs to have - set c_lex_string_translate to 0. It would be better to follow the - C++ parser rather than using the c_lex_string_translate kludge. */ + set lex_untranslated_string to 1. It would be better to follow the + C++ parser rather than using this kludge. */ static tree c_parser_asm_string_literal (c_parser *parser) @@ -2771,16 +2775,16 @@ c_parser_simple_asm_expr (c_parser *parser) tree str; gcc_assert (c_parser_next_token_is_keyword (parser, RID_ASM)); /* ??? Follow the C++ parser rather than using the - c_lex_string_translate kludge. */ - c_lex_string_translate = 0; + lex_untranslated_string kludge. */ + parser->lex_untranslated_string = true; c_parser_consume_token (parser); if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>")) { - c_lex_string_translate = 1; + parser->lex_untranslated_string = false; return NULL_TREE; } str = c_parser_asm_string_literal (parser); - c_lex_string_translate = 1; + parser->lex_untranslated_string = false; if (!c_parser_require (parser, CPP_CLOSE_PAREN, "expected %<)%>")) { c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL); @@ -2823,17 +2827,17 @@ c_parser_attributes (c_parser *parser) while (c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE)) { /* ??? Follow the C++ parser rather than using the - c_lex_string_translate kludge. */ - c_lex_string_translate = 0; + lex_untranslated_string kludge. */ + parser->lex_untranslated_string = true; c_parser_consume_token (parser); if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>")) { - c_lex_string_translate = 1; + parser->lex_untranslated_string = false; return attrs; } if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>")) { - c_lex_string_translate = 1; + parser->lex_untranslated_string = false; c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL); return attrs; } @@ -2933,7 +2937,7 @@ c_parser_attributes (c_parser *parser) c_parser_consume_token (parser); else { - c_lex_string_translate = 1; + parser->lex_untranslated_string = false; c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>"); return attrs; @@ -2944,7 +2948,7 @@ c_parser_attributes (c_parser *parser) c_parser_consume_token (parser); else { - c_lex_string_translate = 1; + parser->lex_untranslated_string = false; c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>"); return attrs; @@ -2953,12 +2957,12 @@ c_parser_attributes (c_parser *parser) c_parser_consume_token (parser); else { - c_lex_string_translate = 1; + parser->lex_untranslated_string = false; c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>"); return attrs; } - c_lex_string_translate = 1; + parser->lex_untranslated_string = false; } return attrs; } @@ -4139,11 +4143,11 @@ c_parser_asm_statement (c_parser *parser) else quals = NULL_TREE; /* ??? Follow the C++ parser rather than using the - c_lex_string_translate kludge. */ - c_lex_string_translate = 0; + lex_untranslated_string kludge. */ + parser->lex_untranslated_string = true; if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>")) { - c_lex_string_translate = 1; + parser->lex_untranslated_string = false; return NULL_TREE; } str = c_parser_asm_string_literal (parser); @@ -4157,7 +4161,7 @@ c_parser_asm_statement (c_parser *parser) } if (!c_parser_require (parser, CPP_COLON, "expected %<:%> or %<)%>")) { - c_lex_string_translate = 1; + parser->lex_untranslated_string = false; c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL); return NULL_TREE; } @@ -4176,7 +4180,7 @@ c_parser_asm_statement (c_parser *parser) } if (!c_parser_require (parser, CPP_COLON, "expected %<:%> or %<)%>")) { - c_lex_string_translate = 1; + parser->lex_untranslated_string = false; c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL); return NULL_TREE; } @@ -4193,14 +4197,14 @@ c_parser_asm_statement (c_parser *parser) } if (!c_parser_require (parser, CPP_COLON, "expected %<:%> or %<)%>")) { - c_lex_string_translate = 1; + parser->lex_untranslated_string = false; c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL); return NULL_TREE; } /* Parse clobbers. */ clobbers = c_parser_asm_clobbers (parser); done_asm: - c_lex_string_translate = 1; + parser->lex_untranslated_string = false; if (!c_parser_require (parser, CPP_CLOSE_PAREN, "expected %<)%>")) { c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL); @@ -4258,16 +4262,16 @@ c_parser_asm_operands (c_parser *parser, bool convert_p) str = c_parser_asm_string_literal (parser); if (str == NULL_TREE) return NULL_TREE; - c_lex_string_translate = 1; + parser->lex_untranslated_string = false; if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>")) { - c_lex_string_translate = 0; + parser->lex_untranslated_string = true; return NULL_TREE; } expr = c_parser_expression (parser); if (convert_p) expr = default_function_array_conversion (expr); - c_lex_string_translate = 0; + parser->lex_untranslated_string = true; if (!c_parser_require (parser, CPP_CLOSE_PAREN, "expected %<)%>")) { c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL); diff --git a/gcc/c-pragma.h b/gcc/c-pragma.h index 8ccf4ba..9896f43 100644 --- a/gcc/c-pragma.h +++ b/gcc/c-pragma.h @@ -110,19 +110,18 @@ extern void add_to_renaming_pragma_list (tree, tree); extern enum cpp_ttype pragma_lex (tree *); +/* Flags for use with c_lex_with_flags. The values here were picked + so that 0 means to translate and join strings. */ +#define C_LEX_STRING_NO_TRANSLATE 1 /* Do not lex strings into + execution character set. */ +#define C_LEX_RAW_STRINGS 2 /* Return raw strings -- no + concatenation, no + translation. */ + /* This is not actually available to pragma parsers. It's merely a convenient location to declare this function for c-lex, after having enum cpp_ttype declared. */ -extern enum cpp_ttype c_lex_with_flags (tree *, location_t *, unsigned char *); - -/* If 1, then lex strings into the execution character set. - If 0, lex strings into the host character set. - If -1, lex both, and chain them together, such that the former - is the TREE_CHAIN of the latter. */ -extern int c_lex_string_translate; - -/* If true, strings should be passed to the caller of c_lex completely - unmolested (no concatenation, no translation). */ -extern bool c_lex_return_raw_strings; +extern enum cpp_ttype c_lex_with_flags (tree *, location_t *, unsigned char *, + int); #endif /* GCC_C_PRAGMA_H */ diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index a73da49..dfcbb02 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,10 @@ +2007-09-13 Tom Tromey + + * parser.c (cp_lexer_new_main): Don't use + c_lex_return_raw_strings. + (cp_lexer_get_preprocessor_token): Update. Add special case when + lexer is NULL. + 2007-09-11 Jan Hubicka * method.c (use_thunk): Use tree_rest_of_compilation diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c index 9f96717..ede0d7e 100644 --- a/gcc/cp/parser.c +++ b/gcc/cp/parser.c @@ -277,9 +277,6 @@ cp_lexer_new_main (void) allocating any memory. */ cp_parser_initial_pragma (&first_token); - /* Tell c_lex_with_flags not to merge string constants. */ - c_lex_return_raw_strings = true; - c_common_no_more_pch (); /* Allocate the memory. */ @@ -402,17 +399,19 @@ cp_lexer_saving_tokens (const cp_lexer* lexer) } /* Store the next token from the preprocessor in *TOKEN. Return true - if we reach EOF. */ + if we reach EOF. If LEXER is NULL, assume we are handling an + initial #pragma pch_preprocess, and thus want the lexer to return + processed strings. */ static void -cp_lexer_get_preprocessor_token (cp_lexer *lexer ATTRIBUTE_UNUSED , - cp_token *token) +cp_lexer_get_preprocessor_token (cp_lexer *lexer, cp_token *token) { static int is_extern_c = 0; /* Get a new token from the preprocessor. */ token->type - = c_lex_with_flags (&token->u.value, &token->location, &token->flags); + = c_lex_with_flags (&token->u.value, &token->location, &token->flags, + lexer == NULL ? 0 : C_LEX_RAW_STRINGS); token->input_file_stack_index = input_file_stack_tick; token->keyword = RID_MAX; token->pragma_kind = PRAGMA_NONE; -- 2.7.4