home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / fchk294s.zip / ftnchek-2.9.4 / symtab.h < prev    next >
C/C++ Source or Header  |  1996-05-26  |  24KB  |  830 lines

  1. /* symtab.h:
  2.  
  3.     Shared declarations for symbol-table routines.  Note: uses
  4.     declarations in ftnchek.h.
  5.  
  6.     Copyright (C) 1993 by Robert K. Moniot.
  7.     This program is free software.  Permission is granted to
  8.     modify it and/or redistribute it, retaining this notice.
  9.     No guarantees accompany this software.
  10.  
  11.  
  12. */
  13.  
  14. #ifdef SYMTAB            /* "home" for variables is symtab.c */
  15. #define SYM_SHARED
  16. #else
  17. #define SYM_SHARED extern
  18. #endif
  19.  
  20. #ifdef DYNAMIC_TABLES
  21. #ifdef __TURBOC__    /* Turbo C has only one free() */
  22. #define cfree free
  23. #endif
  24. #endif
  25.  
  26.                 /* Statement sequence info for fortran.y
  27.                    and to give hints to forlex.c */
  28. #define SEQ_HEADER   1
  29. #define SEQ_IMPLICIT 2
  30. #define SEQ_SPECIF   3
  31. #define SEQ_STMT_FUN 4
  32. #define SEQ_EXEC     5
  33. #define SEQ_END      6
  34.  
  35.         /* Definitions of symbol table information */
  36.  
  37. /*    Token subclasses (classes are in tokdefs.h)
  38.  */
  39.  
  40. #define relop_EQ    0
  41. #define relop_NE    1
  42. #define relop_LE    2
  43. #define relop_LT    3
  44. #define relop_GE    4
  45. #define relop_GT    5
  46.  
  47.  
  48.  
  49.     /* Storage Class types for variables, consts, and externals */
  50. #define class_VAR 0
  51. #define class_SUBPROGRAM 1
  52. #define class_COMMON_BLOCK 2
  53. #define class_STMT_FUNCTION 3
  54. #define class_LABEL 4
  55. #define class_NAMELIST 5
  56.  
  57.  
  58.     /* Data types for variables, consts, and externals */
  59.     /* N.B. 0 thru 7 are wired into lookup tables in exprtype.c */
  60. #define type_UNDECL 0
  61. #define type_ERROR 0        /* for result of erroneous operation */
  62. #define type_INTEGER 1
  63. #define type_REAL 2
  64. #define type_DP 3
  65. #define type_COMPLEX 4
  66. #define type_DCOMPLEX 5
  67. #define type_LOGICAL 6
  68. #define type_STRING 7
  69. #define type_HOLLERITH 8
  70. #define type_GENERIC 9
  71. #define type_SUBROUTINE 10
  72. #define type_COMMON_BLOCK 11
  73. #define type_PROGRAM 12
  74. #define type_BLOCK_DATA 13
  75. #define type_LABEL 14
  76. #define type_NAMELIST 15
  77.  
  78. #define size_DEFAULT    (0L)    /* code for standard numeric sizes */
  79. #define size_ADJUSTABLE    (-1L)    /* codes for special char string lengths */
  80. #define size_UNKNOWN    (-2L)
  81.  
  82.             /* Defns for support of quad precision.  It is
  83.                implemented as REAL*4n, not a genuine type of
  84.                its own, since no QUAD type declaration exists.
  85.                Here n = BpW or whatever wordsize is set at runtime.
  86.              */
  87. #define type_QUAD type_REAL
  88. #define size_QUAD (4*type_size[type_REAL])
  89. #define type_CQUAD type_COMPLEX
  90. #define size_CQUAD (8*type_size[type_REAL])
  91.  
  92.                 /* test for types usable in exprs */
  93. #define is_computational_type(t) ((unsigned)(t) <= (unsigned)type_HOLLERITH)
  94.                 /* test for numeric types */
  95. #define is_numeric_type(t) ((unsigned)(t) <= (unsigned)type_DCOMPLEX)
  96.                 /* test for arith, char, or logical type */
  97. #define is_const_type(t) (((t)>(unsigned)0) && ((t)<=(unsigned)type_STRING))
  98.                 /* test for numeric or logical type */
  99. #define is_num_log_type(t) ((t) <= type_LOGICAL)
  100.                 /* test for real/d.p./complex/d.complx type */
  101. #define is_float_type(t) ((t)>=type_REAL && (t)<=type_DCOMPLEX)
  102.  
  103.     /* Type categories equate DoubleP to Real, Double Complex
  104.        to Complex, and Hollerith to Int to simplify expression
  105.        type propagation and argument checking.  Computational
  106.        types only, except that since subroutine can be passed
  107.        as an argument, table goes up that high.  */
  108. SYM_SHARED
  109. unsigned char type_category[]
  110. #ifdef SYMTAB
  111. ={    type_UNDECL,
  112.     type_INTEGER,
  113.     type_REAL,
  114.     type_REAL,
  115.     type_COMPLEX,
  116.     type_COMPLEX,
  117.     type_LOGICAL,
  118.     type_STRING,
  119.     type_INTEGER,
  120.     type_GENERIC,
  121.     type_SUBROUTINE,
  122. }
  123. #endif
  124. ;
  125.     /* Equivalence types equate Real, DoubleP, Complex and Double
  126.        Complex, for use in checking mixed equivalence and mixed
  127.        common, since it is standard and portable to interpret complex
  128.        as a pair of real values: real part and imag part */
  129. SYM_SHARED
  130. unsigned char equiv_type[]
  131. #ifdef SYMTAB
  132. ={    type_UNDECL,
  133.     type_INTEGER,
  134.     type_REAL,
  135.     type_REAL,
  136.     type_REAL,
  137.     type_REAL,
  138.     type_LOGICAL,
  139.     type_STRING,
  140.     type_INTEGER}
  141. #endif
  142. ;
  143.  
  144. typedef unsigned char BYTE;
  145.  
  146.         /* Array of class and type name translations */
  147. SYM_SHARED
  148. char *class_name[]
  149. #ifdef SYMTAB
  150.  = {
  151.     "",
  152.     "subprog",
  153.     "common",
  154.     "stmt fun",
  155.     "label",
  156.     "namelist",
  157. }
  158. #endif
  159. ;
  160. SYM_SHARED
  161. char *type_name[]        /* Type names as used in warnings etc.  */
  162. #ifdef SYMTAB
  163.  = {
  164.     "undf",
  165.     "intg",
  166.     "real",
  167.     "dble",
  168.     "cplx",
  169.     "dcpx",
  170.     "logl",
  171.     "char",
  172.     "holl",
  173.     "genr",
  174.     "subr",
  175.     "comm",
  176.     "prog",
  177.     "data",
  178.     "labl",
  179.     "naml",
  180. }
  181. #endif
  182. ;
  183.  
  184. SYM_SHARED
  185. char *type_table[]        /* Names as used in FORTRAN statements */
  186. #ifdef SYMTAB
  187.  =  {
  188.     "??ERROR??",
  189.     "INTEGER",
  190.     "REAL",
  191.     "DOUBLE PRECISION",
  192.     "COMPLEX",
  193.     "DOUBLE COMPLEX",        /* could be "COMPLEX*16" too */
  194.     "LOGICAL",
  195.     "CHARACTER",
  196. /* The rest do not appear in actual use, here for completeness only */
  197.     "HOLLERITH",
  198.     "GENERIC",
  199.     "SUBROUTINE",
  200.     "COMMON",
  201.     "PROGRAM",
  202.     "BLOCK DATA",
  203.     "LABEL",
  204.     "NAMELIST",
  205.     }
  206. #endif
  207. ;
  208.  
  209.  
  210. /* Here declare typical sizes of objects of each data type, for use in
  211. checking argument and common block size matchups.  BpW (bytes per word)
  212. is defined in ftnchek.h */
  213.  
  214.  
  215. SYM_SHARED
  216. BYTE type_size[]
  217. #ifdef SYMTAB
  218. ={
  219.     0, /*undf*/
  220.       BpW, /*intg*/
  221.       BpW, /*real*/
  222.     2*BpW, /*dble*/
  223.     2*BpW, /*cplx*/
  224.     4*BpW, /*dcpx*/
  225.       BpW, /*logl*/
  226.     1, /*char*/
  227.       BpW, /*holl*/
  228.     0, /*genr*/
  229.     0, /*subr*/
  230.     0, /*comm*/
  231.     0, /*prog*/
  232.     0, /*data*/
  233.     0, /*labl*/
  234.     0, /*naml*/
  235. }
  236. #endif
  237. ;
  238.  
  239.  
  240.  
  241.         /* implicit and default typing lookup table.  Two extra spots
  242.            provided to accommodate '$' and '_' too.  The size defns
  243.            should accommodate EBCDIC as well as ASCII. */
  244. SYM_SHARED
  245. int implicit_type[('Z'-'A'+1)+2],    /* indexed by [char - 'A'] */
  246.     implicit_size[('Z'-'A'+1)+2];
  247. SYM_SHARED
  248. char *implicit_len_text[('Z'-'A'+1)+2];
  249.  
  250.  
  251.     /* Declaration of Token data structure.  N.B. do not change without
  252.        consulting preamble of fortran.y for uses with nonterminals.
  253.      */
  254.             /* temporary equivs for future separate fields */
  255. #ifndef TOKEN_TYPE_SEPARATE /* define this to unequivalence type==class */
  256. #define TOK_type class
  257. #endif
  258. #ifndef TOKEN_FLAGS_SEPARATE /* define this to unequivalence flags==subclass */
  259. #define TOK_flags subclass
  260. #endif
  261.                 /* these are for array-bounds tokens */
  262. #define TOK_dims TOK_type
  263. #define TOK_elts TOK_flags
  264.  
  265. #define TOK_start TOK_type
  266. #define TOK_end  TOK_flags
  267.  
  268.  
  269. struct tokstruct {
  270.     union {
  271.         long integer;
  272.         DBLVAL dbl;
  273.         char *string;
  274.     } value;
  275.     struct tokstruct
  276.       *left_token,        /* Left child in expr tree */
  277.       *next_token;        /* Right child or next in linked list */
  278.     char *src_text;        /* Original text string of token */
  279.     long size;
  280. #ifndef TOK_type
  281.     long TOK_type;
  282. #endif
  283. #ifndef TOK_flags
  284.     unsigned long TOK_flags;
  285. #endif
  286.     long class,subclass;
  287.     unsigned line_num;    /* Line and column where token occurred */
  288.     unsigned col_num : 8;
  289.     unsigned size_is_adjustable : 1;
  290.     unsigned size_is_expression : 1;
  291. };
  292.  
  293. typedef struct tokstruct Token;
  294.  
  295. #undef  YYSTYPE
  296. #define YYSTYPE Token    /* Type defn for yylval and Yacc stack */
  297.  
  298.  
  299.  
  300. SYM_SHARED
  301. unsigned long loc_symtab_top,    /* Next avail spot in local symbol table */
  302.    glob_symtab_top;        /* Ditto global */
  303.  
  304. SYM_SHARED
  305. unsigned long loc_str_top;    /* Top of local stringspace */
  306.  
  307. SYM_SHARED
  308.    unsigned long srctextspace_top; /* Top of token src text space */
  309.  
  310. SYM_SHARED
  311.    unsigned long ptrspace_top;    /* Top of pointer space */
  312.  
  313. SYM_SHARED
  314.    unsigned long param_info_space_top;    /* Top of parameter info space */
  315.  
  316. SYM_SHARED
  317.    unsigned long token_space_top,    /* Top of token space */
  318.          token_head_space_top;    /* Top of TL_head space */
  319.  
  320.     /* Counts of extra items dynamically allocated, for -resource */
  321. SYM_SHARED
  322.   int extra_locstrspace,
  323.       extra_paraminfospace,
  324.       extra_srctextspace,
  325.       extra_tokheadspace,
  326.       extra_tokspace,
  327.       extra_ptrspace;
  328.  
  329. SYM_SHARED
  330.   unsigned top_file_line_num;
  331.  
  332. SYM_SHARED
  333.   int global_save;    /* module contains SAVE with no list */
  334.  
  335.         /* Define names for anonymous things */
  336. #ifdef SYMTAB
  337. char blank_com_name[] = "%BLANK",  /* id for blank common entry in symtab */
  338.      unnamed_prog[]="%MAIN",      /* id for unnamed program module */
  339.      unnamed_block_data[]="%DAT00";  /* id for unnamed block data module */
  340. int  block_data_number=0;       /* count of multiple anonymous block data */
  341. #else
  342. extern char blank_com_name[],
  343.         unnamed_prog[],
  344.         unnamed_block_data[];
  345. extern int block_data_number;
  346. #endif
  347.  
  348.                 /* Symbol table argument list declarations */
  349.  
  350. typedef union {        /* InfoUnion: misc info about symtab entry */
  351.          unsigned long array_dim;    /* array size and no. of dims */
  352.          struct ALHead *arglist;    /* ptr to func/subr argument list */
  353.          struct CMHead *comlist;    /* ptr to common block list */
  354.          struct TLHead *toklist;  /* ptr to token list */
  355.          struct IInfo *intrins_info;/* ptr to intrinsic func info */
  356.          struct PInfo *param;    /* parameter information field */
  357. } InfoUnion;
  358.  
  359. typedef struct {    /* ArgListElement: holds subprog argument data */
  360.     char *name;        /* name of dummy arg or text of actual arg */
  361.     InfoUnion info;
  362.     long size;
  363.     BYTE type;
  364.     unsigned is_lvalue: 1,
  365.          set_flag: 1,
  366.          assigned_flag: 1,
  367.          used_before_set: 1,
  368.          array_var: 1,
  369.          array_element: 1,
  370.          declared_external: 1;
  371. } ArgListElement;
  372.  
  373.  
  374. typedef struct ALHead {        /* ArgListHeader: head node of argument list */
  375.     long size;
  376.     BYTE type;
  377.     short numargs;
  378.     ArgListElement *arg_array;
  379.     struct gSymtEntry *module;
  380.     char *filename,*topfile;
  381.     unsigned
  382.          line_num,top_line_num,
  383.          is_defn: 1,
  384.          is_call: 1,
  385.          external_decl: 1,    /* EXTERNAL decl, not arg list */
  386.              actual_arg: 1;    /* subprog passed as arg */
  387.     struct ALHead *next;
  388. } ArgListHeader;
  389.  
  390.         /* Symbol table common block list declarations */
  391.  
  392. typedef struct {    /* ComListElement: holds common var data */
  393.     char *name;        /* name of common variable */
  394.     unsigned long dimen_info;
  395.     long size;
  396.     BYTE type;
  397.     unsigned        /* copies of flags from symtab */
  398.       used:1,
  399.       set:1,
  400.       used_before_set:1,
  401.       assigned:1;
  402. } ComListElement;
  403.  
  404. typedef struct CMHead {    /* ComListHeader: head node of common var list */
  405.     short numargs;
  406.     unsigned line_num,top_line_num;
  407.     ComListElement *com_list_array;
  408.     struct gSymtEntry *module;
  409.     char *filename,*topfile;
  410.     struct CMHead *next;
  411.     unsigned
  412.       any_used:1,        /* any of its variables accessed */
  413.       any_set:1,        /* any of its variables set */
  414.       saved:1;        /* declared in SAVE statement */
  415. } ComListHeader;
  416.  
  417.  
  418. typedef struct TLHead {    /* TokenListHeader: head node of token list */
  419.     Token *tokenlist;
  420.     struct TLHead *next;
  421.     char *filename;
  422.     unsigned line_num, top_line_num;
  423.     unsigned
  424.       external_decl:1,
  425.       actual_arg:1;
  426. } TokenListHeader;
  427.  
  428.  
  429.             /* Structure for intrinsic-function info */
  430. typedef struct IInfo{
  431.     char *name;
  432.     short num_args,
  433.           arg_type,
  434.           result_type;
  435.     unsigned short
  436.           intrins_flags;    /* nonstandard,  mixed arg types */
  437. } IntrinsInfo;
  438.  
  439.             /* Structure for parameter info */
  440. typedef struct PInfo{
  441.     char *src_text;        /* source text of parameter value */
  442.     union {
  443.       long integer;        /* integer value */
  444.       DBLVAL dbl;        /* float value */
  445.       char *string;        /* character string value */
  446.     } value;
  447.     int seq_num;        /* position in parameter definitions */
  448. } ParamInfo;
  449.     
  450.     /* Define special num_args values for intrinsics that have
  451.        variable numbers of arguments. */
  452. #define I_1or2    (-1)        /* 1 or 2 arguments */
  453. #define I_2up    (-2)        /* 2 or more arguments */
  454. #define I_0or1    (-3)        /* 0 or 1 argument */
  455.  
  456.             /* for intrins_flags field */
  457.  
  458.     /* Integer-valued intrinsics that are evaluated if args const */
  459. #define I_ABS        0x1
  460. #define I_SIGN        0x2
  461. #define I_DIM        0x3
  462. #define I_MOD        0x4
  463. #define I_MAX        0x5
  464. #define I_MIN        0x6
  465. #define I_ICHAR        0x7
  466. #define I_LEN        0x8
  467. #define I_INDEX        0x9
  468. #define I_EVALUATED    0xf    /* any bit of digit set */
  469.  
  470.         /* Various properties of intrinsics*/
  471. #define I_F77         0x00    /* Standard intrinsic (no flag: placeholder) */
  472. #define I_NONF77    0x10    /* Nonstandard */
  473. #define I_MIXED_ARGS    0x20    /* Has mixed arg types */
  474. #define I_NONPURE    0x40    /* Arg need not be set when called */
  475. #define I_C_TO_R    0x80    /* Complex -> real in generic form */
  476. #define I_NOTARG    0x100    /* Not allowed as actual argument */
  477. #define I_SP_R        0x200    /* special for REAL function */
  478. #define I_CHAR        0x400    /* special handling for CHAR function */
  479. #define I_QARG        0x800    /* Arg type is R*16 or X*32 */
  480. #define I_QUAD        0x1000    /* Result type is R*16 or X*32 */
  481. #define I_EXTRA        0x2000    /* commonly found extra intrinsics */
  482. #define I_VMS        0x4000    /* VMS systems only */
  483. #define I_UNIX        0x8000    /* Unix systems only */
  484.  
  485.             /* Structure for call-tree child list */
  486. typedef struct childlist {
  487.   struct gSymtEntry *child;    /* Pointer to child's symtab entry */
  488.   struct childlist *next;/* Pointer to next child on list */
  489. } ChildList;
  490.  
  491.         /*  Identifier symbol table declaration */
  492.  
  493.  
  494. typedef struct lSymtEntry{
  495.     char *name;             /* Identifier name in stringspace */
  496.     InfoUnion info;
  497.     union{
  498.       char *text;        /* Source text string */
  499.       char **textvec;    /* List of source text strings */
  500.       TokenListHeader *toklist; /* for namelist & common block makedecls */
  501.     } src;
  502.     struct lSymtEntry *equiv_link;    /* Link for equivalence lists */
  503.     long size;        /* Size of object in bytes */
  504.     BYTE  type;        /* Type & storage class: see macros below */
  505.             /* Flags */
  506.     unsigned
  507.          used_flag: 1,    /* value is accessed (read from variable) */
  508.          set_flag: 1,    /* variable is set or passed as subr arg */
  509.          assigned_flag: 1,    /* value is really set (by assignment stmt) */
  510.          used_before_set: 1,/* set_flag is not set when used_flag is set */
  511.          is_current_module: 1, /* this symtab entry is the main module */
  512.          library_module: 1,    /* module was processed in -library mode */
  513.          array_var: 1,    /* variable is dimensioned */
  514.          common_var: 1,    /* variable is in common */
  515.          entry_point: 1,    /* name of an entry point */
  516.          parameter: 1,    /* name of a parameter */
  517.          argument: 1,    /* dummy argument */
  518.          external: 1,    /* function or subr called by this routine */
  519.          intrinsic: 1,    /* intrinsic function */
  520.          saved: 1,        /* named in SAVE statement */
  521.          invoked_as_func: 1, /* usage as f(x) was seen */
  522.          defined_in_include: 1, /* to suppress some warnings if unused */
  523.          declared_external: 1, /* explicitly declared external */
  524.          declared_intrinsic: 1; /* explicitly declared intrinsic */
  525.          unsigned size_is_adjustable : 1; /* CHARACTER*(*) declaration */
  526.          unsigned size_is_expression : 1; /* CHARACTER*(expr) declaration */
  527. } Lsymtab;
  528.  
  529. typedef struct gSymtEntry{    /* Global symbol table element */
  530.     char *name;             /* Identifier name in stringspace */
  531.     InfoUnion info;
  532.     union {
  533.       struct childlist *child_list; /* List of callees (for module) */
  534.       struct gSymtEntry *module; /* Module (for interior entry) */
  535.     } link;
  536.     long size;
  537.     BYTE  type;        /* Type & storage class: see macros below */
  538.             /* Flags.  See remarks above */
  539.     unsigned
  540.          used_flag: 1,
  541.          set_flag: 1,
  542.          assigned_flag: 1,
  543.          used_before_set: 1,
  544.          library_module: 1,
  545.          internal_entry: 1,    /* entry point other than at the top */
  546.          invoked_as_func: 1,
  547.          visited: 1,       /* this entry point is in call tree */
  548.          visited_somewhere: 1, /* some entry point of module is in call tree */
  549.          defined: 1,    /* is defined somewhere */
  550.          defined_in_include: 1,
  551.          declared_external: 1;
  552. } Gsymtab;
  553.  
  554.  
  555.         /*  Identifier hashtable declaration  */
  556.  
  557. typedef struct hashEntry {
  558.     char    *name;        /* Identifier name in stringspace */
  559.     Lsymtab    *loc_symtab,    /* Local symtab entry for vars etc. */
  560.         *com_loc_symtab;/* Local symtab entry for common blocks */
  561.     Gsymtab    *glob_symtab,    /* Global symtab entry for vars etc. */
  562.         *com_glob_symtab;/* Global symtab entry for common blocks */
  563. } HashTable;
  564.  
  565.  
  566.                 /* Struct for chunks of string space */
  567. typedef struct STSpace {
  568.   struct STSpace *next;
  569.   char strspace[STRSPACESZ];
  570. } StrSpace;
  571.  
  572.                 /* Struct for providing chunks of space
  573.                    for parameter info. */
  574. typedef struct PISpace {
  575.   struct PISpace *next;
  576.   ParamInfo paraminfospace[PARAMINFOSPACESZ];
  577. } ParamInfoSpace;
  578.  
  579.                 /* Struct for providing chunks of space
  580.                    for token list headers for arg lists etc. */
  581. typedef struct THSpace {
  582.   struct THSpace *next;
  583.   TokenListHeader tokheadspace[TOKHEADSPACESZ];
  584. } TokHeadSpace;
  585.  
  586.  
  587.                 /* Struct for providing chunks of space
  588.                    for tokens for arg lists etc.  */
  589. typedef struct TSpace {
  590.   struct TSpace *next;
  591.   Token tokenspace[TOKENSPACESZ];
  592. } TokenSpace;
  593.  
  594.                 /* Struct for providing chunks of space
  595.                    for pointers to array & param text */
  596. typedef struct PSpace {
  597.   struct PSpace *next;
  598.   char * ptrspace[PTRSPACESZ];
  599. } PtrSpace;
  600.  
  601.  
  602.         /* Macro to zero out symbol table entry */
  603.  
  604. #define clear_symtab_entry(S) {register int i;\
  605.                  for(i=0;i<sizeof(*S);i++)((char*)S)[i]=0;}
  606.  
  607.  
  608.     /* These macros pack and unpack datatype and storage class in type
  609.        field of symbol table entry. Datatype is least 4 bits. */
  610.  
  611. #define datatype_of(TYPE) ((unsigned)((TYPE) & 0xF))
  612. #define storage_class_of(TYPE) ((unsigned)((TYPE) >> 4))
  613. #define type_byte(SCLASS,DTYPE) ((unsigned)(((SCLASS)<<4) + (DTYPE)))
  614.  
  615.  
  616.     /* This macro is for pattern matching in flag checking */
  617.  
  618. #define flag_combo(A,B,C) (((A)<<2) | ((B)<<1) | (C))
  619.  
  620.  
  621.     /* These macros are for dimensions & sizes of arrays */
  622.  
  623. #define array_dims(dim_info) ((dim_info)&0xF)
  624. #define array_size(dim_info) ((dim_info)>>4)
  625. #define array_dim_info(dim,size) (((long)(size)<<4)+(dim))
  626.  
  627.  
  628.  
  629.         /* Defns used by expression type propagation mechanisms
  630.            in fortran.y and exprtype.c  The flags go in token.subclass
  631.          */
  632.  
  633. #define make_true(flag,x) ((x) |= (flag))        /* x.flag <-- true   */
  634. #define make_false(flag,x) ((x) &= ~(flag))        /* x.flag <-- false  */
  635. #define is_true(flag,x) ((x) & (flag))            /* x.flag == true?   */
  636. #define copy_flag(flag,x,y)  ((x) |= ((y)&(flag)))    /* x.flag <-- y.flag */
  637.  
  638. #define ID_EXPR            0x1    /* a variable */
  639. #define LVALUE_EXPR        0x2    /* assignable */
  640. #define CONST_EXPR        0x4    /* compile-time constant per std 6.7*/
  641. #define LIT_CONST        0x8    /* a number or string literal */
  642. #define ARRAY_ID_EXPR        0x10    /* an array or array element */
  643. #define ARRAY_ELEMENT_EXPR    0x20     /* an array element */
  644. #define INT_QUOTIENT_EXPR    0x40     /* contains INT/INT */
  645. #define STMT_FUNCTION_EXPR    0x80
  646. #define PARAMETER_EXPR        0x100/* == CONST_EXPR || intrinsic || **real */
  647. #define EVALUATED_EXPR        0x200  /* token.value has value of expr */
  648. #define SET_FLAG        0x400  /* id may be set */
  649. #define ASSIGNED_FLAG        0x800  /* id is set in assignment stmt */
  650. #define USED_BEFORE_SET        0x1000  /* id used beforre set */
  651. #define COMPLEX_FLAG        0x2000    /* remembers complex_const_allowed */
  652. #define CHAR_ID_EXPR        0x4000    /* char var or array elt not substr */
  653. #define IN_ASSIGN        0x8000    /* for tracking assgn stmt lhs */
  654. #define COMMA_FLAG         0x10000/* keeps track of extra or missing
  655.                          commas in exprlists (obsolete) */
  656. #define NONSTD_USAGE_FLAG    0x20000    /* concentrator for -f77 warnings */
  657. #define SYNTAX_ERROR_FLAG    0x40000    /* concentrator for syntax errors */
  658.  
  659. #ifdef DYNAMIC_TABLES        /* tables will be mallocked at runtime */
  660. SYM_SHARED
  661. Lsymtab    *loc_symtab
  662. #ifdef SYMTAB
  663.   =(Lsymtab *)NULL
  664. #endif
  665. ;
  666. SYM_SHARED
  667. Gsymtab *glob_symtab
  668. #ifdef SYMTAB
  669.   =(Gsymtab *)NULL
  670. #endif
  671. ;
  672. SYM_SHARED
  673. HashTable *hashtab
  674. #ifdef SYMTAB
  675.   =(HashTable *)NULL
  676. #endif
  677. ;
  678.  
  679. #else                /* static tables declared at compile time */
  680.         /* Each major table is housed in a separate file so that
  681.            on IBM PC architecture with huge memory model
  682.            each will be in its own 64K segment not all in one. */
  683. #ifndef PLSYMTAB
  684. extern
  685. #endif
  686. Lsymtab    loc_symtab[LOCSYMTABSZ]; /* Local identifiers */
  687. #ifndef PGSYMTAB
  688. extern
  689. #endif
  690. Gsymtab glob_symtab[GLOBSYMTABSZ]; /* Global identifiers: subrs and com blks */
  691. #ifndef EXPRTYPE
  692. extern
  693. #endif
  694. HashTable hashtab[HASHSZ];    /* Hash table for identifier lookup */
  695.  
  696. #endif/* end static tables */
  697.  
  698.     /* The following tables start life as statically declared
  699.        tables, but when add'l space is needed, new structs of same
  700.        kind will be allocated and linked via next field of struct.
  701.        Because they are dynamically extended, they are not in
  702.        the DYNAMIC_TABLES section or its complement above.  Note
  703.        that as global variables they start off at 0, so next field
  704.        of each is implicitly initialized to NULL.  */
  705.  
  706. #ifndef FORLEX
  707. extern
  708. #endif
  709. TokenSpace tokspace;    /* Tokens for arg lists etc */
  710.  
  711. #ifndef PROJECT
  712. extern
  713. #endif
  714. TokHeadSpace tokheadspace;/* Tokenlist headers */
  715.  
  716. #ifndef PROJECT
  717. extern
  718. #endif
  719. ParamInfoSpace paraminfospace;/* Parameter info structs */
  720.  
  721. #ifndef PROJECT
  722. extern
  723. #endif
  724. PtrSpace ptrspace;    /* Space for storing arrays of pointers */
  725.  
  726. #ifndef SYMTAB
  727. extern
  728. #endif
  729. StrSpace lstrspace;    /* String space for local identifiers */
  730.  
  731. #ifndef SYMTAB
  732. extern
  733. #endif
  734. StrSpace srctextspace;/* String space for token source text */
  735.  
  736.  
  737.         /* Shared routines */
  738.  
  739.  
  740.             /* in exprtype.c */
  741. PROTO(void assignment_stmt_type,( Token *term1, Token *equals, Token *term2 ));
  742. PROTO(void binexpr_type,( Token *term1, Token *operator, Token *term2, Token
  743.           *result ));
  744. PROTO(void func_ref_expr,( Token *id, Token *args, Token *result ));
  745. PROTO(void primary_id_expr,( Token *id, Token *primary ));
  746. PROTO(void stmt_fun_arg_cmp,( Lsymtab *symt, Token *d_arg, Token *a_arg ));
  747. PROTO(int substring_size,( Token *id, Token *limits ));
  748. PROTO(void unexpr_type,( Token *term1, Token *operator, Token *result ));
  749. PROTO(int intrins_arg_cmp,( IntrinsInfo *defn, Token *t));
  750.  
  751.             /* in forlex.c */
  752. PROTO(void implied_id_token,( Token *t, char *s ));
  753. PROTO(int yylex,( void ));
  754.  
  755.             /* in fortran.y/fortran.c */
  756. PROTO(void check_seq_header,( Token *t ));
  757.  
  758.             /* in plsymtab.c */
  759. PROTO(void print_loc_symbols,( int curmodhash ));
  760.  
  761.             /* in symtab.c */
  762. PROTO(void call_func,( Token *id, Token *arg ));
  763. PROTO(void call_subr,( Token *id, Token *arg ));
  764. PROTO(char * char_expr_value,( Token *t ));
  765. PROTO(void check_loose_ends,( int curmodhash ));
  766. PROTO(void declare_type,( Token *id, int datatype, long size, char *size_text ));
  767. PROTO(void def_arg_name,( Token *id ));
  768. PROTO(void def_array_dim,( Token *id, Token *arg ));
  769. PROTO(void def_com_block,( Token *id, Token *comlist ));
  770. PROTO(void def_com_variable,( Token *id ));
  771. PROTO(int def_curr_module,( Token *id ));
  772. PROTO(void def_equiv_name,( Token *id ));
  773. PROTO(void def_ext_name,( Token *id ));
  774. PROTO(void def_function,( int datatype, long size, char *size_text, Token
  775.           *id, Token *args ));
  776. PROTO(void def_intrins_name,( Token *id ));
  777. #ifdef CHECK_LABELS
  778. PROTO(void def_label,( Token *lab ));
  779. #endif
  780. PROTO(void def_namelist,( Token *id, Token *list ));
  781. PROTO(void def_namelist_item,( Token *id ));
  782. PROTO(void def_parameter,( Token *id, Token *val ));
  783. PROTO(void def_stmt_function,( Token *id, Token *args ));
  784. PROTO(void do_ASSIGN,( Token *id ));
  785. PROTO(void do_assigned_GOTO,( Token *id ));
  786. PROTO(void do_ENTRY,( Token *id, Token *args, int hashno ));
  787. PROTO(void do_RETURN,( int hashno, Token *keyword ));
  788. PROTO(void equivalence,( Token *id1, Token *id2 ));
  789. PROTO(DBLVAL float_expr_value,( Token *t ));
  790. PROTO(int get_size,( Lsymtab *symt, int type ));
  791. PROTO(char * get_size_text,( Lsymtab *symt, int type ));
  792. PROTO(int get_type,( Lsymtab *symt ));
  793. PROTO(unsigned hash_lookup,( char *s ));
  794. PROTO(Gsymtab* install_global,( int h, int datatype, int storage_class ));
  795. PROTO(int int_expr_value,( Token *t ));
  796. PROTO(char * new_global_string,( char *s ));
  797. PROTO(void free_textvec,( char **p ));
  798. PROTO(char * new_src_text,( char *s, int len ));
  799. PROTO(char * new_src_text_alloc,( int size ));
  800. PROTO(char * new_tree_text,( Token *t ));
  801. PROTO(char ** new_textvec,( int n ));
  802. PROTO(Token * new_token,( void ));
  803. #ifdef DEBUG_EXPRTREES
  804. PROTO(void print_src_text,( Token *t ));
  805. PROTO(void print_expr_tree,( Token *t ));
  806. PROTO(void print_expr_list,( Token *t ));
  807. #endif
  808. PROTO(void process_lists,( int curmodhash ));
  809. PROTO(void ref_array,( Token *id, Token *subscrs ));
  810. PROTO(void ref_namelist,( Token *id, int stmt_class ));
  811. PROTO(void ref_variable,( Token *id ));
  812. PROTO(void save_com_block,( Token *id ));
  813. PROTO(void save_variable,( Token *id ));
  814. PROTO(void set_implicit_type,( int type, long size, char *len_text, int c1, int c2 ));
  815. PROTO(void stmt_function_stmt,( Token *id ));
  816. PROTO(char * token_name,( Token t ));
  817. PROTO(void use_actual_arg,( Token *id ));
  818. PROTO(void use_implied_do_index,( Token *id ));
  819. PROTO(void use_io_keyword,( Token *keyword, Token *value, int stmt_class ));
  820. PROTO(void use_special_open_keywd,( Token *id ));
  821. PROTO(void use_lvalue,( Token *id ));
  822. PROTO(void use_parameter,( Token *id ));
  823. PROTO(void use_variable,( Token *id ));
  824.  
  825.                 /* in symtab.c (formerly hash.c) */
  826. PROTO(unsigned long hash,( char *s ));
  827. PROTO(unsigned long rehash,( unsigned long hnum ));
  828.  
  829.  
  830.