/* C preprocessor macro expansion for GDB.
- Copyright (C) 2002, 2007, 2008, 2009 Free Software Foundation, Inc.
+ Copyright (C) 2002, 2007, 2008, 2009, 2010 Free Software Foundation, Inc.
Contributed by Red Hat, Inc.
This file is part of GDB.
#include "macrotab.h"
#include "macroexp.h"
#include "gdb_assert.h"
+#include "c-lang.h"
\f
way GDB's C/C++ lexer does. So we call parse_escape in utils.c
to handle escape sequences. */
if ((p + 1 <= end && *p == '\'')
- || (p + 2 <= end && p[0] == 'L' && p[1] == '\''))
+ || (p + 2 <= end
+ && (p[0] == 'L' || p[0] == 'u' || p[0] == 'U')
+ && p[1] == '\''))
{
char *tok_start = p;
char *body_start;
+ int char_count = 0;
if (*p == '\'')
p++;
- else if (*p == 'L')
+ else if (*p == 'L' || *p == 'u' || *p == 'U')
p += 2;
else
gdb_assert (0);
error (_("Unmatched single quote."));
else if (*p == '\'')
{
- if (p == body_start)
+ if (!char_count)
error (_("A character constant must contain at least one "
"character."));
p++;
else if (*p == '\\')
{
p++;
- parse_escape (&p);
+ char_count += c_parse_escape (&p, NULL);
}
else
- p++;
+ {
+ p++;
+ char_count++;
+ }
}
set_token (tok, tok_start, p);
get_string_literal (struct macro_buffer *tok, char *p, char *end)
{
if ((p + 1 <= end
- && *p == '\"')
+ && *p == '"')
|| (p + 2 <= end
- && p[0] == 'L'
- && p[1] == '\"'))
+ && (p[0] == 'L' || p[0] == 'u' || p[0] == 'U')
+ && p[1] == '"'))
{
char *tok_start = p;
- if (*p == '\"')
+ if (*p == '"')
p++;
- else if (*p == 'L')
+ else if (*p == 'L' || *p == 'u' || *p == 'U')
p += 2;
else
gdb_assert (0);
{
if (p >= end)
error (_("Unterminated string in expression."));
- else if (*p == '\"')
+ else if (*p == '"')
{
p++;
break;
else if (*p == '\\')
{
p++;
- parse_escape (&p);
+ c_parse_escape (&p, NULL);
}
else
p++;
{
/* How many characters did we consume, including whitespace? */
int consumed = p - src->text + tok->len;
+
src->text += consumed;
src->len -= consumed;
return 1;
paren. */
{
struct macro_buffer temp;
+
init_shared_buffer (&temp, src->text, src->len);
if (! get_token (&tok, &temp)
depth = 0;
for (;;)
{
- char *start = src->text;
-
if (! get_token (&tok, src))
error (_("Malformed argument list for macro `%s'."), name);
&& lookahead.text[0] == '#'
&& lookahead.text[1] == '#')
{
- int arg, finished = 0;
+ int finished = 0;
int prev_was_comma = 0;
/* Note that GCC warns if the result of splicing is not a
{
int arg = find_parameter (&tok, is_varargs, va_arg_name,
def->argc, def->argv);
+
if (arg != -1)
appendmem (dest, argv[arg].text, argv[arg].len);
else
{
int arg = find_parameter (&tok, is_varargs, va_arg_name,
def->argc, def->argv);
+
if (arg != -1)
appendmem (dest, argv[arg].text, argv[arg].len);
else
else
{
int len = strlen (def->argv[def->argc - 1]);
+
if (len > 3
&& strcmp (def->argv[def->argc - 1] + len - 3, "...") == 0)
{
lookup function expects. */
char *id = xmalloc (src_first->len + 1);
struct cleanup *back_to = make_cleanup (xfree, id);
+
memcpy (id, src_first->text, src_first->len);
id[src_first->len] = 0;