File: symtab.h

package info (click to toggle)
ftnchek 3.1.2-2
  • links: PTS
  • area: main
  • in suites: woody
  • size: 6,436 kB
  • ctags: 5,393
  • sloc: ansic: 24,609; fortran: 5,565; yacc: 3,682; sh: 2,518; makefile: 772; lisp: 264; f90: 94; perl: 76
file content (1000 lines) | stat: -rw-r--r-- 29,969 bytes parent folder | download
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
/* $Id: symtab.h,v 1.36 2001/11/03 00:50:53 moniot Exp $

	Shared declarations for symbol-table routines.  Note: uses
	declarations in ftnchek.h.

Copyright (c) 1999 by Robert K. Moniot.

Permission is hereby granted, free of charge, to any person obtaining a
copy of this software and associated documentation files (the "Software"),
to deal in the Software without restriction, including without limitation
the rights to use, copy, modify, merge, publish, distribute, sublicense,
and/or sell copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
ROBERT K. MONIOT OR FORDHAM UNIVERSITY BE LIABLE FOR ANY CLAIM, DAMAGES OR
OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.

Except as contained in this notice, the name of ftnchek shall not be used
in advertising or otherwise to promote the sale, use or other dealings in
this Software without prior written authorization from the author.


*/

#define SYMTAB_H		/* for intrins.h */

#ifdef SYMTAB			/* "home" for variables is symtab.c */
#define SYM_SHARED
#else
#define SYM_SHARED extern
#endif

#ifdef DYNAMIC_TABLES
#ifdef __TURBOC__	/* Turbo C has only one free() */
#define cfree free
#endif
#endif

				/* Statement sequence info for fortran.y
				   and to give hints to forlex.c */
#define SEQ_HEADER   1
#define SEQ_IMPLICIT 2
#define SEQ_SPECIF   3
#define SEQ_STMT_FUN 4
#define SEQ_EXEC     5
#define SEQ_END      6

				/* Separate sequence defs to allow checking
				   f90 sequence requirements. */
#define F90_SEQ_HEADER		1
#define F90_SEQ_USE		2
#define F90_SEQ_IMPLICIT_NONE	3
#define F90_SEQ_IMPLICIT	4
#define F90_SEQ_SPECIF		5
#define F90_SEQ_EXEC		6
#define F90_SEQ_CONTAINS	7
#define F90_SEQ_INTERNAL	8
#define F90_SEQ_END		9

		/* Definitions of symbol table information */

/*	Token subclasses (classes are in tokdefs.h)
 */

#define relop_EQ	0
#define relop_NE	1
#define relop_LE	2
#define relop_LT	3
#define relop_GE	4
#define relop_GT	5



	/* Storage Class types for variables, consts, and externals */
#define class_VAR 0
#define class_SUBPROGRAM 1
#define class_COMMON_BLOCK 2
#define class_STMT_FUNCTION 3
#define class_LABEL 4
#define class_NAMELIST 5


	/* Data types for variables, consts, and externals */
	/* N.B. 0 thru 7 are wired into lookup tables in exprtype.c */
#define type_UNDECL 0
#define type_ERROR 0		/* for result of erroneous operation */
#define type_INTEGER 1
#define type_REAL 2
#define type_DP 3
#define type_COMPLEX 4
#define type_DCOMPLEX 5
#define type_LOGICAL 6
#define type_STRING 7
#define type_HOLLERITH 8
#define type_GENERIC 9
#define type_SUBROUTINE 10
#define type_COMMON_BLOCK 11
#define type_PROGRAM 12
#define type_BLOCK_DATA 13
#define type_LABEL 14
#define type_NAMELIST 15

#define size_DEFAULT	(0L)	/* code for standard numeric sizes */
#define size_ADJUSTABLE	(-1L)	/* codes for special char string lengths */
#define size_UNKNOWN	(-2L)

			/* Defns for support of quad precision.  It is
			   implemented as REAL*4n, not a genuine type of
			   its own, since no QUAD type declaration exists.
			   Here n = BpW or whatever wordsize is set at runtime.
			 */
#define type_QUAD type_REAL
#define size_QUAD (4*type_size[type_REAL])
#define type_CQUAD type_COMPLEX
#define size_CQUAD (8*type_size[type_REAL])

				/* test for types usable in exprs */
#define is_computational_type(t) ((unsigned)(t) <= (unsigned)type_HOLLERITH)
				/* test for numeric types */
