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