/*
 *  MODULE  : idtab.h
 *  identifier table
{*  last modification:	09.07.92  12:28   }

 *  uli 03.01.91 : moduniquename move from module.h
 *                 newname is local now
 *  uli 04.01.91 : cast (boolean) added to id_is
 *  uli 25.01.91 : idkndtext declared.
 *  Dima 30.01.91: idroutfnd : parameter callclass added
 *  uli 04.03.91 : type optabptr added
 *  uli 26.03.91 : idflag forvariable added
 *  Dima 23.04.91: sub_or_base_of : added
 *  uli 23.04.91 : idrdconv and idruconv added.
 *  uli 02.05.91 : sub_or_base_of is boolean.
 *  uli 08.05.91 : rconstype added.
 *  uli 16.07.91 : idfset sets true.
 *  uli 16.07.91 : idfclr added, sets false.
 *  uli 06.08.91 : idPTRCHAR and ptrchartype added.
 *  uli 09.08.91 : idINT_OF_C, idFILE_OF_C and idPOINTER_OF_C
		   pointer_of_ctype, int_of_ctype, file_of_ctype  added.
 *  uli 12.08.91 : idtab flag "nogener" added.
 *  uli 19.08.91 : idtab flag "nogener" replaced by nodecl and noinit.
 *  Dima 22.11.91 : sub_or_base_of : moved to optab (coers)
 *  uli 23.01.92 : idIDOT etc. and idot etc. added.
 *  uli 23.06.92 : pointer_of_ctype changed to ptr_of_ctype.
 *  PJ  09.07.92 : prototype definition of function idsetglobal removed
                   ( there is no complete definition and it is never called )
*/


typedef enum idkind	/* Variables of type 'idkind'	*/
			/* have on of the next values.	*/
{
   IDNONE        ,  /*  0	/ *-------------------------*/
   IDPROGRAM     ,  /*  1	/ * List of possible kinds  */ 
   IDCONST       ,  /*  2	/ * an identifier may have. */
   IDTYPE        ,  /*  3	/ *-------------------------*/
   IDFUNCTION    ,  /*  4 */
   IDPROCEDURE   ,  /*  5 */
   IDMODULE      ,  /*  6 */
   IDRES1VAR     ,  /*  7  * left side of := to function result */
   IDVAR         ,  /*  8 */
   IDPARAM       ,  /*  9  * Pascal value Parameter */
   IDVALPARAM    ,  /* 10  * value Parameter to be copied in C */
   IDVARPARAM    ,  /* 11  * Pascal var Parameter */
   IDRES2VAR     ,  /* 12  * pointer to function result */
#ifdef OLD
   IDDEN1VAR        13 /* record of local variables */
   IDDEN2VAR        14 /* pointer variable to previous inkarnation */
   IDDEN3VAR        15 /* global pointer var to current inkarnation */
   IDRECKOMP        16
   IDDYN1VAR        17
   IDDYN2VAR        20
#endif
   IDIMPORT       , /* 18 */
   IDLABEL        } /* 19 */
  idkind ;

typedef struct bin      * binptr;        /* Types of pointers to   */
typedef struct id       * idptr;         /* fundamental structures */
typedef struct block    * blockptr;      /* of 'bintab', 'idtab',  */
typedef struct oprlist  * opptr;         /* 'blktab' and 'optab'.  */
typedef struct op       * optabptr;      /* pointer to a whole optab */

					/*-------------------------------*/
					/* idptr to standard identifiers */
