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