#define is_numeric_type(t) ((unsigned)(t) <= (unsigned)type_DCOMPLEX)
				/* test for arith, char, or logical type */
#define is_const_type(t) (((unsigned)(t)>(unsigned)0) && ((unsigned)(t)<=(unsigned)type_STRING))
				/* test for numeric or logical type */
#define is_num_log_type(t) ((unsigned)(t) <= type_LOGICAL)
				/* test for real/d.p./complex/d.complx type */
#define is_float_type(t) ((unsigned)(t)>=type_REAL && (unsigned)(t)<=type_DCOMPLEX)

	/* Type categories equate DoubleP to Real, Double Complex
	   to Complex, and Hollerith to Int to simplify expression
	   type propagation and argument checking.  Computational
	   types only, except that since subroutine can be passed
	   as an argument, table goes up that high.  */
SYM_SHARED
unsigned char type_category[]
#ifdef SYMTAB
={	type_UNDECL,
	type_INTEGER,
	type_REAL,
	type_REAL,
	type_COMPLEX,
	type_COMPLEX,
	type_LOGICAL,
	type_STRING,
	type_INTEGER,
	type_GENERIC,
	type_SUBROUTINE,
}
#endif
;
	/* Equivalence types equate Real, DoubleP, Complex and Double
	   Complex, for use in checking mixed equivalence and mixed
	   common, since it is standard and portable to interpret complex
	   as a pair of real values: real part and imag part */
SYM_SHARED
unsigned char equiv_type[]
#ifdef SYMTAB
={	type_UNDECL,
	type_INTEGER,
	type_REAL,
	type_REAL,
	type_REAL,
	type_REAL,
	type_LOGICAL,
	type_STRING,
	type_INTEGER}
#endif
;

/*
 * statement types referencing labels
 */

#define LAB_NO_TYPE 	   0               /* label never defined */           
#define LAB_SPECIFICATION  1
#define LAB_FORMAT	   2
#define LAB_EXECUTABLE	   3
#define LAB_GOTO	   4
#define LAB_ASSIGN	   5
#define LAB_DO		   6
#define LAB_IO		   7
#define LAB_CALL           8
SYM_SHARED
char *lab_type_name[]
#ifdef SYMTAB
 = {
    "undef",
    "specif",
    "format",
    "exec",
    "goto",
    "assign",
    "do",
    "I/O",
    "arg",
}
#endif
;

typedef unsigned char BYTE;

		/* Array of class and type name translations */
SYM_SHARED
char *class_name[]
#ifdef SYMTAB
 = {
	"",
	"subprog",
	"common",
	"stmt fun",
	"label",
	"namelist",
}
#endif
;
SYM_SHARED
char *type_name[]		/* Type names as used in warnings etc.  */
#ifdef SYMTAB
 = {
	"undf",
	"intg",
	"real",
	"dble",
	"cplx",
	"dcpx",
	"logl",
	"char",
	"holl",
	"genr",
	"subr",
	"comm",
	"prog",
	"data",
	"labl",
	"naml",
}
#endif
;

SYM_SHARED
char *type_table[]		/* Names as used in FORTRAN statements */
#ifdef SYMTAB
 =  {
	"??ERROR??",
	"INTEGER",
	"REAL",
	"DOUBLE PRECISION",
	"COMPLEX",
	"DOUBLE COMPLEX",		/* could be "COMPLEX*16" too */
	"LOGICAL",
	"CHARACTER",
/* The rest do not appear in actual use, here for completeness only */
	"HOLLERITH",
	"GENERIC",
	"SUBROUTINE",
	"COMMON",
	"PROGRAM",
	"BLOCK DATA",
	"LABEL",
	"NAMELIST",
    }
#endif
;


/* Here declare typical sizes of objects of each data type, for use in
checking argument and common block size matchups.  BpW (bytes per word)
is defined in ftnchek.h */


SYM_SHARED
BYTE type_size[]
#ifdef SYMTAB
={
	0, /*undf*/
      BpW, /*intg*/
      BpW, /*real*/
    2*BpW, /*dble*/
    2*BpW, /*cplx*/
    4*BpW, /*dcpx*/
      BpW, /*logl*/
	1, /*char*/
      BpW, /*holl*/
	0, /*genr*/
	0, /*subr*/
	0, /*comm*/
	0, /*prog*/
	0, /*data*/
	0, /*labl*/
	0, /*naml*/
}
#endif
;



		/* implicit and default typing lookup table.  Two extra spots
		   provided to accommodate '$' and '_' too.  The size defns
		   should accommodate EBCDIC as well as ASCII. */
