annotate dmd/TypeArray.d @ 114:e28b18c23469

added a module dmd.common for commonly used stuff it currently holds code for consistency checking of predefined versions also added a VisualD project file
author Trass3r
date Wed, 01 Sep 2010 18:21:58 +0200
parents be2ab491772e
children 60bb0fe4563e
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;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
46 static string name[2] = [ "_adReverseChar", "_adReverseWchar" ];
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
47
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
48 nm = name[n.ty == Twchar];
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
49 fd = FuncDeclaration.genCfunc(Type.tindex, nm);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
50 ec = new VarExp(Loc(0), fd);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
51 e = e.castTo(sc, n.arrayOf()); // convert to dynamic array
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
52 arguments = new Expressions();
84
be2ab491772e Expressions -> Vector!Expression
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 72
diff changeset
53 arguments.push(e);
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
54 e = new CallExp(e.loc, ec, arguments);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
55 e.type = next.arrayOf();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
56 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
57 else if (ident == Id.sort && (n.ty == Tchar || n.ty == Twchar))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
58 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
59 Expression ec;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
60 FuncDeclaration fd;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
61 Expressions arguments;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
62 string nm;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
63 static string name2[2] = [ "_adSortChar", "_adSortWchar" ];
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
64
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
65 nm = name2[n.ty == Twchar];
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
66 fd = FuncDeclaration.genCfunc(Type.tindex, nm);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
67 ec = new VarExp(Loc(0), fd);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
68 e = e.castTo(sc, n.arrayOf()); // convert to dynamic array
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
69 arguments = new Expressions();
84
be2ab491772e Expressions -> Vector!Expression
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 72
diff changeset
70 arguments.push(e);
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
71 e = new CallExp(e.loc, ec, arguments);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
72 e.type = next.arrayOf();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
73 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
74 else if (ident == Id.reverse || ident == Id.dup || ident == Id.idup)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
75 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
76 Expression ec;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
77 FuncDeclaration fd;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
78 Expressions arguments;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
79 int size = cast(int)next.size(e.loc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
80 int dup;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
81
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
82 assert(size);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
83 dup = (ident == Id.dup || ident == Id.idup);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
84 fd = FuncDeclaration.genCfunc(Type.tindex, dup ? Id.adDup : Id.adReverse);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
85 ec = new VarExp(Loc(0), fd);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
86 e = e.castTo(sc, n.arrayOf()); // convert to dynamic array
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
87 arguments = new Expressions();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
88 if (dup)
84
be2ab491772e Expressions -> Vector!Expression
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 72
diff changeset
89 arguments.push(getTypeInfo(sc));
be2ab491772e Expressions -> Vector!Expression
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 72
diff changeset
90 arguments.push(e);
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
91 if (!dup)
84
be2ab491772e Expressions -> Vector!Expression
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 72
diff changeset
92 arguments.push(new IntegerExp(Loc(0), size, Type.tsize_t));
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
93 e = new CallExp(e.loc, ec, arguments);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
94 if (ident == Id.idup)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
95 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
96 Type einv = next.invariantOf();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
97 if (next.implicitConvTo(einv) < MATCHconst)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
98 error(e.loc, "cannot implicitly convert element type %s to immutable", next.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
99 e.type = einv.arrayOf();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
100 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
101 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
102 e.type = next.mutableOf().arrayOf();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
103 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
104 else if (ident == Id.sort)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
105 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
106 Expression ec;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
107 FuncDeclaration fd;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
108 Expressions arguments;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
109
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
110 fd = FuncDeclaration.genCfunc(tint32.arrayOf(), "_adSort");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
111 ec = new VarExp(Loc(0), fd);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
112 e = e.castTo(sc, n.arrayOf()); // convert to dynamic array
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
113 arguments = new Expressions();
84
be2ab491772e Expressions -> Vector!Expression
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 72
diff changeset
114 arguments.push(e);
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
115 arguments.push(n.ty == Tsarray
84
be2ab491772e Expressions -> Vector!Expression
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 72
diff changeset
116 ? n.getTypeInfo(sc) // don't convert to dynamic array
be2ab491772e Expressions -> Vector!Expression
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 72
diff changeset
117 : n.getInternalTypeInfo(sc));
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
118 e = new CallExp(e.loc, ec, arguments);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
119 e.type = next.arrayOf();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
120 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
121 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
122 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
123 e = Type.dotExp(sc, e, ident);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
124 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
125 return e;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
126 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
127
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
128 version (DumbClone) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
129 } else {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
130 Type clone()
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
131 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
132 assert(false);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
133 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
134 }
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 0
diff changeset
135 }