Mercurial > projects > ddmd
annotate dmd/InvariantDeclaration.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.InvariantDeclaration; |
2 | |
114 | 3 import dmd.common; |
0 | 4 import dmd.FuncDeclaration; |
5 import dmd.Loc; | |
6 import dmd.Dsymbol; | |
7 import dmd.Id; | |
8 import dmd.Scope; | |
9 import dmd.OutBuffer; | |
10 import dmd.HdrGenState; | |
11 import dmd.LINK; | |
12 import dmd.STC; | |
13 import dmd.TypeFunction; | |
14 import dmd.Type; | |
15 import dmd.AggregateDeclaration; | |
16 | |
187
b0d41ff5e0df
Added expandability scheme outlined in http://www.dsource.org/forums/viewtopic.php?t=5659&sid=6f2150ff5b0bffcd47512a6a7608d218
Abscissa
parents:
179
diff
changeset
|
17 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
|
18 |
0 | 19 class InvariantDeclaration : FuncDeclaration |
20 { | |
187
b0d41ff5e0df
Added expandability scheme outlined in http://www.dsource.org/forums/viewtopic.php?t=5659&sid=6f2150ff5b0bffcd47512a6a7608d218
Abscissa
parents:
179
diff
changeset
|
21 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
|
22 |
0 | 23 this(Loc loc, Loc endloc) |
24 { | |
178 | 25 register(); |
0 | 26 super(loc, endloc, Id.classInvariant, STCundefined, null); |
27 } | |
28 | |
72 | 29 override Dsymbol syntaxCopy(Dsymbol s) |
0 | 30 { |
31 assert(!s); | |
32 InvariantDeclaration id = new InvariantDeclaration(loc, endloc); | |
33 FuncDeclaration.syntaxCopy(id); | |
34 return id; | |
35 } | |
36 | |
72 | 37 override void semantic(Scope sc) |
0 | 38 { |
39 parent = sc.parent; | |
40 Dsymbol parent = toParent(); | |
179 | 41 AggregateDeclaration ad = parent.isAggregateDeclaration(); |
0 | 42 if (!ad) |
43 { | |
44 error("invariants are only for struct/union/class definitions"); | |
45 return; | |
46 } | |
179 | 47 else if (ad.inv && ad.inv != this && semanticRun < PASSsemantic) |
0 | 48 { |
49 error("more than one invariant for %s", ad.toChars()); | |
50 } | |
51 ad.inv = this; | |
179 | 52 if (!type) |
53 type = new TypeFunction(null, Type.tvoid, false, LINKd); | |
0 | 54 |
55 sc = sc.push(); | |
56 sc.stc &= ~STCstatic; // not a static invariant | |
57 sc.incontract++; | |
58 sc.linkage = LINK.LINKd; | |
59 | |
60 FuncDeclaration.semantic(sc); | |
61 | |
62 sc.pop(); | |
63 } | |
64 | |
72 | 65 override bool isVirtual() |
0 | 66 { |
67 return false; | |
68 } | |
69 | |
72 | 70 override bool addPreInvariant() |
0 | 71 { |
72 return false; | |
73 } | |
74 | |
72 | 75 override bool addPostInvariant() |
0 | 76 { |
77 return false; | |
78 } | |
79 | |
72 | 80 override void emitComment(Scope sc) |
0 | 81 { |
82 assert(false); | |
83 } | |
84 | |
72 | 85 override void toCBuffer(OutBuffer buf, HdrGenState* hgs) |
0 | 86 { |
87 if (hgs.hdrgen) | |
88 return; | |
89 buf.writestring("invariant"); | |
90 bodyToCBuffer(buf, hgs); | |
91 } | |
92 | |
79 | 93 override void toJsonBuffer(OutBuffer buf) |
94 { | |
95 } | |
96 | |
97 override InvariantDeclaration isInvariantDeclaration() { return this; } | |
72 | 98 } |