* 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.
This commit is contained in:
parent
d38eb334b6
commit
24daaebce8
5 changed files with 94 additions and 159 deletions
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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) */
|
||||
|
|
167
gdb/parse.c
167
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;
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue