Mercurial > projects > ddmd
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 |
rev | line source |
---|---|
0 | 1 module dmd.TypeReturn; |
2 | |
114 | 3 import dmd.common; |
0 | 4 import dmd.Loc; |
5 import dmd.MOD; | |
6 import dmd.Type; | |
7 import dmd.TypeQualified; | |
8 import dmd.Scope; | |
9 import dmd.Dsymbol; | |
10 import dmd.OutBuffer; | |
11 import dmd.HdrGenState; | |
1 | 12 import dmd.Identifier; |
0 | 13 import dmd.TY; |
14 | |
15 class TypeReturn : TypeQualified | |
16 { | |
17 this(Loc loc) | |
18 { | |
178 | 19 register(); |
0 | 20 super(TY.Treturn, loc); |
21 } | |
22 | |
72 | 23 override Type syntaxCopy() |
0 | 24 { |
25 TypeReturn t = new TypeReturn(loc); | |
26 t.syntaxCopyHelper(this); | |
27 t.mod = mod; | |
28 return t; | |
29 } | |
30 | |
72 | 31 override Dsymbol toDsymbol(Scope sc) |
0 | 32 { |
1 | 33 Type t = semantic(Loc(0), sc); |
34 if (t is this) | |
0 | 35 return null; |
1 | 36 |
0 | 37 return t.toDsymbol(sc); |
38 } | |
39 | |
72 | 40 override Type semantic(Loc loc, Scope sc) |
0 | 41 { |
42 Type t; | |
43 if (!sc.func) | |
44 { | |
45 error(loc, "typeof(return) must be inside function"); | |
46 goto Lerr; | |
47 } | |
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 | 54 t = t.addMod(mod); |
55 | |
56 if (idents.dim) | |
57 { | |
58 Dsymbol s = t.toDsymbol(sc); | |
59 for (size_t i = 0; i < idents.dim; i++) | |
60 { | |
61 if (!s) | |
62 break; | |
63 Identifier id = cast(Identifier)idents.data[i]; | |
64 s = s.searchX(loc, sc, id); | |
65 } | |
66 if (s) | |
67 { | |
68 t = s.getType(); | |
69 if (!t) | |
70 { | |
71 error(loc, "%s is not a type", s.toChars()); | |
72 goto Lerr; | |
73 } | |
74 } | |
75 else | |
76 { | |
77 error(loc, "cannot resolve .property for %s", toChars()); | |
78 goto Lerr; | |
79 } | |
80 } | |
81 | |
82 return t; | |
83 | |
84 Lerr: | |
85 return terror; | |
86 } | |
87 | |
72 | 88 override void toCBuffer2(OutBuffer buf, HdrGenState* hgs, MOD mod) |
0 | 89 { |
181 | 90 if (mod != this.mod) |
91 { | |
92 toCBuffer3(buf, hgs, mod); | |
93 return; | |
94 } | |
95 buf.writestring("typeof(return)"); | |
96 toCBuffer2Helper(buf, hgs); | |
0 | 97 } |
72 | 98 } |