expr.str 2.5 KB

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