Disallow x[y] if x has a maybe type
[delight/core.git] / dt.cc
blob4773f96811315c1c187d1e6153f50f9dcf39fe3b
1 /* GDC -- D front-end for GCC
2 Copyright (C) 2004 David Friedman
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 #include <assert.h>
20 #include "dt.h"
22 dt_t**
23 dtval(dt_t** pdt, DT t, integer_t i, void * p)
25 dt_t * d = new dt_t;
26 d->dt = t;
27 d->DTnext = 0;
28 d->DTint = i;
29 d->DTpointer = p;
30 return dtcat(pdt, d);
33 dt_t**
34 dtcat(dt_t** pdt, dt_t * d)
36 assert(d);
37 // wasted time and mem touching... shortcut DTend field?
38 while (*pdt)
39 pdt = & (*pdt)->DTnext;
40 *pdt = d;
41 return & d->DTnext;
44 typedef unsigned bitunit_t;
46 dt_t**
47 dtnbits(dt_t** pdt, size_t count, char * pbytes, unsigned unit_size)
49 assert(unit_size == sizeof(bitunit_t));
50 assert(count % unit_size == 0);
52 bitunit_t * p_unit = (bitunit_t *) pbytes,
53 * p_unit_end = (bitunit_t *) (pbytes + count);
54 char * pbits = new char[count];
55 char * p_out = pbits;
56 unsigned b = 0;
57 char outv = 0;
59 while (p_unit < p_unit_end) {
60 bitunit_t inv = *p_unit++;
62 for (unsigned i = 0; i < sizeof(bitunit_t)*8; i++) {
63 outv |= ((inv >> i) & 1) << b;
64 if (++b == 8) {
65 *p_out++ = outv;
66 b = 0;
67 outv = 0;
71 assert( (unsigned)(p_out - pbits) == count);
73 return dtnbytes(pdt, count, pbits);