annotate dmd/CtorDeclaration.d @ 187:b0d41ff5e0df

Added expandability scheme outlined in http://www.dsource.org/forums/viewtopic.php?t=5659&sid=6f2150ff5b0bffcd47512a6a7608d218
author Abscissa
date Tue, 07 Jun 2011 23:37:34 -0400
parents cd48cb899aee
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1 module dmd.CtorDeclaration;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2
114
e28b18c23469 added a module dmd.common for commonly used stuff
Trass3r
parents: 72
diff changeset
3 import dmd.common;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4 import dmd.FuncDeclaration;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5 import dmd.ArrayTypes;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6 import dmd.Loc;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
7 import dmd.Dsymbol;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
8 import dmd.Scope;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
9 import dmd.OutBuffer;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
10 import dmd.HdrGenState;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
11 import dmd.STC;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
12 import dmd.AggregateDeclaration;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
13 import dmd.TypeFunction;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
14 import dmd.Type;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
15 import dmd.Global;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
16 import dmd.LINK;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
17 import dmd.Expression;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
18 import dmd.ThisExp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
19 import dmd.Statement;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
20 import dmd.ReturnStatement;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
21 import dmd.CompoundStatement;
130
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 114
diff changeset
22 import dmd.Parameter;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
23 import dmd.Id;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
24
187
b0d41ff5e0df Added expandability scheme outlined in http://www.dsource.org/forums/viewtopic.php?t=5659&sid=6f2150ff5b0bffcd47512a6a7608d218
Abscissa
parents: 179
diff changeset
25 import dmd.DDMDExtensions;
b0d41ff5e0df Added expandability scheme outlined in http://www.dsource.org/forums/viewtopic.php?t=5659&sid=6f2150ff5b0bffcd47512a6a7608d218
Abscissa
parents: 179
diff changeset
26
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
27 class CtorDeclaration : FuncDeclaration
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
28 {
187
b0d41ff5e0df Added expandability scheme outlined in http://www.dsource.org/forums/viewtopic.php?t=5659&sid=6f2150ff5b0bffcd47512a6a7608d218
Abscissa
parents: 179
diff changeset
29 mixin insertMemberExtension!(typeof(this));
b0d41ff5e0df Added expandability scheme outlined in http://www.dsource.org/forums/viewtopic.php?t=5659&sid=6f2150ff5b0bffcd47512a6a7608d218
Abscissa
parents: 179
diff changeset
30
130
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 114
diff changeset
31 Parameters arguments;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
32 int varargs;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
33
130
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 114
diff changeset
34 this(Loc loc, Loc endloc, Parameters arguments, int varargs)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
35 {
178
e3afd1303184 Many small bugs fixed
korDen
parents: 130
diff changeset
36 register();
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
37 super(loc, endloc, Id.ctor, STC.STCundefined, null);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
38
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
39 this.arguments = arguments;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
40 this.varargs = varargs;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
41 //printf("CtorDeclaration(loc = %s) %s\n", loc.toChars(), toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
42 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
43
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 49
diff changeset
44 override Dsymbol syntaxCopy(Dsymbol)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
45 {
49
0aa7d1437ada AttribDeclaration.oneMember
korDen
parents: 0
diff changeset
46 CtorDeclaration f = new CtorDeclaration(loc, endloc, null, varargs);
0aa7d1437ada AttribDeclaration.oneMember
korDen
parents: 0
diff changeset
47
0aa7d1437ada AttribDeclaration.oneMember
korDen
parents: 0
diff changeset
48 f.outId = outId;
0aa7d1437ada AttribDeclaration.oneMember
korDen
parents: 0
diff changeset
49 f.frequire = frequire ? frequire.syntaxCopy() : null;
0aa7d1437ada AttribDeclaration.oneMember
korDen
parents: 0
diff changeset
50 f.fensure = fensure ? fensure.syntaxCopy() : null;
0aa7d1437ada AttribDeclaration.oneMember
korDen
parents: 0
diff changeset
51 f.fbody = fbody ? fbody.syntaxCopy() : null;
0aa7d1437ada AttribDeclaration.oneMember
korDen
parents: 0
diff changeset
52 assert(!fthrows); // deprecated
0aa7d1437ada AttribDeclaration.oneMember
korDen
parents: 0
diff changeset
53
130
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 114
diff changeset
54 f.arguments = Parameter.arraySyntaxCopy(arguments);
49
0aa7d1437ada AttribDeclaration.oneMember
korDen
parents: 0
diff changeset
55 return f;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
56 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
57
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 49
diff changeset
58 override void semantic(Scope sc)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
59 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
60 //printf("CtorDeclaration.semantic() %s\n", toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
61 sc = sc.push();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
62 sc.stc &= ~STCstatic; // not a static constructor
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
63
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
64 parent = sc.parent;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
65 Dsymbol parent = toParent2();
179
cd48cb899aee Updated to dmd2.040
korDen
parents: 178
diff changeset
66 Type tret;
cd48cb899aee Updated to dmd2.040
korDen
parents: 178
diff changeset
67 AggregateDeclaration ad = parent.isAggregateDeclaration();
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
68 if (!ad || parent.isUnionDeclaration())
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
69 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
70 error("constructors are only for class or struct definitions");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
71 tret = Type.tvoid;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
72 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
73 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
74 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
75 tret = ad.handle;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
76 assert(tret);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
77 }
179
cd48cb899aee Updated to dmd2.040
korDen
parents: 178
diff changeset
78 if (!type)
cd48cb899aee Updated to dmd2.040
korDen
parents: 178
diff changeset
79 type = new TypeFunction(arguments, tret, varargs, LINKd);
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
80
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
81 version (STRUCTTHISREF) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
82 if (ad && ad.isStructDeclaration())
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
83 (cast(TypeFunction)type).isref = true;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
84 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
85 if (!originalType)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
86 originalType = type;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
87
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
88 sc.flags |= SCOPE.SCOPEctor;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
89 type = type.semantic(loc, sc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
90 sc.flags &= ~SCOPE.SCOPEctor;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
91
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
92 // Append:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
93 // return this;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
94 // to the function body
179
cd48cb899aee Updated to dmd2.040
korDen
parents: 178
diff changeset
95 if (fbody && semanticRun < PASSsemantic)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
96 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
97 Expression e = new ThisExp(loc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
98 Statement s = new ReturnStatement(loc, e);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
99 fbody = new CompoundStatement(loc, fbody, s);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
100 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
101
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
102 FuncDeclaration.semantic(sc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
103
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
104 sc.pop();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
105
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
106 // See if it's the default constructor
130
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 114
diff changeset
107 if (ad && varargs == 0 && Parameter.dim(arguments) == 0)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
108 { if (ad.isStructDeclaration())
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
109 error("default constructor not allowed for structs");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
110 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
111 ad.defaultCtor = this;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
112 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
113 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
114
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 49
diff changeset
115 override void toCBuffer(OutBuffer buf, HdrGenState* hgs)
0
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
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 49
diff changeset
120 override string kind()
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
121 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
122 return "constructor";
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
123 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
124
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 49
diff changeset
125 override string toChars()
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
126 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
127 return "this";
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
128 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
129
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 49
diff changeset
130 override bool isVirtual()
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
131 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
132 return false;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
133 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
134
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 49
diff changeset
135 override bool addPreInvariant()
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
136 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
137 return false;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
138 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
139
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 49
diff changeset
140 override bool addPostInvariant()
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
141 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
142 return (isThis() && vthis && global.params.useInvariants);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
143 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
144
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 49
diff changeset
145 override void toDocBuffer(OutBuffer buf)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
146 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
147 assert(false);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
148 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
149
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 49
diff changeset
150 override CtorDeclaration isCtorDeclaration() { return this; }
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 49
diff changeset
151 }