home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / harbb30g.zip / INCLUDE / compiler.h < prev    next >
C/C++ Source or Header  |  1999-09-17  |  7KB  |  169 lines

  1. /*
  2.  * $Id: compiler.h,v 1.23 1999/09/17 13:29:24 vszel Exp $
  3.  */
  4.  
  5. /*
  6.  * Harbour Project source code:
  7.  * Header file for the Harbour Compiler
  8.  *
  9.  * Copyright 1999 Antonio Linares <alinares@fivetech.com>
  10.  * www - http://www.harbour-project.org
  11.  *
  12.  * This program is free software; you can redistribute it and/or modify
  13.  * it under the terms of the GNU General Public License as published by
  14.  * the Free Software Foundation; either version 2 of the License, or
  15.  * (at your option) any later version, with one exception:
  16.  *
  17.  * The exception is that if you link the Harbour Runtime Library (HRL)
  18.  * and/or the Harbour Virtual Machine (HVM) with other files to produce
  19.  * an executable, this does not by itself cause the resulting executable
  20.  * to be covered by the GNU General Public License. Your use of that
  21.  * executable is in no way restricted on account of linking the HRL
  22.  * and/or HVM code into it.
  23.  *
  24.  * This program is distributed in the hope that it will be useful,
  25.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  26.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  27.  * GNU General Public License for more details.
  28.  *
  29.  * You should have received a copy of the GNU General Public License
  30.  * along with this program; if not, write to the Free Software
  31.  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA (or visit
  32.  * their web site at http://www.gnu.org/).
  33.  *
  34.  */
  35.  
  36. #ifndef HB_COMPILER_H_
  37. #define HB_COMPILER_H_
  38.  
  39. #include "hbpp.h"
  40.  
  41. /* TODO: Remove these (WORD/DWORD) when the compiler is cleaned up from them. */
  42. #if defined(__IBMCPP__)
  43.    #undef WORD                            /* 2 bytes unsigned */
  44.    typedef unsigned short int WORD;
  45. #else
  46.    #if ! defined(HB_DONT_DEFINE_BASIC_TYPES)
  47.       #undef WORD                            /* 2 bytes unsigned */
  48.       typedef unsigned short int WORD;
  49.  
  50.       #undef DWORD                           /* 4 bytes unsigned */
  51.       typedef unsigned long DWORD;
  52.    #endif
  53. #endif
  54.  
  55. /* compiler related declarations */
  56.  
  57. /* locals, static, public variables support */
  58. typedef struct _VAR
  59. {
  60.    char * szName;          /* variable name */
  61.    char * szAlias;         /* variable alias namespace */
  62.    int    iUsed;           /* number of times used */
  63.    char   cType;           /* optional strong typing */
  64.    struct _VAR * pNext;    /* pointer to next defined variable */
  65. } VAR, * PVAR;
  66.  
  67. /* structure to hold a Clipper defined function */
  68. typedef struct __FUNC      /* functions definition support */
  69. {
  70.    char * szName;          /* name of a defined Clipper function */
  71.    char   cScope;          /* scope of a defined Clipper function */
  72.    BYTE   bFlags;          /* some flags we may need */
  73.    WORD   wParamCount;     /* number of declared parameters */
  74.    WORD   wParamNum;       /* current parameter number */
  75.    PVAR   pLocals;         /* pointer to local variables list */
  76.    PVAR   pStatics;        /* pointer to static variables list */
  77.    PVAR   pFields;         /* pointer to fields variables list */
  78.    PVAR   pMemvars;        /* pointer to memvar variables list */
  79.    BYTE * pCode;           /* pointer to a memory block where pcode is stored */
  80.    ULONG  lPCodeSize;      /* total memory size for pcode */
  81.    ULONG  lPCodePos;       /* actual pcode offset */
  82.    int    iStaticsBase;    /* base for this function statics */
  83.    struct __FUNC * pOwner; /* pointer to the function/procedure that owns the codeblock */
  84.    struct __FUNC * pNext;  /* pointer to the next defined function */
  85. } _FUNC, * PFUNCTION;
  86.  
  87. /* structure to control all Clipper defined functions */
  88. typedef struct
  89. {
  90.    PFUNCTION pFirst;       /* pointer to the first defined funtion */
  91.    PFUNCTION pLast;        /* pointer to the last defined function */
  92.    int       iCount;       /* number of defined functions */
  93. } FUNCTIONS;
  94.  
  95. /* compiler symbol support structure */
  96. typedef struct _COMSYMBOL
  97. {
  98.    char * szName;              /* the name of the symbol */
  99.    char   cScope;              /* the scope of the symbol */
  100.    char   cType;
  101.    struct _COMSYMBOL * pNext;  /* pointer to the next defined symbol */
  102. } COMSYMBOL, * PCOMSYMBOL;
  103.  
  104. /* symbol table support structures */
  105. typedef struct
  106. {
  107.    PCOMSYMBOL pFirst;      /* pointer to the first defined symbol */
  108.    PCOMSYMBOL pLast;       /* pointer to the last defined symbol */
  109.    int        iCount;      /* number of defined symbols */
  110. } SYMBOLS;
  111.  
  112. /* locals, static, public variables support */
  113. typedef struct _STACK_VAL_TYPE
  114. {
  115.    char cType;                      /* type of stack value */
  116.    struct _STACK_VAL_TYPE * pPrev;    /* pointer to previous stack value's type */
  117. } STACK_VAL_TYPE, * PSTACK_VAL_TYPE;
  118.  
  119. extern PFUNCTION GetFunction( char * szFunName ); /* locates a previously defined function */
  120. extern WORD      GetFunctionPos( char * szSymbolName ); /* returns the index + 1 of a function on the functions defined list */
  121.  
  122. extern void *   hb_xgrab( ULONG lSize );   /* allocates memory, exists on failure */
  123. extern void *   hb_xrealloc( void * pMem, ULONG lSize );   /* reallocates memory */
  124. extern void     hb_xfree( void * pMem );    /* frees memory */
  125.  
  126. char * yy_strdup( char * p );  /* this will exit if there is not enough memory */
  127. char * yy_strupr( char * p );
  128.  
  129. #if 0
  130. static void __yy_memcpy( char * from, char * to, int count ); /* Bison prototype */
  131. #endif
  132.  
  133. extern WORD FixSymbolPos( WORD );    /* converts symbol's compile-time position into generation-time position */
  134. extern PFUNCTION GetFuncall( char * szFunName ); /* locates a previously defined called function */
  135. extern PVAR GetVar( PVAR pVars, WORD wOrder ); /* returns a variable if defined or zero */
  136. extern PCOMSYMBOL GetSymbol( char *, WORD * ); /* returns a symbol pointer from the symbol table */
  137. extern PCOMSYMBOL GetSymbolOrd( WORD );   /* returns a symbol based on its index on the symbol table */
  138. extern PFUNCTION KillFunction( PFUNCTION );    /* releases all memory allocated by function and returns the next one */
  139. extern PCOMSYMBOL KillSymbol( PCOMSYMBOL );    /* releases all memory allocated by symbol and returns the next one */
  140.  
  141. extern FUNCTIONS functions, funcalls;
  142. extern PFUNCTION _pInitFunc;
  143. extern SYMBOLS symbols;
  144. extern PHB_FNAME _pFileName;
  145. extern BOOL _bQuiet;
  146. extern BOOL _bStartProc;
  147. extern char _szPrefix[ 20 ];         /* holds the prefix added to the generated symbol init function name (in C output currently) */
  148.  
  149. extern char * _szCErrors[];
  150.  
  151. #define VS_LOCAL      1
  152. #define VS_STATIC     2
  153. #define VS_FIELD      4
  154. #define VS_PARAMETER  8
  155. #define VS_PRIVATE    64
  156. #define VS_PUBLIC     128
  157. #define VS_MEMVAR     ( VS_PUBLIC | VS_PRIVATE )
  158.  
  159. /*
  160.  * flags for bFlags member
  161. */
  162. #define FUN_STATEMENTS    1 /* Function have at least one executable statement */
  163. #define FUN_USES_STATICS  2 /* Function uses static variables */
  164. #define FUN_PROCEDURE     4 /* This is a procedure that shouldn't return value */
  165. #define FUN_ILLEGAL_INIT  8 /* Attempt to initialize static variable with a function call */
  166. #define FUN_USES_LOCAL_PARAMS 16 /* parameters are declared using () */
  167.  
  168. #endif /* HB_COMPILER_H_ */
  169.