Mercurial > projects > ddmd
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 |
rev | line source |
---|---|
0 | 1 module dmd.CtorDeclaration; |
2 | |
114 | 3 import dmd.common; |
0 | 4 import dmd.FuncDeclaration; |
5 import dmd.ArrayTypes; | |
6 import dmd.Loc; | |
7 import dmd.Dsymbol; | |
8 import dmd.Scope; | |
9 import dmd.OutBuffer; | |
10 import dmd.HdrGenState; | |
11 import dmd.STC; | |
12 import dmd.AggregateDeclaration; | |
13 import dmd.TypeFunction; | |
14 import dmd.Type; | |
15 import dmd.Global; | |
16 import dmd.LINK; | |
17 import dmd.Expression; | |
18 import dmd.ThisExp; | |
19 import dmd.Statement; | |
20 import dmd.ReturnStatement; | |
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 | 23 import dmd.Id; |
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 | 27 class CtorDeclaration : FuncDeclaration |
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 | 32 int varargs; |
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 | 35 { |
178 | 36 register(); |
0 | 37 super(loc, endloc, Id.ctor, STC.STCundefined, null); |
38 | |
39 this.arguments = arguments; | |
40 this.varargs = varargs; | |
41 //printf("CtorDeclaration(loc = %s) %s\n", loc.toChars(), toChars()); | |
42 } | |
43 | |
72 | 44 override Dsymbol syntaxCopy(Dsymbol) |
0 | 45 { |
49 | 46 CtorDeclaration f = new CtorDeclaration(loc, endloc, null, varargs); |
47 | |
48 f.outId = outId; | |
49 f.frequire = frequire ? frequire.syntaxCopy() : null; | |
50 f.fensure = fensure ? fensure.syntaxCopy() : null; | |
51 f.fbody = fbody ? fbody.syntaxCopy() : null; | |
52 assert(!fthrows); // deprecated | |
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 | 55 return f; |
0 | 56 } |
57 | |
72 | 58 override void semantic(Scope sc) |
0 | 59 { |
60 //printf("CtorDeclaration.semantic() %s\n", toChars()); | |
61 sc = sc.push(); | |
62 sc.stc &= ~STCstatic; // not a static constructor | |
63 | |
64 parent = sc.parent; | |
65 Dsymbol parent = toParent2(); | |
179 | 66 Type tret; |
67 AggregateDeclaration ad = parent.isAggregateDeclaration(); | |
0 | 68 if (!ad || parent.isUnionDeclaration()) |
69 { | |
70 error("constructors are only for class or struct definitions"); | |
71 tret = Type.tvoid; | |
72 } | |
73 else | |
74 { | |
75 tret = ad.handle; | |
76 assert(tret); | |
77 } | |
179 | 78 if (!type) |
79 type = new TypeFunction(arguments, tret, varargs, LINKd); | |
0 | 80 |
81 version (STRUCTTHISREF) { | |
82 if (ad && ad.isStructDeclaration()) | |
83 (cast(TypeFunction)type).isref = true; | |
84 } | |
85 if (!originalType) | |
86 originalType = type; | |
87 | |
88 sc.flags |= SCOPE.SCOPEctor; | |
89 type = type.semantic(loc, sc); | |
90 sc.flags &= ~SCOPE.SCOPEctor; | |
91 | |
92 // Append: | |
93 // return this; | |
94 // to the function body | |
179 | 95 if (fbody && semanticRun < PASSsemantic) |
0 | 96 { |
97 Expression e = new ThisExp(loc); | |
98 Statement s = new ReturnStatement(loc, e); | |
99 fbody = new CompoundStatement(loc, fbody, s); | |
100 } | |
101 | |
102 FuncDeclaration.semantic(sc); | |
103 | |
104 sc.pop(); | |
105 | |
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 | 108 { if (ad.isStructDeclaration()) |
109 error("default constructor not allowed for structs"); | |
110 else | |
111 ad.defaultCtor = this; | |
112 } | |
113 } | |
114 | |
72 | 115 override void toCBuffer(OutBuffer buf, HdrGenState* hgs) |
0 | 116 { |
117 assert(false); | |
118 } | |
119 | |
72 | 120 override string kind() |
0 | 121 { |
122 return "constructor"; | |
123 } | |
124 | |
72 | 125 override string toChars() |
0 | 126 { |
127 return "this"; | |
128 } | |
129 | |
72 | 130 override bool isVirtual() |
0 | 131 { |
132 return false; | |
133 } | |
134 | |
72 | 135 override bool addPreInvariant() |
0 | 136 { |
137 return false; | |
138 } | |
139 | |
72 | 140 override bool addPostInvariant() |
0 | 141 { |
142 return (isThis() && vthis && global.params.useInvariants); | |
143 } | |
144 | |
72 | 145 override void toDocBuffer(OutBuffer buf) |
0 | 146 { |
147 assert(false); | |
148 } | |
149 | |
72 | 150 override CtorDeclaration isCtorDeclaration() { return this; } |
151 } |