annotate dmd/SuperExp.d @ 0:10317f0c89a5

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