annotate dmd/PtrExp.d @ 72:2e2a5c3f943a

reduced warnings by adding override to the methods think this also normalizes different line endings used all over the place
author Trass3r
date Sat, 28 Aug 2010 16:19:48 +0200
parents cab4c37afb89
children e28b18c23469
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
1 module dmd.PtrExp;
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
2
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
3 import dmd.Expression;
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
4 import dmd.Identifier;
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
5 import dmd.backend.elem;
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
6 import dmd.UnaExp;
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
7 import dmd.InterState;
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
8 import dmd.Type;
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
9 import dmd.OutBuffer;
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
10 import dmd.Loc;
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
11 import dmd.Scope;
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
12 import dmd.IRState;
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
13 import dmd.HdrGenState;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
14 import dmd.TOK;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
15 import dmd.GlobalExpressions;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
16 import dmd.SymOffExp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
17 import dmd.AddrExp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
18 import dmd.VarDeclaration;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
19 import dmd.StructLiteralExp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
20 import dmd.TypePointer;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
21 import dmd.TypeArray;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
22 import dmd.ErrorExp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
23 import dmd.TY;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
24 import dmd.expression.Ptr;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
25 import dmd.expression.Util;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
26
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
27 import dmd.backend.Util;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
28 import dmd.backend.TYM;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
29 import dmd.backend.mTY;
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
30 import dmd.backend.OPER;
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
31
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
32 class PtrExp : UnaExp
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
33 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
34 this(Loc loc, Expression e)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
35 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
36 super(loc, TOK.TOKstar, PtrExp.sizeof, e);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
37 // if (e.type)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
38 // type = ((TypePointer *)e.type).next;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
39 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
40
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
41 this(Loc loc, Expression e, Type t)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
42 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
43 super(loc, TOKstar, PtrExp.sizeof, e);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
44 type = t;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
45 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
46
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
47 override Expression semantic(Scope sc)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
48 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
49 version (LOGSEMANTIC) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
50 printf("PtrExp::semantic('%s')\n", toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
51 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
52 if (!type)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
53 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
54 UnaExp.semantic(sc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
55 e1 = resolveProperties(sc, e1);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
56 if (!e1.type)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
57 writef("PtrExp.semantic('%s')\n", toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
58 Expression e = op_overload(sc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
59 if (e)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
60 return e;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
61 Type tb = e1.type.toBasetype();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
62 switch (tb.ty)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
63 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
64 case Tpointer:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
65 type = (cast(TypePointer)tb).next;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
66 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
67
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
68 case Tsarray:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
69 case Tarray:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
70 type = (cast(TypeArray)tb).next;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
71 e1 = e1.castTo(sc, type.pointerTo());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
72 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
73
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
74 default:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
75 error("can only * a pointer, not a '%s'", e1.type.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
76 return new ErrorExp();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
77 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
78 rvalue();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
79 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
80 return this;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
81 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
82
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
83 override int isLvalue()
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
84 {
61
4ae0d790a452 OnScopeStatement.syntaxCopy
korDen
parents: 0
diff changeset
85 return 1;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
86 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
87
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
88 override Expression toLvalue(Scope sc, Expression e)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
89 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
90 static if (false) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
91 tym = tybasic(e1.ET.Tty);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
92 if (!(tyscalar(tym) ||
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
93 tym == TYstruct ||
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
94 tym == TYarray && e.Eoper == TOKaddr)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
95 )
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
96 synerr(EM_lvalue); // lvalue expected
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
97 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
98 return this;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
99 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
100
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
101 version (DMDV2) {
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
102 override Expression modifiableLvalue(Scope sc, Expression e)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
103 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
104 //printf("PtrExp.modifiableLvalue() %s, type %s\n", toChars(), type.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
105
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
106 if (e1.op == TOKsymoff)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
107 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
108 SymOffExp se = cast(SymOffExp)e1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
109 se.var.checkModify(loc, sc, type);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
110 //return toLvalue(sc, e);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
111 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
112
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
113 return Expression.modifiableLvalue(sc, e);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
114 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
115 }
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
116 override void toCBuffer(OutBuffer buf, HdrGenState* hgs)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
117 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
118 assert(false);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
119 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
120
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
121 override elem* toElem(IRState* irs)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
122 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
123 elem* e;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
124
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
125 //printf("PtrExp::toElem() %s\n", toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
126 e = e1.toElem(irs);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
127 e = el_una(OPER.OPind, type.totym(), e);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
128
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
129 if (tybasic(e.Ety) == TYM.TYstruct)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
130 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
131 e.Enumbytes = cast(uint)type.size();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
132 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
133
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
134 el_setLoc(e,loc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
135 return e;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
136 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
137
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
138 override Expression optimize(int result)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
139 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
140 //printf("PtrExp.optimize(result = x%x) %s\n", result, toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
141 e1 = e1.optimize(result);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
142 // Convert *&ex to ex
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
143 if (e1.op == TOK.TOKaddress)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
144 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
145 Expression e;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
146 Expression ex;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
147
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
148 ex = (cast(AddrExp)e1).e1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
149 if (type.equals(ex.type))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
150 e = ex;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
151 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
152 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
153 e = ex.copy();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
154 e.type = type;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
155 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
156 return e;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
157 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
158 // Constant fold *(&structliteral + offset)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
159 if (e1.op == TOK.TOKadd)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
160 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
161 Expression e;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
162 e = Ptr(type, e1);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
163 if (e !is EXP_CANT_INTERPRET)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
164 return e;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
165 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
166
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
167 if (e1.op == TOK.TOKsymoff)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
168 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
169 SymOffExp se = cast(SymOffExp)e1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
170 VarDeclaration v = se.var.isVarDeclaration();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
171 Expression e = expandVar(result, v);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
172 if (e && e.op == TOK.TOKstructliteral)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
173 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
174 StructLiteralExp sle = cast(StructLiteralExp)e;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
175 e = sle.getField(type, se.offset);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
176 if (e && e !is EXP_CANT_INTERPRET)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
177 return e;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
178 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
179 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
180 return this;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
181 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
182
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
183 override Expression interpret(InterState istate)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
184 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
185 assert(false);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
186 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
187
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
188 override Identifier opId()
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
189 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
190 assert(false);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
191 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
192 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
193