annotate dmd/StringExp.d @ 176:fa9a71a9f5a8

Moved all the mutable globals to Global
author korDen
date Sun, 10 Oct 2010 05:22:45 +0400
parents 94b6033c07f3
children 1475fd394c9e
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
5
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
1 module dmd.StringExp;
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
2
114
e28b18c23469 added a module dmd.common for commonly used stuff
Trass3r
parents: 108
diff changeset
3 import dmd.common;
5
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
4 import dmd.Expression;
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
5 import dmd.backend.elem;
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
6 import dmd.InterState;
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
7 import dmd.TypeSArray;
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
8 import dmd.CastExp;
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
9 import dmd.MATCH;
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
10 import dmd.TY;
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
11 import dmd.TypeDArray;
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
12 import dmd.Type;
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
13 import dmd.TOK;
22
fd4acc376c45 Implemented object file output and linking on linux.
Robert Clipsham <robert@octarineparrot.com>
parents: 20
diff changeset
14 import dmd.Module;
5
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
15 import dmd.OutBuffer;
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
16 import dmd.Loc;
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
17 import dmd.Scope;
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
18 import dmd.IRState;
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
19 import dmd.StringExp;
176
fa9a71a9f5a8 Moved all the mutable globals to Global
korDen
parents: 175
diff changeset
20 import dmd.Global;
5
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
21 import dmd.HdrGenState;
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
22 import dmd.Utf;
20
1628b221808d Fleshed out more unimplemented methods.
Robert Clipsham <robert@octarineparrot.com>
parents: 11
diff changeset
23 import dmd.Util;
48
0bd8afbaffd7 StringExp.length & StringExp.toUTF8
korDen
parents: 46
diff changeset
24 import dmd.WANT;
5
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
25 import dmd.backend.dt_t;
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
26 import dmd.backend.Symbol;
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
27 import dmd.backend.StringTab;
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
28 import dmd.backend.Util;
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
29 import dmd.backend.SC;
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
30 import dmd.backend.TYM;
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
31 import dmd.backend.FL;
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
32 import dmd.backend.TYPE;
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
33 import dmd.backend.OPER;
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
34
45
ccbc1e0bb3f0 StringExp.equals implemented
korDen
parents: 22
diff changeset
35 import dmd.Dsymbol : isExpression;
ccbc1e0bb3f0 StringExp.equals implemented
korDen
parents: 22
diff changeset
36
5
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
37 import core.memory;
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
38
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
39 import core.stdc.string;
11
3356c90e9aac Bad merge fix
korDen
parents: 10
diff changeset
40 import core.stdc.stdlib;
10
korDen
parents: 9 5
diff changeset
41 import core.stdc.ctype;
5
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
42
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
43 class StringExp : Expression
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
44 {
5
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
45 void* string_; // char, wchar, or dchar data
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
46 size_t len; // number of chars, wchars, or dchars
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
47 ubyte sz; // 1: char, 2: wchar, 4: dchar
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
48 ubyte committed; // !=0 if type is committed
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
49 ubyte postfix; // 'c', 'w', 'd'
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
50
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
51 this(Loc loc, string s)
5
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
52 {
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
53 this(loc, s, 0);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
54 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
55
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
56 this(Loc loc, string s, ubyte postfix)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
57 {
5
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
58 super(loc, TOK.TOKstring, StringExp.sizeof);
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
59
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
60 this.string_ = cast(void*)s.ptr;
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
61 this.len = s.length;
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
62 this.sz = 1;
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
63 this.committed = 0;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
64 this.postfix = postfix;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
65 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
66
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 68
diff changeset
67 override bool equals(Object o)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
68 {
45
ccbc1e0bb3f0 StringExp.equals implemented
korDen
parents: 22
diff changeset
69 Expression e;
ccbc1e0bb3f0 StringExp.equals implemented
korDen
parents: 22
diff changeset
70 //printf("StringExp.equals('%s')\n", o.toChars());
ccbc1e0bb3f0 StringExp.equals implemented
korDen
parents: 22
diff changeset
71 if (o && ((e = isExpression(o)) !is null))
ccbc1e0bb3f0 StringExp.equals implemented
korDen
parents: 22
diff changeset
72 {
ccbc1e0bb3f0 StringExp.equals implemented
korDen
parents: 22
diff changeset
73 if (e.op == TOKstring)
ccbc1e0bb3f0 StringExp.equals implemented
korDen
parents: 22
diff changeset
74 {
68
ee3a9f34dc48 final bits of codegen implementation to compile Phobos
korDen
parents: 63
diff changeset
75 return opCmp(o) == 0;
45
ccbc1e0bb3f0 StringExp.equals implemented
korDen
parents: 22
diff changeset
76 }
ccbc1e0bb3f0 StringExp.equals implemented
korDen
parents: 22
diff changeset
77 }
ccbc1e0bb3f0 StringExp.equals implemented
korDen
parents: 22
diff changeset
78
ccbc1e0bb3f0 StringExp.equals implemented
korDen
parents: 22
diff changeset
79 return false;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
80 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
81
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 68
diff changeset
82 override string toChars()
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
83 {
10
korDen
parents: 9 5
diff changeset
84 scope OutBuffer buf = new OutBuffer();
korDen
parents: 9 5
diff changeset
85 HdrGenState hgs;
korDen
parents: 9 5
diff changeset
86 char *p;
korDen
parents: 9 5
diff changeset
87
korDen
parents: 9 5
diff changeset
88 memset(&hgs, 0, hgs.sizeof);
korDen
parents: 9 5
diff changeset
89 toCBuffer(buf, &hgs);
korDen
parents: 9 5
diff changeset
90 buf.writeByte(0);
korDen
parents: 9 5
diff changeset
91 return buf.extractString();
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
92 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
93
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 68
diff changeset
94 override Expression semantic(Scope sc)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
95 {
5
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
96 version (LOGSEMANTIC) {
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
97 printf("StringExp.semantic() %s\n", toChars());
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
98 }
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
99 if (!type)
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
100 {
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
101 scope OutBuffer buffer = new OutBuffer();
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
102 size_t newlen = 0;
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
103 string p;
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
104 size_t u;
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
105 dchar c;
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
106
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
107 switch (postfix)
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
108 {
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
109 case 'd':
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
110 for (u = 0; u < len;)
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
111 {
129
010eb8f0e18d further work on dmd test suite
korDen
parents: 114
diff changeset
112 p = utf_decodeChar((cast(char*)string_)[0..len], &u, &c);
5
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
113 if (p !is null)
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
114 {
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
115 error("%s", p);
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
116 break;
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
117 }
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
118 else
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
119 {
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
120 buffer.write4(c);
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
121 newlen++;
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
122 }
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
123 }
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
124 buffer.write4(0);
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
125 string_ = buffer.extractData();
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
126 len = newlen;
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
127 sz = 4;
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
128 //type = new TypeSArray(Type.tdchar, new IntegerExp(loc, len, Type.tindex));
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
129 type = new TypeDArray(Type.tdchar.invariantOf());
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
130 committed = 1;
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
131 break;
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
132
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
133 case 'w':
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
134 for (u = 0; u < len;)
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
135 {
129
010eb8f0e18d further work on dmd test suite
korDen
parents: 114
diff changeset
136 p = utf_decodeChar((cast(char*)string_)[0..len], &u, &c);
5
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
137 if (p !is null)
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
138 {
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
139 error("%s", p);
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
140 break;
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
141 }
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
142 else
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
143 {
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
144 buffer.writeUTF16(c);
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
145 newlen++;
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
146 if (c >= 0x10000)
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
147 newlen++;
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
148 }
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
149 }
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
150 buffer.writeUTF16(0);
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
151 string_ = buffer.extractData();
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
152 len = newlen;
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
153 sz = 2;
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
154 //type = new TypeSArray(Type.twchar, new IntegerExp(loc, len, Type.tindex));
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
155 type = new TypeDArray(Type.twchar.invariantOf());
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
156 committed = 1;
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
157 break;
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
158
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
159 case 'c':
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
160 committed = 1;
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
161 default:
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
162 //type = new TypeSArray(Type.tchar, new IntegerExp(loc, len, Type.tindex));
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
163 type = new TypeDArray(Type.tchar.invariantOf());
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
164 break;
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
165 }
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
166 type = type.semantic(loc, sc);
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
167 //type = type.invariantOf();
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
168 //printf("type = %s\n", type.toChars());
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
169 }
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
170 return this;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
171 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
172
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 68
diff changeset
173 override Expression interpret(InterState istate)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
174 {
63
cab4c37afb89 A bunch of implementations
korDen
parents: 48
diff changeset
175 version (LOG) {
cab4c37afb89 A bunch of implementations
korDen
parents: 48
diff changeset
176 printf("StringExp.interpret() %.*s\n", toChars());
cab4c37afb89 A bunch of implementations
korDen
parents: 48
diff changeset
177 }
cab4c37afb89 A bunch of implementations
korDen
parents: 48
diff changeset
178 return this;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
179 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
180
48
0bd8afbaffd7 StringExp.length & StringExp.toUTF8
korDen
parents: 46
diff changeset
181 /**********************************
0bd8afbaffd7 StringExp.length & StringExp.toUTF8
korDen
parents: 46
diff changeset
182 * Return length of string.
0bd8afbaffd7 StringExp.length & StringExp.toUTF8
korDen
parents: 46
diff changeset
183 */
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
184 size_t length()
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
185 {
48
0bd8afbaffd7 StringExp.length & StringExp.toUTF8
korDen
parents: 46
diff changeset
186 size_t result = 0;
0bd8afbaffd7 StringExp.length & StringExp.toUTF8
korDen
parents: 46
diff changeset
187 dchar c;
0bd8afbaffd7 StringExp.length & StringExp.toUTF8
korDen
parents: 46
diff changeset
188 string p;
0bd8afbaffd7 StringExp.length & StringExp.toUTF8
korDen
parents: 46
diff changeset
189
0bd8afbaffd7 StringExp.length & StringExp.toUTF8
korDen
parents: 46
diff changeset
190 switch (sz)
0bd8afbaffd7 StringExp.length & StringExp.toUTF8
korDen
parents: 46
diff changeset
191 {
0bd8afbaffd7 StringExp.length & StringExp.toUTF8
korDen
parents: 46
diff changeset
192 case 1:
0bd8afbaffd7 StringExp.length & StringExp.toUTF8
korDen
parents: 46
diff changeset
193 for (size_t u = 0; u < len;)
0bd8afbaffd7 StringExp.length & StringExp.toUTF8
korDen
parents: 46
diff changeset
194 {
129
010eb8f0e18d further work on dmd test suite
korDen
parents: 114
diff changeset
195 p = utf_decodeChar((cast(char*)string_)[0..len], &u, &c);
48
0bd8afbaffd7 StringExp.length & StringExp.toUTF8
korDen
parents: 46
diff changeset
196 if (p)
0bd8afbaffd7 StringExp.length & StringExp.toUTF8
korDen
parents: 46
diff changeset
197 {
0bd8afbaffd7 StringExp.length & StringExp.toUTF8
korDen
parents: 46
diff changeset
198 error("%s", p);
0bd8afbaffd7 StringExp.length & StringExp.toUTF8
korDen
parents: 46
diff changeset
199 break;
0bd8afbaffd7 StringExp.length & StringExp.toUTF8
korDen
parents: 46
diff changeset
200 }
0bd8afbaffd7 StringExp.length & StringExp.toUTF8
korDen
parents: 46
diff changeset
201 else
0bd8afbaffd7 StringExp.length & StringExp.toUTF8
korDen
parents: 46
diff changeset
202 result++;
0bd8afbaffd7 StringExp.length & StringExp.toUTF8
korDen
parents: 46
diff changeset
203 }
0bd8afbaffd7 StringExp.length & StringExp.toUTF8
korDen
parents: 46
diff changeset
204 break;
0bd8afbaffd7 StringExp.length & StringExp.toUTF8
korDen
parents: 46
diff changeset
205
0bd8afbaffd7 StringExp.length & StringExp.toUTF8
korDen
parents: 46
diff changeset
206 case 2:
0bd8afbaffd7 StringExp.length & StringExp.toUTF8
korDen
parents: 46
diff changeset
207 for (size_t u = 0; u < len;)
0bd8afbaffd7 StringExp.length & StringExp.toUTF8
korDen
parents: 46
diff changeset
208 {
129
010eb8f0e18d further work on dmd test suite
korDen
parents: 114
diff changeset
209 p = utf_decodeWchar((cast(wchar*)string_)[0..len], &u, &c);
48
0bd8afbaffd7 StringExp.length & StringExp.toUTF8
korDen
parents: 46
diff changeset
210 if (p)
0bd8afbaffd7 StringExp.length & StringExp.toUTF8
korDen
parents: 46
diff changeset
211 { error("%s", p);
0bd8afbaffd7 StringExp.length & StringExp.toUTF8
korDen
parents: 46
diff changeset
212 break;
0bd8afbaffd7 StringExp.length & StringExp.toUTF8
korDen
parents: 46
diff changeset
213 }
0bd8afbaffd7 StringExp.length & StringExp.toUTF8
korDen
parents: 46
diff changeset
214 else
0bd8afbaffd7 StringExp.length & StringExp.toUTF8
korDen
parents: 46
diff changeset
215 result++;
0bd8afbaffd7 StringExp.length & StringExp.toUTF8
korDen
parents: 46
diff changeset
216 }
0bd8afbaffd7 StringExp.length & StringExp.toUTF8
korDen
parents: 46
diff changeset
217 break;
0bd8afbaffd7 StringExp.length & StringExp.toUTF8
korDen
parents: 46
diff changeset
218
0bd8afbaffd7 StringExp.length & StringExp.toUTF8
korDen
parents: 46
diff changeset
219 case 4:
0bd8afbaffd7 StringExp.length & StringExp.toUTF8
korDen
parents: 46
diff changeset
220 result = len;
0bd8afbaffd7 StringExp.length & StringExp.toUTF8
korDen
parents: 46
diff changeset
221 break;
0bd8afbaffd7 StringExp.length & StringExp.toUTF8
korDen
parents: 46
diff changeset
222
0bd8afbaffd7 StringExp.length & StringExp.toUTF8
korDen
parents: 46
diff changeset
223 default:
0bd8afbaffd7 StringExp.length & StringExp.toUTF8
korDen
parents: 46
diff changeset
224 assert(0);
0bd8afbaffd7 StringExp.length & StringExp.toUTF8
korDen
parents: 46
diff changeset
225 }
0bd8afbaffd7 StringExp.length & StringExp.toUTF8
korDen
parents: 46
diff changeset
226 return result;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
227 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
228
48
0bd8afbaffd7 StringExp.length & StringExp.toUTF8
korDen
parents: 46
diff changeset
229 /****************************************
0bd8afbaffd7 StringExp.length & StringExp.toUTF8
korDen
parents: 46
diff changeset
230 * Convert string to char[].
0bd8afbaffd7 StringExp.length & StringExp.toUTF8
korDen
parents: 46
diff changeset
231 */
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
232 StringExp toUTF8(Scope sc)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
233 {
48
0bd8afbaffd7 StringExp.length & StringExp.toUTF8
korDen
parents: 46
diff changeset
234 if (sz != 1)
0bd8afbaffd7 StringExp.length & StringExp.toUTF8
korDen
parents: 46
diff changeset
235 {
0bd8afbaffd7 StringExp.length & StringExp.toUTF8
korDen
parents: 46
diff changeset
236 // Convert to UTF-8 string
0bd8afbaffd7 StringExp.length & StringExp.toUTF8
korDen
parents: 46
diff changeset
237 committed = 0;
0bd8afbaffd7 StringExp.length & StringExp.toUTF8
korDen
parents: 46
diff changeset
238 Expression e = castTo(sc, Type.tchar.arrayOf());
0bd8afbaffd7 StringExp.length & StringExp.toUTF8
korDen
parents: 46
diff changeset
239 e = e.optimize(WANTvalue);
0bd8afbaffd7 StringExp.length & StringExp.toUTF8
korDen
parents: 46
diff changeset
240 assert(e.op == TOKstring);
0bd8afbaffd7 StringExp.length & StringExp.toUTF8
korDen
parents: 46
diff changeset
241 StringExp se = cast(StringExp)e;
0bd8afbaffd7 StringExp.length & StringExp.toUTF8
korDen
parents: 46
diff changeset
242 assert(se.sz == 1);
0bd8afbaffd7 StringExp.length & StringExp.toUTF8
korDen
parents: 46
diff changeset
243 return se;
0bd8afbaffd7 StringExp.length & StringExp.toUTF8
korDen
parents: 46
diff changeset
244 }
0bd8afbaffd7 StringExp.length & StringExp.toUTF8
korDen
parents: 46
diff changeset
245 return this;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
246 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
247
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 68
diff changeset
248 override Expression implicitCastTo(Scope sc, Type t)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
249 {
5
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
250 //printf("StringExp.implicitCastTo(%s of type %s) => %s\n", toChars(), type.toChars(), t.toChars());
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
251 ubyte committed = this.committed;
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
252 Expression e = Expression.implicitCastTo(sc, t);
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
253 if (e.op == TOK.TOKstring)
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
254 {
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
255 // Retain polysemous nature if it started out that way
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
256 (cast(StringExp)e).committed = committed;
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
257 }
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
258 return e;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
259 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
260
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 68
diff changeset
261 override MATCH implicitConvTo(Type t)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
262 {
5
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
263 MATCH m;
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
264
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
265 static if (false) {
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
266 printf("StringExp.implicitConvTo(this=%s, committed=%d, type=%s, t=%s)\n",
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
267 toChars(), committed, type.toChars(), t.toChars());
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
268 }
5
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
269 if (!committed)
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
270 {
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
271 if (!committed && t.ty == TY.Tpointer && t.nextOf().ty == TY.Tvoid)
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
272 {
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
273 return MATCH.MATCHnomatch;
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
274 }
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
275 if (type.ty == TY.Tsarray || type.ty == TY.Tarray || type.ty == TY.Tpointer)
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
276 {
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
277 TY tyn = type.nextOf().ty;
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
278 if (tyn == TY.Tchar || tyn == TY.Twchar || tyn == TY.Tdchar)
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
279 {
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
280 Type tn;
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
281 MATCH mm;
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
282
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
283 switch (t.ty)
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
284 {
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
285 case TY.Tsarray:
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
286 if (type.ty == TY.Tsarray)
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
287 {
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
288 if ((cast(TypeSArray)type).dim.toInteger() !=
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
289 (cast(TypeSArray)t).dim.toInteger())
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
290 return MATCH.MATCHnomatch;
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
291 TY tynto = t.nextOf().ty;
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
292 if (tynto == TY.Tchar || tynto == TY.Twchar || tynto == TY.Tdchar)
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
293 return MATCH.MATCHexact;
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
294 }
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
295 else if (type.ty == TY.Tarray)
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
296 {
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
297 if (length() > (cast(TypeSArray)t).dim.toInteger())
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
298 return MATCH.MATCHnomatch;
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
299 TY tynto = t.nextOf().ty;
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
300 if (tynto == TY.Tchar || tynto == TY.Twchar || tynto == TY.Tdchar)
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
301 return MATCH.MATCHexact;
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
302 }
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
303 case TY.Tarray:
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
304 case TY.Tpointer:
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
305 tn = t.nextOf();
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
306 mm = MATCH.MATCHexact;
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
307 if (type.nextOf().mod != tn.mod)
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
308 {
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
309 if (!tn.isConst())
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
310 return MATCH.MATCHnomatch;
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
311 mm = MATCH.MATCHconst;
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
312 }
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
313 switch (tn.ty)
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
314 {
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
315 case TY.Tchar:
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
316 case TY.Twchar:
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
317 case TY.Tdchar:
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
318 return mm;
154
14feb7ae01a6 * changed the build system to build a release version if the debug one compiles
trass3r
parents: 129
diff changeset
319 default:
5
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
320 }
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
321 break;
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
322 default:
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
323 break; ///
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
324 }
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
325 }
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
326 }
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
327 }
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
328 return Expression.implicitConvTo(t);
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
329 static if (false) {
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
330 m = cast(MATCH)type.implicitConvTo(t);
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
331 if (m)
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
332 {
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
333 return m;
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
334 }
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
335
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
336 return MATCH.MATCHnomatch;
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
337 }
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
338 }
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
339
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
340 static uint X(TY tf, TY tt) {
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
341 return ((tf) * 256 + (tt));
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
342 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
343
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 68
diff changeset
344 override Expression castTo(Scope sc, Type t)
5
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
345 {
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
346 /* This follows copy-on-write; any changes to 'this'
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
347 * will result in a copy.
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
348 * The this.string member is considered immutable.
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
349 */
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
350 int copied = 0;
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
351
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
352 //printf("StringExp.castTo(t = %s), '%s' committed = %d\n", t.toChars(), toChars(), committed);
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
353
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
354 if (!committed && t.ty == TY.Tpointer && t.nextOf().ty == TY.Tvoid)
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
355 {
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
356 error("cannot convert string literal to void*");
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
357 }
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
358
98
5c859d5fbe27 and more
Trass3r
parents: 93
diff changeset
359 StringExp se = this;
5
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
360 if (!committed)
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
361 {
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
362 se = cast(StringExp)copy();
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
363 se.committed = 1;
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
364 copied = 1;
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
365 }
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
366
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
367 if (type == t)
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
368 {
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
369 return se;
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
370 }
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
371
98
5c859d5fbe27 and more
Trass3r
parents: 93
diff changeset
372 Type tb = t.toBasetype();
5
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
373 //printf("\ttype = %s\n", type.toChars());
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
374 if (tb.ty == TY.Tdelegate && type.toBasetype().ty != TY.Tdelegate)
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
375 return Expression.castTo(sc, t);
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
376
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
377 Type typeb = type.toBasetype();
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
378 if (typeb == tb)
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
379 {
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
380 if (!copied)
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
381 {
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
382 se = cast(StringExp)copy();
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
383 copied = 1;
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
384 }
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
385 se.type = t;
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
386 return se;
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
387 }
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
388
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
389 if (committed && tb.ty == TY.Tsarray && typeb.ty == TY.Tarray)
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
390 {
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
391 se = cast(StringExp)copy();
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
392 se.sz = cast(ubyte)tb.nextOf().size();
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
393 se.len = (len * sz) / se.sz;
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
394 se.committed = 1;
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
395 se.type = t;
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
396 return se;
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
397 }
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
398
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
399 if (tb.ty != TY.Tsarray && tb.ty != TY.Tarray && tb.ty != TY.Tpointer)
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
400 {
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
401 if (!copied)
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
402 {
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
403 se = cast(StringExp)copy();
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
404 copied = 1;
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
405 }
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
406 goto Lcast;
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
407 }
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
408 if (typeb.ty != TY.Tsarray && typeb.ty != TY.Tarray && typeb.ty != TY.Tpointer)
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
409 {
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
410 if (!copied)
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
411 {
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
412 se = cast(StringExp)copy();
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
413 copied = 1;
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
414 }
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
415 goto Lcast;
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
416 }
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
417
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
418 if (typeb.nextOf().size() == tb.nextOf().size())
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
419 {
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
420 if (!copied)
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
421 {
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
422 se = cast(StringExp)copy();
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
423 copied = 1;
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
424 }
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
425
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
426 if (tb.ty == TY.Tsarray)
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
427 goto L2; // handle possible change in static array dimension
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
428 se.type = t;
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
429 return se;
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
430 }
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
431
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
432 if (committed)
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
433 goto Lcast;
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
434
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
435 {
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
436 scope OutBuffer buffer = new OutBuffer();
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
437 size_t newlen = 0;
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
438 TY tfty = typeb.nextOf().toBasetype().ty;
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
439 TY ttty = tb.nextOf().toBasetype().ty;
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
440 switch (X(tfty, ttty))
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
441 {
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
442 case X(TY.Tchar, TY.Tchar):
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
443 case X(TY.Twchar,TY.Twchar):
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
444 case X(TY.Tdchar,TY.Tdchar):
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
445 break;
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
446
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
447 case X(TY.Tchar, TY.Twchar):
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
448 for (size_t u = 0; u < len;)
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
449 {
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
450 dchar c;
129
010eb8f0e18d further work on dmd test suite
korDen
parents: 114
diff changeset
451 string p = utf_decodeChar((cast(char*)se.string_)[0..len], &u, &c);
5
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
452 if (p !is null)
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
453 error("%s", p);
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
454 else
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
455 buffer.writeUTF16(c);
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
456 }
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
457 newlen = buffer.offset / 2;
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
458 buffer.writeUTF16(0);
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
459 goto L1;
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
460
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
461 case X(TY.Tchar, TY.Tdchar):
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
462 for (size_t u = 0; u < len;)
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
463 {
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
464 dchar c;
129
010eb8f0e18d further work on dmd test suite
korDen
parents: 114
diff changeset
465 string p = utf_decodeChar((cast(char*)se.string_)[0..len], &u, &c);
5
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
466 if (p !is null)
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
467 error("%s", p);
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
468 buffer.write4(c);
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
469 newlen++;
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
470 }
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
471 buffer.write4(0);
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
472 goto L1;
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
473
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
474 case X(TY.Twchar,TY.Tchar):
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
475 for (size_t u = 0; u < len;)
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
476 {
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
477 dchar c;
129
010eb8f0e18d further work on dmd test suite
korDen
parents: 114
diff changeset
478 string p = utf_decodeWchar((cast(wchar*)se.string_)[0..len], &u, &c);
5
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
479 if (p)
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
480 error("%s", p);
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
481 else
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
482 buffer.writeUTF8(c);
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
483 }
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
484 newlen = buffer.offset;
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
485 buffer.writeUTF8(0);
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
486 goto L1;
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
487
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
488 case X(TY.Twchar,TY.Tdchar):
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
489 for (size_t u = 0; u < len;)
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
490 {
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
491 dchar c;
129
010eb8f0e18d further work on dmd test suite
korDen
parents: 114
diff changeset
492 string p = utf_decodeWchar((cast(wchar*)se.string_)[0..len], &u, &c);
5
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
493 if (p)
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
494 error("%s", p);
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
495 buffer.write4(c);
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
496 newlen++;
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
497 }
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
498 buffer.write4(0);
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
499 goto L1;
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
500
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
501 case X(TY.Tdchar,TY.Tchar):
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
502 for (size_t u = 0; u < len; u++)
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
503 {
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
504 dchar c = (cast(dchar*)se.string_)[u];
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
505 if (!utf_isValidDchar(c))
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
506 error("invalid UCS-32 char \\U%08x", c);
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
507 else
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
508 buffer.writeUTF8(c);
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
509 newlen++;
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
510 }
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
511 newlen = buffer.offset;
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
512 buffer.writeUTF8(0);
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
513 goto L1;
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
514
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
515 case X(TY.Tdchar,TY.Twchar):
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
516 for (size_t u = 0; u < len; u++)
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
517 {
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
518 dchar c = (cast(dchar*)se.string_)[u];
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
519 if (!utf_isValidDchar(c))
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
520 error("invalid UCS-32 char \\U%08x", c);
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
521 else
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
522 buffer.writeUTF16(c);
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
523 newlen++;
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
524 }
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
525 newlen = buffer.offset / 2;
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
526 buffer.writeUTF16(0);
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
527 goto L1;
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
528
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
529 L1:
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
530 if (!copied)
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
531 {
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
532 se = cast(StringExp)copy();
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
533 copied = 1;
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
534 }
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
535 se.string_ = buffer.extractData();
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
536 se.len = newlen;
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
537 se.sz = cast(ubyte)tb.nextOf().size();
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
538 break;
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
539
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
540 default:
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
541 assert(typeb.nextOf().size() != tb.nextOf().size());
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
542 goto Lcast;
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
543 }
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
544 }
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
545 L2:
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
546 assert(copied);
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
547
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
548 // See if need to truncate or extend the literal
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
549 if (tb.ty == TY.Tsarray)
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
550 {
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
551 int dim2 = cast(int)(cast(TypeSArray)tb).dim.toInteger();
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
552
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
553 //printf("dim from = %d, to = %d\n", se.len, dim2);
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
554
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
555 // Changing dimensions
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
556 if (dim2 != se.len)
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
557 {
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
558 // Copy when changing the string literal
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
559 uint newsz = se.sz;
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
560 void *s;
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
561 int d;
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
562
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
563 d = (dim2 < se.len) ? dim2 : se.len;
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
564 s = cast(ubyte*)GC.malloc((dim2 + 1) * newsz);
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
565 memcpy(s, se.string_, d * newsz);
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
566 // Extend with 0, add terminating 0
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
567 memset(cast(char*)s + d * newsz, 0, (dim2 + 1 - d) * newsz);
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
568 se.string_ = s;
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
569 se.len = dim2;
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
570 }
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
571 }
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
572 se.type = t;
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
573 return se;
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
574
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
575 Lcast:
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
576 Expression e = new CastExp(loc, se, t);
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
577 e.type = t; // so semantic() won't be run on e
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
578 return e;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
579 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
580
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 68
diff changeset
581 override int opCmp(Object obj)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
582 {
46
0d32fd48dac4 StringExp.compare
korDen
parents: 45
diff changeset
583 // Used to sort case statement expressions so we can do an efficient lookup
0d32fd48dac4 StringExp.compare
korDen
parents: 45
diff changeset
584 StringExp se2 = cast(StringExp)(obj);
0d32fd48dac4 StringExp.compare
korDen
parents: 45
diff changeset
585
0d32fd48dac4 StringExp.compare
korDen
parents: 45
diff changeset
586 // This is a kludge so isExpression() in template.c will return 5
0d32fd48dac4 StringExp.compare
korDen
parents: 45
diff changeset
587 // for StringExp's.
0d32fd48dac4 StringExp.compare
korDen
parents: 45
diff changeset
588 /// ??????????????????
0d32fd48dac4 StringExp.compare
korDen
parents: 45
diff changeset
589 if (!se2)
0d32fd48dac4 StringExp.compare
korDen
parents: 45
diff changeset
590 return 5;
0d32fd48dac4 StringExp.compare
korDen
parents: 45
diff changeset
591
0d32fd48dac4 StringExp.compare
korDen
parents: 45
diff changeset
592 assert(se2.op == TOKstring);
0d32fd48dac4 StringExp.compare
korDen
parents: 45
diff changeset
593
0d32fd48dac4 StringExp.compare
korDen
parents: 45
diff changeset
594 int len1 = len;
0d32fd48dac4 StringExp.compare
korDen
parents: 45
diff changeset
595 int len2 = se2.len;
0d32fd48dac4 StringExp.compare
korDen
parents: 45
diff changeset
596
0d32fd48dac4 StringExp.compare
korDen
parents: 45
diff changeset
597 if (len1 == len2)
0d32fd48dac4 StringExp.compare
korDen
parents: 45
diff changeset
598 {
0d32fd48dac4 StringExp.compare
korDen
parents: 45
diff changeset
599 switch (sz)
0d32fd48dac4 StringExp.compare
korDen
parents: 45
diff changeset
600 {
0d32fd48dac4 StringExp.compare
korDen
parents: 45
diff changeset
601 case 1:
0d32fd48dac4 StringExp.compare
korDen
parents: 45
diff changeset
602 return strcmp(cast(char*)string_, cast(char*)se2.string_);
0d32fd48dac4 StringExp.compare
korDen
parents: 45
diff changeset
603
0d32fd48dac4 StringExp.compare
korDen
parents: 45
diff changeset
604 case 2:
0d32fd48dac4 StringExp.compare
korDen
parents: 45
diff changeset
605 {
0d32fd48dac4 StringExp.compare
korDen
parents: 45
diff changeset
606 wchar* s1 = cast(wchar*)string_;
0d32fd48dac4 StringExp.compare
korDen
parents: 45
diff changeset
607 wchar* s2 = cast(wchar*)se2.string_;
0d32fd48dac4 StringExp.compare
korDen
parents: 45
diff changeset
608
0d32fd48dac4 StringExp.compare
korDen
parents: 45
diff changeset
609 for (uint u = 0; u < len; u++)
0d32fd48dac4 StringExp.compare
korDen
parents: 45
diff changeset
610 {
0d32fd48dac4 StringExp.compare
korDen
parents: 45
diff changeset
611 if (s1[u] != s2[u]) {
0d32fd48dac4 StringExp.compare
korDen
parents: 45
diff changeset
612 return s1[u] - s2[u];
0d32fd48dac4 StringExp.compare
korDen
parents: 45
diff changeset
613 }
0d32fd48dac4 StringExp.compare
korDen
parents: 45
diff changeset
614 }
0d32fd48dac4 StringExp.compare
korDen
parents: 45
diff changeset
615 }
0d32fd48dac4 StringExp.compare
korDen
parents: 45
diff changeset
616
0d32fd48dac4 StringExp.compare
korDen
parents: 45
diff changeset
617 case 4:
0d32fd48dac4 StringExp.compare
korDen
parents: 45
diff changeset
618 {
0d32fd48dac4 StringExp.compare
korDen
parents: 45
diff changeset
619 dchar* s1 = cast(dchar *)string_;
0d32fd48dac4 StringExp.compare
korDen
parents: 45
diff changeset
620 dchar* s2 = cast(dchar *)se2.string_;
0d32fd48dac4 StringExp.compare
korDen
parents: 45
diff changeset
621
0d32fd48dac4 StringExp.compare
korDen
parents: 45
diff changeset
622 for (uint u = 0; u < len; u++)
0d32fd48dac4 StringExp.compare
korDen
parents: 45
diff changeset
623 {
0d32fd48dac4 StringExp.compare
korDen
parents: 45
diff changeset
624 if (s1[u] != s2[u]) {
0d32fd48dac4 StringExp.compare
korDen
parents: 45
diff changeset
625 return s1[u] - s2[u];
0d32fd48dac4 StringExp.compare
korDen
parents: 45
diff changeset
626 }
0d32fd48dac4 StringExp.compare
korDen
parents: 45
diff changeset
627 }
0d32fd48dac4 StringExp.compare
korDen
parents: 45
diff changeset
628 }
0d32fd48dac4 StringExp.compare
korDen
parents: 45
diff changeset
629 break;
0d32fd48dac4 StringExp.compare
korDen
parents: 45
diff changeset
630
0d32fd48dac4 StringExp.compare
korDen
parents: 45
diff changeset
631 default:
0d32fd48dac4 StringExp.compare
korDen
parents: 45
diff changeset
632 assert(0);
0d32fd48dac4 StringExp.compare
korDen
parents: 45
diff changeset
633 }
0d32fd48dac4 StringExp.compare
korDen
parents: 45
diff changeset
634 }
0d32fd48dac4 StringExp.compare
korDen
parents: 45
diff changeset
635
0d32fd48dac4 StringExp.compare
korDen
parents: 45
diff changeset
636 return len1 - len2;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
637 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
638
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 68
diff changeset
639 override bool isBool(bool result)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
640 {
93
df6d0f967680 implemented a whole bunch of methods to make phobos 2.035 compile
Trass3r
parents: 72
diff changeset
641 return result ? true : false;
df6d0f967680 implemented a whole bunch of methods to make phobos 2.035 compile
Trass3r
parents: 72
diff changeset
642 }
df6d0f967680 implemented a whole bunch of methods to make phobos 2.035 compile
Trass3r
parents: 72
diff changeset
643
df6d0f967680 implemented a whole bunch of methods to make phobos 2.035 compile
Trass3r
parents: 72
diff changeset
644 version(DMDV2)
df6d0f967680 implemented a whole bunch of methods to make phobos 2.035 compile
Trass3r
parents: 72
diff changeset
645 {
df6d0f967680 implemented a whole bunch of methods to make phobos 2.035 compile
Trass3r
parents: 72
diff changeset
646 override bool isLvalue()
df6d0f967680 implemented a whole bunch of methods to make phobos 2.035 compile
Trass3r
parents: 72
diff changeset
647 {
df6d0f967680 implemented a whole bunch of methods to make phobos 2.035 compile
Trass3r
parents: 72
diff changeset
648 return true;
df6d0f967680 implemented a whole bunch of methods to make phobos 2.035 compile
Trass3r
parents: 72
diff changeset
649 }
df6d0f967680 implemented a whole bunch of methods to make phobos 2.035 compile
Trass3r
parents: 72
diff changeset
650 }
df6d0f967680 implemented a whole bunch of methods to make phobos 2.035 compile
Trass3r
parents: 72
diff changeset
651
df6d0f967680 implemented a whole bunch of methods to make phobos 2.035 compile
Trass3r
parents: 72
diff changeset
652 override Expression toLvalue(Scope sc, Expression e)
df6d0f967680 implemented a whole bunch of methods to make phobos 2.035 compile
Trass3r
parents: 72
diff changeset
653 {
df6d0f967680 implemented a whole bunch of methods to make phobos 2.035 compile
Trass3r
parents: 72
diff changeset
654 // writef("StringExp::toLvalue(%s)\n", toChars());
df6d0f967680 implemented a whole bunch of methods to make phobos 2.035 compile
Trass3r
parents: 72
diff changeset
655 return this;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
656 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
657
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
658 uint charAt(size_t i)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
659 {
10
korDen
parents: 9 5
diff changeset
660 uint value;
korDen
parents: 9 5
diff changeset
661
korDen
parents: 9 5
diff changeset
662 switch (sz)
korDen
parents: 9 5
diff changeset
663 {
korDen
parents: 9 5
diff changeset
664 case 1:
korDen
parents: 9 5
diff changeset
665 value = (cast(ubyte *)string_)[i];
korDen
parents: 9 5
diff changeset
666 break;
korDen
parents: 9 5
diff changeset
667
korDen
parents: 9 5
diff changeset
668 case 2:
korDen
parents: 9 5
diff changeset
669 value = (cast(ushort *)string_)[i];
korDen
parents: 9 5
diff changeset
670 break;
korDen
parents: 9 5
diff changeset
671
korDen
parents: 9 5
diff changeset
672 case 4:
korDen
parents: 9 5
diff changeset
673 value = (cast(uint *)string_)[i];
korDen
parents: 9 5
diff changeset
674 break;
korDen
parents: 9 5
diff changeset
675
korDen
parents: 9 5
diff changeset
676 default:
korDen
parents: 9 5
diff changeset
677 assert(0);
korDen
parents: 9 5
diff changeset
678 break;
korDen
parents: 9 5
diff changeset
679 }
9
0ce5333b21b8 StringExp.toChars() implemented
korDen
parents: 4
diff changeset
680 return value;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
681 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
682
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 68
diff changeset
683 override void toCBuffer(OutBuffer buf, HdrGenState* hgs)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
684 {
10
korDen
parents: 9 5
diff changeset
685 buf.writeByte('"');
korDen
parents: 9 5
diff changeset
686 for (size_t i = 0; i < len; i++)
korDen
parents: 9 5
diff changeset
687 {
korDen
parents: 9 5
diff changeset
688 uint c = charAt(i);
korDen
parents: 9 5
diff changeset
689
korDen
parents: 9 5
diff changeset
690 switch (c)
korDen
parents: 9 5
diff changeset
691 {
korDen
parents: 9 5
diff changeset
692 case '"':
korDen
parents: 9 5
diff changeset
693 case '\\':
korDen
parents: 9 5
diff changeset
694 if (!hgs.console)
korDen
parents: 9 5
diff changeset
695 buf.writeByte('\\');
korDen
parents: 9 5
diff changeset
696 default:
korDen
parents: 9 5
diff changeset
697 if (c <= 0xFF)
korDen
parents: 9 5
diff changeset
698 {
korDen
parents: 9 5
diff changeset
699 if (c <= 0x7F && (isprint(c) || hgs.console))
korDen
parents: 9 5
diff changeset
700 buf.writeByte(c);
korDen
parents: 9 5
diff changeset
701 else
korDen
parents: 9 5
diff changeset
702 buf.printf("\\x%02x", c);
korDen
parents: 9 5
diff changeset
703 }
korDen
parents: 9 5
diff changeset
704 else if (c <= 0xFFFF)
korDen
parents: 9 5
diff changeset
705 buf.printf("\\x%02x\\x%02x", c & 0xFF, c >> 8);
korDen
parents: 9 5
diff changeset
706 else
korDen
parents: 9 5
diff changeset
707 buf.printf("\\x%02x\\x%02x\\x%02x\\x%02x", c & 0xFF, (c >> 8) & 0xFF, (c >> 16) & 0xFF, c >> 24);
korDen
parents: 9 5
diff changeset
708 break;
korDen
parents: 9 5
diff changeset
709 }
korDen
parents: 9 5
diff changeset
710 }
korDen
parents: 9 5
diff changeset
711 buf.writeByte('"');
korDen
parents: 9 5
diff changeset
712 if (postfix)
9
0ce5333b21b8 StringExp.toChars() implemented
korDen
parents: 4
diff changeset
713 buf.writeByte(postfix);
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
714 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
715
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 68
diff changeset
716 override void toMangleBuffer(OutBuffer buf)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
717 {
20
1628b221808d Fleshed out more unimplemented methods.
Robert Clipsham <robert@octarineparrot.com>
parents: 11
diff changeset
718 char m;
1628b221808d Fleshed out more unimplemented methods.
Robert Clipsham <robert@octarineparrot.com>
parents: 11
diff changeset
719 OutBuffer tmp = new OutBuffer();
1628b221808d Fleshed out more unimplemented methods.
Robert Clipsham <robert@octarineparrot.com>
parents: 11
diff changeset
720 string p;
1628b221808d Fleshed out more unimplemented methods.
Robert Clipsham <robert@octarineparrot.com>
parents: 11
diff changeset
721 dchar c;
1628b221808d Fleshed out more unimplemented methods.
Robert Clipsham <robert@octarineparrot.com>
parents: 11
diff changeset
722 size_t u;
1628b221808d Fleshed out more unimplemented methods.
Robert Clipsham <robert@octarineparrot.com>
parents: 11
diff changeset
723 ubyte *q;
1628b221808d Fleshed out more unimplemented methods.
Robert Clipsham <robert@octarineparrot.com>
parents: 11
diff changeset
724 uint qlen;
1628b221808d Fleshed out more unimplemented methods.
Robert Clipsham <robert@octarineparrot.com>
parents: 11
diff changeset
725
1628b221808d Fleshed out more unimplemented methods.
Robert Clipsham <robert@octarineparrot.com>
parents: 11
diff changeset
726 /* Write string in UTF-8 format
1628b221808d Fleshed out more unimplemented methods.
Robert Clipsham <robert@octarineparrot.com>
parents: 11
diff changeset
727 */
1628b221808d Fleshed out more unimplemented methods.
Robert Clipsham <robert@octarineparrot.com>
parents: 11
diff changeset
728 switch (sz)
1628b221808d Fleshed out more unimplemented methods.
Robert Clipsham <robert@octarineparrot.com>
parents: 11
diff changeset
729 { case 1:
1628b221808d Fleshed out more unimplemented methods.
Robert Clipsham <robert@octarineparrot.com>
parents: 11
diff changeset
730 m = 'a';
1628b221808d Fleshed out more unimplemented methods.
Robert Clipsham <robert@octarineparrot.com>
parents: 11
diff changeset
731 q = cast(ubyte *)string_;
1628b221808d Fleshed out more unimplemented methods.
Robert Clipsham <robert@octarineparrot.com>
parents: 11
diff changeset
732 qlen = len;
1628b221808d Fleshed out more unimplemented methods.
Robert Clipsham <robert@octarineparrot.com>
parents: 11
diff changeset
733 break;
1628b221808d Fleshed out more unimplemented methods.
Robert Clipsham <robert@octarineparrot.com>
parents: 11
diff changeset
734 case 2:
1628b221808d Fleshed out more unimplemented methods.
Robert Clipsham <robert@octarineparrot.com>
parents: 11
diff changeset
735 m = 'w';
1628b221808d Fleshed out more unimplemented methods.
Robert Clipsham <robert@octarineparrot.com>
parents: 11
diff changeset
736 for (u = 0; u < len; )
1628b221808d Fleshed out more unimplemented methods.
Robert Clipsham <robert@octarineparrot.com>
parents: 11
diff changeset
737 {
129
010eb8f0e18d further work on dmd test suite
korDen
parents: 114
diff changeset
738 p = utf_decodeWchar((cast(wchar*)string_)[0..len], &u, &c);
20
1628b221808d Fleshed out more unimplemented methods.
Robert Clipsham <robert@octarineparrot.com>
parents: 11
diff changeset
739 if (p)
1628b221808d Fleshed out more unimplemented methods.
Robert Clipsham <robert@octarineparrot.com>
parents: 11
diff changeset
740 error("%s", p);
1628b221808d Fleshed out more unimplemented methods.
Robert Clipsham <robert@octarineparrot.com>
parents: 11
diff changeset
741 else
1628b221808d Fleshed out more unimplemented methods.
Robert Clipsham <robert@octarineparrot.com>
parents: 11
diff changeset
742 tmp.writeUTF8(c);
1628b221808d Fleshed out more unimplemented methods.
Robert Clipsham <robert@octarineparrot.com>
parents: 11
diff changeset
743 }
1628b221808d Fleshed out more unimplemented methods.
Robert Clipsham <robert@octarineparrot.com>
parents: 11
diff changeset
744 q = tmp.data;
1628b221808d Fleshed out more unimplemented methods.
Robert Clipsham <robert@octarineparrot.com>
parents: 11
diff changeset
745 qlen = tmp.offset;
1628b221808d Fleshed out more unimplemented methods.
Robert Clipsham <robert@octarineparrot.com>
parents: 11
diff changeset
746 break;
1628b221808d Fleshed out more unimplemented methods.
Robert Clipsham <robert@octarineparrot.com>
parents: 11
diff changeset
747 case 4:
1628b221808d Fleshed out more unimplemented methods.
Robert Clipsham <robert@octarineparrot.com>
parents: 11
diff changeset
748 m = 'd';
1628b221808d Fleshed out more unimplemented methods.
Robert Clipsham <robert@octarineparrot.com>
parents: 11
diff changeset
749 for (u = 0; u < len; u++)
1628b221808d Fleshed out more unimplemented methods.
Robert Clipsham <robert@octarineparrot.com>
parents: 11
diff changeset
750 {
1628b221808d Fleshed out more unimplemented methods.
Robert Clipsham <robert@octarineparrot.com>
parents: 11
diff changeset
751 c = (cast(uint*)string_)[u];
1628b221808d Fleshed out more unimplemented methods.
Robert Clipsham <robert@octarineparrot.com>
parents: 11
diff changeset
752 if (!utf_isValidDchar(c))
1628b221808d Fleshed out more unimplemented methods.
Robert Clipsham <robert@octarineparrot.com>
parents: 11
diff changeset
753 error("invalid UCS-32 char \\U%08x", c);
1628b221808d Fleshed out more unimplemented methods.
Robert Clipsham <robert@octarineparrot.com>
parents: 11
diff changeset
754 else
1628b221808d Fleshed out more unimplemented methods.
Robert Clipsham <robert@octarineparrot.com>
parents: 11
diff changeset
755 tmp.writeUTF8(c);
1628b221808d Fleshed out more unimplemented methods.
Robert Clipsham <robert@octarineparrot.com>
parents: 11
diff changeset
756 }
1628b221808d Fleshed out more unimplemented methods.
Robert Clipsham <robert@octarineparrot.com>
parents: 11
diff changeset
757 q = tmp.data;
1628b221808d Fleshed out more unimplemented methods.
Robert Clipsham <robert@octarineparrot.com>
parents: 11
diff changeset
758 qlen = tmp.offset;
1628b221808d Fleshed out more unimplemented methods.
Robert Clipsham <robert@octarineparrot.com>
parents: 11
diff changeset
759 break;
1628b221808d Fleshed out more unimplemented methods.
Robert Clipsham <robert@octarineparrot.com>
parents: 11
diff changeset
760 default:
1628b221808d Fleshed out more unimplemented methods.
Robert Clipsham <robert@octarineparrot.com>
parents: 11
diff changeset
761 assert(0);
1628b221808d Fleshed out more unimplemented methods.
Robert Clipsham <robert@octarineparrot.com>
parents: 11
diff changeset
762 }
1628b221808d Fleshed out more unimplemented methods.
Robert Clipsham <robert@octarineparrot.com>
parents: 11
diff changeset
763 buf.writeByte(m);
1628b221808d Fleshed out more unimplemented methods.
Robert Clipsham <robert@octarineparrot.com>
parents: 11
diff changeset
764 buf.printf("%d_", qlen);
1628b221808d Fleshed out more unimplemented methods.
Robert Clipsham <robert@octarineparrot.com>
parents: 11
diff changeset
765 for (size_t i = 0; i < qlen; i++)
1628b221808d Fleshed out more unimplemented methods.
Robert Clipsham <robert@octarineparrot.com>
parents: 11
diff changeset
766 buf.printf("%02x", q[i]);
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
767 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
768
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 68
diff changeset
769 override elem* toElem(IRState* irs)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
770 {
5
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
771 elem* e;
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
772 Type tb = type.toBasetype();
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
773
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
774 static if (false) {
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
775 printf("StringExp.toElem() %s, type = %s\n", toChars(), type.toChars());
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
776 }
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
777
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
778 if (tb.ty == TY.Tarray)
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
779 {
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
780 Symbol* si;
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
781 dt_t* dt;
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
782 StringTab* st;
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
783
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
784 static if (false) {
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
785 printf("irs.m = %p\n", irs.m);
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
786 printf(" m = %s\n", irs.m.toChars());
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
787 printf(" len = %d\n", len);
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
788 printf(" sz = %d\n", sz);
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
789 }
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
790 for (size_t i = 0; i < STSIZE; i++)
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
791 {
176
fa9a71a9f5a8 Moved all the mutable globals to Global
korDen
parents: 175
diff changeset
792 st = &global.stringTab[(global.stidx + i) % STSIZE];
5
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
793 //if (!st.m) continue;
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
794 //printf(" st.m = %s\n", st.m.toChars());
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
795 //printf(" st.len = %d\n", st.len);
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
796 //printf(" st.sz = %d\n", st.sz);
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
797 if (st.m is irs.m &&
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
798 st.si &&
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
799 st.len == len &&
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
800 st.sz == sz &&
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
801 memcmp(st.string_, string_, sz * len) == 0)
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
802 {
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
803 //printf("use cached value\n");
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
804 si = st.si; // use cached value
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
805 goto L1;
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
806 }
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
807 }
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
808
176
fa9a71a9f5a8 Moved all the mutable globals to Global
korDen
parents: 175
diff changeset
809 global.stidx = (global.stidx + 1) % STSIZE;
fa9a71a9f5a8 Moved all the mutable globals to Global
korDen
parents: 175
diff changeset
810 st = &global.stringTab[global.stidx];
5
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
811
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
812 dt = null;
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
813 toDt(&dt);
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
814
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
815 si = symbol_generate(SC.SCstatic, type_fake(TYM.TYdarray));
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
816 si.Sdt = dt;
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
817 si.Sfl = FL.FLdata;
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
818 version (ELFOBJ) {// Burton
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
819 si.Sseg = Segment.CDATA;
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
820 }
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
821 version (MACHOBJ) {
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
822 si.Sseg = Segment.DATA;
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
823 }
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
824 outdata(si);
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
825
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
826 st.m = irs.m;
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
827 st.si = si;
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
828 st.string_ = string_;
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
829 st.len = len;
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
830 st.sz = sz;
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
831 L1:
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
832 e = el_var(si);
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
833 }
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
834 else if (tb.ty == TY.Tsarray)
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
835 {
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
836 dt_t *dt = null;
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
837
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
838 toDt(&dt);
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
839 dtnzeros(&dt, sz); // leave terminating 0
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
840
108
6da99741178e e2ir.c changes, mainly accounts for static arrays being value types now
Trass3r
parents: 98
diff changeset
841 Symbol* si = symbol_generate(SC.SCstatic,type_allocn(TYM.TYarray, tschar));
5
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
842 si.Sdt = dt;
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
843 si.Sfl = FL.FLdata;
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
844
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
845 version (ELFOBJ_OR_MACHOBJ) { // Burton
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
846 si.Sseg = Segment.CDATA;
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
847 }
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
848 outdata(si);
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
849
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
850 e = el_var(si);
108
6da99741178e e2ir.c changes, mainly accounts for static arrays being value types now
Trass3r
parents: 98
diff changeset
851 e.Enumbytes = len * sz;
5
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
852 }
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
853 else if (tb.ty == TY.Tpointer)
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
854 {
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
855 e = el_calloc();
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
856 e.Eoper = OPER.OPstring;
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
857 static if (true) {
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
858 // Match MEM_PH_FREE for OPstring in ztc\el.c
175
94b6033c07f3 get rid of globals
korDen
parents: 154
diff changeset
859 e.EV.ss.Vstring = cast(char*)GC.malloc((len + 1) * sz); /// !
5
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
860 memcpy(e.EV.ss.Vstring, string_, (len + 1) * sz);
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
861 } else {
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
862 e.EV.ss.Vstring = cast(char*)string_;
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
863 }
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
864 e.EV.ss.Vstrlen = (len + 1) * sz;
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
865 e.Ety = TYM.TYnptr;
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
866 }
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
867 else
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
868 {
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
869 writef("type is %s\n", type.toChars());
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
870 assert(0);
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
871 }
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
872 el_setLoc(e,loc);
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
873 return e;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
874 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
875
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 68
diff changeset
876 override dt_t** toDt(dt_t** pdt)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
877 {
5
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
878 //printf("StringExp.toDt() '%s', type = %s\n", toChars(), type.toChars());
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
879 Type t = type.toBasetype();
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
880
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
881 // BUG: should implement some form of static string pooling
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
882 switch (t.ty)
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
883 {
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
884 case TY.Tarray:
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
885 dtdword(pdt, len);
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
886 pdt = dtabytes(pdt, TYM.TYnptr, 0, (len + 1) * sz, cast(char*)string_);
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
887 break;
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
888
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
889 case TY.Tsarray:
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
890 {
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
891 TypeSArray tsa = cast(TypeSArray)type;
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
892 long dim;
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
893
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
894 pdt = dtnbytes(pdt, len * sz, cast(const(char)*)string_);
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
895 if (tsa.dim)
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
896 {
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
897 dim = tsa.dim.toInteger();
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
898 if (len < dim)
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
899 {
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
900 // Pad remainder with 0
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
901 pdt = dtnzeros(pdt, cast(uint)((dim - len) * tsa.next.size()));
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
902 }
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
903 }
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
904 break;
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
905 }
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
906
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
907 case TY.Tpointer:
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
908 pdt = dtabytes(pdt, TYM.TYnptr, 0, (len + 1) * sz, cast(char*)string_);
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
909 break;
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
910
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
911 default:
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
912 writef("StringExp.toDt(type = %s)\n", type.toChars());
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
913 assert(0);
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
914 }
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
915
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
916 return pdt;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
917 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
918 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
919