SYM_SHARED
int implicit_type[('Z'-'A'+1)+2],	/* indexed by [char - 'A'] */
    implicit_size[('Z'-'A'+1)+2];
SYM_SHARED
char *implicit_len_text[('Z'-'A'+1)+2];


	/* Declaration of Token data structure.  N.B. do not change without
	   consulting preamble of fortran.y for uses with nonterminals.
	 */

			/* temporary equivs for future separate fields */
				/* these are for array-bounds tokens */
#define TOK_dims tclass
#define TOK_elts tsubclass

#define TOK_start tclass
#define TOK_end  tsubclass


struct tokstruct {
	union {
		long integer;
		DBLVAL dbl;
		char *string;
	} value;		/* Value of constant */
	struct tokstruct
	  *left_token,		/* Left child in expr tree */
	  *next_token;		/* Right child or next in linked list */
	char *src_text;		/* Original text string of token */
	long tclass,tsubclass;	/* Token category and subcategory */
	long size;		/* sizeof(datatype) */
	long TOK_type;		/* Storage class & data type of identifier */
	unsigned TOK_flags:32;	/* Exprtype flags (see defns below) */
	LINENO_t line_num;	/* Line where token occurred */
	COLNO_t col_num;	/* Column where token occurred */
	unsigned size_is_adjustable : 1;
	unsigned size_is_expression : 1;
};

typedef struct tokstruct Token;

#ifdef  YYSTYPE
#undef  YYSTYPE
#endif
#define YYSTYPE Token	/* Type defn for yylval and Yacc stack */



SYM_SHARED
long loc_symtab_top,	/* Next avail spot in local symbol table */
   glob_symtab_top;		/* Ditto global */

SYM_SHARED
unsigned long loc_str_top;	/* Top of local stringspace */

SYM_SHARED
   unsigned long srctextspace_top; /* Top of token src text space */

SYM_SHARED
   unsigned long ptrspace_top;	/* Top of pointer space */

SYM_SHARED
   unsigned long param_info_space_top;	/* Top of parameter info space */

SYM_SHARED
   unsigned long token_space_top,	/* Top of token space */
		 token_head_space_top;	/* Top of TL_head space */

	/* Counts of extra items dynamically allocated, for -resource */
SYM_SHARED
  int extra_locstrspace,
      extra_paraminfospace,
      extra_srctextspace,
      extra_tokheadspace,
      extra_tokspace,
      extra_ptrspace;

SYM_SHARED
  LINENO_t top_file_line_num;

SYM_SHARED
  int global_save;	/* module contains SAVE with no list */

		/* Define names for anonymous things */
#ifdef SYMTAB
char blank_com_name[] = "%BLANK",  /* id for blank common entry in symtab */
     unnamed_prog[]="%MAIN",	  /* id for unnamed program module */
     unnamed_block_data[]="%DAT00";  /* id for unnamed block data module */
int  block_data_number=0;       /* count of multiple anonymous block data */
#else
extern char blank_com_name[],
	    unnamed_prog[],
	    unnamed_block_data[];
extern int block_data_number;
#endif

typedef int LABEL_t;              /* a label (0-99999) */         

#define NO_LABEL ((LABEL_t)-1)    /* label never used/defined */

                /* Symbol table argument list declarations */

typedef union {		/* InfoUnion: misc info about symtab entry */
	     unsigned long array_dim;	/* array size and no. of dims */
	     struct ALHead *arglist;	/* ptr to func/subr argument list */
	     struct CMHead *comlist;    /* ptr to common block list */
	     struct TLHead *toklist;  /* ptr to token list */
	     struct IInfo *intrins_info;/* ptr to intrinsic func info */
	     struct PInfo *param;	/* parameter information field */
} InfoUnion;

typedef struct {	/* ArgListElement: holds subprog argument data */
	char *name;		/* name of dummy arg or text of actual arg */
	InfoUnion info;
	struct gSymtEntry *common_block; /* block it belongs to if any */
	long common_index;	/* index in block */
	long size;
	BYTE type;
	short same_as;	/* index if two actual arguments the same */
	unsigned is_lvalue: 1,
		 set_flag: 1,
		 assigned_flag: 1,
		 used_before_set: 1,
		 array_var: 1,
		 array_element: 1,
		 declared_external: 1,
		 active_do_var: 1;
} ArgListElement;


