expr.h 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. /* $Header$ */
  2. /* EXPRESSION DESCRIPTOR */
  3. /* What we want to define is the struct expr, but since it contains
  4. a union of various goodies, we define them first; so be patient.
  5. */
  6. struct value {
  7. struct idf *vl_idf; /* idf of an external name or 0 */
  8. arith vl_value; /* constant, or offset if idf != 0 */
  9. };
  10. struct string {
  11. char *sg_value; /* string of characters repr. the constant */
  12. label sg_datlab; /* global data-label */
  13. };
  14. struct floating {
  15. char *fl_value; /* pointer to string repr. the fp const. */
  16. label fl_datlab; /* global data_label */
  17. };
  18. struct oper {
  19. struct type *op_type; /* resulting type of the operation */
  20. struct expr *op_left;
  21. int op_oper; /* the symbol of the operator */
  22. struct expr *op_right;
  23. };
  24. /* The following constants indicate the class of the expression: */
  25. #define Value 0 /* it is a value known at load time */
  26. #define String 1 /* it is a string constant */
  27. #define Float 2 /* it is a floating point constant */
  28. #define Oper 3 /* it is a run-time expression */
  29. #define Type 4 /* only its type is relevant */
  30. struct expr {
  31. struct expr *next;
  32. char *ex_file; /* the file it (probably) comes from */
  33. unsigned int ex_line; /* the line it (probably) comes from */
  34. struct type *ex_type;
  35. char ex_lvalue;
  36. char ex_flags;
  37. int ex_class;
  38. int ex_depth;
  39. union {
  40. struct value ex_value;
  41. struct string ex_string;
  42. struct floating ex_float;
  43. struct oper ex_oper;
  44. } ex_object;
  45. };
  46. /* some abbreviated selections */
  47. #define VL_VALUE ex_object.ex_value.vl_value
  48. #define VL_IDF ex_object.ex_value.vl_idf
  49. #define SG_VALUE ex_object.ex_string.sg_value
  50. #define SG_DATLAB ex_object.ex_string.sg_datlab
  51. #define FL_VALUE ex_object.ex_float.fl_value
  52. #define FL_DATLAB ex_object.ex_float.fl_datlab
  53. #define OP_TYPE ex_object.ex_oper.op_type
  54. #define OP_LEFT ex_object.ex_oper.op_left
  55. #define OP_OPER ex_object.ex_oper.op_oper
  56. #define OP_RIGHT ex_object.ex_oper.op_right
  57. #define EXPRTYPE(e) ((e)->ex_type->tp_fund)
  58. /* An expression is a `load-time constant' if it is of the form
  59. <idf> +/- <integral> or <integral>;
  60. it is a `compile-time constant' if it is an <integral>.
  61. */
  62. #define is_ld_cst(e) ((e)->ex_lvalue == 0 && (e)->ex_class == Value)
  63. #define is_cp_cst(e) (is_ld_cst(e) && (e)->VL_IDF == 0)
  64. /* a floating constant expression ?
  65. */
  66. #define is_fp_cst(e) ((e)->ex_class == Float)
  67. /* some bits for the ex_flag field, to keep track of various
  68. interesting properties of an expression.
  69. */
  70. #define EX_SIZEOF 001 /* contains sizeof operator */
  71. #define EX_CAST 002 /* contains cast */
  72. #define EX_LOGICAL 004 /* contains logical operator */
  73. #define EX_COMMA 010 /* contains expression comma */
  74. #define EX_PARENS 020 /* the top level is parenthesized */
  75. #define NILEXPR ((struct expr *)0)
  76. extern struct expr *intexpr(), *new_oper();
  77. /* allocation definitions of struct expr */
  78. /* ALLOCDEF "expr" */
  79. extern char *st_alloc();
  80. extern struct expr *h_expr;
  81. #define new_expr() ((struct expr *) \
  82. st_alloc((char **)&h_expr, sizeof(struct expr)))
  83. #define free_expr(p) st_free(p, h_expr, sizeof(struct expr))
  84. #define ISCOMMA(e) ((e)->ex_class == Oper && (e)->OP_OPER == INITCOMMA)