xref: /openbsd/gnu/usr.bin/gcc/gcc/f/type.c (revision c87b03e5)
1 /* Implementation of Fortran type abstraction
2    Copyright (C) 1995 Free Software Foundation, Inc.
3    Contributed by James Craig Burley.
4 
5 This file is part of GNU Fortran.
6 
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.
11 
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.
16 
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.  */
21 
22 #include "proj.h"
23 #include "type.h"
24 #include "malloc.h"
25 
26 
27 /* Look up a type given its base type and kind value.  */
28 
29 ffetype
ffetype_lookup_kind(ffetype base_type,int kind)30 ffetype_lookup_kind (ffetype base_type, int kind)
31 {
32   if ((base_type->kinds_ == NULL)
33       || (kind < 0)
34       || (((size_t) kind) >= ARRAY_SIZE (base_type->kinds_->type_)))
35     return NULL;
36 
37   return base_type->kinds_->type_[kind];
38 }
39 
40 ffetype
ffetype_lookup_star(ffetype base_type,int star)41 ffetype_lookup_star (ffetype base_type, int star)
42 {
43   if ((base_type->stars_ == NULL)
44       || (star < 0)
45       || (((size_t) star) >= ARRAY_SIZE (base_type->stars_->type_)))
46     return NULL;
47 
48   return base_type->stars_->type_[star];
49 }
50 
51 ffetype
ffetype_new(void)52 ffetype_new (void)
53 {
54   ffetype type;
55 
56   type = (ffetype) malloc_new_kp (malloc_pool_image (), "ffetype",
57 				    sizeof (*type));
58   type->kinds_ = NULL;
59   type->stars_ = NULL;
60   type->alignment_ = 0;
61   type->modulo_ = 0;
62   type->size_ = 0;
63 
64   return type;
65 }
66 
67 void
ffetype_set_kind(ffetype base_type,int kind,ffetype type)68 ffetype_set_kind (ffetype base_type, int kind, ffetype type)
69 {
70   assert (kind < (int) sizeof (*(base_type->kinds_)));
71 
72   if (base_type->kinds_ == NULL)
73     {
74       int i;
75 
76       base_type->kinds_
77 	= (ffetype_indexes_) malloc_new_kp (malloc_pool_image (),
78 					    "ffetype_indexes_[kinds]",
79 					    sizeof (*(base_type->kinds_)));
80       for (i = 0; ((size_t) i) < ARRAY_SIZE (base_type->kinds_->type_); ++i)
81 	base_type->kinds_->type_[i] = NULL;
82     }
83 
84   assert (base_type->kinds_->type_[kind] == NULL);
85 
86   base_type->kinds_->type_[kind] = type;
87 }
88 
89 void
ffetype_set_star(ffetype base_type,int star,ffetype type)90 ffetype_set_star (ffetype base_type, int star, ffetype type)
91 {
92   if (base_type->stars_ == NULL)
93     {
94       int i;
95 
96       base_type->stars_
97 	= (ffetype_indexes_) malloc_new_kp (malloc_pool_image (),
98 					    "ffetype_indexes_[stars]",
99 					    sizeof (*(base_type->stars_)));
100       for (i = 0; ((size_t) i) < ARRAY_SIZE (base_type->stars_->type_); ++i)
101 	base_type->stars_->type_[i] = NULL;
102     }
103 
104   assert (base_type->stars_->type_[star] == NULL);
105 
106   base_type->stars_->type_[star] = type;
107 }
108