typedef struct ALHead {	    /* ArgListHeader: head node of argument list */
	long size;
	BYTE type;
	short numargs;
	ArgListElement *arg_array;
	struct gSymtEntry *module;
	char *filename,*topfile;
	LINENO_t line_num,top_line_num;
	unsigned
	     is_defn: 1,
	     is_call: 1,
	     external_decl: 1,	/* EXTERNAL decl, not arg list */
             actual_arg: 1;	/* subprog passed as arg */
	struct ALHead *next;
} ArgListHeader;

		/* Symbol table common block list declarations */

typedef struct {	/* ComListElement: holds common var data */
	char *name;		/* name of common variable */
	unsigned long dimen_info;
	long size;
	BYTE type;
	unsigned		/* copies of flags from symtab */
	  used:1,
	  set:1,
	  used_before_set:1,
	  assigned:1,
	  marked:1;		/* for listing of offenders */
} ComListElement;

typedef struct CMHead {	/* ComListHeader: head node of common var list */
	short numargs;
	LINENO_t line_num,top_line_num;
	ComListElement *com_list_array;
	struct gSymtEntry *module;
	char *filename,*topfile;
	struct CMHead *next;
	unsigned
	  any_used:1,		/* any of its variables accessed */
	  any_set:1,		/* any of its variables set */
	  saved:1;		/* declared in SAVE statement */
} ComListHeader;


typedef struct TLHead {	/* TokenListHeader: head node of token list */
	Token *tokenlist;
	struct TLHead *next;
	char *filename;
	LINENO_t line_num, top_line_num;
	unsigned
	  external_decl:1,
	  actual_arg:1;
} TokenListHeader;


			/* Structure for intrinsic-function info */

	/* Define special num_args values for intrinsics that have
	   variable numbers of arguments. */
#define I_1or2	(-1)		/* 1 or 2 arguments */
#define I_2up	(-2)		/* 2 or more arguments */
#define I_0or1	(-3)		/* 0 or 1 argument */

			/* for intrins_flags field */

	/* Integer-valued intrinsics that are evaluated if args const */
#define I_ABS		0x1
#define I_SIGN		0x2
#define I_DIM		0x3
#define I_MOD		0x4
#define I_MAX		0x5
#define I_MIN		0x6
#define I_ICHAR		0x7
#define I_LEN		0x8
#define I_INDEX		0x9
#define I_EVALUATED	0xf	/* any bit of digit set */

		/* Various properties of intrinsics*/
#define I_F77 		0x00	/* Standard intrinsic (no flag: placeholder) */
#define I_NONF77	0x10	/* Nonstandard */
#define I_MIXED_ARGS	0x20	/* Has mixed arg types */
#define I_NONPURE	0x40	/* Arg need not be set when called */
#define I_C_TO_R	0x80	/* Complex -> real in generic form */
#define I_NOTARG	0x100	/* Not allowed as actual argument */
#define I_SP_R		0x200	/* special for REAL function */
#define I_CHAR		0x400	/* special handling for CHAR function */
#define I_QARG		0x800	/* Arg type is R*16 or X*32 */
#define I_QUAD		0x1000	/* Result type is R*16 or X*32 */
#define I_EXTRA		0x2000	/* commonly found extra intrinsics */
#define I_VMS		0x4000	/* VMS systems only */
#define I_UNIX		0x8000	/* Unix systems only */
#define I_NONF90	0x10000	/* Not in F90 standard */

				/* Define flag type big enough for 17 bits */
#if (SIZEOF_SHORT > 2)
typedef unsigned short intrins_flags_t;
#else
#if (SIZEOF_INT > 2)
typedef unsigned int intrins_flags_t;
#else
#if (SIZEOF_LONG > 2)
typedef unsigned long intrins_flags_t;
#endif
#endif
#endif
typedef struct IInfo{
	char *name;
	short num_args,
	      arg_type,
	      result_type;
	intrins_flags_t
	      intrins_flags;	/* nonstandard,  mixed arg types */
} IntrinsInfo;

			/* Structure for parameter info */
typedef struct PInfo{
	char *src_text;		/* source text of parameter value */
	union {
	  long integer;		/* integer value */
	  DBLVAL dbl;		/* float value */
	  char *string;		/* character string value */
	} value;
	int seq_num;		/* position in parameter definitions */
} ParamInfo;
	

			/* Structure for call-tree child list */
