26f096f9e5
* bad.c (_ffebad_message_, ffebad_string_, ffebad_message_, ffebad_bufputs_, ffebad_bufputs_, ffebad_start_, ffebad_string, ffebad_finish): Const-ify a char*. * bld.c (ffebld_op_string_, ffebld_op_string): Likewise. * bld.h (ffebld_op_string): Likewise. * com.c (ffecom_arglist_expr_, ffecom_build_f2c_string_, ffecom_debug_kludge_, ffecom_f2c_make_type_, ffecom_get_appended_identifier_, ffecom_get_identifier_, ffecom_gfrt_args_): Likewise. (ffecom_convert_narrow_, ffecom_convert_widen_): Add prototype. (builtin_function, ffecom_gfrt_name_, ffecom_gfrt_argstring_, ffecom_arglist_expr_, ffecom_build_f2c_string_, ffecom_debug_kludge_, ffecom_f2c_make_type_, ffecom_get_appended_identifier_, ffecom_get_external_identifier_, ffecom_get_identifier_, ffecom_decl_field, ffecom_get_invented_identifier, lang_print_error_function, skip_redundant_dir_prefix, read_name_map, print_containing_files): Const-ify a char*. (savestring): Remove, use `xstrdup' instead. * com.h (ffecom_decl_field, ffecom_get_invented_identifier): Const-ify a char*. * data.c (ffebld, ffedata_gather_): Make explicitly static. * expr.c (ffeexpr_isdigits_, ffeexpr_percent_, ffeexpr_reduced_concatenate_, ffeexpr_nil_real_, ffeexpr_nil_number_, ffeexpr_nil_number_period_, ffeexpr_nil_number_real_, ffeexpr_token_real_, ffeexpr_token_number_, ffeexpr_token_number_period_, ffeexpr_token_number_real_): Const-ify a char*. * fini.c (xspaces): Likewise. * global.c (ffeglobal_type_string_): Likewise. (ffeglobal_drive): Protoize. (ffeglobal_proc_def_arg): Const-ify a char*. * global.h (ffeglobal_drive): Protoize. (ffeglobal_proc_def_arg): Const-ify a char*. * implic.c (ffeimplic_none, ffeimplic_peek_symbol_type): Likewise. * implic.h (ffeimplic_peek_symbol_type): Likewise. * info.c (ffeinfo_basictype_string_, ffeinfo_kind_message_, ffeinfo_kind_string_, ffeinfo_kindtype_string_, ffeinfo_where_string_, ffeinfo_basictype_string, ffeinfo_kind_message, ffeinfo_kind_string, ffeinfo_kindtype_string, ffeinfo_where_string): Likewise. * info.h (ffeinfo_basictype_string, ffeinfo_kind_message, ffeinfo_kind_string, ffeinfo_kindtype_string, ffeinfo_where_string): Likewise. * intrin.c (_ffeintrin_name_, _ffeintrin_gen_, _ffeintrin_spec_, _ffeintrin_imp_, ffeintrin_check_, ffeintrin_cmp_name_, ffeintrin_fulfill_specific, ffeintrin_init_0, ffeintrin_is_actualarg, ffeintrin_is_intrinsic, ffeintrin_name_generic, ffeintrin_name_implementation, ffeintrin_name_specific): Likewise. * intrin.h (ffeintrin_is_intrinsic, ffeintrin_name_generic, ffeintrin_name_implementation, ffeintrin_name_specific): Likewise. * lex.c (ffelex_type_string_, ffelex_token_new_character, ffelex_token_new_name, ffelex_token_new_names, ffelex_token_new_number): Likewise. * lex.h (ffelex_token_new_character, ffelex_token_new_name, ffelex_token_new_names, ffelex_token_new_number): Likewise. * malloc.c (malloc_types_, malloc_pool_new, malloc_new_inpool_, malloc_new_zinpool_): Likewise. * malloc.h (malloc_new_inpool_, malloc_new_zinpool_, malloc_pool_new): Likewise. * name.c (ffename_space_drive_global, ffename_space_drive_symbol): Protoize. * name.h (ffename_space_drive_global, ffename_space_drive_symbol): Likewise. * symbol.c (ffesymbol_state_name_, ffesymbol_attr_name_, ffesymbol_attrs_string): Const-ify a char*. (ffesymbol_drive, ffesymbol_drive_sfnames): Protoize. (ffesymbol_state_string): Const-ify a char*. * symbol.h (ffesymbol_attrs_string): Likewise. (ffesymbol_drive, ffesymbol_drive_sfnames): Protoize. (ffesymbol_state_string): Const-ify a char*. * target.c (ffetarget_layout): Likewise. * target.h (ffetarget_layout): Likewise. From-SVN: r26013
383 lines
8.8 KiB
C
383 lines
8.8 KiB
C
/* implic.c -- Implementation File (module.c template V1.0)
|
||
Copyright (C) 1995 Free Software Foundation, Inc.
|
||
Contributed by James Craig Burley.
|
||
|
||
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_ (unsigned 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_ (unsigned 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;
|
||
const 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, const 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 ()
|
||
{
|
||
}
|