aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--gdb/ChangeLog32
-rw-r--r--gdb/expprint.c44
-rw-r--r--gdb/expression.h8
-rw-r--r--gdb/parse.c167
-rw-r--r--gdb/parser-defs.h2
5 files changed, 94 insertions, 159 deletions
diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index 1cefe8b..04798de 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,3 +1,35 @@
+2003-09-23 Paul N. Hilfinger <hilfingr@nile.gnat.com>
+
+ * parser-defs.h (operator_length): Declare.
+
+ * parse.c (length_of_subexp): Use operator_length to get operator
+ lengths and arities for operators.
+ Move most code to new operator_length function.
+ (operator_length): New function absorbing most code from
+ length_of_subexp.
+ (prefixify_subexp): Remove large case and use operator_length instead.
+ (parse_exp_1): Use renamings:
+ dump_prefix_expression => dump_raw_expression and
+ dump_postfix_expression => dump_prefix_expression.
+
+ * expression.h (dump_prefix_expression): Rename to ...
+ (dump_raw_expression): New name.
+ (dump_postfix_expression): Rename to ...
+ (dump_prefix_expression): New name.
+
+ * expprint.c (dump_subexp): Make global. Add comment.
+ Move most existing code to dump_subexp_body.
+ (dump_subexp_body): New function.
+ (dump_prefix_expression): Rename to dump_raw_expression.
+ Remove attempt to print the expression via print_expression: it can't
+ work before the expression is prefixified.
+ (dump_raw_expression): Renamed from dump_prefix_expression.
+ (dump_postfix_expression): Rename to dump_prefix_expression, since
+ that's what it does.
+ Remove 'note' parameter, since this routine must be used on
+ prefixified expression.
+ (dump_prefix_expression): Renamed from dump_postfix_expression.
+
2003-09-22 Jim Blandy <jimb@redhat.com>
* dwarf2read.c (read_array_type): When building the type for an
diff --git a/gdb/expprint.c b/gdb/expprint.c
index a3001b1..8db4c36 100644
--- a/gdb/expprint.c
+++ b/gdb/expprint.c
@@ -548,6 +548,7 @@ op_string (enum exp_opcode op)
form. */
static char *op_name (int opcode);
+static int dump_subexp_body (struct expression *exp, struct ui_file *, int);
static char *
op_name (int opcode)
@@ -737,8 +738,8 @@ op_name (int opcode)
}
void
-dump_prefix_expression (struct expression *exp, struct ui_file *stream,
- char *note)
+dump_raw_expression (struct expression *exp, struct ui_file *stream,
+ char *note)
{
int elt;
char *opcode_name;
@@ -747,11 +748,6 @@ dump_prefix_expression (struct expression *exp, struct ui_file *stream,
fprintf_filtered (stream, "Dump of expression @ ");
gdb_print_host_address (exp, stream);
- fprintf_filtered (stream, ", %s:\nExpression: `", note);
- if (exp->elts[0].opcode != OP_TYPE)
- print_expression (exp, stream);
- else
- fprintf_filtered (stream, "Type printing not yet supported....");
fprintf_filtered (stream, "'\n\tLanguage %s, %d elements, %ld bytes each.\n",
exp->language_defn->la_name, exp->nelts,
(long) sizeof (union exp_element));
@@ -778,10 +774,11 @@ dump_prefix_expression (struct expression *exp, struct ui_file *stream,
}
}
-static int dump_subexp (struct expression *exp, struct ui_file *stream,
- int elt);
+/* Dump the subexpression of prefix expression EXP whose operator is at
+ position ELT onto STREAM. Returns the position of the next
+ subexpression in EXP. */
-static int
+int
dump_subexp (struct expression *exp, struct ui_file *stream, int elt)
{
static int indent = 0;
@@ -796,7 +793,23 @@ dump_subexp (struct expression *exp, struct ui_file *stream, int elt)
fprintf_filtered (stream, "%-20s ", op_name (exp->elts[elt].opcode));
- switch (exp->elts[elt++].opcode)
+ elt = dump_subexp_body (exp, stream, elt);
+
+ indent -= 2;
+
+ return elt;
+}
+
+/* Dump the operands of prefix expression EXP whose opcode is at
+ position ELT onto STREAM. Returns the position of the next
+ subexpression in EXP. */
+
+static int
+dump_subexp_body (struct expression *exp, struct ui_file *stream, int elt)
+{
+ int opcode = exp->elts[elt++].opcode;
+
+ switch (opcode)
{
case TERNOP_COND:
case TERNOP_SLICE:
@@ -914,7 +927,7 @@ dump_subexp (struct expression *exp, struct ui_file *stream, int elt)
break;
case OP_FUNCALL:
{
- int nargs;
+ int i, nargs;
nargs = longest_to_int (exp->elts[elt].longconst);
@@ -1006,20 +1019,17 @@ dump_subexp (struct expression *exp, struct ui_file *stream, int elt)
fprintf_filtered (stream, "Unknown format");
}
- indent -= 2;
-
return elt;
}
void
-dump_postfix_expression (struct expression *exp, struct ui_file *stream,
- char *note)
+dump_prefix_expression (struct expression *exp, struct ui_file *stream)
{
int elt;
fprintf_filtered (stream, "Dump of expression @ ");
gdb_print_host_address (exp, stream);
- fprintf_filtered (stream, ", %s:\nExpression: `", note);
+ fputs_filtered (", after conversion to prefix form:\nExpression: `", stream);
if (exp->elts[0].opcode != OP_TYPE)
print_expression (exp, stream);
else
diff --git a/gdb/expression.h b/gdb/expression.h
index da95fcb..356725e 100644
--- a/gdb/expression.h
+++ b/gdb/expression.h
@@ -393,11 +393,7 @@ extern void print_expression (struct expression *, struct ui_file *);
extern char *op_string (enum exp_opcode);
-extern void dump_prefix_expression (struct expression *,
- struct ui_file *,
- char *);
-extern void dump_postfix_expression (struct expression *,
- struct ui_file *,
- char *);
+extern void dump_raw_expression (struct expression *, struct ui_file *, char *);
+extern void dump_prefix_expression (struct expression *, struct ui_file *);
#endif /* !defined (EXPRESSION_H) */
diff --git a/gdb/parse.c b/gdb/parse.c
index 6a02fe4..6166cf6 100644
--- a/gdb/parse.c
+++ b/gdb/parse.c
@@ -784,18 +784,38 @@ prefixify_expression (struct expression *expr)
prefixify_subexp (temp, expr, inpos, outpos);
}
-/* Return the number of exp_elements in the subexpression of EXPR
- whose last exp_element is at index ENDPOS - 1 in EXPR. */
+/* Return the number of exp_elements in the postfix subexpression
+ of EXPR whose operator is at index ENDPOS - 1 in EXPR. */
int
length_of_subexp (struct expression *expr, int endpos)
{
+ int oplen, args, i;
+
+ operator_length (expr, endpos, &oplen, &args);
+
+ while (args > 0)
+ {
+ oplen += length_of_subexp (expr, endpos - oplen);
+ args--;
+ }
+
+ return oplen;
+}
+
+/* Sets *OPLENP to the length of the operator whose (last) index is
+ ENDPOS - 1 in EXPR, and sets *ARGSP to the number of arguments that
+ operator takes. */
+
+void
+operator_length (struct expression *expr, int endpos, int *oplenp, int *argsp)
+{
int oplen = 1;
int args = 0;
int i;
if (endpos < 1)
- error ("?error in length_of_subexp");
+ error ("?error in operator_length");
i = (int) expr->elts[endpos - 1].opcode;
@@ -916,13 +936,8 @@ length_of_subexp (struct expression *expr, int endpos)
args = 1 + (i < (int) BINOP_END);
}
- while (args > 0)
- {
- oplen += length_of_subexp (expr, endpos - oplen);
- args--;
- }
-
- return oplen;
+ *oplenp = oplen;
+ *argsp = args;
}
/* Copy the subexpression ending just before index INEND in INEXPR
@@ -933,132 +948,13 @@ static void
prefixify_subexp (struct expression *inexpr,
struct expression *outexpr, int inend, int outbeg)
{
- int oplen = 1;
- int args = 0;
+ int oplen;
+ int args;
int i;
int *arglens;
enum exp_opcode opcode;
- /* Compute how long the last operation is (in OPLEN),
- and also how many preceding subexpressions serve as
- arguments for it (in ARGS). */
-
- opcode = inexpr->elts[inend - 1].opcode;
- switch (opcode)
- {
- /* C++ */
- case OP_SCOPE:
- oplen = longest_to_int (inexpr->elts[inend - 2].longconst);
- oplen = 5 + BYTES_TO_EXP_ELEM (oplen + 1);
- break;
-
- case OP_LONG:
- case OP_DOUBLE:
- case OP_VAR_VALUE:
- oplen = 4;
- break;
-
- case OP_TYPE:
- case OP_BOOL:
- case OP_LAST:
- case OP_REGISTER:
- case OP_INTERNALVAR:
- oplen = 3;
- break;
-
- case OP_COMPLEX:
- oplen = 1;
- args = 2;
- break;
-
- case OP_FUNCALL:
- case OP_F77_UNDETERMINED_ARGLIST:
- oplen = 3;
- args = 1 + longest_to_int (inexpr->elts[inend - 2].longconst);
- break;
-
- case OP_OBJC_MSGCALL: /* Objective C message (method) call */
- oplen = 4;
- args = 1 + longest_to_int (inexpr->elts[inend - 2].longconst);
- break;
-
- case UNOP_MIN:
- case UNOP_MAX:
- oplen = 3;
- break;
-
- case UNOP_CAST:
- case UNOP_MEMVAL:
- oplen = 3;
- args = 1;
- break;
-
- case UNOP_ABS:
- case UNOP_CAP:
- case UNOP_CHR:
- case UNOP_FLOAT:
- case UNOP_HIGH:
- case UNOP_ODD:
- case UNOP_ORD:
- case UNOP_TRUNC:
- oplen = 1;
- args = 1;
- break;
-
- case STRUCTOP_STRUCT:
- case STRUCTOP_PTR:
- case OP_LABELED:
- args = 1;
- /* fall through */
- case OP_M2_STRING:
- case OP_STRING:
- case OP_OBJC_NSSTRING: /* Objective C Foundation Class NSString constant */
- case OP_OBJC_SELECTOR: /* Objective C "@selector" pseudo-op */
- case OP_NAME:
- case OP_EXPRSTRING:
- oplen = longest_to_int (inexpr->elts[inend - 2].longconst);
- oplen = 4 + BYTES_TO_EXP_ELEM (oplen + 1);
- break;
-
- case OP_BITSTRING:
- oplen = longest_to_int (inexpr->elts[inend - 2].longconst);
- oplen = (oplen + HOST_CHAR_BIT - 1) / HOST_CHAR_BIT;
- oplen = 4 + BYTES_TO_EXP_ELEM (oplen);
- break;
-
- case OP_ARRAY:
- oplen = 4;
- args = longest_to_int (inexpr->elts[inend - 2].longconst);
- args -= longest_to_int (inexpr->elts[inend - 3].longconst);
- args += 1;
- break;
-
- case TERNOP_COND:
- case TERNOP_SLICE:
- case TERNOP_SLICE_COUNT:
- args = 3;
- break;
-
- case BINOP_ASSIGN_MODIFY:
- oplen = 3;
- args = 2;
- break;
-
- /* Modula-2 */
- case MULTI_SUBSCRIPT:
- oplen = 3;
- args = 1 + longest_to_int (inexpr->elts[inend - 2].longconst);
- break;
-
- /* C++ */
- case OP_THIS:
- case OP_OBJC_SELF:
- oplen = 2;
- break;
-
- default:
- args = 1 + ((int) opcode < (int) BINOP_END);
- }
+ operator_length (inexpr, inend, &oplen, &args);
/* Copy the final operator itself, from the end of the input
to the beginning of the output. */
@@ -1156,14 +1052,13 @@ parse_exp_1 (char **stringptr, struct block *block, int comma)
parser, to a prefix form. */
if (expressiondebug)
- dump_prefix_expression (expout, gdb_stdlog,
- "before conversion to prefix form");
+ dump_raw_expression (expout, gdb_stdlog,
+ "before conversion to prefix form");
prefixify_expression (expout);
if (expressiondebug)
- dump_postfix_expression (expout, gdb_stdlog,
- "after conversion to prefix form");
+ dump_prefix_expression (expout, gdb_stdlog);
*stringptr = lexptr;
return expout;
diff --git a/gdb/parser-defs.h b/gdb/parser-defs.h
index f03f537..54b39a8 100644
--- a/gdb/parser-defs.h
+++ b/gdb/parser-defs.h
@@ -159,6 +159,8 @@ extern int pop_type_int (void);
extern int length_of_subexp (struct expression *, int);
+extern void operator_length (struct expression *, int, int *, int *);
+
extern struct type *follow_types (struct type *);
/* During parsing of a C expression, the pointer to the next character