typedef struct childlist {
  struct gSymtEntry *child;	/* Pointer to child's symtab entry */
  struct childlist *next;/* Pointer to next child on list */
} ChildList;

		/*  Identifier symbol table declaration */


typedef struct lSymtEntry{
	char *name;             /* Identifier name in stringspace */
	InfoUnion info;
	union{
	  char *text;		/* Source text string */
	  char **textvec;	/* List of source text strings */
	  TokenListHeader *toklist; /* for namelist & common block makedecls */
	} src;
	struct lSymtEntry *equiv_link;	/* Link for equivalence lists */
		/* common_block is a ptr to block if this is a common
		   variable, and common_index is its position (starting
		   from 1).  For block, common_index is the count of
		   variables in it. */
	struct gSymtEntry *common_block;
	long common_index;
	long size;		/* Size of object in bytes */
		/* Object can be referenced in an include file. Next fields
		   are line numbers within file where object is referred
		   to, then come indexes into include-file list.  */
	LINENO_t line_declared, line_set, line_used;
	short file_declared, file_set, file_used;
	BYTE  type;		/* Type & storage class: see macros below */
			/* Flags */
	unsigned
	     used_flag: 1,	/* value is accessed (read from variable) */
	     set_flag: 1,	/* variable is set or passed as subr arg */
	     assigned_flag: 1,	/* value is really set (by assignment stmt) */
	     used_before_set: 1,/* set_flag is not set when used_flag is set */
	     is_current_module: 1, /* this symtab entry is the main module */
	     library_module: 1,	/* module was processed in -library mode */
	     active_do_var: 1,	/* variable is an active DO index */
	     array_var: 1,	/* variable is dimensioned */
	     common_var: 1,	/* variable is in common */
	     entry_point: 1,	/* name of an entry point */
	     parameter: 1,	/* name of a parameter */
	     argument: 1,	/* dummy argument */
	     external: 1,	/* function or subr called by this routine */
	     intrinsic: 1,	/* intrinsic function */
	     saved: 1,		/* named in SAVE statement */
	     invoked_as_func: 1, /* usage as f(x) was seen */
	     defined_in_include: 1, /* to suppress some warnings if unused */
	     declared_external: 1, /* explicitly declared external */
	     declared_intrinsic: 1; /* explicitly declared intrinsic */
	     unsigned size_is_adjustable : 1; /* CHARACTER*(*) declaration */
	     unsigned size_is_expression : 1; /* CHARACTER*(expr) declaration */
} Lsymtab;

typedef struct gSymtEntry{	/* Global symbol table element */
	char *name;             /* Identifier name in stringspace */
	InfoUnion info;
	union {
	  struct childlist *child_list; /* List of callees (for module) */
	  struct gSymtEntry *module; /* Module (for interior entry) */
	} link;
	long size;
	BYTE  type;		/* Type & storage class: see macros below */
			/* Flags.  See remarks above */
	unsigned
	     used_flag: 1,
	     set_flag: 1,
	     assigned_flag: 1,
	     used_before_set: 1,
	     library_module: 1,
	     internal_entry: 1,	/* entry point other than at the top */
	     invoked_as_func: 1,
	     visited: 1,	   /* this entry point is in call tree */
	     visited_somewhere: 1, /* some entry point of module is in call tree */
	     defined: 1,	/* is defined somewhere */
	     defined_in_include: 1,
	     declared_external: 1,
			/* The following flags are for project-file use.
			   They get reset when a file is opened and accumulate
			   values as file is read.  */
	     used_this_file: 1,
	     set_this_file: 1,
	     invoked_as_func_this_file: 1,
	     declared_external_this_file: 1;
} Gsymtab;


		/*  Identifier hashtable declaration  */

typedef struct hashEntry {
	char	*name;		/* Identifier name in stringspace */
	Lsymtab	*loc_symtab,	/* Local symtab entry for vars etc. */
		*com_loc_symtab;/* Local symtab entry for common blocks */
	Gsymtab	*glob_symtab,	/* Global symtab entry for vars etc. */
		*com_glob_symtab;/* Global symtab entry for common blocks */
} HashTable;

SYM_SHARED
    int current_module_hash	/* hashtable index of current module name */
#ifdef SYMTAB
 = -1
#endif
;

				/* Struct for include-file list */
