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