コード例 #1
0
ファイル: 293.cpp プロジェクト: grokus/exp
void
gen_admissible()
{
    unsigned n = 2;
    while (n < NMAX)
    {
        b1.set(n);
        n *= 2;
    }
    overall |= b1;
    for (int i = 0; i < num_primes; i++)
    {
        uint64 p = primes[i];
        do
        {
            size_t pos = b1.find_first();
            uint64 j;
            while (pos != string::npos && (j = pos * p) < NMAX)
            {
                //cout << j << endl;
                b2.set(j);
                pos = b1.find_next(pos);
            }
            p *= primes[i];
        } while (p < NMAX);
        overall |= b2;
        b1.clear();
        b1.resize(NMAX + 1);
        b1.swap(b2);
    }
}
コード例 #2
0
dt_t *ArrayInitializer::toDtBit()
{
#if DMDV1
    unsigned size;
    unsigned length;
    unsigned tadim;
    dt_t *d;
    dt_t **pdtend;
    Type *tb = type->toBasetype();

    //printf("ArrayInitializer::toDtBit('%s')\n", toChars());

    Bits databits;
    Bits initbits;

    if (tb->ty == Tsarray)
    {
        /* The 'dim' for ArrayInitializer is only the maximum dimension
         * seen in the initializer, not the type. So, for static arrays,
         * use instead the dimension of the type in order
         * to get the whole thing.
         */
        dinteger_t value = ((TypeSArray*)tb)->dim->toInteger();
        tadim = value;
        assert(tadim == value);  // truncation overflow should already be checked
        databits.resize(tadim);
        initbits.resize(tadim);
    }
    else
    {
        databits.resize(dim);
        initbits.resize(dim);
    }

    /* The default initializer may be something other than zero.
     */
    if (tb->next->defaultInit()->toInteger())
        databits.set();

    size = sizeof(databits.data[0]);

    length = 0;
    for (size_t i = 0; i < index.dim; i++)
    {   Expression *idx;
        Initializer *val;
        Expression *eval;

        idx = (Expression *)index.data[i];
        if (idx)
        {   dinteger_t value;
            value = idx->toInteger();
            length = value;
            if (length != value)
            {   error(loc, "index overflow %llu", value);
                length = 0;
            }
        }
        assert(length < dim);

        val = (Initializer *)value.data[i];
        eval = val->toExpression();
        if (initbits.test(length))
            error(loc, "duplicate initializations for index %d", length);
        initbits.set(length);
        if (eval->toInteger())          // any non-zero value is boolean 'true'
            databits.set(length);
        else
            databits.clear(length);     // boolean 'false'
        length++;
    }

    d = NULL;
#ifdef IN_GCC
    pdtend = dtnbits(&d, databits.allocdim * size, (char *)databits.data, sizeof(databits.data[0]));
#else
    pdtend = dtnbytes(&d, databits.allocdim * size, (char *)databits.data);
#endif
    switch (tb->ty)
    {
    case Tsarray:
    {
        if (dim > tadim)
        {
            error(loc, "too many initializers, %d, for array[%d]", dim, tadim);
        }
        else
        {
            tadim = (tadim + 31) / 32;
            if (databits.allocdim < tadim)
                pdtend = dtnzeros(pdtend, size * (tadim - databits.allocdim));      // pad out end of array
        }
        break;
    }

    case Tpointer:
    case Tarray:
        // Create symbol, and then refer to it
        Symbol *s;
        s = static_sym();
        s->Sdt = d;
        outdata(s);

        d = NULL;
        if (tb->ty == Tarray)
            dtsize_t(&d, dim);
        dtxoff(&d, s, 0, TYnptr);
        break;

    default:
        assert(0);
    }
    return d;
#else
    return NULL;
#endif
}