typedef struct {
    char *fname;		/* name of include file */
    LINENO_t line;		/* line of topfile where included */
    short footnote;             /* footnote number--for printing
				   labels */
} IncFile;

SYM_SHARED
IncFile* incfile_list
#ifdef SYMTAB
 = (IncFile*)NULL
#endif
;

SYM_SHARED
int num_incfiles		/* number of include-files in list */
#ifdef SYMTAB
 = 0
#endif
;

SYM_SHARED
short inctable_index;		/* index of current include-file in list */

				/* Struct for chunks of string space */
typedef struct STSpace {
  struct STSpace *next;
  char strspace[STRSPACESZ];
} StrSpace;

				/* Struct for providing chunks of space
				   for parameter info. */
typedef struct PISpace {
  struct PISpace *next;
  ParamInfo paraminfospace[PARAMINFOSPACESZ];
} ParamInfoSpace;

				/* Struct for providing chunks of space
				   for token list headers for arg lists etc. */
typedef struct THSpace {
  struct THSpace *next;
  TokenListHeader tokheadspace[TOKHEADSPACESZ];
} TokHeadSpace;


				/* Struct for providing chunks of space
				   for tokens for arg lists etc.  */
typedef struct TSpace {
  struct TSpace *next;
  Token tokenspace[TOKENSPACESZ];
} TokenSpace;

				/* Struct for providing chunks of space
				   for pointers to array & param text */
typedef struct PSpace {
  struct PSpace *next;
  char * ptrspace[PTRSPACESZ];
} PtrSpace;


		/* Macro to zero out symbol table entry */

#define clear_symtab_entry(S) {register unsigned i;\
				 for(i=0;i<sizeof(*S);i++)((char*)S)[i]=0;}


	/* These macros pack and unpack datatype and storage class in type
	   field of symbol table entry. Datatype is least 4 bits. */

#define datatype_of(TYPE) ((unsigned)((TYPE) & 0xF))
#define storage_class_of(TYPE) ((unsigned)((TYPE) >> 4))
#define type_byte(SCLASS,DTYPE) ((unsigned)(((SCLASS)<<4) + (DTYPE)))


	/* This macro is for pattern matching in flag checking */

#define flag_combo(A,B,C) (((A)<<2) | ((B)<<1) | (C))


	/* These macros are for dimensions & sizes of arrays */

#define array_dims(dim_info) ((dim_info)&0xF)
#define array_size(dim_info) ((dim_info)>>4)
#define array_dim_info(dim,size) (((long)(size)<<4)+(dim))



		/* Defns used by expression type propagation mechanisms
		   in fortran.y and exprtype.c  The flags go in token.TOK_flags
		   Make sure size of TOK_flags declared above suffices for
		   largest item in the list below.
		 */

#define make_true(flag,x) ((x) |= ((unsigned)flag))	/* x.flag <-- true   */
#define make_false(flag,x) ((x) &= ~((unsigned)flag))	/* x.flag <-- false  */
#define is_true(flag,x) ((x) & (flag))			/* x.flag == true?   */
#define copy_flag(flag,x,y)  ((x) |= ((y)&((unsigned)flag))) /* x.flag <-- y.flag */

#define ID_EXPR			0x1	/* a variable */
#define LVALUE_EXPR		0x2	/* assignable */
#define CONST_EXPR		0x4	/* compile-time constant per std 6.7*/
#define LIT_CONST		0x8	/* a number or string literal */
#define ARRAY_ID_EXPR		0x10	/* an array or array element */
#define ARRAY_ELEMENT_EXPR	0x20 	/* an array element */
#define INT_QUOTIENT_EXPR	0x40 	/* contains INT/INT */
#define STMT_FUNCTION_EXPR	0x80
#define PARAMETER_EXPR		0x100/* == CONST_EXPR || intrinsic || **real */
#define EVALUATED_EXPR		0x200  /* token.value has value of expr */
#define SET_FLAG		0x400  /* id may be set */
#define ASSIGNED_FLAG		0x800  /* id is set in assignment stmt */
#define USED_BEFORE_SET		0x1000  /* id used beforre set */
#define COMPLEX_FLAG		0x2000	/* remembers complex_const_allowed */
#define CHAR_ID_EXPR		0x4000	/* char var or array elt not substr */
#define DIM_BOUND_EXPR		0x8000	/* no array or func ref (5.1.1.1) */
#define IN_ASSIGN 		0x10000	/* for tracking assgn stmt lhs */
#define COMMA_FLAG		0x20000/* keeps track of extra or missing
				   	  commas in exprlists (obsolete) */
