Mercurial > projects > ddmd
diff dmd/UnitTestDeclaration.d @ 0:10317f0c89a5
Initial commit
author | korDen |
---|---|
date | Sat, 24 Oct 2009 08:42:06 +0400 |
parents | |
children | 832f71e6f96c |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/dmd/UnitTestDeclaration.d Sat Oct 24 08:42:06 2009 +0400 @@ -0,0 +1,92 @@ +module dmd.UnitTestDeclaration; + +import dmd.FuncDeclaration; +import dmd.Loc; +import dmd.Dsymbol; +import dmd.AggregateDeclaration; +import dmd.OutBuffer; +import dmd.HdrGenState; +import dmd.Type; +import dmd.Scope; +import dmd.Global; +import dmd.LINK; +import dmd.TypeFunction; +import dmd.Module; +import dmd.STC; +import dmd.Lexer; +import dmd.Identifier; + +/******************************* + * Generate unique unittest function Id so we can have multiple + * instances per module. + */ +Identifier unitTestId() +{ + return Lexer.uniqueId("__unittest"); +} + +class UnitTestDeclaration : FuncDeclaration +{ + this(Loc loc, Loc endloc) + { + super(loc, endloc, unitTestId(), STC.STCundefined, null); + } + + Dsymbol syntaxCopy(Dsymbol s) + { + UnitTestDeclaration utd; + + assert(!s); + utd = new UnitTestDeclaration(loc, endloc); + + return FuncDeclaration.syntaxCopy(utd); + } + + void semantic(Scope sc) + { + if (global.params.useUnitTests) + { + type = new TypeFunction(null, Type.tvoid, false, LINKd); + Scope sc2 = sc.push(); + sc2.linkage = LINK.LINKd; + FuncDeclaration.semantic(sc2); + sc2.pop(); + } + + // We're going to need ModuleInfo even if the unit tests are not + // compiled in, because other modules may import this module and refer + // to this ModuleInfo. + Module m = getModule(); + if (!m) + m = sc.module_; + if (m) + m.needmoduleinfo = 1; + } + + AggregateDeclaration isThis() + { + assert(false); + } + + bool isVirtual() + { + assert(false); + } + + bool addPreInvariant() + { + assert(false); + } + + bool addPostInvariant() + { + assert(false); + } + + void toCBuffer(OutBuffer buf, HdrGenState* hgs) + { + assert(false); + } + + UnitTestDeclaration isUnitTestDeclaration() { return this; } +} \ No newline at end of file