view gen/utils.h @ 1602:a413ae7329bf

Merge DMD r243: some harmonization with D2 dmd --- dmd/aggregate.h | 24 ++++- dmd/attrib.c | 63 ++++++---- dmd/attrib.h | 10 +- dmd/declaration.h | 5 +- dmd/func.c | 337 ++++++++++++++++++++++------------------------------- dmd/mars.c | 2 +- dmd/mars.h | 7 + dmd/mtype.h | 13 ++- dmd/parse.c | 32 ++++- dmd/parse.h | 14 ++- dmd/scope.h | 2 +- 11 files changed, 263 insertions(+), 246 deletions(-)
author Leandro Lucarella <llucax@gmail.com>
date Wed, 06 Jan 2010 15:18:19 -0300
parents ec1d9dc1d32a
children
line wrap: on
line source

#ifndef __LDC_GEN_UTILS_H__
#define __LDC_GEN_UTILS_H__

#include "root.h"

/// Very simple templated iterator for DMD ArrayS.
template<class C>
struct ArrayIter
{
    Array* array;
    size_t index;

    ArrayIter(Array& arr, size_t idx = 0)
    :   array(&arr), index(idx)
    { }
    ArrayIter(Array* arr, size_t idx = 0)
    :   array(arr), index(idx)
    { assert(arr && "null array"); }

    ArrayIter<C>& operator=(const Array& arr)
    {
        array = &arr;
        index = 0;
        return *this;
    }
    ArrayIter<C>& operator=(const Array* arr)
    {
        assert(arr && "null array");
        array = arr;
        index = 0;
        return *this;
    }

    bool done()
    {
        return index >= array->dim;
    }
    bool more()
    {
        return index < array->dim;
    }

    C* get() {
        return static_cast<C*>(array->data[index]);
    }
    C* operator->() {
        return get();
    }
    C* operator*() {
        return get();
    }

    void next()
    {
        ++index;
    }

    bool operator==(const ArrayIter<C>& other) {
        return &array->data[index] == &other.array->data[other.index];
    }
};

// some aliases
typedef ArrayIter<Dsymbol> DsymbolIter;
typedef ArrayIter<FuncDeclaration> FuncDeclarationIter;
typedef ArrayIter<VarDeclaration> VarDeclarationIter;

#endif