#define NONSTD_USAGE_FLAG	0x40000	/* concentrator for -f77 warnings */
#define NOT_DO_TERMINAL_STMT    0x80000 /* stmt illegal as end of DO loop */
#define DO_VARIABLE		0x100000 /* id is active DO index variable */
#define SYNTAX_ERROR_FLAG	0x200000/* concentrator for syntax errors */

#ifdef DYNAMIC_TABLES		/* tables will be mallocked at runtime */
SYM_SHARED
Lsymtab	*loc_symtab
#ifdef SYMTAB
  =(Lsymtab *)NULL
#endif
;
SYM_SHARED
Gsymtab *glob_symtab
#ifdef SYMTAB
  =(Gsymtab *)NULL
#endif
;
SYM_SHARED
HashTable *hashtab
#ifdef SYMTAB
  =(HashTable *)NULL
#endif
;

#else				/* static tables declared at compile time */
		/* Each major table is housed in a separate file so that
		   on IBM PC architecture with huge memory model
		   each will be in its own 64K segment not all in one. */
#ifndef PLSYMTAB
extern
#endif
Lsymtab	loc_symtab[LOCSYMTABSZ]; /* Local identifiers */
#ifndef PGSYMTAB
extern
#endif
Gsymtab glob_symtab[GLOBSYMTABSZ]; /* Global identifiers: subrs and com blks */
#ifndef EXPRTYPE
extern
#endif
HashTable hashtab[HASHSZ];	/* Hash table for identifier lookup */

#endif/* end static tables */

	/* The following tables start life as statically declared
	   tables, but when add'l space is needed, new structs of same
	   kind will be allocated and linked via next field of struct.
	   Because they are dynamically extended, they are not in
	   the DYNAMIC_TABLES section or its complement above.  Note
	   that as global variables they start off at 0, so next field
	   of each is implicitly initialized to NULL.  */

#ifndef FORLEX
extern
#endif
TokenSpace tokspace;	/* Tokens for arg lists etc */

#ifndef PROJECT
extern
#endif
TokHeadSpace tokheadspace;/* Tokenlist headers */

#ifndef PROJECT
extern
#endif
ParamInfoSpace paraminfospace;/* Parameter info structs */

#ifndef PROJECT
extern
#endif
PtrSpace ptrspace;	/* Space for storing arrays of pointers */

#ifndef SYMTAB
extern
#endif
StrSpace lstrspace;	/* String space for local identifiers */

#ifndef SYMTAB
extern
#endif
StrSpace srctextspace;/* String space for token source text */


		/* Shared routines */


			/* in exprtype.c */
PROTO(void assignment_stmt_type,( Token *term1, Token *equals, Token *term2 ));
PROTO(void binexpr_type,( Token *term1, Token *op, Token *term2, Token
		  *result ));
PROTO(void func_ref_expr,( Token *id, Token *args, Token *result ));
PROTO(void primary_id_expr,( Token *id, Token *primary ));
PROTO(void stmt_fun_arg_cmp,( const Lsymtab *symt, const Token *d_arg, const Token *a_arg ));
PROTO(int substring_size,( Token *id, Token *limits ));
PROTO(void unexpr_type,( Token *term1, Token *op, Token *result ));
PROTO(int intrins_arg_cmp,( IntrinsInfo *defn, Token *t));

			/* in advance.c */
PROTO(int see_double_colon,( void ));

			/* in forlex.c */
PROTO(void implied_id_token,( Token *t, char *s ));
PROTO(int yylex,( void ));

			/* in keywords.c */
PROTO(char *keytok_name,(int tclass));

			/* in fortran.y/fortran.c */
PROTO(void check_seq_header,( Token *t ));

			/* in prlocsym.c */
PROTO(void print_loc_symbols,( void ));

			/* in makedcls.c */
PROTO(void make_declarations,( Lsymtab *sym_list[], char *mod_name ));

			/* in symtab.c */
