annotate dmd/UnaExp.d @ 114:e28b18c23469

added a module dmd.common for commonly used stuff it currently holds code for consistency checking of predefined versions also added a VisualD project file
author Trass3r
date Wed, 01 Sep 2010 18:21:58 +0200
parents 2e2a5c3f943a
children 60bb0fe4563e
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: 64
diff changeset
1 module dmd.UnaExp;
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 64
diff changeset
2
114
e28b18c23469 added a module dmd.common for commonly used stuff
Trass3r
parents: 72
diff changeset
3 import dmd.common;
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 64
diff changeset
4 import dmd.Expression;
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 64
diff changeset
5 import dmd.InterState;
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 64
diff changeset
6 import dmd.TY;
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 64
diff changeset
7 import dmd.TypeClass;
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 64
diff changeset
8 import dmd.TypeStruct;
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 64
diff changeset
9 import dmd.Dsymbol;
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 64
diff changeset
10 import dmd.AggregateDeclaration;
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 64
diff changeset
11 import dmd.Type;
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 64
diff changeset
12 import dmd.OutBuffer;
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 64
diff changeset
13 import dmd.Loc;
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 64
diff changeset
14 import dmd.TOK;
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 64
diff changeset
15 import dmd.Scope;
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 64
diff changeset
16 import dmd.InlineCostState;
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 64
diff changeset
17 import dmd.InlineDoState;
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 64
diff changeset
18 import dmd.HdrGenState;
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 64
diff changeset
19 import dmd.InlineScanState;
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 64
diff changeset
20 import dmd.DotIdExp;
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 64
diff changeset
21 import dmd.ArrayExp;
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 64
diff changeset
22 import dmd.CallExp;
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 64
diff changeset
23 import dmd.PREC;
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 64
diff changeset
24 import dmd.Token;
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 64
diff changeset
25 import dmd.expression.Util;
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 64
diff changeset
26
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
27 class UnaExp : Expression
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
28 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
29 Expression e1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
30
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
31 this(Loc loc, TOK op, int size, Expression e1)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
32 {
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 64
diff changeset
33 super(loc, op, size);
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
34 this.e1 = e1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
35 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
36
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 64
diff changeset
37 override Expression syntaxCopy()
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
38 {
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 64
diff changeset
39 UnaExp e = cast(UnaExp)copy();
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 64
diff changeset
40 e.type = null;
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 64
diff changeset
41 e.e1 = e.e1.syntaxCopy();
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 64
diff changeset
42
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
43 return e;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
44 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
45
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 64
diff changeset
46 override Expression semantic(Scope sc)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
47 {
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 64
diff changeset
48 version (LOGSEMANTIC) {
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 64
diff changeset
49 writef("UnaExp.semantic('%s')\n", toChars());
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 64
diff changeset
50 }
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 64
diff changeset
51 e1 = e1.semantic(sc);
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 64
diff changeset
52 // if (!e1.type)
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 64
diff changeset
53 // error("%s has no value", e1.toChars());
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
54 return this;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
55 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
56
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 64
diff changeset
57 override void toCBuffer(OutBuffer buf, HdrGenState* hgs)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
58 {
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 64
diff changeset
59 buf.writestring(Token.toChars(op));
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
60 expToCBuffer(buf, hgs, e1, precedence[op]);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
61 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
62
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 64
diff changeset
63 override Expression optimize(int result)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
64 {
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 64
diff changeset
65 e1 = e1.optimize(result);
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
66 return this;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
67 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
68
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 64
diff changeset
69 override void dump(int indent)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
70 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
71 assert(false);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
72 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
73
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 64
diff changeset
74 override void scanForNestedRef(Scope sc)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
75 {
64
4290d870944a More fixes
korDen
parents: 63
diff changeset
76 e1.scanForNestedRef(sc);
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
77 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
78
63
cab4c37afb89 A bunch of implementations
korDen
parents: 0
diff changeset
79 Expression interpretCommon(InterState istate, Expression *(*fp)(Type* a0, Expression* a1))
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
80 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
81 assert(false);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
82 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
83
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 64
diff changeset
84 override bool canThrow()
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
85 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
86 return e1.canThrow();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
87 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
88
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 64
diff changeset
89 override int inlineCost(InlineCostState* ics)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
90 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
91 return 1 + e1.inlineCost(ics);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
92 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
93
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 64
diff changeset
94 override Expression doInline(InlineDoState ids)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
95 {
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 64
diff changeset
96 UnaExp ue = cast(UnaExp)copy();
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 64
diff changeset
97
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 64
diff changeset
98 ue.e1 = e1.doInline(ids);
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
99 return ue;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
100 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
101
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 64
diff changeset
102 override Expression inlineScan(InlineScanState* iss)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
103 {
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 64
diff changeset
104 e1 = e1.inlineScan(iss);
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
105 return this;
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 64
diff changeset
106 }
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 64
diff changeset
107
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 64
diff changeset
108 /************************************
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 64
diff changeset
109 * Operator overload.
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 64
diff changeset
110 * Check for operator overload, if so, replace
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 64
diff changeset
111 * with function call.
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 64
diff changeset
112 * Return null if not an operator overload.
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
113 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
114 Expression op_overload(Scope sc)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
115 {
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 64
diff changeset
116 //printf("UnaExp.op_overload() (%s)\n", toChars());
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 64
diff changeset
117 AggregateDeclaration ad;
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 64
diff changeset
118 Dsymbol fd;
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 64
diff changeset
119 Type t1 = e1.type.toBasetype();
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 64
diff changeset
120
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 64
diff changeset
121 if (t1.ty == TY.Tclass)
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 64
diff changeset
122 {
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 64
diff changeset
123 ad = (cast(TypeClass)t1).sym;
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 64
diff changeset
124 goto L1;
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 64
diff changeset
125 }
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 64
diff changeset
126 else if (t1.ty == TY.Tstruct)
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 64
diff changeset
127 {
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 64
diff changeset
128 ad = (cast(TypeStruct)t1).sym;
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 64
diff changeset
129
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 64
diff changeset
130 L1:
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 64
diff changeset
131 fd = search_function(ad, opId());
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 64
diff changeset
132 if (fd)
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 64
diff changeset
133 {
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 64
diff changeset
134 if (op == TOK.TOKarray)
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 64
diff changeset
135 {
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 64
diff changeset
136 /* Rewrite op e1[arguments] as:
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 64
diff changeset
137 * e1.fd(arguments)
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 64
diff changeset
138 */
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 64
diff changeset
139 Expression e = new DotIdExp(loc, e1, fd.ident);
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 64
diff changeset
140 ArrayExp ae = cast(ArrayExp)this;
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 64
diff changeset
141 e = new CallExp(loc, e, ae.arguments);
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 64
diff changeset
142 e = e.semantic(sc);
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 64
diff changeset
143 return e;
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 64
diff changeset
144 }
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 64
diff changeset
145 else
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 64
diff changeset
146 {
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 64
diff changeset
147 // Rewrite +e1 as e1.add()
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 64
diff changeset
148 return build_overload(loc, sc, e1, null, fd.ident);
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 64
diff changeset
149 }
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 64
diff changeset
150 }
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 64
diff changeset
151
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 64
diff changeset
152 version (DMDV2) {
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 64
diff changeset
153 // Didn't find it. Forward to aliasthis
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 64
diff changeset
154 if (ad.aliasthis)
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 64
diff changeset
155 {
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 64
diff changeset
156 /* Rewrite op(e1) as:
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 64
diff changeset
157 * op(e1.aliasthis)
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 64
diff changeset
158 */
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 64
diff changeset
159 Expression e1 = new DotIdExp(loc, this.e1, ad.aliasthis.ident);
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 64
diff changeset
160 Expression e = copy();
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 64
diff changeset
161 (cast(UnaExp)e).e1 = e1;
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 64
diff changeset
162 e = e.semantic(sc);
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 64
diff changeset
163 return e;
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 64
diff changeset
164 }
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 64
diff changeset
165 }
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 64
diff changeset
166 }
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
167 return null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
168 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
169 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
170