Mercurial > projects > ddmd
annotate dmd/TypeReturn.d @ 132:c494af1dba80
Fixes for dmd 2.037
author | Eldar Insafutdinov <e.insafutdinov@gmail.com> |
---|---|
date | Fri, 10 Sep 2010 19:14:09 +0100 |
parents | 60bb0fe4563e |
children | e3afd1303184 |
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 { | |
19 super(TY.Treturn, loc); | |
20 } | |
21 | |
22 version (DumbClone) { | |
23 } else { | |
24 Type clone() | |
25 { | |
26 assert(false); | |
27 } | |
28 } | |
29 | |
72 | 30 override Type syntaxCopy() |
0 | 31 { |
32 TypeReturn t = new TypeReturn(loc); | |
33 t.syntaxCopyHelper(this); | |
34 t.mod = mod; | |
35 return t; | |
36 } | |
37 | |
72 | 38 override Dsymbol toDsymbol(Scope sc) |
0 | 39 { |
1 | 40 Type t = semantic(Loc(0), sc); |
41 if (t is this) | |
0 | 42 return null; |
1 | 43 |
0 | 44 return t.toDsymbol(sc); |
45 } | |
46 | |
72 | 47 override Type semantic(Loc loc, Scope sc) |
0 | 48 { |
49 Type t; | |
50 if (!sc.func) | |
51 { | |
52 error(loc, "typeof(return) must be inside function"); | |
53 goto Lerr; | |
54 } | |
55 t = sc.func.type.nextOf(); | |
130
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
114
diff
changeset
|
56 if (!t) |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
114
diff
changeset
|
57 { |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
114
diff
changeset
|
58 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
|
59 goto Lerr; |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
114
diff
changeset
|
60 } |
0 | 61 t = t.addMod(mod); |
62 | |
63 if (idents.dim) | |
64 { | |
65 Dsymbol s = t.toDsymbol(sc); | |
66 for (size_t i = 0; i < idents.dim; i++) | |
67 { | |
68 if (!s) | |
69 break; | |
70 Identifier id = cast(Identifier)idents.data[i]; | |
71 s = s.searchX(loc, sc, id); | |
72 } | |
73 if (s) | |
74 { | |
75 t = s.getType(); | |
76 if (!t) | |
77 { | |
78 error(loc, "%s is not a type", s.toChars()); | |
79 goto Lerr; | |
80 } | |
81 } | |
82 else | |
83 { | |
84 error(loc, "cannot resolve .property for %s", toChars()); | |
85 goto Lerr; | |
86 } | |
87 } | |
88 | |
89 return t; | |
90 | |
91 Lerr: | |
92 return terror; | |
93 } | |
94 | |
72 | 95 override void toCBuffer2(OutBuffer buf, HdrGenState* hgs, MOD mod) |
0 | 96 { |
97 assert(false); | |
98 } | |
72 | 99 } |