1 |
/* |
2 |
* FOR Loop Index Variable Table |
3 |
* by Tom Epperly |
4 |
* Created: 1/14/89 |
5 |
* Version: $Revision: 1.8 $ |
6 |
* Version control file: $RCSfile: forvars.h,v $ |
7 |
* Date last modified: $Date: 1998/02/05 16:36:08 $ |
8 |
* Last modified by: $Author: ballan $ |
9 |
* |
10 |
* This file is part of the Ascend Language Interpreter. |
11 |
* |
12 |
* Copyright (C) 1990, 1993, 1994 Thomas Guthrie Epperly |
13 |
* |
14 |
* The Ascend Language Interpreter is free software; you can redistribute |
15 |
* it and/or modify it under the terms of the GNU General Public License as |
16 |
* published by the Free Software Foundation; either version 2 of the |
17 |
* License, or (at your option) any later version. |
18 |
* |
19 |
* The Ascend Language Interpreter is distributed in hope that it will be |
20 |
* useful, but WITHOUT ANY WARRANTY; without even the implied warranty of |
21 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
22 |
* General Public License for more details. |
23 |
* |
24 |
* You should have received a copy of the GNU General Public License |
25 |
* along with the program; if not, write to the Free Software Foundation, |
26 |
* Inc., 675 Mass Ave, Cambridge, MA 02139 USA. Check the file named |
27 |
* COPYING. |
28 |
*/ |
29 |
|
30 |
/** @file |
31 |
* FOR Loop Index Variable Table. |
32 |
* <pre> |
33 |
* When #including forvars.h, make sure these files are #included first: |
34 |
* #include "utilities/ascConfig.h" |
35 |
* #include "compiler.h" |
36 |
* </pre> |
37 |
*/ |
38 |
|
39 |
#ifndef ASC_FORVARS_H |
40 |
#define ASC_FORVARS_H |
41 |
|
42 |
/** addtogroup compiler Compiler |
43 |
@{ |
44 |
*/ |
45 |
|
46 |
enum for_kind { |
47 |
f_untyped, |
48 |
f_integer, |
49 |
f_symbol, |
50 |
f_set |
51 |
}; |
52 |
|
53 |
union for_union_t{ |
54 |
long ivalue; |
55 |
symchar *sym_ptr; |
56 |
struct set_t *sptr; |
57 |
}; |
58 |
|
59 |
struct for_var_t { |
60 |
symchar *name; /**< internally used as a recycle ptr */ |
61 |
enum for_kind t; /**< what type of index variable it is */ |
62 |
union for_union_t value; |
63 |
}; |
64 |
|
65 |
#define for_table_t gl_list_t |
66 |
|
67 |
extern struct for_table_t *CreateForTable(void); |
68 |
/**< |
69 |
* <!-- struct for_table_t *CreateForTable() --> |
70 |
* This function creates an empty FOR table which is then ready for use. |
71 |
*/ |
72 |
|
73 |
extern void DestroyForTable(struct for_table_t *ft); |
74 |
/**< |
75 |
* <!-- void DestroyForTable(ft) --> |
76 |
* <!-- struct for_table_t *ft; --> |
77 |
* This procedure deallocates the memory associated with the for table. |
78 |
*/ |
79 |
|
80 |
extern void WriteForTable(FILE *out, struct for_table_t *ft); |
81 |
/**< |
82 |
* <!-- void WriteForTable(out,ft) --> |
83 |
* <!-- FILE *out; --> |
84 |
* <!-- struct for_table_t *ft; --> |
85 |
* This procedure writes the contents of a for table. |
86 |
*/ |
87 |
|
88 |
extern unsigned long ActiveForLoops(CONST struct for_table_t *ft); |
89 |
/**< |
90 |
* <!-- unsigned long ActiveForLoops(ft) --> |
91 |
* <!-- struct for_table_t *ft; --> |
92 |
* Returns the number of active FOR loops. |
93 |
*/ |
94 |
|
95 |
extern void AddLoopVariable(struct for_table_t *ft,struct for_var_t *var); |
96 |
/**< |
97 |
* <!-- void AddLoopVariable(ft,var) --> |
98 |
* <!-- struct for_table_t *ft; --> |
99 |
* <!-- struct for_var_t *var; --> |
100 |
* Add another loop variable to the for table. Adding a loop variable to |
101 |
* the for table is like activating the FOR loop variable |
102 |
*/ |
103 |
|
104 |
extern struct for_var_t *LoopIndex(CONST struct for_table_t *ft, |
105 |
unsigned long num); |
106 |
/**< |
107 |
* <!-- struct for_var_t *LoopIndex(ft,num) --> |
108 |
* <!-- const struct for_table_t *ft; --> |
109 |
* <!-- unsigned long num; --> |
110 |
* Returns the num'th loop index. Loop indices are numbered in the |
111 |
* order they are added to the list. The first being one and the last |
112 |
* being the number given by ActiveForLoops(ft). |
113 |
*/ |
114 |
|
115 |
extern struct for_var_t *FindForVar(CONST struct for_table_t *ft, |
116 |
symchar *name); |
117 |
/**< |
118 |
* <!-- struct for_var_t *FindForVar(ft,name) --> |
119 |
* <!-- CONST struct for_table_t *ft; --> |
120 |
* <!-- symchar *name; --> |
121 |
* Searches for a FOR index variable which matches name. If it finds a |
122 |
* match it returns the for_var_t; otherwise, it returns NULL. |
123 |
*/ |
124 |
|
125 |
extern void RemoveForVariable(struct for_table_t *ft); |
126 |
/**< |
127 |
* <!-- void RemoveForVariable(ft) --> |
128 |
* <!-- struct for_table_t *ft; --> |
129 |
* This removes the most recently added FOR index variable. The |
130 |
* for_var_t is automatically deallocated. |
131 |
*/ |
132 |
|
133 |
/* |
134 |
* Routines to create, query, modify and destroy for_var_t's. |
135 |
*/ |
136 |
|
137 |
extern struct for_var_t *CreateForVar(symchar *name); |
138 |
/**< |
139 |
* <!-- struct for_var_t *CreateForVar(name) --> |
140 |
* <!-- const char *name; --> |
141 |
* Create a for_var_t with the name given. This for_var_t starts out being |
142 |
* f_untyped. You can use the routines below to set type and values. |
143 |
* Never free a for_var_t except by using DestroyForVar below. |
144 |
*/ |
145 |
|
146 |
extern void SetForVarType(struct for_var_t *ft, enum for_kind t); |
147 |
/**< |
148 |
* <!-- void SetForVarType(fv,t) --> |
149 |
* <!-- struct for_var_t *fv; --> |
150 |
* <!-- enum for_kind t; --> |
151 |
* Set the type to t. fv must be untyped. |
152 |
*/ |
153 |
|
154 |
extern void SetForInteger(struct for_var_t *fv, long ivalue); |
155 |
/**< |
156 |
* <!-- void SetForInteger(fv,ivalue) --> |
157 |
* <!-- struct for_var_t *fv; --> |
158 |
* <!-- long ivalue; --> |
159 |
* Set an integer for variable's value to ivalue. |
160 |
*/ |
161 |
|
162 |
extern void SetForSymbol(struct for_var_t *fv, symchar *sym_ptr); |
163 |
/**< |
164 |
* <!-- void SetForSymbol(fv,sym_ptr) --> |
165 |
* <!-- struct for_var_t *fv; --> |
166 |
* <!-- const char *sym_ptr; --> |
167 |
* Set a symbol for variable's value to sym_ptr. |
168 |
*/ |
169 |
|
170 |
extern void SetForSet(struct for_var_t *fv, struct set_t *sptr); |
171 |
/**< |
172 |
* <!-- void SetForSet(fv,sptr) --> |
173 |
* <!-- struct for_var_t *fv; --> |
174 |
* <!-- struct set_t *sptr; --> |
175 |
* Set a set for variable's value to sptr. |
176 |
*/ |
177 |
|
178 |
extern enum for_kind GetForKind(CONST struct for_var_t *fv); |
179 |
/**< |
180 |
* <!-- for_kind GetForKind(fv) --> |
181 |
* <!-- const struct for_var_t *fv; --> |
182 |
* Return the type of the for variable. |
183 |
*/ |
184 |
|
185 |
extern symchar *GetForName(CONST struct for_var_t *fv); |
186 |
/**< |
187 |
* <!-- symchar *GetForName(fv) --> |
188 |
* <!-- const struct for_var_t *fv; --> |
189 |
* Return the name of the for variable |
190 |
*/ |
191 |
|
192 |
extern long GetForInteger(CONST struct for_var_t *fv); |
193 |
/**< |
194 |
* <!-- long GetForInteger(fv) --> |
195 |
* <!-- const struct for_var_t *fv; --> |
196 |
* Return the value of an integer for variable. |
197 |
*/ |
198 |
|
199 |
extern symchar *GetForSymbol(CONST struct for_var_t *fv); |
200 |
/**< |
201 |
* <!-- symchar *GetForSymbol(fv) --> |
202 |
* <!-- const struct for_var_t *fv; --> |
203 |
* Return the value of a symbol for variable. |
204 |
*/ |
205 |
|
206 |
extern CONST struct set_t *GetForSet(CONST struct for_var_t *fv); |
207 |
/**< |
208 |
* <!-- const struct set_t *GetForSet(fv) --> |
209 |
* <!-- const struct for_var_t *fv; --> |
210 |
* Return the value of a set for variable. |
211 |
*/ |
212 |
|
213 |
extern void DestroyForVar(struct for_var_t *fv); |
214 |
/**< |
215 |
* <!-- void DestroyForVar(fv) --> |
216 |
* <!-- struct for_var_t *fv; --> |
217 |
* Deallocate the memory of this for variable. In the case of a set |
218 |
* for variable, this will also deallocate the set. |
219 |
*/ |
220 |
|
221 |
extern int ClearForVarRecycle(void); |
222 |
/**< |
223 |
* <!-- int ClearForVarRecycle(); --> |
224 |
* Deallocates the recycle list of forvar_t. returns the list length, |
225 |
* if anyone cares. |
226 |
* This function may be safely called at any time. |
227 |
* There is no recycle initialization function. |
228 |
*/ |
229 |
|
230 |
/* @} */ |
231 |
|
232 |
#endif /* ASC_FORVARS_H */ |
233 |
|