home *** CD-ROM | disk | FTP | other *** search
/ CD Shareware Magazine 1996 December / CD_shareware_12-96.iso / DOS / Programa / CCDL122.ZIP / INCLUDE / C.H < prev    next >
Encoding:
C/C++ Source or Header  |  1996-08-06  |  9.8 KB  |  352 lines

  1. /*
  2.  * 68K/386 32-bit C compiler.
  3.  *
  4.  * copyright (c) 1996, David Lindauer
  5.  * 
  6.  * This compiler is intended for educational use.  It may not be used
  7.  * for profit without the express written consent of the author.
  8.  *
  9.  * It may be freely redistributed, as long as this notice remains intact
  10.  * and sources are distributed along with any executables derived from them.
  11.  *
  12.  * The author is not responsible for damages, either direct or consequential,
  13.  * that may arise from use of this software.
  14.  *
  15.  * v1.5 August 1996
  16.  * David Lindauer, gclind01@starbase.spd.louisville.edu
  17.  *
  18.  * Credits to Mathew Brandt for original K&R C compiler
  19.  *
  20.  */
  21.  
  22. /*      compiler header file    */
  23.  
  24. #define TRUE 1
  25. #define FALSE 0
  26.  
  27. /* Codegen config */
  28. #ifdef i386
  29. #define FREEDATA 3
  30. #define FREEADDRESS 1
  31. #define FREEFLOAT 3
  32. #define MAXDATA 4
  33. #define MAXADDRESS 12
  34. #else
  35. #define MAXDATA 8
  36. #define MAXADDRESS 13
  37. #define LINKREG 6
  38. #define BASEREG 5
  39. #define FREEDATA 3
  40. #define FREEADDRESS 2
  41. #define FREEFLOAT 3
  42. #endif
  43.  
  44. /* declaration flags */
  45. #define DF_INT 1
  46. #define DF_ABS 2
  47. #define DF_CONST 4
  48. #define DF_VOL 8
  49. #define DF_FUNCPARMS 16
  50. #define DF_GLOBAL 32
  51. #define DF_AUTOREG 64
  52.  
  53. #define UF_DEFINED 1
  54. #define UF_USED    2
  55. #define UF_ASSIGNED 4
  56. #define UF_CANASSIGN 8
  57.  
  58. #define GF_ASSIGN 1
  59. #define GF_CONTINUABLE 2
  60. #define GF_CONTINUE 4
  61. #define GF_GOTO 8
  62. #define GF_DEF 16
  63. #define GF_BREAK 32
  64. #define GF_RETURN 64
  65. #define GF_UNREACH 128
  66. #define GF_NOPROTO 256
  67. #define GF_AND 512
  68. #define GF_SUPERAND 1024
  69. #define GF_INLOOP 2048
  70. #define GF_INFUNCPARMS 4096
  71.  
  72. #define PF_PRIVATE 0
  73. #define PF_PROTECTED 1
  74. #define PF_PUBLIC 2
  75. #define PF_VIRTUAL 4
  76. #define PF_PURE 8
  77. #define PF_INLINE 16
  78. #define PF_STATIC 32
  79. #define PF_CLASSDEF 64
  80. #define PF_CLASSFUNC 128
  81. #define PF_CLASSHEAD 256
  82.  
  83. #ifdef i386
  84. #define    LDBLSIZE    10
  85. #else
  86. #define LDBLSIZE     12
  87. #endif
  88. /* keywords and symbols */
  89. enum e_sym {
  90.         id, cconst, iconst, lconst, sconst, rconst, plus, minus,
  91.         star, divide, lshift, rshift, modop, eq, neq, lt, leq, gt,
  92.         geq, assign, asplus, asminus, astimes, asdivide, asmodop,
  93.         aslshift, asrshift, asand, asor, autoinc, autodec, hook, compl,
  94.         comma, colon, semicolon, uparrow, openbr, closebr, begin, end,
  95.         openpa, closepa, pointsto, dot, lor, land, not, or, and, ellipse, 
  96.     classsel, pointstar, dotstar, kw_int,
  97.         kw_void, kw_char, kw_float, kw_double, kw_struct, kw_union,
  98.         kw_long, kw_short, kw_unsigned, kw_signed, kw_auto, kw_extern,
  99.         kw_register, kw_typedef, kw_static, kw_goto, kw_return,
  100.         kw_sizeof, kw_break, kw_continue, kw_if, kw_else, kw_for,
  101.         kw_do, kw_while, kw_switch, kw_case, kw_default, kw_enum, kw_volatile,
  102.     kw_const, kw_phitext, kw__trap, kw__interrupt, kw__abs, kw__genword,
  103.     kw_public, kw_private, kw_protected, kw_class, kw_friend, kw_new,
  104.     kw_delete, kw_this, kw_operator, kw_inline,
  105.     kw_try,kw_throw,kw_catch, kw_template,
  106. #ifdef i386
  107.     kw__EAX,kw__ECX,kw__EDX,kw__EBX,kw__ESP,kw__EBP,kw__ESI,kw__EDI,
  108. #else
  109.     kw__D0,kw__D1,kw__D2,kw__D3,kw__D4,kw__D5,kw__D6,kw__D7,
  110.     kw__A0,kw__A1,kw__A2,kw__A3,kw__A4,kw__A5,kw__A6,kw__A7,
  111.     kw__FP0,kw__FP1,kw__FP2,kw__FP3,kw__FP4,kw__FP5,kw__FP6,kw__FP7,
  112. #endif
  113.     eof };
  114.  
  115. /* storage classes */
  116. enum e_sc {
  117.         sc_static, sc_auto, sc_global, sc_external, sc_type, sc_defunc, sc_const,
  118.         sc_member, sc_label, sc_ulabel, sc_argument, sc_memberreg, sc_autoreg,
  119.     sc_externalfunc,sc_abs };
  120.  
  121. /* basic types */
  122. enum e_bt {
  123.     /* This first two lines MUST be ordered for the 
  124.      * lostconv stuff to work
  125.      */
  126.         bt_char, bt_unsignedchar, bt_enum,bt_short, bt_unsignedshort, 
  127.     bt_long, bt_unsigned, bt_float, bt_double, bt_longdouble, bt_untyped,
  128.     bt_pointer,bt_ref,bt_void,bt_struct, bt_union, bt_func, bt_class, bt_iclass,
  129.     bt_ifunc, bt_ptrfunc,bt_matchall, bt_ellipse, bt_bitfield };
  130.  
  131. struct slit {
  132.         struct slit     *next;
  133.         int             label;
  134.         char            *str;
  135.         };
  136.  
  137. /* symbols */
  138. struct sym {
  139.         struct sym      *next;            /* next symbol (local tabs only) */
  140.         char            *name;            /* symbol name */
  141.         char        storage_class;        /* storage class */
  142.     char        extflag:1;        /* if external, was it used */
  143.     char        absflag:1;        /* the _abs keyword was used */
  144.     char        intflag:1;        /* the _interrupt keyword was used */
  145. //    char        pflags;
  146. //    struct sym     *parent;                /* Parent class */
  147.     long         addr;            /* address */
  148.     ENODE *        defalt;            /* Default for function params */
  149.                         /* Also name for CPP overload lists */
  150.     /* these fields depend on storage_class */
  151.         union   {
  152.                 long            i;        /* int val */
  153.                 unsigned        u;        /* nsigned val */
  154.                 double          f;        /* float val */
  155.         struct stab {    
  156.             struct sym *head, *tail; /* Overload table*/
  157.             } overlist;
  158.                 char            *s;        /* string val */
  159.                 }
  160.                         value;
  161.     /* Type declarations */
  162.         struct typ {
  163.                 char               type;    /* the type */
  164.                 char            val_flag;       /* set if is an array */
  165.                char        uflags;            /* Track usage */
  166.         char        cflags;        /* const & vol flags */
  167.         char         classflags;    /* Public, protected, private */
  168.         char        bits;        /* -1 for not a bit val, else bit field len */
  169.         char        startbit;    /* start of bit field */    
  170.                 long            size;        /* total size of type */
  171.         /* local symbol tables */
  172.         struct stab lst;         /* Symbol table for structs & functions */
  173.                 struct typ      *btp;        /* pointer to next type (pointers & arrays */
  174.                 char            *sname;        /* structure name ? */
  175.         struct sym *tdef;        /* Pointer to a typedef entry */
  176.                 }
  177.                         *tp;
  178.         };
  179.  
  180. #define SYM     struct sym
  181. #define TYP     struct typ
  182. #define TABLE   struct stab
  183.  
  184. #define MAX_STRLEN      120
  185. #define MAX_STLP1       121
  186.  
  187. /* struct for preprocessor if tracking */
  188. typedef struct ifstruct {
  189.         struct ifstruct *link;        /* link */
  190.         short iflevel;            
  191.         short elsetaken;
  192. } IFSTRUCT;
  193.         
  194. /* #define tracking */
  195. typedef struct {
  196.         char *string;
  197.         short argcount;
  198.         char **args;
  199. } DEFSTRUCT;
  200.  
  201. /* error list */
  202. struct errl {
  203.         struct errl *link;
  204.         short errno;
  205.         void *data;
  206. };
  207.  
  208. /* used for error skimming */
  209. #define BALANCE struct balance
  210. #define BAL_PAREN   0
  211. #define BAL_BRACKET 0
  212. #define ERRORS struct errl
  213.  
  214. struct balance {
  215.         struct balance *back;
  216.         short type;
  217.         short count;
  218. };
  219.  
  220. /* Global symbol table is a hash table */
  221. #define HASHTABLESIZE 1023
  222.  
  223. typedef struct _hashrec_ {
  224.    struct _hashrec_ *link;    /* Link to next element in list */
  225.    char *key;    /* Full key */
  226. } HASHREC;
  227.  
  228. /* known errors */
  229.  
  230. #define ERR_ILLCHAR     1
  231. #define ERR_NEEDCHAR    2
  232. #define ERR_NEEDCONST   3
  233. #define ERR_FPCON       4
  234. #define ERR_IDEXPECT    5
  235. #define ERR_IDENTEXPECT 6
  236. #define ERR_UNEXPECT    7
  237. #define ERR_PUNCT       8
  238. #define ERR_INSERT    9
  239. #define ERR_UNDEFINED   10
  240. #define ERR_DUPSYM      11
  241. #define ERR_NOINIT      12
  242. #define ERR_INITSIZE    13
  243. #define ERR_NOCASE      14
  244. #define ERR_DUPCASE     15
  245. #define ERR_LABEL       16
  246. #define ERR_ELSE    17
  247. #define ERR_EXPREXPECT  18
  248. #define ERR_ILLCLASS    19
  249. #define ERR_ILLCLASS2   20
  250. #define ERR_NOPOINTER   21
  251. #define ERR_NOFUNC      22
  252. #define ERR_LVALUE      23
  253. #define ERR_DEREF       24
  254. #define ERR_ILLCAST    25
  255. #define ERR_PREPROCID   26
  256. #define ERR_INCLFILE    27
  257. #define ERR_CANTOPEN    28
  258. #define ERR_PREPROCMATCH 29
  259. #define ERR_MACROSUBS   30
  260. #define ERR_ARGMISMATCH 31
  261. #define ERR_ARGLENSHORT 32
  262. #define ERR_ARGLENLONG  33
  263. #define ERR_CALLMISMATCH 34
  264. #define ERR_CALLLENSHORT 35
  265. #define ERR_CALLLENLONG  36
  266. #define ERR_FUNCMISMATCH 37
  267. #define ERR_RETMISMATCH 38
  268. #define ERR_MISMATCH    39
  269. #define ERR_ARRAYMISMATCH 40
  270. #define ERR_ILLTYPE    41
  271. #define ERR_DECLEXPECT  42
  272. #define ERR_INVFLOAT    43
  273. #define ERR_INVTRAP    44
  274. #define ERR_BFILLEGAL    45
  275. #define ERR_BFTOOBIG    46
  276. #define ERR_ERROR    47    /* User error */
  277. #define ERR_BFTYPE    48    /* Bit field non-scalar */
  278. #define ERR_INTERP    49
  279. #define ERR_BFADDR    50
  280. #define ERR_MODCONS    51
  281. #define ERR_SZTYPE    52
  282. #define ERR_FUNCRETVAL 53
  283. #define ERR_SYMUNUSED    54
  284. #define ERR_SYMUNDEF    55
  285. #define ERR_SYMASSIGNED 56
  286. #define ERR_NONPORT    57
  287. #define ERR_UNREACHABLE 58
  288. #define ERR_FUNCUNUSED    59
  289. #define ERR_CODENONE    60
  290. #define ERR_BADEQUATE    61
  291. #define ERR_NOANDREG     62
  292. #define ERR_NOCONTINUE  63
  293. #define ERR_DUPLABEL    64
  294. #define ERR_NOFUNCARRAY 65
  295. #define ERR_NOVOIDRET   66
  296. #define ERR_ZEROSTORAGE 67
  297. #define ERR_SHORTPOINTER 68
  298. #define ERR_NOSTATICFUNC 69
  299. #define ERR_UNUSEDLABEL    70                                            
  300. #define ERR_NOPROTO     71
  301. #define ERR_LOSTCONV    72
  302. #define ERR_UNDEFLABEL    73
  303. #define ERR_ILLREGISTER 74
  304. #define ERR_SUPERAND    75
  305. #define ERR_STATICSYMUNUSED 76
  306. #define ERR_NODECLARE     77
  307. #define ERR_ZEROPTR    78
  308. #define ERR_NOMAIN 79
  309. #define ERR_NOREF 80
  310. #define ERR_CANTREF 81
  311. #define ERR_TEMPUSED 82
  312. #define ERR_REFMUSTINIT 83
  313. #define ERR_TEMPINIT 84
  314. #define ERR_REFLVALUE 85
  315. #define ERR_REFNOCONS 86
  316. #define ERR_MISSINGDEFAULT 87
  317. #define ERR_AMBIGFUNC 88
  318. #define ERR_NOLOCALDEFAULT 89
  319. #define ERR_CPPMISMATCH 90
  320. #define ERR_NOOVERMAIN 91
  321. #define ERR_SWITCHINT 92
  322. #define ERR_NOFUNCMATCH 93
  323. #define ERR_PREDEFSTRUCT 94
  324. #define ERR_LOCALCLASS 95
  325. #define ERR_PUREDECL 96
  326. #define ERR_BADESTRUCT 97
  327. #define ERR_TYPECONSTRUCT 98
  328. #define ERR_NOTYPEQUAL 99
  329. #define ERR_NOTACLASS 100
  330. #define ERR_MAX 101
  331.  
  332. /*      alignment sizes         */
  333.  
  334. #ifdef i386
  335. #define AL_CHAR         1
  336. #define AL_SHORT        2
  337. #define AL_LONG         4
  338. #define AL_POINTER      4
  339. #define AL_FLOAT        4
  340. #define AL_DOUBLE       4
  341. #define AL_STRUCT       4
  342. #define AL_LONGDOUBLE   4
  343. #else
  344. #define AL_CHAR         1
  345. #define AL_SHORT        2
  346. #define AL_LONG         4
  347. #define AL_POINTER      4
  348. #define AL_FLOAT        4
  349. #define AL_DOUBLE       4
  350. #define AL_STRUCT       4
  351. #define AL_LONGDOUBLE   4
  352. #endif