Use new tail-calling mechanism on ARM.
[official-gcc.git] / gcc / f / data.c
blob51eb2b7661b6ee5f71c547b11dca04f75c906dc4
1 /* data.c -- Implementation File (module.c template V1.0)
2 Copyright (C) 1995, 1996 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)
10 any later version.
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
20 02111-1307, USA.
22 Related Modules:
24 Description:
25 Do the tough things for DATA statement (and INTEGER FOO/.../-style
26 initializations), like implied-DO and suchlike.
28 Modifications:
31 /* Include files. */
33 #include "proj.h"
34 #include "data.h"
35 #include "bit.h"
36 #include "bld.h"
37 #include "com.h"
38 #include "expr.h"
39 #include "global.h"
40 #include "malloc.h"
41 #include "st.h"
42 #include "storag.h"
43 #include "top.h"
45 /* Externals defined here. */
48 /* Simple definitions and enumerations. */
50 /* I picked this value as one that, when plugged into a couple of small
51 but nearly identical test cases I have called BIG-0.f and BIG-1.f,
52 causes BIG-1.f to take about 10 times as long (elapsed) to compile
53 (in f771 only) as BIG-0.f. These test cases differ in that BIG-0.f
54 doesn't put the one initialized variable in a common area that has
55 a large uninitialized array in it, while BIG-1.f does. The size of
56 the array is this many elements, as long as they all are INTEGER
57 type. Note that, as of 0.5.18, sparse cases are better handled,
58 so BIG-2.f now is used; it provides nonzero initial
59 values for all elements of the same array BIG-0 has. */
60 #ifndef FFEDATA_sizeTOO_BIG_INIT_
61 #define FFEDATA_sizeTOO_BIG_INIT_ 75*1024
62 #endif
64 /* Internal typedefs. */
66 typedef struct _ffedata_convert_cache_ *ffedataConvertCache_;
67 typedef struct _ffedata_impdo_ *ffedataImpdo_;
69 /* Private include files. */
72 /* Internal structure definitions. */
74 struct _ffedata_convert_cache_
76 ffebld converted; /* Results of converting expr to following
77 type. */
78 ffeinfoBasictype basic_type;
79 ffeinfoKindtype kind_type;
80 ffetargetCharacterSize size;
81 ffeinfoRank rank;
84 struct _ffedata_impdo_
86 ffedataImpdo_ outer; /* Enclosing IMPDO construct. */
87 ffebld outer_list; /* Item after my IMPDO on the outer list. */
88 ffebld my_list; /* Beginning of list in my IMPDO. */
89 ffesymbol itervar; /* Iteration variable. */
90 ffetargetIntegerDefault increment;
91 ffetargetIntegerDefault final;
94 /* Static objects accessed by functions in this module. */
96 static ffedataImpdo_ ffedata_stack_ = NULL;
97 static ffebld ffedata_list_ = NULL;
98 static bool ffedata_reinit_; /* value_ should report REINIT error. */
99 static bool ffedata_reported_error_; /* Error has been reported. */
100 static ffesymbol ffedata_symbol_ = NULL; /* Symbol being initialized. */
101 static ffeinfoBasictype ffedata_basictype_; /* Info on symbol. */
102 static ffeinfoKindtype ffedata_kindtype_;
103 static ffestorag ffedata_storage_; /* If non-NULL, inits go into this parent. */
104 static ffeinfoBasictype ffedata_storage_bt_; /* Info on storage. */
105 static ffeinfoKindtype ffedata_storage_kt_;
106 static ffetargetOffset ffedata_storage_size_; /* Size of entire storage. */
107 static ffetargetAlign ffedata_storage_units_; /* #units per storage unit. */
108 static ffetargetOffset ffedata_arraysize_; /* Size of array being
109 inited. */
110 static ffetargetOffset ffedata_expected_; /* Number of elements to
111 init. */
112 static ffetargetOffset ffedata_number_; /* #elements inited so far. */
113 static ffetargetOffset ffedata_offset_; /* Offset of next element. */
114 static ffetargetOffset ffedata_symbolsize_; /* Size of entire sym. */
115 static ffetargetCharacterSize ffedata_size_; /* Size of an element. */
116 static ffetargetCharacterSize ffedata_charexpected_; /* #char to init. */
117 static ffetargetCharacterSize ffedata_charnumber_; /* #chars inited. */
118 static ffetargetCharacterSize ffedata_charoffset_; /* Offset of next char. */
119 static ffedataConvertCache_ ffedata_convert_cache_; /* Fewer conversions. */
120 static int ffedata_convert_cache_max_ = 0; /* #entries available. */
121 static int ffedata_convert_cache_use_ = 0; /* #entries in use. */
123 /* Static functions (internal). */
125 static bool ffedata_advance_ (void);
126 static ffebld ffedata_convert_ (ffebld source, ffelexToken source_token,
127 ffelexToken dest_token, ffeinfoBasictype bt, ffeinfoKindtype kt,
128 ffeinfoRank rk, ffetargetCharacterSize sz);
129 static ffetargetInteger1 ffedata_eval_integer1_ (ffebld expr);
130 static ffetargetOffset ffedata_eval_offset_ (ffebld subscripts,
131 ffebld dims);
132 static ffetargetCharacterSize ffedata_eval_substr_begin_ (ffebld expr);
133 static ffetargetCharacterSize ffedata_eval_substr_end_ (ffebld expr,
134 ffetargetCharacterSize min, ffetargetCharacterSize max);
135 static void ffedata_gather_ (ffestorag mst, ffestorag st);
136 static void ffedata_pop_ (void);
137 static void ffedata_push_ (void);
138 static bool ffedata_value_ (ffebld value, ffelexToken token);
140 /* Internal macros. */
143 /* ffedata_begin -- Initialize with list of targets
145 ffebld list;
146 ffedata_begin(list); // ITEM... list of SYMTERs, ARRAYs, SUBSTRs, ...
148 Remember the list. After this call, 0...n calls to ffedata_value must
149 follow, and then a single call to ffedata_end. */
151 void
152 ffedata_begin (ffebld list)
154 assert (ffedata_list_ == NULL);
155 ffedata_list_ = list;
156 ffedata_symbol_ = NULL;
157 ffedata_reported_error_ = FALSE;
158 ffedata_reinit_ = FALSE;
159 ffedata_advance_ ();
162 /* ffedata_end -- End of initialization sequence
164 if (ffedata_end(FALSE))
165 // everything's ok
167 Make sure the end of the list is valid here. */
169 bool
170 ffedata_end (bool reported_error, ffelexToken t)
172 reported_error |= ffedata_reported_error_;
174 /* If still targets to initialize, too few initializers, so complain. */
176 if ((ffedata_symbol_ != NULL) && !reported_error)
178 reported_error = TRUE;
179 ffebad_start (FFEBAD_DATA_TOOFEW);
180 ffebad_here (0, ffelex_token_where_line (t), ffelex_token_where_column (t));
181 ffebad_string (ffesymbol_text (ffedata_symbol_));
182 ffebad_finish ();
185 /* Pop off any impdo stacks (present only if ffedata_symbol_ != NULL). */
187 while (ffedata_stack_ != NULL)
188 ffedata_pop_ ();
190 if (ffedata_list_ != NULL)
192 assert (reported_error);
193 ffedata_list_ = NULL;
196 return TRUE;
199 /* ffedata_gather -- Gather previously disparate initializations into one place
201 ffestorag st; // A typeCBLOCK or typeLOCAL aggregate.
202 ffedata_gather(st);
204 Prior to this call, st has no init or accretion info, but (presumably
205 at least one of) its subordinate storage areas has init or accretion
206 info. After this call, none of the subordinate storage areas has inits,
207 because they've all been moved into the newly created init/accretion
208 info for st. During this call, conflicting inits produce only one
209 error message. */
211 void
212 ffedata_gather (ffestorag st)
214 ffesymbol s;
215 ffebld b;
217 /* Prepare info on the storage area we're putting init info into. */
219 ffetarget_aggregate_info (&ffedata_storage_bt_, &ffedata_storage_kt_,
220 &ffedata_storage_units_, ffestorag_basictype (st),
221 ffestorag_kindtype (st));
222 ffedata_storage_size_ = ffestorag_size (st) / ffedata_storage_units_;
223 assert (ffestorag_size (st) % ffedata_storage_units_ == 0);
225 /* If a CBLOCK, gather all the init info for its explicit members. */
227 if ((ffestorag_type (st) == FFESTORAG_typeCBLOCK)
228 && (ffestorag_symbol (st) != NULL))
230 s = ffestorag_symbol (st);
231 for (b = ffesymbol_commonlist (s); b != NULL; b = ffebld_trail (b))
232 ffedata_gather_ (st,
233 ffesymbol_storage (ffebld_symter (ffebld_head (b))));
236 /* For CBLOCK or LOCAL, gather all the init info for equivalenced members. */
238 ffestorag_drive (ffestorag_list_equivs (st), ffedata_gather_, st);
241 /* ffedata_value -- Provide some number of initial values
243 ffebld value;
244 ffelexToken t; // Points to the value.
245 if (ffedata_value(1,value,t))
246 // Everything's ok
248 Makes sure the value is ok, then remembers it according to the list
249 provided to ffedata_begin. As many instances of the value may be
250 supplied as desired, as indicated by the first argument. */
252 bool
253 ffedata_value (ffetargetIntegerDefault rpt, ffebld value, ffelexToken token)
255 ffetargetIntegerDefault i;
257 /* Maybe ignore zero values, to speed up compiling, even though we lose
258 checking for multiple initializations for now. */
260 if (!ffe_is_zeros ()
261 && (value != NULL)
262 && (ffebld_op (value) == FFEBLD_opCONTER)
263 && ffebld_constant_is_zero (ffebld_conter (value)))
264 value = NULL;
265 else if ((value != NULL)
266 && (ffebld_op (value) == FFEBLD_opANY))
267 value = NULL;
268 else
270 /* Must be a constant. */
271 assert (value != NULL);
272 assert (ffebld_op (value) == FFEBLD_opCONTER);
275 /* Later we can optimize certain cases by seeing that the target array can
276 take some number of values, and provide this number to _value_. */
278 if (rpt == 1)
279 ffedata_convert_cache_use_ = -1; /* Don't bother caching. */
280 else
281 ffedata_convert_cache_use_ = 0; /* Maybe use the cache. */
283 for (i = 0; i < rpt; ++i)
285 if ((ffedata_symbol_ != NULL)
286 && !ffesymbol_is_init (ffedata_symbol_))
288 ffesymbol_signal_change (ffedata_symbol_);
289 ffesymbol_update_init (ffedata_symbol_);
290 if (1 || ffe_is_90 ())
291 ffesymbol_update_save (ffedata_symbol_);
292 #if FFEGLOBAL_ENABLED
293 if (ffesymbol_common (ffedata_symbol_) != NULL)
294 ffeglobal_init_common (ffesymbol_common (ffedata_symbol_),
295 token);
296 #endif
297 ffesymbol_signal_unreported (ffedata_symbol_);
299 if (!ffedata_value_ (value, token))
300 return FALSE;
303 return TRUE;
306 /* ffedata_advance_ -- Advance initialization target to next item in list
308 if (ffedata_advance_())
309 // everything's ok
311 Sets common info to characterize the next item in the list. Handles
312 IMPDO constructs accordingly. Does not handle advances within a single
313 item, as in the common extension "DATA CHARTYPE/33,34,35/", where
314 CHARTYPE is CHARACTER*3, for example. */
316 static bool
317 ffedata_advance_ ()
319 ffebld next;
321 /* Come here after handling an IMPDO. */
323 tail_recurse: /* :::::::::::::::::::: */
325 /* Assume we're not going to find a new target for now. */
327 ffedata_symbol_ = NULL;
329 /* If at the end of the list, we're done. */
331 if (ffedata_list_ == NULL)
333 ffetargetIntegerDefault newval;
335 if (ffedata_stack_ == NULL)
336 return TRUE; /* No IMPDO in progress, we is done! */
338 /* Iterate the IMPDO. */
340 newval = ffesymbol_value (ffedata_stack_->itervar)
341 + ffedata_stack_->increment;
343 /* See if we're still in the loop. */
345 if (((ffedata_stack_->increment > 0)
346 ? newval > ffedata_stack_->final
347 : newval < ffedata_stack_->final)
348 || (((ffesymbol_value (ffedata_stack_->itervar) < 0)
349 == (ffedata_stack_->increment < 0))
350 && ((ffesymbol_value (ffedata_stack_->itervar) < 0)
351 != (newval < 0)))) /* Overflow/underflow? */
352 { /* Done with the loop. */
353 ffedata_list_ = ffedata_stack_->outer_list; /* Restore list. */
354 ffedata_pop_ (); /* Pop me off the impdo stack. */
356 else
357 { /* Still in the loop, reset the list and
358 update the iter var. */
359 ffedata_list_ = ffedata_stack_->my_list; /* Reset list. */
360 ffesymbol_set_value (ffedata_stack_->itervar, newval);
362 goto tail_recurse; /* :::::::::::::::::::: */
365 /* Move to the next item in the list. */
367 next = ffebld_head (ffedata_list_);
368 ffedata_list_ = ffebld_trail (ffedata_list_);
370 /* Really shouldn't happen. */
372 if (next == NULL)
373 return TRUE;
375 /* See what kind of target this is. */
377 switch (ffebld_op (next))
379 case FFEBLD_opSYMTER: /* Simple reference to scalar or array. */
380 ffedata_symbol_ = ffebld_symter (next);
381 ffedata_storage_ = (ffesymbol_storage (ffedata_symbol_) == NULL) ? NULL
382 : ffestorag_parent (ffesymbol_storage (ffedata_symbol_));
383 if (ffedata_storage_ != NULL)
385 ffetarget_aggregate_info (&ffedata_storage_bt_, &ffedata_storage_kt_,
386 &ffedata_storage_units_,
387 ffestorag_basictype (ffedata_storage_),
388 ffestorag_kindtype (ffedata_storage_));
389 ffedata_storage_size_ = ffestorag_size (ffedata_storage_)
390 / ffedata_storage_units_;
391 assert (ffestorag_size (ffedata_storage_) % ffedata_storage_units_ == 0);
394 if ((ffesymbol_init (ffedata_symbol_) != NULL)
395 || (ffesymbol_accretion (ffedata_symbol_) != NULL)
396 || ((ffedata_storage_ != NULL)
397 && (ffestorag_init (ffedata_storage_) != NULL)))
399 #if 0
400 ffebad_start (FFEBAD_DATA_REINIT);
401 ffest_ffebad_here_current_stmt (0);
402 ffebad_string (ffesymbol_text (ffedata_symbol_));
403 ffebad_finish ();
404 ffedata_reported_error_ = TRUE;
405 return FALSE;
406 #else
407 ffedata_reinit_ = TRUE;
408 return TRUE;
409 #endif
411 ffedata_basictype_ = ffesymbol_basictype (ffedata_symbol_);
412 ffedata_kindtype_ = ffesymbol_kindtype (ffedata_symbol_);
413 if (ffesymbol_rank (ffedata_symbol_) == 0)
414 ffedata_arraysize_ = 1;
415 else
417 ffebld size = ffesymbol_arraysize (ffedata_symbol_);
419 assert (size != NULL);
420 assert (ffebld_op (size) == FFEBLD_opCONTER);
421 assert (ffeinfo_basictype (ffebld_info (size))
422 == FFEINFO_basictypeINTEGER);
423 assert (ffeinfo_kindtype (ffebld_info (size))
424 == FFEINFO_kindtypeINTEGERDEFAULT);
425 ffedata_arraysize_ = ffebld_constant_integerdefault (ffebld_conter
426 (size));
428 ffedata_expected_ = ffedata_arraysize_;
429 ffedata_number_ = 0;
430 ffedata_offset_ = 0;
431 ffedata_size_ = (ffedata_basictype_ == FFEINFO_basictypeCHARACTER)
432 ? ffesymbol_size (ffedata_symbol_) : 1;
433 ffedata_symbolsize_ = ffedata_size_ * ffedata_arraysize_;
434 ffedata_charexpected_ = ffedata_size_;
435 ffedata_charnumber_ = 0;
436 ffedata_charoffset_ = 0;
437 break;
439 case FFEBLD_opARRAYREF: /* Reference to element of array. */
440 ffedata_symbol_ = ffebld_symter (ffebld_left (next));
441 ffedata_storage_ = (ffesymbol_storage (ffedata_symbol_) == NULL) ? NULL
442 : ffestorag_parent (ffesymbol_storage (ffedata_symbol_));
443 if (ffedata_storage_ != NULL)
445 ffetarget_aggregate_info (&ffedata_storage_bt_, &ffedata_storage_kt_,
446 &ffedata_storage_units_,
447 ffestorag_basictype (ffedata_storage_),
448 ffestorag_kindtype (ffedata_storage_));
449 ffedata_storage_size_ = ffestorag_size (ffedata_storage_)
450 / ffedata_storage_units_;
451 assert (ffestorag_size (ffedata_storage_) % ffedata_storage_units_ == 0);
454 if ((ffesymbol_init (ffedata_symbol_) != NULL)
455 || ((ffedata_storage_ != NULL)
456 && (ffestorag_init (ffedata_storage_) != NULL)))
458 #if 0
459 ffebad_start (FFEBAD_DATA_REINIT);
460 ffest_ffebad_here_current_stmt (0);
461 ffebad_string (ffesymbol_text (ffedata_symbol_));
462 ffebad_finish ();
463 ffedata_reported_error_ = TRUE;
464 return FALSE;
465 #else
466 ffedata_reinit_ = TRUE;
467 return TRUE;
468 #endif
470 ffedata_basictype_ = ffesymbol_basictype (ffedata_symbol_);
471 ffedata_kindtype_ = ffesymbol_kindtype (ffedata_symbol_);
472 if (ffesymbol_rank (ffedata_symbol_) == 0)
473 ffedata_arraysize_ = 1; /* Shouldn't happen in this case... */
474 else
476 ffebld size = ffesymbol_arraysize (ffedata_symbol_);
478 assert (size != NULL);
479 assert (ffebld_op (size) == FFEBLD_opCONTER);
480 assert (ffeinfo_basictype (ffebld_info (size))
481 == FFEINFO_basictypeINTEGER);
482 assert (ffeinfo_kindtype (ffebld_info (size))
483 == FFEINFO_kindtypeINTEGERDEFAULT);
484 ffedata_arraysize_ = ffebld_constant_integerdefault (ffebld_conter
485 (size));
487 ffedata_expected_ = 1;
488 ffedata_number_ = 0;
489 ffedata_offset_ = ffedata_eval_offset_ (ffebld_right (next),
490 ffesymbol_dims (ffedata_symbol_));
491 ffedata_size_ = (ffedata_basictype_ == FFEINFO_basictypeCHARACTER)
492 ? ffesymbol_size (ffedata_symbol_) : 1;
493 ffedata_symbolsize_ = ffedata_size_ * ffedata_arraysize_;
494 ffedata_charexpected_ = ffedata_size_;
495 ffedata_charnumber_ = 0;
496 ffedata_charoffset_ = 0;
497 break;
499 case FFEBLD_opSUBSTR: /* Substring reference to scalar or array
500 element. */
502 bool arrayref = ffebld_op (ffebld_left (next)) == FFEBLD_opARRAYREF;
503 ffebld colon = ffebld_right (next);
505 assert (colon != NULL);
507 ffedata_symbol_ = ffebld_symter (ffebld_left (arrayref
508 ? ffebld_left (next) : next));
509 ffedata_storage_ = (ffesymbol_storage (ffedata_symbol_) == NULL) ? NULL
510 : ffestorag_parent (ffesymbol_storage (ffedata_symbol_));
511 if (ffedata_storage_ != NULL)
513 ffetarget_aggregate_info (&ffedata_storage_bt_, &ffedata_storage_kt_,
514 &ffedata_storage_units_,
515 ffestorag_basictype (ffedata_storage_),
516 ffestorag_kindtype (ffedata_storage_));
517 ffedata_storage_size_ = ffestorag_size (ffedata_storage_)
518 / ffedata_storage_units_;
519 assert (ffestorag_size (ffedata_storage_) % ffedata_storage_units_ == 0);
522 if ((ffesymbol_init (ffedata_symbol_) != NULL)
523 || ((ffedata_storage_ != NULL)
524 && (ffestorag_init (ffedata_storage_) != NULL)))
526 #if 0
527 ffebad_start (FFEBAD_DATA_REINIT);
528 ffest_ffebad_here_current_stmt (0);
529 ffebad_string (ffesymbol_text (ffedata_symbol_));
530 ffebad_finish ();
531 ffedata_reported_error_ = TRUE;
532 return FALSE;
533 #else
534 ffedata_reinit_ = TRUE;
535 return TRUE;
536 #endif
538 ffedata_basictype_ = ffesymbol_basictype (ffedata_symbol_);
539 ffedata_kindtype_ = ffesymbol_kindtype (ffedata_symbol_);
540 if (ffesymbol_rank (ffedata_symbol_) == 0)
541 ffedata_arraysize_ = 1;
542 else
544 ffebld size = ffesymbol_arraysize (ffedata_symbol_);
546 assert (size != NULL);
547 assert (ffebld_op (size) == FFEBLD_opCONTER);
548 assert (ffeinfo_basictype (ffebld_info (size))
549 == FFEINFO_basictypeINTEGER);
550 assert (ffeinfo_kindtype (ffebld_info (size))
551 == FFEINFO_kindtypeINTEGERDEFAULT);
552 ffedata_arraysize_ = ffebld_constant_integerdefault (ffebld_conter
553 (size));
555 ffedata_expected_ = arrayref ? 1 : ffedata_arraysize_;
556 ffedata_number_ = 0;
557 ffedata_offset_ = arrayref ? ffedata_eval_offset_ (ffebld_right
558 (ffebld_left (next)), ffesymbol_dims (ffedata_symbol_)) : 0;
559 ffedata_size_ = ffesymbol_size (ffedata_symbol_);
560 ffedata_symbolsize_ = ffedata_size_ * ffedata_arraysize_;
561 ffedata_charnumber_ = 0;
562 ffedata_charoffset_ = ffedata_eval_substr_begin_ (ffebld_head (colon));
563 ffedata_charexpected_ = ffedata_eval_substr_end_ (ffebld_head
564 (ffebld_trail (colon)), ffedata_charoffset_,
565 ffedata_size_) - ffedata_charoffset_ + 1;
567 break;
569 case FFEBLD_opIMPDO: /* Implied-DO construct. */
571 ffebld itervar;
572 ffebld start;
573 ffebld end;
574 ffebld incr;
575 ffebld item = ffebld_right (next);
577 itervar = ffebld_head (item);
578 item = ffebld_trail (item);
579 start = ffebld_head (item);
580 item = ffebld_trail (item);
581 end = ffebld_head (item);
582 item = ffebld_trail (item);
583 incr = ffebld_head (item);
585 ffedata_push_ ();
586 ffedata_stack_->outer_list = ffedata_list_;
587 ffedata_stack_->my_list = ffedata_list_ = ffebld_left (next);
589 assert (ffeinfo_basictype (ffebld_info (itervar))
590 == FFEINFO_basictypeINTEGER);
591 assert (ffeinfo_kindtype (ffebld_info (itervar))
592 == FFEINFO_kindtypeINTEGERDEFAULT);
593 ffedata_stack_->itervar = ffebld_symter (itervar);
595 assert (ffeinfo_basictype (ffebld_info (start))
596 == FFEINFO_basictypeINTEGER);
597 assert (ffeinfo_kindtype (ffebld_info (start))
598 == FFEINFO_kindtypeINTEGERDEFAULT);
599 ffesymbol_set_value (ffedata_stack_->itervar, ffedata_eval_integer1_ (start));
601 assert (ffeinfo_basictype (ffebld_info (end))
602 == FFEINFO_basictypeINTEGER);
603 assert (ffeinfo_kindtype (ffebld_info (end))
604 == FFEINFO_kindtypeINTEGERDEFAULT);
605 ffedata_stack_->final = ffedata_eval_integer1_ (end);
607 if (incr == NULL)
608 ffedata_stack_->increment = 1;
609 else
611 assert (ffeinfo_basictype (ffebld_info (incr))
612 == FFEINFO_basictypeINTEGER);
613 assert (ffeinfo_kindtype (ffebld_info (incr))
614 == FFEINFO_kindtypeINTEGERDEFAULT);
615 ffedata_stack_->increment = ffedata_eval_integer1_ (incr);
616 if (ffedata_stack_->increment == 0)
618 ffebad_start (FFEBAD_DATA_ZERO);
619 ffest_ffebad_here_current_stmt (0);
620 ffebad_string (ffesymbol_text (ffedata_stack_->itervar));
621 ffebad_finish ();
622 ffedata_pop_ ();
623 ffedata_reported_error_ = TRUE;
624 return FALSE;
628 if ((ffedata_stack_->increment > 0)
629 ? ffesymbol_value (ffedata_stack_->itervar)
630 > ffedata_stack_->final
631 : ffesymbol_value (ffedata_stack_->itervar)
632 < ffedata_stack_->final)
634 ffedata_reported_error_ = TRUE;
635 ffebad_start (FFEBAD_DATA_EMPTY);
636 ffest_ffebad_here_current_stmt (0);
637 ffebad_string (ffesymbol_text (ffedata_stack_->itervar));
638 ffebad_finish ();
639 ffedata_pop_ ();
640 return FALSE;
643 goto tail_recurse; /* :::::::::::::::::::: */
645 case FFEBLD_opANY:
646 ffedata_reported_error_ = TRUE;
647 return FALSE;
649 default:
650 assert ("bad op" == NULL);
651 break;
654 return TRUE;
657 /* ffedata_convert_ -- Convert source expression to given type using cache
659 ffebld source;
660 ffelexToken source_token;
661 ffelexToken dest_token; // Any appropriate token for "destination".
662 ffeinfoBasictype bt;
663 ffeinfoKindtype kt;
664 ffetargetCharactersize sz;
665 source = ffedata_convert_(source,source_token,dest_token,bt,kt,sz);
667 Like ffeexpr_convert, but calls it only if necessary (if the converted
668 expression doesn't already exist in the cache) and then puts the result
669 in the cache. */
671 static ffebld
672 ffedata_convert_ (ffebld source, ffelexToken source_token,
673 ffelexToken dest_token, ffeinfoBasictype bt,
674 ffeinfoKindtype kt, ffeinfoRank rk,
675 ffetargetCharacterSize sz)
677 ffebld converted;
678 int i;
679 int max;
680 ffedataConvertCache_ cache;
682 for (i = 0; i < ffedata_convert_cache_use_; ++i)
683 if ((bt == ffedata_convert_cache_[i].basic_type)
684 && (kt == ffedata_convert_cache_[i].kind_type)
685 && (sz == ffedata_convert_cache_[i].size)
686 && (rk == ffedata_convert_cache_[i].rank))
687 return ffedata_convert_cache_[i].converted;
689 converted = ffeexpr_convert (source, source_token, dest_token, bt, kt, rk,
690 sz, FFEEXPR_contextDATA);
692 if (ffedata_convert_cache_use_ >= ffedata_convert_cache_max_)
694 if (ffedata_convert_cache_max_ == 0)
695 max = 4;
696 else
697 max = ffedata_convert_cache_max_ << 1;
699 if (max > ffedata_convert_cache_max_)
701 cache = (ffedataConvertCache_) malloc_new_ks (malloc_pool_image (),
702 "FFEDATA cache", max * sizeof (*cache));
703 if (ffedata_convert_cache_max_ != 0)
705 memcpy (cache, ffedata_convert_cache_,
706 ffedata_convert_cache_max_ * sizeof (*cache));
707 malloc_kill_ks (malloc_pool_image (), ffedata_convert_cache_,
708 ffedata_convert_cache_max_ * sizeof (*cache));
710 ffedata_convert_cache_ = cache;
711 ffedata_convert_cache_max_ = max;
713 else
714 return converted; /* In case int overflows! */
717 i = ffedata_convert_cache_use_++;
719 ffedata_convert_cache_[i].converted = converted;
720 ffedata_convert_cache_[i].basic_type = bt;
721 ffedata_convert_cache_[i].kind_type = kt;
722 ffedata_convert_cache_[i].size = sz;
723 ffedata_convert_cache_[i].rank = rk;
725 return converted;
728 /* ffedata_eval_integer1_ -- Evaluate expression
730 ffetargetIntegerDefault result;
731 ffebld expr; // must be kindtypeINTEGER1.
733 result = ffedata_eval_integer1_(expr);
735 Evalues the expression (which yields a kindtypeINTEGER1 result) and
736 returns the result. */
738 static ffetargetIntegerDefault
739 ffedata_eval_integer1_ (ffebld expr)
741 ffetargetInteger1 result;
742 ffebad error;
744 assert (expr != NULL);
746 switch (ffebld_op (expr))
748 case FFEBLD_opCONTER:
749 return ffebld_constant_integer1 (ffebld_conter (expr));
751 case FFEBLD_opSYMTER:
752 return ffesymbol_value (ffebld_symter (expr));
754 case FFEBLD_opUPLUS:
755 return ffedata_eval_integer1_ (ffebld_left (expr));
757 case FFEBLD_opUMINUS:
758 error = ffetarget_uminus_integer1 (&result,
759 ffedata_eval_integer1_ (ffebld_left (expr)));
760 break;
762 case FFEBLD_opADD:
763 error = ffetarget_add_integer1 (&result,
764 ffedata_eval_integer1_ (ffebld_left (expr)),
765 ffedata_eval_integer1_ (ffebld_right (expr)));
766 break;
768 case FFEBLD_opSUBTRACT:
769 error = ffetarget_subtract_integer1 (&result,
770 ffedata_eval_integer1_ (ffebld_left (expr)),
771 ffedata_eval_integer1_ (ffebld_right (expr)));
772 break;
774 case FFEBLD_opMULTIPLY:
775 error = ffetarget_multiply_integer1 (&result,
776 ffedata_eval_integer1_ (ffebld_left (expr)),
777 ffedata_eval_integer1_ (ffebld_right (expr)));
778 break;
780 case FFEBLD_opDIVIDE:
781 error = ffetarget_divide_integer1 (&result,
782 ffedata_eval_integer1_ (ffebld_left (expr)),
783 ffedata_eval_integer1_ (ffebld_right (expr)));
784 break;
786 case FFEBLD_opPOWER:
788 ffebld r = ffebld_right (expr);
790 if ((ffeinfo_basictype (ffebld_info (r)) != FFEINFO_basictypeINTEGER)
791 || (ffeinfo_kindtype (ffebld_info (r)) != FFEINFO_kindtypeINTEGERDEFAULT))
792 error = FFEBAD_DATA_EVAL;
793 else
794 error = ffetarget_power_integerdefault_integerdefault (&result,
795 ffedata_eval_integer1_ (ffebld_left (expr)),
796 ffedata_eval_integer1_ (r));
798 break;
800 #if 0 /* Only for character basictype. */
801 case FFEBLD_opCONCATENATE:
802 error =;
803 break;
804 #endif
806 case FFEBLD_opNOT:
807 error = ffetarget_not_integer1 (&result,
808 ffedata_eval_integer1_ (ffebld_left (expr)));
809 break;
811 #if 0 /* Only for logical basictype. */
812 case FFEBLD_opLT:
813 error =;
814 break;
816 case FFEBLD_opLE:
817 error =;
818 break;
820 case FFEBLD_opEQ:
821 error =;
822 break;
824 case FFEBLD_opNE:
825 error =;
826 break;
828 case FFEBLD_opGT:
829 error =;
830 break;
832 case FFEBLD_opGE:
833 error =;
834 break;
835 #endif
837 case FFEBLD_opAND:
838 error = ffetarget_and_integer1 (&result,
839 ffedata_eval_integer1_ (ffebld_left (expr)),
840 ffedata_eval_integer1_ (ffebld_right (expr)));
841 break;
843 case FFEBLD_opOR:
844 error = ffetarget_or_integer1 (&result,
845 ffedata_eval_integer1_ (ffebld_left (expr)),
846 ffedata_eval_integer1_ (ffebld_right (expr)));
847 break;
849 case FFEBLD_opXOR:
850 error = ffetarget_xor_integer1 (&result,
851 ffedata_eval_integer1_ (ffebld_left (expr)),
852 ffedata_eval_integer1_ (ffebld_right (expr)));
853 break;
855 case FFEBLD_opEQV:
856 error = ffetarget_eqv_integer1 (&result,
857 ffedata_eval_integer1_ (ffebld_left (expr)),
858 ffedata_eval_integer1_ (ffebld_right (expr)));
859 break;
861 case FFEBLD_opNEQV:
862 error = ffetarget_neqv_integer1 (&result,
863 ffedata_eval_integer1_ (ffebld_left (expr)),
864 ffedata_eval_integer1_ (ffebld_right (expr)));
865 break;
867 case FFEBLD_opPAREN:
868 return ffedata_eval_integer1_ (ffebld_left (expr));
870 #if 0 /* ~~ no idea how to do this */
871 case FFEBLD_opPERCENT_LOC:
872 error =;
873 break;
874 #endif
876 #if 0 /* not allowed by ANSI, but perhaps as an
877 extension someday? */
878 case FFEBLD_opCONVERT:
879 switch (ffeinfo_basictype (ffebld_info (ffebld_left (expr))))
881 case FFEINFO_basictypeINTEGER:
882 switch (ffeinfo_kindtype (ffebld_info (ffebld_left (expr))))
884 default:
885 error = FFEBAD_DATA_EVAL;
886 break;
888 break;
890 case FFEINFO_basictypeREAL:
891 switch (ffeinfo_kindtype (ffebld_info (ffebld_left (expr))))
893 default:
894 error = FFEBAD_DATA_EVAL;
895 break;
897 break;
899 break;
900 #endif
902 #if 0 /* not valid ops */
903 case FFEBLD_opREPEAT:
904 error =;
905 break;
907 case FFEBLD_opBOUNDS:
908 error =;
909 break;
910 #endif
912 #if 0 /* not allowed by ANSI, but perhaps as an
913 extension someday? */
914 case FFEBLD_opFUNCREF:
915 error =;
916 break;
917 #endif
919 #if 0 /* not valid ops */
920 case FFEBLD_opSUBRREF:
921 error =;
922 break;
924 case FFEBLD_opARRAYREF:
925 error =;
926 break;
927 #endif
929 #if 0 /* not valid for integer1 */
930 case FFEBLD_opSUBSTR:
931 error =;
932 break;
933 #endif
935 default:
936 error = FFEBAD_DATA_EVAL;
937 break;
940 if (error != FFEBAD)
942 ffebad_start (error);
943 ffest_ffebad_here_current_stmt (0);
944 ffebad_finish ();
945 result = 0;
948 return result;
951 /* ffedata_eval_offset_ -- Evaluate offset info array
953 ffetargetOffset offset; // 0...max-1.
954 ffebld subscripts; // an opITEM list of subscript exprs.
955 ffebld dims; // an opITEM list of opBOUNDS exprs.
957 result = ffedata_eval_offset_(expr);
959 Evalues the expression (which yields a kindtypeINTEGER1 result) and
960 returns the result. */
962 static ffetargetOffset
963 ffedata_eval_offset_ (ffebld subscripts, ffebld dims)
965 ffetargetIntegerDefault offset = 0;
966 ffetargetIntegerDefault width = 1;
967 ffetargetIntegerDefault value;
968 ffetargetIntegerDefault lowbound;
969 ffetargetIntegerDefault highbound;
970 ffetargetOffset final;
971 ffebld subscript;
972 ffebld dim;
973 ffebld low;
974 ffebld high;
975 int rank = 0;
976 bool ok;
978 while (subscripts != NULL)
980 ++rank;
981 assert (dims != NULL);
983 subscript = ffebld_head (subscripts);
984 dim = ffebld_head (dims);
986 assert (ffeinfo_basictype (ffebld_info (subscript)) == FFEINFO_basictypeINTEGER);
987 assert (ffeinfo_kindtype (ffebld_info (subscript)) == FFEINFO_kindtypeINTEGER1);
988 value = ffedata_eval_integer1_ (subscript);
990 assert (ffebld_op (dim) == FFEBLD_opBOUNDS);
991 low = ffebld_left (dim);
992 high = ffebld_right (dim);
994 if (low == NULL)
995 lowbound = 1;
996 else
998 assert (ffeinfo_basictype (ffebld_info (low)) == FFEINFO_basictypeINTEGER);
999 assert (ffeinfo_kindtype (ffebld_info (low)) == FFEINFO_kindtypeINTEGERDEFAULT);
1000 lowbound = ffedata_eval_integer1_ (low);
1003 assert (ffeinfo_basictype (ffebld_info (high)) == FFEINFO_basictypeINTEGER);
1004 assert (ffeinfo_kindtype (ffebld_info (high)) == FFEINFO_kindtypeINTEGERDEFAULT);
1005 highbound = ffedata_eval_integer1_ (high);
1007 if ((value < lowbound) || (value > highbound))
1009 char rankstr[10];
1011 sprintf (rankstr, "%d", rank);
1012 value = lowbound;
1013 ffebad_start (FFEBAD_DATA_SUBSCRIPT);
1014 ffebad_string (ffesymbol_text (ffedata_symbol_));
1015 ffebad_string (rankstr);
1016 ffebad_finish ();
1019 subscripts = ffebld_trail (subscripts);
1020 dims = ffebld_trail (dims);
1022 offset += width * (value - lowbound);
1023 if (subscripts != NULL)
1024 width *= highbound - lowbound + 1;
1027 assert (dims == NULL);
1029 ok = ffetarget_offset (&final, offset);
1030 assert (ok);
1032 return final;
1035 /* ffedata_eval_substr_begin_ -- Evaluate begin-point of substr reference
1037 ffetargetCharacterSize beginpoint;
1038 ffebld endval; // head(colon).
1040 beginpoint = ffedata_eval_substr_end_(endval);
1042 If beginval is NULL, returns 0. Otherwise makes sure beginval is
1043 kindtypeINTEGERDEFAULT, makes sure its value is > 0,
1044 and returns its value minus one, or issues an error message. */
1046 static ffetargetCharacterSize
1047 ffedata_eval_substr_begin_ (ffebld expr)
1049 ffetargetIntegerDefault val;
1051 if (expr == NULL)
1052 return 0;
1054 assert (ffeinfo_basictype (ffebld_info (expr)) == FFEINFO_basictypeINTEGER);
1055 assert (ffeinfo_kindtype (ffebld_info (expr)) == FFEINFO_kindtypeINTEGERDEFAULT);
1057 val = ffedata_eval_integer1_ (expr);
1059 if (val < 1)
1061 val = 1;
1062 ffebad_start (FFEBAD_DATA_RANGE);
1063 ffest_ffebad_here_current_stmt (0);
1064 ffebad_string (ffesymbol_text (ffedata_symbol_));
1065 ffebad_finish ();
1066 ffedata_reported_error_ = TRUE;
1069 return val - 1;
1072 /* ffedata_eval_substr_end_ -- Evaluate end-point of substr reference
1074 ffetargetCharacterSize endpoint;
1075 ffebld endval; // head(trail(colon)).
1076 ffetargetCharacterSize min; // beginpoint of substr reference.
1077 ffetargetCharacterSize max; // size of entity.
1079 endpoint = ffedata_eval_substr_end_(endval,dflt);
1081 If endval is NULL, returns max. Otherwise makes sure endval is
1082 kindtypeINTEGERDEFAULT, makes sure its value is > min and <= max,
1083 and returns its value minus one, or issues an error message. */
1085 static ffetargetCharacterSize
1086 ffedata_eval_substr_end_ (ffebld expr, ffetargetCharacterSize min,
1087 ffetargetCharacterSize max)
1089 ffetargetIntegerDefault val;
1091 if (expr == NULL)
1092 return max - 1;
1094 assert (ffeinfo_basictype (ffebld_info (expr)) == FFEINFO_basictypeINTEGER);
1095 assert (ffeinfo_kindtype (ffebld_info (expr)) == FFEINFO_kindtypeINTEGER1);
1097 val = ffedata_eval_integer1_ (expr);
1099 if ((val < (ffetargetIntegerDefault) min)
1100 || (val > (ffetargetIntegerDefault) max))
1102 val = 1;
1103 ffebad_start (FFEBAD_DATA_RANGE);
1104 ffest_ffebad_here_current_stmt (0);
1105 ffebad_string (ffesymbol_text (ffedata_symbol_));
1106 ffebad_finish ();
1107 ffedata_reported_error_ = TRUE;
1110 return val - 1;
1113 /* ffedata_gather_ -- Gather initial values for sym into master sym inits
1115 ffestorag mst; // A typeCBLOCK or typeLOCAL aggregate.
1116 ffestorag st; // A typeCOMMON or typeEQUIV member.
1117 ffedata_gather_(mst,st);
1119 If st has any initialization info, transfer that info into mst and
1120 clear st's info. */
1122 static void
1123 ffedata_gather_ (ffestorag mst, ffestorag st)
1125 ffesymbol s;
1126 ffesymbol s_whine; /* Symbol to complain about in diagnostics. */
1127 ffebld b;
1128 ffetargetOffset offset;
1129 ffetargetOffset units_expected;
1130 ffebitCount actual;
1131 ffebldConstantArray array;
1132 ffebld accter;
1133 ffetargetCopyfunc fn;
1134 void *ptr1;
1135 void *ptr2;
1136 size_t size;
1137 ffeinfoBasictype bt;
1138 ffeinfoKindtype kt;
1139 ffeinfoBasictype ign_bt;
1140 ffeinfoKindtype ign_kt;
1141 ffetargetAlign units;
1142 ffebit bits;
1143 ffetargetOffset source_offset;
1144 bool whine = FALSE;
1146 if (st == NULL)
1147 return; /* Nothing to do. */
1149 s = ffestorag_symbol (st);
1151 assert (s != NULL); /* Must have a corresponding symbol (else how
1152 inited?). */
1153 assert (ffestorag_init (st) == NULL); /* No init info on storage itself. */
1154 assert (ffestorag_accretion (st) == NULL);
1156 if ((((b = ffesymbol_init (s)) == NULL)
1157 && ((b = ffesymbol_accretion (s)) == NULL))
1158 || (ffebld_op (b) == FFEBLD_opANY)
1159 || ((ffebld_op (b) == FFEBLD_opCONVERT)
1160 && (ffebld_op (ffebld_left (b)) == FFEBLD_opANY)))
1161 return; /* Nothing to do. */
1163 /* b now holds the init/accretion expr. */
1165 ffesymbol_set_init (s, NULL);
1166 ffesymbol_set_accretion (s, NULL);
1167 ffesymbol_set_accretes (s, 0);
1169 s_whine = ffestorag_symbol (mst);
1170 if (s_whine == NULL)
1171 s_whine = s;
1173 /* Make sure we haven't fully accreted during an array init. */
1175 if (ffestorag_init (mst) != NULL)
1177 ffebad_start (FFEBAD_DATA_MULTIPLE);
1178 ffebad_here (0, ffewhere_line_unknown (), ffewhere_column_unknown ());
1179 ffebad_string (ffesymbol_text (s_whine));
1180 ffebad_finish ();
1181 return;
1184 bt = ffeinfo_basictype (ffebld_info (b));
1185 kt = ffeinfo_kindtype (ffebld_info (b));
1187 /* Calculate offset for aggregate area. */
1189 ffedata_charexpected_ = (bt == FFEINFO_basictypeCHARACTER)
1190 ? ffebld_size (b) : 1;
1191 ffetarget_aggregate_info (&ign_bt, &ign_kt, &units, bt,
1192 kt);/* Find out unit size of source datum. */
1193 assert (units % ffedata_storage_units_ == 0);
1194 units_expected = ffedata_charexpected_ * units / ffedata_storage_units_;
1195 offset = (ffestorag_offset (st) - ffestorag_offset (mst))
1196 / ffedata_storage_units_;
1198 /* Does an accretion array exist? If not, create it. */
1200 if (ffestorag_accretion (mst) == NULL)
1202 #if FFEDATA_sizeTOO_BIG_INIT_ != 0
1203 if (ffedata_storage_size_ >= FFEDATA_sizeTOO_BIG_INIT_)
1205 char bignum[40];
1207 sprintf (&bignum[0], "%ld", (long) ffedata_storage_size_);
1208 ffebad_start (FFEBAD_TOO_BIG_INIT);
1209 ffebad_here (0, ffesymbol_where_line (s_whine),
1210 ffesymbol_where_column (s_whine));
1211 ffebad_string (ffesymbol_text (s_whine));
1212 ffebad_string (bignum);
1213 ffebad_finish ();
1215 #endif
1216 array = ffebld_constantarray_new (ffedata_storage_bt_,
1217 ffedata_storage_kt_, ffedata_storage_size_);
1218 accter = ffebld_new_accter (array, ffebit_new (ffe_pool_program_unit (),
1219 ffedata_storage_size_));
1220 ffebld_set_info (accter, ffeinfo_new
1221 (ffedata_storage_bt_,
1222 ffedata_storage_kt_,
1224 FFEINFO_kindENTITY,
1225 FFEINFO_whereCONSTANT,
1226 (ffedata_basictype_ == FFEINFO_basictypeCHARACTER)
1227 ? 1 : FFETARGET_charactersizeNONE));
1228 ffestorag_set_accretion (mst, accter);
1229 ffestorag_set_accretes (mst, ffedata_storage_size_);
1231 else
1233 accter = ffestorag_accretion (mst);
1234 assert (ffedata_storage_size_ == (ffetargetOffset) ffebld_accter_size (accter));
1235 array = ffebld_accter (accter);
1238 /* Put value in accretion array at desired offset. */
1240 fn = ffetarget_aggregate_ptr_memcpy (ffedata_storage_bt_, ffedata_storage_kt_,
1241 bt, kt);
1243 switch (ffebld_op (b))
1245 case FFEBLD_opCONTER:
1246 ffebld_constantarray_prepare (&ptr1, &ptr2, &size, array, ffedata_storage_bt_,
1247 ffedata_storage_kt_, offset,
1248 ffebld_constant_ptr_to_union (ffebld_conter (b)),
1249 bt, kt);
1250 (*fn) (ptr1, ptr2, size); /* Does the appropriate memcpy-like
1251 operation. */
1252 ffebit_count (ffebld_accter_bits (accter),
1253 offset, FALSE, units_expected, &actual); /* How many FALSE? */
1254 if (units_expected != (ffetargetOffset) actual)
1256 ffebad_start (FFEBAD_DATA_MULTIPLE);
1257 ffebad_here (0, ffewhere_line_unknown (), ffewhere_column_unknown ());
1258 ffebad_string (ffesymbol_text (s));
1259 ffebad_finish ();
1261 ffestorag_set_accretes (mst,
1262 ffestorag_accretes (mst)
1263 - actual); /* Decrement # of values
1264 actually accreted. */
1265 ffebit_set (ffebld_accter_bits (accter), offset, 1, units_expected);
1267 /* If done accreting for this storage area, establish as initialized. */
1269 if (ffestorag_accretes (mst) == 0)
1271 ffestorag_set_init (mst, accter);
1272 ffestorag_set_accretion (mst, NULL);
1273 ffebit_kill (ffebld_accter_bits (ffestorag_init (mst)));
1274 ffebld_set_op (ffestorag_init (mst), FFEBLD_opARRTER);
1275 ffebld_set_arrter (ffestorag_init (mst),
1276 ffebld_accter (ffestorag_init (mst)));
1277 ffebld_arrter_set_size (ffestorag_init (mst),
1278 ffedata_storage_size_);
1279 ffebld_arrter_set_pad (ffestorag_init (mst), 0);
1280 ffecom_notify_init_storage (mst);
1283 return;
1285 case FFEBLD_opARRTER:
1286 ffebld_constantarray_preparray (&ptr1, &ptr2, &size, array, ffedata_storage_bt_,
1287 ffedata_storage_kt_, offset, ffebld_arrter (b),
1288 bt, kt);
1289 size *= ffebld_arrter_size (b);
1290 units_expected *= ffebld_arrter_size (b);
1291 (*fn) (ptr1, ptr2, size); /* Does the appropriate memcpy-like
1292 operation. */
1293 ffebit_count (ffebld_accter_bits (accter),
1294 offset, FALSE, units_expected, &actual); /* How many FALSE? */
1295 if (units_expected != (ffetargetOffset) actual)
1297 ffebad_start (FFEBAD_DATA_MULTIPLE);
1298 ffebad_here (0, ffewhere_line_unknown (), ffewhere_column_unknown ());
1299 ffebad_string (ffesymbol_text (s));
1300 ffebad_finish ();
1302 ffestorag_set_accretes (mst,
1303 ffestorag_accretes (mst)
1304 - actual); /* Decrement # of values
1305 actually accreted. */
1306 ffebit_set (ffebld_accter_bits (accter), offset, 1, units_expected);
1308 /* If done accreting for this storage area, establish as initialized. */
1310 if (ffestorag_accretes (mst) == 0)
1312 ffestorag_set_init (mst, accter);
1313 ffestorag_set_accretion (mst, NULL);
1314 ffebit_kill (ffebld_accter_bits (ffestorag_init (mst)));
1315 ffebld_set_op (ffestorag_init (mst), FFEBLD_opARRTER);
1316 ffebld_set_arrter (ffestorag_init (mst),
1317 ffebld_accter (ffestorag_init (mst)));
1318 ffebld_arrter_set_size (ffestorag_init (mst),
1319 ffedata_storage_size_);
1320 ffebld_arrter_set_pad (ffestorag_init (mst), 0);
1321 ffecom_notify_init_storage (mst);
1324 return;
1326 case FFEBLD_opACCTER:
1327 ffebld_constantarray_preparray (&ptr1, &ptr2, &size, array, ffedata_storage_bt_,
1328 ffedata_storage_kt_, offset, ffebld_accter (b),
1329 bt, kt);
1330 bits = ffebld_accter_bits (b);
1331 source_offset = 0;
1333 for (;;)
1335 ffetargetOffset unexp;
1336 ffetargetOffset siz;
1337 ffebitCount length;
1338 bool value;
1340 ffebit_test (bits, source_offset, &value, &length);
1341 if (length == 0)
1342 break; /* Exit the loop early. */
1343 siz = size * length;
1344 unexp = units_expected * length;
1345 if (value)
1347 (*fn) (ptr1, ptr2, siz); /* Does memcpy-like operation. */
1348 ffebit_count (ffebld_accter_bits (accter), /* How many FALSE? */
1349 offset, FALSE, unexp, &actual);
1350 if (!whine && (unexp != (ffetargetOffset) actual))
1352 whine = TRUE; /* Don't whine more than once for one gather. */
1353 ffebad_start (FFEBAD_DATA_MULTIPLE);
1354 ffebad_here (0, ffewhere_line_unknown (), ffewhere_column_unknown ());
1355 ffebad_string (ffesymbol_text (s));
1356 ffebad_finish ();
1358 ffestorag_set_accretes (mst,
1359 ffestorag_accretes (mst)
1360 - actual); /* Decrement # of values
1361 actually accreted. */
1362 ffebit_set (ffebld_accter_bits (accter), offset, 1, unexp);
1364 source_offset += length;
1365 offset += unexp;
1366 ptr1 = ((char *) ptr1) + siz;
1367 ptr2 = ((char *) ptr2) + siz;
1370 /* If done accreting for this storage area, establish as initialized. */
1372 if (ffestorag_accretes (mst) == 0)
1374 ffestorag_set_init (mst, accter);
1375 ffestorag_set_accretion (mst, NULL);
1376 ffebit_kill (ffebld_accter_bits (ffestorag_init (mst)));
1377 ffebld_set_op (ffestorag_init (mst), FFEBLD_opARRTER);
1378 ffebld_set_arrter (ffestorag_init (mst),
1379 ffebld_accter (ffestorag_init (mst)));
1380 ffebld_arrter_set_size (ffestorag_init (mst),
1381 ffedata_storage_size_);
1382 ffebld_arrter_set_pad (ffestorag_init (mst), 0);
1383 ffecom_notify_init_storage (mst);
1386 return;
1388 default:
1389 assert ("bad init op in gather_" == NULL);
1390 return;
1394 /* ffedata_pop_ -- Pop an impdo stack entry
1396 ffedata_pop_(); */
1398 static void
1399 ffedata_pop_ ()
1401 ffedataImpdo_ victim = ffedata_stack_;
1403 assert (victim != NULL);
1405 ffedata_stack_ = ffedata_stack_->outer;
1407 malloc_kill_ks (ffe_pool_program_unit (), victim, sizeof (*victim));
1410 /* ffedata_push_ -- Push an impdo stack entry
1412 ffedata_push_(); */
1414 static void
1415 ffedata_push_ ()
1417 ffedataImpdo_ baby;
1419 baby = malloc_new_ks (ffe_pool_program_unit (), "ffedataImpdo_", sizeof (*baby));
1421 baby->outer = ffedata_stack_;
1422 ffedata_stack_ = baby;
1425 /* ffedata_value_ -- Provide an initial value
1427 ffebld value;
1428 ffelexToken t; // Points to the value.
1429 if (ffedata_value(value,t))
1430 // Everything's ok
1432 Makes sure the value is ok, then remembers it according to the list
1433 provided to ffedata_begin. */
1435 static bool
1436 ffedata_value_ (ffebld value, ffelexToken token)
1439 /* If already reported an error, don't do anything. */
1441 if (ffedata_reported_error_)
1442 return FALSE;
1444 /* If the value is an error marker, remember we've seen one and do nothing
1445 else. */
1447 if ((value != NULL)
1448 && (ffebld_op (value) == FFEBLD_opANY))
1450 ffedata_reported_error_ = TRUE;
1451 return FALSE;
1454 /* If too many values (no more targets), complain. */
1456 if (ffedata_symbol_ == NULL)
1458 ffebad_start (FFEBAD_DATA_TOOMANY);
1459 ffebad_here (0, ffelex_token_where_line (token),
1460 ffelex_token_where_column (token));
1461 ffebad_finish ();
1462 ffedata_reported_error_ = TRUE;
1463 return FALSE;
1466 /* If ffedata_advance_ wanted to register a complaint, do it now
1467 that we have the token to point at instead of just the start
1468 of the whole statement. */
1470 if (ffedata_reinit_)
1472 ffebad_start (FFEBAD_DATA_REINIT);
1473 ffebad_here (0, ffelex_token_where_line (token),
1474 ffelex_token_where_column (token));
1475 ffebad_string (ffesymbol_text (ffedata_symbol_));
1476 ffebad_finish ();
1477 ffedata_reported_error_ = TRUE;
1478 return FALSE;
1481 #if FFEGLOBAL_ENABLED
1482 if (ffesymbol_common (ffedata_symbol_) != NULL)
1483 ffeglobal_init_common (ffesymbol_common (ffedata_symbol_), token);
1484 #endif
1486 /* Convert value to desired type. */
1488 if (value != NULL)
1490 if (ffedata_convert_cache_use_ == -1)
1491 value = ffeexpr_convert
1492 (value, token, NULL, ffedata_basictype_,
1493 ffedata_kindtype_, 0,
1494 (ffedata_basictype_ == FFEINFO_basictypeCHARACTER)
1495 ? ffedata_charexpected_ : FFETARGET_charactersizeNONE,
1496 FFEEXPR_contextDATA);
1497 else /* Use the cache. */
1498 value = ffedata_convert_
1499 (value, token, NULL, ffedata_basictype_,
1500 ffedata_kindtype_, 0,
1501 (ffedata_basictype_ == FFEINFO_basictypeCHARACTER)
1502 ? ffedata_charexpected_ : FFETARGET_charactersizeNONE);
1505 /* If we couldn't, bug out. */
1507 if ((value != NULL) && (ffebld_op (value) == FFEBLD_opANY))
1509 ffedata_reported_error_ = TRUE;
1510 return FALSE;
1513 /* Handle the case where initializes go to a parent's storage area. */
1515 if (ffedata_storage_ != NULL)
1517 ffetargetOffset offset;
1518 ffetargetOffset units_expected;
1519 ffebitCount actual;
1520 ffebldConstantArray array;
1521 ffebld accter;
1522 ffetargetCopyfunc fn;
1523 void *ptr1;
1524 void *ptr2;
1525 size_t size;
1526 ffeinfoBasictype ign_bt;
1527 ffeinfoKindtype ign_kt;
1528 ffetargetAlign units;
1530 /* Make sure we haven't fully accreted during an array init. */
1532 if (ffestorag_init (ffedata_storage_) != NULL)
1534 ffebad_start (FFEBAD_DATA_MULTIPLE);
1535 ffebad_here (0, ffelex_token_where_line (token),
1536 ffelex_token_where_column (token));
1537 ffebad_string (ffesymbol_text (ffedata_symbol_));
1538 ffebad_finish ();
1539 ffedata_reported_error_ = TRUE;
1540 return FALSE;
1543 /* Calculate offset. */
1545 offset = ffedata_offset_ * ffedata_size_ + ffedata_charoffset_;
1547 /* Is offset within range? If not, whine, but don't do anything else. */
1549 if (offset + ffedata_charexpected_ - 1 > ffedata_symbolsize_)
1551 ffebad_start (FFEBAD_DATA_RANGE);
1552 ffest_ffebad_here_current_stmt (0);
1553 ffebad_string (ffesymbol_text (ffedata_symbol_));
1554 ffebad_finish ();
1555 ffedata_reported_error_ = TRUE;
1556 return FALSE;
1559 /* Now calculate offset for aggregate area. */
1561 ffetarget_aggregate_info (&ign_bt, &ign_kt, &units, ffedata_basictype_,
1562 ffedata_kindtype_); /* Find out unit size of
1563 source datum. */
1564 assert (units % ffedata_storage_units_ == 0);
1565 units_expected = ffedata_charexpected_ * units / ffedata_storage_units_;
1566 offset *= units / ffedata_storage_units_;
1567 offset += (ffestorag_offset (ffesymbol_storage (ffedata_symbol_))
1568 - ffestorag_offset (ffedata_storage_))
1569 / ffedata_storage_units_;
1571 assert (offset + units_expected - 1 <= ffedata_storage_size_);
1573 /* Does an accretion array exist? If not, create it. */
1575 if (value != NULL)
1577 if (ffestorag_accretion (ffedata_storage_) == NULL)
1579 #if FFEDATA_sizeTOO_BIG_INIT_ != 0
1580 if (ffedata_storage_size_ >= FFEDATA_sizeTOO_BIG_INIT_)
1582 char bignum[40];
1584 sprintf (&bignum[0], "%ld", (long) ffedata_storage_size_);
1585 ffebad_start (FFEBAD_TOO_BIG_INIT);
1586 ffebad_here (0, ffelex_token_where_line (token),
1587 ffelex_token_where_column (token));
1588 ffebad_string (ffesymbol_text (ffedata_symbol_));
1589 ffebad_string (bignum);
1590 ffebad_finish ();
1592 #endif
1593 array = ffebld_constantarray_new
1594 (ffedata_storage_bt_, ffedata_storage_kt_,
1595 ffedata_storage_size_);
1596 accter = ffebld_new_accter (array,
1597 ffebit_new (ffe_pool_program_unit (),
1598 ffedata_storage_size_));
1599 ffebld_set_info (accter, ffeinfo_new
1600 (ffedata_storage_bt_,
1601 ffedata_storage_kt_,
1603 FFEINFO_kindENTITY,
1604 FFEINFO_whereCONSTANT,
1605 (ffedata_basictype_
1606 == FFEINFO_basictypeCHARACTER)
1607 ? 1 : FFETARGET_charactersizeNONE));
1608 ffestorag_set_accretion (ffedata_storage_, accter);
1609 ffestorag_set_accretes (ffedata_storage_, ffedata_storage_size_);
1611 else
1613 accter = ffestorag_accretion (ffedata_storage_);
1614 assert (ffedata_storage_size_ == (ffetargetOffset) ffebld_accter_size (accter));
1615 array = ffebld_accter (accter);
1618 /* Put value in accretion array at desired offset. */
1620 fn = ffetarget_aggregate_ptr_memcpy
1621 (ffedata_storage_bt_, ffedata_storage_kt_,
1622 ffedata_basictype_, ffedata_kindtype_);
1623 ffebld_constantarray_prepare
1624 (&ptr1, &ptr2, &size, array, ffedata_storage_bt_,
1625 ffedata_storage_kt_, offset,
1626 ffebld_constant_ptr_to_union (ffebld_conter (value)),
1627 ffedata_basictype_, ffedata_kindtype_);
1628 (*fn) (ptr1, ptr2, size); /* Does the appropriate memcpy-like
1629 operation. */
1630 ffebit_count (ffebld_accter_bits (accter),
1631 offset, FALSE, units_expected,
1632 &actual); /* How many FALSE? */
1633 if (units_expected != (ffetargetOffset) actual)
1635 ffebad_start (FFEBAD_DATA_MULTIPLE);
1636 ffebad_here (0, ffelex_token_where_line (token),
1637 ffelex_token_where_column (token));
1638 ffebad_string (ffesymbol_text (ffedata_symbol_));
1639 ffebad_finish ();
1641 ffestorag_set_accretes (ffedata_storage_,
1642 ffestorag_accretes (ffedata_storage_)
1643 - actual); /* Decrement # of values
1644 actually accreted. */
1645 ffebit_set (ffebld_accter_bits (accter), offset,
1646 1, units_expected);
1648 /* If done accreting for this storage area, establish as
1649 initialized. */
1651 if (ffestorag_accretes (ffedata_storage_) == 0)
1653 ffestorag_set_init (ffedata_storage_, accter);
1654 ffestorag_set_accretion (ffedata_storage_, NULL);
1655 ffebit_kill (ffebld_accter_bits
1656 (ffestorag_init (ffedata_storage_)));
1657 ffebld_set_op (ffestorag_init (ffedata_storage_),
1658 FFEBLD_opARRTER);
1659 ffebld_set_arrter
1660 (ffestorag_init (ffedata_storage_),
1661 ffebld_accter (ffestorag_init (ffedata_storage_)));
1662 ffebld_arrter_set_size (ffestorag_init (ffedata_storage_),
1663 ffedata_storage_size_);
1664 ffebld_arrter_set_pad (ffestorag_init (ffedata_storage_),
1666 ffecom_notify_init_storage (ffedata_storage_);
1670 /* If still accreting, adjust specs accordingly and return. */
1672 if (++ffedata_number_ < ffedata_expected_)
1674 ++ffedata_offset_;
1675 return TRUE;
1678 return ffedata_advance_ ();
1681 /* Figure out where the value goes -- in an accretion array or directly
1682 into the final initial-value slot for the symbol. */
1684 if ((ffedata_number_ != 0)
1685 || (ffedata_arraysize_ > 1)
1686 || (ffedata_charnumber_ != 0)
1687 || (ffedata_size_ > ffedata_charexpected_))
1688 { /* Accrete this value. */
1689 ffetargetOffset offset;
1690 ffebitCount actual;
1691 ffebldConstantArray array;
1692 ffebld accter = NULL;
1694 /* Calculate offset. */
1696 offset = ffedata_offset_ * ffedata_size_ + ffedata_charoffset_;
1698 /* Is offset within range? If not, whine, but don't do anything else. */
1700 if (offset + ffedata_charexpected_ - 1 > ffedata_symbolsize_)
1702 ffebad_start (FFEBAD_DATA_RANGE);
1703 ffest_ffebad_here_current_stmt (0);
1704 ffebad_string (ffesymbol_text (ffedata_symbol_));
1705 ffebad_finish ();
1706 ffedata_reported_error_ = TRUE;
1707 return FALSE;
1710 /* Does an accretion array exist? If not, create it. */
1712 if (value != NULL)
1714 if (ffesymbol_accretion (ffedata_symbol_) == NULL)
1716 #if FFEDATA_sizeTOO_BIG_INIT_ != 0
1717 if (ffedata_symbolsize_ >= FFEDATA_sizeTOO_BIG_INIT_ )
1719 char bignum[40];
1721 sprintf (&bignum[0], "%ld", (long) ffedata_symbolsize_);
1722 ffebad_start (FFEBAD_TOO_BIG_INIT);
1723 ffebad_here (0, ffelex_token_where_line (token),
1724 ffelex_token_where_column (token));
1725 ffebad_string (ffesymbol_text (ffedata_symbol_));
1726 ffebad_string (bignum);
1727 ffebad_finish ();
1729 #endif
1730 array = ffebld_constantarray_new
1731 (ffedata_basictype_, ffedata_kindtype_,
1732 ffedata_symbolsize_);
1733 accter = ffebld_new_accter (array,
1734 ffebit_new (ffe_pool_program_unit (),
1735 ffedata_symbolsize_));
1736 ffebld_set_info (accter, ffeinfo_new
1737 (ffedata_basictype_,
1738 ffedata_kindtype_,
1740 FFEINFO_kindENTITY,
1741 FFEINFO_whereCONSTANT,
1742 (ffedata_basictype_
1743 == FFEINFO_basictypeCHARACTER)
1744 ? 1 : FFETARGET_charactersizeNONE));
1745 ffesymbol_set_accretion (ffedata_symbol_, accter);
1746 ffesymbol_set_accretes (ffedata_symbol_, ffedata_symbolsize_);
1748 else
1750 accter = ffesymbol_accretion (ffedata_symbol_);
1751 assert (ffedata_symbolsize_
1752 == (ffetargetOffset) ffebld_accter_size (accter));
1753 array = ffebld_accter (accter);
1756 /* Put value in accretion array at desired offset. */
1758 ffebld_constantarray_put
1759 (array, ffedata_basictype_, ffedata_kindtype_,
1760 offset, ffebld_constant_union (ffebld_conter (value)));
1761 ffebit_count (ffebld_accter_bits (accter), offset, FALSE,
1762 ffedata_charexpected_,
1763 &actual); /* How many FALSE? */
1764 if (actual != (unsigned long int) ffedata_charexpected_)
1766 ffebad_start (FFEBAD_DATA_MULTIPLE);
1767 ffebad_here (0, ffelex_token_where_line (token),
1768 ffelex_token_where_column (token));
1769 ffebad_string (ffesymbol_text (ffedata_symbol_));
1770 ffebad_finish ();
1772 ffesymbol_set_accretes (ffedata_symbol_,
1773 ffesymbol_accretes (ffedata_symbol_)
1774 - actual); /* Decrement # of values
1775 actually accreted. */
1776 ffebit_set (ffebld_accter_bits (accter), offset,
1777 1, ffedata_charexpected_);
1778 ffesymbol_signal_unreported (ffedata_symbol_);
1781 /* If still accreting, adjust specs accordingly and return. */
1783 if (++ffedata_number_ < ffedata_expected_)
1785 ++ffedata_offset_;
1786 return TRUE;
1789 /* Else, if done accreting for this symbol, establish as initialized. */
1791 if ((value != NULL)
1792 && (ffesymbol_accretes (ffedata_symbol_) == 0))
1794 ffesymbol_set_init (ffedata_symbol_, accter);
1795 ffesymbol_set_accretion (ffedata_symbol_, NULL);
1796 ffebit_kill (ffebld_accter_bits (ffesymbol_init (ffedata_symbol_)));
1797 ffebld_set_op (ffesymbol_init (ffedata_symbol_), FFEBLD_opARRTER);
1798 ffebld_set_arrter (ffesymbol_init (ffedata_symbol_),
1799 ffebld_accter (ffesymbol_init (ffedata_symbol_)));
1800 ffebld_arrter_set_size (ffesymbol_init (ffedata_symbol_),
1801 ffedata_symbolsize_);
1802 ffebld_arrter_set_pad (ffestorag_init (ffedata_symbol_), 0);
1803 ffecom_notify_init_symbol (ffedata_symbol_);
1806 else if (value != NULL)
1808 /* Simple, direct, one-shot assignment. */
1809 ffesymbol_set_init (ffedata_symbol_, value);
1810 ffecom_notify_init_symbol (ffedata_symbol_);
1813 /* Call on advance function to get next target in list. */
1815 return ffedata_advance_ ();