PROTO(void call_func,( Token *id, Token *arg ));
PROTO(void call_subr,( Token *id, Token *arg ));
PROTO(char * char_expr_value,( Token *t ));
PROTO(void check_loose_ends,( int curmodhash ));
PROTO(void declare_type,( Token *id, int datatype, long size, char *size_text ));
PROTO(void def_arg_name,( Token *id ));
PROTO(void def_array_dim,( Token *id, Token *arg ));
PROTO(void def_com_block,( Token *id, Token *comlist ));
PROTO(void def_com_variable,( Token *id ));
PROTO(int def_curr_module,( Token *id ));
PROTO(void def_do_variable,( Token *id ));
PROTO(void def_equiv_name,( Token *id ));
PROTO(void def_ext_name,( Token *id ));
PROTO(void def_function,( int datatype, long size, char *size_text, Token
		  *id, Token *args ));
PROTO(void def_intrins_name,( Token *id ));
PROTO(void def_namelist,( Token *id, Token *list ));
PROTO(void def_namelist_item,( Token *id ));
PROTO(void def_parameter,( Token *id, Token *val, int noparen ));
PROTO(void def_stmt_function,( Token *id, Token *args ));
PROTO(void do_ASSIGN,( Token *id ));
PROTO(void do_assigned_GOTO,( Token *id ));
PROTO(void do_ENTRY,( Token *id, Token *args, int hashno ));
PROTO(int do_RETURN,( int hashno, Token *keyword ));
PROTO(void equivalence,( Token *id1, Token *id2 ));
PROTO(DBLVAL float_expr_value,( Token *t ));
PROTO(int get_size,( const Lsymtab *symt, int type ));
PROTO(char * get_size_text,( const Lsymtab *symt, int type ));
PROTO(int get_type,( const Lsymtab *symt ));
PROTO(unsigned hash_lookup,( char *s ));
PROTO(Gsymtab* install_global,( int h, int datatype, int storage_class ));
PROTO(int int_expr_value,( Token *t ));
PROTO(char * new_global_string,( char *s ));
PROTO(void free_textvec,( char **p ));
PROTO(char * new_src_text,( const char *s, int len ));
PROTO(char * new_src_text_alloc,( int size ));
PROTO(char * new_tree_text,( Token *t ));
PROTO(char ** new_textvec,( int n ));
PROTO(Token * new_token,( void ));
PROTO(void msg_expr_tree, (const Token *t));
#ifdef DEBUG_EXPRTREES
PROTO(void print_src_text,( Token *t ));
PROTO(void print_expr_tree,( Token *t ));
PROTO(void print_expr_list,( Token *t ));
#endif
PROTO(void process_lists,( int curmodhash ));
PROTO(void ref_array,( Token *id, Token *subscrs ));
PROTO(void ref_namelist,( Token *id, int stmt_class ));
PROTO(void ref_identifier,( Token *id ));
PROTO(void ref_variable,( Token *id ));
PROTO(void save_com_block,( Token *id ));
PROTO(void save_variable,( Token *id ));
PROTO(void set_implicit_type,( int type, long size, char *len_text, int c1, int c2 ));
PROTO(void stmt_function_stmt,( Token *id ));
PROTO(char * token_name,( Token *t ));
PROTO(void undef_do_variable,( int h ));
PROTO(void use_actual_arg,( Token *id ));
PROTO(void use_implied_do_index,( Token *id ));
PROTO(void use_io_keyword,( Token *keyword, Token *value, int stmt_class ));
PROTO(void use_special_open_keywd,( Token *id ));
PROTO(void use_lvalue,( Token *id ));
PROTO(void use_parameter,( Token *id ));
PROTO(void use_variable,( Token *id ));

PROTO(char* typespec, ( int t, int has_size, long size,
			int has_len, long len));
				/* The following size is conservative,
				   to make sure no buffer overruns occur.
				 */
		/* Maximum length of a typespec() result.  */
#define MAX_TYPESPEC (4+4+6*sizeof(long))

				/* in symtab.c (formerly hash.c) */
PROTO(unsigned long hash,( const char *s ));
PROTO(unsigned long rehash,( unsigned long hnum ));


			/* To stop printing errors after limit is reached,
			   unless limit is 0.  Increment error count
			   even if don't print.
			 */
#define CASCADE_LIMIT(ERROR_COUNT) (++(ERROR_COUNT) > error_cascade_limit \
			&& error_cascade_limit > 0)


		/* prototypes of label routines */
void init_labtable(void);
void print_labels(void);
void print_label_refs(void); 
void check_labels(char *mod_name);
void sort_labtable(void);
int def_label(Token *t, int type);
void def_do_label(Token *t);
void ref_label(Token *t, int type);
void update_label_resources(void);