xref: /openbsd/gnu/usr.bin/gcc/gcc/f/stt.c (revision c87b03e5)
1*c87b03e5Sespie /* stt.c -- Implementation File (module.c template V1.0)
2*c87b03e5Sespie    Copyright (C) 1995, 1997 Free Software Foundation, Inc.
3*c87b03e5Sespie    Contributed by James Craig Burley.
4*c87b03e5Sespie 
5*c87b03e5Sespie This file is part of GNU Fortran.
6*c87b03e5Sespie 
7*c87b03e5Sespie GNU Fortran is free software; you can redistribute it and/or modify
8*c87b03e5Sespie it under the terms of the GNU General Public License as published by
9*c87b03e5Sespie the Free Software Foundation; either version 2, or (at your option)
10*c87b03e5Sespie any later version.
11*c87b03e5Sespie 
12*c87b03e5Sespie GNU Fortran is distributed in the hope that it will be useful,
13*c87b03e5Sespie but WITHOUT ANY WARRANTY; without even the implied warranty of
14*c87b03e5Sespie MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15*c87b03e5Sespie GNU General Public License for more details.
16*c87b03e5Sespie 
17*c87b03e5Sespie You should have received a copy of the GNU General Public License
18*c87b03e5Sespie along with GNU Fortran; see the file COPYING.  If not, write to
19*c87b03e5Sespie the Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
20*c87b03e5Sespie 02111-1307, USA.
21*c87b03e5Sespie 
22*c87b03e5Sespie    Related Modules:
23*c87b03e5Sespie       None
24*c87b03e5Sespie 
25*c87b03e5Sespie    Description:
26*c87b03e5Sespie       Manages lists of tokens and related info for parsing.
27*c87b03e5Sespie 
28*c87b03e5Sespie    Modifications:
29*c87b03e5Sespie */
30*c87b03e5Sespie 
31*c87b03e5Sespie /* Include files. */
32*c87b03e5Sespie 
33*c87b03e5Sespie #include "proj.h"
34*c87b03e5Sespie #include "stt.h"
35*c87b03e5Sespie #include "bld.h"
36*c87b03e5Sespie #include "expr.h"
37*c87b03e5Sespie #include "info.h"
38*c87b03e5Sespie #include "lex.h"
39*c87b03e5Sespie #include "malloc.h"
40*c87b03e5Sespie #include "sta.h"
41*c87b03e5Sespie #include "stp.h"
42*c87b03e5Sespie 
43*c87b03e5Sespie /* Externals defined here. */
44*c87b03e5Sespie 
45*c87b03e5Sespie 
46*c87b03e5Sespie /* Simple definitions and enumerations. */
47*c87b03e5Sespie 
48*c87b03e5Sespie 
49*c87b03e5Sespie /* Internal typedefs. */
50*c87b03e5Sespie 
51*c87b03e5Sespie 
52*c87b03e5Sespie /* Private include files. */
53*c87b03e5Sespie 
54*c87b03e5Sespie 
55*c87b03e5Sespie /* Internal structure definitions. */
56*c87b03e5Sespie 
57*c87b03e5Sespie 
58*c87b03e5Sespie /* Static objects accessed by functions in this module. */
59*c87b03e5Sespie 
60*c87b03e5Sespie 
61*c87b03e5Sespie /* Static functions (internal). */
62*c87b03e5Sespie 
63*c87b03e5Sespie 
64*c87b03e5Sespie /* Internal macros. */
65*c87b03e5Sespie 
66*c87b03e5Sespie 
67*c87b03e5Sespie /* ffestt_caselist_append -- Append case to list of cases
68*c87b03e5Sespie 
69*c87b03e5Sespie    ffesttCaseList list;
70*c87b03e5Sespie    ffelexToken t;
71*c87b03e5Sespie    ffestt_caselist_append(list,range,case1,case2,t);
72*c87b03e5Sespie 
73*c87b03e5Sespie    list must have already been created by ffestt_caselist_create.  The
74*c87b03e5Sespie    list is allocated out of the scratch pool.  The token is consumed.  */
75*c87b03e5Sespie 
76*c87b03e5Sespie void
ffestt_caselist_append(ffesttCaseList list,bool range,ffebld case1,ffebld case2,ffelexToken t)77*c87b03e5Sespie ffestt_caselist_append (ffesttCaseList list, bool range, ffebld case1,
78*c87b03e5Sespie 			ffebld case2, ffelexToken t)
79*c87b03e5Sespie {
80*c87b03e5Sespie   ffesttCaseList new;
81*c87b03e5Sespie 
82*c87b03e5Sespie   new = (ffesttCaseList) malloc_new_kp (ffesta_scratch_pool,
83*c87b03e5Sespie 					"FFEST case list", sizeof (*new));
84*c87b03e5Sespie   new->next = list->previous->next;
85*c87b03e5Sespie   new->previous = list->previous;
86*c87b03e5Sespie   new->next->previous = new;
87*c87b03e5Sespie   new->previous->next = new;
88*c87b03e5Sespie   new->expr1 = case1;
89*c87b03e5Sespie   new->expr2 = case2;
90*c87b03e5Sespie   new->range = range;
91*c87b03e5Sespie   new->t = t;
92*c87b03e5Sespie }
93*c87b03e5Sespie 
94*c87b03e5Sespie /* ffestt_caselist_create -- Create new list of cases
95*c87b03e5Sespie 
96*c87b03e5Sespie    ffesttCaseList list;
97*c87b03e5Sespie    list = ffestt_caselist_create();
98*c87b03e5Sespie 
99*c87b03e5Sespie    The list is allocated out of the scratch pool.  */
100*c87b03e5Sespie 
101*c87b03e5Sespie ffesttCaseList
ffestt_caselist_create()102*c87b03e5Sespie ffestt_caselist_create ()
103*c87b03e5Sespie {
104*c87b03e5Sespie   ffesttCaseList new;
105*c87b03e5Sespie 
106*c87b03e5Sespie   new = (ffesttCaseList) malloc_new_kp (ffesta_scratch_pool,
107*c87b03e5Sespie 					"FFEST case list root",
108*c87b03e5Sespie 					sizeof (*new));
109*c87b03e5Sespie   new->next = new->previous = new;
110*c87b03e5Sespie   new->t = NULL;
111*c87b03e5Sespie   new->expr1 = NULL;
112*c87b03e5Sespie   new->expr2 = NULL;
113*c87b03e5Sespie   new->range = FALSE;
114*c87b03e5Sespie   return new;
115*c87b03e5Sespie }
116*c87b03e5Sespie 
117*c87b03e5Sespie /* ffestt_caselist_kill -- Kill list of cases
118*c87b03e5Sespie 
119*c87b03e5Sespie    ffesttCaseList list;
120*c87b03e5Sespie    ffestt_caselist_kill(list);
121*c87b03e5Sespie 
122*c87b03e5Sespie    The tokens on the list are killed.
123*c87b03e5Sespie 
124*c87b03e5Sespie    02-Mar-90  JCB  1.1
125*c87b03e5Sespie       Don't kill the list itself or change it, since it will be trashed when
126*c87b03e5Sespie       ffesta_scratch_pool is killed anyway, so kill only the lex tokens.  */
127*c87b03e5Sespie 
128*c87b03e5Sespie void
ffestt_caselist_kill(ffesttCaseList list)129*c87b03e5Sespie ffestt_caselist_kill (ffesttCaseList list)
130*c87b03e5Sespie {
131*c87b03e5Sespie   ffesttCaseList next;
132*c87b03e5Sespie 
133*c87b03e5Sespie   for (next = list->next; next != list; next = next->next)
134*c87b03e5Sespie     {
135*c87b03e5Sespie       ffelex_token_kill (next->t);
136*c87b03e5Sespie     }
137*c87b03e5Sespie }
138*c87b03e5Sespie 
139*c87b03e5Sespie /* ffestt_dimlist_append -- Append dim to list of dims
140*c87b03e5Sespie 
141*c87b03e5Sespie    ffesttDimList list;
142*c87b03e5Sespie    ffelexToken t;
143*c87b03e5Sespie    ffestt_dimlist_append(list,lower,upper,t);
144*c87b03e5Sespie 
145*c87b03e5Sespie    list must have already been created by ffestt_dimlist_create.  The
146*c87b03e5Sespie    list is allocated out of the scratch pool.  The token is consumed.  */
147*c87b03e5Sespie 
148*c87b03e5Sespie void
ffestt_dimlist_append(ffesttDimList list,ffebld lower,ffebld upper,ffelexToken t)149*c87b03e5Sespie ffestt_dimlist_append (ffesttDimList list, ffebld lower, ffebld upper,
150*c87b03e5Sespie 		       ffelexToken t)
151*c87b03e5Sespie {
152*c87b03e5Sespie   ffesttDimList new;
153*c87b03e5Sespie 
154*c87b03e5Sespie   new = (ffesttDimList) malloc_new_kp (ffesta_scratch_pool,
155*c87b03e5Sespie 				       "FFEST dim list", sizeof (*new));
156*c87b03e5Sespie   new->next = list->previous->next;
157*c87b03e5Sespie   new->previous = list->previous;
158*c87b03e5Sespie   new->next->previous = new;
159*c87b03e5Sespie   new->previous->next = new;
160*c87b03e5Sespie   new->lower = lower;
161*c87b03e5Sespie   new->upper = upper;
162*c87b03e5Sespie   new->t = t;
163*c87b03e5Sespie }
164*c87b03e5Sespie 
165*c87b03e5Sespie /* Convert list of dims into ffebld format.
166*c87b03e5Sespie 
167*c87b03e5Sespie    ffesttDimList list;
168*c87b03e5Sespie    ffeinfoRank rank;
169*c87b03e5Sespie    ffebld array_size;
170*c87b03e5Sespie    ffebld extents;
171*c87b03e5Sespie    ffestt_dimlist_as_expr (list, &rank, &array_size, &extents);
172*c87b03e5Sespie 
173*c87b03e5Sespie    The dims in the list are converted to a list of ITEMs; the rank of the
174*c87b03e5Sespie    array, an expression representing the array size, a list of extent
175*c87b03e5Sespie    expressions, and the list of ITEMs are returned.
176*c87b03e5Sespie 
177*c87b03e5Sespie    If is_ugly_assumed, treat a final dimension with no lower bound
178*c87b03e5Sespie    and an upper bound of 1 as a * bound.  */
179*c87b03e5Sespie 
180*c87b03e5Sespie ffebld
ffestt_dimlist_as_expr(ffesttDimList list,ffeinfoRank * rank,ffebld * array_size,ffebld * extents,bool is_ugly_assumed)181*c87b03e5Sespie ffestt_dimlist_as_expr (ffesttDimList list, ffeinfoRank *rank,
182*c87b03e5Sespie 			ffebld *array_size, ffebld *extents,
183*c87b03e5Sespie 			bool is_ugly_assumed)
184*c87b03e5Sespie {
185*c87b03e5Sespie   ffesttDimList next;
186*c87b03e5Sespie   ffebld expr;
187*c87b03e5Sespie   ffebld as;
188*c87b03e5Sespie   ffebld ex;			/* List of extents. */
189*c87b03e5Sespie   ffebld ext;			/* Extent of a given dimension. */
190*c87b03e5Sespie   ffebldListBottom bottom;
191*c87b03e5Sespie   ffeinfoRank r;
192*c87b03e5Sespie   ffeinfoKindtype nkt;
193*c87b03e5Sespie   ffetargetIntegerDefault low;
194*c87b03e5Sespie   ffetargetIntegerDefault high;
195*c87b03e5Sespie   bool zero = FALSE;		/* Zero-size array. */
196*c87b03e5Sespie   bool any = FALSE;
197*c87b03e5Sespie   bool star = FALSE;		/* Adjustable array. */
198*c87b03e5Sespie 
199*c87b03e5Sespie   assert (list != NULL);
200*c87b03e5Sespie 
201*c87b03e5Sespie   r = 0;
202*c87b03e5Sespie   ffebld_init_list (&expr, &bottom);
203*c87b03e5Sespie   for (next = list->next; next != list; next = next->next)
204*c87b03e5Sespie     {
205*c87b03e5Sespie       ++r;
206*c87b03e5Sespie       if (((next->lower == NULL)
207*c87b03e5Sespie 	   || (ffebld_op (next->lower) == FFEBLD_opCONTER))
208*c87b03e5Sespie 	  && (ffebld_op (next->upper) == FFEBLD_opCONTER))
209*c87b03e5Sespie 	{
210*c87b03e5Sespie 	  if (next->lower == NULL)
211*c87b03e5Sespie 	    low = 1;
212*c87b03e5Sespie 	  else
213*c87b03e5Sespie 	    low = ffebld_constant_integerdefault (ffebld_conter (next->lower));
214*c87b03e5Sespie 	  high = ffebld_constant_integerdefault (ffebld_conter (next->upper));
215*c87b03e5Sespie 	  if (low
216*c87b03e5Sespie 	      > high)
217*c87b03e5Sespie 	    zero = TRUE;
218*c87b03e5Sespie 	  if ((next->next == list)
219*c87b03e5Sespie 	      && is_ugly_assumed
220*c87b03e5Sespie 	      && (next->lower == NULL)
221*c87b03e5Sespie 	      && (high == 1)
222*c87b03e5Sespie 	      && (ffebld_conter_orig (next->upper) == NULL))
223*c87b03e5Sespie 	    {
224*c87b03e5Sespie 	      star = TRUE;
225*c87b03e5Sespie 	      ffebld_append_item (&bottom,
226*c87b03e5Sespie 				  ffebld_new_bounds (NULL, ffebld_new_star ()));
227*c87b03e5Sespie 	      continue;
228*c87b03e5Sespie 	    }
229*c87b03e5Sespie 	}
230*c87b03e5Sespie       else if (((next->lower != NULL)
231*c87b03e5Sespie 		&& (ffebld_op (next->lower) == FFEBLD_opANY))
232*c87b03e5Sespie 	       || (ffebld_op (next->upper) == FFEBLD_opANY))
233*c87b03e5Sespie 	any = TRUE;
234*c87b03e5Sespie       else if (ffebld_op (next->upper) == FFEBLD_opSTAR)
235*c87b03e5Sespie 	star = TRUE;
236*c87b03e5Sespie       ffebld_append_item (&bottom,
237*c87b03e5Sespie 			  ffebld_new_bounds (next->lower, next->upper));
238*c87b03e5Sespie     }
239*c87b03e5Sespie   ffebld_end_list (&bottom);
240*c87b03e5Sespie 
241*c87b03e5Sespie   if (zero)
242*c87b03e5Sespie     {
243*c87b03e5Sespie       as = ffebld_new_conter (ffebld_constant_new_integerdefault_val (0));
244*c87b03e5Sespie       ffebld_set_info (as, ffeinfo_new
245*c87b03e5Sespie 		       (FFEINFO_basictypeINTEGER,
246*c87b03e5Sespie 			FFEINFO_kindtypeINTEGERDEFAULT,
247*c87b03e5Sespie 			0,
248*c87b03e5Sespie 			FFEINFO_kindENTITY,
249*c87b03e5Sespie 			FFEINFO_whereCONSTANT,
250*c87b03e5Sespie 			FFETARGET_charactersizeNONE));
251*c87b03e5Sespie       ex = NULL;
252*c87b03e5Sespie     }
253*c87b03e5Sespie   else if (any)
254*c87b03e5Sespie     {
255*c87b03e5Sespie       as = ffebld_new_any ();
256*c87b03e5Sespie       ffebld_set_info (as, ffeinfo_new_any ());
257*c87b03e5Sespie       ex = ffebld_copy (as);
258*c87b03e5Sespie     }
259*c87b03e5Sespie   else if (star)
260*c87b03e5Sespie     {
261*c87b03e5Sespie       as = ffebld_new_star ();
262*c87b03e5Sespie       ex = ffebld_new_star ();	/* ~~Should really be list as below. */
263*c87b03e5Sespie     }
264*c87b03e5Sespie   else
265*c87b03e5Sespie     {
266*c87b03e5Sespie       as = NULL;
267*c87b03e5Sespie       ffebld_init_list (&ex, &bottom);
268*c87b03e5Sespie       for (next = list->next; next != list; next = next->next)
269*c87b03e5Sespie 	{
270*c87b03e5Sespie 	  if ((next->lower == NULL)
271*c87b03e5Sespie 	      || ((ffebld_op (next->lower) == FFEBLD_opCONTER)
272*c87b03e5Sespie 		  && (ffebld_constant_integerdefault (ffebld_conter
273*c87b03e5Sespie 						      (next->lower)) == 1)))
274*c87b03e5Sespie 	    ext = ffebld_copy (next->upper);
275*c87b03e5Sespie 	  else
276*c87b03e5Sespie 	    {
277*c87b03e5Sespie 	      ext = ffebld_new_subtract (next->upper, next->lower);
278*c87b03e5Sespie 	      nkt
279*c87b03e5Sespie 		= ffeinfo_kindtype_max (FFEINFO_basictypeINTEGER,
280*c87b03e5Sespie 					ffeinfo_kindtype (ffebld_info
281*c87b03e5Sespie 							  (next->lower)),
282*c87b03e5Sespie 					ffeinfo_kindtype (ffebld_info
283*c87b03e5Sespie 							  (next->upper)));
284*c87b03e5Sespie 	      ffebld_set_info (ext,
285*c87b03e5Sespie 			       ffeinfo_new (FFEINFO_basictypeINTEGER,
286*c87b03e5Sespie 					    nkt,
287*c87b03e5Sespie 					    0,
288*c87b03e5Sespie 					    FFEINFO_kindENTITY,
289*c87b03e5Sespie 					    ((ffebld_op (ffebld_left (ext))
290*c87b03e5Sespie 					      == FFEBLD_opCONTER)
291*c87b03e5Sespie 					     && (ffebld_op (ffebld_right
292*c87b03e5Sespie 							    (ext))
293*c87b03e5Sespie 						 == FFEBLD_opCONTER))
294*c87b03e5Sespie 					    ? FFEINFO_whereCONSTANT
295*c87b03e5Sespie 					    : FFEINFO_whereFLEETING,
296*c87b03e5Sespie 					    FFETARGET_charactersizeNONE));
297*c87b03e5Sespie 	      ffebld_set_left (ext,
298*c87b03e5Sespie 			       ffeexpr_convert_expr (ffebld_left (ext),
299*c87b03e5Sespie 						     next->t, ext, next->t,
300*c87b03e5Sespie 						     FFEEXPR_contextLET));
301*c87b03e5Sespie 	      ffebld_set_right (ext,
302*c87b03e5Sespie 				ffeexpr_convert_expr (ffebld_right (ext),
303*c87b03e5Sespie 						      next->t, ext,
304*c87b03e5Sespie 						      next->t,
305*c87b03e5Sespie 						      FFEEXPR_contextLET));
306*c87b03e5Sespie 	      ext = ffeexpr_collapse_subtract (ext, next->t);
307*c87b03e5Sespie 
308*c87b03e5Sespie 	      nkt
309*c87b03e5Sespie 		= ffeinfo_kindtype_max (FFEINFO_basictypeINTEGER,
310*c87b03e5Sespie 					ffeinfo_kindtype (ffebld_info (ext)),
311*c87b03e5Sespie 					FFEINFO_kindtypeINTEGERDEFAULT);
312*c87b03e5Sespie 	      ext
313*c87b03e5Sespie 		= ffebld_new_add (ext,
314*c87b03e5Sespie 				  ffebld_new_conter
315*c87b03e5Sespie 				  (ffebld_constant_new_integerdefault_val
316*c87b03e5Sespie 				   (1)));
317*c87b03e5Sespie 	      ffebld_set_info (ffebld_right (ext), ffeinfo_new
318*c87b03e5Sespie 			       (FFEINFO_basictypeINTEGER,
319*c87b03e5Sespie 				FFEINFO_kindtypeINTEGERDEFAULT,
320*c87b03e5Sespie 				0,
321*c87b03e5Sespie 				FFEINFO_kindENTITY,
322*c87b03e5Sespie 				FFEINFO_whereCONSTANT,
323*c87b03e5Sespie 				FFETARGET_charactersizeNONE));
324*c87b03e5Sespie 	      ffebld_set_info (ext,
325*c87b03e5Sespie 			       ffeinfo_new (FFEINFO_basictypeINTEGER,
326*c87b03e5Sespie 					    nkt, 0, FFEINFO_kindENTITY,
327*c87b03e5Sespie 					    (ffebld_op (ffebld_left (ext))
328*c87b03e5Sespie 					     == FFEBLD_opCONTER)
329*c87b03e5Sespie 					    ? FFEINFO_whereCONSTANT
330*c87b03e5Sespie 					    : FFEINFO_whereFLEETING,
331*c87b03e5Sespie 					    FFETARGET_charactersizeNONE));
332*c87b03e5Sespie 	      ffebld_set_left (ext,
333*c87b03e5Sespie 			       ffeexpr_convert_expr (ffebld_left (ext),
334*c87b03e5Sespie 						     next->t, ext,
335*c87b03e5Sespie 						     next->t,
336*c87b03e5Sespie 						     FFEEXPR_contextLET));
337*c87b03e5Sespie 	      ffebld_set_right (ext,
338*c87b03e5Sespie 				ffeexpr_convert_expr (ffebld_right (ext),
339*c87b03e5Sespie 						      next->t, ext,
340*c87b03e5Sespie 						      next->t,
341*c87b03e5Sespie 						      FFEEXPR_contextLET));
342*c87b03e5Sespie 	      ext = ffeexpr_collapse_add (ext, next->t);
343*c87b03e5Sespie 	    }
344*c87b03e5Sespie 	  ffebld_append_item (&bottom, ext);
345*c87b03e5Sespie 	  if (as == NULL)
346*c87b03e5Sespie 	    as = ext;
347*c87b03e5Sespie 	  else
348*c87b03e5Sespie 	    {
349*c87b03e5Sespie 	      nkt
350*c87b03e5Sespie 		= ffeinfo_kindtype_max (FFEINFO_basictypeINTEGER,
351*c87b03e5Sespie 					ffeinfo_kindtype (ffebld_info (as)),
352*c87b03e5Sespie 				      ffeinfo_kindtype (ffebld_info (ext)));
353*c87b03e5Sespie 	      as = ffebld_new_multiply (as, ext);
354*c87b03e5Sespie 	      ffebld_set_info (as,
355*c87b03e5Sespie 			       ffeinfo_new (FFEINFO_basictypeINTEGER,
356*c87b03e5Sespie 					    nkt, 0, FFEINFO_kindENTITY,
357*c87b03e5Sespie 					    ((ffebld_op (ffebld_left (as))
358*c87b03e5Sespie 					      == FFEBLD_opCONTER)
359*c87b03e5Sespie 					     && (ffebld_op (ffebld_right
360*c87b03e5Sespie 							    (as))
361*c87b03e5Sespie 						 == FFEBLD_opCONTER))
362*c87b03e5Sespie 					    ? FFEINFO_whereCONSTANT
363*c87b03e5Sespie 					    : FFEINFO_whereFLEETING,
364*c87b03e5Sespie 					    FFETARGET_charactersizeNONE));
365*c87b03e5Sespie 	      ffebld_set_left (as,
366*c87b03e5Sespie 			       ffeexpr_convert_expr (ffebld_left (as),
367*c87b03e5Sespie 						     next->t, as, next->t,
368*c87b03e5Sespie 						     FFEEXPR_contextLET));
369*c87b03e5Sespie 	      ffebld_set_right (as,
370*c87b03e5Sespie 				ffeexpr_convert_expr (ffebld_right (as),
371*c87b03e5Sespie 						      next->t, as,
372*c87b03e5Sespie 						      next->t,
373*c87b03e5Sespie 						      FFEEXPR_contextLET));
374*c87b03e5Sespie 	      as = ffeexpr_collapse_multiply (as, next->t);
375*c87b03e5Sespie 	    }
376*c87b03e5Sespie 	}
377*c87b03e5Sespie       ffebld_end_list (&bottom);
378*c87b03e5Sespie       as = ffeexpr_convert (as, list->next->t, NULL,
379*c87b03e5Sespie 			    FFEINFO_basictypeINTEGER,
380*c87b03e5Sespie 			    FFEINFO_kindtypeINTEGERDEFAULT, 0,
381*c87b03e5Sespie 			    FFETARGET_charactersizeNONE,
382*c87b03e5Sespie 			    FFEEXPR_contextLET);
383*c87b03e5Sespie     }
384*c87b03e5Sespie 
385*c87b03e5Sespie   *rank = r;
386*c87b03e5Sespie   *array_size = as;
387*c87b03e5Sespie   *extents = ex;
388*c87b03e5Sespie   return expr;
389*c87b03e5Sespie }
390*c87b03e5Sespie 
391*c87b03e5Sespie /* ffestt_dimlist_create -- Create new list of dims
392*c87b03e5Sespie 
393*c87b03e5Sespie    ffesttDimList list;
394*c87b03e5Sespie    list = ffestt_dimlist_create();
395*c87b03e5Sespie 
396*c87b03e5Sespie    The list is allocated out of the scratch pool.  */
397*c87b03e5Sespie 
398*c87b03e5Sespie ffesttDimList
ffestt_dimlist_create()399*c87b03e5Sespie ffestt_dimlist_create ()
400*c87b03e5Sespie {
401*c87b03e5Sespie   ffesttDimList new;
402*c87b03e5Sespie 
403*c87b03e5Sespie   new = (ffesttDimList) malloc_new_kp (ffesta_scratch_pool,
404*c87b03e5Sespie 				       "FFEST dim list root", sizeof (*new));
405*c87b03e5Sespie   new->next = new->previous = new;
406*c87b03e5Sespie   new->t = NULL;
407*c87b03e5Sespie   new->lower = NULL;
408*c87b03e5Sespie   new->upper = NULL;
409*c87b03e5Sespie   return new;
410*c87b03e5Sespie }
411*c87b03e5Sespie 
412*c87b03e5Sespie /* ffestt_dimlist_kill -- Kill list of dims
413*c87b03e5Sespie 
414*c87b03e5Sespie    ffesttDimList list;
415*c87b03e5Sespie    ffestt_dimlist_kill(list);
416*c87b03e5Sespie 
417*c87b03e5Sespie    The tokens on the list are killed.  */
418*c87b03e5Sespie 
419*c87b03e5Sespie void
ffestt_dimlist_kill(ffesttDimList list)420*c87b03e5Sespie ffestt_dimlist_kill (ffesttDimList list)
421*c87b03e5Sespie {
422*c87b03e5Sespie   ffesttDimList next;
423*c87b03e5Sespie 
424*c87b03e5Sespie   for (next = list->next; next != list; next = next->next)
425*c87b03e5Sespie     {
426*c87b03e5Sespie       ffelex_token_kill (next->t);
427*c87b03e5Sespie     }
428*c87b03e5Sespie }
429*c87b03e5Sespie 
430*c87b03e5Sespie /* Determine type of list of dimensions.
431*c87b03e5Sespie 
432*c87b03e5Sespie    Return KNOWN for all-constant bounds, ADJUSTABLE for constant
433*c87b03e5Sespie    and variable but no * bounds, ASSUMED for constant and * but
434*c87b03e5Sespie    not variable bounds, ADJUSTABLEASSUMED for constant and variable
435*c87b03e5Sespie    and * bounds.
436*c87b03e5Sespie 
437*c87b03e5Sespie    If is_ugly_assumed, treat a final dimension with no lower bound
438*c87b03e5Sespie    and an upper bound of 1 as a * bound.  */
439*c87b03e5Sespie 
440*c87b03e5Sespie ffestpDimtype
ffestt_dimlist_type(ffesttDimList list,bool is_ugly_assumed)441*c87b03e5Sespie ffestt_dimlist_type (ffesttDimList list, bool is_ugly_assumed)
442*c87b03e5Sespie {
443*c87b03e5Sespie   ffesttDimList next;
444*c87b03e5Sespie   ffestpDimtype type;
445*c87b03e5Sespie 
446*c87b03e5Sespie   if (list == NULL)
447*c87b03e5Sespie     return FFESTP_dimtypeNONE;
448*c87b03e5Sespie 
449*c87b03e5Sespie   type = FFESTP_dimtypeKNOWN;
450*c87b03e5Sespie   for (next = list->next; next != list; next = next->next)
451*c87b03e5Sespie     {
452*c87b03e5Sespie       bool ugly_assumed = FALSE;
453*c87b03e5Sespie 
454*c87b03e5Sespie       if ((next->next == list)
455*c87b03e5Sespie 	  && is_ugly_assumed
456*c87b03e5Sespie 	  && (next->lower == NULL)
457*c87b03e5Sespie 	  && (next->upper != NULL)
458*c87b03e5Sespie 	  && (ffebld_op (next->upper) == FFEBLD_opCONTER)
459*c87b03e5Sespie 	  && (ffebld_constant_integerdefault (ffebld_conter (next->upper))
460*c87b03e5Sespie 	      == 1)
461*c87b03e5Sespie 	  && (ffebld_conter_orig (next->upper) == NULL))
462*c87b03e5Sespie 	ugly_assumed = TRUE;
463*c87b03e5Sespie 
464*c87b03e5Sespie       if (next->lower != NULL)
465*c87b03e5Sespie 	{
466*c87b03e5Sespie 	  if (ffebld_op (next->lower) != FFEBLD_opCONTER)
467*c87b03e5Sespie 	    {
468*c87b03e5Sespie 	      if (type == FFESTP_dimtypeASSUMED)
469*c87b03e5Sespie 		type = FFESTP_dimtypeADJUSTABLEASSUMED;
470*c87b03e5Sespie 	      else
471*c87b03e5Sespie 		type = FFESTP_dimtypeADJUSTABLE;
472*c87b03e5Sespie 	    }
473*c87b03e5Sespie 	}
474*c87b03e5Sespie       if (next->upper != NULL)
475*c87b03e5Sespie 	{
476*c87b03e5Sespie 	  if (ugly_assumed
477*c87b03e5Sespie 	      || (ffebld_op (next->upper) == FFEBLD_opSTAR))
478*c87b03e5Sespie 	    {
479*c87b03e5Sespie 	      if (type == FFESTP_dimtypeADJUSTABLE)
480*c87b03e5Sespie 		type = FFESTP_dimtypeADJUSTABLEASSUMED;
481*c87b03e5Sespie 	      else
482*c87b03e5Sespie 		type = FFESTP_dimtypeASSUMED;
483*c87b03e5Sespie 	    }
484*c87b03e5Sespie 	  else if (ffebld_op (next->upper) != FFEBLD_opCONTER)
485*c87b03e5Sespie 	    type = FFESTP_dimtypeADJUSTABLE;
486*c87b03e5Sespie 	}
487*c87b03e5Sespie     }
488*c87b03e5Sespie 
489*c87b03e5Sespie   return type;
490*c87b03e5Sespie }
491*c87b03e5Sespie 
492*c87b03e5Sespie /* ffestt_exprlist_append -- Append expr to list of exprs
493*c87b03e5Sespie 
494*c87b03e5Sespie    ffesttExprList list;
495*c87b03e5Sespie    ffelexToken t;
496*c87b03e5Sespie    ffestt_exprlist_append(list,expr,t);
497*c87b03e5Sespie 
498*c87b03e5Sespie    list must have already been created by ffestt_exprlist_create.  The
499*c87b03e5Sespie    list is allocated out of the scratch pool.  The token is consumed.  */
500*c87b03e5Sespie 
501*c87b03e5Sespie void
ffestt_exprlist_append(ffesttExprList list,ffebld expr,ffelexToken t)502*c87b03e5Sespie ffestt_exprlist_append (ffesttExprList list, ffebld expr, ffelexToken t)
503*c87b03e5Sespie {
504*c87b03e5Sespie   ffesttExprList new;
505*c87b03e5Sespie 
506*c87b03e5Sespie   new = (ffesttExprList) malloc_new_kp (ffesta_scratch_pool,
507*c87b03e5Sespie 					"FFEST expr list", sizeof (*new));
508*c87b03e5Sespie   new->next = list->previous->next;
509*c87b03e5Sespie   new->previous = list->previous;
510*c87b03e5Sespie   new->next->previous = new;
511*c87b03e5Sespie   new->previous->next = new;
512*c87b03e5Sespie   new->expr = expr;
513*c87b03e5Sespie   new->t = t;
514*c87b03e5Sespie }
515*c87b03e5Sespie 
516*c87b03e5Sespie /* ffestt_exprlist_create -- Create new list of exprs
517*c87b03e5Sespie 
518*c87b03e5Sespie    ffesttExprList list;
519*c87b03e5Sespie    list = ffestt_exprlist_create();
520*c87b03e5Sespie 
521*c87b03e5Sespie    The list is allocated out of the scratch pool.  */
522*c87b03e5Sespie 
523*c87b03e5Sespie ffesttExprList
ffestt_exprlist_create()524*c87b03e5Sespie ffestt_exprlist_create ()
525*c87b03e5Sespie {
526*c87b03e5Sespie   ffesttExprList new;
527*c87b03e5Sespie 
528*c87b03e5Sespie   new = (ffesttExprList) malloc_new_kp (ffesta_scratch_pool,
529*c87b03e5Sespie 				     "FFEST expr list root", sizeof (*new));
530*c87b03e5Sespie   new->next = new->previous = new;
531*c87b03e5Sespie   new->expr = NULL;
532*c87b03e5Sespie   new->t = NULL;
533*c87b03e5Sespie   return new;
534*c87b03e5Sespie }
535*c87b03e5Sespie 
536*c87b03e5Sespie /* ffestt_exprlist_drive -- Drive list of token pairs into function
537*c87b03e5Sespie 
538*c87b03e5Sespie    ffesttExprList list;
539*c87b03e5Sespie    void fn(ffebld expr,ffelexToken t);
540*c87b03e5Sespie    ffestt_exprlist_drive(list,fn);
541*c87b03e5Sespie 
542*c87b03e5Sespie    The expr/token pairs in the list are passed to the function one pair
543*c87b03e5Sespie    at a time.  */
544*c87b03e5Sespie 
545*c87b03e5Sespie void
ffestt_exprlist_drive(ffesttExprList list,void (* fn)(ffebld,ffelexToken))546*c87b03e5Sespie ffestt_exprlist_drive (ffesttExprList list, void (*fn) (ffebld, ffelexToken))
547*c87b03e5Sespie {
548*c87b03e5Sespie   ffesttExprList next;
549*c87b03e5Sespie 
550*c87b03e5Sespie   if (list == NULL)
551*c87b03e5Sespie     return;
552*c87b03e5Sespie 
553*c87b03e5Sespie   for (next = list->next; next != list; next = next->next)
554*c87b03e5Sespie     {
555*c87b03e5Sespie       (*fn) (next->expr, next->t);
556*c87b03e5Sespie     }
557*c87b03e5Sespie }
558*c87b03e5Sespie 
559*c87b03e5Sespie /* ffestt_exprlist_kill -- Kill list of exprs
560*c87b03e5Sespie 
561*c87b03e5Sespie    ffesttExprList list;
562*c87b03e5Sespie    ffestt_exprlist_kill(list);
563*c87b03e5Sespie 
564*c87b03e5Sespie    The tokens on the list are killed.
565*c87b03e5Sespie 
566*c87b03e5Sespie    02-Mar-90  JCB  1.1
567*c87b03e5Sespie       Don't kill the list itself or change it, since it will be trashed when
568*c87b03e5Sespie       ffesta_scratch_pool is killed anyway, so kill only the lex tokens.  */
569*c87b03e5Sespie 
570*c87b03e5Sespie void
ffestt_exprlist_kill(ffesttExprList list)571*c87b03e5Sespie ffestt_exprlist_kill (ffesttExprList list)
572*c87b03e5Sespie {
573*c87b03e5Sespie   ffesttExprList next;
574*c87b03e5Sespie 
575*c87b03e5Sespie   for (next = list->next; next != list; next = next->next)
576*c87b03e5Sespie     {
577*c87b03e5Sespie       ffelex_token_kill (next->t);
578*c87b03e5Sespie     }
579*c87b03e5Sespie }
580*c87b03e5Sespie 
581*c87b03e5Sespie /* ffestt_formatlist_append -- Append null format to list of formats
582*c87b03e5Sespie 
583*c87b03e5Sespie    ffesttFormatList list, new;
584*c87b03e5Sespie    new = ffestt_formatlist_append(list);
585*c87b03e5Sespie 
586*c87b03e5Sespie    list must have already been created by ffestt_formatlist_create.  The
587*c87b03e5Sespie    new item is allocated out of the scratch pool.  The caller must initialize
588*c87b03e5Sespie    it appropriately.  */
589*c87b03e5Sespie 
590*c87b03e5Sespie ffesttFormatList
ffestt_formatlist_append(ffesttFormatList list)591*c87b03e5Sespie ffestt_formatlist_append (ffesttFormatList list)
592*c87b03e5Sespie {
593*c87b03e5Sespie   ffesttFormatList new;
594*c87b03e5Sespie 
595*c87b03e5Sespie   new = (ffesttFormatList) malloc_new_kp (ffesta_scratch_pool,
596*c87b03e5Sespie 					"FFEST format list", sizeof (*new));
597*c87b03e5Sespie   new->next = list->previous->next;
598*c87b03e5Sespie   new->previous = list->previous;
599*c87b03e5Sespie   new->next->previous = new;
600*c87b03e5Sespie   new->previous->next = new;
601*c87b03e5Sespie   return new;
602*c87b03e5Sespie }
603*c87b03e5Sespie 
604*c87b03e5Sespie /* ffestt_formatlist_create -- Create new list of formats
605*c87b03e5Sespie 
606*c87b03e5Sespie    ffesttFormatList list;
607*c87b03e5Sespie    list = ffestt_formatlist_create(NULL);
608*c87b03e5Sespie 
609*c87b03e5Sespie    The list is allocated out of the scratch pool.  */
610*c87b03e5Sespie 
611*c87b03e5Sespie ffesttFormatList
ffestt_formatlist_create(ffesttFormatList parent,ffelexToken t)612*c87b03e5Sespie ffestt_formatlist_create (ffesttFormatList parent, ffelexToken t)
613*c87b03e5Sespie {
614*c87b03e5Sespie   ffesttFormatList new;
615*c87b03e5Sespie 
616*c87b03e5Sespie   new = (ffesttFormatList) malloc_new_kp (ffesta_scratch_pool,
617*c87b03e5Sespie 				   "FFEST format list root", sizeof (*new));
618*c87b03e5Sespie   new->next = new->previous = new;
619*c87b03e5Sespie   new->type = FFESTP_formattypeNone;
620*c87b03e5Sespie   new->t = t;
621*c87b03e5Sespie   new->u.root.parent = parent;
622*c87b03e5Sespie   return new;
623*c87b03e5Sespie }
624*c87b03e5Sespie 
625*c87b03e5Sespie /* ffestt_formatlist_kill -- Kill tokens on list of formats
626*c87b03e5Sespie 
627*c87b03e5Sespie    ffesttFormatList list;
628*c87b03e5Sespie    ffestt_formatlist_kill(list);
629*c87b03e5Sespie 
630*c87b03e5Sespie    The tokens on the list are killed.  */
631*c87b03e5Sespie 
632*c87b03e5Sespie void
ffestt_formatlist_kill(ffesttFormatList list)633*c87b03e5Sespie ffestt_formatlist_kill (ffesttFormatList list)
634*c87b03e5Sespie {
635*c87b03e5Sespie   ffesttFormatList next;
636*c87b03e5Sespie 
637*c87b03e5Sespie   /* Always kill from the very top on down. */
638*c87b03e5Sespie 
639*c87b03e5Sespie   while (list->u.root.parent != NULL)
640*c87b03e5Sespie     list = list->u.root.parent->next;
641*c87b03e5Sespie 
642*c87b03e5Sespie   /* Kill first token for this list. */
643*c87b03e5Sespie 
644*c87b03e5Sespie   if (list->t != NULL)
645*c87b03e5Sespie     ffelex_token_kill (list->t);
646*c87b03e5Sespie 
647*c87b03e5Sespie   /* Kill each item in this list. */
648*c87b03e5Sespie 
649*c87b03e5Sespie   for (next = list->next; next != list; next = next->next)
650*c87b03e5Sespie     {
651*c87b03e5Sespie       ffelex_token_kill (next->t);
652*c87b03e5Sespie       switch (next->type)
653*c87b03e5Sespie 	{
654*c87b03e5Sespie 	case FFESTP_formattypeI:
655*c87b03e5Sespie 	case FFESTP_formattypeB:
656*c87b03e5Sespie 	case FFESTP_formattypeO:
657*c87b03e5Sespie 	case FFESTP_formattypeZ:
658*c87b03e5Sespie 	case FFESTP_formattypeF:
659*c87b03e5Sespie 	case FFESTP_formattypeE:
660*c87b03e5Sespie 	case FFESTP_formattypeEN:
661*c87b03e5Sespie 	case FFESTP_formattypeG:
662*c87b03e5Sespie 	case FFESTP_formattypeL:
663*c87b03e5Sespie 	case FFESTP_formattypeA:
664*c87b03e5Sespie 	case FFESTP_formattypeD:
665*c87b03e5Sespie 	  if (next->u.R1005.R1004.t != NULL)
666*c87b03e5Sespie 	    ffelex_token_kill (next->u.R1005.R1004.t);
667*c87b03e5Sespie 	  if (next->u.R1005.R1006.t != NULL)
668*c87b03e5Sespie 	    ffelex_token_kill (next->u.R1005.R1006.t);
669*c87b03e5Sespie 	  if (next->u.R1005.R1007_or_R1008.t != NULL)
670*c87b03e5Sespie 	    ffelex_token_kill (next->u.R1005.R1007_or_R1008.t);
671*c87b03e5Sespie 	  if (next->u.R1005.R1009.t != NULL)
672*c87b03e5Sespie 	    ffelex_token_kill (next->u.R1005.R1009.t);
673*c87b03e5Sespie 	  break;
674*c87b03e5Sespie 
675*c87b03e5Sespie 	case FFESTP_formattypeQ:
676*c87b03e5Sespie 	case FFESTP_formattypeDOLLAR:
677*c87b03e5Sespie 	case FFESTP_formattypeP:
678*c87b03e5Sespie 	case FFESTP_formattypeT:
679*c87b03e5Sespie 	case FFESTP_formattypeTL:
680*c87b03e5Sespie 	case FFESTP_formattypeTR:
681*c87b03e5Sespie 	case FFESTP_formattypeX:
682*c87b03e5Sespie 	case FFESTP_formattypeS:
683*c87b03e5Sespie 	case FFESTP_formattypeSP:
684*c87b03e5Sespie 	case FFESTP_formattypeSS:
685*c87b03e5Sespie 	case FFESTP_formattypeBN:
686*c87b03e5Sespie 	case FFESTP_formattypeBZ:
687*c87b03e5Sespie 	case FFESTP_formattypeSLASH:
688*c87b03e5Sespie 	case FFESTP_formattypeCOLON:
689*c87b03e5Sespie 	  if (next->u.R1010.val.t != NULL)
690*c87b03e5Sespie 	    ffelex_token_kill (next->u.R1010.val.t);
691*c87b03e5Sespie 	  break;
692*c87b03e5Sespie 
693*c87b03e5Sespie 	case FFESTP_formattypeR1016:
694*c87b03e5Sespie 	  break;		/* Nothing more to do. */
695*c87b03e5Sespie 
696*c87b03e5Sespie 	case FFESTP_formattypeFORMAT:
697*c87b03e5Sespie 	  if (next->u.R1003D.R1004.t != NULL)
698*c87b03e5Sespie 	    ffelex_token_kill (next->u.R1003D.R1004.t);
699*c87b03e5Sespie 	  next->u.R1003D.format->u.root.parent = NULL;	/* Parent already dying. */
700*c87b03e5Sespie 	  ffestt_formatlist_kill (next->u.R1003D.format);
701*c87b03e5Sespie 	  break;
702*c87b03e5Sespie 
703*c87b03e5Sespie 	default:
704*c87b03e5Sespie 	  assert (FALSE);
705*c87b03e5Sespie 	}
706*c87b03e5Sespie     }
707*c87b03e5Sespie }
708*c87b03e5Sespie 
709*c87b03e5Sespie /* ffestt_implist_append -- Append token pair to list of token pairs
710*c87b03e5Sespie 
711*c87b03e5Sespie    ffesttImpList list;
712*c87b03e5Sespie    ffelexToken t;
713*c87b03e5Sespie    ffestt_implist_append(list,start_token,end_token);
714*c87b03e5Sespie 
715*c87b03e5Sespie    list must have already been created by ffestt_implist_create.  The
716*c87b03e5Sespie    list is allocated out of the scratch pool.  The tokens are consumed.	 */
717*c87b03e5Sespie 
718*c87b03e5Sespie void
ffestt_implist_append(ffesttImpList list,ffelexToken first,ffelexToken last)719*c87b03e5Sespie ffestt_implist_append (ffesttImpList list, ffelexToken first, ffelexToken last)
720*c87b03e5Sespie {
721*c87b03e5Sespie   ffesttImpList new;
722*c87b03e5Sespie 
723*c87b03e5Sespie   new = (ffesttImpList) malloc_new_kp (ffesta_scratch_pool,
724*c87b03e5Sespie 				       "FFEST token list", sizeof (*new));
725*c87b03e5Sespie   new->next = list->previous->next;
726*c87b03e5Sespie   new->previous = list->previous;
727*c87b03e5Sespie   new->next->previous = new;
728*c87b03e5Sespie   new->previous->next = new;
729*c87b03e5Sespie   new->first = first;
730*c87b03e5Sespie   new->last = last;
731*c87b03e5Sespie }
732*c87b03e5Sespie 
733*c87b03e5Sespie /* ffestt_implist_create -- Create new list of token pairs
734*c87b03e5Sespie 
735*c87b03e5Sespie    ffesttImpList list;
736*c87b03e5Sespie    list = ffestt_implist_create();
737*c87b03e5Sespie 
738*c87b03e5Sespie    The list is allocated out of the scratch pool.  */
739*c87b03e5Sespie 
740*c87b03e5Sespie ffesttImpList
ffestt_implist_create()741*c87b03e5Sespie ffestt_implist_create ()
742*c87b03e5Sespie {
743*c87b03e5Sespie   ffesttImpList new;
744*c87b03e5Sespie 
745*c87b03e5Sespie   new = (ffesttImpList) malloc_new_kp (ffesta_scratch_pool,
746*c87b03e5Sespie 				       "FFEST token list root",
747*c87b03e5Sespie 				       sizeof (*new));
748*c87b03e5Sespie   new->next = new->previous = new;
749*c87b03e5Sespie   new->first = NULL;
750*c87b03e5Sespie   new->last = NULL;
751*c87b03e5Sespie   return new;
752*c87b03e5Sespie }
753*c87b03e5Sespie 
754*c87b03e5Sespie /* ffestt_implist_drive -- Drive list of token pairs into function
755*c87b03e5Sespie 
756*c87b03e5Sespie    ffesttImpList list;
757*c87b03e5Sespie    void fn(ffelexToken first,ffelexToken last);
758*c87b03e5Sespie    ffestt_implist_drive(list,fn);
759*c87b03e5Sespie 
760*c87b03e5Sespie    The token pairs in the list are passed to the function one pair at a time.  */
761*c87b03e5Sespie 
762*c87b03e5Sespie void
ffestt_implist_drive(ffesttImpList list,void (* fn)(ffelexToken,ffelexToken))763*c87b03e5Sespie ffestt_implist_drive (ffesttImpList list, void (*fn) (ffelexToken, ffelexToken))
764*c87b03e5Sespie {
765*c87b03e5Sespie   ffesttImpList next;
766*c87b03e5Sespie 
767*c87b03e5Sespie   if (list == NULL)
768*c87b03e5Sespie     return;
769*c87b03e5Sespie 
770*c87b03e5Sespie   for (next = list->next; next != list; next = next->next)
771*c87b03e5Sespie     {
772*c87b03e5Sespie       (*fn) (next->first, next->last);
773*c87b03e5Sespie     }
774*c87b03e5Sespie }
775*c87b03e5Sespie 
776*c87b03e5Sespie /* ffestt_implist_kill -- Kill list of token pairs
777*c87b03e5Sespie 
778*c87b03e5Sespie    ffesttImpList list;
779*c87b03e5Sespie    ffestt_implist_kill(list);
780*c87b03e5Sespie 
781*c87b03e5Sespie    The tokens on the list are killed.  */
782*c87b03e5Sespie 
783*c87b03e5Sespie void
ffestt_implist_kill(ffesttImpList list)784*c87b03e5Sespie ffestt_implist_kill (ffesttImpList list)
785*c87b03e5Sespie {
786*c87b03e5Sespie   ffesttImpList next;
787*c87b03e5Sespie 
788*c87b03e5Sespie   for (next = list->next; next != list; next = next->next)
789*c87b03e5Sespie     {
790*c87b03e5Sespie       ffelex_token_kill (next->first);
791*c87b03e5Sespie       if (next->last != NULL)
792*c87b03e5Sespie 	ffelex_token_kill (next->last);
793*c87b03e5Sespie     }
794*c87b03e5Sespie }
795*c87b03e5Sespie 
796*c87b03e5Sespie /* ffestt_tokenlist_append -- Append token to list of tokens
797*c87b03e5Sespie 
798*c87b03e5Sespie    ffesttTokenList tl;
799*c87b03e5Sespie    ffelexToken t;
800*c87b03e5Sespie    ffestt_tokenlist_append(tl,t);
801*c87b03e5Sespie 
802*c87b03e5Sespie    tl must have already been created by ffestt_tokenlist_create.  The
803*c87b03e5Sespie    list is allocated out of the scratch pool.  The token is consumed.  */
804*c87b03e5Sespie 
805*c87b03e5Sespie void
ffestt_tokenlist_append(ffesttTokenList tl,ffelexToken t)806*c87b03e5Sespie ffestt_tokenlist_append (ffesttTokenList tl, ffelexToken t)
807*c87b03e5Sespie {
808*c87b03e5Sespie   ffesttTokenItem ti;
809*c87b03e5Sespie 
810*c87b03e5Sespie   ti = (ffesttTokenItem) malloc_new_kp (ffesta_scratch_pool,
811*c87b03e5Sespie 					"FFEST token item", sizeof (*ti));
812*c87b03e5Sespie   ti->next = (ffesttTokenItem) &tl->first;
813*c87b03e5Sespie   ti->previous = tl->last;
814*c87b03e5Sespie   ti->next->previous = ti;
815*c87b03e5Sespie   ti->previous->next = ti;
816*c87b03e5Sespie   ti->t = t;
817*c87b03e5Sespie   ++tl->count;
818*c87b03e5Sespie }
819*c87b03e5Sespie 
820*c87b03e5Sespie /* ffestt_tokenlist_create -- Create new list of tokens
821*c87b03e5Sespie 
822*c87b03e5Sespie    ffesttTokenList tl;
823*c87b03e5Sespie    tl = ffestt_tokenlist_create();
824*c87b03e5Sespie 
825*c87b03e5Sespie    The list is allocated out of the scratch pool.  */
826*c87b03e5Sespie 
827*c87b03e5Sespie ffesttTokenList
ffestt_tokenlist_create()828*c87b03e5Sespie ffestt_tokenlist_create ()
829*c87b03e5Sespie {
830*c87b03e5Sespie   ffesttTokenList tl;
831*c87b03e5Sespie 
832*c87b03e5Sespie   tl = (ffesttTokenList) malloc_new_kp (ffesta_scratch_pool,
833*c87b03e5Sespie 					"FFEST token list", sizeof (*tl));
834*c87b03e5Sespie   tl->first = tl->last = (ffesttTokenItem) &tl->first;
835*c87b03e5Sespie   tl->count = 0;
836*c87b03e5Sespie   return tl;
837*c87b03e5Sespie }
838*c87b03e5Sespie 
839*c87b03e5Sespie /* ffestt_tokenlist_drive -- Drive list of tokens
840*c87b03e5Sespie 
841*c87b03e5Sespie    ffesttTokenList tl;
842*c87b03e5Sespie    void fn(ffelexToken t);
843*c87b03e5Sespie    ffestt_tokenlist_drive(tl,fn);
844*c87b03e5Sespie 
845*c87b03e5Sespie    The tokens in the list are passed to the given function.  */
846*c87b03e5Sespie 
847*c87b03e5Sespie void
ffestt_tokenlist_drive(ffesttTokenList tl,void (* fn)(ffelexToken))848*c87b03e5Sespie ffestt_tokenlist_drive (ffesttTokenList tl, void (*fn) (ffelexToken))
849*c87b03e5Sespie {
850*c87b03e5Sespie   ffesttTokenItem ti;
851*c87b03e5Sespie 
852*c87b03e5Sespie   if (tl == NULL)
853*c87b03e5Sespie     return;
854*c87b03e5Sespie 
855*c87b03e5Sespie   for (ti = tl->first; ti != (ffesttTokenItem) &tl->first; ti = ti->next)
856*c87b03e5Sespie     {
857*c87b03e5Sespie       (*fn) (ti->t);
858*c87b03e5Sespie     }
859*c87b03e5Sespie }
860*c87b03e5Sespie 
861*c87b03e5Sespie /* ffestt_tokenlist_handle -- Handle list of tokens
862*c87b03e5Sespie 
863*c87b03e5Sespie    ffesttTokenList tl;
864*c87b03e5Sespie    ffelexHandler handler;
865*c87b03e5Sespie    handler = ffestt_tokenlist_handle(tl,handler);
866*c87b03e5Sespie 
867*c87b03e5Sespie    The tokens in the list are passed to the handler(s).	 */
868*c87b03e5Sespie 
869*c87b03e5Sespie ffelexHandler
ffestt_tokenlist_handle(ffesttTokenList tl,ffelexHandler handler)870*c87b03e5Sespie ffestt_tokenlist_handle (ffesttTokenList tl, ffelexHandler handler)
871*c87b03e5Sespie {
872*c87b03e5Sespie   ffesttTokenItem ti;
873*c87b03e5Sespie 
874*c87b03e5Sespie   for (ti = tl->first; ti != (ffesttTokenItem) &tl->first; ti = ti->next)
875*c87b03e5Sespie     handler = (ffelexHandler) (*handler) (ti->t);
876*c87b03e5Sespie 
877*c87b03e5Sespie   return (ffelexHandler) handler;
878*c87b03e5Sespie }
879*c87b03e5Sespie 
880*c87b03e5Sespie /* ffestt_tokenlist_kill -- Kill list of tokens
881*c87b03e5Sespie 
882*c87b03e5Sespie    ffesttTokenList tl;
883*c87b03e5Sespie    ffestt_tokenlist_kill(tl);
884*c87b03e5Sespie 
885*c87b03e5Sespie    The tokens on the list are killed.
886*c87b03e5Sespie 
887*c87b03e5Sespie    02-Mar-90  JCB  1.1
888*c87b03e5Sespie       Don't kill the list itself or change it, since it will be trashed when
889*c87b03e5Sespie       ffesta_scratch_pool is killed anyway, so kill only the lex tokens.  */
890*c87b03e5Sespie 
891*c87b03e5Sespie void
ffestt_tokenlist_kill(ffesttTokenList tl)892*c87b03e5Sespie ffestt_tokenlist_kill (ffesttTokenList tl)
893*c87b03e5Sespie {
894*c87b03e5Sespie   ffesttTokenItem ti;
895*c87b03e5Sespie 
896*c87b03e5Sespie   for (ti = tl->first; ti != (ffesttTokenItem) &tl->first; ti = ti->next)
897*c87b03e5Sespie     {
898*c87b03e5Sespie       ffelex_token_kill (ti->t);
899*c87b03e5Sespie     }
900*c87b03e5Sespie }
901