expr.str 3.2 KB

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