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
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 58
diff changeset
1 module dmd.SuperExp;
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 58
diff changeset
2
114
e28b18c23469 added a module dmd.common for commonly used stuff
Trass3r
parents: 72
diff changeset
3 import dmd.common;
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 58
diff changeset
4 import dmd.Expression;
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 58
diff changeset
5 import dmd.OutBuffer;
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 58
diff changeset
6 import dmd.Loc;
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 58
diff changeset
7 import dmd.Scope;
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 58
diff changeset
8 import dmd.InlineCostState;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
9 import dmd.InlineDoState;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
10 import dmd.FuncDeclaration;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
11 import dmd.ClassDeclaration;
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 58
diff changeset
12 import dmd.Dsymbol;
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 58
diff changeset
13 import dmd.HdrGenState;
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 58
diff changeset
14 import dmd.ThisExp;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
15 import dmd.TOK;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
16 import dmd.CSX;
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 58
diff changeset
17 import dmd.Type;
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 58
diff changeset
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
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
21 class SuperExp : ThisExp
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
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
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
25 this(Loc loc)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
26 {
178
e3afd1303184 Many small bugs fixed
korDen
parents: 163
diff changeset
27 register();
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
28 super(loc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
29 op = TOK.TOKsuper;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
30 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
31
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 58
diff changeset
32 override Expression semantic(Scope sc)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
33 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
34 FuncDeclaration fd;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
35 FuncDeclaration fdthis;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
36
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
37 version (LOGSEMANTIC) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
38 printf("SuperExp.semantic('%s')\n", toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
39 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
40 if (type)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
41 return this;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
42
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
43 /* Special case for typeof(this) and typeof(super) since both
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
44 * should work even if they are not inside a non-static member function
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
45 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
46 if (sc.intypeof)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
47 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
48 // Find enclosing class
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
49 for (Dsymbol s = sc.parent; 1; s = s.parent)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
50 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
51 ClassDeclaration cd;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
52
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
53 if (!s)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
54 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
55 error("%s is not in a class scope", toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
56 goto Lerr;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
57 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
58 cd = s.isClassDeclaration();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
59 if (cd)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
60 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
61 cd = cd.baseClass;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
62 if (!cd)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
63 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
64 error("class %s has no 'super'", s.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
65 goto Lerr;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
66 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
67 type = cd.type;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
68 return this;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
69 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
70 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
71 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
72
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
73 fdthis = sc.parent.isFuncDeclaration();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
74 fd = hasThis(sc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
75 if (!fd)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
76 goto Lerr;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
77 assert(fd.vthis);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
78 var = fd.vthis;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
79 assert(var.parent);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
80
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
81 Dsymbol s = fd.toParent();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
82 while (s && s.isTemplateInstance())
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
83 s = s.toParent();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
84 assert(s);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
85 ClassDeclaration cd = s.isClassDeclaration();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
86 //printf("parent is %s %s\n", fd.toParent().kind(), fd.toParent().toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
87 if (!cd)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
88 goto Lerr;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
89 if (!cd.baseClass)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
90 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
91 error("no base class for %s", cd.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
92 type = fd.vthis.type;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
93 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
94 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
95 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
96 type = cd.baseClass.type;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
97 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
98
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
99 var.isVarDeclaration().checkNestedReference(sc, loc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
100
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
101 if (!sc.intypeof)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
102 sc.callSuper |= CSXsuper;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
103 return this;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
104
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
105 Lerr:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
106 error("'super' is only allowed in non-static class member functions");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
107 type = Type.tint32;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
108 return this;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
109 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
110
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 58
diff changeset
111 override void toCBuffer(OutBuffer buf, HdrGenState* hgs)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
112 {
58
ecf732dfe11e Statement.error
korDen
parents: 0
diff changeset
113 buf.writestring("super");
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
114 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
115
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 58
diff changeset
116 override void scanForNestedRef(Scope sc)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
117 {
163
fe932c1a9563 *.interpret functions implemenation
korDen
parents: 114
diff changeset
118 ThisExp.scanForNestedRef(sc);
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
119 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
120
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 58
diff changeset
121 override int inlineCost(InlineCostState* ics)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
122 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
123 assert(false);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
124 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
125
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 58
diff changeset
126 override Expression doInline(InlineDoState ids)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
127 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
128 assert(false);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
129 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
130 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
131