annotate dmd/TypeReturn.d @ 182:b64060ab22df

Now compileable with dmd2.050
author korDen
date Sat, 30 Oct 2010 05:05:32 +0400
parents aa70dca07cb0
children b0d41ff5e0df
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1 module dmd.TypeReturn;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2
114
e28b18c23469 added a module dmd.common for commonly used stuff
Trass3r
parents: 72
diff changeset
3 import dmd.common;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4 import dmd.Loc;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5 import dmd.MOD;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6 import dmd.Type;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
7 import dmd.TypeQualified;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
8 import dmd.Scope;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
9 import dmd.Dsymbol;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
10 import dmd.OutBuffer;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
11 import dmd.HdrGenState;
1
5a2059196104 Project build commands update
korDen
parents: 0
diff changeset
12 import dmd.Identifier;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
13 import dmd.TY;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
14
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
15 class TypeReturn : TypeQualified
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
16 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
17 this(Loc loc)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
18 {
178
e3afd1303184 Many small bugs fixed
korDen
parents: 130
diff changeset
19 register();
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
20 super(TY.Treturn, loc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
21 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
22
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 1
diff changeset
23 override Type syntaxCopy()
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
24 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
25 TypeReturn t = new TypeReturn(loc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
26 t.syntaxCopyHelper(this);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
27 t.mod = mod;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
28 return t;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
29 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
30
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 1
diff changeset
31 override Dsymbol toDsymbol(Scope sc)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
32 {
1
5a2059196104 Project build commands update
korDen
parents: 0
diff changeset
33 Type t = semantic(Loc(0), sc);
5a2059196104 Project build commands update
korDen
parents: 0
diff changeset
34 if (t is this)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
35 return null;
1
5a2059196104 Project build commands update
korDen
parents: 0
diff changeset
36
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
37 return t.toDsymbol(sc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
38 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
39
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 1
diff changeset
40 override Type semantic(Loc loc, Scope sc)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
41 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
42 Type t;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
43 if (!sc.func)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
44 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
45 error(loc, "typeof(return) must be inside function");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
46 goto Lerr;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
47 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
48 t = sc.func.type.nextOf();
130
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 114
diff changeset
49 if (!t)
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 114
diff changeset
50 {
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 114
diff changeset
51 error(loc, "cannot use typeof(return) inside function %s with inferred return type", sc.func.toChars());
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 114
diff changeset
52 goto Lerr;
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 114
diff changeset
53 }
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
54 t = t.addMod(mod);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
55
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
56 if (idents.dim)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
57 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
58 Dsymbol s = t.toDsymbol(sc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
59 for (size_t i = 0; i < idents.dim; i++)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
60 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
61 if (!s)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
62 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
63 Identifier id = cast(Identifier)idents.data[i];
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
64 s = s.searchX(loc, sc, id);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
65 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
66 if (s)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
67 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
68 t = s.getType();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
69 if (!t)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
70 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
71 error(loc, "%s is not a type", s.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
72 goto Lerr;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
73 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
74 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
75 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
76 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
77 error(loc, "cannot resolve .property for %s", toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
78 goto Lerr;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
79 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
80 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
81
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
82 return t;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
83
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
84 Lerr:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
85 return terror;
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: 1
diff changeset
88 override void toCBuffer2(OutBuffer buf, HdrGenState* hgs, MOD mod)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
89 {
181
aa70dca07cb0 ArrayExp.toCBuffer and TypeReturn.toCBuffer2
korDen
parents: 178
diff changeset
90 if (mod != this.mod)
aa70dca07cb0 ArrayExp.toCBuffer and TypeReturn.toCBuffer2
korDen
parents: 178
diff changeset
91 {
aa70dca07cb0 ArrayExp.toCBuffer and TypeReturn.toCBuffer2
korDen
parents: 178
diff changeset
92 toCBuffer3(buf, hgs, mod);
aa70dca07cb0 ArrayExp.toCBuffer and TypeReturn.toCBuffer2
korDen
parents: 178
diff changeset
93 return;
aa70dca07cb0 ArrayExp.toCBuffer and TypeReturn.toCBuffer2
korDen
parents: 178
diff changeset
94 }
aa70dca07cb0 ArrayExp.toCBuffer and TypeReturn.toCBuffer2
korDen
parents: 178
diff changeset
95 buf.writestring("typeof(return)");
aa70dca07cb0 ArrayExp.toCBuffer and TypeReturn.toCBuffer2
korDen
parents: 178
diff changeset
96 toCBuffer2Helper(buf, hgs);
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
97 }
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 1
diff changeset
98 }