annotate dmd/TypeArray.d @ 174:af724d3510d7

lot os toCBuffer methods implemented moved shared Type.* stuff into Global
author korDen
date Sun, 10 Oct 2010 03:47:23 +0400
parents 60bb0fe4563e
children e3afd1303184
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1 module dmd.TypeArray;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2
114
e28b18c23469 added a module dmd.common for commonly used stuff
Trass3r
parents: 84
diff changeset
3 import dmd.common;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4 import dmd.Type;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5 import dmd.TypeNext;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6 import dmd.Id;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
7 import dmd.Loc;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
8 import dmd.ArrayTypes;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
9 import dmd.CallExp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
10 import dmd.FuncDeclaration;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
11 import dmd.VarExp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
12 import dmd.Expression;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
13 import dmd.MATCH;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
14 import dmd.Scope;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
15 import dmd.Identifier;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
16 import dmd.TY;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
17 import dmd.IntegerExp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
18 import dmd.Global;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
19
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
20 // Allow implicit conversion of T[] to T*
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
21 bool IMPLICIT_ARRAY_TO_PTR()
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
22 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
23 return global.params.useDeprecated;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
24 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
25
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
26 class TypeArray : TypeNext
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
27 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
28 this(TY ty, Type next)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
29 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
30 super(ty, next);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
31 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
32
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 0
diff changeset
33 override Expression dotExp(Scope sc, Expression e, Identifier ident)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
34 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
35 Type n = this.next.toBasetype(); // uncover any typedef's
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
36
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
37 version (LOGDOTEXP) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
38 printf("TypeArray.dotExp(e = '%s', ident = '%s')\n", e.toChars(), ident.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
39 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
40 if (ident == Id.reverse && (n.ty == Tchar || n.ty == Twchar))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
41 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
42 Expression ec;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
43 FuncDeclaration fd;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
44 Expressions arguments;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
45 string nm;
174
af724d3510d7 lot os toCBuffer methods implemented
korDen
parents: 130
diff changeset
46
af724d3510d7 lot os toCBuffer methods implemented
korDen
parents: 130
diff changeset
47 enum string name[2] = [ "_adReverseChar", "_adReverseWchar" ];
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
48
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
49 nm = name[n.ty == Twchar];
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
50 fd = FuncDeclaration.genCfunc(Type.tindex, nm);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
51 ec = new VarExp(Loc(0), fd);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
52 e = e.castTo(sc, n.arrayOf()); // convert to dynamic array
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
53 arguments = new Expressions();
84
be2ab491772e Expressions -> Vector!Expression
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 72
diff changeset
54 arguments.push(e);
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
55 e = new CallExp(e.loc, ec, arguments);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
56 e.type = next.arrayOf();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
57 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
58 else if (ident == Id.sort && (n.ty == Tchar || n.ty == Twchar))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
59 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
60 Expression ec;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
61 FuncDeclaration fd;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
62 Expressions arguments;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
63 string nm;
174
af724d3510d7 lot os toCBuffer methods implemented
korDen
parents: 130
diff changeset
64
af724d3510d7 lot os toCBuffer methods implemented
korDen
parents: 130
diff changeset
65 enum string name2[2] = [ "_adSortChar", "_adSortWchar" ];
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
66
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
67 nm = name2[n.ty == Twchar];
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
68 fd = FuncDeclaration.genCfunc(Type.tindex, nm);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
69 ec = new VarExp(Loc(0), fd);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
70 e = e.castTo(sc, n.arrayOf()); // convert to dynamic array
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
71 arguments = new Expressions();
84
be2ab491772e Expressions -> Vector!Expression
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 72
diff changeset
72 arguments.push(e);
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
73 e = new CallExp(e.loc, ec, arguments);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
74 e.type = next.arrayOf();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
75 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
76 else if (ident == Id.reverse || ident == Id.dup || ident == Id.idup)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
77 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
78 Expression ec;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
79 FuncDeclaration fd;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
80 Expressions arguments;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
81 int size = cast(int)next.size(e.loc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
82 int dup;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
83
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
84 assert(size);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
85 dup = (ident == Id.dup || ident == Id.idup);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
86 fd = FuncDeclaration.genCfunc(Type.tindex, dup ? Id.adDup : Id.adReverse);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
87 ec = new VarExp(Loc(0), fd);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
88 e = e.castTo(sc, n.arrayOf()); // convert to dynamic array
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
89 arguments = new Expressions();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
90 if (dup)
84
be2ab491772e Expressions -> Vector!Expression
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 72
diff changeset
91 arguments.push(getTypeInfo(sc));
be2ab491772e Expressions -> Vector!Expression
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 72
diff changeset
92 arguments.push(e);
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
93 if (!dup)
84
be2ab491772e Expressions -> Vector!Expression
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 72
diff changeset
94 arguments.push(new IntegerExp(Loc(0), size, Type.tsize_t));
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
95 e = new CallExp(e.loc, ec, arguments);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
96 if (ident == Id.idup)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
97 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
98 Type einv = next.invariantOf();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
99 if (next.implicitConvTo(einv) < MATCHconst)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
100 error(e.loc, "cannot implicitly convert element type %s to immutable", next.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
101 e.type = einv.arrayOf();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
102 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
103 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
104 e.type = next.mutableOf().arrayOf();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
105 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
106 else if (ident == Id.sort)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
107 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
108 Expression ec;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
109 FuncDeclaration fd;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
110 Expressions arguments;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
111
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
112 fd = FuncDeclaration.genCfunc(tint32.arrayOf(), "_adSort");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
113 ec = new VarExp(Loc(0), fd);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
114 e = e.castTo(sc, n.arrayOf()); // convert to dynamic array
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
115 arguments = new Expressions();
84
be2ab491772e Expressions -> Vector!Expression
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 72
diff changeset
116 arguments.push(e);
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
117 arguments.push(n.ty == Tsarray
84
be2ab491772e Expressions -> Vector!Expression
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 72
diff changeset
118 ? n.getTypeInfo(sc) // don't convert to dynamic array
be2ab491772e Expressions -> Vector!Expression
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 72
diff changeset
119 : n.getInternalTypeInfo(sc));
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
120 e = new CallExp(e.loc, ec, arguments);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
121 e.type = next.arrayOf();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
122 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
123 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
124 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
125 e = Type.dotExp(sc, e, ident);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
126 }
130
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 114
diff changeset
127 e = e.semantic(sc);
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
128 return e;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
129 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
130
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
131 version (DumbClone) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
132 } else {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
133 Type clone()
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
134 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
135 assert(false);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
136 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
137 }
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 0
diff changeset
138 }