Mercurial > projects > ddmd
annotate dmd/SuperExp.d @ 192:eb38fdcb3e62 default tip
updated to compile with dmd2.062
author | korDen |
---|---|
date | Sat, 02 Mar 2013 01:25:52 -0800 |
parents | b0d41ff5e0df |
children |
rev | line source |
---|---|
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 | |
187
b0d41ff5e0df
Added expandability scheme outlined in http://www.dsource.org/forums/viewtopic.php?t=5659&sid=6f2150ff5b0bffcd47512a6a7608d218
Abscissa
parents:
178
diff
changeset
|
19 import dmd.DDMDExtensions; |
b0d41ff5e0df
Added expandability scheme outlined in http://www.dsource.org/forums/viewtopic.php?t=5659&sid=6f2150ff5b0bffcd47512a6a7608d218
Abscissa
parents:
178
diff
changeset
|
20 |
0 | 21 class SuperExp : ThisExp |
22 { | |
187
b0d41ff5e0df
Added expandability scheme outlined in http://www.dsource.org/forums/viewtopic.php?t=5659&sid=6f2150ff5b0bffcd47512a6a7608d218
Abscissa
parents:
178
diff
changeset
|
23 mixin insertMemberExtension!(typeof(this)); |
b0d41ff5e0df
Added expandability scheme outlined in http://www.dsource.org/forums/viewtopic.php?t=5659&sid=6f2150ff5b0bffcd47512a6a7608d218
Abscissa
parents:
178
diff
changeset
|
24 |
0 | 25 this(Loc loc) |
26 { | |
178 | 27 register(); |
0 | 28 super(loc); |
29 op = TOK.TOKsuper; | |
30 } | |
31 | |
72 | 32 override Expression semantic(Scope sc) |
0 | 33 { |
34 FuncDeclaration fd; | |
35 FuncDeclaration fdthis; | |
36 | |
37 version (LOGSEMANTIC) { | |
38 printf("SuperExp.semantic('%s')\n", toChars()); | |
39 } | |
40 if (type) | |
41 return this; | |
42 | |
43 /* Special case for typeof(this) and typeof(super) since both | |
44 * should work even if they are not inside a non-static member function | |
45 */ | |
46 if (sc.intypeof) | |
47 { | |
48 // Find enclosing class | |
49 for (Dsymbol s = sc.parent; 1; s = s.parent) | |
50 { | |
51 ClassDeclaration cd; | |
52 | |
53 if (!s) | |
54 { | |
55 error("%s is not in a class scope", toChars()); | |
56 goto Lerr; | |
57 } | |
58 cd = s.isClassDeclaration(); | |
59 if (cd) | |
60 { | |
61 cd = cd.baseClass; | |
62 if (!cd) | |
63 { | |
64 error("class %s has no 'super'", s.toChars()); | |
65 goto Lerr; | |
66 } | |
67 type = cd.type; | |
68 return this; | |
69 } | |
70 } | |
71 } | |
72 | |
73 fdthis = sc.parent.isFuncDeclaration(); | |
74 fd = hasThis(sc); | |
75 if (!fd) | |
76 goto Lerr; | |
77 assert(fd.vthis); | |
78 var = fd.vthis; | |
79 assert(var.parent); | |
80 | |
81 Dsymbol s = fd.toParent(); | |
82 while (s && s.isTemplateInstance()) | |
83 s = s.toParent(); | |
84 assert(s); | |
85 ClassDeclaration cd = s.isClassDeclaration(); | |
86 //printf("parent is %s %s\n", fd.toParent().kind(), fd.toParent().toChars()); | |
87 if (!cd) | |
88 goto Lerr; | |
89 if (!cd.baseClass) | |
90 { | |
91 error("no base class for %s", cd.toChars()); | |
92 type = fd.vthis.type; | |
93 } | |
94 else | |
95 { | |
96 type = cd.baseClass.type; | |
97 } | |
98 | |
99 var.isVarDeclaration().checkNestedReference(sc, loc); | |
100 | |
101 if (!sc.intypeof) | |
102 sc.callSuper |= CSXsuper; | |
103 return this; | |
104 | |
105 Lerr: | |
106 error("'super' is only allowed in non-static class member functions"); | |
107 type = Type.tint32; | |
108 return this; | |
109 } | |
110 | |
72 | 111 override void toCBuffer(OutBuffer buf, HdrGenState* hgs) |
0 | 112 { |
58 | 113 buf.writestring("super"); |
0 | 114 } |
115 | |
72 | 116 override void scanForNestedRef(Scope sc) |
0 | 117 { |
163 | 118 ThisExp.scanForNestedRef(sc); |
0 | 119 } |
120 | |
72 | 121 override int inlineCost(InlineCostState* ics) |
0 | 122 { |
123 assert(false); | |
124 } | |
125 | |
72 | 126 override Expression doInline(InlineDoState ids) |
0 | 127 { |
128 assert(false); | |
129 } | |
130 } | |
131 |