expr.str 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  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. /* classes of value */
  11. #define Const 1
  12. #define Name 2
  13. #define Label 3
  14. struct value {
  15. int vl_class; /* Const, Name or Label */
  16. arith vl_value; /* constant value or offset */
  17. union {
  18. struct idf *vl_idf; /* external name */
  19. label vl_lbl; /* compiler-generated label */
  20. } vl_data;
  21. };
  22. struct string {
  23. char *sg_value; /* row of bytes repr. the constant */
  24. int sg_len; /* length of the row */
  25. };
  26. struct oper {
  27. struct type *op_type; /* resulting type of the operation */
  28. struct expr *op_left;
  29. int op_oper; /* the symbol of the operator */
  30. struct expr *op_right;
  31. };
  32. /* The following constants indicate the class of the expression: */
  33. #define Value 0 /* it is a value known at load time */
  34. #define String 1 /* it is a string constant */
  35. #define Float 2 /* it is a floating point constant */
  36. #define Oper 3 /* it is a run-time expression */
  37. #define Type 4 /* only its type is relevant */
  38. struct expr {
  39. char *ex_file; /* the file it (probably) comes from */
  40. unsigned int ex_line; /* the line it (probably) comes from */
  41. struct type *ex_type;
  42. short ex_lvalue;
  43. short ex_flags;
  44. int ex_class;
  45. int ex_depth;
  46. union {
  47. struct value ex_value;
  48. struct string ex_string;
  49. flt_arith ex_fl_arith;
  50. struct oper ex_oper;
  51. } ex_object;
  52. };
  53. /* some abbreviated selections */
  54. #define EX_VALUE ex_object.ex_value
  55. #define VL_CLASS EX_VALUE.vl_class
  56. #define VL_VALUE EX_VALUE.vl_value
  57. #define VL_IDF EX_VALUE.vl_data.vl_idf
  58. #define VL_LBL EX_VALUE.vl_data.vl_lbl
  59. #define SG_VALUE ex_object.ex_string.sg_value
  60. #define SG_LEN ex_object.ex_string.sg_len
  61. #define FL_ARITH ex_object.ex_fl_arith
  62. #define OP_TYPE ex_object.ex_oper.op_type
  63. #define OP_LEFT ex_object.ex_oper.op_left
  64. #define OP_OPER ex_object.ex_oper.op_oper
  65. #define OP_RIGHT ex_object.ex_oper.op_right
  66. /* some bits for the ex_flag field, to keep track of various
  67. interesting properties of an expression.
  68. */
  69. #define EX_SIZEOF 0x001 /* contains sizeof operator */
  70. #define EX_CAST 0x002 /* contains cast */
  71. #define EX_LOGICAL 0x004 /* contains logical operator */
  72. #define EX_COMMA 0x008 /* contains expression comma */
  73. #define EX_PARENS 0x010 /* the top level is parenthesized */
  74. #define EX_SIDEEFFECTS 0x020 /* expression has side effects */
  75. #define EX_READONLY 0x040 /* read only variabele */
  76. #define EX_VOLATILE 0x080 /* volatile variabele */
  77. #define EX_ILVALUE 0x100 /* an illegal lvalue e.g. f().x */
  78. #define EX_ERROR 0x200 /* the expression is wrong */
  79. #define EX_PTRDIFF 0x400 /* subtracting 2 pointers in expr. */
  80. #define NILEXPR ((struct expr *)0)
  81. /* some useful tests */
  82. #define ISNAME(e) ((e)->ex_class == Value && (e)->VL_CLASS == Name)
  83. #define ISCOMMA(e) ((e)->ex_class == Oper && (e)->OP_OPER == INITCOMMA)
  84. extern struct expr *intexpr(), *new_oper();
  85. /* ALLOCDEF "expr" 20 */