annotate dmd/TypeNext.d @ 56:51605de93870

TupleExp.optimize UnrolledLoopStatement.ctor UnrolledLoopStatement.semantic UnrolledLoopStatement.blockExit OrOrExp.checkSideEffect FuncExp.syntaxCopy FuncLiteralDeclaration.syntaxCopy WhileStatement.hasBreak StructInitializer.toExpression StructLiteralExp.ctor StructLiteralExp.optimize BinExp.commonSemanticAssign ModAssignExp.opId Argument.isLazyArray CommaExp.implicitConvTo CommaExp.castTo TypeClass.isBaseOf createTypeInfoArray TypeTuple.getTypeInfoDeclaration TypeInfoTupleDeclaration.ctor TypeNext.constConv XorExp.implicitConvTo TemplateParameter.isTemplateValueParameter
author korDen
date Sat, 21 Aug 2010 14:16:53 +0400
parents 10317f0c89a5
children 2e2a5c3f943a
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1 module dmd.TypeNext;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3 import dmd.Type;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4 import dmd.TY;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5 import dmd.OutBuffer;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6 import dmd.Loc;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
7 import dmd.Scope;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
8 import dmd.MATCH;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
9 import dmd.MOD;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
10
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
11 class TypeNext : Type
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
12 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
13 Type next;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
14
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
15 this(TY ty, Type next)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
16 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
17 super(ty);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
18 this.next = next;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
19 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
20 version (DumbClone) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
21 } else {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
22 final TypeNext cloneTo(TypeNext t)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
23 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
24 super.cloneTo(t);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
25 return t;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
26 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
27
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
28 TypeNext clone()
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
29 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
30 assert(this.classinfo == TypeNext.classinfo);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
31 return cloneTo(new TypeNext(ty, next));
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
32 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
33 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
34 void toDecoBuffer(OutBuffer buf, int flag)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
35 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
36 super.toDecoBuffer(buf, flag);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
37 assert(next !is this);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
38 //printf("this = %p, ty = %d, next = %p, ty = %d\n", this, this.ty, next, next.ty);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
39 next.toDecoBuffer(buf, (flag & 0x100) ? 0 : mod);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
40 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
41
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
42 void checkDeprecated(Loc loc, Scope sc)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
43 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
44 Type.checkDeprecated(loc, sc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
45 if (next) // next can be null if TypeFunction and auto return type
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
46 next.checkDeprecated(loc, sc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
47 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
48
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
49 Type reliesOnTident()
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
50 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
51 return next.reliesOnTident();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
52 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
53
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
54 Type nextOf()
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
55 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
56 return next;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
57 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
58
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
59 Type makeConst()
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
60 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
61 //printf("TypeNext::makeConst() %p, %s\n", this, toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
62 if (cto)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
63 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
64 assert(cto.mod == MOD.MODconst);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
65 return cto;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
66 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
67
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
68 TypeNext t = cast(TypeNext)super.makeConst();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
69 if (ty != TY.Tfunction && ty != TY.Tdelegate &&
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
70 (next.deco || next.ty == TY.Tfunction) &&
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
71 !next.isInvariant() && !next.isConst())
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
72 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
73 if (next.isShared())
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
74 t.next = next.sharedConstOf();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
75 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
76 t.next = next.constOf();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
77 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
78 //printf("TypeNext::makeConst() returns %p, %s\n", t, t.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
79 return t;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
80 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
81
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
82 Type makeInvariant()
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
83 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
84 //printf("TypeNext::makeInvariant() %s\n", toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
85 if (ito)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
86 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
87 assert(ito.isInvariant());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
88 return ito;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
89 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
90 TypeNext t = cast(TypeNext)Type.makeInvariant();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
91 if (ty != TY.Tfunction && ty != TY.Tdelegate && (next.deco || next.ty == TY.Tfunction) && !next.isInvariant())
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
92 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
93 t.next = next.invariantOf();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
94 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
95 return t;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
96 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
97
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
98 Type makeShared()
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
99 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
100 //printf("TypeNext::makeShared() %s\n", toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
101 if (sto)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
102 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
103 assert(sto.mod == MODshared);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
104 return sto;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
105 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
106 TypeNext t = cast(TypeNext)Type.makeShared();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
107 if (ty != Tfunction && ty != Tdelegate &&
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
108 (next.deco || next.ty == Tfunction) &&
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
109 !next.isInvariant() && !next.isShared())
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
110 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
111 if (next.isConst())
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
112 t.next = next.sharedConstOf();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
113 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
114 t.next = next.sharedOf();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
115 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
116
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
117 //printf("TypeNext::makeShared() returns %p, %s\n", t, t.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
118 return t;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
119 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
120
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
121 Type makeSharedConst()
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
122 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
123 assert(false);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
124 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
125
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
126 MATCH constConv(Type to)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
127 {
56
51605de93870 TupleExp.optimize
korDen
parents: 0
diff changeset
128 MATCH m = Type.constConv(to);
51605de93870 TupleExp.optimize
korDen
parents: 0
diff changeset
129
51605de93870 TupleExp.optimize
korDen
parents: 0
diff changeset
130 if (m == MATCHconst && next.constConv((cast(TypeNext)to).next) == MATCHnomatch)
51605de93870 TupleExp.optimize
korDen
parents: 0
diff changeset
131 m = MATCHnomatch;
51605de93870 TupleExp.optimize
korDen
parents: 0
diff changeset
132 return m;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
133 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
134
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
135 void transitive()
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
136 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
137 /* Invoke transitivity of type attributes
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
138 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
139 next = next.addMod(mod);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
140 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
141 }