~jdpipe/ascend/trunk-old

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
/*	ASCEND modelling environment
	Copyright (C) 1990, 1993, 1994 Thomas Guthrie Epperly
	Copyright (C) 2006-2007 Carnegie Mellon University

	This program 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.

	This program 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 this program.  If not, see <http://www.gnu.org/licenses/>.
*//**
	@file
	Type Definition Library.

	Implements a type definition library for use by the ASCEND compiler.
	Each type encountered during parsing is converted to a TypeDescription
	and stored in the main type library maintained by this module.
	The type library will only maintain one definition for a given type
	name.  The library will complain if you try to add two types with the
	same name unless it happens when reloading a module.
*//*
	by Tom Epperly, 1/12/90
	Last in CVS: $Revision: 1.17 $ $Date: 1998/04/16 00:43:24 $ $Author: ballan $
*/

#ifndef ASC_LIBRARY_H
#define ASC_LIBRARY_H

#include <ascend/general/list.h>

#include "compiler.h"
#include "type_desc.h"
#include "module.h"

/**	@addtogroup compiler_file Compiler File Handling
	@{
*/


/** For use in constructing hierarchies. */
struct HierarchyNode {
  struct TypeDescription *desc;   /**< The type at this node. */
  struct gl_list_t *descendents;  /**< The list of refinements of desc. */
};

extern void InitializeLibrary(void);
/**<
 *  Initializes the library.
 *  This should be called before using any other functions
 *  or globals in this module.  Call DestroyLibrary() when
 *  finished with the library.
 */

ASC_DLLSPEC void DestroyLibrary(void);
/**<
 *  Cleans up after library use.
 *  Do not use any other functions or globals in this module after
 *  using this function until InitializeLibrary() is called.
 */

ASC_DLLSPEC struct TypeDescription *FindType(symchar *name);
/**<
 *  Finds the type description associated with name.
 *  Returns NULL if unable to locate the type.
 *  Handles NULL input gracefully.
 *
 *  @param name The type name to look up.
 *  @return The type description having the specified name,
 *          or NULL if none have that name.
 */

extern struct TypeDescription *FindRelationType(void);
/**<
 *  Finds the type description associated with real relations.
 *  Returns NULL if never defined, which means someone forgot to
 *  load a system.lib equivalent.
 */

extern struct TypeDescription *FindLogRelType(void);
/**<
 *  Finds the type description associated with logical relations.
 *  Returns NULL if never defined, which means someone forgot to
 *  load a system.lib equivalent.
 */

extern struct TypeDescription *FindSetType(void);
/**<
 *  Finds the type description associated with set statements.
 *  Returns NULL if never defined, which is an extreme error.
 */

extern struct TypeDescription *FindDummyType(void);
/**<
 *  Finds the type description associated with unselected statements.
 *  Returns NULL if never defined, which is an extreme error.
 */

extern struct TypeDescription *FindWhenType(void);
/**<
 *  Finds the type description associated with WHEN statements.
 *  Returns NULL if never defined, which is an extreme error.
 */

extern struct TypeDescription *FindExternalType(void);
/**<
 *  Finds the type description associated with external statements.
 *  Returns NULL if never defined, which is an extreme error.
 */

extern int AddType(struct TypeDescription *desc);
/**<
 *  Adds a type to the library.
 *  The type is not added if it is already present in the
 *  type library.  Otherwise, the library takes ownership of
 *  desc and adds it to the library.
 *
 *  @param desc The type to add to the library.
 *  @return Returns 1 if the new type is added and kept,
 *          0 if it was already present.
 */

ASC_DLLSPEC struct gl_list_t *FindFundamentalTypes(void);
/**<
 *  Creates a gl_list_t containing pointers to the fundamental
 *  types.  Destruction of the returned list (but not it's
 *  contents) is the responsibility of the caller.
 *
 *  @return A gl_list_t of (struct TypeDescription *) to the
 *          fundamental types.
 */

