-
Notifications
You must be signed in to change notification settings - Fork 0
/
proc.c
1834 lines (1596 loc) · 38.3 KB
/
proc.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
/****************************************************************
Copyright 1990, 1994-6, 2000-2001 by AT&T, Lucent Technologies and Bellcore.
Permission to use, copy, modify, and distribute this software
and its documentation for any purpose and without fee is hereby
granted, provided that the above copyright notice appear in all
copies and that both that the copyright notice and this
permission notice and warranty disclaimer appear in supporting
documentation, and that the names of AT&T, Bell Laboratories,
Lucent or Bellcore or any of their entities not be used in
advertising or publicity pertaining to distribution of the
software without specific, written prior permission.
AT&T, Lucent and Bellcore disclaim all warranties with regard to
this software, including all implied warranties of
merchantability and fitness. In no event shall AT&T, Lucent or
Bellcore be liable for any special, indirect or consequential
damages or any damages whatsoever resulting from loss of use,
data or profits, whether in an action of contract, negligence or
other tortious action, arising out of or in connection with the
use or performance of this software.
****************************************************************/
#include "defs.h"
#include "names.h"
#include "output.h"
#include "p1defs.h"
/* round a up to the nearest multiple of b:
a = b * floor ( (a + (b - 1)) / b )*/
#undef roundup
#define roundup(a,b) ( b * ( (a+b-1)/b) )
#define EXNULL (union Expression *)0
static void dobss Argdcl((void));
static void docomleng Argdcl((void));
static void docommon Argdcl((void));
static void doentry Argdcl((struct Entrypoint*));
static void epicode Argdcl((void));
static int nextarg Argdcl((int));
static void retval Argdcl((int));
static char Blank[] = BLANKCOMMON;
static char *postfix[] = { "g", "h", "i",
#ifdef TYQUAD
"j",
#endif
"r", "d", "c", "z", "g", "h", "i" };
chainp new_procs;
int prev_proc, proc_argchanges, proc_protochanges;
void
#ifdef KR_headers
changedtype(q)
Namep q;
#else
changedtype(Namep q)
#endif
{
char buf[200];
int qtype, type1;
register Extsym *e;
Argtypes *at;
if (q->vtypewarned)
return;
q->vtypewarned = 1;
qtype = q->vtype;
e = &extsymtab[q->vardesc.varno];
if (!(at = e->arginfo)) {
if (!e->exused)
return;
}
else if (at->changes & 2 && qtype != TYUNKNOWN && !at->defined)
proc_protochanges++;
type1 = e->extype;
if (type1 == TYUNKNOWN)
return;
if (qtype == TYUNKNOWN)
/* e.g.,
subroutine foo
end
external foo
call goo(foo)
end
*/
return;
sprintf(buf, "%.90s: inconsistent declarations:\n\
here %s%s, previously %s%s.", q->fvarname, ftn_types[qtype],
qtype == TYSUBR ? "" : " function",
ftn_types[type1], type1 == TYSUBR ? "" : " function");
warn(buf);
}
void
#ifdef KR_headers
unamstring(q, s)
register Addrp q;
register char *s;
#else
unamstring(register Addrp q, register char *s)
#endif
{
register int k;
register char *t;
k = strlen(s);
if (k < IDENT_LEN) {
q->uname_tag = UNAM_IDENT;
t = q->user.ident;
}
else {
q->uname_tag = UNAM_CHARP;
q->user.Charp = t = mem(k+1, 0);
}
strcpy(t, s);
}
static void
fix_entry_returns(Void) /* for multiple entry points */
{
Addrp a;
int i;
struct Entrypoint *e;
Namep np;
e = entries = (struct Entrypoint *)revchain((chainp)entries);
allargs = revchain(allargs);
if (!multitype)
return;
/* TYLOGICAL should have been turned into TYLONG or TYSHORT by now */
for(i = TYINT1; i <= TYLOGICAL; i++)
if (a = xretslot[i])
sprintf(a->user.ident, "(*ret_val).%s",
postfix[i-TYINT1]);
do {
np = e->enamep;
switch(np->vtype) {
case TYINT1:
case TYSHORT:
case TYLONG:
#ifdef TYQUAD
case TYQUAD:
#endif
case TYREAL:
case TYDREAL:
case TYCOMPLEX:
case TYDCOMPLEX:
case TYLOGICAL1:
case TYLOGICAL2:
case TYLOGICAL:
np->vstg = STGARG;
}
}
while(e = e->entnextp);
}
static void
#ifdef KR_headers
putentries(outfile)
FILE *outfile;
#else
putentries(FILE *outfile)
#endif
/* put out wrappers for multiple entries */
{
char base[MAXNAMELEN+4];
struct Entrypoint *e;
Namep *A, *Ae, *Ae1, **Alp, *a, **a1, np;
chainp args, lengths;
int i, k, mt, nL, t, type;
extern char *dfltarg[], **dfltproc;
e = entries;
if (!e->enamep) /* only possible with erroneous input */
return;
nL = (nallargs + nallchargs) * sizeof(Namep *);
if (!nL)
nL = 8;
A = (Namep *)ckalloc(nL + nallargs*sizeof(Namep **));
Ae = A + nallargs;
Alp = (Namep **)(Ae1 = Ae + nallchargs);
i = k = 0;
for(a1 = Alp, args = allargs; args; a1++, args = args->nextp) {
np = (Namep)args->datap;
if (np->vtype == TYCHAR && np->vclass != CLPROC)
*a1 = &Ae[i++];
}
mt = multitype;
multitype = 0;
sprintf(base, "%s0_", e->enamep->cvarname);
do {
np = e->enamep;
lengths = length_comp(e, 0);
proctype = type = np->vtype;
if (protofile)
protowrite(protofile, type, np->cvarname, e, lengths);
nice_printf(outfile, "\n%s ", c_type_decl(type, 1));
nice_printf(outfile, "%s", np->cvarname);
if (!Ansi) {
listargs(outfile, e, 0, lengths);
nice_printf(outfile, "\n");
}
list_arg_types(outfile, e, lengths, 0, "\n");
nice_printf(outfile, "{\n");
frchain(&lengths);
next_tab(outfile);
if (mt)
nice_printf(outfile,
"Multitype ret_val;\n%s(%d, &ret_val",
base, k); /*)*/
else if (ISCOMPLEX(type))
nice_printf(outfile, "%s(%d,%s", base, k,
xretslot[type]->user.ident); /*)*/
else if (type == TYCHAR)
nice_printf(outfile,
"%s(%d, ret_val, ret_val_len", base, k); /*)*/
else
nice_printf(outfile, "return %s(%d", base, k); /*)*/
k++;
memset((char *)A, 0, nL);
for(args = e->arglist; args; args = args->nextp) {
np = (Namep)args->datap;
A[np->argno] = np;
if (np->vtype == TYCHAR && np->vclass != CLPROC)
*Alp[np->argno] = np;
}
args = allargs;
for(a = A; a < Ae; a++, args = args->nextp) {
t = ((Namep)args->datap)->vtype;
nice_printf(outfile, ", %s", (np = *a)
? np->cvarname
: ((Namep)args->datap)->vclass == CLPROC
? dfltproc[((Namep)args->datap)->vimpltype
? (Castargs ? TYUNKNOWN : TYSUBR)
: t == TYREAL && forcedouble && !Castargs
? TYDREAL : t]
: dfltarg[((Namep)args->datap)->vtype]);
}
for(; a < Ae1; a++)
if (np = *a)
nice_printf(outfile, ", %s",
new_arg_length(np));
else
nice_printf(outfile, ", (ftnint)0");
nice_printf(outfile, /*(*/ ");\n");
if (mt) {
if (type == TYCOMPLEX)
nice_printf(outfile,
"r_v->r = ret_val.c.r; r_v->i = ret_val.c.i;\n");
else if (type == TYDCOMPLEX)
nice_printf(outfile,
"r_v->r = ret_val.z.r; r_v->i = ret_val.z.i;\n");
else if (type <= TYLOGICAL)
nice_printf(outfile, "return ret_val.%s;\n",
postfix[type-TYINT1]);
}
nice_printf(outfile, "}\n");
prev_tab(outfile);
}
while(e = e->entnextp);
free((char *)A);
}
static void
#ifdef KR_headers
entry_goto(outfile)
FILE *outfile;
#else
entry_goto(FILE *outfile)
#endif
{
struct Entrypoint *e = entries;
int k = 0;
nice_printf(outfile, "switch(n__) {\n");
next_tab(outfile);
while(e = e->entnextp)
nice_printf(outfile, "case %d: goto %s;\n", ++k,
user_label((long)(extsymtab - e->entryname - 1)));
nice_printf(outfile, "}\n\n");
prev_tab(outfile);
}
/* start a new procedure */
void
newproc(Void)
{
if(parstate != OUTSIDE)
{
execerr("missing end statement", CNULL);
endproc();
}
parstate = INSIDE;
procclass = CLMAIN; /* default */
}
static void
zap_changes(Void)
{
register chainp cp;
register Argtypes *at;
/* arrange to get correct count of prototypes that would
change by running f2c again */
if (prev_proc && proc_argchanges)
proc_protochanges++;
prev_proc = proc_argchanges = 0;
for(cp = new_procs; cp; cp = cp->nextp)
if (at = ((Namep)cp->datap)->arginfo)
at->changes &= ~1;
frchain(&new_procs);
}
/* end of procedure. generate variables, epilogs, and prologs */
void
endproc(Void)
{
struct Labelblock *lp;
Extsym *ext;
if(parstate < INDATA)
enddcl();
if(ctlstack >= ctls)
err("DO loop or BLOCK IF not closed");
for(lp = labeltab ; lp < labtabend ; ++lp)
if(lp->stateno!=0 && lp->labdefined==NO)
errstr("missing statement label %s",
convic(lp->stateno) );
/* Save copies of the common variables in extptr -> allextp */
for (ext = extsymtab; ext < nextext; ext++)
if (ext -> extstg == STGCOMMON && ext -> extp) {
extern int usedefsforcommon;
/* Write out the abbreviations for common block reference */
copy_data (ext -> extp);
if (usedefsforcommon) {
wr_abbrevs (c_file, 1, ext -> extp);
ext -> used_here = 1;
}
else
ext -> extp = CHNULL;
}
if (nentry > 1)
fix_entry_returns();
epicode();
donmlist();
dobss();
start_formatting ();
if (nentry > 1)
putentries(c_file);
zap_changes();
procinit(); /* clean up for next procedure */
}
/* End of declaration section of procedure. Allocate storage. */
void
enddcl(Void)
{
register struct Entrypoint *ep;
struct Entrypoint *ep0;
chainp cp;
extern char *err_proc;
static char comblks[] = "common blocks";
err_proc = comblks;
docommon();
/* Now the hash table entries for fields of common blocks have STGCOMMON,
vdcldone, voffset, and varno. And the common blocks themselves have
their full sizes in extleng. */
err_proc = "equivalences";
doequiv();
err_proc = comblks;
docomleng();
/* This implies that entry points in the declarations are buffered in
entries but not written out */
err_proc = "entries";
if (ep = ep0 = (struct Entrypoint *)revchain((chainp)entries)) {
/* entries could be 0 in case of an error */
do doentry(ep);
while(ep = ep->entnextp);
entries = (struct Entrypoint *)revchain((chainp)ep0);
}
err_proc = 0;
parstate = INEXEC;
p1put(P1_PROCODE);
freetemps();
if (earlylabs) {
for(cp = earlylabs = revchain(earlylabs); cp; cp = cp->nextp)
p1_label((Addr)cp->datap);
frchain(&earlylabs);
}
p1_line_number(lineno); /* for files that start with a MAIN program */
/* that starts with an executable statement */
}
/* ROUTINES CALLED WHEN ENCOUNTERING ENTRY POINTS */
/* Main program or Block data */
void
#ifdef KR_headers
startproc(progname, Class)
Extsym *progname;
int Class;
#else
startproc(Extsym *progname, int Class)
#endif
{
register struct Entrypoint *p;
p = ALLOC(Entrypoint);
if(Class == CLMAIN) {
puthead(CNULL, CLMAIN);
if (progname)
strcpy (main_alias, progname->cextname);
} else {
if (progname) {
/* Construct an empty subroutine with this name */
/* in case the name is needed to force loading */
/* of this block-data subprogram: the name can */
/* appear elsewhere in an external statement. */
entrypt(CLPROC, TYSUBR, (ftnint)0, progname, (chainp)0);
endproc();
newproc();
}
puthead(CNULL, CLBLOCK);
}
if(Class == CLMAIN)
newentry( mkname(" MAIN"), 0 )->extinit = 1;
p->entryname = progname;
entries = p;
procclass = Class;
fprintf(diagfile, " %s", (Class==CLMAIN ? "MAIN" : "BLOCK DATA") );
if(progname) {
fprintf(diagfile, " %s", progname->fextname);
procname = progname->cextname;
}
fprintf(diagfile, ":\n");
fflush(diagfile);
}
/* subroutine or function statement */
Extsym *
#ifdef KR_headers
newentry(v, substmsg)
register Namep v;
int substmsg;
#else
newentry(register Namep v, int substmsg)
#endif
{
register Extsym *p;
char buf[128], badname[64];
static int nbad = 0;
static char already[] = "external name already used";
p = mkext(v->fvarname, addunder(v->cvarname));
if(p->extinit || ! ONEOF(p->extstg, M(STGUNKNOWN)|M(STGEXT)) )
{
sprintf(badname, "%s_bad%d", v->fvarname, ++nbad);
if (substmsg) {
sprintf(buf,"%s\n\tsubstituting \"%s\"",
already, badname);
dclerr(buf, v);
}
else
dclerr(already, v);
p = mkext(v->fvarname, badname);
}
v->vstg = STGAUTO;
v->vprocclass = PTHISPROC;
v->vclass = CLPROC;
if (p->extstg == STGEXT)
prev_proc = 1;
else
p->extstg = STGEXT;
p->extinit = YES;
v->vardesc.varno = p - extsymtab;
return(p);
}
void
#ifdef KR_headers
entrypt(Class, type, length, entry, args)
int Class;
int type;
ftnint length;
Extsym *entry;
chainp args;
#else
entrypt(int Class, int type, ftnint length, Extsym *entry, chainp args)
#endif
{
register Namep q;
register struct Entrypoint *p;
if(Class != CLENTRY)
puthead( procname = entry->cextname, Class);
else
fprintf(diagfile, " entry ");
fprintf(diagfile, " %s:\n", entry->fextname);
fflush(diagfile);
q = mkname(entry->fextname);
if (type == TYSUBR)
q->vstg = STGEXT;
type = lengtype(type, length);
if(Class == CLPROC)
{
procclass = CLPROC;
proctype = type;
procleng = type == TYCHAR ? length : 0;
}
p = ALLOC(Entrypoint);
p->entnextp = entries;
entries = p;
p->entryname = entry;
p->arglist = revchain(args);
p->enamep = q;
if(Class == CLENTRY)
{
Class = CLPROC;
if(proctype == TYSUBR)
type = TYSUBR;
}
q->vclass = Class;
q->vprocclass = 0;
settype(q, type, length);
q->vprocclass = PTHISPROC;
/* hold all initial entry points till end of declarations */
if(parstate >= INDATA)
doentry(p);
}
/* generate epilogs */
/* epicode -- write out the proper function return mechanism at the end of
the procedure declaration. Handles multiple return value types, as
well as cooercion into the proper value */
LOCAL void
epicode(Void)
{
extern int lastwasbranch;
if(procclass==CLPROC)
{
if(proctype==TYSUBR)
{
/* Return a zero only when the alternate return mechanism has been
specified in the function header */
if ((substars || Ansi) && lastwasbranch != YES)
p1_subr_ret (ICON(0));
}
else if (!multitype && lastwasbranch != YES)
retval(proctype);
}
else if (procclass == CLMAIN && Ansi && lastwasbranch != YES)
p1_subr_ret (ICON(0));
lastwasbranch = NO;
}
/* generate code to return value of type t */
LOCAL void
#ifdef KR_headers
retval(t)
register int t;
#else
retval(register int t)
#endif
{
register Addrp p;
switch(t)
{
case TYCHAR:
case TYCOMPLEX:
case TYDCOMPLEX:
break;
case TYLOGICAL:
t = tylogical;
case TYINT1:
case TYADDR:
case TYSHORT:
case TYLONG:
#ifdef TYQUAD
case TYQUAD:
#endif
case TYREAL:
case TYDREAL:
case TYLOGICAL1:
case TYLOGICAL2:
p = (Addrp) cpexpr((expptr)retslot);
p->vtype = t;
p1_subr_ret (mkconv (t, fixtype((expptr)p)));
break;
default:
badtype("retval", t);
}
}
/* Do parameter adjustments */
void
#ifdef KR_headers
procode(outfile)
FILE *outfile;
#else
procode(FILE *outfile)
#endif
{
prolog(outfile, allargs);
if (nentry > 1)
entry_goto(outfile);
}
static void
#ifdef KR_headers
bad_dimtype(q) Namep q;
#else
bad_dimtype(Namep q)
#endif
{
errstr("bad dimension type for %.70s", q->fvarname);
}
/* Finish bound computations now that all variables are declared.
* This used to be in setbound(), but under -u the following incurred
* an erroneous error message:
* subroutine foo(x,n)
* real x(n)
* integer n
*/
static void
#ifdef KR_headers
dim_finish(v)
Namep v;
#else
dim_finish(Namep v)
#endif
{
register struct Dimblock *p;
register expptr q;
register int i, nd;
p = v->vdim;
v->vdimfinish = 0;
nd = p->ndim;
doin_setbound = 1;
for(i = 0; i < nd; i++)
if (q = p->dims[i].dimexpr) {
q = p->dims[i].dimexpr = make_int_expr(putx(fixtype(q)));
if (!ONEOF(q->headblock.vtype, MSKINT|MSKREAL))
bad_dimtype(v);
}
if (q = p->basexpr)
p->basexpr = make_int_expr(putx(fixtype(q)));
doin_setbound = 0;
}
static void
#ifdef KR_headers
duparg(q)
Namep q;
#else
duparg(Namep q)
#endif
{ errstr("duplicate argument %.80s", q->fvarname); }
/*
manipulate argument lists (allocate argument slot positions)
* keep track of return types and labels
*/
LOCAL void
#ifdef KR_headers
doentry(ep)
struct Entrypoint *ep;
#else
doentry(struct Entrypoint *ep)
#endif
{
register int type;
register Namep np;
chainp p, p1;
register Namep q;
Addrp rs;
int it, k;
extern char dflttype[26];
Extsym *entryname = ep->entryname;
if (++nentry > 1)
p1_label((long)(extsymtab - entryname - 1));
/* The main program isn't allowed to have parameters, so any given
parameters are ignored */
if(procclass == CLMAIN && !ep->arglist || procclass == CLBLOCK)
return;
/* Entry points in MAIN are an error, but we process them here */
/* to prevent faults elsewhere. */
/* So now we're working with something other than CLMAIN or CLBLOCK.
Determine the type of its return value. */
impldcl( np = mkname(entryname->fextname) );
type = np->vtype;
proc_argchanges = prev_proc && type != entryname->extype;
entryname->extseen = 1;
if(proctype == TYUNKNOWN)
if( (proctype = type) == TYCHAR)
procleng = np->vleng ? np->vleng->constblock.Const.ci
: (ftnint) (-1);
if(proctype == TYCHAR)
{
if(type != TYCHAR)
err("noncharacter entry of character function");
/* Functions returning type char can only have multiple entries if all
entries return the same length */
else if( (np->vleng ? np->vleng->constblock.Const.ci :
(ftnint) (-1)) != procleng)
err("mismatched character entry lengths");
}
else if(type == TYCHAR)
err("character entry of noncharacter function");
else if(type != proctype)
multitype = YES;
if(rtvlabel[type] == 0)
rtvlabel[type] = (int)newlabel();
ep->typelabel = rtvlabel[type];
if(type == TYCHAR)
{
if(chslot < 0)
{
chslot = nextarg(TYADDR);
chlgslot = nextarg(TYLENG);
}
np->vstg = STGARG;
/* Put a new argument in the function, one which will hold the result of
a character function. This will have to be named sometime, probably in
mkarg(). */
if(procleng < 0) {
np->vleng = (expptr) mkarg(TYLENG, chlgslot);
np->vleng->addrblock.uname_tag = UNAM_IDENT;
strcpy (np -> vleng -> addrblock.user.ident,
new_func_length());
}
if (!xretslot[TYCHAR]) {
xretslot[TYCHAR] = rs =
autovar(0, type, ISCONST(np->vleng)
? np->vleng : ICON(0), "");
strcpy(rs->user.ident, "ret_val");
}
}
/* Handle a complex return type -- declare a new parameter (pointer to
a complex value) */
else if( ISCOMPLEX(type) ) {
if (!xretslot[type])
xretslot[type] =
autovar(0, type, EXNULL, " ret_val");
/* the blank is for use in out_addr */
np->vstg = STGARG;
if(cxslot < 0)
cxslot = nextarg(TYADDR);
}
else if (type != TYSUBR) {
if (type == TYUNKNOWN) {
dclerr("untyped function", np);
proctype = type = np->vtype =
dflttype[letter(np->fvarname[0])];
}
if (!xretslot[type])
xretslot[type] = retslot =
autovar(1, type, EXNULL, " ret_val");
/* the blank is for use in out_addr */
np->vstg = STGAUTO;
}
for(p = ep->arglist ; p ; p = p->nextp)
if(! (( q = (Namep) (p->datap) )->vknownarg) ) {
q->vknownarg = 1;
q->vardesc.varno = nextarg(TYADDR);
allargs = mkchain((char *)q, allargs);
q->argno = nallargs++;
}
else if (nentry == 1)
duparg(q);
else for(p1 = ep->arglist ; p1 != p; p1 = p1->nextp)
if ((Namep)p1->datap == q)
duparg(q);
k = 0;
for(p = ep->arglist ; p ; p = p->nextp) {
if(! (( q = (Namep) (p->datap) )->vdcldone) )
{
impldcl(q);
q->vdcldone = YES;
if(q->vtype == TYCHAR)
{
/* If we don't know the length of a char*(*) (i.e. a string), we must add
in this additional length argument. */
++nallchargs;
if (q->vclass == CLPROC)
nallchargs--;
else if (q->vleng == NULL) {
/* character*(*) */
q->vleng = (expptr)
mkarg(TYLENG, nextarg(TYLENG) );
unamstring((Addrp)q->vleng,
new_arg_length(q));
}
}
}
if (q->vdimfinish)
dim_finish(q);
if (q->vtype == TYCHAR && q->vclass != CLPROC)
k++;
}
if (entryname->extype != type)
changedtype(np);
/* save information for checking consistency of arg lists */
it = infertypes;
if (entryname->exproto)
infertypes = 1;
save_argtypes(ep->arglist, &entryname->arginfo, &np->arginfo,
0, np->fvarname, STGEXT, k, np->vtype, 2);
infertypes = it;
}
LOCAL int
#ifdef KR_headers
nextarg(type)
int type;
#else
nextarg(int type)
#endif
{
type = type; /* shut up warning */
return(lastargslot++);
}
LOCAL void
#ifdef KR_headers
dim_check(q)
Namep q;
#else
dim_check(Namep q)
#endif
{
register struct Dimblock *vdim = q->vdim;
register expptr nelt;
if(!(nelt = vdim->nelt) || !ISCONST(nelt))
dclerr("adjustable dimension on non-argument", q);
else if (!ONEOF(nelt->headblock.vtype, MSKINT|MSKREAL))
bad_dimtype(q);
else if (ISINT(nelt->headblock.vtype)
? nelt->constblock.Const.ci <= 0
: nelt->constblock.Const.cd[0] <= 0.)
dclerr("nonpositive dimension", q);
}
LOCAL void
dobss(Void)
{
register struct Hashentry *p;
register Namep q;
int qstg, qclass, qtype;
Extsym *e;
for(p = hashtab ; p<lasthash ; ++p)
if(q = p->varp)
{
qstg = q->vstg;
qtype = q->vtype;
qclass = q->vclass;
if( (qclass==CLUNKNOWN && qstg!=STGARG) ||
(qclass==CLVAR && qstg==STGUNKNOWN) ) {
if (!(q->vis_assigned | q->vimpldovar))
warn1("local variable %s never used",
q->fvarname);
}
else if(qclass==CLVAR && qstg==STGBSS)
{ ; }
/* Give external procedures the proper storage class */
else if(qclass==CLPROC && q->vprocclass==PEXTERNAL
&& qstg!=STGARG) {
e = mkext(q->fvarname,addunder(q->cvarname));
e->extstg = STGEXT;
q->vardesc.varno = e - extsymtab;
if (e->extype != qtype)
changedtype(q);
}
if(qclass==CLVAR) {
if (qstg != STGARG && q->vdim)
dim_check(q);
} /* if qclass == CLVAR */
}
}
void
donmlist(Void)
{
register struct Hashentry *p;
register Namep q;
for(p=hashtab; p<lasthash; ++p)
if( (q = p->varp) && q->vclass==CLNAMELIST)
namelist(q);
}
/* iarrlen -- Returns the size of the array in bytes, or -1 */
ftnint
#ifdef KR_headers
iarrlen(q)
register Namep q;
#else
iarrlen(register Namep q)
#endif
{
ftnint leng;
leng = typesize[q->vtype];
if(leng <= 0)
return(-1);
if(q->vdim)
if( ISICON(q->vdim->nelt) )
leng *= q->vdim->nelt->constblock.Const.ci;
else return(-1);
if(q->vleng)
if( ISICON(q->vleng) )