1 /* implic.c -- Implementation File (module.c template V1.0)
2 Copyright (C) 1995 Free Software Foundation, Inc.
3 Contributed by James Craig Burley (burley@gnu.org).
5 This file is part of GNU Fortran.
7 GNU Fortran is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2, or (at your option)
12 GNU Fortran is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GNU Fortran; see the file COPYING. If not, write to
19 the Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
26 The GNU Fortran Front End.
41 /* Externals defined here. */
44 /* Simple definitions and enumerations. */
48 FFEIMPLIC_stateINITIAL_
,
49 FFEIMPLIC_stateASSUMED_
,
50 FFEIMPLIC_stateESTABLISHED_
,
54 /* Internal typedefs. */
56 typedef struct _ffeimplic_
*ffeimplic_
;
58 /* Private include files. */
61 /* Internal structure definitions. */
65 ffeimplicState_ state
;
69 /* Static objects accessed by functions in this module. */
71 /* NOTE: This is definitely ASCII-specific!! */
73 static struct _ffeimplic_ ffeimplic_table_
['z' - 'A' + 1];
75 /* Static functions (internal). */
77 static ffeimplic_
ffeimplic_lookup_ (char c
);
79 /* Internal macros. */
82 /* ffeimplic_lookup_ -- Look up implicit descriptor for initial character
85 if ((imp = ffeimplic_lookup_('A')) == NULL)
88 Returns a pointer to an implicit descriptor block based on the character
89 passed, or NULL if it is not a valid initial character for an implicit
93 ffeimplic_lookup_ (char c
)
95 /* NOTE: This is definitely ASCII-specific!! */
96 if (isalpha (c
) || (c
== '_'))
97 return &ffeimplic_table_
[c
- 'A'];
101 /* ffeimplic_establish_initial -- Establish type of implicit initial letter
104 if (!ffeimplic_establish_initial(s))
107 Assigns implicit type information to the symbol based on the first
108 character of the symbol's name. */
111 ffeimplic_establish_initial (char c
, ffeinfoBasictype basic_type
,
112 ffeinfoKindtype kind_type
, ffetargetCharacterSize size
)
116 imp
= ffeimplic_lookup_ (c
);
118 return FALSE
; /* Character not A-Z or some such thing. */
119 if (ffeinfo_basictype (imp
->info
) == FFEINFO_basictypeNONE
)
120 return FALSE
; /* IMPLICIT NONE in effect here. */
124 case FFEIMPLIC_stateINITIAL_
:
125 imp
->info
= ffeinfo_new (basic_type
,
131 imp
->state
= FFEIMPLIC_stateESTABLISHED_
;
134 case FFEIMPLIC_stateASSUMED_
:
135 if ((ffeinfo_basictype (imp
->info
) != basic_type
)
136 || (ffeinfo_kindtype (imp
->info
) != kind_type
)
137 || (ffeinfo_size (imp
->info
) != size
))
139 imp
->state
= FFEIMPLIC_stateESTABLISHED_
;
142 case FFEIMPLIC_stateESTABLISHED_
:
146 assert ("Weird state for implicit object" == NULL
);
151 /* ffeimplic_establish_symbol -- Establish implicit type of a symbol
154 if (!ffeimplic_establish_symbol(s))
157 Assigns implicit type information to the symbol based on the first
158 character of the symbol's name.
160 If symbol already has a type, return TRUE.
161 Get first character of symbol's name.
162 Get ffeimplic_ object for it (return FALSE if NULL returned).
163 Return FALSE if object has no assigned type (IMPLICIT NONE).
164 Copy the type information from the object to the symbol.
165 If the object is state "INITIAL", set to state "ASSUMED" so no
166 subsequent IMPLICIT statement may change the state.
170 ffeimplic_establish_symbol (ffesymbol s
)
175 if (ffesymbol_basictype (s
) != FFEINFO_basictypeNONE
)
178 c
= *(ffesymbol_text (s
));
179 imp
= ffeimplic_lookup_ (c
);
181 return FALSE
; /* First character not A-Z or some such
183 if (ffeinfo_basictype (imp
->info
) == FFEINFO_basictypeNONE
)
184 return FALSE
; /* IMPLICIT NONE in effect here. */
186 ffesymbol_signal_change (s
); /* Gonna change, save existing? */
188 /* Establish basictype, kindtype, size; preserve rank, kind, where. */
190 ffesymbol_set_info (s
,
191 ffeinfo_new (ffeinfo_basictype (imp
->info
),
192 ffeinfo_kindtype (imp
->info
),
196 ffeinfo_size (imp
->info
)));
198 if (imp
->state
== FFEIMPLIC_stateINITIAL_
)
199 imp
->state
= FFEIMPLIC_stateASSUMED_
;
201 if (ffe_is_warn_implicit ())
203 ffebad_start_msg ("Implicit declaration of `%A' at %0",
204 FFEBAD_severityWARNING
);
205 ffebad_here (0, ffesymbol_where_line (s
),
206 ffesymbol_where_column (s
));
207 ffebad_string (ffesymbol_text (s
));
214 /* ffeimplic_init_2 -- Initialize table
218 Assigns initial type information to all initial letters.
220 Allows for holes in the sequence of letters (i.e. EBCDIC). */
228 for (c
= 'A'; c
<= 'z'; ++c
)
230 imp
= &ffeimplic_table_
[c
- 'A'];
231 imp
->state
= FFEIMPLIC_stateINITIAL_
;
275 imp
->info
= ffeinfo_new (FFEINFO_basictypeREAL
,
276 FFEINFO_kindtypeREALDEFAULT
,
280 FFETARGET_charactersizeNONE
);
295 imp
->info
= ffeinfo_new (FFEINFO_basictypeINTEGER
,
296 FFEINFO_kindtypeINTEGERDEFAULT
, 0, FFEINFO_kindNONE
, FFEINFO_whereNONE
,
297 FFETARGET_charactersizeNONE
);
301 imp
->info
= ffeinfo_new (FFEINFO_basictypeNONE
, FFEINFO_kindtypeNONE
, 0,
302 FFEINFO_kindNONE
, FFEINFO_whereNONE
, FFETARGET_charactersizeNONE
);
308 /* ffeimplic_none -- Implement IMPLICIT NONE statement
312 Assigns null type information to all initial letters. */
319 for (imp
= &ffeimplic_table_
[0];
320 imp
!= &ffeimplic_table_
[ARRAY_SIZE (ffeimplic_table_
)];
323 imp
->info
= ffeinfo_new (FFEINFO_basictypeNONE
,
324 FFEINFO_kindtypeNONE
,
328 FFETARGET_charactersizeNONE
);
332 /* ffeimplic_peek_symbol_type -- Determine implicit type of a symbol
335 char *name; // name for s in case it is NULL, or NULL if s never NULL
336 if (ffeimplic_peek_symbol_type(s,name) == FFEINFO_basictypeCHARACTER)
337 // is or will be a CHARACTER-typed name
339 Like establish_symbol, but doesn't change anything.
341 If symbol is non-NULL and already has a type, return it.
342 Get first character of symbol's name or from name arg if symbol is NULL.
343 Get ffeimplic_ object for it (return FALSE if NULL returned).
344 Return NONE if object has no assigned type (IMPLICIT NONE).
345 Return the data type indicated in the object.
348 Take a char * instead of ffelexToken, since the latter isn't always
349 needed anyway (as when ffecom calls it). */
352 ffeimplic_peek_symbol_type (ffesymbol s
, char *name
)
361 if (ffesymbol_basictype (s
) != FFEINFO_basictypeNONE
)
362 return ffesymbol_basictype (s
);
364 c
= *(ffesymbol_text (s
));
367 imp
= ffeimplic_lookup_ (c
);
369 return FFEINFO_basictypeNONE
; /* First character not A-Z or
371 return ffeinfo_basictype (imp
->info
);
374 /* ffeimplic_terminate_2 -- Terminate table
376 ffeimplic_terminate_2();
378 Kills info object for each entry in table. */
381 ffeimplic_terminate_2 ()