0
|
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
|
72
|
23 override Dsymbol syntaxCopy(Dsymbol s)
|
0
|
24 {
|
|
25 assert(!s);
|
|
26 InvariantDeclaration id = new InvariantDeclaration(loc, endloc);
|
|
27 FuncDeclaration.syntaxCopy(id);
|
|
28 return id;
|
|
29 }
|
|
30
|
72
|
31 override void semantic(Scope sc)
|
0
|
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
|
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 }
|