expr.str 3.0 KB

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