Pristine Ack-5.5
[Ack-5.5.git] / lang / cem / cemcom / 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 3.16 1994/06/24 12:03:42 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 #include        "nofloat.h"
13
14 /* classes of value */
15 #define Const   1
16 #define Name    2
17 #define Label   3
18
19 struct value    {
20         int vl_class;           /* Const, Name or Label */
21         arith vl_value;         /* constant value or offset */
22         union {
23                 struct idf *vl_idf;     /* external name */
24                 label vl_lbl;           /* compiler-generated label */
25         } vl_data;
26 };
27
28 struct string   {
29         char *sg_value;         /* row of bytes repr. the constant */
30         int sg_len;             /* length of the row */
31         label sg_datlab;        /* global data-label                    */
32 };
33
34 #ifndef NOFLOAT
35 struct floating {
36         char *fl_value;         /* pointer to string repr. the fp const. */
37         label fl_datlab;        /* global data_label    */
38 };
39 #endif /* NOFLOAT */
40
41 struct oper     {
42         struct type *op_type;   /* resulting type of the operation      */
43         struct expr *op_left;
44         int op_oper;                    /* the symbol of the operator   */
45         struct expr *op_right;
46 };
47
48 /* The following constants indicate the class of the expression: */
49 #define Value   0               /* it is a value known at load time */
50 #define String  1               /* it is a string constant  */
51 #ifndef NOFLOAT
52 #define Float   2               /* it is a floating point constant      */
53 #endif /* NOFLOAT */
54 #define Oper    3               /* it is a run-time expression */
55 #define Type    4               /* only its type is relevant */
56
57 struct expr     {
58         struct expr *next;
59         char *ex_file;          /* the file it (probably) comes from */
60         unsigned int ex_line;   /* the line it (probably) comes from */
61         struct type *ex_type;
62         char ex_lvalue;
63         char ex_flags;
64         int ex_class;
65         int ex_depth;
66         union   {
67                 struct value ex_value;
68                 struct string ex_string;
69 #ifndef NOFLOAT
70                 struct floating ex_float;
71 #endif /* NOFLOAT */
72                 struct oper ex_oper;
73         } ex_object;
74 };
75
76 /* some abbreviated selections  */
77 #define EX_VALUE        ex_object.ex_value
78 #define VL_CLASS        EX_VALUE.vl_class
79 #define VL_VALUE        EX_VALUE.vl_value
80 #define VL_IDF          EX_VALUE.vl_data.vl_idf
81 #define VL_LBL          EX_VALUE.vl_data.vl_lbl
82 #define SG_VALUE        ex_object.ex_string.sg_value
83 #define SG_LEN          ex_object.ex_string.sg_len
84 #define SG_DATLAB       ex_object.ex_string.sg_datlab
85 #ifndef NOFLOAT
86 #define FL_VALUE        ex_object.ex_float.fl_value
87 #define FL_DATLAB       ex_object.ex_float.fl_datlab
88 #endif /* NOFLOAT */
89 #define OP_TYPE         ex_object.ex_oper.op_type
90 #define OP_LEFT         ex_object.ex_oper.op_left
91 #define OP_OPER         ex_object.ex_oper.op_oper
92 #define OP_RIGHT        ex_object.ex_oper.op_right
93
94 /*      some bits for the ex_flag field, to keep track of various
95         interesting properties of an expression.
96 */
97 #define EX_SIZEOF       0001            /* contains sizeof operator */
98 #define EX_CAST         0002            /* contains cast */
99 #define EX_LOGICAL      0004            /* contains logical operator */
100 #define EX_COMMA        0010            /* contains expression comma */
101 #define EX_PARENS       0020            /* the top level is parenthesized */
102 #define EX_SIDEEFFECTS  0040            /* expression has side effects */
103 #define EX_ERROR        0200            /* the expression is wrong */
104
105 #define NILEXPR         ((struct expr *)0)
106
107 /* some useful tests */
108 #define ISNAME(e)       ((e)->ex_class == Value && (e)->VL_CLASS == Name)
109 #define ISCOMMA(e)      ((e)->ex_class == Oper && (e)->OP_OPER == INITCOMMA)
110
111 extern struct expr *intexpr(), *new_oper();
112
113 /* ALLOCDEF "expr" 20 */
114