Mercurial > projects > ddmd
annotate dmd/NewAnonClassExp.d @ 154:14feb7ae01a6
* changed the build system to build a release version if the debug one compiles
and enabled warnings
+ reduced warnings by adding appriopriate overrides
+ IfStatement.interpret()
+ ScopeStatement.interpret()
+ TypeSArray.constConv()
+ TypedefDeclaration.syntaxCopy()
* fixed a bug in StringExp
author | trass3r |
---|---|
date | Wed, 15 Sep 2010 15:32:31 +0200 |
parents | 9e39c7de8438 |
children | e3afd1303184 |
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 |
0 | 18 class NewAnonClassExp : Expression |
19 { | |
20 /* thisexp.new(newargs) class baseclasses { } (arguments) | |
21 */ | |
22 Expression thisexp; // if !NULL, 'this' for class being allocated | |
23 Expressions newargs; // Array of Expression's to call new operator | |
24 ClassDeclaration cd; // class being instantiated | |
25 Expressions arguments; // Array of Expression's to call class constructor | |
26 | |
27 this(Loc loc, Expression thisexp, Expressions newargs, ClassDeclaration cd, Expressions arguments) | |
28 { | |
123 | 29 super(loc, TOKnewanonclass, NewAnonClassExp.sizeof); |
30 this.thisexp = thisexp; | |
31 this.newargs = newargs; | |
32 this.cd = cd; | |
33 this.arguments = arguments; | |
0 | 34 } |
35 | |
72 | 36 override Expression syntaxCopy() |
0 | 37 { |
123 | 38 return new NewAnonClassExp(loc, |
39 thisexp ? thisexp.syntaxCopy() : null, | |
40 arraySyntaxCopy(newargs), | |
41 cast(ClassDeclaration)cd.syntaxCopy(null), | |
42 arraySyntaxCopy(arguments)); | |
0 | 43 } |
123 | 44 |
72 | 45 override Expression semantic(Scope sc) |
0 | 46 { |
123 | 47 version (LOGSEMANTIC) { |
48 printf("NewAnonClassExp.semantic() %s\n", toChars()); | |
49 //printf("thisexp = %p\n", thisexp); | |
50 //printf("type: %s\n", type.toChars()); | |
51 } | |
52 | |
53 Expression d = new DeclarationExp(loc, cd); | |
54 d = d.semantic(sc); | |
55 | |
56 Expression n = new NewExp(loc, thisexp, newargs, cd.type, arguments); | |
57 | |
58 Expression c = new CommaExp(loc, d, n); | |
59 return c.semantic(sc); | |
0 | 60 } |
61 | |
72 | 62 override bool checkSideEffect(int flag) |
0 | 63 { |
123 | 64 return true; |
0 | 65 } |
66 | |
154
14feb7ae01a6
* changed the build system to build a release version if the debug one compiles
trass3r
parents:
123
diff
changeset
|
67 override void toCBuffer(OutBuffer buf, HdrGenState* hgs) |
0 | 68 { |
123 | 69 if (thisexp) |
70 { | |
71 expToCBuffer(buf, hgs, thisexp, PREC.PREC_primary); | |
72 buf.writeByte('.'); | |
73 } | |
74 buf.writestring("new"); | |
75 if (newargs && newargs.dim) | |
76 { | |
77 buf.writeByte('('); | |
78 argsToCBuffer(buf, newargs, hgs); | |
79 buf.writeByte(')'); | |
80 } | |
81 buf.writestring(" class "); | |
82 if (arguments && arguments.dim) | |
83 { | |
84 buf.writeByte('('); | |
85 argsToCBuffer(buf, arguments, hgs); | |
86 buf.writeByte(')'); | |
87 } | |
88 //buf.writestring(" { }"); | |
89 if (cd) | |
90 { | |
91 cd.toCBuffer(buf, hgs); | |
92 } | |
0 | 93 } |
94 | |
72 | 95 override bool canThrow() |
0 | 96 { |
123 | 97 return true; |
0 | 98 } |
99 } | |
100 |