expr.str 3.3 KB

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