annotate gcc/fortran/gfc-internals.texi @ 125:2c7bdd5a49f6

supress return with no value, in function returning non-void warning on goto code segment in normal function
author Shinji KONO <kono@ie.u-ryukyu.ac.jp>
date Sun, 01 Apr 2018 14:05:45 +0900
parents 04ced10e8804
children 84e7813d76e9
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
111
kono
parents:
diff changeset
1 \input texinfo @c -*-texinfo-*-
kono
parents:
diff changeset
2 @c %**start of header
kono
parents:
diff changeset
3 @setfilename gfc-internals.info
kono
parents:
diff changeset
4 @set copyrights-gfortran 2007-2017
kono
parents:
diff changeset
5
kono
parents:
diff changeset
6 @include gcc-common.texi
kono
parents:
diff changeset
7
kono
parents:
diff changeset
8 @synindex tp cp
kono
parents:
diff changeset
9
kono
parents:
diff changeset
10 @settitle GNU Fortran Compiler Internals
kono
parents:
diff changeset
11
kono
parents:
diff changeset
12 @c %**end of header
kono
parents:
diff changeset
13
kono
parents:
diff changeset
14 @c Use with @@smallbook.
kono
parents:
diff changeset
15
kono
parents:
diff changeset
16 @c %** start of document
kono
parents:
diff changeset
17
kono
parents:
diff changeset
18 @c Cause even numbered pages to be printed on the left hand side of
kono
parents:
diff changeset
19 @c the page and odd numbered pages to be printed on the right hand
kono
parents:
diff changeset
20 @c side of the page. Using this, you can print on both sides of a
kono
parents:
diff changeset
21 @c sheet of paper and have the text on the same part of the sheet.
kono
parents:
diff changeset
22
kono
parents:
diff changeset
23 @c The text on right hand pages is pushed towards the right hand
kono
parents:
diff changeset
24 @c margin and the text on left hand pages is pushed toward the left
kono
parents:
diff changeset
25 @c hand margin.
kono
parents:
diff changeset
26 @c (To provide the reverse effect, set bindingoffset to -0.75in.)
kono
parents:
diff changeset
27
kono
parents:
diff changeset
28 @c @tex
kono
parents:
diff changeset
29 @c \global\bindingoffset=0.75in
kono
parents:
diff changeset
30 @c \global\normaloffset =0.75in
kono
parents:
diff changeset
31 @c @end tex
kono
parents:
diff changeset
32
kono
parents:
diff changeset
33 @copying
kono
parents:
diff changeset
34 Copyright @copyright{} @value{copyrights-gfortran} Free Software Foundation, Inc.
kono
parents:
diff changeset
35
kono
parents:
diff changeset
36 Permission is granted to copy, distribute and/or modify this document
kono
parents:
diff changeset
37 under the terms of the GNU Free Documentation License, Version 1.3 or
kono
parents:
diff changeset
38 any later version published by the Free Software Foundation; with the
kono
parents:
diff changeset
39 Invariant Sections being ``Funding Free Software'', the Front-Cover
kono
parents:
diff changeset
40 Texts being (a) (see below), and with the Back-Cover Texts being (b)
kono
parents:
diff changeset
41 (see below). A copy of the license is included in the section entitled
kono
parents:
diff changeset
42 ``GNU Free Documentation License''.
kono
parents:
diff changeset
43
kono
parents:
diff changeset
44 (a) The FSF's Front-Cover Text is:
kono
parents:
diff changeset
45
kono
parents:
diff changeset
46 A GNU Manual
kono
parents:
diff changeset
47
kono
parents:
diff changeset
48 (b) The FSF's Back-Cover Text is:
kono
parents:
diff changeset
49
kono
parents:
diff changeset
50 You have freedom to copy and modify this GNU Manual, like GNU
kono
parents:
diff changeset
51 software. Copies published by the Free Software Foundation raise
kono
parents:
diff changeset
52 funds for GNU development.
kono
parents:
diff changeset
53 @end copying
kono
parents:
diff changeset
54
kono
parents:
diff changeset
55 @ifinfo
kono
parents:
diff changeset
56 @dircategory Software development
kono
parents:
diff changeset
57 @direntry
kono
parents:
diff changeset
58 * gfortran: (gfortran). The GNU Fortran Compiler.
kono
parents:
diff changeset
59 @end direntry
kono
parents:
diff changeset
60 This file documents the internals of the GNU Fortran
kono
parents:
diff changeset
61 compiler, (@command{gfortran}).
kono
parents:
diff changeset
62
kono
parents:
diff changeset
63 Published by the Free Software Foundation
kono
parents:
diff changeset
64 51 Franklin Street, Fifth Floor
kono
parents:
diff changeset
65 Boston, MA 02110-1301 USA
kono
parents:
diff changeset
66
kono
parents:
diff changeset
67 @insertcopying
kono
parents:
diff changeset
68 @end ifinfo
kono
parents:
diff changeset
69
kono
parents:
diff changeset
70
kono
parents:
diff changeset
71 @setchapternewpage odd
kono
parents:
diff changeset
72 @titlepage
kono
parents:
diff changeset
73 @title GNU Fortran Internals
kono
parents:
diff changeset
74 @versionsubtitle
kono
parents:
diff changeset
75 @author The @t{gfortran} team
kono
parents:
diff changeset
76 @page
kono
parents:
diff changeset
77 @vskip 0pt plus 1filll
kono
parents:
diff changeset
78 Published by the Free Software Foundation@*
kono
parents:
diff changeset
79 51 Franklin Street, Fifth Floor@*
kono
parents:
diff changeset
80 Boston, MA 02110-1301, USA@*
kono
parents:
diff changeset
81 @c Last printed ??ber, 19??.@*
kono
parents:
diff changeset
82 @c Printed copies are available for $? each.@*
kono
parents:
diff changeset
83 @c ISBN ???
kono
parents:
diff changeset
84 @sp 1
kono
parents:
diff changeset
85 @insertcopying
kono
parents:
diff changeset
86 @end titlepage
kono
parents:
diff changeset
87
kono
parents:
diff changeset
88 @summarycontents
kono
parents:
diff changeset
89 @contents
kono
parents:
diff changeset
90
kono
parents:
diff changeset
91 @page
kono
parents:
diff changeset
92
kono
parents:
diff changeset
93 @c ---------------------------------------------------------------------
kono
parents:
diff changeset
94 @c TexInfo table of contents.
kono
parents:
diff changeset
95 @c ---------------------------------------------------------------------
kono
parents:
diff changeset
96
kono
parents:
diff changeset
97 @ifnottex
kono
parents:
diff changeset
98 @node Top
kono
parents:
diff changeset
99 @top Introduction
kono
parents:
diff changeset
100 @cindex Introduction
kono
parents:
diff changeset
101
kono
parents:
diff changeset
102 This manual documents the internals of @command{gfortran},
kono
parents:
diff changeset
103 the GNU Fortran compiler.
kono
parents:
diff changeset
104
kono
parents:
diff changeset
105 @ifset DEVELOPMENT
kono
parents:
diff changeset
106 @emph{Warning:} This document, and the compiler it describes, are still
kono
parents:
diff changeset
107 under development. While efforts are made to keep it up-to-date, it might
kono
parents:
diff changeset
108 not accurately reflect the status of the most recent GNU Fortran compiler.
kono
parents:
diff changeset
109 @end ifset
kono
parents:
diff changeset
110
kono
parents:
diff changeset
111 @comment
kono
parents:
diff changeset
112 @comment When you add a new menu item, please keep the right hand
kono
parents:
diff changeset
113 @comment aligned to the same column. Do not use tabs. This provides
kono
parents:
diff changeset
114 @comment better formatting.
kono
parents:
diff changeset
115 @comment
kono
parents:
diff changeset
116 @menu
kono
parents:
diff changeset
117 * Introduction:: About this manual.
kono
parents:
diff changeset
118 * User Interface:: Code that Interacts with the User.
kono
parents:
diff changeset
119 * Frontend Data Structures::
kono
parents:
diff changeset
120 Data structures used by the frontend
kono
parents:
diff changeset
121 * Object Orientation:: Internals of Fortran 2003 OOP features.
kono
parents:
diff changeset
122 * LibGFortran:: The LibGFortran Runtime Library.
kono
parents:
diff changeset
123 * GNU Free Documentation License::
kono
parents:
diff changeset
124 How you can copy and share this manual.
kono
parents:
diff changeset
125 * Index:: Index of this documentation.
kono
parents:
diff changeset
126 @end menu
kono
parents:
diff changeset
127 @end ifnottex
kono
parents:
diff changeset
128
kono
parents:
diff changeset
129 @c ---------------------------------------------------------------------
kono
parents:
diff changeset
130 @c Introduction
kono
parents:
diff changeset
131 @c ---------------------------------------------------------------------
kono
parents:
diff changeset
132
kono
parents:
diff changeset
133 @node Introduction
kono
parents:
diff changeset
134 @chapter Introduction
kono
parents:
diff changeset
135
kono
parents:
diff changeset
136 @c The following duplicates the text on the TexInfo table of contents.
kono
parents:
diff changeset
137 @iftex
kono
parents:
diff changeset
138 This manual documents the internals of @command{gfortran}, the GNU Fortran
kono
parents:
diff changeset
139 compiler.
kono
parents:
diff changeset
140
kono
parents:
diff changeset
141 @ifset DEVELOPMENT
kono
parents:
diff changeset
142 @emph{Warning:} This document, and the compiler it describes, are still
kono
parents:
diff changeset
143 under development. While efforts are made to keep it up-to-date, it
kono
parents:
diff changeset
144 might not accurately reflect the status of the most recent GNU Fortran
kono
parents:
diff changeset
145 compiler.
kono
parents:
diff changeset
146 @end ifset
kono
parents:
diff changeset
147 @end iftex
kono
parents:
diff changeset
148
kono
parents:
diff changeset
149 At present, this manual is very much a work in progress, containing
kono
parents:
diff changeset
150 miscellaneous notes about the internals of the compiler. It is hoped
kono
parents:
diff changeset
151 that at some point in the future it will become a reasonably complete
kono
parents:
diff changeset
152 guide; in the interim, GNU Fortran developers are strongly encouraged to
kono
parents:
diff changeset
153 contribute to it as a way of keeping notes while working on the
kono
parents:
diff changeset
154 compiler.
kono
parents:
diff changeset
155
kono
parents:
diff changeset
156
kono
parents:
diff changeset
157 @c ---------------------------------------------------------------------
kono
parents:
diff changeset
158 @c Code that Interacts with the User
kono
parents:
diff changeset
159 @c ---------------------------------------------------------------------
kono
parents:
diff changeset
160
kono
parents:
diff changeset
161 @node User Interface
kono
parents:
diff changeset
162 @chapter Code that Interacts with the User
kono
parents:
diff changeset
163
kono
parents:
diff changeset
164 @menu
kono
parents:
diff changeset
165 * Command-Line Options:: Command-Line Options.
kono
parents:
diff changeset
166 * Error Handling:: Error Handling.
kono
parents:
diff changeset
167 @end menu
kono
parents:
diff changeset
168
kono
parents:
diff changeset
169
kono
parents:
diff changeset
170 @c ---------------------------------------------------------------------
kono
parents:
diff changeset
171 @c Command-Line Options
kono
parents:
diff changeset
172 @c ---------------------------------------------------------------------
kono
parents:
diff changeset
173
kono
parents:
diff changeset
174 @node Command-Line Options
kono
parents:
diff changeset
175 @section Command-Line Options
kono
parents:
diff changeset
176
kono
parents:
diff changeset
177 Command-line options for @command{gfortran} involve four interrelated
kono
parents:
diff changeset
178 pieces within the Fortran compiler code.
kono
parents:
diff changeset
179
kono
parents:
diff changeset
180 The relevant command-line flag is defined in @file{lang.opt}, according
kono
parents:
diff changeset
181 to the documentation in @ref{Options,, Options, gccint, GNU Compiler
kono
parents:
diff changeset
182 Collection Internals}. This is then processed by the overall GCC
kono
parents:
diff changeset
183 machinery to create the code that enables @command{gfortran} and
kono
parents:
diff changeset
184 @command{gcc} to recognize the option in the command-line arguments and
kono
parents:
diff changeset
185 call the relevant handler function.
kono
parents:
diff changeset
186
kono
parents:
diff changeset
187 This generated code calls the @code{gfc_handle_option} code in
kono
parents:
diff changeset
188 @file{options.c} with an enumerator variable indicating which option is
kono
parents:
diff changeset
189 to be processed, and the relevant integer or string values associated
kono
parents:
diff changeset
190 with that option flag. Typically, @code{gfc_handle_option} uses these
kono
parents:
diff changeset
191 arguments to set global flags which record the option states.
kono
parents:
diff changeset
192
kono
parents:
diff changeset
193 The global flags that record the option states are stored in the
kono
parents:
diff changeset
194 @code{gfc_option_t} struct, which is defined in @file{gfortran.h}.
kono
parents:
diff changeset
195 Before the options are processed, initial values for these flags are set
kono
parents:
diff changeset
196 in @code{gfc_init_option} in @file{options.c}; these become the default
kono
parents:
diff changeset
197 values for the options.
kono
parents:
diff changeset
198
kono
parents:
diff changeset
199
kono
parents:
diff changeset
200
kono
parents:
diff changeset
201 @c ---------------------------------------------------------------------
kono
parents:
diff changeset
202 @c Error Handling
kono
parents:
diff changeset
203 @c ---------------------------------------------------------------------
kono
parents:
diff changeset
204
kono
parents:
diff changeset
205 @node Error Handling
kono
parents:
diff changeset
206 @section Error Handling
kono
parents:
diff changeset
207
kono
parents:
diff changeset
208 The GNU Fortran compiler's parser operates by testing each piece of
kono
parents:
diff changeset
209 source code against a variety of matchers. In some cases, if these
kono
parents:
diff changeset
210 matchers do not match the source code, they will store an error message
kono
parents:
diff changeset
211 in a buffer. If the parser later finds a matcher that does correctly
kono
parents:
diff changeset
212 match the source code, then the buffered error is discarded. However,
kono
parents:
diff changeset
213 if the parser cannot find a match, then the buffered error message is
kono
parents:
diff changeset
214 reported to the user. This enables the compiler to provide more
kono
parents:
diff changeset
215 meaningful error messages even in the many cases where (erroneous)
kono
parents:
diff changeset
216 Fortran syntax is ambiguous due to things like the absence of reserved
kono
parents:
diff changeset
217 keywords.
kono
parents:
diff changeset
218
kono
parents:
diff changeset
219 As an example of how this works, consider the following line:
kono
parents:
diff changeset
220 @smallexample
kono
parents:
diff changeset
221 IF = 3
kono
parents:
diff changeset
222 @end smallexample
kono
parents:
diff changeset
223 Hypothetically, this may get passed to the matcher for an @code{IF}
kono
parents:
diff changeset
224 statement. Since this could plausibly be an erroneous @code{IF}
kono
parents:
diff changeset
225 statement, the matcher will buffer an error message reporting the
kono
parents:
diff changeset
226 absence of an expected @samp{(} following an @code{IF}. Since no
kono
parents:
diff changeset
227 matchers reported an error-free match, however, the parser will also try
kono
parents:
diff changeset
228 matching this against a variable assignment. When @code{IF} is a valid
kono
parents:
diff changeset
229 variable, this will be parsed as an assignment statement, and the error
kono
parents:
diff changeset
230 discarded. However, when @code{IF} is not a valid variable, this
kono
parents:
diff changeset
231 buffered error message will be reported to the user.
kono
parents:
diff changeset
232
kono
parents:
diff changeset
233 The error handling code is implemented in @file{error.c}. Errors are
kono
parents:
diff changeset
234 normally entered into the buffer with the @code{gfc_error} function.
kono
parents:
diff changeset
235 Warnings go through a similar buffering process, and are entered into
kono
parents:
diff changeset
236 the buffer with @code{gfc_warning}. There is also a special-purpose
kono
parents:
diff changeset
237 function, @code{gfc_notify_std}, for things which have an error/warning
kono
parents:
diff changeset
238 status that depends on the currently-selected language standard.
kono
parents:
diff changeset
239
kono
parents:
diff changeset
240 The @code{gfc_error_check} function checks the buffer for errors,
kono
parents:
diff changeset
241 reports the error message to the user if one exists, clears the buffer,
kono
parents:
diff changeset
242 and returns a flag to the user indicating whether or not an error
kono
parents:
diff changeset
243 existed. To check the state of the buffer without changing its state or
kono
parents:
diff changeset
244 reporting the errors, the @code{gfc_error_flag_test} function can be
kono
parents:
diff changeset
245 used. The @code{gfc_clear_error} function will clear out any errors in
kono
parents:
diff changeset
246 the buffer, without reporting them. The @code{gfc_warning_check} and
kono
parents:
diff changeset
247 @code{gfc_clear_warning} functions provide equivalent functionality for
kono
parents:
diff changeset
248 the warning buffer.
kono
parents:
diff changeset
249
kono
parents:
diff changeset
250 Only one error and one warning can be in the buffers at a time, and
kono
parents:
diff changeset
251 buffering another will overwrite the existing one. In cases where one
kono
parents:
diff changeset
252 may wish to work on a smaller piece of source code without disturbing an
kono
parents:
diff changeset
253 existing error state, the @code{gfc_push_error}, @code{gfc_pop_error},
kono
parents:
diff changeset
254 and @code{gfc_free_error} mechanism exists to implement a stack for the
kono
parents:
diff changeset
255 error buffer.
kono
parents:
diff changeset
256
kono
parents:
diff changeset
257 For cases where an error or warning should be reported immediately
kono
parents:
diff changeset
258 rather than buffered, the @code{gfc_error_now} and
kono
parents:
diff changeset
259 @code{gfc_warning_now} functions can be used. Normally, the compiler
kono
parents:
diff changeset
260 will continue attempting to parse the program after an error has
kono
parents:
diff changeset
261 occurred, but if this is not appropriate, the @code{gfc_fatal_error}
kono
parents:
diff changeset
262 function should be used instead. For errors that are always the result
kono
parents:
diff changeset
263 of a bug somewhere in the compiler, the @code{gfc_internal_error}
kono
parents:
diff changeset
264 function should be used.
kono
parents:
diff changeset
265
kono
parents:
diff changeset
266 The syntax for the strings used to produce the error/warning message in
kono
parents:
diff changeset
267 the various error and warning functions is similar to the @code{printf}
kono
parents:
diff changeset
268 syntax, with @samp{%}-escapes to insert variable values. The details,
kono
parents:
diff changeset
269 and the allowable codes, are documented in the @code{error_print}
kono
parents:
diff changeset
270 function in @file{error.c}.
kono
parents:
diff changeset
271
kono
parents:
diff changeset
272 @c ---------------------------------------------------------------------
kono
parents:
diff changeset
273 @c Frontend Data Structures
kono
parents:
diff changeset
274 @c ---------------------------------------------------------------------
kono
parents:
diff changeset
275
kono
parents:
diff changeset
276 @node Frontend Data Structures
kono
parents:
diff changeset
277 @chapter Frontend Data Structures
kono
parents:
diff changeset
278 @cindex data structures
kono
parents:
diff changeset
279
kono
parents:
diff changeset
280 This chapter should describe the details necessary to understand how
kono
parents:
diff changeset
281 the various @code{gfc_*} data are used and interact. In general it is
kono
parents:
diff changeset
282 advisable to read the code in @file{dump-parse-tree.c} as its routines
kono
parents:
diff changeset
283 should exhaust all possible valid combinations of content for these
kono
parents:
diff changeset
284 structures.
kono
parents:
diff changeset
285
kono
parents:
diff changeset
286 @menu
kono
parents:
diff changeset
287 * gfc_code:: Representation of Executable Statements.
kono
parents:
diff changeset
288 * gfc_expr:: Representation of Values and Expressions.
kono
parents:
diff changeset
289 @end menu
kono
parents:
diff changeset
290
kono
parents:
diff changeset
291
kono
parents:
diff changeset
292 @c gfc_code
kono
parents:
diff changeset
293 @c --------
kono
parents:
diff changeset
294
kono
parents:
diff changeset
295 @node gfc_code
kono
parents:
diff changeset
296 @section @code{gfc_code}
kono
parents:
diff changeset
297 @cindex statement chaining
kono
parents:
diff changeset
298 @tindex @code{gfc_code}
kono
parents:
diff changeset
299 @tindex @code{struct gfc_code}
kono
parents:
diff changeset
300
kono
parents:
diff changeset
301 The executable statements in a program unit are represented by a
kono
parents:
diff changeset
302 nested chain of @code{gfc_code} structures. The type of statement is
kono
parents:
diff changeset
303 identified by the @code{op} member of the structure, the different
kono
parents:
diff changeset
304 possible values are enumerated in @code{gfc_exec_op}. A special
kono
parents:
diff changeset
305 member of this @code{enum} is @code{EXEC_NOP} which is used to
kono
parents:
diff changeset
306 represent the various @code{END} statements if they carry a label.
kono
parents:
diff changeset
307 Depending on the type of statement some of the other fields will be
kono
parents:
diff changeset
308 filled in. Fields that are generally applicable are the @code{next}
kono
parents:
diff changeset
309 and @code{here} fields. The former points to the next statement in
kono
parents:
diff changeset
310 the current block or is @code{NULL} if the current statement is the
kono
parents:
diff changeset
311 last in a block, @code{here} points to the statement label of the
kono
parents:
diff changeset
312 current statement.
kono
parents:
diff changeset
313
kono
parents:
diff changeset
314 If the current statement is one of @code{IF}, @code{DO}, @code{SELECT}
kono
parents:
diff changeset
315 it starts a block, i.e.@: a nested level in the program. In order to
kono
parents:
diff changeset
316 represent this, the @code{block} member is set to point to a
kono
parents:
diff changeset
317 @code{gfc_code} structure whose @code{next} member starts the chain of
kono
parents:
diff changeset
318 statements inside the block; this structure's @code{op} member should be set to
kono
parents:
diff changeset
319 the same value as the parent structure's @code{op} member. The @code{SELECT}
kono
parents:
diff changeset
320 and @code{IF} statements may contain various blocks (the chain of @code{ELSE IF}
kono
parents:
diff changeset
321 and @code{ELSE} blocks or the various @code{CASE}s, respectively). These chains
kono
parents:
diff changeset
322 are linked-lists formed by the @code{block} members.
kono
parents:
diff changeset
323
kono
parents:
diff changeset
324 Consider the following example code:
kono
parents:
diff changeset
325
kono
parents:
diff changeset
326 @example
kono
parents:
diff changeset
327 IF (foo < 20) THEN
kono
parents:
diff changeset
328 PRINT *, "Too small"
kono
parents:
diff changeset
329 foo = 20
kono
parents:
diff changeset
330 ELSEIF (foo > 50) THEN
kono
parents:
diff changeset
331 PRINT *, "Too large"
kono
parents:
diff changeset
332 foo = 50
kono
parents:
diff changeset
333 ELSE
kono
parents:
diff changeset
334 PRINT *, "Good"
kono
parents:
diff changeset
335 END IF
kono
parents:
diff changeset
336 @end example
kono
parents:
diff changeset
337
kono
parents:
diff changeset
338 This statement-block will be represented in the internal gfortran tree as
kono
parents:
diff changeset
339 follows, were the horizontal link-chains are those induced by the @code{next}
kono
parents:
diff changeset
340 members and vertical links down are those of @code{block}. @samp{==|} and
kono
parents:
diff changeset
341 @samp{--|} mean @code{NULL} pointers to mark the end of a chain:
kono
parents:
diff changeset
342
kono
parents:
diff changeset
343 @example
kono
parents:
diff changeset
344 ... ==> IF ==> ...
kono
parents:
diff changeset
345 |
kono
parents:
diff changeset
346 +--> IF foo < 20 ==> PRINT *, "Too small" ==> foo = 20 ==|
kono
parents:
diff changeset
347 |
kono
parents:
diff changeset
348 +--> IF foo > 50 ==> PRINT *, "Too large" ==> foo = 50 ==|
kono
parents:
diff changeset
349 |
kono
parents:
diff changeset
350 +--> ELSE ==> PRINT *, "Good" ==|
kono
parents:
diff changeset
351 |
kono
parents:
diff changeset
352 +--|
kono
parents:
diff changeset
353 @end example
kono
parents:
diff changeset
354
kono
parents:
diff changeset
355
kono
parents:
diff changeset
356 @subsection IF Blocks
kono
parents:
diff changeset
357
kono
parents:
diff changeset
358 Conditionals are represented by @code{gfc_code} structures with their
kono
parents:
diff changeset
359 @code{op} member set to @code{EXEC_IF}. This structure's @code{block}
kono
parents:
diff changeset
360 member must point to another @code{gfc_code} node that is the header of the
kono
parents:
diff changeset
361 if-block. This header's @code{op} member must be set to @code{EXEC_IF}, too,
kono
parents:
diff changeset
362 its @code{expr} member holds the condition to check for, and its @code{next}
kono
parents:
diff changeset
363 should point to the code-chain of the statements to execute if the condition is
kono
parents:
diff changeset
364 true.
kono
parents:
diff changeset
365
kono
parents:
diff changeset
366 If in addition an @code{ELSEIF} or @code{ELSE} block is present, the
kono
parents:
diff changeset
367 @code{block} member of the if-block-header node points to yet another
kono
parents:
diff changeset
368 @code{gfc_code} structure that is the header of the elseif- or else-block. Its
kono
parents:
diff changeset
369 structure is identical to that of the if-block-header, except that in case of an
kono
parents:
diff changeset
370 @code{ELSE} block without a new condition the @code{expr} member should be
kono
parents:
diff changeset
371 @code{NULL}. This block can itself have its @code{block} member point to the
kono
parents:
diff changeset
372 next @code{ELSEIF} or @code{ELSE} block if there's a chain of them.
kono
parents:
diff changeset
373
kono
parents:
diff changeset
374
kono
parents:
diff changeset
375 @subsection Loops
kono
parents:
diff changeset
376
kono
parents:
diff changeset
377 @code{DO} loops are stored in the tree as @code{gfc_code} nodes with their
kono
parents:
diff changeset
378 @code{op} set to @code{EXEC_DO} for a @code{DO} loop with iterator variable and
kono
parents:
diff changeset
379 to @code{EXEC_DO_WHILE} for infinite @code{DO}s and @code{DO WHILE} blocks.
kono
parents:
diff changeset
380 Their @code{block} member should point to a @code{gfc_code} structure heading
kono
parents:
diff changeset
381 the code-chain of the loop body; its @code{op} member should be set to
kono
parents:
diff changeset
382 @code{EXEC_DO} or @code{EXEC_DO_WHILE}, too, respectively.
kono
parents:
diff changeset
383
kono
parents:
diff changeset
384 For @code{DO WHILE} loops, the loop condition is stored on the top
kono
parents:
diff changeset
385 @code{gfc_code} structure's @code{expr} member; @code{DO} forever loops are
kono
parents:
diff changeset
386 simply @code{DO WHILE} loops with a constant @code{.TRUE.} loop condition in
kono
parents:
diff changeset
387 the internal representation.
kono
parents:
diff changeset
388
kono
parents:
diff changeset
389 Similarly, @code{DO} loops with an iterator have instead of the condition their
kono
parents:
diff changeset
390 @code{ext.iterator} member set to the correct values for the loop iterator
kono
parents:
diff changeset
391 variable and its range.
kono
parents:
diff changeset
392
kono
parents:
diff changeset
393
kono
parents:
diff changeset
394 @subsection @code{SELECT} Statements
kono
parents:
diff changeset
395
kono
parents:
diff changeset
396 A @code{SELECT} block is introduced by a @code{gfc_code} structure with an
kono
parents:
diff changeset
397 @code{op} member of @code{EXEC_SELECT} and @code{expr} containing the expression
kono
parents:
diff changeset
398 to evaluate and test. Its @code{block} member starts a list of @code{gfc_code}
kono
parents:
diff changeset
399 structures linked together by their @code{block} members that stores the various
kono
parents:
diff changeset
400 @code{CASE} parts.
kono
parents:
diff changeset
401
kono
parents:
diff changeset
402 Each @code{CASE} node has its @code{op} member set to @code{EXEC_SELECT}, too,
kono
parents:
diff changeset
403 its @code{next} member points to the code-chain to be executed in the current
kono
parents:
diff changeset
404 case-block, and @code{extx.case_list} contains the case-values this block
kono
parents:
diff changeset
405 corresponds to. The @code{block} member links to the next case in the list.
kono
parents:
diff changeset
406
kono
parents:
diff changeset
407
kono
parents:
diff changeset
408 @subsection @code{BLOCK} and @code{ASSOCIATE}
kono
parents:
diff changeset
409
kono
parents:
diff changeset
410 The code related to a @code{BLOCK} statement is stored inside an
kono
parents:
diff changeset
411 @code{gfc_code} structure (say @var{c})
kono
parents:
diff changeset
412 with @code{c.op} set to @code{EXEC_BLOCK}. The
kono
parents:
diff changeset
413 @code{gfc_namespace} holding the locally defined variables of the
kono
parents:
diff changeset
414 @code{BLOCK} is stored in @code{c.ext.block.ns}. The code inside the
kono
parents:
diff changeset
415 construct is in @code{c.code}.
kono
parents:
diff changeset
416
kono
parents:
diff changeset
417 @code{ASSOCIATE} constructs are based on @code{BLOCK} and thus also have
kono
parents:
diff changeset
418 the internal storage structure described above (including @code{EXEC_BLOCK}).
kono
parents:
diff changeset
419 However, for them @code{c.ext.block.assoc} is set additionally and points
kono
parents:
diff changeset
420 to a linked list of @code{gfc_association_list} structures. Those
kono
parents:
diff changeset
421 structures basically store a link of associate-names to target expressions.
kono
parents:
diff changeset
422 The associate-names themselves are still also added to the @code{BLOCK}'s
kono
parents:
diff changeset
423 namespace as ordinary symbols, but they have their @code{gfc_symbol}'s
kono
parents:
diff changeset
424 member @code{assoc} set also pointing to the association-list structure.
kono
parents:
diff changeset
425 This way associate-names can be distinguished from ordinary variables
kono
parents:
diff changeset
426 and their target expressions identified.
kono
parents:
diff changeset
427
kono
parents:
diff changeset
428 For association to expressions (as opposed to variables), at the very beginning
kono
parents:
diff changeset
429 of the @code{BLOCK} construct assignments are automatically generated to
kono
parents:
diff changeset
430 set the corresponding variables to their target expressions' values, and
kono
parents:
diff changeset
431 later on the compiler simply disallows using such associate-names in contexts
kono
parents:
diff changeset
432 that may change the value.
kono
parents:
diff changeset
433
kono
parents:
diff changeset
434
kono
parents:
diff changeset
435 @c gfc_expr
kono
parents:
diff changeset
436 @c --------
kono
parents:
diff changeset
437
kono
parents:
diff changeset
438 @node gfc_expr
kono
parents:
diff changeset
439 @section @code{gfc_expr}
kono
parents:
diff changeset
440 @tindex @code{gfc_expr}
kono
parents:
diff changeset
441 @tindex @code{struct gfc_expr}
kono
parents:
diff changeset
442
kono
parents:
diff changeset
443 Expressions and ``values'', including constants, variable-, array- and
kono
parents:
diff changeset
444 component-references as well as complex expressions consisting of operators and
kono
parents:
diff changeset
445 function calls are internally represented as one or a whole tree of
kono
parents:
diff changeset
446 @code{gfc_expr} objects. The member @code{expr_type} specifies the overall
kono
parents:
diff changeset
447 type of an expression (for instance, @code{EXPR_CONSTANT} for constants or
kono
parents:
diff changeset
448 @code{EXPR_VARIABLE} for variable references). The members @code{ts} and
kono
parents:
diff changeset
449 @code{rank} as well as @code{shape}, which can be @code{NULL}, specify
kono
parents:
diff changeset
450 the type, rank and, if applicable, shape of the whole expression or expression
kono
parents:
diff changeset
451 tree of which the current structure is the root. @code{where} is the locus of
kono
parents:
diff changeset
452 this expression in the source code.
kono
parents:
diff changeset
453
kono
parents:
diff changeset
454 Depending on the flavor of the expression being described by the object
kono
parents:
diff changeset
455 (that is, the value of its @code{expr_type} member), the corresponding structure
kono
parents:
diff changeset
456 in the @code{value} union will usually contain additional data describing the
kono
parents:
diff changeset
457 expression's value in a type-specific manner. The @code{ref} member is used to
kono
parents:
diff changeset
458 build chains of (array-, component- and substring-) references if the expression
kono
parents:
diff changeset
459 in question contains such references, see below for details.
kono
parents:
diff changeset
460
kono
parents:
diff changeset
461
kono
parents:
diff changeset
462 @subsection Constants
kono
parents:
diff changeset
463
kono
parents:
diff changeset
464 Scalar constants are represented by @code{gfc_expr} nodes with their
kono
parents:
diff changeset
465 @code{expr_type} set to @code{EXPR_CONSTANT}. The constant's value shall
kono
parents:
diff changeset
466 already be known at compile-time and is stored in the @code{logical},
kono
parents:
diff changeset
467 @code{integer}, @code{real}, @code{complex} or @code{character} struct inside
kono
parents:
diff changeset
468 @code{value}, depending on the constant's type specification.
kono
parents:
diff changeset
469
kono
parents:
diff changeset
470
kono
parents:
diff changeset
471 @subsection Operators
kono
parents:
diff changeset
472
kono
parents:
diff changeset
473 Operator-expressions are expressions that are the result of the execution of
kono
parents:
diff changeset
474 some operator on one or two operands. The expressions have an @code{expr_type}
kono
parents:
diff changeset
475 of @code{EXPR_OP}. Their @code{value.op} structure contains additional data.
kono
parents:
diff changeset
476
kono
parents:
diff changeset
477 @code{op1} and optionally @code{op2} if the operator is binary point to the
kono
parents:
diff changeset
478 two operands, and @code{operator} or @code{uop} describe the operator that
kono
parents:
diff changeset
479 should be evaluated on these operands, where @code{uop} describes a user-defined
kono
parents:
diff changeset
480 operator.
kono
parents:
diff changeset
481
kono
parents:
diff changeset
482
kono
parents:
diff changeset
483 @subsection Function Calls
kono
parents:
diff changeset
484
kono
parents:
diff changeset
485 If the expression is the return value of a function-call, its @code{expr_type}
kono
parents:
diff changeset
486 is set to @code{EXPR_FUNCTION}, and @code{symtree} must point to the symtree
kono
parents:
diff changeset
487 identifying the function to be called. @code{value.function.actual} holds the
kono
parents:
diff changeset
488 actual arguments given to the function as a linked list of
kono
parents:
diff changeset
489 @code{gfc_actual_arglist} nodes.
kono
parents:
diff changeset
490
kono
parents:
diff changeset
491 The other members of @code{value.function} describe the function being called
kono
parents:
diff changeset
492 in more detail, containing a link to the intrinsic symbol or user-defined
kono
parents:
diff changeset
493 function symbol if the call is to an intrinsic or external function,
kono
parents:
diff changeset
494 respectively. These values are determined during resolution-phase from the
kono
parents:
diff changeset
495 structure's @code{symtree} member.
kono
parents:
diff changeset
496
kono
parents:
diff changeset
497 A special case of function calls are ``component calls'' to type-bound
kono
parents:
diff changeset
498 procedures; those have the @code{expr_type} @code{EXPR_COMPCALL} with
kono
parents:
diff changeset
499 @code{value.compcall} containing the argument list and the procedure called,
kono
parents:
diff changeset
500 while @code{symtree} and @code{ref} describe the object on which the procedure
kono
parents:
diff changeset
501 was called in the same way as a @code{EXPR_VARIABLE} expression would.
kono
parents:
diff changeset
502 @xref{Type-bound Procedures}.
kono
parents:
diff changeset
503
kono
parents:
diff changeset
504
kono
parents:
diff changeset
505 @subsection Array- and Structure-Constructors
kono
parents:
diff changeset
506
kono
parents:
diff changeset
507 Array- and structure-constructors (one could probably call them ``array-'' and
kono
parents:
diff changeset
508 ``derived-type constants'') are @code{gfc_expr} structures with their
kono
parents:
diff changeset
509 @code{expr_type} member set to @code{EXPR_ARRAY} or @code{EXPR_STRUCTURE},
kono
parents:
diff changeset
510 respectively. For structure constructors, @code{symtree} points to the
kono
parents:
diff changeset
511 derived-type symbol for the type being constructed.
kono
parents:
diff changeset
512
kono
parents:
diff changeset
513 The values for initializing each array element or structure component are
kono
parents:
diff changeset
514 stored as linked-list of @code{gfc_constructor} nodes in the
kono
parents:
diff changeset
515 @code{value.constructor} member.
kono
parents:
diff changeset
516
kono
parents:
diff changeset
517
kono
parents:
diff changeset
518 @subsection Null
kono
parents:
diff changeset
519
kono
parents:
diff changeset
520 @code{NULL} is a special value for pointers; it can be of different base types.
kono
parents:
diff changeset
521 Such a @code{NULL} value is represented in the internal tree by a
kono
parents:
diff changeset
522 @code{gfc_expr} node with @code{expr_type} @code{EXPR_NULL}. If the base type
kono
parents:
diff changeset
523 of the @code{NULL} expression is known, it is stored in @code{ts} (that's for
kono
parents:
diff changeset
524 instance the case for default-initializers of @code{ALLOCATABLE} components),
kono
parents:
diff changeset
525 but this member can also be set to @code{BT_UNKNOWN} if the information is not
kono
parents:
diff changeset
526 available (for instance, when the expression is a pointer-initializer
kono
parents:
diff changeset
527 @code{NULL()}).
kono
parents:
diff changeset
528
kono
parents:
diff changeset
529
kono
parents:
diff changeset
530 @subsection Variables and Reference Expressions
kono
parents:
diff changeset
531
kono
parents:
diff changeset
532 Variable references are @code{gfc_expr} structures with their @code{expr_type}
kono
parents:
diff changeset
533 set to @code{EXPR_VARIABLE}; their @code{symtree} should point to the variable
kono
parents:
diff changeset
534 that is referenced.
kono
parents:
diff changeset
535
kono
parents:
diff changeset
536 For this type of expression, it's also possible to chain array-, component-
kono
parents:
diff changeset
537 or substring-references to the original expression to get something like
kono
parents:
diff changeset
538 @samp{struct%component(2:5)}, where @code{component} is either an array or
kono
parents:
diff changeset
539 a @code{CHARACTER} member of @code{struct} that is of some derived-type. Such a
kono
parents:
diff changeset
540 chain of references is achieved by a linked list headed by @code{ref} of the
kono
parents:
diff changeset
541 @code{gfc_expr} node. For the example above it would be (@samp{==|} is the
kono
parents:
diff changeset
542 last @code{NULL} pointer):
kono
parents:
diff changeset
543
kono
parents:
diff changeset
544 @smallexample
kono
parents:
diff changeset
545 EXPR_VARIABLE(struct) ==> REF_COMPONENT(component) ==> REF_ARRAY(2:5) ==|
kono
parents:
diff changeset
546 @end smallexample
kono
parents:
diff changeset
547
kono
parents:
diff changeset
548 If @code{component} is a string rather than an array, the last element would be
kono
parents:
diff changeset
549 a @code{REF_SUBSTRING} reference, of course. If the variable itself or some
kono
parents:
diff changeset
550 component referenced is an array and the expression should reference the whole
kono
parents:
diff changeset
551 array rather than being followed by an array-element or -section reference, a
kono
parents:
diff changeset
552 @code{REF_ARRAY} reference must be built as the last element in the chain with
kono
parents:
diff changeset
553 an array-reference type of @code{AR_FULL}. Consider this example code:
kono
parents:
diff changeset
554
kono
parents:
diff changeset
555 @smallexample
kono
parents:
diff changeset
556 TYPE :: mytype
kono
parents:
diff changeset
557 INTEGER :: array(42)
kono
parents:
diff changeset
558 END TYPE mytype
kono
parents:
diff changeset
559
kono
parents:
diff changeset
560 TYPE(mytype) :: variable
kono
parents:
diff changeset
561 INTEGER :: local_array(5)
kono
parents:
diff changeset
562
kono
parents:
diff changeset
563 CALL do_something (variable%array, local_array)
kono
parents:
diff changeset
564 @end smallexample
kono
parents:
diff changeset
565
kono
parents:
diff changeset
566 The @code{gfc_expr} nodes representing the arguments to the @samp{do_something}
kono
parents:
diff changeset
567 call will have a reference-chain like this:
kono
parents:
diff changeset
568
kono
parents:
diff changeset
569 @smallexample
kono
parents:
diff changeset
570 EXPR_VARIABLE(variable) ==> REF_COMPONENT(array) ==> REF_ARRAY(FULL) ==|
kono
parents:
diff changeset
571 EXPR_VARIABLE(local_array) ==> REF_ARRAY(FULL) ==|
kono
parents:
diff changeset
572 @end smallexample
kono
parents:
diff changeset
573
kono
parents:
diff changeset
574
kono
parents:
diff changeset
575 @subsection Constant Substring References
kono
parents:
diff changeset
576
kono
parents:
diff changeset
577 @code{EXPR_SUBSTRING} is a special type of expression that encodes a substring
kono
parents:
diff changeset
578 reference of a constant string, as in the following code snippet:
kono
parents:
diff changeset
579
kono
parents:
diff changeset
580 @smallexample
kono
parents:
diff changeset
581 x = "abcde"(1:2)
kono
parents:
diff changeset
582 @end smallexample
kono
parents:
diff changeset
583
kono
parents:
diff changeset
584 In this case, @code{value.character} contains the full string's data as if it
kono
parents:
diff changeset
585 was a string constant, but the @code{ref} member is also set and points to a
kono
parents:
diff changeset
586 substring reference as described in the subsection above.
kono
parents:
diff changeset
587
kono
parents:
diff changeset
588
kono
parents:
diff changeset
589 @c ---------------------------------------------------------------------
kono
parents:
diff changeset
590 @c F2003 OOP
kono
parents:
diff changeset
591 @c ---------------------------------------------------------------------
kono
parents:
diff changeset
592
kono
parents:
diff changeset
593 @node Object Orientation
kono
parents:
diff changeset
594 @chapter Internals of Fortran 2003 OOP Features
kono
parents:
diff changeset
595
kono
parents:
diff changeset
596 @menu
kono
parents:
diff changeset
597 * Type-bound Procedures:: Type-bound procedures.
kono
parents:
diff changeset
598 * Type-bound Operators:: Type-bound operators.
kono
parents:
diff changeset
599 @end menu
kono
parents:
diff changeset
600
kono
parents:
diff changeset
601
kono
parents:
diff changeset
602 @c Type-bound procedures
kono
parents:
diff changeset
603 @c ---------------------
kono
parents:
diff changeset
604
kono
parents:
diff changeset
605 @node Type-bound Procedures
kono
parents:
diff changeset
606 @section Type-bound Procedures
kono
parents:
diff changeset
607
kono
parents:
diff changeset
608 Type-bound procedures are stored in the @code{tb_sym_root} of the namespace
kono
parents:
diff changeset
609 @code{f2k_derived} associated with the derived-type symbol as @code{gfc_symtree}
kono
parents:
diff changeset
610 nodes. The name and symbol of these symtrees corresponds to the binding-name
kono
parents:
diff changeset
611 of the procedure, i.e. the name that is used to call it from the context of an
kono
parents:
diff changeset
612 object of the derived-type.
kono
parents:
diff changeset
613
kono
parents:
diff changeset
614 In addition, this type of symtrees stores in @code{n.tb} a struct of type
kono
parents:
diff changeset
615 @code{gfc_typebound_proc} containing the additional data needed: The
kono
parents:
diff changeset
616 binding attributes (like @code{PASS} and @code{NOPASS}, @code{NON_OVERRIDABLE}
kono
parents:
diff changeset
617 or the access-specifier), the binding's target(s) and, if the current binding
kono
parents:
diff changeset
618 overrides or extends an inherited binding of the same name, @code{overridden}
kono
parents:
diff changeset
619 points to this binding's @code{gfc_typebound_proc} structure.
kono
parents:
diff changeset
620
kono
parents:
diff changeset
621
kono
parents:
diff changeset
622 @subsection Specific Bindings
kono
parents:
diff changeset
623 @c --------------------------
kono
parents:
diff changeset
624
kono
parents:
diff changeset
625 For specific bindings (declared with @code{PROCEDURE}), if they have a
kono
parents:
diff changeset
626 passed-object argument, the passed-object dummy argument is first saved by its
kono
parents:
diff changeset
627 name, and later during resolution phase the corresponding argument is looked for
kono
parents:
diff changeset
628 and its position remembered as @code{pass_arg_num} in @code{gfc_typebound_proc}.
kono
parents:
diff changeset
629 The binding's target procedure is pointed-to by @code{u.specific}.
kono
parents:
diff changeset
630
kono
parents:
diff changeset
631 @code{DEFERRED} bindings are just like ordinary specific bindings, except
kono
parents:
diff changeset
632 that their @code{deferred} flag is set of course and that @code{u.specific}
kono
parents:
diff changeset
633 points to their ``interface'' defining symbol (might be an abstract interface)
kono
parents:
diff changeset
634 instead of the target procedure.
kono
parents:
diff changeset
635
kono
parents:
diff changeset
636 At the moment, all type-bound procedure calls are statically dispatched and
kono
parents:
diff changeset
637 transformed into ordinary procedure calls at resolution time; their actual
kono
parents:
diff changeset
638 argument list is updated to include at the right position the passed-object
kono
parents:
diff changeset
639 argument, if applicable, and then a simple procedure call to the binding's
kono
parents:
diff changeset
640 target procedure is built. To handle dynamic dispatch in the future, this will
kono
parents:
diff changeset
641 be extended to allow special code generation during the trans-phase to dispatch
kono
parents:
diff changeset
642 based on the object's dynamic type.
kono
parents:
diff changeset
643
kono
parents:
diff changeset
644
kono
parents:
diff changeset
645 @subsection Generic Bindings
kono
parents:
diff changeset
646 @c -------------------------
kono
parents:
diff changeset
647
kono
parents:
diff changeset
648 Bindings declared as @code{GENERIC} store the specific bindings they target as
kono
parents:
diff changeset
649 a linked list using nodes of type @code{gfc_tbp_generic} in @code{u.generic}.
kono
parents:
diff changeset
650 For each specific target, the parser records its symtree and during resolution
kono
parents:
diff changeset
651 this symtree is bound to the corresponding @code{gfc_typebound_proc} structure
kono
parents:
diff changeset
652 of the specific target.
kono
parents:
diff changeset
653
kono
parents:
diff changeset
654 Calls to generic bindings are handled entirely in the resolution-phase, where
kono
parents:
diff changeset
655 for the actual argument list present the matching specific binding is found
kono
parents:
diff changeset
656 and the call's target procedure (@code{value.compcall.tbp}) is re-pointed to
kono
parents:
diff changeset
657 the found specific binding and this call is subsequently handled by the logic
kono
parents:
diff changeset
658 for specific binding calls.
kono
parents:
diff changeset
659
kono
parents:
diff changeset
660
kono
parents:
diff changeset
661 @subsection Calls to Type-bound Procedures
kono
parents:
diff changeset
662 @c ---------------------------------------
kono
parents:
diff changeset
663
kono
parents:
diff changeset
664 Calls to type-bound procedures are stored in the parse-tree as @code{gfc_expr}
kono
parents:
diff changeset
665 nodes of type @code{EXPR_COMPCALL}. Their @code{value.compcall.actual} saves
kono
parents:
diff changeset
666 the actual argument list of the call and @code{value.compcall.tbp} points to the
kono
parents:
diff changeset
667 @code{gfc_typebound_proc} structure of the binding to be called. The object
kono
parents:
diff changeset
668 in whose context the procedure was called is saved by combination of
kono
parents:
diff changeset
669 @code{symtree} and @code{ref}, as if the expression was of type
kono
parents:
diff changeset
670 @code{EXPR_VARIABLE}.
kono
parents:
diff changeset
671
kono
parents:
diff changeset
672 For code like this:
kono
parents:
diff changeset
673 @smallexample
kono
parents:
diff changeset
674 CALL myobj%procedure (arg1, arg2)
kono
parents:
diff changeset
675 @end smallexample
kono
parents:
diff changeset
676 @noindent
kono
parents:
diff changeset
677 the @code{CALL} is represented in the parse-tree as a @code{gfc_code} node of
kono
parents:
diff changeset
678 type @code{EXEC_COMPCALL}. The @code{expr} member of this node holds an
kono
parents:
diff changeset
679 expression of type @code{EXPR_COMPCALL} of the same structure as mentioned above
kono
parents:
diff changeset
680 except that its target procedure is of course a @code{SUBROUTINE} and not a
kono
parents:
diff changeset
681 @code{FUNCTION}.
kono
parents:
diff changeset
682
kono
parents:
diff changeset
683 Expressions that are generated internally (as expansion of a type-bound
kono
parents:
diff changeset
684 operator call) may also use additional flags and members.
kono
parents:
diff changeset
685 @code{value.compcall.ignore_pass} signals that even though a @code{PASS}
kono
parents:
diff changeset
686 attribute may be present the actual argument list should not be updated because
kono
parents:
diff changeset
687 it already contains the passed-object.
kono
parents:
diff changeset
688 @code{value.compcall.base_object} overrides, if it is set, the base-object
kono
parents:
diff changeset
689 (that is normally stored in @code{symtree} and @code{ref} as mentioned above);
kono
parents:
diff changeset
690 this is needed because type-bound operators can be called on a base-object that
kono
parents:
diff changeset
691 need not be of type @code{EXPR_VARIABLE} and thus representable in this way.
kono
parents:
diff changeset
692 Finally, if @code{value.compcall.assign} is set, the call was produced in
kono
parents:
diff changeset
693 expansion of a type-bound assignment; this means that proper dependency-checking
kono
parents:
diff changeset
694 needs to be done when relevant.
kono
parents:
diff changeset
695
kono
parents:
diff changeset
696
kono
parents:
diff changeset
697 @c Type-bound operators
kono
parents:
diff changeset
698 @c --------------------
kono
parents:
diff changeset
699
kono
parents:
diff changeset
700 @node Type-bound Operators
kono
parents:
diff changeset
701 @section Type-bound Operators
kono
parents:
diff changeset
702
kono
parents:
diff changeset
703 Type-bound operators are in fact basically just @code{GENERIC} procedure
kono
parents:
diff changeset
704 bindings and are represented much in the same way as those (see
kono
parents:
diff changeset
705 @ref{Type-bound Procedures}).
kono
parents:
diff changeset
706
kono
parents:
diff changeset
707 They come in two flavours:
kono
parents:
diff changeset
708 User-defined operators (like @code{.MYOPERATOR.})
kono
parents:
diff changeset
709 are stored in the @code{f2k_derived} namespace's @code{tb_uop_root}
kono
parents:
diff changeset
710 symtree exactly like ordinary type-bound procedures are stored in
kono
parents:
diff changeset
711 @code{tb_sym_root}; their symtrees' names are the operator-names (e.g.
kono
parents:
diff changeset
712 @samp{myoperator} in the example).
kono
parents:
diff changeset
713 Intrinsic operators on the other hand are stored in the namespace's
kono
parents:
diff changeset
714 array member @code{tb_op} indexed by the intrinsic operator's enum
kono
parents:
diff changeset
715 value. Those need not be packed into @code{gfc_symtree} structures and are
kono
parents:
diff changeset
716 only @code{gfc_typebound_proc} instances.
kono
parents:
diff changeset
717
kono
parents:
diff changeset
718 When an operator call or assignment is found that can not be handled in
kono
parents:
diff changeset
719 another way (i.e. neither matches an intrinsic nor interface operator
kono
parents:
diff changeset
720 definition) but that contains a derived-type expression, all type-bound
kono
parents:
diff changeset
721 operators defined on that derived-type are checked for a match with
kono
parents:
diff changeset
722 the operator call. If there's indeed a relevant definition, the
kono
parents:
diff changeset
723 operator call is replaced with an internally generated @code{GENERIC}
kono
parents:
diff changeset
724 type-bound procedure call to the respective definition and that call is
kono
parents:
diff changeset
725 further processed.
kono
parents:
diff changeset
726
kono
parents:
diff changeset
727
kono
parents:
diff changeset
728 @c ---------------------------------------------------------------------
kono
parents:
diff changeset
729 @c LibGFortran
kono
parents:
diff changeset
730 @c ---------------------------------------------------------------------
kono
parents:
diff changeset
731
kono
parents:
diff changeset
732 @node LibGFortran
kono
parents:
diff changeset
733 @chapter The LibGFortran Runtime Library
kono
parents:
diff changeset
734
kono
parents:
diff changeset
735 @menu
kono
parents:
diff changeset
736 * Symbol Versioning:: Symbol Versioning.
kono
parents:
diff changeset
737 @end menu
kono
parents:
diff changeset
738
kono
parents:
diff changeset
739
kono
parents:
diff changeset
740 @c ---------------------------------------------------------------------
kono
parents:
diff changeset
741 @c Symbol Versioning
kono
parents:
diff changeset
742 @c ---------------------------------------------------------------------
kono
parents:
diff changeset
743
kono
parents:
diff changeset
744 @node Symbol Versioning
kono
parents:
diff changeset
745 @section Symbol Versioning
kono
parents:
diff changeset
746 @comment Based on https://gcc.gnu.org/wiki/SymbolVersioning,
kono
parents:
diff changeset
747 @comment as of 2006-11-05, written by Janne Blomqvist.
kono
parents:
diff changeset
748
kono
parents:
diff changeset
749 In general, this capability exists only on a few platforms, thus there
kono
parents:
diff changeset
750 is a need for configure magic so that it is used only on those targets
kono
parents:
diff changeset
751 where it is supported.
kono
parents:
diff changeset
752
kono
parents:
diff changeset
753 The central concept in symbol versioning is the so-called map file,
kono
parents:
diff changeset
754 which specifies the version node(s) exported symbols are labeled with.
kono
parents:
diff changeset
755 Also, the map file is used to hide local symbols.
kono
parents:
diff changeset
756
kono
parents:
diff changeset
757 Some relevant references:
kono
parents:
diff changeset
758 @itemize @bullet
kono
parents:
diff changeset
759 @item
kono
parents:
diff changeset
760 @uref{https://sourceware.org/binutils/docs/ld/VERSION.html,
kono
parents:
diff changeset
761 GNU @command{ld} manual}
kono
parents:
diff changeset
762
kono
parents:
diff changeset
763 @item
kono
parents:
diff changeset
764 @uref{https://www.akkadia.org/drepper/symbol-versioning, ELF Symbol
kono
parents:
diff changeset
765 Versioning - Ulrich Depper}
kono
parents:
diff changeset
766
kono
parents:
diff changeset
767 @item
kono
parents:
diff changeset
768 @uref{https://www.akkadia.org/drepper/dsohowto.pdf, How to Write Shared
kono
parents:
diff changeset
769 Libraries - Ulrich Drepper (see Chapter 3)}
kono
parents:
diff changeset
770
kono
parents:
diff changeset
771 @end itemize
kono
parents:
diff changeset
772
kono
parents:
diff changeset
773 If one adds a new symbol to a library that should be exported, the new
kono
parents:
diff changeset
774 symbol should be mentioned in the map file and a new version node
kono
parents:
diff changeset
775 defined, e.g., if one adds a new symbols @code{foo} and @code{bar} to
kono
parents:
diff changeset
776 libgfortran for the next GCC release, the following should be added to
kono
parents:
diff changeset
777 the map file:
kono
parents:
diff changeset
778 @smallexample
kono
parents:
diff changeset
779 GFORTRAN_1.1 @{
kono
parents:
diff changeset
780 global:
kono
parents:
diff changeset
781 foo;
kono
parents:
diff changeset
782 bar;
kono
parents:
diff changeset
783 @} GFORTRAN_1.0;
kono
parents:
diff changeset
784 @end smallexample
kono
parents:
diff changeset
785 @noindent
kono
parents:
diff changeset
786 where @code{GFORTRAN_1.0} is the version node of the current release,
kono
parents:
diff changeset
787 and @code{GFORTRAN_1.1} is the version node of the next release where
kono
parents:
diff changeset
788 foo and bar are made available.
kono
parents:
diff changeset
789
kono
parents:
diff changeset
790 If one wants to change an existing interface, it is possible by using
kono
parents:
diff changeset
791 some asm trickery (from the @command{ld} manual referenced above):
kono
parents:
diff changeset
792
kono
parents:
diff changeset
793 @smallexample
kono
parents:
diff changeset
794 __asm__(".symver original_foo,foo@@");
kono
parents:
diff changeset
795 __asm__(".symver old_foo,foo@@VERS_1.1");
kono
parents:
diff changeset
796 __asm__(".symver old_foo1,foo@@VERS_1.2");
kono
parents:
diff changeset
797 __asm__(".symver new_foo,foo@@VERS_2.0");
kono
parents:
diff changeset
798 @end smallexample
kono
parents:
diff changeset
799
kono
parents:
diff changeset
800 In this example, @code{foo@@} represents the symbol @code{foo} bound to
kono
parents:
diff changeset
801 the unspecified base version of the symbol. The source file that
kono
parents:
diff changeset
802 contains this example would define 4 C functions: @code{original_foo},
kono
parents:
diff changeset
803 @code{old_foo}, @code{old_foo1}, and @code{new_foo}.
kono
parents:
diff changeset
804
kono
parents:
diff changeset
805 In this case the map file must contain @code{foo} in @code{VERS_1.1}
kono
parents:
diff changeset
806 and @code{VERS_1.2} as well as in @code{VERS_2.0}.
kono
parents:
diff changeset
807
kono
parents:
diff changeset
808
kono
parents:
diff changeset
809 @c ---------------------------------------------------------------------
kono
parents:
diff changeset
810 @c GNU Free Documentation License
kono
parents:
diff changeset
811 @c ---------------------------------------------------------------------
kono
parents:
diff changeset
812
kono
parents:
diff changeset
813 @include fdl.texi
kono
parents:
diff changeset
814
kono
parents:
diff changeset
815
kono
parents:
diff changeset
816 @c ---------------------------------------------------------------------
kono
parents:
diff changeset
817 @c Index
kono
parents:
diff changeset
818 @c ---------------------------------------------------------------------
kono
parents:
diff changeset
819
kono
parents:
diff changeset
820 @node Index
kono
parents:
diff changeset
821 @unnumbered Index
kono
parents:
diff changeset
822
kono
parents:
diff changeset
823 @printindex cp
kono
parents:
diff changeset
824
kono
parents:
diff changeset
825 @bye