2003-12-26 Guilhem Lavaux <guilhem@kaffe.org>
[official-gcc.git] / gcc / f / info.c
blob3c0030f27f8f172514fb5a3719d1c473f9227452
1 /* info.c -- Implementation File (module.c template V1.0)
2 Copyright (C) 1995, 2002, 2003 Free Software Foundation, Inc.
3 Contributed by James Craig Burley.
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)
10 any later version.
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
20 02111-1307, USA.
22 Related Modules:
23 None
25 Description:
26 An abstraction for information maintained on a per-operator and per-
27 operand basis in expression trees.
29 Modifications:
30 30-Aug-90 JCB 2.0
31 Extensive rewrite for new cleaner approach.
34 /* Include files. */
36 #include "proj.h"
37 #include "info.h"
38 #include "target.h"
39 #include "type.h"
41 /* Externals defined here. */
44 /* Simple definitions and enumerations. */
47 /* Internal typedefs. */
50 /* Private include files. */
53 /* Internal structure definitions. */
56 /* Static objects accessed by functions in this module. */
58 static const char *const ffeinfo_basictype_string_[]
61 #define FFEINFO_BASICTYPE(KWD,LNAM,SNAM) SNAM,
62 #include "info-b.def"
63 #undef FFEINFO_BASICTYPE
65 static const char *const ffeinfo_kind_message_[]
68 #define FFEINFO_KIND(kwd,msgid,snam) msgid,
69 #include "info-k.def"
70 #undef FFEINFO_KIND
72 static const char *const ffeinfo_kind_string_[]
75 #define FFEINFO_KIND(KWD,LNAM,SNAM) SNAM,
76 #include "info-k.def"
77 #undef FFEINFO_KIND
79 static ffeinfoBasictype ffeinfo_combine_[FFEINFO_basictype][FFEINFO_basictype];
80 static const char *const ffeinfo_kindtype_string_[]
83 "",
84 "1",
85 "2",
86 "3",
87 "4",
88 "5",
89 "6",
90 "7",
91 "8",
92 "*",
94 static const char *const ffeinfo_where_string_[]
97 #define FFEINFO_WHERE(KWD,LNAM,SNAM) SNAM,
98 #include "info-w.def"
99 #undef FFEINFO_WHERE
101 static ffetype ffeinfo_types_[FFEINFO_basictype][FFEINFO_kindtype];
103 /* Static functions (internal). */
106 /* Internal macros. */
109 /* ffeinfo_basictype_combine -- Combine two basictypes into highest rank type
111 ffeinfoBasictype i, j, k;
112 k = ffeinfo_basictype_combine(i,j);
114 Returns a type based on "standard" operation between two given types. */
116 ffeinfoBasictype
117 ffeinfo_basictype_combine (ffeinfoBasictype l, ffeinfoBasictype r)
119 assert (l < FFEINFO_basictype);
120 assert (r < FFEINFO_basictype);
121 return ffeinfo_combine_[l][r];
124 /* ffeinfo_basictype_string -- Return tiny string showing the basictype
126 ffeinfoBasictype i;
127 printf("%s",ffeinfo_basictype_string(dt));
129 Returns the string based on the basic type. */
131 const char *
132 ffeinfo_basictype_string (ffeinfoBasictype basictype)
134 if (basictype >= ARRAY_SIZE (ffeinfo_basictype_string_))
135 return "?\?\?";
136 return ffeinfo_basictype_string_[basictype];
139 /* ffeinfo_init_0 -- Initialize
141 ffeinfo_init_0(); */
143 void
144 ffeinfo_init_0 (void)
146 ffeinfoBasictype i;
147 ffeinfoBasictype j;
149 assert (FFEINFO_basictype == ARRAY_SIZE (ffeinfo_basictype_string_));
150 assert (FFEINFO_kind == ARRAY_SIZE (ffeinfo_kind_message_));
151 assert (FFEINFO_kind == ARRAY_SIZE (ffeinfo_kind_string_));
152 assert (FFEINFO_kindtype == ARRAY_SIZE (ffeinfo_kindtype_string_));
153 assert (FFEINFO_where == ARRAY_SIZE (ffeinfo_where_string_));
155 /* Make array that, given two basic types, produces resulting basic type. */
157 for (i = 0; i < FFEINFO_basictype; ++i)
158 for (j = 0; j < FFEINFO_basictype; ++j)
159 if ((i == FFEINFO_basictypeANY) || (j == FFEINFO_basictypeANY))
160 ffeinfo_combine_[i][j] = FFEINFO_basictypeANY;
161 else
162 ffeinfo_combine_[i][j] = FFEINFO_basictypeNONE;
164 #define same(bt) ffeinfo_combine_[bt][bt] = bt
165 #define use2(bt1,bt2) ffeinfo_combine_[bt1][bt2] \
166 = ffeinfo_combine_[bt2][bt1] = bt2
168 same (FFEINFO_basictypeINTEGER);
169 same (FFEINFO_basictypeLOGICAL);
170 same (FFEINFO_basictypeREAL);
171 same (FFEINFO_basictypeCOMPLEX);
172 same (FFEINFO_basictypeCHARACTER);
173 use2 (FFEINFO_basictypeINTEGER, FFEINFO_basictypeREAL);
174 use2 (FFEINFO_basictypeINTEGER, FFEINFO_basictypeCOMPLEX);
175 use2 (FFEINFO_basictypeREAL, FFEINFO_basictypeCOMPLEX);
177 #undef same
178 #undef use2
181 /* ffeinfo_kind_message -- Return helpful string showing the kind
183 ffeinfoKind kind;
184 printf("%s",ffeinfo_kind_message(kind));
186 Returns the string based on the kind. */
188 const char *
189 ffeinfo_kind_message (ffeinfoKind kind)
191 if (kind >= ARRAY_SIZE (ffeinfo_kind_message_))
192 return "?\?\?";
193 return ffeinfo_kind_message_[kind];
196 /* ffeinfo_kind_string -- Return tiny string showing the kind
198 ffeinfoKind kind;
199 printf("%s",ffeinfo_kind_string(kind));
201 Returns the string based on the kind. */
203 const char *
204 ffeinfo_kind_string (ffeinfoKind kind)
206 if (kind >= ARRAY_SIZE (ffeinfo_kind_string_))
207 return "?\?\?";
208 return ffeinfo_kind_string_[kind];
211 ffeinfoKindtype
212 ffeinfo_kindtype_max(ffeinfoBasictype bt,
213 ffeinfoKindtype k1,
214 ffeinfoKindtype k2)
216 if ((bt == FFEINFO_basictypeANY)
217 || (k1 == FFEINFO_kindtypeANY)
218 || (k2 == FFEINFO_kindtypeANY))
219 return FFEINFO_kindtypeANY;
221 if (ffetype_size (ffeinfo_types_[bt][k1])
222 > ffetype_size (ffeinfo_types_[bt][k2]))
223 return k1;
224 return k2;
227 /* ffeinfo_kindtype_string -- Return tiny string showing the kind type
229 ffeinfoKindtype kind_type;
230 printf("%s",ffeinfo_kindtype_string(kind));
232 Returns the string based on the kind type. */
234 const char *
235 ffeinfo_kindtype_string (ffeinfoKindtype kind_type)
237 if (kind_type >= ARRAY_SIZE (ffeinfo_kindtype_string_))
238 return "?\?\?";
239 return ffeinfo_kindtype_string_[kind_type];
242 void
243 ffeinfo_set_type (ffeinfoBasictype basictype, ffeinfoKindtype kindtype,
244 ffetype type)
246 assert (basictype < FFEINFO_basictype);
247 assert (kindtype < FFEINFO_kindtype);
248 assert (ffeinfo_types_[basictype][kindtype] == NULL);
250 ffeinfo_types_[basictype][kindtype] = type;
253 ffetype
254 ffeinfo_type (ffeinfoBasictype basictype, ffeinfoKindtype kindtype)
256 assert (basictype < FFEINFO_basictype);
257 assert (kindtype < FFEINFO_kindtype);
259 return ffeinfo_types_[basictype][kindtype];
262 /* ffeinfo_where_string -- Return tiny string showing the where
264 ffeinfoWhere where;
265 printf("%s",ffeinfo_where_string(where));
267 Returns the string based on the where. */
269 const char *
270 ffeinfo_where_string (ffeinfoWhere where)
272 if (where >= ARRAY_SIZE (ffeinfo_where_string_))
273 return "?\?\?";
274 return ffeinfo_where_string_[where];
277 /* ffeinfo_new -- Return object representing datatype, kind, and where info
279 ffeinfo i;
280 i = ffeinfo_new(FFEINFO_datatypeINTEGER,FFEINFO_kindSCALAR,
281 FFEINFO_whereLOCAL);
283 Returns the string based on the data type. */
285 #ifndef __GNUC__
286 ffeinfo
287 ffeinfo_new (ffeinfoBasictype basictype, ffeinfoKindtype kindtype,
288 ffeinfoRank rank, ffeinfoKind kind, ffeinfoWhere where,
289 ffetargetCharacterSize size)
291 ffeinfo i;
293 i.basictype = basictype;
294 i.kindtype = kindtype;
295 i.rank = rank;
296 i.size = size;
297 i.kind = kind;
298 i.where = where;
299 i.size = size;
301 return i;
303 #endif