Mercurial > projects > ddmd
annotate dmd/UnitTestDeclaration.d @ 178:e3afd1303184
Many small bugs fixed
Made all classes derive from TObject to detect memory leaks (functionality is disabled for now)
Began work on overriding backend memory allocations (to avoid memory leaks)
author | korDen |
---|---|
date | Sun, 17 Oct 2010 07:42:00 +0400 |
parents | e28b18c23469 |
children | cd48cb899aee |
rev | line source |
---|---|
0 | 1 module dmd.UnitTestDeclaration; |
2 | |
114 | 3 import dmd.common; |
0 | 4 import dmd.FuncDeclaration; |
5 import dmd.Loc; | |
6 import dmd.Dsymbol; | |
7 import dmd.AggregateDeclaration; | |
8 import dmd.OutBuffer; | |
9 import dmd.HdrGenState; | |
10 import dmd.Type; | |
11 import dmd.Scope; | |
12 import dmd.Global; | |
13 import dmd.LINK; | |
14 import dmd.TypeFunction; | |
15 import dmd.Module; | |
16 import dmd.STC; | |
17 import dmd.Lexer; | |
18 import dmd.Identifier; | |
19 | |
20 /******************************* | |
21 * Generate unique unittest function Id so we can have multiple | |
22 * instances per module. | |
23 */ | |
24 Identifier unitTestId() | |
25 { | |
26 return Lexer.uniqueId("__unittest"); | |
27 } | |
28 | |
29 class UnitTestDeclaration : FuncDeclaration | |
30 { | |
31 this(Loc loc, Loc endloc) | |
32 { | |
178 | 33 register(); |
0 | 34 super(loc, endloc, unitTestId(), STC.STCundefined, null); |
35 } | |
36 | |
72 | 37 override Dsymbol syntaxCopy(Dsymbol s) |
0 | 38 { |
39 UnitTestDeclaration utd; | |
40 | |
41 assert(!s); | |
42 utd = new UnitTestDeclaration(loc, endloc); | |
43 | |
44 return FuncDeclaration.syntaxCopy(utd); | |
45 } | |
46 | |
72 | 47 override void semantic(Scope sc) |
0 | 48 { |
49 if (global.params.useUnitTests) | |
50 { | |
51 type = new TypeFunction(null, Type.tvoid, false, LINKd); | |
52 Scope sc2 = sc.push(); | |
53 sc2.linkage = LINK.LINKd; | |
54 FuncDeclaration.semantic(sc2); | |
55 sc2.pop(); | |
56 } | |
57 | |
98 | 58 static if (false) |
59 { | |
0 | 60 // We're going to need ModuleInfo even if the unit tests are not |
61 // compiled in, because other modules may import this module and refer | |
62 // to this ModuleInfo. | |
98 | 63 // (This doesn't make sense to me?) |
0 | 64 Module m = getModule(); |
65 if (!m) | |
66 m = sc.module_; | |
67 if (m) | |
98 | 68 { |
69 // writef("module3 %s needs moduleinfo\n", m.toChars()); | |
0 | 70 m.needmoduleinfo = 1; |
98 | 71 } |
72 } | |
0 | 73 } |
74 | |
72 | 75 override AggregateDeclaration isThis() |
0 | 76 { |
12
832f71e6f96c
*Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents:
0
diff
changeset
|
77 return null; |
0 | 78 } |
79 | |
72 | 80 override bool isVirtual() |
0 | 81 { |
12
832f71e6f96c
*Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents:
0
diff
changeset
|
82 return false; |
0 | 83 } |
84 | |
72 | 85 override bool addPreInvariant() |
0 | 86 { |
12
832f71e6f96c
*Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents:
0
diff
changeset
|
87 return false; |
0 | 88 } |
89 | |
72 | 90 override bool addPostInvariant() |
0 | 91 { |
12
832f71e6f96c
*Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents:
0
diff
changeset
|
92 return false; |
0 | 93 } |
94 | |
72 | 95 override void toCBuffer(OutBuffer buf, HdrGenState* hgs) |
0 | 96 { |
97 assert(false); | |
98 } | |
99 | |
72 | 100 override UnitTestDeclaration isUnitTestDeclaration() { return this; } |
101 } |