annotate dmd/SuperExp.d @ 114:e28b18c23469

added a module dmd.common for commonly used stuff it currently holds code for consistency checking of predefined versions also added a VisualD project file
author Trass3r
date Wed, 01 Sep 2010 18:21:58 +0200
parents 2e2a5c3f943a
children fe932c1a9563
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
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
19 class SuperExp : ThisExp
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
20 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
21 this(Loc loc)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
22 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
23 super(loc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
24 op = TOK.TOKsuper;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
25 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
26
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 58
diff changeset
27 override Expression semantic(Scope sc)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
28 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
29 FuncDeclaration fd;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
30 FuncDeclaration fdthis;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
31
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
32 version (LOGSEMANTIC) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
33 printf("SuperExp.semantic('%s')\n", toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
34 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
35 if (type)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
36 return this;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
37
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
38 /* Special case for typeof(this) and typeof(super) since both
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
39 * should work even if they are not inside a non-static member function
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
40 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
41 if (sc.intypeof)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
42 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
43 // Find enclosing class
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
44 for (Dsymbol s = sc.parent; 1; s = s.parent)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
45 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
46 ClassDeclaration cd;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
47
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
48 if (!s)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
49 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
50 error("%s is not in a class scope", toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
51 goto Lerr;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
52 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
53 cd = s.isClassDeclaration();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
54 if (cd)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
55 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
56 cd = cd.baseClass;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
57 if (!cd)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
58 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
59 error("class %s has no 'super'", s.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
60 goto Lerr;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
61 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
62 type = cd.type;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
63 return this;
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
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
68 fdthis = sc.parent.isFuncDeclaration();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
69 fd = hasThis(sc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
70 if (!fd)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
71 goto Lerr;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
72 assert(fd.vthis);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
73 var = fd.vthis;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
74 assert(var.parent);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
75
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
76 Dsymbol s = fd.toParent();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
77 while (s && s.isTemplateInstance())
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
78 s = s.toParent();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
79 assert(s);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
80 ClassDeclaration cd = s.isClassDeclaration();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
81 //printf("parent is %s %s\n", fd.toParent().kind(), fd.toParent().toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
82 if (!cd)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
83 goto Lerr;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
84 if (!cd.baseClass)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
85 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
86 error("no base class for %s", cd.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
87 type = fd.vthis.type;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
88 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
89 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
90 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
91 type = cd.baseClass.type;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
92 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
93
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
94 var.isVarDeclaration().checkNestedReference(sc, loc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
95
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
96 if (!sc.intypeof)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
97 sc.callSuper |= CSXsuper;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
98 return this;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
99
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
100 Lerr:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
101 error("'super' is only allowed in non-static class member functions");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
102 type = Type.tint32;
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
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 58
diff changeset
106 override void toCBuffer(OutBuffer buf, HdrGenState* hgs)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
107 {
58
ecf732dfe11e Statement.error
korDen
parents: 0
diff changeset
108 buf.writestring("super");
0
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 scanForNestedRef(Scope sc)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
112 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
113 assert(false);
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 int inlineCost(InlineCostState* ics)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
117 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
118 assert(false);
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 Expression doInline(InlineDoState ids)
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 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
126