Pristine Ack-5.5
[Ack-5.5.git] / lang / cem / cemcom.ansi / expr.str
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: expr.str,v 1.7 1994/06/27 07:59:44 ceriel Exp $ */
6 /* EXPRESSION DESCRIPTOR */
7
8 /*      What we want to define is the struct expr, but since it contains
9         a union of various goodies, we define them first; so be patient.
10 */
11
12 /* classes of value */
13 #define Const   1
14 #define Name    2
15 #define Label   3
16
17 struct value    {
18         int vl_class;           /* Const, Name or Label */
19         arith vl_value;         /* constant value or offset */
20         union {
21                 struct idf *vl_idf;     /* external name */
22                 label vl_lbl;           /* compiler-generated label */
23         } vl_data;
24 };
25
26 struct string   {
27         char *sg_value;         /* row of bytes repr. the constant */
28         int sg_len;             /* length of the row */
29 };
30
31 struct oper     {
32         struct type *op_type;   /* resulting type of the operation      */
33         struct expr *op_left;
34         int op_oper;                    /* the symbol of the operator   */
35         struct expr *op_right;
36 };
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
45 struct expr     {
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         short ex_lvalue;
50         short ex_flags;
51         int ex_class;
52         int ex_depth;
53         union   {
54                 struct value ex_value;
55                 struct string ex_string;
56                 flt_arith ex_fl_arith;
57                 struct oper ex_oper;
58         } ex_object;
59 };
60
61 /* some abbreviated selections  */
62 #define EX_VALUE        ex_object.ex_value
63 #define VL_CLASS        EX_VALUE.vl_class
64 #define VL_VALUE        EX_VALUE.vl_value
65 #define VL_IDF          EX_VALUE.vl_data.vl_idf
66 #define VL_LBL          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 FL_ARITH        ex_object.ex_fl_arith
70 #define OP_TYPE         ex_object.ex_oper.op_type
71 #define OP_LEFT         ex_object.ex_oper.op_left
72 #define OP_OPER         ex_object.ex_oper.op_oper
73 #define OP_RIGHT        ex_object.ex_oper.op_right
74
75 /*      some bits for the ex_flag field, to keep track of various
76         interesting properties of an expression.
77 */
78 #define EX_SIZEOF       0x001           /* contains sizeof operator */
79 #define EX_CAST         0x002           /* contains cast */
80 #define EX_LOGICAL      0x004           /* contains logical operator */
81 #define EX_COMMA        0x008           /* contains expression comma */
82 #define EX_PARENS       0x010           /* the top level is parenthesized */
83 #define EX_SIDEEFFECTS  0x020           /* expression has side effects */
84 #define EX_READONLY     0x040           /* read only variabele */
85 #define EX_VOLATILE     0x080           /* volatile variabele */
86 #define EX_ILVALUE      0x100           /* an illegal lvalue e.g. f().x */
87 #define EX_ERROR        0x200           /* the expression is wrong */
88 #define EX_PTRDIFF      0x400           /* subtracting 2 pointers in expr. */
89
90 #define NILEXPR         ((struct expr *)0)
91
92 /* some useful tests */
93 #define ISNAME(e)       ((e)->ex_class == Value && (e)->VL_CLASS == Name)
94 #define ISCOMMA(e)      ((e)->ex_class == Oper && (e)->OP_OPER == INITCOMMA)
95
96 extern struct expr *intexpr(), *new_oper();
97
98 /* ALLOCDEF "expr" 20 */
99