00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033 #include "proj.h"
00034 #include "stt.h"
00035 #include "bld.h"
00036 #include "expr.h"
00037 #include "info.h"
00038 #include "lex.h"
00039 #include "malloc.h"
00040 #include "sta.h"
00041 #include "stp.h"
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076 void
00077 ffestt_caselist_append (ffesttCaseList list, bool range, ffebld case1,
00078 ffebld case2, ffelexToken t)
00079 {
00080 ffesttCaseList new;
00081
00082 new = (ffesttCaseList) malloc_new_kp (ffesta_scratch_pool,
00083 "FFEST case list", sizeof (*new));
00084 new->next = list->previous->next;
00085 new->previous = list->previous;
00086 new->next->previous = new;
00087 new->previous->next = new;
00088 new->expr1 = case1;
00089 new->expr2 = case2;
00090 new->range = range;
00091 new->t = t;
00092 }
00093
00094
00095
00096
00097
00098
00099
00100
00101 ffesttCaseList
00102 ffestt_caselist_create ()
00103 {
00104 ffesttCaseList new;
00105
00106 new = (ffesttCaseList) malloc_new_kp (ffesta_scratch_pool,
00107 "FFEST case list root",
00108 sizeof (*new));
00109 new->next = new->previous = new;
00110 new->t = NULL;
00111 new->expr1 = NULL;
00112 new->expr2 = NULL;
00113 new->range = FALSE;
00114 return new;
00115 }
00116
00117
00118
00119
00120
00121
00122
00123
00124
00125
00126
00127
00128 void
00129 ffestt_caselist_kill (ffesttCaseList list)
00130 {
00131 ffesttCaseList next;
00132
00133 for (next = list->next; next != list; next = next->next)
00134 {
00135 ffelex_token_kill (next->t);
00136 }
00137 }
00138
00139
00140
00141
00142
00143
00144
00145
00146
00147
00148 void
00149 ffestt_dimlist_append (ffesttDimList list, ffebld lower, ffebld upper,
00150 ffelexToken t)
00151 {
00152 ffesttDimList new;
00153
00154 new = (ffesttDimList) malloc_new_kp (ffesta_scratch_pool,
00155 "FFEST dim list", sizeof (*new));
00156 new->next = list->previous->next;
00157 new->previous = list->previous;
00158 new->next->previous = new;
00159 new->previous->next = new;
00160 new->lower = lower;
00161 new->upper = upper;
00162 new->t = t;
00163 }
00164
00165
00166
00167
00168
00169
00170
00171
00172
00173
00174
00175
00176
00177
00178
00179
00180 ffebld
00181 ffestt_dimlist_as_expr (ffesttDimList list, ffeinfoRank *rank,
00182 ffebld *array_size, ffebld *extents,
00183 bool is_ugly_assumed)
00184 {
00185 ffesttDimList next;
00186 ffebld expr;
00187 ffebld as;
00188 ffebld ex;
00189 ffebld ext;
00190 ffebldListBottom bottom;
00191 ffeinfoRank r;
00192 ffeinfoKindtype nkt;
00193 ffetargetIntegerDefault low;
00194 ffetargetIntegerDefault high;
00195 bool zero = FALSE;
00196 bool any = FALSE;
00197 bool star = FALSE;
00198
00199 assert (list != NULL);
00200
00201 r = 0;
00202 ffebld_init_list (&expr, &bottom);
00203 for (next = list->next; next != list; next = next->next)
00204 {
00205 ++r;
00206 if (((next->lower == NULL)
00207 || (ffebld_op (next->lower) == FFEBLD_opCONTER))
00208 && (ffebld_op (next->upper) == FFEBLD_opCONTER))
00209 {
00210 if (next->lower == NULL)
00211 low = 1;
00212 else
00213 low = ffebld_constant_integerdefault (ffebld_conter (next->lower));
00214 high = ffebld_constant_integerdefault (ffebld_conter (next->upper));
00215 if (low
00216 > high)
00217 zero = TRUE;
00218 if ((next->next == list)
00219 && is_ugly_assumed
00220 && (next->lower == NULL)
00221 && (high == 1)
00222 && (ffebld_conter_orig (next->upper) == NULL))
00223 {
00224 star = TRUE;
00225 ffebld_append_item (&bottom,
00226 ffebld_new_bounds (NULL, ffebld_new_star ()));
00227 continue;
00228 }
00229 }
00230 else if (((next->lower != NULL)
00231 && (ffebld_op (next->lower) == FFEBLD_opANY))
00232 || (ffebld_op (next->upper) == FFEBLD_opANY))
00233 any = TRUE;
00234 else if (ffebld_op (next->upper) == FFEBLD_opSTAR)
00235 star = TRUE;
00236 ffebld_append_item (&bottom,
00237 ffebld_new_bounds (next->lower, next->upper));
00238 }
00239 ffebld_end_list (&bottom);
00240
00241 if (zero)
00242 {
00243 as = ffebld_new_conter (ffebld_constant_new_integerdefault_val (0));
00244 ffebld_set_info (as, ffeinfo_new
00245 (FFEINFO_basictypeINTEGER,
00246 FFEINFO_kindtypeINTEGERDEFAULT,
00247 0,
00248 FFEINFO_kindENTITY,
00249 FFEINFO_whereCONSTANT,
00250 FFETARGET_charactersizeNONE));
00251 ex = NULL;
00252 }
00253 else if (any)
00254 {
00255 as = ffebld_new_any ();
00256 ffebld_set_info (as, ffeinfo_new_any ());
00257 ex = ffebld_copy (as);
00258 }
00259 else if (star)
00260 {
00261 as = ffebld_new_star ();
00262 ex = ffebld_new_star ();
00263 }
00264 else
00265 {
00266 as = NULL;
00267 ffebld_init_list (&ex, &bottom);
00268 for (next = list->next; next != list; next = next->next)
00269 {
00270 if ((next->lower == NULL)
00271 || ((ffebld_op (next->lower) == FFEBLD_opCONTER)
00272 && (ffebld_constant_integerdefault (ffebld_conter
00273 (next->lower)) == 1)))
00274 ext = ffebld_copy (next->upper);
00275 else
00276 {
00277 ext = ffebld_new_subtract (next->upper, next->lower);
00278 nkt
00279 = ffeinfo_kindtype_max (FFEINFO_basictypeINTEGER,
00280 ffeinfo_kindtype (ffebld_info
00281 (next->lower)),
00282 ffeinfo_kindtype (ffebld_info
00283 (next->upper)));
00284 ffebld_set_info (ext,
00285 ffeinfo_new (FFEINFO_basictypeINTEGER,
00286 nkt,
00287 0,
00288 FFEINFO_kindENTITY,
00289 ((ffebld_op (ffebld_left (ext))
00290 == FFEBLD_opCONTER)
00291 && (ffebld_op (ffebld_right
00292 (ext))
00293 == FFEBLD_opCONTER))
00294 ? FFEINFO_whereCONSTANT
00295 : FFEINFO_whereFLEETING,
00296 FFETARGET_charactersizeNONE));
00297 ffebld_set_left (ext,
00298 ffeexpr_convert_expr (ffebld_left (ext),
00299 next->t, ext, next->t,
00300 FFEEXPR_contextLET));
00301 ffebld_set_right (ext,
00302 ffeexpr_convert_expr (ffebld_right (ext),
00303 next->t, ext,
00304 next->t,
00305 FFEEXPR_contextLET));
00306 ext = ffeexpr_collapse_subtract (ext, next->t);
00307
00308 nkt
00309 = ffeinfo_kindtype_max (FFEINFO_basictypeINTEGER,
00310 ffeinfo_kindtype (ffebld_info (ext)),
00311 FFEINFO_kindtypeINTEGERDEFAULT);
00312 ext
00313 = ffebld_new_add (ext,
00314 ffebld_new_conter
00315 (ffebld_constant_new_integerdefault_val
00316 (1)));
00317 ffebld_set_info (ffebld_right (ext), ffeinfo_new
00318 (FFEINFO_basictypeINTEGER,
00319 FFEINFO_kindtypeINTEGERDEFAULT,
00320 0,
00321 FFEINFO_kindENTITY,
00322 FFEINFO_whereCONSTANT,
00323 FFETARGET_charactersizeNONE));
00324 ffebld_set_info (ext,
00325 ffeinfo_new (FFEINFO_basictypeINTEGER,
00326 nkt, 0, FFEINFO_kindENTITY,
00327 (ffebld_op (ffebld_left (ext))
00328 == FFEBLD_opCONTER)
00329 ? FFEINFO_whereCONSTANT
00330 : FFEINFO_whereFLEETING,
00331 FFETARGET_charactersizeNONE));
00332 ffebld_set_left (ext,
00333 ffeexpr_convert_expr (ffebld_left (ext),
00334 next->t, ext,
00335 next->t,
00336 FFEEXPR_contextLET));
00337 ffebld_set_right (ext,
00338 ffeexpr_convert_expr (ffebld_right (ext),
00339 next->t, ext,
00340 next->t,
00341 FFEEXPR_contextLET));
00342 ext = ffeexpr_collapse_add (ext, next->t);
00343 }
00344 ffebld_append_item (&bottom, ext);
00345 if (as == NULL)
00346 as = ext;
00347 else
00348 {
00349 nkt
00350 = ffeinfo_kindtype_max (FFEINFO_basictypeINTEGER,
00351 ffeinfo_kindtype (ffebld_info (as)),
00352 ffeinfo_kindtype (ffebld_info (ext)));
00353 as = ffebld_new_multiply (as, ext);
00354 ffebld_set_info (as,
00355 ffeinfo_new (FFEINFO_basictypeINTEGER,
00356 nkt, 0, FFEINFO_kindENTITY,
00357 ((ffebld_op (ffebld_left (as))
00358 == FFEBLD_opCONTER)
00359 && (ffebld_op (ffebld_right
00360 (as))
00361 == FFEBLD_opCONTER))
00362 ? FFEINFO_whereCONSTANT
00363 : FFEINFO_whereFLEETING,
00364 FFETARGET_charactersizeNONE));
00365 ffebld_set_left (as,
00366 ffeexpr_convert_expr (ffebld_left (as),
00367 next->t, as, next->t,
00368 FFEEXPR_contextLET));
00369 ffebld_set_right (as,
00370 ffeexpr_convert_expr (ffebld_right (as),
00371 next->t, as,
00372 next->t,
00373 FFEEXPR_contextLET));
00374 as = ffeexpr_collapse_multiply (as, next->t);
00375 }
00376 }
00377 ffebld_end_list (&bottom);
00378 as = ffeexpr_convert (as, list->next->t, NULL,
00379 FFEINFO_basictypeINTEGER,
00380 FFEINFO_kindtypeINTEGERDEFAULT, 0,
00381 FFETARGET_charactersizeNONE,
00382 FFEEXPR_contextLET);
00383 }
00384
00385 *rank = r;
00386 *array_size = as;
00387 *extents = ex;
00388 return expr;
00389 }
00390
00391
00392
00393
00394
00395
00396
00397
00398 ffesttDimList
00399 ffestt_dimlist_create ()
00400 {
00401 ffesttDimList new;
00402
00403 new = (ffesttDimList) malloc_new_kp (ffesta_scratch_pool,
00404 "FFEST dim list root", sizeof (*new));
00405 new->next = new->previous = new;
00406 new->t = NULL;
00407 new->lower = NULL;
00408 new->upper = NULL;
00409 return new;
00410 }
00411
00412
00413
00414
00415
00416
00417
00418
00419 void
00420 ffestt_dimlist_kill (ffesttDimList list)
00421 {
00422 ffesttDimList next;
00423
00424 for (next = list->next; next != list; next = next->next)
00425 {
00426 ffelex_token_kill (next->t);
00427 }
00428 }
00429
00430
00431
00432
00433
00434
00435
00436
00437
00438
00439
00440 ffestpDimtype
00441 ffestt_dimlist_type (ffesttDimList list, bool is_ugly_assumed)
00442 {
00443 ffesttDimList next;
00444 ffestpDimtype type;
00445
00446 if (list == NULL)
00447 return FFESTP_dimtypeNONE;
00448
00449 type = FFESTP_dimtypeKNOWN;
00450 for (next = list->next; next != list; next = next->next)
00451 {
00452 bool ugly_assumed = FALSE;
00453
00454 if ((next->next == list)
00455 && is_ugly_assumed
00456 && (next->lower == NULL)
00457 && (next->upper != NULL)
00458 && (ffebld_op (next->upper) == FFEBLD_opCONTER)
00459 && (ffebld_constant_integerdefault (ffebld_conter (next->upper))
00460 == 1)
00461 && (ffebld_conter_orig (next->upper) == NULL))
00462 ugly_assumed = TRUE;
00463
00464 if (next->lower != NULL)
00465 {
00466 if (ffebld_op (next->lower) != FFEBLD_opCONTER)
00467 {
00468 if (type == FFESTP_dimtypeASSUMED)
00469 type = FFESTP_dimtypeADJUSTABLEASSUMED;
00470 else
00471 type = FFESTP_dimtypeADJUSTABLE;
00472 }
00473 }
00474 if (next->upper != NULL)
00475 {
00476 if (ugly_assumed
00477 || (ffebld_op (next->upper) == FFEBLD_opSTAR))
00478 {
00479 if (type == FFESTP_dimtypeADJUSTABLE)
00480 type = FFESTP_dimtypeADJUSTABLEASSUMED;
00481 else
00482 type = FFESTP_dimtypeASSUMED;
00483 }
00484 else if (ffebld_op (next->upper) != FFEBLD_opCONTER)
00485 type = FFESTP_dimtypeADJUSTABLE;
00486 }
00487 }
00488
00489 return type;
00490 }
00491
00492
00493
00494
00495
00496
00497
00498
00499
00500
00501 void
00502 ffestt_exprlist_append (ffesttExprList list, ffebld expr, ffelexToken t)
00503 {
00504 ffesttExprList new;
00505
00506 new = (ffesttExprList) malloc_new_kp (ffesta_scratch_pool,
00507 "FFEST expr list", sizeof (*new));
00508 new->next = list->previous->next;
00509 new->previous = list->previous;
00510 new->next->previous = new;
00511 new->previous->next = new;
00512 new->expr = expr;
00513 new->t = t;
00514 }
00515
00516
00517
00518
00519
00520
00521
00522
00523 ffesttExprList
00524 ffestt_exprlist_create ()
00525 {
00526 ffesttExprList new;
00527
00528 new = (ffesttExprList) malloc_new_kp (ffesta_scratch_pool,
00529 "FFEST expr list root", sizeof (*new));
00530 new->next = new->previous = new;
00531 new->expr = NULL;
00532 new->t = NULL;
00533 return new;
00534 }
00535
00536
00537
00538
00539
00540
00541
00542
00543
00544
00545 void
00546 ffestt_exprlist_drive (ffesttExprList list, void (*fn) (ffebld, ffelexToken))
00547 {
00548 ffesttExprList next;
00549
00550 if (list == NULL)
00551 return;
00552
00553 for (next = list->next; next != list; next = next->next)
00554 {
00555 (*fn) (next->expr, next->t);
00556 }
00557 }
00558
00559
00560
00561
00562
00563
00564
00565
00566
00567
00568
00569
00570 void
00571 ffestt_exprlist_kill (ffesttExprList list)
00572 {
00573 ffesttExprList next;
00574
00575 for (next = list->next; next != list; next = next->next)
00576 {
00577 ffelex_token_kill (next->t);
00578 }
00579 }
00580
00581
00582
00583
00584
00585
00586
00587
00588
00589
00590 ffesttFormatList
00591 ffestt_formatlist_append (ffesttFormatList list)
00592 {
00593 ffesttFormatList new;
00594
00595 new = (ffesttFormatList) malloc_new_kp (ffesta_scratch_pool,
00596 "FFEST format list", sizeof (*new));
00597 new->next = list->previous->next;
00598 new->previous = list->previous;
00599 new->next->previous = new;
00600 new->previous->next = new;
00601 return new;
00602 }
00603
00604
00605
00606
00607
00608
00609
00610
00611 ffesttFormatList
00612 ffestt_formatlist_create (ffesttFormatList parent, ffelexToken t)
00613 {
00614 ffesttFormatList new;
00615
00616 new = (ffesttFormatList) malloc_new_kp (ffesta_scratch_pool,
00617 "FFEST format list root", sizeof (*new));
00618 new->next = new->previous = new;
00619 new->type = FFESTP_formattypeNone;
00620 new->t = t;
00621 new->u.root.parent = parent;
00622 return new;
00623 }
00624
00625
00626
00627
00628
00629
00630
00631
00632 void
00633 ffestt_formatlist_kill (ffesttFormatList list)
00634 {
00635 ffesttFormatList next;
00636
00637
00638
00639 while (list->u.root.parent != NULL)
00640 list = list->u.root.parent->next;
00641
00642
00643
00644 if (list->t != NULL)
00645 ffelex_token_kill (list->t);
00646
00647
00648
00649 for (next = list->next; next != list; next = next->next)
00650 {
00651 ffelex_token_kill (next->t);
00652 switch (next->type)
00653 {
00654 case FFESTP_formattypeI:
00655 case FFESTP_formattypeB:
00656 case FFESTP_formattypeO:
00657 case FFESTP_formattypeZ:
00658 case FFESTP_formattypeF:
00659 case FFESTP_formattypeE:
00660 case FFESTP_formattypeEN:
00661 case FFESTP_formattypeG:
00662 case FFESTP_formattypeL:
00663 case FFESTP_formattypeA:
00664 case FFESTP_formattypeD:
00665 if (next->u.R1005.R1004.t != NULL)
00666 ffelex_token_kill (next->u.R1005.R1004.t);
00667 if (next->u.R1005.R1006.t != NULL)
00668 ffelex_token_kill (next->u.R1005.R1006.t);
00669 if (next->u.R1005.R1007_or_R1008.t != NULL)
00670 ffelex_token_kill (next->u.R1005.R1007_or_R1008.t);
00671 if (next->u.R1005.R1009.t != NULL)
00672 ffelex_token_kill (next->u.R1005.R1009.t);
00673 break;
00674
00675 case FFESTP_formattypeQ:
00676 case FFESTP_formattypeDOLLAR:
00677 case FFESTP_formattypeP:
00678 case FFESTP_formattypeT:
00679 case FFESTP_formattypeTL:
00680 case FFESTP_formattypeTR:
00681 case FFESTP_formattypeX:
00682 case FFESTP_formattypeS:
00683 case FFESTP_formattypeSP:
00684 case FFESTP_formattypeSS:
00685 case FFESTP_formattypeBN:
00686 case FFESTP_formattypeBZ:
00687 case FFESTP_formattypeSLASH:
00688 case FFESTP_formattypeCOLON:
00689 if (next->u.R1010.val.t != NULL)
00690 ffelex_token_kill (next->u.R1010.val.t);
00691 break;
00692
00693 case FFESTP_formattypeR1016:
00694 break;
00695
00696 case FFESTP_formattypeFORMAT:
00697 if (next->u.R1003D.R1004.t != NULL)
00698 ffelex_token_kill (next->u.R1003D.R1004.t);
00699 next->u.R1003D.format->u.root.parent = NULL;
00700 ffestt_formatlist_kill (next->u.R1003D.format);
00701 break;
00702
00703 default:
00704 assert (FALSE);
00705 }
00706 }
00707 }
00708
00709
00710
00711
00712
00713
00714
00715
00716
00717
00718 void
00719 ffestt_implist_append (ffesttImpList list, ffelexToken first, ffelexToken last)
00720 {
00721 ffesttImpList new;
00722
00723 new = (ffesttImpList) malloc_new_kp (ffesta_scratch_pool,
00724 "FFEST token list", sizeof (*new));
00725 new->next = list->previous->next;
00726 new->previous = list->previous;
00727 new->next->previous = new;
00728 new->previous->next = new;
00729 new->first = first;
00730 new->last = last;
00731 }
00732
00733
00734
00735
00736
00737
00738
00739
00740 ffesttImpList
00741 ffestt_implist_create ()
00742 {
00743 ffesttImpList new;
00744
00745 new = (ffesttImpList) malloc_new_kp (ffesta_scratch_pool,
00746 "FFEST token list root",
00747 sizeof (*new));
00748 new->next = new->previous = new;
00749 new->first = NULL;
00750 new->last = NULL;
00751 return new;
00752 }
00753
00754
00755
00756
00757
00758
00759
00760
00761
00762 void
00763 ffestt_implist_drive (ffesttImpList list, void (*fn) (ffelexToken, ffelexToken))
00764 {
00765 ffesttImpList next;
00766
00767 if (list == NULL)
00768 return;
00769
00770 for (next = list->next; next != list; next = next->next)
00771 {
00772 (*fn) (next->first, next->last);
00773 }
00774 }
00775
00776
00777
00778
00779
00780
00781
00782
00783 void
00784 ffestt_implist_kill (ffesttImpList list)
00785 {
00786 ffesttImpList next;
00787
00788 for (next = list->next; next != list; next = next->next)
00789 {
00790 ffelex_token_kill (next->first);
00791 if (next->last != NULL)
00792 ffelex_token_kill (next->last);
00793 }
00794 }
00795
00796
00797
00798
00799
00800
00801
00802
00803
00804
00805 void
00806 ffestt_tokenlist_append (ffesttTokenList tl, ffelexToken t)
00807 {
00808 ffesttTokenItem ti;
00809
00810 ti = (ffesttTokenItem) malloc_new_kp (ffesta_scratch_pool,
00811 "FFEST token item", sizeof (*ti));
00812 ti->next = (ffesttTokenItem) &tl->first;
00813 ti->previous = tl->last;
00814 ti->next->previous = ti;
00815 ti->previous->next = ti;
00816 ti->t = t;
00817 ++tl->count;
00818 }
00819
00820
00821
00822
00823
00824
00825
00826
00827 ffesttTokenList
00828 ffestt_tokenlist_create ()
00829 {
00830 ffesttTokenList tl;
00831
00832 tl = (ffesttTokenList) malloc_new_kp (ffesta_scratch_pool,
00833 "FFEST token list", sizeof (*tl));
00834 tl->first = tl->last = (ffesttTokenItem) &tl->first;
00835 tl->count = 0;
00836 return tl;
00837 }
00838
00839
00840
00841
00842
00843
00844
00845
00846
00847 void
00848 ffestt_tokenlist_drive (ffesttTokenList tl, void (*fn) (ffelexToken))
00849 {
00850 ffesttTokenItem ti;
00851
00852 if (tl == NULL)
00853 return;
00854
00855 for (ti = tl->first; ti != (ffesttTokenItem) &tl->first; ti = ti->next)
00856 {
00857 (*fn) (ti->t);
00858 }
00859 }
00860
00861
00862
00863
00864
00865
00866
00867
00868
00869 ffelexHandler
00870 ffestt_tokenlist_handle (ffesttTokenList tl, ffelexHandler handler)
00871 {
00872 ffesttTokenItem ti;
00873
00874 for (ti = tl->first; ti != (ffesttTokenItem) &tl->first; ti = ti->next)
00875 handler = (ffelexHandler) (*handler) (ti->t);
00876
00877 return (ffelexHandler) handler;
00878 }
00879
00880
00881
00882
00883
00884
00885
00886
00887
00888
00889
00890
00891 void
00892 ffestt_tokenlist_kill (ffesttTokenList tl)
00893 {
00894 ffesttTokenItem ti;
00895
00896 for (ti = tl->first; ti != (ffesttTokenItem) &tl->first; ti = ti->next)
00897 {
00898 ffelex_token_kill (ti->t);
00899 }
00900 }