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
|
|
17 class InvariantDeclaration : FuncDeclaration
|
|
18 {
|
|
19 this(Loc loc, Loc endloc)
|
|
20 {
|
178
|
21 register();
|
0
|
22 super(loc, endloc, Id.classInvariant, STCundefined, null);
|
|
23 }
|
|
24
|
72
|
25 override Dsymbol syntaxCopy(Dsymbol s)
|
0
|
26 {
|
|
27 assert(!s);
|
|
28 InvariantDeclaration id = new InvariantDeclaration(loc, endloc);
|
|
29 FuncDeclaration.syntaxCopy(id);
|
|
30 return id;
|
|
31 }
|
|
32
|
72
|
33 override void semantic(Scope sc)
|
0
|
34 {
|
|
35 AggregateDeclaration ad;
|
|
36 Type tret;
|
|
37
|
|
38 parent = sc.parent;
|
|
39 Dsymbol parent = toParent();
|
|
40 ad = parent.isAggregateDeclaration();
|
|
41 if (!ad)
|
|
42 {
|
|
43 error("invariants are only for struct/union/class definitions");
|
|
44 return;
|
|
45 }
|
|
46 else if (ad.inv && ad.inv != this)
|
|
47 {
|
|
48 error("more than one invariant for %s", ad.toChars());
|
|
49 }
|
|
50 ad.inv = this;
|
|
51 type = new TypeFunction(null, Type.tvoid, false, LINKd);
|
|
52
|
|
53 sc = sc.push();
|
|
54 sc.stc &= ~STCstatic; // not a static invariant
|
|
55 sc.incontract++;
|
|
56 sc.linkage = LINK.LINKd;
|
|
57
|
|
58 FuncDeclaration.semantic(sc);
|
|
59
|
|
60 sc.pop();
|
|
61 }
|
|
62
|
72
|
63 override bool isVirtual()
|
0
|
64 {
|
|
65 return false;
|
|
66 }
|
|
67
|
72
|
68 override bool addPreInvariant()
|
0
|
69 {
|
|
70 return false;
|
|
71 }
|
|
72
|
72
|
73 override bool addPostInvariant()
|
0
|
74 {
|
|
75 return false;
|
|
76 }
|
|
77
|
72
|
78 override void emitComment(Scope sc)
|
0
|
79 {
|
|
80 assert(false);
|
|
81 }
|
|
82
|
72
|
83 override void toCBuffer(OutBuffer buf, HdrGenState* hgs)
|
0
|
84 {
|
|
85 if (hgs.hdrgen)
|
|
86 return;
|
|
87 buf.writestring("invariant");
|
|
88 bodyToCBuffer(buf, hgs);
|
|
89 }
|
|
90
|
79
|
91 override void toJsonBuffer(OutBuffer buf)
|
|
92 {
|
|
93 }
|
|
94
|
|
95 override InvariantDeclaration isInvariantDeclaration() { return this; }
|
72
|
96 }
|