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