This is the mail archive of the
fortran@gcc.gnu.org
mailing list for the GNU Fortran project.
Re: [gfortran] Exponentiation by integral exponents
> Anyway, I tried to implement Andrew's suggestion as a quick'n'dirty
> hack. Right now I get an ICE. What is the correct way to generate the
> equivalent of a typecast in C?
>
> What I tried was this: gfc_conv_power_op has this code:
>
> type = TREE_TYPE (lse.expr);
>
> kind = expr->op1->ts.kind;
> switch (expr->op2->ts.type)
> {
> case BT_INTEGER:
> /* Integer powers are expanded inline as multiplications. */
> gfc_conv_integer_power (se, lse.expr, rse.expr);
> return;
>
> Instead of calling gfc_integer_power and returning, I want to convert
> rse.expr to the type of lse.expr.
Yes.
> So I tried both of the following
> (gfc_conv_expr_type has no explanatory comment, so I'm just guessing
> that this might be the function I'm looking for):
There are some some comments in trans.h, but they do need commenting properly.
I thought I'd put an overview of expression translation somewhere, but maybe
it was only mental notes :)
> gfc_conv_expr_type (&rse, expr->op2, type); // first try
The gfc_conv_expr* functions translate a frontend gfc_expr into gcc trees. The
expression is stored in se->expr. Because fortran expressions can be more
complicated then gcc tree expressions the resulting expression also has two
code blocks associated with it. These are setup/cleanup code that must be
executes immediately before/after the expression is used. The code is held in
se->pre and se->post.
The _val, _type and _reference variants are convenience wrappers around
gfc_conv_expr which ensure the resulting expression meets certain criteria.
Somewhat confusingly gcc expressions, statements and types all use the same
"tree" node data structure.
In this case the expression has already been translated, so this is not the
function you want. We should never translate an expression more than once.
rse.expr is the gcc tree of the operand. The pre chain (rse.pre) has already
been added to the parent se, and gfc_conv_expr_val guarantees the post chain
is empty.
> rse.expr = convert (type, rse.expr); // second try
This is correct. You should then just fall through to the BT_REAL case.
Paul