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