Mercurial > projects > ddmd
view dmd/InvariantDeclaration.d @ 182:b64060ab22df
Now compileable with dmd2.050
author | korDen |
---|---|
date | Sat, 30 Oct 2010 05:05:32 +0400 |
parents | cd48cb899aee |
children | b0d41ff5e0df |
line wrap: on
line source
module dmd.InvariantDeclaration; import dmd.common; 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) { register(); super(loc, endloc, Id.classInvariant, STCundefined, null); } override Dsymbol syntaxCopy(Dsymbol s) { assert(!s); InvariantDeclaration id = new InvariantDeclaration(loc, endloc); FuncDeclaration.syntaxCopy(id); return id; } override void semantic(Scope sc) { parent = sc.parent; Dsymbol parent = toParent(); AggregateDeclaration ad = parent.isAggregateDeclaration(); if (!ad) { error("invariants are only for struct/union/class definitions"); return; } else if (ad.inv && ad.inv != this && semanticRun < PASSsemantic) { error("more than one invariant for %s", ad.toChars()); } ad.inv = this; if (!type) 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(); } override bool isVirtual() { return false; } override bool addPreInvariant() { return false; } override bool addPostInvariant() { return false; } override void emitComment(Scope sc) { assert(false); } override void toCBuffer(OutBuffer buf, HdrGenState* hgs) { if (hgs.hdrgen) return; buf.writestring("invariant"); bodyToCBuffer(buf, hgs); } override void toJsonBuffer(OutBuffer buf) { } override InvariantDeclaration isInvariantDeclaration() { return this; } }