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