global idptr     idBAD_ID
,                idFALSE
,                idTRUE
,                idMAXINT
,                idBOOLEAN
,                idCHAR
,                idPTRCHAR
,                idINTEGER
,                idINT_OF_C
,                idFILE_OF_C
,                idPOINTER_OF_C
,                idREAL
,                idTEXT
,                idDOTPRECISION
,                idIDOTPRECISION
,                idCDOTPRECISION
,                idCIDOTPRECISION
,                idLITERAL
,                idSTRING
,                idINPUT
,                idOUTPUT
,                idCINTERVAL
,                idCOMPLEX
,                idINTERVAL
,                idRVECTOR
,                idCVECTOR
,                idIVECTOR
,                idCIVECTOR
,                idRMATRIX
,                idCMATRIX
,                idIMATRIX
,                idCIMATRIX
,                idcurrf        /* current function */
;
extern idptr     idrconv ;      /* real constant conversion function */
extern idptr     idrdconv;      /* real constant conversion function */
extern idptr     idruconv;      /* real constant conversion function */

global binptr    integertype     ,	/*---------------------*/
		 realtype        ,	/* standard data types */
		 booleantype     ,	/*---------------------*/
		 chartype        ,
		 ptrchartype     ,
		 int_of_ctype    ,
		 ptr_of_ctype    ,
		 file_of_ctype   ,
		 rconstype       , /*  type of real constants  */
			    /* may be redefined by realconstantconversion */
		 literaltype     ,
/*               filetype        , */
		 texttype        ,
		 stringtype      ,
		 pointertype     ,
		 intervaltype    ,
		 complextype     ,
		 cintervaltype   ,
		 dotprecisiontype,
		 idotprecisiontype,
		 cdotprecisiontype,
		 cidotprecisiontype,
		 rvectortype     ,
		 cvectortype     ,
		 ivectortype     ,
		 civectortype    ,
		 rmatrixtype     ,
		 cmatrixtype     ,
		 imatrixtype     ,
		 cimatrixtype    ,
/*               settype         ,
		 arraytype       ,
		 dynamictype     ,
		 recordtype      , */
		 voidtype        ,      /* result of procedure call */
		 anytype         ,      /* unknown type */
		 notype          ;

global int MAXDENLEVEL;
global symptr symresid;
global boolean idglobdecl ;     /* parsing a global declaration */
				/* set by decl.c */
global char * idkndtext [20] ;  /* textual representation od idkind */
global char initname[FILENAME_MAX+3];
			/* name of module-initialisation routine */
			/* defined by initmoduniquename, used by generate.c */

typedef struct {
		   unsigned int is_global   : 1;
		   unsigned int imported    : 1;
		   unsigned int used        : 1;      /* Attention !!       */
		   unsigned int innerused   : 1;      /* Do allways update  */
		   unsigned int forward     : 1;      /* idfinit in idtab.c */
		   unsigned int globalglobal: 1;
		   unsigned int generated   : 1;
		   unsigned int dynamic     : 1;
		   unsigned int hidden      : 1;
		   unsigned int external    : 1;
		   unsigned int nooverload  : 1;
		   unsigned int stdmodule   : 1;
		   unsigned int usedglobal  : 1;
		   unsigned int arraytype   : 1;
		   unsigned int desctype    : 1;
		   unsigned int varpl       : 1;
		   unsigned int varpr       : 1;
		   unsigned int formpara    : 1;
		   unsigned int hasdyn      : 1;
		   unsigned int parused     : 1;
		   unsigned int forvariable : 1;
		   unsigned int nodecl      : 1; /* no declaration */
		   unsigned int noinit      : 1; /* no initialization */

		} idflags;

# define id_is(id,flag) (boolean)(idflag(id,false)->flag)  /* Flags erfragen */
# define idfset(id,flag) (idflag(id,true)->flag) = true    /* Flags aendern */
# define idfclr(id,flag) (idflag(id,true)->flag) = false   /* Flags aendern */


#ifdef LINT_ARGS

global void      idinit       (void);		/* IDTBAB initialisieren. */
global idptr     idins        (symptr,idkind);  /* Identifier in Baum einfuegen.       */
global idptr     idistypeid   (binptr exp);
global void 	 idroutins    (binptr);		/* insert subroutine to tree */
global idptr 	 idcreate     (symptr, idkind);	/* IDTAB-Knoten generieren. */