ASC_DLLSPEC struct gl_list_t*Asc_TypeByModule(CONST struct module_t *module);
/**<
 *  Builds a list of type names defined in module that are already
 *  present in the main type library.  Destruction of the returned
 *  list (but not its contents) is the responsibility of the caller.
 *
 *  @param module The module to parse for defined type names.
 *  @return A gl_list_t of (symchar *) to the names of types found
 *          both in module and in the main type library.
 */

ASC_DLLSPEC struct gl_list_t *TypesThatRefineMe (symchar *name);
/**<
 *  Builds a list of type names in the main type library which refine
 *  the type having the specified name.  The returned list includes
 *  immediate refinements only, not all of the refinements in a chain
 *  such as a<-b<-c<-d.  Given a, only b is included in the list.
 *  This should be an expensive function and could be made more
 *  efficient for certain atomic types.  Destruction of the returned
 *  list (but not its contents) is the responsibility of the caller.
 *
 *  @param name The type name to check for registered refinements.
 *  @return A gl_list_t of (symchar *) to the names of types in the main
 *          type library which refine the specified type.
 */

ASC_DLLSPEC struct gl_list_t *AllTypesThatRefineMe_Flat (symchar *name);
/**<
 *  Builds a list of all type names in the main type library which
 *  refine the type having the specified name.  The returned list
 *  includes all refinements in a chain such as a<-b<-c<-d.  Given a,
 *  b, c, and d are all included in the list.  This is only slightly
 *  more expensive than TypesThatRefineMe().  For efficiency atoms
 *  and models are handled differently.  Destruction of the returned
 *  list (but not its contents) is the responsibility of the caller.
 *
 *  @param name The type name to check for registered refinements.
 *  @return A gl_list_t of (symchar *) to the names of types in the main
 *          type library which refine the specified type.
 */

ASC_DLLSPEC struct HierarchyNode *AllTypesThatRefineMe_Tree (symchar *name);
/**<
 *  Builds a tree of HierarchyNodes all types in the main type library
 *  which refine the type having the specified name.  This is similar to
 *  AllTypesThatRefineMe_Flat() except that the results are returned in
 *  a HierarchyNodes tree.  This is somewhat pricey in terms of the number
 *  of pointer comparisons.   For efficiency atoms and models are handled
 *  separately.  The first node returned is the node of the type given.
 *  If it is null, the type given was not found.  Destruction of the
 *  returned tree is the responsibility of the caller.  Use
 *  DestroyHierarchyNode() for this purpose.
 *
 *  @param name The type name to check for registered refinements.
 *  @return A tree of HierarchyNodes containing the types in the main
 *          type library which refine the specified type.
 */

ASC_DLLSPEC void DestroyHierarchyNode(struct HierarchyNode *heir);
/**<
 *  Deallocates (recursively) all the memory associated with a
 *  HierarchyNode.  Use this function to destroy the tree returned
 *  by AllTypesThatRefineMe_Tree().
 *
 *  @param heir Head of the HeirarchyNode tree to destroy.
 */

ASC_DLLSPEC int IsTypeRefined(CONST struct TypeDescription *desc);
/**<
 *  Check whether the specified type is refined by any other type in
 *  the main type library.
 *
 *  @param desc The type to check for refinements.
 *  @return Returns 1 if desc is refined, 0 otherwise.
 */

ASC_DLLSPEC struct gl_list_t *DefinitionList(void);
/**<
 *  Makes a sorted list of all registered definitions.
 *  In the case of there being two versions of a given type,
 *  the latest version is used.  This doesn't include array type
 *  definitions.  The user is responsible for destroying the
 *  returned list (but not its content).
 *
 *  @return A gl_list_t of (struct TypeDescription *) containing
 *          the sorted types.
 */

ASC_DLLSPEC unsigned int CheckFundamental(symchar *f);
/**<
 *  Checks whether string f is a fundamental type name.
 *  f must be from the symbol table (i.e. not an externally-defined
 *  character string).
 *
 *  @param f The string to check.
 *  @return Returns 1 if f is a fundamental type name, 0 if not.
 */

/* @} */

#endif /* ASC_LIBRARY_H */