annotate dmd/ExpInitializer.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 10317f0c89a5
children ef02e2e203c2
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1 module dmd.ExpInitializer;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3 import dmd.Initializer;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4 import dmd.Loc;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5 import dmd.Scope;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6 import dmd.Type;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
7 import dmd.SymOffExp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
8 import dmd.Expression;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
9 import dmd.OutBuffer;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
10 import dmd.HdrGenState;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
11 import dmd.WANT;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
12 import dmd.TOK;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
13 import dmd.StringExp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
14 import dmd.TY;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
15 import dmd.TypeSArray;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
16
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
17 import dmd.backend.dt_t;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
18
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
19 class ExpInitializer : Initializer
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
20 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
21 Expression exp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
22
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
23 this(Loc loc, Expression exp)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
24 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
25 super(loc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
26 this.exp = exp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
27 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
28
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 0
diff changeset
29 override Initializer syntaxCopy()
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
30 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
31 return new ExpInitializer(loc, exp.syntaxCopy());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
32 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
33
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 0
diff changeset
34 override Initializer semantic(Scope sc, Type t)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
35 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
36 //printf("ExpInitializer.semantic(%s), type = %s\n", exp.toChars(), t.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
37 exp = exp.semantic(sc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
38 exp = resolveProperties(sc, exp);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
39 exp = exp.optimize(WANT.WANTvalue | WANT.WANTinterpret);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
40 Type tb = t.toBasetype();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
41
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
42 /* Look for case of initializing a static array with a too-short
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
43 * string literal, such as:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
44 * char[5] foo = "abc";
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
45 * Allow this by doing an explicit cast, which will lengthen the string
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
46 * literal.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
47 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
48 if (exp.op == TOK.TOKstring && tb.ty == TY.Tsarray && exp.type.ty == TY.Tsarray)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
49 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
50 StringExp se = cast(StringExp)exp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
51
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
52 if (!se.committed && se.type.ty == TY.Tsarray && (cast(TypeSArray)se.type).dim.toInteger() < (cast(TypeSArray)t).dim.toInteger())
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
53 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
54 exp = se.castTo(sc, t);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
55 goto L1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
56 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
57 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
58
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
59 // Look for the case of statically initializing an array
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
60 // with a single member.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
61 if (tb.ty == TY.Tsarray && !tb.nextOf().equals(exp.type.toBasetype().nextOf()) && exp.implicitConvTo(tb.nextOf()))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
62 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
63 t = tb.nextOf();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
64 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
65
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
66 exp = exp.implicitCastTo(sc, t);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
67 L1:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
68 exp = exp.optimize(WANT.WANTvalue | WANT.WANTinterpret);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
69 //printf("-ExpInitializer.semantic(): "); exp.print();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
70 return this;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
71 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
72
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 0
diff changeset
73 override Type inferType(Scope sc)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
74 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
75 //printf("ExpInitializer::inferType() %s\n", toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
76 exp = exp.semantic(sc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
77 exp = resolveProperties(sc, exp);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
78
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
79 // Give error for overloaded function addresses
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
80 if (exp.op == TOKsymoff)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
81 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
82 SymOffExp se = cast(SymOffExp)exp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
83 if (se.hasOverloads && !se.var.isFuncDeclaration().isUnique())
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
84 exp.error("cannot infer type from overloaded function symbol %s", exp.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
85 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
86
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
87 Type t = exp.type;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
88 if (!t)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
89 t = Initializer.inferType(sc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
90
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
91 return t;
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: 0
diff changeset
94 override Expression toExpression()
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
95 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
96 return exp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
97 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
98
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 0
diff changeset
99 override void toCBuffer(OutBuffer buf, HdrGenState* hgs)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
100 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
101 assert(false);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
102 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
103
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 0
diff changeset
104 override dt_t* toDt()
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
105 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
106 dt_t* dt = null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
107
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
108 exp = exp.optimize(WANT.WANTvalue);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
109 exp.toDt(&dt);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
110
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
111 return dt;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
112 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
113
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 0
diff changeset
114 override ExpInitializer isExpInitializer() { return this; }
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 0
diff changeset
115 }