+2007-09-13 Tom Tromey <tromey@redhat.com>
+
+ * c-common.c (fname_as_string): Update.
+ * c-parser.c (c_parser) <lex_untranslated_string>: 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 <bernd.schmidt@analog.com>
From Jie Zhang:
{
const char *name = "top level";
char *namep;
- int vrb = 2;
+ int vrb = 2, len;
+ cpp_string cstr = { 0, 0 }, strname;
if (!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;
}
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);
(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 *);
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;
case CPP_STRING:
case CPP_WSTRING:
- type = lex_string (tok, value, true);
+ type = lex_string (tok, value, true, true);
break;
case CPP_NAME:
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);
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;
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
{
/* 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
{
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;
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)
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);
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;
}
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_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_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;
}
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);
}
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;
}
}
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;
}
}
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);
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);
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 */
+2007-09-13 Tom Tromey <tromey@redhat.com>
+
+ * 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 <jh@suse.cz>
* method.c (use_thunk): Use tree_rest_of_compilation
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. */
}
/* 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;