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
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1 module dmd.InvariantDeclaration;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2
114
e28b18c23469 added a module dmd.common for commonly used stuff
Trass3r
parents: 79
diff changeset
3 import dmd.common;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4 import dmd.FuncDeclaration;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5 import dmd.Loc;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6 import dmd.Dsymbol;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
7 import dmd.Id;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
8 import dmd.Scope;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
9 import dmd.OutBuffer;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
10 import dmd.HdrGenState;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
11 import dmd.LINK;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
12 import dmd.STC;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
13 import dmd.TypeFunction;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
14 import dmd.Type;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
15 import dmd.AggregateDeclaration;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
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
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
19 class InvariantDeclaration : FuncDeclaration
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
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
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
23 this(Loc loc, Loc endloc)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
24 {
178
e3afd1303184 Many small bugs fixed
korDen
parents: 114
diff changeset
25 register();
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
26 super(loc, endloc, Id.classInvariant, STCundefined, null);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
27 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
28
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 0
diff changeset
29 override Dsymbol syntaxCopy(Dsymbol s)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
30 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
31 assert(!s);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
32 InvariantDeclaration id = new InvariantDeclaration(loc, endloc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
33 FuncDeclaration.syntaxCopy(id);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
34 return id;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
35 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
36
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 0
diff changeset
37 override void semantic(Scope sc)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
38 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
39 parent = sc.parent;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
40 Dsymbol parent = toParent();
179
cd48cb899aee Updated to dmd2.040
korDen
parents: 178
diff changeset
41 AggregateDeclaration ad = parent.isAggregateDeclaration();
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
42 if (!ad)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
43 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
44 error("invariants are only for struct/union/class definitions");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
45 return;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
46 }
179
cd48cb899aee Updated to dmd2.040
korDen
parents: 178
diff changeset
47 else if (ad.inv && ad.inv != this && semanticRun < PASSsemantic)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
48 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
49 error("more than one invariant for %s", ad.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
50 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
51 ad.inv = this;
179
cd48cb899aee Updated to dmd2.040
korDen
parents: 178
diff changeset
52 if (!type)
cd48cb899aee Updated to dmd2.040
korDen
parents: 178
diff changeset
53 type = new TypeFunction(null, Type.tvoid, false, LINKd);
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
54
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
55 sc = sc.push();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
56 sc.stc &= ~STCstatic; // not a static invariant
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
57 sc.incontract++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
58 sc.linkage = LINK.LINKd;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
59
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
60 FuncDeclaration.semantic(sc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
61
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
62 sc.pop();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
63 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
64
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 0
diff changeset
65 override bool isVirtual()
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
66 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
67 return false;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
68 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
69
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 0
diff changeset
70 override bool addPreInvariant()
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
71 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
72 return false;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
73 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
74
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 0
diff changeset
75 override bool addPostInvariant()
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
76 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
77 return false;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
78 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
79
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 0
diff changeset
80 override void emitComment(Scope sc)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
81 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
82 assert(false);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
83 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
84
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 0
diff changeset
85 override void toCBuffer(OutBuffer buf, HdrGenState* hgs)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
86 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
87 if (hgs.hdrgen)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
88 return;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
89 buf.writestring("invariant");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
90 bodyToCBuffer(buf, hgs);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
91 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
92
79
43073c7c7769 updated to 2.035
Trass3r
parents: 72
diff changeset
93 override void toJsonBuffer(OutBuffer buf)
43073c7c7769 updated to 2.035
Trass3r
parents: 72
diff changeset
94 {
43073c7c7769 updated to 2.035
Trass3r
parents: 72
diff changeset
95 }
43073c7c7769 updated to 2.035
Trass3r
parents: 72
diff changeset
96
43073c7c7769 updated to 2.035
Trass3r
parents: 72
diff changeset
97 override InvariantDeclaration isInvariantDeclaration() { return this; }
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 0
diff changeset
98 }