re PR fortran/21915 ([4.0 only] Would like atanh etc. as intrinsics)
[platform/upstream/gcc.git] / gcc / fortran / gfortran.h
1 /* gfortran header file
2    Copyright (C) 2000, 2001, 2002, 2003, 2004, 2005 Free Software Foundation,
3    Inc.
4    Contributed by Andy Vaught
5
6 This file is part of GCC.
7
8 GCC is free software; you can redistribute it and/or modify it under
9 the terms of the GNU General Public License as published by the Free
10 Software Foundation; either version 2, or (at your option) any later
11 version.
12
13 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
14 WARRANTY; without even the implied warranty of MERCHANTABILITY or
15 FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
16 for more details.
17
18 You should have received a copy of the GNU General Public License
19 along with GCC; see the file COPYING.  If not, write to the Free
20 Software Foundation, 59 Temple Place - Suite 330, Boston, MA
21 02111-1307, USA.  */
22
23 #ifndef GCC_GFORTRAN_H
24 #define GCC_GFORTRAN_H
25
26 /* It's probably insane to have this large of a header file, but it
27    seemed like everything had to be recompiled anyway when a change
28    was made to a header file, and there were ordering issues with
29    multiple header files.  Besides, Microsoft's winnt.h was 250k last
30    time I looked, so by comparison this is perfectly reasonable.  */
31
32 #include "system.h"
33 #include "coretypes.h"
34 #include "input.h"
35
36 /* The following ifdefs are recommended by the autoconf documentation
37    for any code using alloca.  */
38
39 /* AIX requires this to be the first thing in the file.  */
40 #ifdef __GNUC__
41 #else /* not __GNUC__ */
42 #ifdef HAVE_ALLOCA_H
43 #include <alloca.h>
44 #else /* do not HAVE_ALLOCA_H */
45 #ifdef _AIX
46 #pragma alloca
47 #else
48 #ifndef alloca                  /* predefined by HP cc +Olibcalls */
49 char *alloca ();
50 #endif /* not predefined */
51 #endif /* not _AIX */
52 #endif /* do not HAVE_ALLOCA_H */
53 #endif /* not __GNUC__ */
54
55 /* Major control parameters.  */
56
57 #define GFC_MAX_SYMBOL_LEN 63
58 #define GFC_MAX_LINE 132        /* Characters beyond this are not seen.  */
59 #define GFC_MAX_DIMENSIONS 7    /* Maximum dimensions in an array.  */
60 #define GFC_LETTERS 26          /* Number of letters in the alphabet.  */
61 #define MAX_ERROR_MESSAGE 1000  /* Maximum length of an error message.  */
62
63 #define free(x) Use_gfc_free_instead_of_free()
64 #define gfc_is_whitespace(c) ((c==' ') || (c=='\t'))
65
66 #ifndef NULL
67 #define NULL ((void *) 0)
68 #endif
69
70 /* Stringization.  */
71 #define stringize(x) expand_macro(x)
72 #define expand_macro(x) # x
73
74 /* For a the runtime library, a standard prefix is a requirement to
75    avoid cluttering the namespace with things nobody asked for.  It's
76    ugly to look at and a pain to type when you add the prefix by hand,
77    so we hide it behind a macro.  */
78 #define PREFIX(x) "_gfortran_" x
79 #define PREFIX_LEN 10
80
81 /* Macro to initialize an mstring structure.  */
82 #define minit(s, t) { s, NULL, t }
83
84 /* Structure for storing strings to be matched by gfc_match_string.  */
85 typedef struct
86 {
87   const char *string;
88   const char *mp;
89   int tag;
90 }
91 mstring;
92
93
94 /* Flags to specify which standard/extension contains a feature.  */
95 #define GFC_STD_LEGACY          (1<<6) /* Backward compatibility.  */
96 #define GFC_STD_GNU             (1<<5)    /* GNU Fortran extension.  */
97 #define GFC_STD_F2003           (1<<4)    /* New in F2003.  */
98 /* Note that no features were obsoleted nor deleted in F2003.  */
99 #define GFC_STD_F95             (1<<3)    /* New in F95.  */
100 #define GFC_STD_F95_DEL         (1<<2)    /* Deleted in F95.  */
101 #define GFC_STD_F95_OBS         (1<<1)    /* Obsoleted in F95.  */
102 #define GFC_STD_F77             (1<<0)    /* Up to and including F77.  */
103
104 /*************************** Enums *****************************/
105
106 /* The author remains confused to this day about the convention of
107    returning '0' for 'SUCCESS'... or was it the other way around?  The
108    following enum makes things much more readable.  We also start
109    values off at one instead of zero.  */
110
111 typedef enum
112 { SUCCESS = 1, FAILURE }
113 try;
114
115 /* Matchers return one of these three values.  The difference between
116    MATCH_NO and MATCH_ERROR is that MATCH_ERROR means that a match was
117    successful, but that something non-syntactic is wrong and an error
118    has already been issued.  */
119
120 typedef enum
121 { MATCH_NO = 1, MATCH_YES, MATCH_ERROR }
122 match;
123
124 typedef enum
125 { FORM_FREE, FORM_FIXED, FORM_UNKNOWN }
126 gfc_source_form;
127
128 typedef enum
129 { BT_UNKNOWN = 1, BT_INTEGER, BT_REAL, BT_COMPLEX,
130   BT_LOGICAL, BT_CHARACTER, BT_DERIVED, BT_PROCEDURE
131 }
132 bt;
133
134 /* Expression node types.  */
135 typedef enum
136 { EXPR_OP = 1, EXPR_FUNCTION, EXPR_CONSTANT, EXPR_VARIABLE,
137   EXPR_SUBSTRING, EXPR_STRUCTURE, EXPR_ARRAY, EXPR_NULL
138 }
139 expr_t;
140
141 /* Array types.  */
142 typedef enum
143 { AS_EXPLICIT = 1, AS_ASSUMED_SHAPE, AS_DEFERRED,
144   AS_ASSUMED_SIZE, AS_UNKNOWN
145 }
146 array_type;
147
148 typedef enum
149 { AR_FULL = 1, AR_ELEMENT, AR_SECTION, AR_UNKNOWN }
150 ar_type;
151
152 /* Statement label types.  */
153 typedef enum
154 { ST_LABEL_UNKNOWN = 1, ST_LABEL_TARGET,
155   ST_LABEL_BAD_TARGET, ST_LABEL_FORMAT
156 }
157 gfc_sl_type;
158
159 /* Intrinsic operators.  */
160 typedef enum
161 { GFC_INTRINSIC_BEGIN = 0,
162   INTRINSIC_NONE = -1, INTRINSIC_UPLUS = GFC_INTRINSIC_BEGIN,
163   INTRINSIC_UMINUS, INTRINSIC_PLUS, INTRINSIC_MINUS, INTRINSIC_TIMES,
164   INTRINSIC_DIVIDE, INTRINSIC_POWER, INTRINSIC_CONCAT,
165   INTRINSIC_AND, INTRINSIC_OR, INTRINSIC_EQV, INTRINSIC_NEQV,
166   INTRINSIC_EQ, INTRINSIC_NE, INTRINSIC_GT, INTRINSIC_GE,
167   INTRINSIC_LT, INTRINSIC_LE, INTRINSIC_NOT, INTRINSIC_USER,
168   INTRINSIC_ASSIGN,
169   GFC_INTRINSIC_END /* Sentinel */
170 }
171 gfc_intrinsic_op;
172
173
174 /* Strings for all intrinsic operators.  */
175 extern mstring intrinsic_operators[];
176
177
178 /* This macro is the number of intrinsic operators that exist.
179    Assumptions are made about the numbering of the interface_op enums.  */
180 #define GFC_INTRINSIC_OPS GFC_INTRINSIC_END
181
182 /* Arithmetic results.  */
183 typedef enum
184 { ARITH_OK = 1, ARITH_OVERFLOW, ARITH_UNDERFLOW, ARITH_NAN,
185   ARITH_DIV0, ARITH_INCOMMENSURATE, ARITH_ASYMMETRIC
186 }
187 arith;
188
189 /* Statements.  */
190 typedef enum
191 {
192   ST_ARITHMETIC_IF, ST_ALLOCATE, ST_ATTR_DECL, ST_BACKSPACE, ST_BLOCK_DATA,
193   ST_CALL, ST_CASE, ST_CLOSE, ST_COMMON, ST_CONTINUE, ST_CONTAINS, ST_CYCLE,
194   ST_DATA, ST_DATA_DECL, ST_DEALLOCATE, ST_DO, ST_ELSE, ST_ELSEIF,
195   ST_ELSEWHERE, ST_END_BLOCK_DATA, ST_ENDDO, ST_IMPLIED_ENDDO,
196   ST_END_FILE, ST_END_FORALL, ST_END_FUNCTION, ST_ENDIF, ST_END_INTERFACE,
197   ST_END_MODULE, ST_END_PROGRAM, ST_END_SELECT, ST_END_SUBROUTINE,
198   ST_END_WHERE, ST_END_TYPE, ST_ENTRY, ST_EQUIVALENCE, ST_EXIT, ST_FORALL,
199   ST_FORALL_BLOCK, ST_FORMAT, ST_FUNCTION, ST_GOTO, ST_IF_BLOCK, ST_IMPLICIT,
200   ST_IMPLICIT_NONE, ST_INQUIRE, ST_INTERFACE, ST_PARAMETER, ST_MODULE,
201   ST_MODULE_PROC, ST_NAMELIST, ST_NULLIFY, ST_OPEN, ST_PAUSE, ST_PRIVATE,
202   ST_PROGRAM, ST_PUBLIC, ST_READ, ST_RETURN, ST_REWIND, ST_STOP,
203   ST_SUBROUTINE,
204   ST_TYPE, ST_USE, ST_WHERE_BLOCK, ST_WHERE, ST_WRITE, ST_ASSIGNMENT,
205   ST_POINTER_ASSIGNMENT, ST_SELECT_CASE, ST_SEQUENCE, ST_SIMPLE_IF,
206   ST_STATEMENT_FUNCTION, ST_DERIVED_DECL, ST_LABEL_ASSIGNMENT, ST_NONE
207 }
208 gfc_statement;
209
210
211 /* Types of interfaces that we can have.  Assignment interfaces are
212    considered to be intrinsic operators.  */
213 typedef enum
214 {
215   INTERFACE_NAMELESS = 1, INTERFACE_GENERIC,
216   INTERFACE_INTRINSIC_OP, INTERFACE_USER_OP
217 }
218 interface_type;
219
220 /* Symbol flavors: these are all mutually exclusive.
221    10 elements = 4 bits.  */
222 typedef enum sym_flavor
223 {
224   FL_UNKNOWN = 0, FL_PROGRAM, FL_BLOCK_DATA, FL_MODULE, FL_VARIABLE,
225   FL_PARAMETER, FL_LABEL, FL_PROCEDURE, FL_DERIVED, FL_NAMELIST
226 }
227 sym_flavor;
228
229 /* Procedure types.  7 elements = 3 bits.  */
230 typedef enum procedure_type
231 { PROC_UNKNOWN, PROC_MODULE, PROC_INTERNAL, PROC_DUMMY,
232   PROC_INTRINSIC, PROC_ST_FUNCTION, PROC_EXTERNAL
233 }
234 procedure_type;
235
236 /* Intent types.  */
237 typedef enum sym_intent
238 { INTENT_UNKNOWN = 0, INTENT_IN, INTENT_OUT, INTENT_INOUT
239 }
240 sym_intent;
241
242 /* Access types.  */
243 typedef enum gfc_access
244 { ACCESS_UNKNOWN = 0, ACCESS_PUBLIC, ACCESS_PRIVATE
245 }
246 gfc_access;
247
248 /* Flags to keep track of where an interface came from.
249    4 elements = 2 bits.  */
250 typedef enum ifsrc
251 { IFSRC_UNKNOWN = 0, IFSRC_DECL, IFSRC_IFBODY, IFSRC_USAGE
252 }
253 ifsrc;
254
255 /* Strings for all symbol attributes.  We use these for dumping the
256    parse tree, in error messages, and also when reading and writing
257    modules.  In symbol.c.  */
258 extern const mstring flavors[];
259 extern const mstring procedures[];
260 extern const mstring intents[];
261 extern const mstring access_types[];
262 extern const mstring ifsrc_types[];
263
264 /* Enumeration of all the generic intrinsic functions.  Used by the
265    backend for identification of a function.  */
266
267 enum gfc_generic_isym_id
268 {
269   /* GFC_ISYM_NONE is used for intrinsics which will never be seen by
270      the backend (eg. KIND).  */
271   GFC_ISYM_NONE = 0,
272   GFC_ISYM_ABS,
273   GFC_ISYM_ACHAR,
274   GFC_ISYM_ACOS,
275   GFC_ISYM_ACOSH,
276   GFC_ISYM_ADJUSTL,
277   GFC_ISYM_ADJUSTR,
278   GFC_ISYM_AIMAG,
279   GFC_ISYM_AINT,
280   GFC_ISYM_ALL,
281   GFC_ISYM_ALLOCATED,
282   GFC_ISYM_ANINT,
283   GFC_ISYM_ANY,
284   GFC_ISYM_ASIN,
285   GFC_ISYM_ASINH,
286   GFC_ISYM_ASSOCIATED,
287   GFC_ISYM_ATAN,
288   GFC_ISYM_ATANH,
289   GFC_ISYM_ATAN2,
290   GFC_ISYM_J0,
291   GFC_ISYM_J1,
292   GFC_ISYM_JN,
293   GFC_ISYM_Y0,
294   GFC_ISYM_Y1,
295   GFC_ISYM_YN,
296   GFC_ISYM_BTEST,
297   GFC_ISYM_CEILING,
298   GFC_ISYM_CHAR,
299   GFC_ISYM_CHDIR,
300   GFC_ISYM_CMPLX,
301   GFC_ISYM_COMMAND_ARGUMENT_COUNT,
302   GFC_ISYM_CONJG,
303   GFC_ISYM_COS,
304   GFC_ISYM_COSH,
305   GFC_ISYM_COUNT,
306   GFC_ISYM_CSHIFT,
307   GFC_ISYM_DBLE,
308   GFC_ISYM_DIM,
309   GFC_ISYM_DOT_PRODUCT,
310   GFC_ISYM_DPROD,
311   GFC_ISYM_EOSHIFT,
312   GFC_ISYM_ERF,
313   GFC_ISYM_ERFC,
314   GFC_ISYM_ETIME,
315   GFC_ISYM_EXP,
316   GFC_ISYM_EXPONENT,
317   GFC_ISYM_FLOOR,
318   GFC_ISYM_FNUM,
319   GFC_ISYM_FRACTION,
320   GFC_ISYM_FSTAT,
321   GFC_ISYM_GETCWD,
322   GFC_ISYM_GETGID,
323   GFC_ISYM_GETPID,
324   GFC_ISYM_GETUID,
325   GFC_ISYM_HOSTNM,
326   GFC_ISYM_IACHAR,
327   GFC_ISYM_IAND,
328   GFC_ISYM_IARGC,
329   GFC_ISYM_IBCLR,
330   GFC_ISYM_IBITS,
331   GFC_ISYM_IBSET,
332   GFC_ISYM_ICHAR,
333   GFC_ISYM_IEOR,
334   GFC_ISYM_IERRNO,
335   GFC_ISYM_INDEX,
336   GFC_ISYM_INT,
337   GFC_ISYM_IOR,
338   GFC_ISYM_IRAND,
339   GFC_ISYM_ISHFT,
340   GFC_ISYM_ISHFTC,
341   GFC_ISYM_KILL,
342   GFC_ISYM_LBOUND,
343   GFC_ISYM_LEN,
344   GFC_ISYM_LEN_TRIM,
345   GFC_ISYM_LINK,
346   GFC_ISYM_LGE,
347   GFC_ISYM_LGT,
348   GFC_ISYM_LLE,
349   GFC_ISYM_LLT,
350   GFC_ISYM_LOG,
351   GFC_ISYM_LOG10,
352   GFC_ISYM_LOGICAL,
353   GFC_ISYM_MATMUL,
354   GFC_ISYM_MAX,
355   GFC_ISYM_MAXLOC,
356   GFC_ISYM_MAXVAL,
357   GFC_ISYM_MERGE,
358   GFC_ISYM_MIN,
359   GFC_ISYM_MINLOC,
360   GFC_ISYM_MINVAL,
361   GFC_ISYM_MOD,
362   GFC_ISYM_MODULO,
363   GFC_ISYM_NEAREST,
364   GFC_ISYM_NINT,
365   GFC_ISYM_NOT,
366   GFC_ISYM_PACK,
367   GFC_ISYM_PRESENT,
368   GFC_ISYM_PRODUCT,
369   GFC_ISYM_RAND,
370   GFC_ISYM_REAL,
371   GFC_ISYM_RENAME,
372   GFC_ISYM_REPEAT,
373   GFC_ISYM_RESHAPE,
374   GFC_ISYM_RRSPACING,
375   GFC_ISYM_SCALE,
376   GFC_ISYM_SCAN,
377   GFC_ISYM_SECOND,
378   GFC_ISYM_SET_EXPONENT,
379   GFC_ISYM_SHAPE,
380   GFC_ISYM_SI_KIND,
381   GFC_ISYM_SIGN,
382   GFC_ISYM_SIN,
383   GFC_ISYM_SINH,
384   GFC_ISYM_SIZE,
385   GFC_ISYM_SPACING,
386   GFC_ISYM_SPREAD,
387   GFC_ISYM_SQRT,
388   GFC_ISYM_SR_KIND,
389   GFC_ISYM_STAT,
390   GFC_ISYM_SUM,
391   GFC_ISYM_SYMLNK,
392   GFC_ISYM_SYSTEM,
393   GFC_ISYM_TAN,
394   GFC_ISYM_TANH,
395   GFC_ISYM_TIME,
396   GFC_ISYM_TIME8,
397   GFC_ISYM_TRANSFER,
398   GFC_ISYM_TRANSPOSE,
399   GFC_ISYM_TRIM,
400   GFC_ISYM_UBOUND,
401   GFC_ISYM_UMASK,
402   GFC_ISYM_UNLINK,
403   GFC_ISYM_UNPACK,
404   GFC_ISYM_VERIFY,
405   GFC_ISYM_CONVERSION
406 };
407 typedef enum gfc_generic_isym_id gfc_generic_isym_id;
408
409 /************************* Structures *****************************/
410
411 /* Symbol attribute structure.  */
412 typedef struct
413 {
414   /* Variable attributes.  */
415   unsigned allocatable:1, dimension:1, external:1, intrinsic:1,
416     optional:1, pointer:1, save:1, target:1,
417     dummy:1, result:1, assign:1;
418
419   unsigned data:1,              /* Symbol is named in a DATA statement.  */
420     use_assoc:1;                /* Symbol has been use-associated.  */
421
422   unsigned in_namelist:1, in_common:1;
423   unsigned function:1, subroutine:1, generic:1;
424   unsigned implicit_type:1;     /* Type defined via implicit rules.  */
425   unsigned untyped:1;           /* No implicit type could be found.  */
426
427   /* Function/subroutine attributes */
428   unsigned sequence:1, elemental:1, pure:1, recursive:1;
429   unsigned unmaskable:1, masked:1, contained:1;
430
431   /* Set if this procedure is an alternate entry point.  These procedures
432      don't have any code associated, and the backend will turn them into
433      thunks to the master function.  */
434   unsigned entry:1;
435   /* Set if this is the master function for a procedure with multiple
436      entry points.  */
437   unsigned entry_master:1;
438   /* Set if this is the master function for a function with multiple
439      entry points where characteristics of the entry points differ.  */
440   unsigned mixed_entry_master:1;
441
442   /* Set if a function must always be referenced by an explicit interface.  */
443   unsigned always_explicit:1;
444
445   /* Set if the symbol has been referenced in an expression.  No further
446      modification of type or type parameters is permitted.  */
447   unsigned referenced:1;
448
449   /* Mutually exclusive multibit attributes.  */
450   ENUM_BITFIELD (gfc_access) access:2;
451   ENUM_BITFIELD (sym_intent) intent:2;
452   ENUM_BITFIELD (sym_flavor) flavor:4;
453   ENUM_BITFIELD (ifsrc) if_source:2;
454
455   ENUM_BITFIELD (procedure_type) proc:3;
456
457 }
458 symbol_attribute;
459
460
461 /* The following three structures are used to identify a location in
462    the sources. 
463    
464    gfc_file is used to maintain a tree of the source files and how
465    they include each other
466
467    gfc_linebuf holds a single line of source code and information
468    which file it resides in
469
470    locus point to the sourceline and the character in the source
471    line.  
472 */
473
474 typedef struct gfc_file 
475 {
476   struct gfc_file *included_by, *next, *up;
477   int inclusion_line, line;
478   char *filename;
479 } gfc_file;
480
481 typedef struct gfc_linebuf 
482 {
483 #ifdef USE_MAPPED_LOCATION
484   source_location location;
485 #else
486   int linenum;
487 #endif
488   struct gfc_file *file;
489   struct gfc_linebuf *next;
490
491   int truncated;
492
493   char line[1];
494 } gfc_linebuf;
495
496 #define gfc_linebuf_header_size (offsetof (gfc_linebuf, line))
497
498 typedef struct 
499 {
500   char *nextc;
501   gfc_linebuf *lb;
502 } locus;
503
504
505 #include <limits.h>
506 #ifndef PATH_MAX
507 # include <sys/param.h>
508 # define PATH_MAX MAXPATHLEN
509 #endif
510
511
512 extern int gfc_suppress_error;
513
514
515 /* Character length structures hold the expression that gives the
516    length of a character variable.  We avoid putting these into
517    gfc_typespec because doing so prevents us from doing structure
518    copies and forces us to deallocate any typespecs we create, as well
519    as structures that contain typespecs.  They also can have multiple
520    character typespecs pointing to them.
521
522    These structures form a singly linked list within the current
523    namespace and are deallocated with the namespace.  It is possible to
524    end up with gfc_charlen structures that have nothing pointing to them.  */
525
526 typedef struct gfc_charlen
527 {
528   struct gfc_expr *length;
529   struct gfc_charlen *next;
530   tree backend_decl;
531 }
532 gfc_charlen;
533
534 #define gfc_get_charlen() gfc_getmem(sizeof(gfc_charlen))
535
536 /* Type specification structure.  FIXME: derived and cl could be union???  */
537 typedef struct
538 {
539   bt type;
540   int kind;
541   struct gfc_symbol *derived;
542   gfc_charlen *cl;      /* For character types only.  */
543 }
544 gfc_typespec;
545
546 /* Array specification.  */
547 typedef struct
548 {
549   int rank;     /* A rank of zero means that a variable is a scalar.  */
550   array_type type;
551   struct gfc_expr *lower[GFC_MAX_DIMENSIONS], *upper[GFC_MAX_DIMENSIONS];
552 }
553 gfc_array_spec;
554
555 #define gfc_get_array_spec() gfc_getmem(sizeof(gfc_array_spec))
556
557
558 /* Components of derived types.  */
559 typedef struct gfc_component
560 {
561   const char *name;
562   gfc_typespec ts;
563
564   int pointer, dimension;
565   gfc_array_spec *as;
566
567   tree backend_decl;
568   locus loc;
569   struct gfc_expr *initializer;
570   struct gfc_component *next;
571 }
572 gfc_component;
573
574 #define gfc_get_component() gfc_getmem(sizeof(gfc_component))
575
576 /* Formal argument lists are lists of symbols.  */
577 typedef struct gfc_formal_arglist
578 {
579   /* Symbol representing the argument at this position in the arglist.  */
580   struct gfc_symbol *sym;
581   /* Points to the next formal argument.  */
582   struct gfc_formal_arglist *next;
583 }
584 gfc_formal_arglist;
585
586 #define gfc_get_formal_arglist() gfc_getmem(sizeof(gfc_formal_arglist))
587
588
589 /* The gfc_actual_arglist structure is for actual arguments.  */
590 typedef struct gfc_actual_arglist
591 {
592   const char *name;
593   /* Alternate return label when the expr member is null.  */
594   struct gfc_st_label *label;
595
596   /* This is set to the type of an eventual omitted optional
597      argument. This is used to determine if a hidden string length
598      argument has to be added to a function call.  */
599   bt missing_arg_type;
600
601   struct gfc_expr *expr;
602   struct gfc_actual_arglist *next;
603 }
604 gfc_actual_arglist;
605
606 #define gfc_get_actual_arglist() gfc_getmem(sizeof(gfc_actual_arglist))
607
608
609 /* Because a symbol can belong to multiple namelists, they must be
610    linked externally to the symbol itself.  */
611 typedef struct gfc_namelist
612 {
613   struct gfc_symbol *sym;
614   struct gfc_namelist *next;
615 }
616 gfc_namelist;
617
618 #define gfc_get_namelist() gfc_getmem(sizeof(gfc_namelist))
619
620
621 /* The gfc_st_label structure is a doubly linked list attached to a
622    namespace that records the usage of statement labels within that
623    space.  */
624 /* TODO: Make format/statement specifics a union.  */
625 typedef struct gfc_st_label
626 {
627   int value;
628
629   gfc_sl_type defined, referenced;
630
631   struct gfc_expr *format;
632
633   tree backend_decl;
634
635   locus where;
636
637   struct gfc_st_label *prev, *next;
638 }
639 gfc_st_label;
640
641
642 /* gfc_interface()-- Interfaces are lists of symbols strung together.  */
643 typedef struct gfc_interface
644 {
645   struct gfc_symbol *sym;
646   locus where;
647   struct gfc_interface *next;
648 }
649 gfc_interface;
650
651 #define gfc_get_interface() gfc_getmem(sizeof(gfc_interface))
652
653
654 /* User operator nodes.  These are like stripped down symbols.  */
655 typedef struct
656 {
657   const char *name;
658
659   gfc_interface *operator;
660   struct gfc_namespace *ns;
661   gfc_access access;
662 }
663 gfc_user_op;
664
665 /* Symbol nodes.  These are important things.  They are what the
666    standard refers to as "entities".  The possibly multiple names that
667    refer to the same entity are accomplished by a binary tree of
668    symtree structures that is balanced by the red-black method-- more
669    than one symtree node can point to any given symbol.  */
670
671 typedef struct gfc_symbol
672 {
673   const char *name;     /* Primary name, before renaming */
674   const char *module;   /* Module this symbol came from */
675   locus declared_at;
676
677   gfc_typespec ts;
678   symbol_attribute attr;
679
680   /* The interface member points to the formal argument list if the
681      symbol is a function or subroutine name.  If the symbol is a
682      generic name, the generic member points to the list of
683      interfaces.  */
684
685   gfc_interface *generic;
686   gfc_access component_access;
687
688   gfc_formal_arglist *formal;
689   struct gfc_namespace *formal_ns;
690
691   struct gfc_expr *value;       /* Parameter/Initializer value */
692   gfc_array_spec *as;
693   struct gfc_symbol *result;    /* function result symbol */
694   gfc_component *components;    /* Derived type components */
695
696   struct gfc_symbol *common_next;       /* Links for COMMON syms */
697   /* Make sure setup code for dummy arguments is generated in the correct
698      order.  */
699   int dummy_order;
700
701   gfc_namelist *namelist, *namelist_tail;
702
703   /* Change management fields.  Symbols that might be modified by the
704      current statement have the mark member nonzero and are kept in a
705      singly linked list through the tlink field.  Of these symbols,
706      symbols with old_symbol equal to NULL are symbols created within
707      the current statement.  Otherwise, old_symbol points to a copy of
708      the old symbol.  */
709
710   struct gfc_symbol *old_symbol, *tlink;
711   unsigned mark:1, new:1;
712   /* Nonzero if all equivalences associated with this symbol have been
713      processed.  */
714   unsigned equiv_built:1;
715   int refs;
716   struct gfc_namespace *ns;     /* namespace containing this symbol */
717
718   tree backend_decl;
719 }
720 gfc_symbol;
721
722
723 /* This structure is used to keep track of symbols in common blocks.  */
724
725 typedef struct
726 {
727   locus where;
728   int use_assoc, saved;
729   char name[GFC_MAX_SYMBOL_LEN + 1];
730   gfc_symbol *head;
731
732 gfc_common_head;
733
734 #define gfc_get_common_head() gfc_getmem(sizeof(gfc_common_head))
735
736
737 /* A list of all the alternate entry points for a procedure.  */
738
739 typedef struct gfc_entry_list
740 {
741   /* The symbol for this entry point.  */
742   gfc_symbol *sym;
743   /* The zero-based id of this entry point.  */
744   int id;
745   /* The LABEL_EXPR marking this entry point.  */
746   tree label;
747   /* The nest item in the list.  */
748   struct gfc_entry_list *next;
749 }
750 gfc_entry_list;
751
752 #define gfc_get_entry_list() \
753   (gfc_entry_list *) gfc_getmem(sizeof(gfc_entry_list))
754
755 /* Within a namespace, symbols are pointed to by symtree nodes that
756    are linked together in a balanced binary tree.  There can be
757    several symtrees pointing to the same symbol node via USE
758    statements.  */
759
760 #define BBT_HEADER(self) int priority; struct self *left, *right
761
762 typedef struct gfc_symtree
763 {
764   BBT_HEADER (gfc_symtree);
765   const char *name;
766   int ambiguous;
767   union
768   {
769     gfc_symbol *sym;            /* Symbol associated with this node */
770     gfc_user_op *uop;
771     gfc_common_head *common;
772   }
773   n;
774
775 }
776 gfc_symtree;
777
778
779 /* A namespace describes the contents of procedure, module or
780    interface block.  */
781 /* ??? Anything else use these?  */
782
783 typedef struct gfc_namespace
784 {
785   /* Tree containing all the symbols in this namespace.  */
786   gfc_symtree *sym_root;
787   /* Tree containing all the user-defined operators in the namespace.  */
788   gfc_symtree *uop_root;
789   /* Tree containing all the common blocks.  */
790   gfc_symtree *common_root;     
791
792   /* If set_flag[letter] is set, an implicit type has been set for letter.  */
793   int set_flag[GFC_LETTERS];
794   /* Keeps track of the implicit types associated with the letters.  */
795   gfc_typespec default_type[GFC_LETTERS];
796
797   /* If this is a namespace of a procedure, this points to the procedure.  */
798   struct gfc_symbol *proc_name;
799   /* If this is the namespace of a unit which contains executable
800      code, this points to it.  */
801   struct gfc_code *code;
802
803   /* Points to the equivalences set up in this namespace.  */
804   struct gfc_equiv *equiv;
805   gfc_interface *operator[GFC_INTRINSIC_OPS];
806
807   /* Points to the parent namespace, i.e. the namespace of a module or
808      procedure in which the procedure belonging to this namespace is
809      contained. The parent namespace points to this namespace either
810      directly via CONTAINED, or indirectly via the chain built by
811      SIBLING.  */
812   struct gfc_namespace *parent;
813   /* CONTAINED points to the first contained namespace. Sibling
814      namespaces are chained via SIBLING.  */
815   struct gfc_namespace  *contained, *sibling;
816
817   gfc_common_head blank_common;
818   gfc_access default_access, operator_access[GFC_INTRINSIC_OPS];
819
820   gfc_st_label *st_labels;
821   /* This list holds information about all the data initializers in
822      this namespace.  */
823   struct gfc_data *data;
824
825   gfc_charlen *cl_list;
826
827   int save_all, seen_save, seen_implicit_none;
828
829   /* Normally we don't need to refcount namespaces.  However when we read
830      a module containing a function with multiple entry points, this
831      will appear as several functions with the same formal namespace.  */
832   int refs;
833
834   /* A list of all alternate entry points to this procedure (or NULL).  */
835   gfc_entry_list *entries;
836
837   /* Set to 1 if namespace is a BLOCK DATA program unit.  */
838   int is_block_data;
839 }
840 gfc_namespace;
841
842 extern gfc_namespace *gfc_current_ns;
843
844 /* Global symbols are symbols of global scope. Currently we only use
845    this to detect collisions already when parsing.
846    TODO: Extend to verify procedure calls.  */
847
848 typedef struct gfc_gsymbol
849 {
850   BBT_HEADER(gfc_gsymbol);
851
852   const char *name;
853   enum { GSYM_UNKNOWN=1, GSYM_PROGRAM, GSYM_FUNCTION, GSYM_SUBROUTINE,
854         GSYM_MODULE, GSYM_COMMON, GSYM_BLOCK_DATA } type;
855
856   int defined, used;
857   locus where;
858 }
859 gfc_gsymbol;
860
861 extern gfc_gsymbol *gfc_gsym_root;
862
863 /* Information on interfaces being built.  */
864 typedef struct
865 {
866   interface_type type;
867   gfc_symbol *sym;
868   gfc_namespace *ns;
869   gfc_user_op *uop;
870   gfc_intrinsic_op op;
871 }
872 gfc_interface_info;
873
874 extern gfc_interface_info current_interface;
875
876
877 /* Array reference.  */
878 typedef struct gfc_array_ref
879 {
880   ar_type type;
881   int dimen;                    /* # of components in the reference */
882   locus where;
883   gfc_array_spec *as;
884
885   locus c_where[GFC_MAX_DIMENSIONS];    /* All expressions can be NULL */
886   struct gfc_expr *start[GFC_MAX_DIMENSIONS], *end[GFC_MAX_DIMENSIONS],
887     *stride[GFC_MAX_DIMENSIONS];
888
889   enum
890   { DIMEN_ELEMENT = 1, DIMEN_RANGE, DIMEN_VECTOR, DIMEN_UNKNOWN }
891   dimen_type[GFC_MAX_DIMENSIONS];
892
893   struct gfc_expr *offset;
894 }
895 gfc_array_ref;
896
897 #define gfc_get_array_ref() gfc_getmem(sizeof(gfc_array_ref))
898
899
900 /* Component reference nodes.  A variable is stored as an expression
901    node that points to the base symbol.  After that, a singly linked
902    list of component reference nodes gives the variable's complete
903    resolution.  The array_ref component may be present and comes
904    before the component component.  */
905
906 typedef enum
907   { REF_ARRAY, REF_COMPONENT, REF_SUBSTRING }
908 ref_type;
909
910 typedef struct gfc_ref
911 {
912   ref_type type;
913
914   union
915   {
916     struct gfc_array_ref ar;
917
918     struct
919     {
920       gfc_component *component;
921       gfc_symbol *sym;
922     }
923     c;
924
925     struct
926     {
927       struct gfc_expr *start, *end;     /* Substring */
928       gfc_charlen *length;
929     }
930     ss;
931
932   }
933   u;
934
935   struct gfc_ref *next;
936 }
937 gfc_ref;
938
939 #define gfc_get_ref() gfc_getmem(sizeof(gfc_ref))
940
941
942 /* Structures representing intrinsic symbols and their arguments lists.  */
943 typedef struct gfc_intrinsic_arg
944 {
945   char name[GFC_MAX_SYMBOL_LEN + 1];
946
947   gfc_typespec ts;
948   int optional;
949   gfc_actual_arglist *actual;
950
951   struct gfc_intrinsic_arg *next;
952
953 }
954 gfc_intrinsic_arg;
955
956
957 /* Specifies the various kinds of check functions used to verify the
958    argument lists of intrinsic functions. fX with X an integer refer
959    to check functions of intrinsics with X arguments. f1m is used for
960    the MAX and MIN intrinsics which can have an arbitrary number of
961    arguments, f3ml is used for the MINLOC and MAXLOC intrinsics as
962    these have special semantics.  */
963
964 typedef union
965 {
966   try (*f0)(void);
967   try (*f1)(struct gfc_expr *);
968   try (*f1m)(gfc_actual_arglist *);
969   try (*f2)(struct gfc_expr *, struct gfc_expr *);
970   try (*f3)(struct gfc_expr *, struct gfc_expr *, struct gfc_expr *);
971   try (*f3ml)(gfc_actual_arglist *);
972   try (*f3red)(gfc_actual_arglist *);
973   try (*f4)(struct gfc_expr *, struct gfc_expr *, struct gfc_expr *,
974             struct gfc_expr *);
975   try (*f5)(struct gfc_expr *, struct gfc_expr *, struct gfc_expr *,
976             struct gfc_expr *, struct gfc_expr *);
977 }
978 gfc_check_f;
979
980 /* Like gfc_check_f, these specify the type of the simplification
981    function associated with an intrinsic. The fX are just like in
982    gfc_check_f. cc is used for type conversion functions.  */
983
984 typedef union
985 {
986   struct gfc_expr *(*f0)(void);
987   struct gfc_expr *(*f1)(struct gfc_expr *);
988   struct gfc_expr *(*f2)(struct gfc_expr *, struct gfc_expr *);
989   struct gfc_expr *(*f3)(struct gfc_expr *, struct gfc_expr *,
990                          struct gfc_expr *);
991   struct gfc_expr *(*f4)(struct gfc_expr *, struct gfc_expr *,
992                          struct gfc_expr *, struct gfc_expr *);
993   struct gfc_expr *(*f5)(struct gfc_expr *, struct gfc_expr *,
994                          struct gfc_expr *, struct gfc_expr *,
995                          struct gfc_expr *);
996   struct gfc_expr *(*cc)(struct gfc_expr *, bt, int);
997 }
998 gfc_simplify_f;
999
1000 /* Again like gfc_check_f, these specify the type of the resolution
1001    function associated with an intrinsic. The fX are just like in
1002    gfc_check_f. f1m is used for MIN and MAX, s1 is used for abort().
1003    */
1004
1005 typedef union
1006 {
1007   void (*f0)(struct gfc_expr *);
1008   void (*f1)(struct gfc_expr *, struct gfc_expr *);
1009   void (*f1m)(struct gfc_expr *, struct gfc_actual_arglist *);
1010   void (*f2)(struct gfc_expr *, struct gfc_expr *, struct gfc_expr *);
1011   void (*f3)(struct gfc_expr *, struct gfc_expr *, struct gfc_expr *,
1012              struct gfc_expr *);
1013   void (*f4)(struct gfc_expr *, struct gfc_expr *, struct gfc_expr *,
1014              struct gfc_expr *, struct gfc_expr *);
1015   void (*f5)(struct gfc_expr *, struct gfc_expr *, struct gfc_expr *,
1016              struct gfc_expr *, struct gfc_expr *, struct gfc_expr *);
1017   void (*s1)(struct gfc_code *);
1018 }
1019 gfc_resolve_f;
1020
1021
1022 typedef struct gfc_intrinsic_sym
1023 {
1024   const char *name, *lib_name;
1025   gfc_intrinsic_arg *formal;
1026   gfc_typespec ts;
1027   int elemental, pure, generic, specific, actual_ok, standard;
1028
1029   gfc_simplify_f simplify;
1030   gfc_check_f check;
1031   gfc_resolve_f resolve;
1032   struct gfc_intrinsic_sym *specific_head, *next;
1033   gfc_generic_isym_id generic_id;
1034
1035 }
1036 gfc_intrinsic_sym;
1037
1038
1039 /* Expression nodes.  The expression node types deserve explanations,
1040    since the last couple can be easily misconstrued:
1041
1042    EXPR_OP         Operator node pointing to one or two other nodes
1043    EXPR_FUNCTION   Function call, symbol points to function's name
1044    EXPR_CONSTANT   A scalar constant: Logical, String, Real, Int or Complex
1045    EXPR_VARIABLE   An Lvalue with a root symbol and possible reference list
1046                    which expresses structure, array and substring refs.
1047    EXPR_NULL       The NULL pointer value (which also has a basic type).
1048    EXPR_SUBSTRING  A substring of a constant string
1049    EXPR_STRUCTURE  A structure constructor
1050    EXPR_ARRAY      An array constructor.  */
1051
1052 #include <gmp.h>
1053 #include <mpfr.h>
1054 #define GFC_RND_MODE GMP_RNDN
1055
1056 typedef struct gfc_expr
1057 {
1058   expr_t expr_type;
1059
1060   gfc_typespec ts;      /* These two refer to the overall expression */
1061
1062   int rank;
1063   mpz_t *shape;         /* Can be NULL if shape is unknown at compile time */
1064
1065   /* Nonnull for functions and structure constructors */
1066   gfc_symtree *symtree;
1067
1068   gfc_ref *ref;
1069
1070   locus where;
1071
1072   union
1073   {
1074     int logical;
1075     mpz_t integer;
1076
1077     mpfr_t real;
1078
1079     struct
1080     {
1081       mpfr_t r, i;
1082     }
1083     complex;
1084
1085     struct
1086     {
1087       gfc_intrinsic_op operator;
1088       gfc_user_op *uop;
1089       struct gfc_expr *op1, *op2;
1090     }
1091     op;
1092
1093     struct
1094     {
1095       gfc_actual_arglist *actual;
1096       const char *name; /* Points to the ultimate name of the function */
1097       gfc_intrinsic_sym *isym;
1098       gfc_symbol *esym;
1099     }
1100     function;
1101
1102     struct
1103     {
1104       int length;
1105       char *string;
1106     }
1107     character;
1108
1109     struct gfc_constructor *constructor;
1110   }
1111   value;
1112
1113 }
1114 gfc_expr;
1115
1116
1117 #define gfc_get_shape(rank) ((mpz_t *) gfc_getmem((rank)*sizeof(mpz_t)))
1118
1119 /* Structures for information associated with different kinds of
1120    numbers.  The first set of integer parameters define all there is
1121    to know about a particular kind.  The rest of the elements are
1122    computed from the first elements.  */
1123
1124 typedef struct
1125 {
1126   /* Values really representable by the target.  */
1127   mpz_t huge, pedantic_min_int, min_int, max_int;
1128
1129   int kind, radix, digits, bit_size, range;
1130
1131   /* True if the C type of the given name maps to this precision.
1132      Note that more than one bit can be set.  */
1133   unsigned int c_char : 1;
1134   unsigned int c_short : 1;
1135   unsigned int c_int : 1;
1136   unsigned int c_long : 1;
1137   unsigned int c_long_long : 1;
1138 }
1139 gfc_integer_info;
1140
1141 extern gfc_integer_info gfc_integer_kinds[];
1142
1143
1144 typedef struct
1145 {
1146   int kind, bit_size;
1147
1148   /* True if the C++ type bool, C99 type _Bool, maps to this precision.  */
1149   unsigned int c_bool : 1;
1150 }
1151 gfc_logical_info;
1152
1153 extern gfc_logical_info gfc_logical_kinds[];
1154
1155
1156 typedef struct
1157 {
1158   mpfr_t epsilon, huge, tiny, subnormal;
1159   int kind, radix, digits, min_exponent, max_exponent;
1160   int range, precision;
1161
1162   /* The precision of the type as reported by GET_MODE_PRECISION.  */
1163   int mode_precision;
1164
1165   /* True if the C type of the given name maps to this precision.
1166      Note that more than one bit can be set.  */
1167   unsigned int c_float : 1;
1168   unsigned int c_double : 1;
1169   unsigned int c_long_double : 1;
1170 }
1171 gfc_real_info;
1172
1173 extern gfc_real_info gfc_real_kinds[];
1174
1175
1176 /* Equivalence structures.  Equivalent lvalues are linked along the
1177    *eq pointer, equivalence sets are strung along the *next node.  */
1178 typedef struct gfc_equiv
1179 {
1180   struct gfc_equiv *next, *eq;
1181   gfc_expr *expr;
1182   int used;
1183 }
1184 gfc_equiv;
1185
1186 #define gfc_get_equiv() gfc_getmem(sizeof(gfc_equiv))
1187
1188
1189 /* gfc_case stores the selector list of a case statement.  The *low
1190    and *high pointers can point to the same expression in the case of
1191    a single value.  If *high is NULL, the selection is from *low
1192    upwards, if *low is NULL the selection is *high downwards.
1193
1194    This structure has separate fields to allow single and double linked
1195    lists of CASEs at the same time.  The singe linked list along the NEXT
1196    field is a list of cases for a single CASE label.  The double linked
1197    list along the LEFT/RIGHT fields is used to detect overlap and to
1198    build a table of the cases for SELECT constructs with a CHARACTER
1199    case expression.  */
1200
1201 typedef struct gfc_case
1202 {
1203   /* Where we saw this case.  */
1204   locus where;
1205   int n;
1206
1207   /* Case range values.  If (low == high), it's a single value.  If one of
1208      the labels is NULL, it's an unbounded case.  If both are NULL, this
1209      represents the default case.  */
1210   gfc_expr *low, *high;
1211
1212   /* Next case label in the list of cases for a single CASE label.  */
1213   struct gfc_case *next;
1214
1215   /* Used for detecting overlap, and for code generation.  */
1216   struct gfc_case *left, *right;
1217
1218   /* True if this case label can never be matched.  */
1219   int unreachable;
1220 }
1221 gfc_case;
1222
1223 #define gfc_get_case() gfc_getmem(sizeof(gfc_case))
1224
1225
1226 typedef struct
1227 {
1228   gfc_expr *var, *start, *end, *step;
1229 }
1230 gfc_iterator;
1231
1232 #define gfc_get_iterator() gfc_getmem(sizeof(gfc_iterator))
1233
1234
1235 /* Allocation structure for ALLOCATE, DEALLOCATE and NULLIFY statements.  */
1236
1237 typedef struct gfc_alloc
1238 {
1239   gfc_expr *expr;
1240   struct gfc_alloc *next;
1241 }
1242 gfc_alloc;
1243
1244 #define gfc_get_alloc() gfc_getmem(sizeof(gfc_alloc))
1245
1246
1247 typedef struct
1248 {
1249   gfc_expr *unit, *file, *status, *access, *form, *recl,
1250     *blank, *position, *action, *delim, *pad, *iostat;
1251   gfc_st_label *err;
1252 }
1253 gfc_open;
1254
1255
1256 typedef struct
1257 {
1258   gfc_expr *unit, *status, *iostat;
1259   gfc_st_label *err;
1260 }
1261 gfc_close;
1262
1263
1264 typedef struct
1265 {
1266   gfc_expr *unit, *iostat;
1267   gfc_st_label *err;
1268 }
1269 gfc_filepos;
1270
1271
1272 typedef struct
1273 {
1274   gfc_expr *unit, *file, *iostat, *exist, *opened, *number, *named,
1275     *name, *access, *sequential, *direct, *form, *formatted,
1276     *unformatted, *recl, *nextrec, *blank, *position, *action, *read,
1277     *write, *readwrite, *delim, *pad, *iolength;
1278
1279   gfc_st_label *err;
1280
1281 }
1282 gfc_inquire;
1283
1284
1285 typedef struct
1286 {
1287   gfc_expr *io_unit, *format_expr, *rec, *advance, *iostat, *size;
1288
1289   gfc_symbol *namelist;
1290   /* A format_label of `format_asterisk' indicates the "*" format */
1291   gfc_st_label *format_label;
1292   gfc_st_label *err, *end, *eor;
1293
1294   locus eor_where, end_where;
1295 }
1296 gfc_dt;
1297
1298
1299 typedef struct gfc_forall_iterator
1300 {
1301   gfc_expr *var, *start, *end, *stride;
1302   struct gfc_forall_iterator *next;
1303 }
1304 gfc_forall_iterator;
1305
1306
1307 /* Executable statements that fill gfc_code structures.  */
1308 typedef enum
1309 {
1310   EXEC_NOP = 1, EXEC_ASSIGN, EXEC_LABEL_ASSIGN, EXEC_POINTER_ASSIGN,
1311   EXEC_GOTO, EXEC_CALL, EXEC_RETURN, EXEC_ENTRY,
1312   EXEC_PAUSE, EXEC_STOP, EXEC_CONTINUE,
1313   EXEC_IF, EXEC_ARITHMETIC_IF, EXEC_DO, EXEC_DO_WHILE, EXEC_SELECT,
1314   EXEC_FORALL, EXEC_WHERE, EXEC_CYCLE, EXEC_EXIT,
1315   EXEC_ALLOCATE, EXEC_DEALLOCATE,
1316   EXEC_OPEN, EXEC_CLOSE,
1317   EXEC_READ, EXEC_WRITE, EXEC_IOLENGTH, EXEC_TRANSFER, EXEC_DT_END,
1318   EXEC_BACKSPACE, EXEC_ENDFILE, EXEC_INQUIRE, EXEC_REWIND
1319 }
1320 gfc_exec_op;
1321
1322 typedef struct gfc_code
1323 {
1324   gfc_exec_op op;
1325
1326   struct gfc_code *block, *next;
1327   locus loc;
1328
1329   gfc_st_label *here, *label, *label2, *label3;
1330   gfc_symtree *symtree;
1331   gfc_expr *expr, *expr2;
1332   /* A name isn't sufficient to identify a subroutine, we need the actual
1333      symbol for the interface definition.
1334   const char *sub_name;  */
1335   gfc_symbol *resolved_sym;
1336
1337   union
1338   {
1339     gfc_actual_arglist *actual;
1340     gfc_case *case_list;
1341     gfc_iterator *iterator;
1342     gfc_alloc *alloc_list;
1343     gfc_open *open;
1344     gfc_close *close;
1345     gfc_filepos *filepos;
1346     gfc_inquire *inquire;
1347     gfc_dt *dt;
1348     gfc_forall_iterator *forall_iterator;
1349     struct gfc_code *whichloop;
1350     int stop_code;
1351     gfc_entry_list *entry;
1352   }
1353   ext;          /* Points to additional structures required by statement */
1354
1355   /* Backend_decl is used for cycle and break labels in do loops, and
1356    * probably for other constructs as well, once we translate them.  */
1357   tree backend_decl;
1358 }
1359 gfc_code;
1360
1361
1362 /* Storage for DATA statements.  */
1363 typedef struct gfc_data_variable
1364 {
1365   gfc_expr *expr;
1366   gfc_iterator iter;
1367   struct gfc_data_variable *list, *next;
1368 }
1369 gfc_data_variable;
1370
1371
1372 typedef struct gfc_data_value
1373 {
1374   unsigned int repeat;
1375   gfc_expr *expr;
1376   struct gfc_data_value *next;
1377 }
1378 gfc_data_value;
1379
1380
1381 typedef struct gfc_data
1382 {
1383   gfc_data_variable *var;
1384   gfc_data_value *value;
1385   locus where;
1386
1387   struct gfc_data *next;
1388 }
1389 gfc_data;
1390
1391 #define gfc_get_data_variable() gfc_getmem(sizeof(gfc_data_variable))
1392 #define gfc_get_data_value() gfc_getmem(sizeof(gfc_data_value))
1393 #define gfc_get_data() gfc_getmem(sizeof(gfc_data))
1394
1395
1396 /* Structure for holding compile options */
1397 typedef struct
1398 {
1399   const char *source;
1400   char *module_dir;
1401   gfc_source_form source_form;
1402   int fixed_line_length;
1403   int max_identifier_length;
1404   int verbose;
1405
1406   int warn_aliasing;
1407   int warn_conversion;
1408   int warn_implicit_interface;
1409   int warn_line_truncation;
1410   int warn_underflow;
1411   int warn_surprising;
1412   int warn_unused_labels;
1413
1414   int flag_default_double;
1415   int flag_default_integer;
1416   int flag_default_real;
1417   int flag_dollar_ok;
1418   int flag_underscoring;
1419   int flag_second_underscore;
1420   int flag_implicit_none;
1421   int flag_max_stack_var_size;
1422   int flag_module_access_private;
1423   int flag_no_backend;
1424   int flag_pack_derived;
1425   int flag_repack_arrays;
1426   int flag_f2c;
1427   int flag_backslash;
1428
1429   int q_kind;
1430
1431   int warn_std;
1432   int allow_std;
1433   int warn_nonstd_intrinsics;
1434 }
1435 gfc_option_t;
1436
1437 extern gfc_option_t gfc_option;
1438
1439
1440 /* Constructor nodes for array and structure constructors.  */
1441 typedef struct gfc_constructor
1442 {
1443   gfc_expr *expr;
1444   gfc_iterator *iterator;
1445   locus where;
1446   struct gfc_constructor *next;
1447   struct
1448   {
1449     mpz_t offset; /* Record the offset of array element which appears in
1450                      data statement like "data a(5)/4/".  */
1451     gfc_component *component; /* Record the component being initialized.  */
1452   }
1453   n;
1454   mpz_t repeat; /* Record the repeat number of initial values in data
1455                  statement like "data a/5*10/".  */
1456 }
1457 gfc_constructor;
1458
1459
1460 typedef struct iterator_stack
1461 {
1462   gfc_symtree *variable;
1463   mpz_t value;
1464   struct iterator_stack *prev;
1465 }
1466 iterator_stack;
1467 extern iterator_stack *iter_stack;
1468
1469 /************************ Function prototypes *************************/
1470
1471 /* data.c  */
1472 void gfc_formalize_init_value (gfc_symbol *);
1473 void gfc_get_section_index (gfc_array_ref *, mpz_t *, mpz_t *);
1474 void gfc_assign_data_value (gfc_expr *, gfc_expr *, mpz_t);
1475 void gfc_assign_data_value_range (gfc_expr *, gfc_expr *, mpz_t, mpz_t);
1476 void gfc_advance_section (mpz_t *, gfc_array_ref *, mpz_t *);
1477
1478 /* scanner.c */
1479 void gfc_scanner_done_1 (void);
1480 void gfc_scanner_init_1 (void);
1481
1482 void gfc_add_include_path (const char *);
1483 void gfc_release_include_path (void);
1484 FILE *gfc_open_included_file (const char *);
1485
1486 int gfc_at_end (void);
1487 int gfc_at_eof (void);
1488 int gfc_at_bol (void);
1489 int gfc_at_eol (void);
1490 void gfc_advance_line (void);
1491 int gfc_check_include (void);
1492
1493 void gfc_skip_comments (void);
1494 int gfc_next_char_literal (int);
1495 int gfc_next_char (void);
1496 int gfc_peek_char (void);
1497 void gfc_error_recovery (void);
1498 void gfc_gobble_whitespace (void);
1499 try gfc_new_file (const char *, gfc_source_form);
1500
1501 extern gfc_source_form gfc_current_form;
1502 extern char *gfc_source_file;
1503 extern locus gfc_current_locus;
1504
1505 /* misc.c */
1506 void *gfc_getmem (size_t) ATTRIBUTE_MALLOC;
1507 void gfc_free (void *);
1508 int gfc_terminal_width(void);
1509 void gfc_clear_ts (gfc_typespec *);
1510 FILE *gfc_open_file (const char *);
1511 const char *gfc_article (const char *);
1512 const char *gfc_basic_typename (bt);
1513 const char *gfc_typename (gfc_typespec *);
1514
1515 #define gfc_op2string(OP) (OP == INTRINSIC_ASSIGN ? \
1516                            "=" : gfc_code2string (intrinsic_operators, OP))
1517
1518 const char *gfc_code2string (const mstring *, int);
1519 int gfc_string2code (const mstring *, const char *);
1520 const char *gfc_intent_string (sym_intent);
1521
1522 void gfc_init_1 (void);
1523 void gfc_init_2 (void);
1524 void gfc_done_1 (void);
1525 void gfc_done_2 (void);
1526
1527 /* options.c */
1528 unsigned int gfc_init_options (unsigned int, const char **);
1529 int gfc_handle_option (size_t, const char *, int);
1530 bool gfc_post_options (const char **);
1531
1532 /* iresolve.c */
1533 const char * gfc_get_string (const char *, ...) ATTRIBUTE_PRINTF_1;
1534
1535 /* error.c */
1536
1537 typedef struct gfc_error_buf
1538 {
1539   int flag;
1540   char message[MAX_ERROR_MESSAGE];
1541 } gfc_error_buf;
1542
1543 void gfc_error_init_1 (void);
1544 void gfc_buffer_error (int);
1545
1546 void gfc_warning (const char *, ...);
1547 void gfc_warning_now (const char *, ...);
1548 void gfc_clear_warning (void);
1549 void gfc_warning_check (void);
1550
1551 void gfc_error (const char *, ...);
1552 void gfc_error_now (const char *, ...);
1553 void gfc_fatal_error (const char *, ...) ATTRIBUTE_NORETURN;
1554 void gfc_internal_error (const char *, ...) ATTRIBUTE_NORETURN;
1555 void gfc_clear_error (void);
1556 int gfc_error_check (void);
1557
1558 try gfc_notify_std (int, const char *, ...);
1559
1560 /* A general purpose syntax error.  */
1561 #define gfc_syntax_error(ST)    \
1562   gfc_error ("Syntax error in %s statement at %C", gfc_ascii_statement (ST));
1563
1564 void gfc_push_error (gfc_error_buf *);
1565 void gfc_pop_error (gfc_error_buf *);
1566
1567 void gfc_status (const char *, ...) ATTRIBUTE_PRINTF_1;
1568 void gfc_status_char (char);
1569
1570 void gfc_get_errors (int *, int *);
1571
1572 /* arith.c */
1573 void gfc_arith_init_1 (void);
1574 void gfc_arith_done_1 (void);
1575
1576 /* trans-types.c */
1577 int gfc_validate_kind (bt, int, bool);
1578 extern int gfc_index_integer_kind;
1579 extern int gfc_default_integer_kind;
1580 extern int gfc_max_integer_kind;
1581 extern int gfc_default_real_kind;
1582 extern int gfc_default_double_kind;
1583 extern int gfc_default_character_kind;
1584 extern int gfc_default_logical_kind;
1585 extern int gfc_default_complex_kind;
1586 extern int gfc_c_int_kind;
1587
1588 /* symbol.c */
1589 void gfc_clear_new_implicit (void);
1590 try gfc_add_new_implicit_range (int, int);
1591 try gfc_merge_new_implicit (gfc_typespec *);
1592 void gfc_set_implicit_none (void);
1593
1594 gfc_typespec *gfc_get_default_type (gfc_symbol *, gfc_namespace *);
1595 try gfc_set_default_type (gfc_symbol *, int, gfc_namespace *);
1596
1597 void gfc_set_component_attr (gfc_component *, symbol_attribute *);
1598 void gfc_get_component_attr (symbol_attribute *, gfc_component *);
1599
1600 void gfc_set_sym_referenced (gfc_symbol * sym);
1601
1602 try gfc_add_allocatable (symbol_attribute *, locus *);
1603 try gfc_add_dimension (symbol_attribute *, const char *, locus *);
1604 try gfc_add_external (symbol_attribute *, locus *);
1605 try gfc_add_intrinsic (symbol_attribute *, locus *);
1606 try gfc_add_optional (symbol_attribute *, locus *);
1607 try gfc_add_pointer (symbol_attribute *, locus *);
1608 try gfc_add_result (symbol_attribute *, const char *, locus *);
1609 try gfc_add_save (symbol_attribute *, const char *, locus *);
1610 try gfc_add_saved_common (symbol_attribute *, locus *);
1611 try gfc_add_target (symbol_attribute *, locus *);
1612 try gfc_add_dummy (symbol_attribute *, const char *, locus *);
1613 try gfc_add_generic (symbol_attribute *, const char *, locus *);
1614 try gfc_add_common (symbol_attribute *, locus *);
1615 try gfc_add_in_common (symbol_attribute *, const char *, locus *);
1616 try gfc_add_data (symbol_attribute *, const char *, locus *);
1617 try gfc_add_in_namelist (symbol_attribute *, const char *, locus *);
1618 try gfc_add_sequence (symbol_attribute *, const char *, locus *);
1619 try gfc_add_elemental (symbol_attribute *, locus *);
1620 try gfc_add_pure (symbol_attribute *, locus *);
1621 try gfc_add_recursive (symbol_attribute *, locus *);
1622 try gfc_add_function (symbol_attribute *, const char *, locus *);
1623 try gfc_add_subroutine (symbol_attribute *, const char *, locus *);
1624
1625 try gfc_add_access (symbol_attribute *, gfc_access, const char *, locus *);
1626 try gfc_add_flavor (symbol_attribute *, sym_flavor, const char *, locus *);
1627 try gfc_add_entry (symbol_attribute *, const char *, locus *);
1628 try gfc_add_procedure (symbol_attribute *, procedure_type,
1629                        const char *, locus *);
1630 try gfc_add_intent (symbol_attribute *, sym_intent, locus *);
1631 try gfc_add_explicit_interface (gfc_symbol *, ifsrc,
1632                                 gfc_formal_arglist *, locus *);
1633 try gfc_add_type (gfc_symbol *, gfc_typespec *, locus *);
1634
1635 void gfc_clear_attr (symbol_attribute *);
1636 try gfc_missing_attr (symbol_attribute *, locus *);
1637 try gfc_copy_attr (symbol_attribute *, symbol_attribute *, locus *);
1638
1639 try gfc_add_component (gfc_symbol *, const char *, gfc_component **);
1640 gfc_symbol *gfc_use_derived (gfc_symbol *);
1641 gfc_symtree *gfc_use_derived_tree (gfc_symtree *);
1642 gfc_component *gfc_find_component (gfc_symbol *, const char *);
1643
1644 gfc_st_label *gfc_get_st_label (int);
1645 void gfc_free_st_label (gfc_st_label *);
1646 void gfc_define_st_label (gfc_st_label *, gfc_sl_type, locus *);
1647 try gfc_reference_st_label (gfc_st_label *, gfc_sl_type);
1648
1649 gfc_namespace *gfc_get_namespace (gfc_namespace *, int);
1650 gfc_symtree *gfc_new_symtree (gfc_symtree **, const char *);
1651 gfc_symtree *gfc_find_symtree (gfc_symtree *, const char *);
1652 gfc_user_op *gfc_get_uop (const char *);
1653 gfc_user_op *gfc_find_uop (const char *, gfc_namespace *);
1654 void gfc_free_symbol (gfc_symbol *);
1655 gfc_symbol *gfc_new_symbol (const char *, gfc_namespace *);
1656 int gfc_find_symbol (const char *, gfc_namespace *, int, gfc_symbol **);
1657 int gfc_find_sym_tree (const char *, gfc_namespace *, int, gfc_symtree **);
1658 int gfc_get_symbol (const char *, gfc_namespace *, gfc_symbol **);
1659 int gfc_get_sym_tree (const char *, gfc_namespace *, gfc_symtree **);
1660 int gfc_get_ha_symbol (const char *, gfc_symbol **);
1661 int gfc_get_ha_sym_tree (const char *, gfc_symtree **);
1662
1663 int gfc_symbols_could_alias (gfc_symbol *, gfc_symbol *);
1664
1665 void gfc_undo_symbols (void);
1666 void gfc_commit_symbols (void);
1667 void gfc_free_namespace (gfc_namespace *);
1668
1669 void gfc_symbol_init_2 (void);
1670 void gfc_symbol_done_2 (void);
1671
1672 void gfc_traverse_symtree (gfc_symtree *, void (*)(gfc_symtree *));
1673 void gfc_traverse_ns (gfc_namespace *, void (*)(gfc_symbol *));
1674 void gfc_traverse_user_op (gfc_namespace *, void (*)(gfc_user_op *));
1675 void gfc_save_all (gfc_namespace *);
1676
1677 void gfc_symbol_state (void);
1678
1679 gfc_gsymbol *gfc_get_gsymbol (const char *);
1680 gfc_gsymbol *gfc_find_gsymbol (gfc_gsymbol *, const char *);
1681
1682 /* intrinsic.c */
1683 extern int gfc_init_expr;
1684
1685 /* Given a symbol that we have decided is intrinsic, mark it as such
1686    by placing it into a special module that is otherwise impossible to
1687    read or write.  */
1688
1689 #define gfc_intrinsic_symbol(SYM) SYM->module = gfc_get_string ("(intrinsic)")
1690
1691 void gfc_intrinsic_init_1 (void);
1692 void gfc_intrinsic_done_1 (void);
1693
1694 char gfc_type_letter (bt);
1695 gfc_symbol * gfc_get_intrinsic_sub_symbol (const char *);
1696 try gfc_convert_type (gfc_expr *, gfc_typespec *, int);
1697 try gfc_convert_type_warn (gfc_expr *, gfc_typespec *, int, int);
1698 int gfc_generic_intrinsic (const char *);
1699 int gfc_specific_intrinsic (const char *);
1700 int gfc_intrinsic_name (const char *, int);
1701 gfc_intrinsic_sym *gfc_find_function (const char *);
1702
1703 match gfc_intrinsic_func_interface (gfc_expr *, int);
1704 match gfc_intrinsic_sub_interface (gfc_code *, int);
1705
1706 /* simplify.c */
1707 void gfc_simplify_init_1 (void);
1708
1709 /* match.c -- FIXME */
1710 void gfc_free_iterator (gfc_iterator *, int);
1711 void gfc_free_forall_iterator (gfc_forall_iterator *);
1712 void gfc_free_alloc_list (gfc_alloc *);
1713 void gfc_free_namelist (gfc_namelist *);
1714 void gfc_free_equiv (gfc_equiv *);
1715 void gfc_free_data (gfc_data *);
1716 void gfc_free_case_list (gfc_case *);
1717
1718 /* expr.c */
1719 void gfc_free_actual_arglist (gfc_actual_arglist *);
1720 gfc_actual_arglist *gfc_copy_actual_arglist (gfc_actual_arglist *);
1721 const char *gfc_extract_int (gfc_expr *, int *);
1722
1723 gfc_expr *gfc_build_conversion (gfc_expr *);
1724 void gfc_free_ref_list (gfc_ref *);
1725 void gfc_type_convert_binary (gfc_expr *);
1726 int gfc_is_constant_expr (gfc_expr *);
1727 try gfc_simplify_expr (gfc_expr *, int);
1728
1729 gfc_expr *gfc_get_expr (void);
1730 void gfc_free_expr (gfc_expr *);
1731 void gfc_replace_expr (gfc_expr *, gfc_expr *);
1732 gfc_expr *gfc_int_expr (int);
1733 gfc_expr *gfc_logical_expr (int, locus *);
1734 mpz_t *gfc_copy_shape (mpz_t *, int);
1735 mpz_t *gfc_copy_shape_excluding (mpz_t *, int, gfc_expr *);
1736 gfc_expr *gfc_copy_expr (gfc_expr *);
1737
1738 try gfc_specification_expr (gfc_expr *);
1739
1740 int gfc_numeric_ts (gfc_typespec *);
1741 int gfc_kind_max (gfc_expr *, gfc_expr *);
1742
1743 try gfc_check_conformance (const char *, gfc_expr *, gfc_expr *);
1744 try gfc_check_assign (gfc_expr *, gfc_expr *, int);
1745 try gfc_check_pointer_assign (gfc_expr *, gfc_expr *);
1746 try gfc_check_assign_symbol (gfc_symbol *, gfc_expr *);
1747
1748 gfc_expr *gfc_default_initializer (gfc_typespec *);
1749 gfc_expr *gfc_get_variable_expr (gfc_symtree *);
1750
1751
1752 /* st.c */
1753 extern gfc_code new_st;
1754
1755 void gfc_clear_new_st (void);
1756 gfc_code *gfc_get_code (void);
1757 gfc_code *gfc_append_code (gfc_code *, gfc_code *);
1758 void gfc_free_statement (gfc_code *);
1759 void gfc_free_statements (gfc_code *);
1760
1761 /* resolve.c */
1762 try gfc_resolve_expr (gfc_expr *);
1763 void gfc_resolve (gfc_namespace *);
1764 int gfc_impure_variable (gfc_symbol *);
1765 int gfc_pure (gfc_symbol *);
1766 int gfc_elemental (gfc_symbol *);
1767 try gfc_resolve_iterator (gfc_iterator *, bool);
1768 try gfc_resolve_index (gfc_expr *, int);
1769
1770 /* array.c */
1771 void gfc_free_array_spec (gfc_array_spec *);
1772 gfc_array_ref *gfc_copy_array_ref (gfc_array_ref *);
1773
1774 try gfc_set_array_spec (gfc_symbol *, gfc_array_spec *, locus *);
1775 gfc_array_spec *gfc_copy_array_spec (gfc_array_spec *);
1776 try gfc_resolve_array_spec (gfc_array_spec *, int);
1777
1778 int gfc_compare_array_spec (gfc_array_spec *, gfc_array_spec *);
1779
1780 gfc_expr *gfc_start_constructor (bt, int, locus *);
1781 void gfc_append_constructor (gfc_expr *, gfc_expr *);
1782 void gfc_free_constructor (gfc_constructor *);
1783 void gfc_simplify_iterator_var (gfc_expr *);
1784 try gfc_expand_constructor (gfc_expr *);
1785 int gfc_constant_ac (gfc_expr *);
1786 int gfc_expanded_ac (gfc_expr *);
1787 try gfc_resolve_array_constructor (gfc_expr *);
1788 try gfc_check_constructor_type (gfc_expr *);
1789 try gfc_check_iter_variable (gfc_expr *);
1790 try gfc_check_constructor (gfc_expr *, try (*)(gfc_expr *));
1791 gfc_constructor *gfc_copy_constructor (gfc_constructor * src);
1792 gfc_expr *gfc_get_array_element (gfc_expr *, int);
1793 try gfc_array_size (gfc_expr *, mpz_t *);
1794 try gfc_array_dimen_size (gfc_expr *, int, mpz_t *);
1795 try gfc_array_ref_shape (gfc_array_ref *, mpz_t *);
1796 gfc_array_ref *gfc_find_array_ref (gfc_expr *);
1797 void gfc_insert_constructor (gfc_expr *, gfc_constructor *);
1798 gfc_constructor *gfc_get_constructor (void);
1799 tree gfc_conv_array_initializer (tree type, gfc_expr * expr);
1800 try spec_size (gfc_array_spec *, mpz_t *);
1801 int gfc_is_compile_time_shape (gfc_array_spec *);
1802
1803 /* interface.c -- FIXME: some of these should be in symbol.c */
1804 void gfc_free_interface (gfc_interface *);
1805 int gfc_compare_types (gfc_typespec *, gfc_typespec *);
1806 void gfc_check_interfaces (gfc_namespace *);
1807 void gfc_procedure_use (gfc_symbol *, gfc_actual_arglist **, locus *);
1808 gfc_symbol *gfc_search_interface (gfc_interface *, int,
1809                                   gfc_actual_arglist **);
1810 try gfc_extend_expr (gfc_expr *);
1811 void gfc_free_formal_arglist (gfc_formal_arglist *);
1812 try gfc_extend_assign (gfc_code *, gfc_namespace *);
1813 try gfc_add_interface (gfc_symbol * sym);
1814
1815 /* io.c */
1816 extern gfc_st_label format_asterisk;
1817
1818 void gfc_free_open (gfc_open *);
1819 try gfc_resolve_open (gfc_open *);
1820 void gfc_free_close (gfc_close *);
1821 try gfc_resolve_close (gfc_close *);
1822 void gfc_free_filepos (gfc_filepos *);
1823 try gfc_resolve_filepos (gfc_filepos *);
1824 void gfc_free_inquire (gfc_inquire *);
1825 try gfc_resolve_inquire (gfc_inquire *);
1826 void gfc_free_dt (gfc_dt *);
1827 try gfc_resolve_dt (gfc_dt *);
1828
1829 /* module.c */
1830 void gfc_module_init_2 (void);
1831 void gfc_module_done_2 (void);
1832 void gfc_dump_module (const char *, int);
1833 bool gfc_check_access (gfc_access, gfc_access);
1834
1835 /* primary.c */
1836 symbol_attribute gfc_variable_attr (gfc_expr *, gfc_typespec *);
1837 symbol_attribute gfc_expr_attr (gfc_expr *);
1838
1839 /* trans.c */
1840 void gfc_generate_code (gfc_namespace *);
1841 void gfc_generate_module_code (gfc_namespace *);
1842
1843 /* bbt.c */
1844 typedef int (*compare_fn) (void *, void *);
1845 void gfc_insert_bbt (void *, void *, compare_fn);
1846 void gfc_delete_bbt (void *, void *, compare_fn);
1847
1848 /* dump-parse-tree.c */
1849 void gfc_show_namespace (gfc_namespace *);
1850
1851 /* parse.c */
1852 try gfc_parse_file (void);
1853
1854 #endif /* GCC_GFORTRAN_H  */