Mercurial > projects > ddmd
annotate dmd/UnitTestDeclaration.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.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 | |
187
b0d41ff5e0df
Added expandability scheme outlined in http://www.dsource.org/forums/viewtopic.php?t=5659&sid=6f2150ff5b0bffcd47512a6a7608d218
Abscissa
parents:
179
diff
changeset
|
20 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
|
21 |
0 | 22 /******************************* |
23 * Generate unique unittest function Id so we can have multiple | |
24 * instances per module. | |
25 */ | |
26 Identifier unitTestId() | |
27 { | |
28 return Lexer.uniqueId("__unittest"); | |
29 } | |
30 | |
31 class UnitTestDeclaration : FuncDeclaration | |
32 { | |
187
b0d41ff5e0df
Added expandability scheme outlined in http://www.dsource.org/forums/viewtopic.php?t=5659&sid=6f2150ff5b0bffcd47512a6a7608d218
Abscissa
parents:
179
diff
changeset
|
33 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
|
34 |
0 | 35 this(Loc loc, Loc endloc) |
36 { | |
178 | 37 register(); |
0 | 38 super(loc, endloc, unitTestId(), STC.STCundefined, null); |
39 } | |
40 | |
72 | 41 override Dsymbol syntaxCopy(Dsymbol s) |
0 | 42 { |
43 UnitTestDeclaration utd; | |
44 | |
45 assert(!s); | |
46 utd = new UnitTestDeclaration(loc, endloc); | |
47 | |
48 return FuncDeclaration.syntaxCopy(utd); | |
49 } | |
50 | |
72 | 51 override void semantic(Scope sc) |
0 | 52 { |
53 if (global.params.useUnitTests) | |
54 { | |
179 | 55 if (!type) |
56 type = new TypeFunction(null, Type.tvoid, false, LINKd); | |
0 | 57 Scope sc2 = sc.push(); |
58 sc2.linkage = LINK.LINKd; | |
59 FuncDeclaration.semantic(sc2); | |
60 sc2.pop(); | |
61 } | |
62 | |
98 | 63 static if (false) |
64 { | |
0 | 65 // We're going to need ModuleInfo even if the unit tests are not |
66 // compiled in, because other modules may import this module and refer | |
67 // to this ModuleInfo. | |
98 | 68 // (This doesn't make sense to me?) |
0 | 69 Module m = getModule(); |
70 if (!m) | |
71 m = sc.module_; | |
72 if (m) | |
98 | 73 { |
74 // writef("module3 %s needs moduleinfo\n", m.toChars()); | |
0 | 75 m.needmoduleinfo = 1; |
98 | 76 } |
77 } | |
0 | 78 } |
79 | |
72 | 80 override AggregateDeclaration isThis() |
0 | 81 { |
12
832f71e6f96c
*Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents:
0
diff
changeset
|
82 return null; |
0 | 83 } |
84 | |
72 | 85 override bool isVirtual() |
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 addPreInvariant() |
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 bool addPostInvariant() |
0 | 96 { |
12
832f71e6f96c
*Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents:
0
diff
changeset
|
97 return false; |
0 | 98 } |
99 | |
72 | 100 override void toCBuffer(OutBuffer buf, HdrGenState* hgs) |
0 | 101 { |
102 assert(false); | |
103 } | |
104 | |
72 | 105 override UnitTestDeclaration isUnitTestDeclaration() { return this; } |
106 } |