From 9507860ea98fccee3a8567de42ed9c71d43bc343 Mon Sep 17 00:00:00 2001 From: Tom Tromey Date: Thu, 21 Mar 2013 15:01:55 +0000 Subject: [PATCH] * c-exp.y (YYPRINT): Define. (c_print_token): New function. --- gdb/ChangeLog | 5 +++++ gdb/c-exp.y | 56 +++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 61 insertions(+) diff --git a/gdb/ChangeLog b/gdb/ChangeLog index da787937f40..10e8cd6ce5b 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,3 +1,8 @@ +2013-03-21 Tom Tromey + + * c-exp.y (YYPRINT): Define. + (c_print_token): New function. + 2013-03-21 Tom Tromey * c-exp.y (%union) : Remove. diff --git a/gdb/c-exp.y b/gdb/c-exp.y index 0cd468395d2..313a63f10d5 100644 --- a/gdb/c-exp.y +++ b/gdb/c-exp.y @@ -167,6 +167,9 @@ void yyerror (char *); static int parse_number (char *, int, int, YYSTYPE *); static struct stoken operator_stoken (const char *); static void check_parameter_typelist (VEC (type_ptr) *); + +static void c_print_token (FILE *file, int type, YYSTYPE value); +#define YYPRINT(FILE, TYPE, VALUE) c_print_token (FILE, TYPE, VALUE) %} %type exp exp1 type_exp start variable qualified_name lcurly @@ -3063,6 +3066,59 @@ c_parse (void) return result; } +/* This is called via the YYPRINT macro when parser debugging is + enabled. It prints a token's value. */ + +static void +c_print_token (FILE *file, int type, YYSTYPE value) +{ + switch (type) + { + case INT: + fprintf (file, "typed_val_int<%s, %s>", + TYPE_SAFE_NAME (value.typed_val_int.type), + pulongest (value.typed_val_int.val)); + break; + + case CHAR: + case STRING: + { + char *copy = alloca (value.tsval.length + 1); + + memcpy (copy, value.tsval.ptr, value.tsval.length); + copy[value.tsval.length] = '\0'; + + fprintf (file, "tsval", value.tsval.type, copy); + } + break; + + case NSSTRING: + case VARIABLE: + fprintf (file, "sval<%s>", copy_name (value.sval)); + break; + + case TYPENAME: + fprintf (file, "tsym", + TYPE_SAFE_NAME (value.tsym.type), + copy_name (value.tsym.stoken)); + break; + + case NAME: + case UNKNOWN_CPP_NAME: + case NAME_OR_INT: + case BLOCKNAME: + fprintf (file, "ssym", + copy_name (value.ssym.stoken), + (value.ssym.sym == NULL + ? "(null)" : SYMBOL_PRINT_NAME (value.ssym.sym)), + value.ssym.is_a_field_of_this); + break; + + case FILENAME: + fprintf (file, "bval<%s>", host_address_to_string (value.bval)); + break; + } +} void yyerror (char *msg) -- 2.30.2