This is the mail archive of the
gdb-patches@sources.redhat.com
mailing list for the GDB project.
[dictionary] fiddling with the parser
- From: David Carlton <carlton at bactrian dot org>
- To: gdb-patches at sources dot redhat dot com
- Date: 07 May 2003 18:12:39 -0700
- Subject: [dictionary] fiddling with the parser
GDB's C++ parser is a mess (which is, to some extent, a side effect of
C++ being a mess); in particular, right now nested type parsing is in
the lexer instead of the parser. That has its plusses and minuses,
but I didn't like the error messages that resulted; this patch moves
nested type stuff to the parser (at the cost of adding 8 reduce/reduce
conflicts, but we already had 20 of them...), and makes other assorted
changes to get 'ptype' working properly.
I would be surprised if I didn't fool around with this some more in
the future. Now that I've discovered EVAL_AVOID_SIDE_EFFECTS, it
might make me rethink the way I do this.
David Carlton
carlton@bactrian.org
2003-05-07 David Carlton <carlton@bactrian.org>
* valops.c (value_aggregate_elt): Add 'noside' argument.
(value_struct_elt_for_reference): Add 'block', 'noside'
arguments. Call value_maybe_namespace_elt.
(value_namespace_elt): Add 'noside' argument. Break out code into
value_maybe_namespace_elt.
(value_maybe_namespace_elt): New. Handle types.
* value.h: Update declaration for value_aggregate_elt.
* eval.c (evaluate_subexp_standard): Pass 'noside' to
value_aggregate_elt.
* c-exp.y: Added 'qualified_type'.
(yylex): Comment out nested type stuff.
2003-05-07 David Carlton <carlton@bactrian.org>
* gdb.c++/namespace.exp: Update messages to match new parser
changes.
Index: c-exp.y
===================================================================
RCS file: /cvs/src/src/gdb/c-exp.y,v
retrieving revision 1.15.2.9
diff -u -p -r1.15.2.9 c-exp.y
--- c-exp.y 7 Mar 2003 22:52:53 -0000 1.15.2.9
+++ c-exp.y 8 May 2003 01:05:07 -0000
@@ -153,7 +153,7 @@ static int parse_number (char *, int, in
%type <voidval> exp exp1 type_exp start variable qualified_name lcurly
%type <lval> rcurly
-%type <tval> type typebase
+%type <tval> type typebase qualified_type
%type <tvec> nonempty_typelist
/* %type <bval> block */
@@ -898,6 +898,32 @@ typebase /* Implements (approximately):
{ $$ = follow_types ($2); }
| typebase const_or_volatile_or_space_identifier_noopt
{ $$ = follow_types ($1); }
+ | qualified_type
+ ;
+
+qualified_type: typebase COLONCOLON name
+ {
+ struct type *type = $1;
+ struct type *new_type;
+ char *ncopy = alloca ($3.length + 1);
+
+ memcpy (ncopy, $3.ptr, $3.length);
+ ncopy[$3.length] = '\0';
+
+ if (TYPE_CODE (type) != TYPE_CODE_STRUCT
+ && TYPE_CODE (type) != TYPE_CODE_UNION
+ && TYPE_CODE (type) != TYPE_CODE_NAMESPACE)
+ error ("`%s' is not defined as an aggregate type.",
+ TYPE_NAME (type));
+
+ new_type = lookup_nested_type (type, ncopy,
+ expression_context_block);
+ if (new_type == NULL)
+ error ("No type \"%s\" within class or namespace \"%s\".",
+ ncopy, TYPE_NAME (type));
+
+ $$ = new_type;
+ }
;
typename: TYPENAME
@@ -1704,7 +1730,7 @@ yylex ()
if (sym && SYMBOL_CLASS (sym) == LOC_TYPEDEF)
{
-#if 1
+#if 0
char *p;
char *namestart;
struct type *best_type;
Index: eval.c
===================================================================
RCS file: /cvs/src/src/gdb/eval.c,v
retrieving revision 1.23.8.8
diff -u -p -r1.23.8.8 eval.c
--- eval.c 1 May 2003 00:46:47 -0000 1.23.8.8
+++ eval.c 8 May 2003 01:05:10 -0000
@@ -409,7 +409,8 @@ evaluate_subexp_standard (struct type *e
(*pos) += 5 + BYTES_TO_EXP_ELEM (tem + 1);
arg1 = value_aggregate_elt (exp->elts[pc + 1].type,
exp->elts[pc + 2].block,
- &exp->elts[pc + 4].string);
+ &exp->elts[pc + 4].string,
+ noside);
if (arg1 == NULL)
error ("There is no field named %s", &exp->elts[pc + 4].string);
return arg1;
Index: valops.c
===================================================================
RCS file: /cvs/src/src/gdb/valops.c,v
retrieving revision 1.75.2.20
diff -u -p -r1.75.2.20 valops.c
--- valops.c 1 May 2003 00:46:53 -0000 1.75.2.20
+++ valops.c 8 May 2003 01:05:14 -0000
@@ -101,11 +101,20 @@ static struct value *value_struct_elt_fo
int offset,
struct type *curtype,
const char *name,
- struct type *intype);
+ struct type *intype,
+ const struct block *
+ block,
+ enum noside noside);
static struct value *value_namespace_elt (const struct type *curtype,
const struct block *block,
- const char *name);
+ const char *name,
+ enum noside noside);
+
+static struct value *value_maybe_namespace_elt (const struct type *curtype,
+ const struct block *block,
+ const char *name,
+ enum noside noside);
static CORE_ADDR allocate_space_in_inferior (int);
@@ -2507,15 +2516,17 @@ check_field (struct value *arg1, const c
struct value *
value_aggregate_elt (struct type *curtype,
const struct block *block,
- const char *name)
+ const char *name,
+ enum noside noside)
{
switch (TYPE_CODE (curtype))
{
case TYPE_CODE_STRUCT:
case TYPE_CODE_UNION:
- return value_struct_elt_for_reference (curtype, 0, curtype, name, NULL);
+ return value_struct_elt_for_reference (curtype, 0, curtype, name, NULL,
+ block, noside);
case TYPE_CODE_NAMESPACE:
- return value_namespace_elt (curtype, block, name);
+ return value_namespace_elt (curtype, block, name, noside);
default:
error ("Internal error: non-aggregate type to value_aggregate_elt");
}
@@ -2531,7 +2542,9 @@ value_aggregate_elt (struct type *curtyp
static struct value *
value_struct_elt_for_reference (struct type *domain, int offset,
struct type *curtype, const char *name,
- struct type *intype)
+ struct type *intype,
+ const struct block *block,
+ enum noside noside)
{
register struct type *t = curtype;
register int i;
@@ -2650,11 +2663,17 @@ value_struct_elt_for_reference (struct t
offset + base_offset,
TYPE_BASECLASS (t, i),
name,
- intype);
+ intype,
+ block,
+ noside);
if (v)
return v;
}
- return 0;
+
+ /* As a last chance, look it up using lookup_symbol_namespace: this
+ works for types. */
+
+ return value_maybe_namespace_elt (curtype, block, name, noside);
}
/* C++: Return the member NAME of the namespace given by the type
@@ -2664,7 +2683,27 @@ value_struct_elt_for_reference (struct t
static struct value *
value_namespace_elt (const struct type *curtype,
const struct block *block,
- const char *name)
+ const char *name,
+ enum noside noside)
+{
+ struct value *retval = value_maybe_namespace_elt (curtype, block, name,
+ noside);
+
+ if (retval == NULL)
+ error ("No symbol \"%s\" in namespace \"%s\".", name,
+ TYPE_TAG_NAME (curtype));
+
+ return retval;
+}
+
+/* A helper function used by value_namespace_elt and
+ value_struct_elt_for_reference. */
+
+static struct value *
+value_maybe_namespace_elt (const struct type *curtype,
+ const struct block *block,
+ const char *name,
+ enum noside noside)
{
const char *namespace_name = TYPE_TAG_NAME (curtype);
const struct symbol *sym;
@@ -2672,13 +2711,13 @@ value_namespace_elt (const struct type *
sym = lookup_symbol_namespace (namespace_name, name, NULL,
block, VAR_NAMESPACE, NULL);
- /* FIXME: carlton/2002-11-24: Should this really be here, or should
- it be in c-exp.y like the other similar messages? Hmm... */
-
if (sym == NULL)
- error ("No symbol \"%s\" in namespace \"%s\".", name, namespace_name);
-
- return value_of_variable (sym, block);
+ return NULL;
+ else if ((noside == EVAL_AVOID_SIDE_EFFECTS)
+ && (SYMBOL_CLASS (sym) == LOC_TYPEDEF))
+ return allocate_value (SYMBOL_TYPE (sym));
+ else
+ return value_of_variable (sym, block);
}
/* Given a pointer value V, find the real (RTTI) type
Index: value.h
===================================================================
RCS file: /cvs/src/src/gdb/value.h,v
retrieving revision 1.36.2.8
diff -u -p -r1.36.2.8 value.h
--- value.h 1 May 2003 00:46:53 -0000 1.36.2.8
+++ value.h 8 May 2003 01:05:15 -0000
@@ -375,7 +375,8 @@ extern struct value *value_struct_elt (s
extern struct value *value_aggregate_elt (struct type *curtype,
const struct block *block,
- const char *name);
+ const char *name,
+ enum noside noside);
extern struct value *value_static_field (struct type *type, int fieldno);
Index: testsuite/gdb.c++/namespace.exp
===================================================================
RCS file: /cvs/src/src/gdb/testsuite/gdb.c++/namespace.exp,v
retrieving revision 1.12.16.12
diff -u -p -r1.12.16.12 namespace.exp
--- testsuite/gdb.c++/namespace.exp 7 Jan 2003 01:28:24 -0000 1.12.16.12
+++ testsuite/gdb.c++/namespace.exp 8 May 2003 01:05:31 -0000
@@ -255,14 +255,14 @@ gdb_test "ptype ::C::CClass" "type = cla
gdb_test "ptype ::C::CClass::NestedClass" "type = class C::CClass::NestedClass \{\r\n public:\r\n int y;\r\n\}"
gdb_test "ptype ::C::NestedClass" "No symbol \"NestedClass\" in namespace \"C\"."
gdb_test "ptype C::CClass" "No symbol \"CClass\" in namespace \"C::C\"."
-gdb_test "ptype C::CClass::NestedClass" "No symbol \"CClass\" in namespace \"C::C\"."
+gdb_test "ptype C::CClass::NestedClass" "No type \"CClass\" within class or namespace \"C::C\"."
gdb_test "ptype C::NestedClass" "No symbol \"NestedClass\" in namespace \"C::C\"."
# Tests involving multiple files
gdb_test "ptype OtherFileClass" "type = class C::OtherFileClass \{\r\n public:\r\n int z;\r\n\}"
gdb_test "ptype ::C::OtherFileClass" "type = class C::OtherFileClass \{\r\n public:\r\n int z;\r\n\}"
-gdb_test "ptype C::OtherFileClass" "No symbol \"Class\" in namespace \"C::C\"."
+gdb_test "ptype C::OtherFileClass" "No symbol \"OtherFileClass\" in namespace \"C::C\"."
# Some anonymous namespace tests.