[rfc][06/37] Eliminate builtin_type_ macros: Make OP_COMPLEX type explicit

uweigand
2008-08-31T17:53:29Z

[-- Attachment #1: diff-type-complex --]
[-- Type: text/plain, Size: 3037 bytes --]

Hello,

the OP_COMPLEX expression type was hard-coded to generate a result of
type "builtin_type_f_complex_s16". This should really be determined
by the front-end. The following patch adds the desired result type
as parameter to the OP_COMPLEX expression.

Bye,
Ulrich

ChangeLog:

* expression.h (enum exp_opcode): Document OP_COMPLEX to take
a type parameter as expression element.
* eval.c (evaluate_subexp_standard) [OP_COMPLEX]: Retrieve result
type as expression element.
* f-exp.y: Pass in type when buildin OP_COMPLEX expression.
* parse.c (operator_length_standard): Update length of OP_COMPLEX.

Index: gdb-head/gdb/eval.c
===================================================================
--- gdb-head.orig/gdb/eval.c
+++ gdb-head/gdb/eval.c
@@ -1369,10 +1369,11 @@ evaluate_subexp_standard (struct type *e
case OP_COMPLEX:
/* We have a complex number, There should be 2 floating
point numbers that compose it */
+ (*pos) += 2;
arg1 = evaluate_subexp (NULL_TYPE, exp, pos, noside);
arg2 = evaluate_subexp (NULL_TYPE, exp, pos, noside);

- return value_literal_complex (arg1, arg2, builtin_type_f_complex_s16);
+ return value_literal_complex (arg1, arg2, exp->elts[pc + 1].type);

case STRUCTOP_STRUCT:
tem = longest_to_int (exp->elts[pc + 1].longconst);
Index: gdb-head/gdb/expression.h
===================================================================
--- gdb-head.orig/gdb/expression.h
+++ gdb-head/gdb/expression.h
@@ -193,8 +193,9 @@ enum exp_opcode
indicates that we have found something of the form <name> ( <stuff> ) */
OP_F77_UNDETERMINED_ARGLIST,

- /* The following OP is a special one, it introduces a F77 complex
- literal. It is followed by exactly two args that are doubles. */
+ /* OP_COMPLEX takes a type in the following element, followed by another
+ OP_COMPLEX, making three exp_elements. It is followed by two double
+ args, and converts them into a complex number of the given type. */
OP_COMPLEX,

/* OP_STRING represents a string constant.
Index: gdb-head/gdb/f-exp.y
===================================================================
--- gdb-head.orig/gdb/f-exp.y
+++ gdb-head/gdb/f-exp.y
@@ -328,7 +328,9 @@ complexnum: exp ',' exp
;

exp : '(' complexnum ')'
- { write_exp_elt_opcode(OP_COMPLEX); }
+ { write_exp_elt_opcode(OP_COMPLEX);
+ write_exp_elt_type (parse_f_type->builtin_complex_s16);
+ write_exp_elt_opcode(OP_COMPLEX); }
;

exp : '(' type ')' exp %prec UNARY
Index: gdb-head/gdb/parse.c
===================================================================
--- gdb-head.orig/gdb/parse.c
+++ gdb-head/gdb/parse.c
@@ -767,7 +767,7 @@ operator_length_standard (struct express
break;

case OP_COMPLEX:
- oplen = 1;
+ oplen = 3;
args = 2;
break;