1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
|
/* implic.c -- Implementation File (module.c template V1.0)
Copyright (C) 1995 Free Software Foundation, Inc.
Contributed by James Craig Burley (burley@gnu.org).
This file is part of GNU Fortran.
GNU Fortran is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
GNU Fortran is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with GNU Fortran; see the file COPYING. If not, write to
the Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
02111-1307, USA.
Related Modules:
None.
Description:
The GNU Fortran Front End.
Modifications:
*/
/* Include files. */
#include "proj.h"
#include "implic.h"
#include "info.h"
#include "src.h"
#include "symbol.h"
#include "target.h"
/* Externals defined here. */
/* Simple definitions and enumerations. */
typedef enum
{
FFEIMPLIC_stateINITIAL_,
FFEIMPLIC_stateASSUMED_,
FFEIMPLIC_stateESTABLISHED_,
FFEIMPLIC_state
} ffeimplicState_;
/* Internal typedefs. */
typedef struct _ffeimplic_ *ffeimplic_;
/* Private include files. */
/* Internal structure definitions. */
struct _ffeimplic_
{
ffeimplicState_ state;
ffeinfo info;
};
/* Static objects accessed by functions in this module. */
/* NOTE: This is definitely ASCII-specific!! */
static struct _ffeimplic_ ffeimplic_table_['z' - 'A' + 1];
/* Static functions (internal). */
static ffeimplic_ ffeimplic_lookup_ (char c);
/* Internal macros. */
/* ffeimplic_lookup_ -- Look up implicit descriptor for initial character
ffeimplic_ imp;
if ((imp = ffeimplic_lookup_('A')) == NULL)
// error
Returns a pointer to an implicit descriptor block based on the character
passed, or NULL if it is not a valid initial character for an implicit
data type. */
static ffeimplic_
ffeimplic_lookup_ (char c)
{
/* NOTE: This is definitely ASCII-specific!! */
if (ISALPHA (c) || (c == '_'))
return &ffeimplic_table_[c - 'A'];
return NULL;
}
/* ffeimplic_establish_initial -- Establish type of implicit initial letter
ffesymbol s;
if (!ffeimplic_establish_initial(s))
// error
Assigns implicit type information to the symbol based on the first
character of the symbol's name. */
bool
ffeimplic_establish_initial (char c, ffeinfoBasictype basic_type,
ffeinfoKindtype kind_type, ffetargetCharacterSize size)
{
ffeimplic_ imp;
imp = ffeimplic_lookup_ (c);
if (imp == NULL)
return FALSE; /* Character not A-Z or some such thing. */
if (ffeinfo_basictype (imp->info) == FFEINFO_basictypeNONE)
return FALSE; /* IMPLICIT NONE in effect here. */
switch (imp->state)
{
case FFEIMPLIC_stateINITIAL_:
imp->info = ffeinfo_new (basic_type,
kind_type,
0,
FFEINFO_kindNONE,
FFEINFO_whereNONE,
size);
imp->state = FFEIMPLIC_stateESTABLISHED_;
return TRUE;
case FFEIMPLIC_stateASSUMED_:
if ((ffeinfo_basictype (imp->info) != basic_type)
|| (ffeinfo_kindtype (imp->info) != kind_type)
|| (ffeinfo_size (imp->info) != size))
return FALSE;
imp->state = FFEIMPLIC_stateESTABLISHED_;
return TRUE;
case FFEIMPLIC_stateESTABLISHED_:
return FALSE;
default:
assert ("Weird state for implicit object" == NULL);
return FALSE;
}
}
/* ffeimplic_establish_symbol -- Establish implicit type of a symbol
ffesymbol s;
if (!ffeimplic_establish_symbol(s))
// error
Assigns implicit type information to the symbol based on the first
character of the symbol's name.
If symbol already has a type, return TRUE.
Get first character of symbol's name.
Get ffeimplic_ object for it (return FALSE if NULL returned).
Return FALSE if object has no assigned type (IMPLICIT NONE).
Copy the type information from the object to the symbol.
If the object is state "INITIAL", set to state "ASSUMED" so no
subsequent IMPLICIT statement may change the state.
Return TRUE. */
bool
ffeimplic_establish_symbol (ffesymbol s)
{
char c;
ffeimplic_ imp;
if (ffesymbol_basictype (s) != FFEINFO_basictypeNONE)
return TRUE;
c = *(ffesymbol_text (s));
imp = ffeimplic_lookup_ (c);
if (imp == NULL)
return FALSE; /* First character not A-Z or some such
thing. */
if (ffeinfo_basictype (imp->info) == FFEINFO_basictypeNONE)
return FALSE; /* IMPLICIT NONE in effect here. */
ffesymbol_signal_change (s); /* Gonna change, save existing? */
/* Establish basictype, kindtype, size; preserve rank, kind, where. */
ffesymbol_set_info (s,
ffeinfo_new (ffeinfo_basictype (imp->info),
ffeinfo_kindtype (imp->info),
ffesymbol_rank (s),
ffesymbol_kind (s),
ffesymbol_where (s),
ffeinfo_size (imp->info)));
if (imp->state == FFEIMPLIC_stateINITIAL_)
imp->state = FFEIMPLIC_stateASSUMED_;
if (ffe_is_warn_implicit ())
{
ffebad_start_msg ("Implicit declaration of `%A' at %0",
FFEBAD_severityWARNING);
ffebad_here (0, ffesymbol_where_line (s),
ffesymbol_where_column (s));
ffebad_string (ffesymbol_text (s));
ffebad_finish ();
}
return TRUE;
}
/* ffeimplic_init_2 -- Initialize table
ffeimplic_init_2();
Assigns initial type information to all initial letters.
Allows for holes in the sequence of letters (i.e. EBCDIC). */
void
ffeimplic_init_2 ()
{
ffeimplic_ imp;
char c;
for (c = 'A'; c <= 'z'; ++c)
{
imp = &ffeimplic_table_[c - 'A'];
imp->state = FFEIMPLIC_stateINITIAL_;
switch (c)
{
case 'A':
case 'B':
case 'C':
case 'D':
case 'E':
case 'F':
case 'G':
case 'H':
case 'O':
case 'P':
case 'Q':
case 'R':
case 'S':
case 'T':
case 'U':
case 'V':
case 'W':
case 'X':
case 'Y':
case 'Z':
case '_':
case 'a':
case 'b':
case 'c':
case 'd':
case 'e':
case 'f':
case 'g':
case 'h':
case 'o':
case 'p':
case 'q':
case 'r':
case 's':
case 't':
case 'u':
case 'v':
case 'w':
case 'x':
case 'y':
case 'z':
imp->info = ffeinfo_new (FFEINFO_basictypeREAL,
FFEINFO_kindtypeREALDEFAULT,
0,
FFEINFO_kindNONE,
FFEINFO_whereNONE,
FFETARGET_charactersizeNONE);
break;
case 'I':
case 'J':
case 'K':
case 'L':
case 'M':
case 'N':
case 'i':
case 'j':
case 'k':
case 'l':
case 'm':
case 'n':
imp->info = ffeinfo_new (FFEINFO_basictypeINTEGER,
FFEINFO_kindtypeINTEGERDEFAULT, 0, FFEINFO_kindNONE, FFEINFO_whereNONE,
FFETARGET_charactersizeNONE);
break;
default:
imp->info = ffeinfo_new (FFEINFO_basictypeNONE, FFEINFO_kindtypeNONE, 0,
FFEINFO_kindNONE, FFEINFO_whereNONE, FFETARGET_charactersizeNONE);
break;
}
}
}
/* ffeimplic_none -- Implement IMPLICIT NONE statement
ffeimplic_none();
Assigns null type information to all initial letters. */
void
ffeimplic_none ()
{
ffeimplic_ imp;
for (imp = &ffeimplic_table_[0];
imp != &ffeimplic_table_[ARRAY_SIZE (ffeimplic_table_)];
imp++)
{
imp->info = ffeinfo_new (FFEINFO_basictypeNONE,
FFEINFO_kindtypeNONE,
0,
FFEINFO_kindNONE,
FFEINFO_whereNONE,
FFETARGET_charactersizeNONE);
}
}
/* ffeimplic_peek_symbol_type -- Determine implicit type of a symbol
ffesymbol s;
char *name; // name for s in case it is NULL, or NULL if s never NULL
if (ffeimplic_peek_symbol_type(s,name) == FFEINFO_basictypeCHARACTER)
// is or will be a CHARACTER-typed name
Like establish_symbol, but doesn't change anything.
If symbol is non-NULL and already has a type, return it.
Get first character of symbol's name or from name arg if symbol is NULL.
Get ffeimplic_ object for it (return FALSE if NULL returned).
Return NONE if object has no assigned type (IMPLICIT NONE).
Return the data type indicated in the object.
24-Oct-91 JCB 2.0
Take a char * instead of ffelexToken, since the latter isn't always
needed anyway (as when ffecom calls it). */
ffeinfoBasictype
ffeimplic_peek_symbol_type (ffesymbol s, char *name)
{
char c;
ffeimplic_ imp;
if (s == NULL)
c = *name;
else
{
if (ffesymbol_basictype (s) != FFEINFO_basictypeNONE)
return ffesymbol_basictype (s);
c = *(ffesymbol_text (s));
}
imp = ffeimplic_lookup_ (c);
if (imp == NULL)
return FFEINFO_basictypeNONE; /* First character not A-Z or
something. */
return ffeinfo_basictype (imp->info);
}
/* ffeimplic_terminate_2 -- Terminate table
ffeimplic_terminate_2();
Kills info object for each entry in table. */
void
ffeimplic_terminate_2 ()
{
}
|