1 /* name.c -- Implementation File (module.c template V1.0)
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)
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 Name and name space abstraction.
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. */
59 /* Static functions (internal). */
61 static ffename ffename_lookup_ (ffenameSpace ns, ffelexToken t, bool *found);
63 /* Internal macros. */
66 /* Searches for and returns the matching ffename object, or returns a
67 pointer to the name before which the new name should go. */
70 ffename_lookup_ (ffenameSpace ns, ffelexToken t, bool *found)
74 for (n = ns->first; n != (ffename) &ns->first; n = n->next)
76 if (ffelex_token_strcmp (t, n->t) == 0)
84 return n; /* (n == (ffename) &ns->first) */
87 /* Searches for and returns the matching ffename object, or creates a new
88 one (with a NULL ffesymbol) and returns that. If last arg is TRUE,
89 check whether token meets character-content requirements (such as
90 "all characters must be uppercase", as determined by
91 ffesrc_bad_char_symbol (), issue diagnostic if it doesn't. */
94 ffename_find (ffenameSpace ns, ffelexToken t)
101 assert ((t != NULL) && ((ffelex_token_type (t) == FFELEX_typeNAME)
102 || (ffelex_token_type (t) == FFELEX_typeNAMES)));
104 n = ffename_lookup_ (ns, t, &found);
108 newn = malloc_new_ks (ns->pool, "FFENAME name", sizeof (*n));
110 newn->previous = n->previous;
112 newn->previous->next = newn;
113 newn->t = ffelex_token_use (t);
119 /* ffename_kill -- Kill name from name space
125 Removes the name from the name space. */
128 ffename_kill (ffenameSpace ns, ffename n)
133 ffelex_token_kill (n->t);
134 n->next->previous = n->previous;
135 n->previous->next = n->next;
136 malloc_kill_ks (ns->pool, n, sizeof (*n));
139 /* ffename_lookup -- Look up name in name space
144 n = ffename_lookup(ns,t);
146 Searches for and returns the matching ffename object, or returns NULL. */
149 ffename_lookup (ffenameSpace ns, ffelexToken t)
155 assert ((t != NULL) && ((ffelex_token_type (t) == FFELEX_typeNAME)
156 || (ffelex_token_type (t) == FFELEX_typeNAMES)));
158 n = ffename_lookup_ (ns, t, &found);
160 return found ? n : NULL;
163 /* ffename_space_drive_global -- Call given fn for each global in name space
167 ffename_space_drive_global(ns,fn); */
170 ffename_space_drive_global (ffenameSpace ns, ffeglobal (*fn) (ffeglobal))
177 for (n = ns->first; n != (ffename) &ns->first; n = n->next)
180 n->u.g = (*fn) (n->u.g);
184 /* ffename_space_drive_symbol -- Call given fn for each symbol in name space
188 ffename_space_drive_symbol(ns,fn); */
191 ffename_space_drive_symbol (ffenameSpace ns, ffesymbol (*fn) (ffesymbol))
198 for (n = ns->first; n != (ffename) &ns->first; n = n->next)
201 n->u.s = (*fn) (n->u.s);
205 /* ffename_space_kill -- Kill name space
208 ffename_space_kill(ns);
210 Removes the names from the name space; kills the name space. */
213 ffename_space_kill (ffenameSpace ns)
217 while (ns->first != (ffename) &ns->first)
218 ffename_kill (ns, ns->first);
220 malloc_kill_ks (ns->pool, ns, sizeof (*ns));
223 /* ffename_space_new -- Create name space
226 ns = ffename_space_new(malloc_pool_image());
228 Create new name space. */
231 ffename_space_new (mallocPool pool)
235 ns = malloc_new_ks (pool, "FFENAME space", sizeof (*ns));
236 ns->first = (ffename) &ns->first;
237 ns->last = (ffename) &ns->first;