Mercurial > projects > ddmd
annotate dmd/NewAnonClassExp.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 | e3afd1303184 |
children |
rev | line source |
---|---|
72 | 1 module dmd.NewAnonClassExp; |
2 | |
114 | 3 import dmd.common; |
72 | 4 import dmd.Expression; |
5 import dmd.OutBuffer; | |
6 import dmd.Loc; | |
7 import dmd.Scope; | |
8 import dmd.ClassDeclaration; | |
123 | 9 import dmd.DeclarationExp; |
10 import dmd.NewExp; | |
11 import dmd.CommaExp; | |
12 import dmd.PREC; | |
72 | 13 import dmd.HdrGenState; |
0 | 14 import dmd.ArrayTypes; |
72 | 15 import dmd.TOK; |
123 | 16 import dmd.expression.Util; |
72 | 17 |
187
b0d41ff5e0df
Added expandability scheme outlined in http://www.dsource.org/forums/viewtopic.php?t=5659&sid=6f2150ff5b0bffcd47512a6a7608d218
Abscissa
parents:
178
diff
changeset
|
18 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
|
19 |
0 | 20 class NewAnonClassExp : Expression |
21 { | |
187
b0d41ff5e0df
Added expandability scheme outlined in http://www.dsource.org/forums/viewtopic.php?t=5659&sid=6f2150ff5b0bffcd47512a6a7608d218
Abscissa
parents:
178
diff
changeset
|
22 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
|
23 |
0 | 24 /* thisexp.new(newargs) class baseclasses { } (arguments) |
25 */ | |
26 Expression thisexp; // if !NULL, 'this' for class being allocated | |
27 Expressions newargs; // Array of Expression's to call new operator | |
28 ClassDeclaration cd; // class being instantiated | |
29 Expressions arguments; // Array of Expression's to call class constructor | |
30 | |
31 this(Loc loc, Expression thisexp, Expressions newargs, ClassDeclaration cd, Expressions arguments) | |
32 { | |
178 | 33 register(); |
123 | 34 super(loc, TOKnewanonclass, NewAnonClassExp.sizeof); |
35 this.thisexp = thisexp; | |
36 this.newargs = newargs; | |
37 this.cd = cd; | |
38 this.arguments = arguments; | |
0 | 39 } |
40 | |
72 | 41 override Expression syntaxCopy() |
0 | 42 { |
123 | 43 return new NewAnonClassExp(loc, |
44 thisexp ? thisexp.syntaxCopy() : null, | |
45 arraySyntaxCopy(newargs), | |
46 cast(ClassDeclaration)cd.syntaxCopy(null), | |
47 arraySyntaxCopy(arguments)); | |
0 | 48 } |
123 | 49 |
72 | 50 override Expression semantic(Scope sc) |
0 | 51 { |
123 | 52 version (LOGSEMANTIC) { |
53 printf("NewAnonClassExp.semantic() %s\n", toChars()); | |
54 //printf("thisexp = %p\n", thisexp); | |
55 //printf("type: %s\n", type.toChars()); | |
56 } | |
57 | |
58 Expression d = new DeclarationExp(loc, cd); | |
59 d = d.semantic(sc); | |
60 | |
61 Expression n = new NewExp(loc, thisexp, newargs, cd.type, arguments); | |
62 | |
63 Expression c = new CommaExp(loc, d, n); | |
64 return c.semantic(sc); | |
0 | 65 } |
66 | |
72 | 67 override bool checkSideEffect(int flag) |
0 | 68 { |
123 | 69 return true; |
0 | 70 } |
71 | |
154
14feb7ae01a6
* changed the build system to build a release version if the debug one compiles
trass3r
parents:
123
diff
changeset
|
72 override void toCBuffer(OutBuffer buf, HdrGenState* hgs) |
0 | 73 { |
123 | 74 if (thisexp) |
75 { | |
76 expToCBuffer(buf, hgs, thisexp, PREC.PREC_primary); | |
77 buf.writeByte('.'); | |
78 } | |
79 buf.writestring("new"); | |
80 if (newargs && newargs.dim) | |
81 { | |
82 buf.writeByte('('); | |
83 argsToCBuffer(buf, newargs, hgs); | |
84 buf.writeByte(')'); | |
85 } | |
86 buf.writestring(" class "); | |
87 if (arguments && arguments.dim) | |
88 { | |
89 buf.writeByte('('); | |
90 argsToCBuffer(buf, arguments, hgs); | |
91 buf.writeByte(')'); | |
92 } | |
93 //buf.writestring(" { }"); | |
94 if (cd) | |
95 { | |
96 cd.toCBuffer(buf, hgs); | |
97 } | |
0 | 98 } |
99 | |
72 | 100 override bool canThrow() |
0 | 101 { |
123 | 102 return true; |
0 | 103 } |
104 } | |
105 |