expr.str 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  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. /* classes of value */
  7. #define Const 1
  8. #define Name 2
  9. #define Label 3
  10. struct value {
  11. int vl_class; /* Const, Name or Label */
  12. arith vl_value; /* constant value or offset */
  13. union {
  14. struct idf *vl_idf; /* external name */
  15. label vl_lbl; /* compiler-generated label */
  16. } vl_data;
  17. };
  18. struct string {
  19. char *sg_value; /* row of bytes repr. the constant */
  20. int sg_len; /* length of the row */
  21. label sg_datlab; /* global data-label */
  22. };
  23. #ifndef NOFLOAT
  24. struct floating {
  25. char *fl_value; /* pointer to string repr. the fp const. */
  26. label fl_datlab; /* global data_label */
  27. };
  28. #endif NOFLOAT
  29. struct oper {
  30. struct type *op_type; /* resulting type of the operation */
  31. struct expr *op_left;
  32. int op_oper; /* the symbol of the operator */
  33. struct expr *op_right;
  34. };
  35. /* The following constants indicate the class of the expression: */
  36. #define Value 0 /* it is a value known at load time */
  37. #define String 1 /* it is a string constant */
  38. #ifndef NOFLOAT
  39. #define Float 2 /* it is a floating point constant */
  40. #endif NOFLOAT
  41. #define Oper 3 /* it is a run-time expression */
  42. #define Type 4 /* only its type is relevant */
  43. struct expr {
  44. struct expr *next;
  45. char *ex_file; /* the file it (probably) comes from */
  46. unsigned int ex_line; /* the line it (probably) comes from */
  47. struct type *ex_type;
  48. char ex_lvalue;
  49. char ex_flags;
  50. int ex_class;
  51. int ex_depth;
  52. union {
  53. struct value ex_value;
  54. struct string ex_string;
  55. #ifndef NOFLOAT
  56. struct floating ex_float;
  57. #endif NOFLOAT
  58. struct oper ex_oper;
  59. } ex_object;
  60. };
  61. /* some abbreviated selections */
  62. #define VL_CLASS ex_object.ex_value.vl_class
  63. #define VL_VALUE ex_object.ex_value.vl_value
  64. #define VL_IDF ex_object.ex_value.vl_data.vl_idf
  65. #define VL_LBL ex_object.ex_value.vl_data.vl_lbl
  66. #define SG_VALUE ex_object.ex_string.sg_value
  67. #define SG_LEN ex_object.ex_string.sg_len
  68. #define SG_DATLAB ex_object.ex_string.sg_datlab
  69. #ifndef NOFLOAT
  70. #define FL_VALUE ex_object.ex_float.fl_value
  71. #define FL_DATLAB ex_object.ex_float.fl_datlab
  72. #endif NOFLOAT
  73. #define OP_TYPE ex_object.ex_oper.op_type
  74. #define OP_LEFT ex_object.ex_oper.op_left
  75. #define OP_OPER ex_object.ex_oper.op_oper
  76. #define OP_RIGHT ex_object.ex_oper.op_right
  77. /* some bits for the ex_flag field, to keep track of various
  78. interesting properties of an expression.
  79. */
  80. #define EX_SIZEOF 0001 /* contains sizeof operator */
  81. #define EX_CAST 0002 /* contains cast */
  82. #define EX_LOGICAL 0004 /* contains logical operator */
  83. #define EX_COMMA 0010 /* contains expression comma */
  84. #define EX_PARENS 0020 /* the top level is parenthesized */
  85. #define EX_ERROR 0200 /* the expression is wrong */
  86. #define NILEXPR ((struct expr *)0)
  87. extern struct expr *intexpr(), *new_oper();
  88. /* ALLOCDEF "expr" */
  89. #define ISCOMMA(e) ((e)->ex_class == Oper && (e)->OP_OPER == INITCOMMA)