]> git.ipfire.org Git - thirdparty/gcc.git/blob - gcc/fortran/doc/gfc-internals/generating-the-intermediate-language-for-later-stages/converting-expressions-to-tree.rst
sphinx: add missing trailing newline
[thirdparty/gcc.git] / gcc / fortran / doc / gfc-internals / generating-the-intermediate-language-for-later-stages / converting-expressions-to-tree.rst
1 ..
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.
5
6 .. _converting-expressions:
7
8 Converting Expressions to tree
9 ******************************
10
11 Converting expressions to ``tree`` is done by functions called
12 ``gfc_conv_*``.
13
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
18 outer ``gfc_se``.
19
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.
26
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:
31
32 .. code-block:: c++
33
34 gfc_se cont_se;
35 tree cont_var;
36
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);
43
44 Conversion functions which need a ``gfc_se`` structure will have a
45 corresponding argument.
46
47 ``gfc_se`` also contains pointers to a ``gfc_ss`` and a
48 ``gfc_loopinfo`` structure. These are needed by the scalarizer.