Mercurial > projects > ddmd
comparison dmd/InvariantDeclaration.d @ 0:10317f0c89a5
Initial commit
author | korDen |
---|---|
date | Sat, 24 Oct 2009 08:42:06 +0400 |
parents | |
children | 2e2a5c3f943a |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:10317f0c89a5 |
---|---|
1 module dmd.InvariantDeclaration; | |
2 | |
3 import dmd.FuncDeclaration; | |
4 import dmd.Loc; | |
5 import dmd.Dsymbol; | |
6 import dmd.Id; | |
7 import dmd.Scope; | |
8 import dmd.OutBuffer; | |
9 import dmd.HdrGenState; | |
10 import dmd.LINK; | |
11 import dmd.STC; | |
12 import dmd.TypeFunction; | |
13 import dmd.Type; | |
14 import dmd.AggregateDeclaration; | |
15 | |
16 class InvariantDeclaration : FuncDeclaration | |
17 { | |
18 this(Loc loc, Loc endloc) | |
19 { | |
20 super(loc, endloc, Id.classInvariant, STCundefined, null); | |
21 } | |
22 | |
23 Dsymbol syntaxCopy(Dsymbol s) | |
24 { | |
25 assert(!s); | |
26 InvariantDeclaration id = new InvariantDeclaration(loc, endloc); | |
27 FuncDeclaration.syntaxCopy(id); | |
28 return id; | |
29 } | |
30 | |
31 void semantic(Scope sc) | |
32 { | |
33 AggregateDeclaration ad; | |
34 Type tret; | |
35 | |
36 parent = sc.parent; | |
37 Dsymbol parent = toParent(); | |
38 ad = parent.isAggregateDeclaration(); | |
39 if (!ad) | |
40 { | |
41 error("invariants are only for struct/union/class definitions"); | |
42 return; | |
43 } | |
44 else if (ad.inv && ad.inv != this) | |
45 { | |
46 error("more than one invariant for %s", ad.toChars()); | |
47 } | |
48 ad.inv = this; | |
49 type = new TypeFunction(null, Type.tvoid, false, LINKd); | |
50 | |
51 sc = sc.push(); | |
52 sc.stc &= ~STCstatic; // not a static invariant | |
53 sc.incontract++; | |
54 sc.linkage = LINK.LINKd; | |
55 | |
56 FuncDeclaration.semantic(sc); | |
57 | |
58 sc.pop(); | |
59 } | |
60 | |
61 bool isVirtual() | |
62 { | |
63 return false; | |
64 } | |
65 | |
66 bool addPreInvariant() | |
67 { | |
68 return false; | |
69 } | |
70 | |
71 bool addPostInvariant() | |
72 { | |
73 return false; | |
74 } | |
75 | |
76 void emitComment(Scope sc) | |
77 { | |
78 assert(false); | |
79 } | |
80 | |
81 void toCBuffer(OutBuffer buf, HdrGenState* hgs) | |
82 { | |
83 if (hgs.hdrgen) | |
84 return; | |
85 buf.writestring("invariant"); | |
86 bodyToCBuffer(buf, hgs); | |
87 } | |
88 | |
89 InvariantDeclaration isInvariantDeclaration() { return this; } | |
90 } |