global void      idtabtraverse(idptr, void (*)(idptr));
						/* Suchoperationen auf Baum */
global idptr     idfnd        (symptr);
global idptr     idforfnd     (symptr);
global idptr     idlclfnd     (symptr);
global idptr     idtypfnd     (symptr);
global idptr     idfortyp     (symptr);
global idptr     idroutfnd    (idkind cc, symptr sym, binptr actparlist,
					   boolean with_coers);
global idptr     idfuncfnd   (symptr sym, idptr par_type, idptr res_type );

					 /* Zugriff */
global shortint  idlevel      (idptr);
global idkind    idgetkind    (idptr);
global binptr	 iddatyp      (idptr);
global binptr	 idparlist    (idptr);
global binptr	 idwith	      (idptr);
global binptr	 idvalue      (idptr);
global symptr    idcsym       (idptr);
global symptr    idsym        (idptr);
global binptr    idbin        (idptr);
					/* Aendern  */
global void      idsetkind    (idptr,idkind);
global void      idsetdatyp   (idptr, binptr);
global void      idsetparlist (idptr, binptr);
global void      idsetwith    (idptr, binptr);
global void      idsetvalue   (idptr, binptr);
global void      idsetcsym    (idptr, symptr);
global void      idsetsym     (idptr, symptr);
global void      idsetbin     (idptr, binptr);

					/* Verschiedenes */

global idflags  *idflag       (idptr,boolean);
global symptr    uniquename   (const char *);
global void      initmoduniquename (void);
global symptr    moduniquename     (void);
global void      iddump       (void);
global int       idforw       (idptr,int);

global boolean binparcompare  (binptr form, binptr act);
#else
global boolean  binparcompare   ();
global boolean   sub_or_base_of ();

global void      idinit       ();
global idptr     idins        ();
global idptr     idistypeid   ();
global void 	 idroutins    ();
global idptr 	 idcreate     ();

global void      idtabtraverse();

global idptr     idfnd        (/* sym */);
global idptr     idforfnd     (/* sym */);
global idptr     idlclfnd     (/* sym */);
global idptr     idtypfnd     (/* sym */);
global idptr     idfortyp     (/* sym */);
global idptr	 idroutfnd    ();
global idptr     idfuncfnd    ();

global shortint  idlevel      ();
global shortint  idnr         ();
global symptr    idcsym       ();
global idkind    idgetkind    (/* id */);
global binptr	 iddatyp      (/* id */);
global binptr	 idparlist    (/* id */);
global binptr	 idwith	      (/* id */);
global binptr	 idvalue      (/* id */);
global symptr    idsym        (/* id */);
global binptr    idbin        ();

global void      idsetsym     ();
global void      idsetkind    (/* id, kind*/);
global void      idsetdatyp    (/* id, st */);
global void      idsetparlist (/* id, st */);
global void      idsetwith    (/* id, st */);
global void      idsetvalue   (/* id, st */);
global void      idsetcsym    (/* id, sym */);
global void      idsetbin     ();
global idflags  *idflag       (/* idptr,boolean*/);

global symptr    uniquename   (/* char[2] */);
global void      initmoduniquename ( );
global symptr    moduniquename     ( );
global void      iddump       (/* */);
global int       idforw       ();

#endif /*LINT_ARGS*/





/*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
/* The following declaration is necessary to satisfy forward declaration. */
/* Do not use the following names globally. */
							/*-------------*/
typedef struct id {                                     /*  i d  table */
	  /* status should be the first member!! */
		idflags   status;
		symptr       sym; /* Pascal symbol */
		symptr      csym; /* C symbol */
		idkind      kind; /* kind of id, i.e. const or var ... */
		binptr        st; /* pointer to datatype */
		binptr       bin; /* Pointer to declaration */
		struct id   *idl; /* sym ordered binary tree */
		struct id   *idr; /*  "  */
		binptr      with; /* pointer to the with variable in a with block */
		shortint   level;
	} idrec;
							/*-------------------*/
