idf.h 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. /* $Header$ */
  2. /* IDENTIFIER DESCRIPTOR */
  3. #include "nopp.h"
  4. /* Since the % operation in the calculation of the hash function
  5. turns out to be expensive, it is replaced by the cheaper XOR (^).
  6. Each character of the identifier is xored with an 8-bit mask which
  7. depends on the position of the character; the sum of these results
  8. is the hash value. The random masks are obtained from a
  9. congruence generator in idf.c.
  10. */
  11. #define HASHSIZE 256 /* must be a power of 2 */
  12. #define HASH_X 0253 /* Knuth's X */
  13. #define HASH_A 77 /* Knuth's a */
  14. #define HASH_C 153 /* Knuth's c */
  15. extern char hmask[]; /* the random masks */
  16. #define HASHMASK (HASHSIZE-1) /* since it is a power of 2 */
  17. #define STARTHASH() (0)
  18. #define ENHASH(hs,ch,ps) (hs + (ch ^ hmask[ps]))
  19. #define STOPHASH(hs) (hs & HASHMASK)
  20. struct idstack_item { /* stack of identifiers */
  21. struct idstack_item *next;
  22. struct idf *is_idf;
  23. };
  24. /* allocation definitions of struct idstack_item */
  25. /* ALLOCDEF "idstack_item" */
  26. extern char *st_alloc();
  27. extern struct idstack_item *h_idstack_item;
  28. #define new_idstack_item() ((struct idstack_item *) \
  29. st_alloc((char **)&h_idstack_item, sizeof(struct idstack_item)))
  30. #define free_idstack_item(p) st_free(p, h_idstack_item, sizeof(struct idstack_item))
  31. struct idf {
  32. struct idf *next;
  33. char *id_text;
  34. #ifndef NOPP
  35. struct macro *id_macro;
  36. int id_resmac; /* if nonzero: keyword of macroproc. */
  37. #endif NOPP
  38. int id_reserved; /* non-zero for reserved words */
  39. struct def *id_def; /* variables, typedefs, enum-constants */
  40. struct sdef *id_sdef; /* selector tags */
  41. struct tag *id_struct; /* struct and union tags */
  42. struct tag *id_enum; /* enum tags */
  43. int id_special; /* special action needed at occurrence */
  44. };
  45. /* allocation definitions of struct idf */
  46. /* ALLOCDEF "idf" */
  47. extern char *st_alloc();
  48. extern struct idf *h_idf;
  49. #define new_idf() ((struct idf *) \
  50. st_alloc((char **)&h_idf, sizeof(struct idf)))
  51. #define free_idf(p) st_free(p, h_idf, sizeof(struct idf))
  52. extern struct idf *str2idf(), *idf_hashed();
  53. extern int level;
  54. extern struct idf *gen_idf();