summaryrefslogtreecommitdiff
path: root/gdb/parse.c
diff options
context:
space:
mode:
authorTom Tromey <tromey@redhat.com>2012-06-19 19:49:38 +0000
committerTom Tromey <tromey@redhat.com>2012-06-19 19:49:38 +0000
commitab7b9759a6b8c5d7d591adfa3a617d3d19783802 (patch)
treebe1e8d6f511939869533d2b1d866838271cdd827 /gdb/parse.c
parent5a187cfd259fccb1ec05018ce9289f8a44d5257f (diff)
downloadgdb-ab7b9759a6b8c5d7d591adfa3a617d3d19783802.tar.gz
PR exp/9514:
* parser-defs.h (insert_type, insert_type_address_space): Declare. (push_type_address_space): Remove. * parse.c (insert_into_type_stack): New function. (insert_type): Likewise. (insert_type_address_space): Rename from push_type_address_space. Insert tp_space_identifier. * c-exp.y (ptr_operator): New production. (abs_decl): Use ptr_operator. (space_identifier): Call insert_type_address_space. (ptype): Don't use const_or_volatile_or_space_identifier. (const_or_volatile_noopt): Call insert_type. (conversion_type_id, conversion_declarator): New productions. (operator): Use conversion_type_id. testsuite * gdb.base/whatis.exp: Add tests.
Diffstat (limited to 'gdb/parse.c')
-rw-r--r--gdb/parse.c69
1 files changed, 67 insertions, 2 deletions
diff --git a/gdb/parse.c b/gdb/parse.c
index f54c6f21e79..0d0467d9ce2 100644
--- a/gdb/parse.c
+++ b/gdb/parse.c
@@ -1367,6 +1367,49 @@ check_type_stack_depth (void)
}
}
+/* A helper function for insert_type and insert_type_address_space.
+ This does work of expanding the type stack and inserting the new
+ element, ELEMENT, into the stack at location SLOT. */
+
+static void
+insert_into_type_stack (int slot, union type_stack_elt element)
+{
+ check_type_stack_depth ();
+
+ if (slot < type_stack_depth)
+ memmove (&type_stack[slot + 1], &type_stack[slot],
+ (type_stack_depth - slot) * sizeof (union type_stack_elt));
+ type_stack[slot] = element;
+ ++type_stack_depth;
+}
+
+/* Insert a new type, TP, at the bottom of the type stack. If TP is
+ tp_pointer or tp_reference, it is inserted at the bottom. If TP is
+ a qualifier, it is inserted at slot 1 (just above a previous
+ tp_pointer) if there is anything on the stack, or simply pushed if
+ the stack is empty. Other values for TP are invalid. */
+
+void
+insert_type (enum type_pieces tp)
+{
+ union type_stack_elt element;
+ int slot;
+
+ gdb_assert (tp == tp_pointer || tp == tp_reference
+ || tp == tp_const || tp == tp_volatile);
+
+ /* If there is anything on the stack (we know it will be a
+ tp_pointer), insert the qualifier above it. Otherwise, simply
+ push this on the top of the stack. */
+ if (type_stack_depth && (tp == tp_const || tp == tp_volatile))
+ slot = 1;
+ else
+ slot = 0;
+
+ element.piece = tp;
+ insert_into_type_stack (slot, element);
+}
+
void
push_type (enum type_pieces tp)
{
@@ -1381,10 +1424,32 @@ push_type_int (int n)
type_stack[type_stack_depth++].int_val = n;
}
+/* Insert a tp_space_identifier and the corresponding address space
+ value into the stack. STRING is the name of an address space, as
+ recognized by address_space_name_to_int. If the stack is empty,
+ the new elements are simply pushed. If the stack is not empty,
+ this function assumes that the first item on the stack is a
+ tp_pointer, and the new values are inserted above the first
+ item. */
+
void
-push_type_address_space (char *string)
+insert_type_address_space (char *string)
{
- push_type_int (address_space_name_to_int (parse_gdbarch, string));
+ union type_stack_elt element;
+ int slot;
+
+ /* If there is anything on the stack (we know it will be a
+ tp_pointer), insert the address space qualifier above it.
+ Otherwise, simply push this on the top of the stack. */
+ if (type_stack_depth)
+ slot = 1;
+ else
+ slot = 0;
+
+ element.piece = tp_space_identifier;
+ insert_into_type_stack (slot, element);
+ element.int_val = address_space_name_to_int (parse_gdbarch, string);
+ insert_into_type_stack (slot, element);
}
enum type_pieces