Mercurial > projects > ddmd
diff dmd/InvariantDeclaration.d @ 0:10317f0c89a5
Initial commit
author | korDen |
---|---|
date | Sat, 24 Oct 2009 08:42:06 +0400 |
parents | |
children | 2e2a5c3f943a |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/dmd/InvariantDeclaration.d Sat Oct 24 08:42:06 2009 +0400 @@ -0,0 +1,90 @@ +module dmd.InvariantDeclaration; + +import dmd.FuncDeclaration; +import dmd.Loc; +import dmd.Dsymbol; +import dmd.Id; +import dmd.Scope; +import dmd.OutBuffer; +import dmd.HdrGenState; +import dmd.LINK; +import dmd.STC; +import dmd.TypeFunction; +import dmd.Type; +import dmd.AggregateDeclaration; + +class InvariantDeclaration : FuncDeclaration +{ + this(Loc loc, Loc endloc) + { + super(loc, endloc, Id.classInvariant, STCundefined, null); + } + + Dsymbol syntaxCopy(Dsymbol s) + { + assert(!s); + InvariantDeclaration id = new InvariantDeclaration(loc, endloc); + FuncDeclaration.syntaxCopy(id); + return id; + } + + void semantic(Scope sc) + { + AggregateDeclaration ad; + Type tret; + + parent = sc.parent; + Dsymbol parent = toParent(); + ad = parent.isAggregateDeclaration(); + if (!ad) + { + error("invariants are only for struct/union/class definitions"); + return; + } + else if (ad.inv && ad.inv != this) + { + error("more than one invariant for %s", ad.toChars()); + } + ad.inv = this; + type = new TypeFunction(null, Type.tvoid, false, LINKd); + + sc = sc.push(); + sc.stc &= ~STCstatic; // not a static invariant + sc.incontract++; + sc.linkage = LINK.LINKd; + + FuncDeclaration.semantic(sc); + + sc.pop(); + } + + bool isVirtual() + { + return false; + } + + bool addPreInvariant() + { + return false; + } + + bool addPostInvariant() + { + return false; + } + + void emitComment(Scope sc) + { + assert(false); + } + + void toCBuffer(OutBuffer buf, HdrGenState* hgs) + { + if (hgs.hdrgen) + return; + buf.writestring("invariant"); + bodyToCBuffer(buf, hgs); + } + + InvariantDeclaration isInvariantDeclaration() { return this; } +} \ No newline at end of file