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 parent = sc.parent;
|
|
36 Dsymbol parent = toParent();
|
179
|
37 AggregateDeclaration ad = parent.isAggregateDeclaration();
|
0
|
38 if (!ad)
|
|
39 {
|
|
40 error("invariants are only for struct/union/class definitions");
|
|
41 return;
|
|
42 }
|
179
|
43 else if (ad.inv && ad.inv != this && semanticRun < PASSsemantic)
|
0
|
44 {
|
|
45 error("more than one invariant for %s", ad.toChars());
|
|
46 }
|
|
47 ad.inv = this;
|
179
|
48 if (!type)
|
|
49 type = new TypeFunction(null, Type.tvoid, false, LINKd);
|
0
|
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
|
72
|
61 override bool isVirtual()
|
0
|
62 {
|
|
63 return false;
|
|
64 }
|
|
65
|
72
|
66 override bool addPreInvariant()
|
0
|
67 {
|
|
68 return false;
|
|
69 }
|
|
70
|
72
|
71 override bool addPostInvariant()
|
0
|
72 {
|
|
73 return false;
|
|
74 }
|
|
75
|
72
|
76 override void emitComment(Scope sc)
|
0
|
77 {
|
|
78 assert(false);
|
|
79 }
|
|
80
|
72
|
81 override void toCBuffer(OutBuffer buf, HdrGenState* hgs)
|
0
|
82 {
|
|
83 if (hgs.hdrgen)
|
|
84 return;
|
|
85 buf.writestring("invariant");
|
|
86 bodyToCBuffer(buf, hgs);
|
|
87 }
|
|
88
|
79
|
89 override void toJsonBuffer(OutBuffer buf)
|
|
90 {
|
|
91 }
|
|
92
|
|
93 override InvariantDeclaration isInvariantDeclaration() { return this; }
|
72
|
94 }
|