0
|
1 module dmd.SuperExp;
|
|
2
|
|
3 import dmd.Expression;
|
|
4 import dmd.OutBuffer;
|
|
5 import dmd.Loc;
|
|
6 import dmd.Scope;
|
|
7 import dmd.InlineCostState;
|
|
8 import dmd.InlineDoState;
|
|
9 import dmd.FuncDeclaration;
|
|
10 import dmd.ClassDeclaration;
|
|
11 import dmd.Dsymbol;
|
|
12 import dmd.HdrGenState;
|
|
13 import dmd.ThisExp;
|
|
14 import dmd.TOK;
|
|
15 import dmd.CSX;
|
|
16 import dmd.Type;
|
|
17
|
|
18 class SuperExp : ThisExp
|
|
19 {
|
|
20 this(Loc loc)
|
|
21 {
|
|
22 super(loc);
|
|
23 op = TOK.TOKsuper;
|
|
24 }
|
|
25
|
|
26 Expression semantic(Scope sc)
|
|
27 {
|
|
28 FuncDeclaration fd;
|
|
29 FuncDeclaration fdthis;
|
|
30
|
|
31 version (LOGSEMANTIC) {
|
|
32 printf("SuperExp.semantic('%s')\n", toChars());
|
|
33 }
|
|
34 if (type)
|
|
35 return this;
|
|
36
|
|
37 /* Special case for typeof(this) and typeof(super) since both
|
|
38 * should work even if they are not inside a non-static member function
|
|
39 */
|
|
40 if (sc.intypeof)
|
|
41 {
|
|
42 // Find enclosing class
|
|
43 for (Dsymbol s = sc.parent; 1; s = s.parent)
|
|
44 {
|
|
45 ClassDeclaration cd;
|
|
46
|
|
47 if (!s)
|
|
48 {
|
|
49 error("%s is not in a class scope", toChars());
|
|
50 goto Lerr;
|
|
51 }
|
|
52 cd = s.isClassDeclaration();
|
|
53 if (cd)
|
|
54 {
|
|
55 cd = cd.baseClass;
|
|
56 if (!cd)
|
|
57 {
|
|
58 error("class %s has no 'super'", s.toChars());
|
|
59 goto Lerr;
|
|
60 }
|
|
61 type = cd.type;
|
|
62 return this;
|
|
63 }
|
|
64 }
|
|
65 }
|
|
66
|
|
67 fdthis = sc.parent.isFuncDeclaration();
|
|
68 fd = hasThis(sc);
|
|
69 if (!fd)
|
|
70 goto Lerr;
|
|
71 assert(fd.vthis);
|
|
72 var = fd.vthis;
|
|
73 assert(var.parent);
|
|
74
|
|
75 Dsymbol s = fd.toParent();
|
|
76 while (s && s.isTemplateInstance())
|
|
77 s = s.toParent();
|
|
78 assert(s);
|
|
79 ClassDeclaration cd = s.isClassDeclaration();
|
|
80 //printf("parent is %s %s\n", fd.toParent().kind(), fd.toParent().toChars());
|
|
81 if (!cd)
|
|
82 goto Lerr;
|
|
83 if (!cd.baseClass)
|
|
84 {
|
|
85 error("no base class for %s", cd.toChars());
|
|
86 type = fd.vthis.type;
|
|
87 }
|
|
88 else
|
|
89 {
|
|
90 type = cd.baseClass.type;
|
|
91 }
|
|
92
|
|
93 var.isVarDeclaration().checkNestedReference(sc, loc);
|
|
94
|
|
95 if (!sc.intypeof)
|
|
96 sc.callSuper |= CSXsuper;
|
|
97 return this;
|
|
98
|
|
99 Lerr:
|
|
100 error("'super' is only allowed in non-static class member functions");
|
|
101 type = Type.tint32;
|
|
102 return this;
|
|
103 }
|
|
104
|
|
105 void toCBuffer(OutBuffer buf, HdrGenState* hgs)
|
|
106 {
|
|
107 assert(false);
|
|
108 }
|
|
109
|
|
110 void scanForNestedRef(Scope sc)
|
|
111 {
|
|
112 assert(false);
|
|
113 }
|
|
114
|
|
115 int inlineCost(InlineCostState* ics)
|
|
116 {
|
|
117 assert(false);
|
|
118 }
|
|
119
|
|
120 Expression doInline(InlineDoState ids)
|
|
121 {
|
|
122 assert(false);
|
|
123 }
|
|
124 }
|
|
125
|