/* vim: set ts=4 sw=4 tw=99 et:
 *
 * Copyright (C) 2012 David Anderson
 *
 * This file is part of SourcePawn.
 *
 * SourcePawn is free software: you can redistribute it and/or modify it under
 * the terms of the GNU General Public License as published by the Free
 * Software Foundation, either version 3 of the License, or (at your option)
 * any later version.
 * 
 * SourcePawn is distributed in the hope that it will be useful, but WITHOUT ANY
 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License along with
 * SourcePawn. If not, see http://www.gnu.org/licenses/.
 */
#ifndef _include_jitcraft_type_manager_h_
#define _include_jitcraft_type_manager_h_

#include "Barriers.h"
#include "Types.h"
#include "VirtualObjectVisitor.h"

namespace ke {

class String;

class TypeManager
{
    Zone *zone_;

    // Primitive type cache.
    Unbarriered<Type> voidType_;
    Unbarriered<Type> uncheckedType_;
    Unbarriered<Type> primitiveTypes_[PrimitiveTypes_Total];
    Unbarriered<Type> referenceTypes_[PrimitiveTypes_Total];

  public:
    TypeManager(Zone *zone);

    bool initialize();

    Type *getPrimitive(PrimitiveType type) {
        return primitiveTypes_[type];
    }

    Type *getVoid() {
        return voidType_;
    }
    Type *getUnchecked() {
        return uncheckedType_;
    }
    Type *getReference(Handle<Type> type, bool isConst);
    Type *newArray(Handle<Type> contained, int elements, bool isConst);
    Type *newEnum(Handle<String> name);
    Type *newFunction(Handle<Type> returnType, Handle<FixedArray> args,
                      Handle<FixedArray> deafults);
    Type *newNative(Handle<Type> returnType, Handle<FixedArray> args,
                    Handle<FixedArray> defaults, bool variadic);
    Type *newStruct(Handle<String> name, Handle<FixedArray> fields, Handle<Map> newMap);
    
    void accept(VirtualObjectVisitor *visitor);
};

}

#endif // _include_jitcraft_type_manager_h_
