|
|
1.1 root 1: *** /tmp/,RCSt1a12446 Tue Nov 7 09:28:11 1989
2: --- /tmp/,RCSt2a12446 Tue Nov 7 09:28:14 1989
3: ***************
4: *** 2,8 ****
5: /*ident "@(#)ctrans:src/expr.c 1.1.5.30" */
6: /*
7: $Source: /usr3/lang/benson/work/stripped_cfront/O/RCS/expr.c,v $ $RCSfile: expr.c,v $
8: ! $Revision: 1.12 $ $Date: 89/10/10 08:39:50 $
9: $Author: benson $ $Locker: $
10: $State: Exp $
11: */
12: --- 2,8 ----
13: /*ident "@(#)ctrans:src/expr.c 1.1.5.30" */
14: /*
15: $Source: /usr3/lang/benson/work/stripped_cfront/O/RCS/expr.c,v $ $RCSfile: expr.c,v $
16: ! $Revision: 1.15 $ $Date: 89/10/20 14:29:13 $
17: $Author: benson $ $Locker: $
18: $State: Exp $
19: */
20: ***************
21: *** 166,171 ****
22: --- 166,172 ----
23: extern ignore_const;
24: extern int logical_context;
25: extern ref_initializer;
26: + extern int refd;
27:
28: class expr_undo : public basic_undo {
29: extended_error_state * ees;
30: ***************
31: *** 176,181 ****
32: --- 177,186 ----
33: int ref_cast;
34: int logical_context;
35: int ref_initializer;
36: + dcl_context * cc;
37: + int refd;
38: + int extended_error_state_stack_ptr;
39: +
40: public:
41: expr_undo (Pexpr msg_expr) {
42: doing_index_maint = :: doing_index_maint;
43: ***************
44: *** 185,190 ****
45: --- 190,198 ----
46: ref_cast = :: ref_cast;
47: ref_initializer = :: ref_initializer;
48: logical_context = :: logical_context;
49: + cc = :: cc;
50: + refd = :: refd;
51: + extended_error_state_stack_ptr = extended_error_state::stack_ptr;
52: if(msg_expr) ees = extended_error_state::push(msg_expr);
53: };
54: virtual ~expr_undo () {
55: ***************
56: *** 195,201 ****
57: :: ref_cast = ref_cast;
58: :: ref_initializer = ref_initializer;
59: :: logical_context = logical_context;
60: ! if(ees) extended_error_state::pop ();
61: };
62: };
63:
64: --- 203,211 ----
65: :: ref_cast = ref_cast;
66: :: ref_initializer = ref_initializer;
67: :: logical_context = logical_context;
68: ! :: cc = cc;
69: ! :: refd = refd;
70: ! extended_error_state::pop_to(extended_error_state_stack_ptr);
71: };
72: };
73:
74: ***************
75: *** 203,213 ****
76: public:
77: static int level;
78: expr_undo0 () { level ++; };
79: ! ~expr_undo0 () { level --; };
80: };
81:
82: int expr_undo0::level = 0;
83:
84: Pexpr expr::typ (Ptable tbl)
85: {
86: Pexpr original;
87: --- 213,263 ----
88: public:
89: static int level;
90: expr_undo0 () { level ++; };
91: ! virtual ~expr_undo0 () { level --; };
92: };
93:
94: int expr_undo0::level = 0;
95:
96: + int in_expr_typ ()
97: + {
98: + return expr_undo0::level > 0;
99: + }
100: +
101: + extern Pname indexable_member_reference (Pexpr, int);
102: +
103: + Ptype add_idx_or_const_to_type(Ptype t, int cnst, int idx)
104: + {
105: + if(cnst) idx = 0; /* const is stronger, we never bother to add both */
106: +
107: + switch(t->base) {
108: + case RPTR:
109: + if(idx) err::print ('i', "Indexable REFERENCE. Not supported.");
110: + Pptr(t)->rdo = cnst;
111: + return t;
112: + case VEC:
113: + if(idx) err::print ('i', "Indexable VECTOR. Not supported.");
114: + return t; /* already const, can't be indexable */
115: + case PTR:
116: + Pptr p = Pptr(t);
117: + Pptr np = new ptr(p->base, p->typ);
118: + *np = *p;
119: + np->rdo = cnst;
120: + np->rdo_indexable = idx;
121: + return np;
122: + case FCT:
123: + case OVERLOAD:
124: + return t; /* should never get called on one of these,
125: + but don't take chances */
126: + default:
127: + Pbase b = Pbase(t);
128: + Pbase nb = new basetype (0, 0);
129: + *nb = *b;
130: + nb->b_const = cnst;
131: + nb->b_indexable = idx;
132: + return nb;
133: + }
134: + }
135: +
136: Pexpr expr::typ (Ptable tbl)
137: {
138: Pexpr original;
139: ***************
140: *** 230,235 ****
141: --- 280,286 ----
142: expr_undo Undo (this);
143: return_value = typ0(tbl);
144: }
145: +
146: if(original) dcl_capture::expr_typ(original, return_value);
147: return return_value;
148: }
149: ***************
150: *** 710,719 ****
151: }
152: }
153:
154: - /*
155: - x.m is not a const even if x is a const object, this case is handled
156: - by lval() rejecting it
157: - */
158:
159: if (mem->tp) {
160: tp = mem->tp;
161: --- 761,766 ----
162: ***************
163: *** 752,758 ****
164: }
165: }
166: /* function or static member */
167: ! return e->tp->base == RPTR ? e->contents() : e;
168: }
169:
170: /*?? case G_CALL: */
171: --- 799,831 ----
172: }
173: }
174: /* function or static member */
175: ! Pexpr result = e->tp->base == RPTR ? e->contents() : e;
176: !
177: ! /* Now propagate const from the LHS to the result */
178: !
179: ! /* can't have fct or vec as e1 of DOT or REF */
180: ! int e1_const = e1 && e1->tp->tconst(const_const);
181: ! int e1_idx = e1 && e1->tp->tconst(const_idx);
182: ! Pptr e1_ptr;
183: ! if (e1 && e1->tp) e1_ptr = e1->tp->is_ptr ();
184: ! /* const foo * C; C->bar; is a const */
185: ! int e1_pt_const = e1_ptr && e1_ptr->typ->tconst (const_const);
186: !
187: ! /* if something is const without indexable,
188: ! there is no earthly reason to propagage indexable
189: ! since const is the stronger restriction. */
190: !
191: ! if((e1_const && base == DOT) || e1_pt_const)
192: ! result->tp = add_idx_or_const_to_type(result->tp, 1, 0);
193: ! else if(e1_idx)
194: ! result->tp = add_idx_or_const_to_type(result->tp, 0, 1);
195: ! /* an indexable member can be ->'ed, but something
196: ! that inherited indexable cannot be ->'ed */
197: ! else if (indexable_member_reference(result, 0) && base == DOT
198: ! && !doing_index_maint)
199: ! result->tp = add_idx_or_const_to_type(result->tp, 0, 1);
200: !
201: ! return result;
202: }
203:
204: /*?? case G_CALL: */
205: ***************
206: *** 1100,1110 ****
207: }
208: }
209:
210: if (tp->is_ref())
211: ! return contents();
212:
213: ! return this;
214:
215: case G_ADDROF:
216: case ADDROF:
217: /*error('d',"addrof(%d) %k %d",base,e2->base,e2->base); */
218: --- 1173,1190 ----
219: }
220: }
221:
222: + Pexpr result;
223: if (tp->is_ref())
224: ! result = contents();
225: ! else result = this;
226:
227: ! /* For a deref, if the ptr dereffed is indexable,
228: ! the result is also indexable. But const is not carried. */
229: ! if(e1 && e1->tp->tconst(const_idx))
230: ! result->tp = add_idx_or_const_to_type(result->tp, 0, 1);
231:
232: + return result;
233: +
234: case G_ADDROF:
235: case ADDROF:
236: /*error('d',"addrof(%d) %k %d",base,e2->base,e2->base); */
237: ***************
238: *** 1906,1916 ****
239: }
240:
241:
242: ! static char rcsinfo[] = "$Header: /usr3/lang/benson/work/stripped_cfront/O/RCS/expr.c,v 1.12 89/10/10 08:39:50 benson Exp $";
243:
244:
245:
246: /* $Log: expr.c,v $
247: * Revision 1.12 89/10/10 08:39:50 benson
248: * tix error handler for malformed expressions.
249: *
250: --- 1986,2005 ----
251: }
252:
253:
254: ! static char rcsinfo[] = "$Header: /usr3/lang/benson/work/stripped_cfront/O/RCS/expr.c,v 1.15 89/10/20 14:29:13 benson Exp $";
255:
256:
257:
258: /* $Log: expr.c,v $
259: + * Revision 1.15 89/10/20 14:29:13 benson
260: + * get const and indexable propagation closer to right.
261: + *
262: + * Revision 1.14 89/10/16 08:14:09 benson
263: + * support for prohibiting some assignments to indexable items.
264: + *
265: + * Revision 1.13 89/10/11 15:55:34 benson
266: + * enforce enherited const. enforce restrictions on indexable data members.,
267: + *
268: * Revision 1.12 89/10/10 08:39:50 benson
269: * tix error handler for malformed expressions.
270: *
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.