2003-12-26 Guilhem Lavaux <guilhem@kaffe.org>
[official-gcc.git] / gcc / f / type.c
blobd25ab50f4c2a1b18057e17b6666ddf2f36837876
1 /* Implementation of Fortran type abstraction
2 Copyright (C) 1995 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 #include "proj.h"
23 #include "type.h"
24 #include "malloc.h"
27 /* Look up a type given its base type and kind value. */
29 ffetype
30 ffetype_lookup_kind (ffetype base_type, int kind)
32 if ((base_type->kinds_ == NULL)
33 || (kind < 0)
34 || (((size_t) kind) >= ARRAY_SIZE (base_type->kinds_->type_)))
35 return NULL;
37 return base_type->kinds_->type_[kind];
40 ffetype
41 ffetype_lookup_star (ffetype base_type, int star)
43 if ((base_type->stars_ == NULL)
44 || (star < 0)
45 || (((size_t) star) >= ARRAY_SIZE (base_type->stars_->type_)))
46 return NULL;
48 return base_type->stars_->type_[star];
51 ffetype
52 ffetype_new (void)
54 ffetype type;
56 type = malloc_new_kp (malloc_pool_image (), "ffetype", sizeof (*type));
57 type->kinds_ = NULL;
58 type->stars_ = NULL;
59 type->alignment_ = 0;
60 type->modulo_ = 0;
61 type->size_ = 0;
63 return type;
66 void
67 ffetype_set_kind (ffetype base_type, int kind, ffetype type)
69 assert (kind < (int) sizeof (*(base_type->kinds_)));
71 if (base_type->kinds_ == NULL)
73 int i;
75 base_type->kinds_
76 = malloc_new_kp (malloc_pool_image (), "ffetype_indexes_[kinds]",
77 sizeof (*(base_type->kinds_)));
78 for (i = 0; ((size_t) i) < ARRAY_SIZE (base_type->kinds_->type_); ++i)
79 base_type->kinds_->type_[i] = NULL;
82 assert (base_type->kinds_->type_[kind] == NULL);
84 base_type->kinds_->type_[kind] = type;
87 void
88 ffetype_set_star (ffetype base_type, int star, ffetype type)
90 if (base_type->stars_ == NULL)
92 int i;
94 base_type->stars_
95 = malloc_new_kp (malloc_pool_image (), "ffetype_indexes_[stars]",
96 sizeof (*(base_type->stars_)));
97 for (i = 0; ((size_t) i) < ARRAY_SIZE (base_type->stars_->type_); ++i)
98 base_type->stars_->type_[i] = NULL;
101 assert (base_type->stars_->type_[star] == NULL);
103 base_type->stars_->type_[star] = type;