-
Notifications
You must be signed in to change notification settings - Fork 0
/
getfns.c
3401 lines (2713 loc) · 120 KB
/
getfns.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
//***************************************************************************
// NARS2000 -- Getxxx Functions
//***************************************************************************
/***************************************************************************
NARS2000 -- An Experimental APL Interpreter
Copyright (C) 2006-2016 Sudley Place Software
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
***************************************************************************/
#define STRICT
#include <windows.h>
#include "headers.h"
static LPVOID Ptr2Null = NULL;
//***************************************************************************
// $GetPtrTknLongest
//
// Return a ptr to either the tkLongest or stLongest of a token
//***************************************************************************
LPAPLLONGEST GetPtrTknLongest
(LPTOKEN lptkToken) // Ptr to the token
{
// If it's named, ...
if (IsTknNamed (lptkToken))
// Get a ptr to the stLongest value from the SYMENTRY
return &lptkToken->tkData.tkSym->stData.stLongest;
else
// Get a ptr to the tkLongest value from the TOKEN
return &lptkToken->tkData.tkLongest;
} // End GetPtrTknLongest
//***************************************************************************
// $GetPtrGlbDataToken
//
// Return the xxGlbData value from a token
// taking into account whether or the token is named
//***************************************************************************
HGLOBAL *GetPtrGlbDataToken
(LPTOKEN lptkToken) // Ptr to the token
{
// If it's named, ...
if (IsTknNamed (lptkToken))
// Get the xxGlbData value from the SYMENTRY
return &lptkToken->tkData.tkSym->stData.stGlbData;
else
if (!IsTknImmed (lptkToken))
// Get the xxGlbData value from the TOKEN
return &lptkToken->tkData.tkGlbData;
else
return &Ptr2Null;
} // End GetPtrGlbDataToken
//***************************************************************************
// $GetGlbDataToken
//
// Return the xxGlbData value from a token
// taking into account whether or the token is named
//***************************************************************************
HGLOBAL GetGlbDataToken
(LPTOKEN lptkToken) // Ptr to the token
{
return *GetPtrGlbDataToken (lptkToken);
} // End GetGlbDataToken
//***************************************************************************
// $ValidateFirstItemToken
//
// Get and validate the first item from the token as an integer
//***************************************************************************
APLLONGEST ValidateFirstItemToken
(APLSTYPE aplTypeRht, // Right arg storage type
LPTOKEN lpToken, // Ptr to the token
LPUBOOL lpbRet) // Ptr to TRUE iff the result is valid
{
APLLONGEST aplLongestRht; // Right arg longest if immediate
HGLOBAL hGlbSubRht; // Right arg item global memory handle
GetFirstItemToken (lpToken, // Ptr to the token
&aplLongestRht, // Ptr to the longest (may be NULL)
NULL, // ... immediate type (see IMM_TYPES) (may be NULL)
&hGlbSubRht); // ... LPSYMENTRY or HGLOBAL (may be NULL)
// Split cases based upon the right arg storage type
switch (aplTypeRht)
{
case ARRAY_BOOL:
case ARRAY_INT:
case ARRAY_APA:
*lpbRet = TRUE;
break;
case ARRAY_FLOAT:
// Attempt to convert the float to an integer using System []CT
aplLongestRht = FloatToAplint_SCT (*(LPAPLFLOAT) &aplLongestRht, lpbRet);
break;
case ARRAY_RAT:
Assert (GetPtrTypeDir (hGlbSubRht) NE PTRTYPE_HGLOBAL);
// Attempt to convert the RAT to an integer using System []CT
aplLongestRht = mpq_get_sctsx ((LPAPLRAT) hGlbSubRht, lpbRet);
break;
case ARRAY_VFP:
Assert (GetPtrTypeDir (hGlbSubRht) NE PTRTYPE_HGLOBAL);
// Attempt to convert the VFP to an integer using System []CT
aplLongestRht = mpfr_get_sctsx ((LPAPLVFP) hGlbSubRht, lpbRet);
break;
case ARRAY_CHAR:
case ARRAY_HETERO:
case ARRAY_NESTED:
*lpbRet = FALSE;
break;
defstop
*lpbRet = FALSE;
break;
} // End SWITCH
return aplLongestRht;
} // End ValidateFirstItemToken
//***************************************************************************
// $GetNextIntegerToken
//
// Return the next value from a token as an integer.
//***************************************************************************
APLINT GetNextIntegerToken
(LPTOKEN lptkArg, // Ptr to arg token
APLINT uIndex, // Index
APLSTYPE aplTypeArg, // Arg storage type
LPUBOOL lpbRet) // Ptr to TRUE iff the result is valid
{
APLLONGEST aplLongestArg; // Immediate value
HGLOBAL hGlbArg = NULL; // Right arg global memory handle
LPVARARRAY_HEADER lpMemHdrArg = NULL; // Ptr to memory header
LPVOID lpMemArg; // Ptr to right arg global memory
APLINT aplIntegerRes; // The result
APLSTYPE aplTypeItm; // Item storage type
APLFLOAT aplFloatItm; // Immediate item as a float
APLCHAR aplCharItm; // Immediate item as a char
HGLOBAL hGlbItm; // ... HGLOBAL
// Assume it'll be successful
*lpbRet = TRUE;
// If the arg is simple non-hetero, ...
if (IsSimpleNH (aplTypeArg))
// Get the next value from the right operand (index origin)
GetNextValueToken (lptkArg, // Ptr to the token
uIndex, // Index to use
NULL, // Ptr to the integer (or Boolean) (may be NULL)
NULL, // ... float (may be NULL)
NULL, // ... char (may be NULL)
&aplLongestArg, // ... longest (may be NULL)
NULL, // ... LPSYMENTRY or HGLOBAL (may be NULL)
NULL, // ... immediate type (see IMM_TYPES) (may be NULL)
NULL); // ... array type: ARRAY_TYPES (may be NULL)
else
// Otherwise it's global numeric
{
// Get the global ptrs
GetGlbPtrs_LOCK (lptkArg, &hGlbArg, &lpMemHdrArg);
// If it's not an immediate, ...
if (hGlbArg NE NULL)
lpMemArg = VarArrayDataFmBase (lpMemHdrArg);
} // End IF/ELSE
// Split cases based upon the storage type
switch (aplTypeArg)
{
case ARRAY_BOOL:
case ARRAY_INT:
case ARRAY_APA:
aplIntegerRes = aplLongestArg;
break;
case ARRAY_FLOAT:
// Attempt to convert the float to an integer using System []CT
aplIntegerRes = FloatToAplint_SCT (*(LPAPLFLOAT) &aplLongestArg, lpbRet);
break;
case ARRAY_RAT:
aplIntegerRes = GetNextRatIntMem (lpMemArg, uIndex, lpbRet);
break;
case ARRAY_VFP:
aplIntegerRes = GetNextVfpIntMem (lpMemArg, uIndex, lpbRet);
break;
case ARRAY_HETERO:
// Get the next values and type
aplTypeItm = GetNextHetero (lpMemArg, uIndex, &aplIntegerRes, &aplFloatItm, &aplCharItm, &hGlbItm);
// Split cases based upon the storage type
switch (aplTypeItm)
{
case ARRAY_BOOL:
case ARRAY_INT:
goto NORMAL_EXIT;
case ARRAY_FLOAT:
// Attempt to convert the float to an integer using System []CT
aplIntegerRes = FloatToAplint_SCT (aplFloatItm, lpbRet);
goto NORMAL_EXIT;
case ARRAY_RAT:
Assert (GetPtrTypeDir (hGlbItm) NE PTRTYPE_HGLOBAL);
// Attempt to convert the RAT to an integer using System []CT
aplIntegerRes = mpq_get_sctsx ((LPAPLRAT) hGlbItm, lpbRet);
goto NORMAL_EXIT;
case ARRAY_VFP:
Assert (GetPtrTypeDir (hGlbItm) NE PTRTYPE_HGLOBAL);
// Attempt to convert the VFP to an integer using System []CT
aplIntegerRes = mpfr_get_sctsx ((LPAPLVFP) hGlbItm, lpbRet);
goto NORMAL_EXIT;
case ARRAY_CHAR:
case ARRAY_NESTED:
break;
case ARRAY_APA: // Can't happen
case ARRAY_HETERO: // ...
defstop
break;
} // End SWITCH
// Fall through to common error code
case ARRAY_CHAR:
case ARRAY_NESTED:
// Mark as in error
*lpbRet = FALSE;
break;
} // End SWITCH
NORMAL_EXIT:
// If it's not an immediate, ...
if (hGlbArg NE NULL)
{
// We no longer need this ptr
MyGlobalUnlock (hGlbArg); lpMemHdrArg = NULL;
} // End IF
return aplIntegerRes;
} // End GetNextIntegerToken
//***************************************************************************
// $GetNextFloatToken
//
// Return the next value from a token as a float.
//***************************************************************************
APLFLOAT GetNextFloatToken
(LPTOKEN lptkArg, // Ptr to arg token
APLINT uIndex, // Index
APLSTYPE aplTypeArg, // Arg storage type
LPUBOOL lpbRet) // Ptr to TRUE iff the result is valid
{
APLLONGEST aplLongestArg; // Immediate value
HGLOBAL hGlbArg = NULL; // Right arg global memory handle
LPVARARRAY_HEADER lpMemHdrArg = NULL; // Ptr to memory header
LPVOID lpMemArg; // Ptr to right arg global memory
APLINT aplIntegerItm; // Immediate value as integer
APLSTYPE aplTypeItm; // Item storage type
APLFLOAT aplFloatRes; // The result
APLCHAR aplCharItm; // Immediate item as a char
HGLOBAL hGlbItm; // ... HGLOBAL
// Assume it'll be successful
*lpbRet = TRUE;
// If the arg is simple non-hetero, ...
if (IsSimpleNH (aplTypeArg))
// Get the next value from the right operand (index origin)
GetNextValueToken (lptkArg, // Ptr to the token
uIndex, // Index to use
NULL, // Ptr to the integer (or Boolean) (may be NULL)
NULL, // ... float (may be NULL)
NULL, // ... char (may be NULL)
&aplLongestArg, // ... longest (may be NULL)
NULL, // ... LPSYMENTRY or HGLOBAL (may be NULL)
NULL, // ... immediate type (see IMM_TYPES) (may be NULL)
NULL); // ... array type: ARRAY_TYPES (may be NULL)
else
// Otherwise it's global numeric
{
// Get the global ptrs
GetGlbPtrs_LOCK (lptkArg, &hGlbArg, &lpMemHdrArg);
// If it's not an immediate, ...
if (hGlbArg NE NULL)
lpMemArg = VarArrayDataFmBase (lpMemHdrArg);
} // End IF/ELSE
// Split cases based upon the storage type
switch (aplTypeArg)
{
case ARRAY_BOOL:
case ARRAY_INT:
case ARRAY_APA:
aplFloatRes = (APLFLOAT) aplLongestArg;
break;
case ARRAY_FLOAT:
aplFloatRes = *(LPAPLFLOAT) &aplLongestArg;
break;
case ARRAY_RAT:
aplFloatRes = GetNextRatFltMem (lpMemArg, uIndex, lpbRet);
break;
case ARRAY_VFP:
aplFloatRes = GetNextVfpFltMem (lpMemArg, uIndex, lpbRet);
break;
case ARRAY_HETERO:
// Get the next values and type
aplTypeItm = GetNextHetero (lpMemArg, uIndex, &aplIntegerItm, &aplFloatRes, &aplCharItm, &hGlbItm);
// Split cases based upon the storage type
switch (aplTypeItm)
{
case ARRAY_BOOL: // GetNextHetero already converts INT to FLOAT
case ARRAY_INT: // ...
case ARRAY_FLOAT:
goto NORMAL_EXIT;
case ARRAY_RAT:
Assert (GetPtrTypeDir (hGlbItm) NE PTRTYPE_HGLOBAL);
// Attempt to convert the RAT to a float
aplFloatRes = mpq_get_d ((LPAPLRAT) hGlbItm);
goto NORMAL_EXIT;
case ARRAY_VFP:
Assert (GetPtrTypeDir (hGlbItm) NE PTRTYPE_HGLOBAL);
// Attempt to convert the VFP to a float
aplFloatRes = mpfr_get_d ((LPAPLVFP) hGlbItm, MPFR_RNDN);
goto NORMAL_EXIT;
case ARRAY_CHAR:
case ARRAY_NESTED:
break;
case ARRAY_APA: // Can't happen
case ARRAY_HETERO: // ...
defstop
break;
} // End SWITCH
break;
case ARRAY_CHAR:
case ARRAY_NESTED:
// Mark as in error
*lpbRet = FALSE;
break;
} // End SWITCH
NORMAL_EXIT:
// If it's not an immediate, ...
if (hGlbArg NE NULL)
{
// We no longer need this ptr
MyGlobalUnlock (hGlbArg); lpMemHdrArg = NULL;
} // End IF
return aplFloatRes;
} // End GetNextFloatToken
//***************************************************************************
// $GetFirstItemToken
//
// Return the first item from the token
//***************************************************************************
void GetFirstItemToken
(LPTOKEN lpToken, // Ptr to the token
LPAPLLONGEST lpaplLongest, // Ptr to the longest (may be NULL)
LPIMM_TYPES lpImmType, // ... immediate type (see IMM_TYPES) (may be NULL)
LPVOID *lpSymGlb) // ... LPSYMENTRY or HGLOBAL (may be NULL)
{
HGLOBAL hGlbData; // Global memory handle of TKT_VARNAMED or TKT_VARARRAY
// Fill in default values
if (lpSymGlb)
*lpSymGlb = NULL;
// Split cases based upon the token type
switch (lpToken->tkFlags.TknType)
{
case TKT_VARNAMED:
// tkData is an LPSYMENTRY
Assert (GetPtrTypeDir (lpToken->tkData.tkVoid) EQ PTRTYPE_STCONST);
// If it's not immediate, we must look inside the array
if (!lpToken->tkData.tkSym->stFlags.Imm)
{
hGlbData = lpToken->tkData.tkSym->stData.stGlbData;
// stData is a valid HGLOBAL variable array
Assert (IsGlbTypeVarDir_PTB (hGlbData));
break; // Continue below with global case
} // End IF
// Handle the immediate case
GetFirstValueImm (lpToken->tkData.tkSym->stFlags.ImmType,
lpToken->tkData.tkSym->stData.stLongest,
NULL,
NULL,
NULL,
lpaplLongest,
lpImmType,
NULL);
return;
case TKT_VARIMMED:
// Handle the immediate case
GetFirstValueImm (lpToken->tkFlags.ImmType,
lpToken->tkData.tkLongest,
NULL,
NULL,
NULL,
lpaplLongest,
lpImmType,
NULL);
return;
case TKT_VARARRAY:
hGlbData = lpToken->tkData.tkGlbData;
// tkData is a valid HGLOBAL variable array
Assert (IsGlbTypeVarDir_PTB (hGlbData));
break; // Continue below with global case
defstop
return;
} // End SWITCH
// Handle the HGLOBAL case
GetFirstValueGlb (hGlbData, // The global memory handle
NULL, // Ptr to integer (or Boolean) (may be NULL)
NULL, // ... float (may be NULL)
NULL, // ... char (may be NULL)
lpaplLongest, // ... longest (may be NULL)
lpSymGlb, // ... LPSYMENTRY or HGLOBAL (may be NULL)
lpImmType, // ... immediate type (see IMM_TYPES) (may be NULL)
NULL, // ... array type -- ARRAY_TYPES (may be NULL)
FALSE); // TRUE iff we should expand LPSYMENTRY into immediate value
} // End GetFirstItemToken
//***************************************************************************
// $GetNextValueTokenIntoToken
//
// Return the next value from a token as either
// a VARIMMED or VARARRAY.
// The token may be an empty array in which case the
// value of the prototype is returned.
//***************************************************************************
void GetNextValueTokenIntoToken
(LPTOKEN lptkArg, // Ptr to the arg token
APLUINT uIndex, // Index to use
LPTOKEN lptkRes) // Ptr to the result token
{
HGLOBAL hGlbData,
hGlbSub;
IMM_TYPES immType;
// Fill in common values
lptkRes->tkFlags.NoDisplay = FALSE;
lptkRes->tkCharIndex = lptkArg->tkCharIndex;
lptkRes->tkSynObj = soA;
// Split cases based upon the token type
switch (lptkArg->tkFlags.TknType)
{
case TKT_VARNAMED:
// tkData is an LPSYMENTRY
Assert (GetPtrTypeDir (lptkArg->tkData.tkVoid) EQ PTRTYPE_STCONST);
// If it's not immediate, we must look inside the array
if (!lptkArg->tkData.tkSym->stFlags.Imm)
{
hGlbData = lptkArg->tkData.tkSym->stData.stGlbData;
// stData is a valid HGLOBAL variable array
Assert (IsGlbTypeVarDir_PTB (hGlbData));
break; // Continue below with global case
} // End IF
Assert (uIndex EQ 0);
// Handle the immediate case
GetFirstValueImm (lptkArg->tkData.tkSym->stFlags.ImmType,
lptkArg->tkData.tkSym->stData.stLongest,
NULL,
NULL,
NULL,
&lptkRes->tkData.tkLongest,
&immType,
NULL);
// Fill in the result token
lptkRes->tkFlags.TknType = TKT_VARIMMED;
lptkRes->tkFlags.ImmType = immType;
////////////lptkRes->tkFlags.NoDisplay = // Filled in above
////////////lptkRes->tkData.tkLongest = // Filled in above
////////////lptkRes->tkCharIndex = // Filled in above
return;
case TKT_VARIMMED:
Assert (uIndex EQ 0);
// Handle the immediate case
GetFirstValueImm (lptkArg->tkFlags.ImmType,
lptkArg->tkData.tkLongest,
NULL,
NULL,
NULL,
&lptkRes->tkData.tkLongest,
&immType,
NULL);
// Fill in the result token
lptkRes->tkFlags.TknType = TKT_VARIMMED;
lptkRes->tkFlags.ImmType = immType;
////////////lptkRes->tkFlags.NoDisplay = // Filled in above
////////////lptkRes->tkData.tkLongest = // Filled in above
////////////lptkRes->tkCharIndex = // Filled in above
return;
case TKT_VARARRAY:
hGlbData = lptkArg->tkData.tkGlbData;
// tkData is a valid HGLOBAL variable array
Assert (IsGlbTypeVarDir_PTB (hGlbData));
break; // Continue below with global case
defstop
return;
} // End SWITCH
// Handle the HGLOBAL case
GetNextValueGlb (hGlbData, // The global memory handle
uIndex, // Index into item
&hGlbSub, // Ptr to result LPSYMENTRY or HGLOBAL (may be NULL)
&lptkRes->tkData.tkLongest, // Ptr to result immediate value (may be NULL)
&immType); // Ptr to result immediate type (see IMM_TYPES) (may be NULL)
// If the return value is immediate, ...
if (hGlbSub EQ NULL)
{
// Fill in the result token
lptkRes->tkFlags.TknType = TKT_VARIMMED;
lptkRes->tkFlags.ImmType = immType;
////////lptkRes->tkFlags.NoDisplay = // Filled in above
////////lptkRes->tkData.tkLongest = // Filled in above
////////lptkRes->tkCharIndex = // Filled in above
} else
{
// Fill in the result token
lptkRes->tkFlags.TknType = TKT_VARARRAY;
lptkRes->tkFlags.ImmType = immType;
////////lptkRes->tkFlags.NoDisplay = // Filled in above
lptkRes->tkData.tkGlbData = hGlbSub;
////////lptkRes->tkCharIndex = // Filled in above
} // End IF/ELSE
} // End GetNextValueTokenIntoToken
//***************************************************************************
// $GetNextValueTokenIntoNamedVarToken_EM
//
// Return the next value from a token as a VARNAMED.
// The token may be an empty array in which case the
// value of the prototype is returned.
// Note that the nested global case increments the reference count
//***************************************************************************
UBOOL GetNextValueTokenIntoNamedVarToken_EM
(LPTOKEN lptkArg, // Ptr to the arg token
APLUINT uIndex, // Index to use
LPTOKEN lptkRes) // Ptr to the result token
{
HGLOBAL hGlbData, // HGLOBAL of data in the arg
hGlbSub; // ... indexed item in the arg
IMM_TYPES immType; // Immediate type
UBOOL bRet = TRUE; // TRUE iff the result is valid
// tkData is an LPSYMENTRY
Assert (GetPtrTypeDir (lptkRes->tkData.tkVoid) EQ PTRTYPE_STCONST);
// Free the previous value (if any)
FreeResultName (lptkRes);
// Fill in common values
lptkRes->tkFlags.ImmType = IMMTYPE_ERROR;
lptkRes->tkFlags.NoDisplay = FALSE;
lptkRes->tkCharIndex = lptkArg->tkCharIndex;
// Split cases based upon the token type
switch (lptkArg->tkFlags.TknType)
{
case TKT_VARNAMED:
// tkData is an LPSYMENTRY
Assert (GetPtrTypeDir (lptkArg->tkData.tkVoid) EQ PTRTYPE_STCONST);
// If it's not immediate, we must look inside the array
if (!lptkArg->tkData.tkSym->stFlags.Imm)
{
hGlbData = lptkArg->tkData.tkSym->stData.stGlbData;
// stData is a valid HGLOBAL variable array
Assert (IsGlbTypeVarDir_PTB (hGlbData));
break; // Continue below with global case
} // End IF
Assert (uIndex EQ 0);
// Handle the immediate case
GetFirstValueImm (lptkArg->tkData.tkSym->stFlags.ImmType,
lptkArg->tkData.tkSym->stData.stLongest,
NULL,
NULL,
NULL,
&lptkRes->tkData.tkSym->stData.stLongest,
&immType,
NULL);
// Fill in the result token
lptkRes->tkFlags.TknType = TKT_VARNAMED;
////////////lptkRes->tkFlags.ImmType = // Filled in above
////////////lptkRes->tkFlags.NoDisplay = // Filled in above
lptkRes->tkData.tkSym->stFlags.Imm = TRUE;
lptkRes->tkData.tkSym->stFlags.ImmType = immType;
lptkRes->tkData.tkSym->stFlags.Value = TRUE;
lptkRes->tkData.tkSym->stFlags.ObjName = OBJNAME_USR;
lptkRes->tkData.tkSym->stFlags.stNameType = NAMETYPE_VAR;
////////////lptkRes->tkData.tkSym->stData.stLongest = // Filled in above
////////////lptkRes->tkCharIndex = // Filled in above
goto NORMAL_EXIT;
case TKT_VARIMMED:
Assert (uIndex EQ 0);
// Handle the immediate case
GetFirstValueImm (lptkArg->tkFlags.ImmType,
lptkArg->tkData.tkLongest,
NULL,
NULL,
NULL,
&lptkRes->tkData.tkSym->stData.stLongest,
&immType,
NULL);
// Fill in the result token
lptkRes->tkFlags.TknType = TKT_VARNAMED;
////////////lptkRes->tkFlags.ImmType = // Filled in above
////////////lptkRes->tkFlags.NoDisplay = // Filled in above
lptkRes->tkData.tkSym->stFlags.Imm = TRUE;
lptkRes->tkData.tkSym->stFlags.ImmType = immType;
lptkRes->tkData.tkSym->stFlags.Value = TRUE;
lptkRes->tkData.tkSym->stFlags.ObjName = OBJNAME_USR;
lptkRes->tkData.tkSym->stFlags.stNameType = NAMETYPE_VAR;
////////////lptkRes->tkData.tkSym->stData.stLongest = // Filled in above
////////////lptkRes->tkCharIndex = // Filled in above
goto NORMAL_EXIT;
case TKT_VARARRAY:
hGlbData = lptkArg->tkData.tkGlbData;
// tkData is a valid HGLOBAL variable array
Assert (IsGlbTypeVarDir_PTB (hGlbData));
break; // Continue below with global case
defstop
goto NORMAL_EXIT;
} // End SWITCH
// Handle the HGLOBAL case
GetNextValueGlb (hGlbData, // The global memory handle
uIndex, // Index into item
&hGlbSub, // Ptr to result LPSYMENTRY or HGLOBAL (may be NULL)
&lptkRes->tkData.tkSym->stData.stLongest,// Ptr to result immediate value (may be NULL)
&immType); // Ptr to result immediate type (see IMM_TYPES) (may be NULL)
// If the return value is immediate, ...
if (hGlbSub EQ NULL)
{
// Fill in the result token
lptkRes->tkFlags.TknType = TKT_VARNAMED;
////////lptkRes->tkFlags.ImmType = // Filled in above
////////lptkRes->tkFlags.NoDisplay = // Filled in above
lptkRes->tkData.tkSym->stFlags.Imm = TRUE;
lptkRes->tkData.tkSym->stFlags.ImmType = immType;
lptkRes->tkData.tkSym->stFlags.Value = TRUE;
lptkRes->tkData.tkSym->stFlags.ObjName = OBJNAME_USR;
lptkRes->tkData.tkSym->stFlags.stNameType = NAMETYPE_VAR;
////////lptkRes->tkData.tkSym->stData.stLongest = // Filled in above
////////lptkRes->tkCharIndex = // Filled in above
} else
{
// Fill in the result token
lptkRes->tkFlags.TknType = TKT_VARNAMED;
////////lptkRes->tkFlags.ImmType = // Filled in above
////////lptkRes->tkFlags.NoDisplay = // Filled in above
lptkRes->tkData.tkSym->stFlags.Imm = FALSE;
lptkRes->tkData.tkSym->stFlags.ImmType = immType;
lptkRes->tkData.tkSym->stFlags.Value = TRUE;
lptkRes->tkData.tkSym->stFlags.ObjName = OBJNAME_USR;
lptkRes->tkData.tkSym->stFlags.stNameType = NAMETYPE_VAR;
////////lptkRes->tkData.tkSym->stData.stGlbData = // Filled in below
////////lptkRes->tkCharIndex = // Filled in above
// Split cases based upon the immediate type
switch (immType)
{
case IMMTYPE_BOOL:
case IMMTYPE_INT:
case IMMTYPE_FLOAT:
case IMMTYPE_CHAR:
case IMMTYPE_ERROR: // For ARRAY_NESTED
lptkRes->tkData.tkSym->stData.stGlbData = CopySymGlbDir_PTB (hGlbSub);
break;
case IMMTYPE_RAT:
case IMMTYPE_VFP:
// Split cases based upon the ptr type
switch (GetPtrTypeDir (hGlbSub))
{
case PTRTYPE_STCONST:
lptkRes->tkData.tkSym->stData.stGlbData =
MakeGlbEntry_EM (TranslateImmTypeToArrayType (immType), // Entry type
hGlbSub, // Ptr to the value
TRUE, // TRUE iff we should initialize the target first
lptkArg); // Ptr to function token
break;
case PTRTYPE_HGLOBAL:
lptkRes->tkData.tkSym->stData.stGlbData = CopySymGlbDir_PTB (hGlbSub);
break;
defstop
break;
} // End SWITCH
break;
defstop
break;
} // End SWITCH
// Check for error
bRet = (lptkRes->tkData.tkSym->stData.stGlbData NE NULL);
} // End IF/ELSE
NORMAL_EXIT:
return bRet;
} // End GetNextValueTokenIntoNamedVarToken_EM
//***************************************************************************
// $GetNextValueToken
//
// Return the next value from a token as either
// both an integer and a float, or as a character,
// or as an LPSYMENTRY/HGLOBAL. The token may be
// an empty array in which case the value of the
// prototype is returned.
//***************************************************************************
void GetNextValueToken
(LPTOKEN lpToken, // Ptr to the token
APLUINT uIndex, // Index to use
LPAPLINT lpaplInteger, // Ptr to the integer (or Boolean) (may be NULL)
LPAPLFLOAT lpaplFloat, // ... float (may be NULL)
LPAPLCHAR lpaplChar, // ... char (may be NULL)
LPAPLLONGEST lpaplLongest, // ... longest (may be NULL)
LPVOID *lpSymGlb, // ... LPSYMENTRY or HGLOBAL (may be NULL)
LPIMM_TYPES lpImmType, // ... immediate type (see IMM_TYPES) (may be NULL)
LPAPLSTYPE lpArrType) // ... array type: ARRAY_TYPES (may be NULL)
{
HGLOBAL hGlbData,
hGlbSub;
APLLONGEST aplLongest;
IMM_TYPES immType;
// Fill in default values
if (lpSymGlb)
*lpSymGlb = NULL;
// Split cases based upon the token type
switch (lpToken->tkFlags.TknType)
{
case TKT_VARNAMED:
// tkData is an LPSYMENTRY
Assert (GetPtrTypeDir (lpToken->tkData.tkVoid) EQ PTRTYPE_STCONST);
// If it's not immediate, we must look inside the array
if (!lpToken->tkData.tkSym->stFlags.Imm)
{
hGlbData = lpToken->tkData.tkSym->stData.stGlbData;
// stData is a valid HGLOBAL variable array
Assert (IsGlbTypeVarDir_PTB (hGlbData));
break; // Continue below with global case
} // End IF
Assert (uIndex EQ 0);
// Handle the immediate case
GetFirstValueImm (lpToken->tkData.tkSym->stFlags.ImmType,
lpToken->tkData.tkSym->stData.stLongest,
lpaplInteger,
lpaplFloat,
lpaplChar,
lpaplLongest,
lpImmType,
lpArrType);
return;
case TKT_VARIMMED:
Assert (uIndex EQ 0);
// Handle the immediate case
GetFirstValueImm (lpToken->tkFlags.ImmType,
lpToken->tkData.tkLongest,
lpaplInteger,
lpaplFloat,
lpaplChar,
lpaplLongest,
lpImmType,
lpArrType);
return;
case TKT_CHRSTRAND:
case TKT_NUMSTRAND:
case TKT_NUMSCALAR:
case TKT_VARARRAY:
hGlbData = lpToken->tkData.tkGlbData;
// tkData is a valid HGLOBAL variable array
Assert (IsGlbTypeVarDir_PTB (hGlbData));
break; // Continue below with global case
defstop
return;
} // End SWITCH
// Handle the HGLOBAL case
GetNextValueGlb (hGlbData, // The global memory handle
uIndex, // Index into item
&hGlbSub, // Ptr to result LPSYMENTRY or HGLOBAL (may be NULL)
&aplLongest, // Ptr to result immediate value (may be NULL)
&immType); // Ptr to result immediate type (see IMM_TYPES) (may be NULL)
// Fill in various result values
if (lpaplLongest)
*lpaplLongest = aplLongest;
if (lpSymGlb)
*lpSymGlb = hGlbSub;
if (lpImmType)
*lpImmType = immType;
if (lpArrType)
*lpArrType = TranslateImmTypeToArrayType (immType);;
// If the return value is immediate, ...
if (hGlbSub EQ NULL)
{
if (lpaplInteger)
*lpaplInteger = (APLINT) aplLongest;
if (lpaplFloat)
*lpaplFloat = *(LPAPLFLOAT) &aplLongest;
if (lpaplChar)
*lpaplChar = (APLCHAR) aplLongest;
} // End IF
} // End GetNextValueToken
//***************************************************************************
// $GetFirstValueToken
//
// Return the first value from a token as either
// both an integer and a float, or as a character,
// or as an LPSYMENTRY/HGLOBAL. The token may be
// an empty array in which case the value of the
// prototype is returned.
//***************************************************************************
void GetFirstValueToken
(LPTOKEN lpToken, // Ptr to the token
LPAPLINT lpaplInteger, // Ptr to the integer (or Boolean) (may be NULL)
LPAPLFLOAT lpaplFloat, // ... float (may be NULL)
LPAPLCHAR lpaplChar, // ... char (may be NULL)
LPAPLLONGEST lpaplLongest, // ... longest (may be NULL)
LPVOID *lpSymGlb, // ... LPSYMENTRY or HGLOBAL (may be NULL)
LPIMM_TYPES lpImmType, // ... immediate type (see IMM_TYPES) (may be NULL)
LPAPLSTYPE lpArrType) // ... array type: ARRAY_TYPES (may be NULL)
{
HGLOBAL hGlbData;
// Fill in default values
if (lpSymGlb)
*lpSymGlb = NULL;
// Split cases based upon the token type
switch (lpToken->tkFlags.TknType)
{
case TKT_VARNAMED:
// tkData is an LPSYMENTRY
Assert (GetPtrTypeDir (lpToken->tkData.tkVoid) EQ PTRTYPE_STCONST);
// If it's not immediate, we must look inside the array
if (!lpToken->tkData.tkSym->stFlags.Imm)
{
hGlbData = lpToken->tkData.tkSym->stData.stGlbData;
// stData is a valid HGLOBAL variable array
Assert (IsGlbTypeVarDir_PTB (hGlbData));
break; // Continue below with global case
} // End IF
// Handle the immediate case
GetFirstValueImm (lpToken->tkData.tkSym->stFlags.ImmType,
lpToken->tkData.tkSym->stData.stLongest,
lpaplInteger,
lpaplFloat,
lpaplChar,