home *** CD-ROM | disk | FTP | other *** search
/ ftp.cs.arizona.edu / ftp.cs.arizona.edu.tar / ftp.cs.arizona.edu / icon / historic / v941.tgz / icon.v941src.tar / icon.v941src / src / preproc / preproc.h < prev    next >
C/C++ Source or Header  |  2001-12-12  |  7KB  |  203 lines

  1. #include "../h/gsupport.h"
  2.  
  3. /*
  4.  * If Bell is not defined, determine the default value for the "bell"
  5.  *   character.
  6.  */
  7. #ifndef Bell
  8. #define Bell '\a'
  9. #endif                    /* Bell */
  10.  
  11. #define CBufSize 256  /* size of buffer for file input */
  12.  
  13. /*
  14.  * Identification numbers for tokens for which there are no definitions
  15.  *   generated from a C grammar by yacc.
  16.  */
  17. #define WhiteSpace 1001   /* white space */
  18. #define PpNumber   1002   /* number (integer or real) */
  19. #define PpIf       1003   /* #if */
  20. #define PpElse     1004   /* #else */
  21. #define PpIfdef    1005   /* #ifdef */
  22. #define PpIfndef   1006   /* #ifndef */
  23. #define PpElif     1007   /* #elif */
  24. #define PpEndif    1008   /* #endif */
  25. #define PpInclude  1009   /* #include */
  26. #define PpDefine   1010   /* #define */
  27. #define PpUndef    1011   /* #undef */
  28. #define PpLine     1012   /* #line */
  29. #define PpError    1013   /* #error */
  30. #define PpPragma   1014   /* #pragma */
  31. #define PpPaste    1015   /* ## */
  32. #define PpDirEnd   1016   /* new-line terminating a directive */
  33. #define PpHeader   1017   /* <...> from #include */
  34. #define PpBegdef   1018   /* #begdef */
  35. #define PpEnddef   1019   /* #enddef */
  36. #define PpNull     1020   /* # */
  37. #define PpKeep     1021   /* directive specific to an application, pass along */
  38. #define PpSkip     1022   /* directive specific to an application discard */
  39. #define Invalid    9999   /* marker */
  40.  
  41. extern char *progname; /* name of this program: for error messages */
  42. extern int line_cntrl; /* flag: are line directives needed in the output */
  43.  
  44. /*
  45.  * whsp_image determines whether the spelling of white space is not retained,
  46.  *   is retained with each comment replaced by a space, or the full spelling
  47.  *   of white space and comments is retained.
  48.  */
  49. #define NoSpelling 0
  50. #define NoComment  1
  51. #define FullImage  2
  52.  
  53. extern int whsp_image;
  54.  
  55. extern int max_recurse;        /* how much recursion is allows in macros */
  56. extern struct token *zero_tok; /* token "0" */
  57. extern struct token *one_tok;  /* token "1" */
  58.  
  59. extern int *first_char;        /* first character in tokenizing buffer */
  60. extern int *next_char;         /* next character in tokenizing buffer */
  61. extern int *last_char;         /* last character in tokenizing buffer */
  62.  
  63. /*
  64.  * Entry in array of preprocessor directive names.
  65.  */
  66. struct rsrvd_wrd {
  67.    char *s;         /* name (without the #) */
  68.    int tok_id;      /* token id of directive */
  69.    };
  70.  
  71. /*
  72.  * token flags:
  73.  */
  74. #define LineChk  0x1   /* A line directive may be needed in the output */
  75. #define NoExpand 0x2   /* Don't macro expand this identifier */
  76.  
  77. /*
  78.  * Token.
  79.  */
  80. struct token {
  81.    int tok_id;        /* token identifier */
  82.    char *image;        /* string image of token */
  83.    char *fname;         /* file name of origin */
  84.    int line;            /* line number of origin */
  85.    int flag;            /* token flag, see above */
  86.    };
  87.  
  88. /*
  89.  * Token list.
  90.  */
  91. struct tok_lst {
  92.    struct token *t;      /* token */
  93.    struct tok_lst *next; /* next entry in list */
  94.    };
  95.  
  96. /*
  97.  * Identifier list.
  98.  */
  99. struct id_lst {
  100.    char *id;            /* identifier */
  101.    struct id_lst *next; /* next entry in list */
  102.    };
  103.  
  104. /*
  105.  * a macro, m, falls into one of several categores:
  106.  *   those with arguments                - m.category = # args >= 0
  107.  *   those with no arguments             - m.category = NoArgs
  108.  *   those that may not be chaged        - m.category = FixedMac
  109.  *   those that require special handling - m.category = SpecMac
  110.  */
  111. #define NoArgs   -1
  112. #define FixedMac -2
  113. #define SpecMac  -3
  114.  
  115. struct macro {
  116.    char *mname;
  117.    int category;
  118.    int multi_line;
  119.    struct id_lst *prmlst;
  120.    struct tok_lst *body;
  121.    int ref_cnt;
  122.    int recurse;
  123.    struct macro *next;
  124.    };
  125.  
  126. /*
  127.  * states for recognizing preprocessor directives
  128.  */
  129. #define Reset    1
  130. #define CanStart 2   /* Just saw a new-line, look for a directive */
  131. #define Within   3   /* Next new-line ends directive */
  132.  
  133. /*
  134.  * Information for a source of tokens created from a character stream.
  135.  *  The characters may come from a file, or they be in a prefilled buffer.
  136.  */
  137. struct char_src {
  138.    FILE *f;               /* file, if the chars come directly from a file */
  139.    char *fname;          /* name of file */
  140.    int bufsize;          /* size of character buffer */
  141.    int *char_buf;         /* pointer to character buffer */
  142.    int *line_buf;      /* buffer of lines characters come from */
  143.    int *next_char;      /* next unprocessed character in buffer */
  144.    int *last_char;      /* last character in buffer */
  145.    int line_adj;      /* line adjustment caused by #line directive */
  146.    int dir_state;      /* state w.r.t. recognizing directives */
  147.    struct token *tok_sav; /* used to save token after look ahead */
  148.    };
  149.  
  150. /*
  151.  * Information for a source of tokens dirived from expanding a macro.
  152.  */
  153. struct mac_expand {
  154.    struct macro *m;          /* the macro being expanded */
  155.    struct tok_lst **args;     /* list of arguments for macro call */
  156.    struct tok_lst **exp_args; /* list of expanded arguments for macro call */
  157.    struct tok_lst *rest_bdy;  /* position within the body of the macro */
  158.    };
  159.  
  160. /*
  161.  * Elements in a list of token lists used for token pasting.
  162.  */
  163. struct paste_lsts {
  164.    struct token *trigger;   /* the token pasting operator */
  165.    struct tok_lst *tlst;    /* the token list */
  166.    struct paste_lsts *next; /* the next element in the list of lists */
  167. };
  168.  
  169. /*
  170.  * Pointers to various token sources.
  171.  */
  172. union src_ref {
  173.    struct char_src *cs;      /* source is tokenized characters */
  174.    struct mac_expand *me;    /* source is macro expansion */
  175.    struct tok_lst *tlst;     /* source is token list (a macro argument) */
  176.    struct paste_lsts *plsts; /* source is token lists for token pasting */
  177.    };
  178.  
  179. /*
  180.  * Types of token sources:
  181.  */
  182. #define CharSrc   0     /* tokenized characters */
  183. #define MacExpand 1     /* macro expansion */
  184. #define TokLst    2     /* token list */
  185. #define PasteLsts 4    /* paste last token of 1st list to first of 2nd */
  186. #define DummySrc  5     /* base of stack */
  187.  
  188. #define NTokSav  2      /* maximum number of tokens that can be pushed back */
  189.  
  190. struct src {
  191.    int flag;            /* indicate what kind of source it is */
  192.    struct tok_lst *cond;    /* list of nested conditionals in effect */
  193.    struct token *toks[NTokSav];    /* token push-back stack for preproc() */
  194.    int ntoks;            /* number of tokens on stack */
  195.    struct src *next;        /* link for creating stack */
  196.    union src_ref u;             /* pointer to specific kind of source */
  197.    };
  198.  
  199. extern struct src dummy;       /* base of stack */
  200.  
  201. extern struct src *src_stack;  /* source stack */
  202.  
  203.