2 Copyright 1988-2022 Free Software Foundation, Inc.
3 This is part of the GCC manual.
4 For copying conditions, see the copyright.rst file.
6 .. _converting-expressions:
8 Converting Expressions to tree
9 ******************************
11 Converting expressions to ``tree`` is done by functions called
14 The central data structure for a GENERIC expression is the
15 ``gfc_se`` structure. Its ``expr`` member is a ``tree`` that
16 holds the value of the expression. A ``gfc_se`` structure is
17 initialized using ``gfc_init_se`` ; it needs to be embedded in an
20 Evaluating Fortran expressions often require things to be done before
21 and after evaluation of the expression, for example code for the
22 allocation of a temporary variable and its subsequent deallocation.
23 Therefore, ``gfc_se`` contains the members ``pre`` and
24 ``post``, which point to ``stmt_block`` blocks for code that
25 needs to be executed before and after evaluation of the expression.
27 When using a local ``gfc_se`` to convert some expression, it is
28 often necessary to add the generated ``pre`` and ``post`` blocks
29 to the ``pre`` or ``post`` blocks of the outer ``gfc_se``.
30 Code like this (lifted from :samp:`trans-expr.cc`) is fairly common:
37 /* cont_var = is_contiguous (expr); . */
38 gfc_init_se (&cont_se, parmse);
39 gfc_conv_is_contiguous_expr (&cont_se, expr);
40 gfc_add_block_to_block (&se->pre, &(&cont_se)->pre);
41 gfc_add_modify (&se->pre, cont_var, cont_se.expr);
42 gfc_add_block_to_block (&se->pre, &(&cont_se)->post);
44 Conversion functions which need a ``gfc_se`` structure will have a
45 corresponding argument.
47 ``gfc_se`` also contains pointers to a ``gfc_ss`` and a
48 ``gfc_loopinfo`` structure. These are needed by the scalarizer.