0
|
1 module dmd.TypeNext;
|
|
2
|
114
|
3 import dmd.common;
|
0
|
4 import dmd.Type;
|
96
|
5 import dmd.TypeAArray;
|
0
|
6 import dmd.TY;
|
|
7 import dmd.OutBuffer;
|
|
8 import dmd.Loc;
|
|
9 import dmd.Scope;
|
|
10 import dmd.MATCH;
|
|
11 import dmd.MOD;
|
|
12
|
|
13 class TypeNext : Type
|
|
14 {
|
|
15 Type next;
|
|
16
|
|
17 this(TY ty, Type next)
|
|
18 {
|
|
19 super(ty);
|
|
20 this.next = next;
|
|
21 }
|
|
22 version (DumbClone) {
|
|
23 } else {
|
|
24 final TypeNext cloneTo(TypeNext t)
|
|
25 {
|
|
26 super.cloneTo(t);
|
|
27 return t;
|
|
28 }
|
|
29
|
|
30 TypeNext clone()
|
|
31 {
|
|
32 assert(this.classinfo == TypeNext.classinfo);
|
|
33 return cloneTo(new TypeNext(ty, next));
|
|
34 }
|
|
35 }
|
72
|
36 override void toDecoBuffer(OutBuffer buf, int flag)
|
0
|
37 {
|
|
38 super.toDecoBuffer(buf, flag);
|
|
39 assert(next !is this);
|
|
40 //printf("this = %p, ty = %d, next = %p, ty = %d\n", this, this.ty, next, next.ty);
|
|
41 next.toDecoBuffer(buf, (flag & 0x100) ? 0 : mod);
|
|
42 }
|
|
43
|
72
|
44 override void checkDeprecated(Loc loc, Scope sc)
|
0
|
45 {
|
|
46 Type.checkDeprecated(loc, sc);
|
|
47 if (next) // next can be null if TypeFunction and auto return type
|
|
48 next.checkDeprecated(loc, sc);
|
|
49 }
|
|
50
|
72
|
51 override Type reliesOnTident()
|
0
|
52 {
|
|
53 return next.reliesOnTident();
|
|
54 }
|
|
55
|
72
|
56 override Type nextOf()
|
0
|
57 {
|
|
58 return next;
|
|
59 }
|
|
60
|
72
|
61 override Type makeConst()
|
0
|
62 {
|
|
63 //printf("TypeNext::makeConst() %p, %s\n", this, toChars());
|
|
64 if (cto)
|
|
65 {
|
|
66 assert(cto.mod == MOD.MODconst);
|
|
67 return cto;
|
|
68 }
|
|
69
|
|
70 TypeNext t = cast(TypeNext)super.makeConst();
|
|
71 if (ty != TY.Tfunction && ty != TY.Tdelegate &&
|
|
72 (next.deco || next.ty == TY.Tfunction) &&
|
|
73 !next.isInvariant() && !next.isConst())
|
|
74 {
|
|
75 if (next.isShared())
|
|
76 t.next = next.sharedConstOf();
|
|
77 else
|
|
78 t.next = next.constOf();
|
|
79 }
|
96
|
80 if (ty == Taarray)
|
|
81 {
|
|
82 (cast(TypeAArray)t).impl = null; // lazily recompute it
|
|
83 }
|
|
84 //writef("TypeNext::makeConst() returns %p, %s\n", t, t.toChars());
|
0
|
85 return t;
|
|
86 }
|
|
87
|
72
|
88 override Type makeInvariant()
|
0
|
89 {
|
|
90 //printf("TypeNext::makeInvariant() %s\n", toChars());
|
|
91 if (ito)
|
|
92 {
|
|
93 assert(ito.isInvariant());
|
|
94 return ito;
|
|
95 }
|
|
96 TypeNext t = cast(TypeNext)Type.makeInvariant();
|
|
97 if (ty != TY.Tfunction && ty != TY.Tdelegate && (next.deco || next.ty == TY.Tfunction) && !next.isInvariant())
|
|
98 {
|
|
99 t.next = next.invariantOf();
|
|
100 }
|
96
|
101 if (ty == Taarray)
|
|
102 {
|
|
103 (cast(TypeAArray)t).impl = null; // lazily recompute it
|
|
104 }
|
0
|
105 return t;
|
|
106 }
|
|
107
|
72
|
108 override Type makeShared()
|
0
|
109 {
|
|
110 //printf("TypeNext::makeShared() %s\n", toChars());
|
|
111 if (sto)
|
|
112 {
|
|
113 assert(sto.mod == MODshared);
|
|
114 return sto;
|
|
115 }
|
|
116 TypeNext t = cast(TypeNext)Type.makeShared();
|
|
117 if (ty != Tfunction && ty != Tdelegate &&
|
|
118 (next.deco || next.ty == Tfunction) &&
|
|
119 !next.isInvariant() && !next.isShared())
|
|
120 {
|
|
121 if (next.isConst())
|
|
122 t.next = next.sharedConstOf();
|
|
123 else
|
|
124 t.next = next.sharedOf();
|
|
125 }
|
96
|
126 if (ty == Taarray)
|
|
127 {
|
|
128 (cast(TypeAArray)t).impl = null; // lazily recompute it
|
|
129 }
|
|
130 //writef("TypeNext::makeShared() returns %p, %s\n", t, t.toChars());
|
0
|
131 return t;
|
|
132 }
|
|
133
|
96
|
134 override Type makeSharedConst()
|
0
|
135 {
|
96
|
136 //printf("TypeNext::makeSharedConst() %s\n", toChars());
|
|
137 if (scto)
|
|
138 {
|
|
139 assert(scto.mod == (MODshared | MODconst));
|
|
140 return scto;
|
|
141 }
|
|
142 TypeNext t = cast(TypeNext) Type.makeSharedConst();
|
|
143 if (ty != Tfunction && ty != Tdelegate &&
|
|
144 (next.deco || next.ty == Tfunction) &&
|
|
145 !next.isInvariant() && !next.isSharedConst())
|
|
146 {
|
|
147 t.next = next.sharedConstOf();
|
|
148 }
|
|
149 if (ty == Taarray)
|
|
150 {
|
|
151 (cast(TypeAArray)t).impl = null; // lazily recompute it
|
|
152 }
|
|
153 // writef("TypeNext::makeSharedConst() returns %p, %s\n", t, t.toChars());
|
|
154 return t;
|
0
|
155 }
|
|
156
|
96
|
157 override MATCH constConv(Type to)
|
0
|
158 {
|
56
|
159 MATCH m = Type.constConv(to);
|
|
160
|
|
161 if (m == MATCHconst && next.constConv((cast(TypeNext)to).next) == MATCHnomatch)
|
|
162 m = MATCHnomatch;
|
|
163 return m;
|
0
|
164 }
|
|
165
|
96
|
166 void transitive()
|
0
|
167 {
|
|
168 /* Invoke transitivity of type attributes
|
|
169 */
|
|
170 next = next.addMod(mod);
|
|
171 }
|
72
|
172 }
|