src/TypeManager.h
author David Anderson <dvander@alliedmods.net>
Sun Jan 06 13:52:21 2013 -0800 (2013-01-06)
changeset 256 3c184218462d
parent 240 e3c851a14f16
child 261 219b49bf4a03
permissions -rw-r--r--
Initial implementation of module imports.
[email protected]
     1
/* vim: set ts=4 sw=4 tw=99 et:
[email protected]
     2
 *
[email protected]
     3
 * Copyright (C) 2012 David Anderson
[email protected]
     4
 *
[email protected]
     5
 * This file is part of SourcePawn.
[email protected]
     6
 *
[email protected]
     7
 * SourcePawn is free software: you can redistribute it and/or modify it under
[email protected]
     8
 * the terms of the GNU General Public License as published by the Free
[email protected]
     9
 * Software Foundation, either version 3 of the License, or (at your option)
[email protected]
    10
 * any later version.
[email protected]
    11
 * 
[email protected]
    12
 * SourcePawn is distributed in the hope that it will be useful, but WITHOUT ANY
[email protected]
    13
 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
[email protected]
    14
 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
[email protected]
    15
 *
[email protected]
    16
 * You should have received a copy of the GNU General Public License along with
[email protected]
    17
 * SourcePawn. If not, see http://www.gnu.org/licenses/.
[email protected]
    18
 */
[email protected]
    19
#ifndef _include_jitcraft_type_manager_h_
[email protected]
    20
#define _include_jitcraft_type_manager_h_
[email protected]
    21
[email protected]
    22
#include "Barriers.h"
[email protected]
    23
#include "Types.h"
[email protected]
    24
#include "HashTable.h"
[email protected]
    25
#include "AllocatorPolicies.h"
[email protected]
    26
#include "VirtualObjectVisitor.h"
[email protected]
    27
[email protected]
    28
namespace ke {
[email protected]
    29
[email protected]
    30
class String;
[email protected]
    31
[email protected]
    32
class TypeManager
[email protected]
    33
{
[email protected]
    34
    struct LookupKey
[email protected]
    35
    {
[email protected]
    36
        Handle<Type> type;
[email protected]
    37
        TypeQualifiers quals;
[email protected]
    38
[email protected]
    39
        LookupKey(Handle<Type> type, TypeQualifiers quals)
[email protected]
    40
          : type(type),
[email protected]
    41
            quals(quals)
[email protected]
    42
        {
[email protected]
    43
        }
[email protected]
    44
    };
[email protected]
    45
[email protected]
    46
    struct Policy
[email protected]
    47
    {
[email protected]
    48
        typedef Type * Payload;
[email protected]
    49
[email protected]
    50
        static uint32 hash(const LookupKey &key) {
[email protected]
    51
            // We'll need to rehash with moving GC.
[email protected]
    52
            return HashPointer(key.type);
[email protected]
    53
        }
[email protected]
    54
        
[email protected]
    55
        static bool matches(const LookupKey &key, Type *type) {
[email protected]
    56
            assert(type->hasTypeQualifiers());
[email protected]
    57
            return key.type == type->unqualified() &&
[email protected]
    58
                   key.quals == type->quals();                   
[email protected]
    59
        }
[email protected]
    60
    };
[email protected]
    61
[email protected]
    62
    typedef HashTable<Policy, ZoneAllocatorPolicy> TypeHashTable;
[email protected]
    63
[email protected]
    64
  public:
[email protected]
    65
    TypeManager(Zone *zone);
[email protected]
    66
[email protected]
    67
    bool initialize();
[email protected]
    68
[email protected]
    69
    Type *getPrimitive(PrimitiveType type) {
[email protected]
    70
        return primitiveTypes_[type];
[email protected]
    71
    }
[email protected]
    72
[email protected]
    73
    Type *getString() {
[email protected]
    74
        return stringType_;
[email protected]
    75
    }
[email protected]
    76
    Type *getVoid() {
[email protected]
    77
        return voidType_;
[email protected]
    78
    }
[email protected]
    79
    Type *getUnchecked() {
[email protected]
    80
        return uncheckedType_;
[email protected]
    81
    }
[email protected]
    82
    Type *getImportable() {
[email protected]
    83
        return importableType_;
[email protected]
    84
    }
[email protected]
    85
    ReferenceType *getReference(Handle<Type> type, bool isConst);
[email protected]
    86
    ArrayType *newArray(Handle<Type> contained, int elements);
[email protected]
    87
    ArrayType *newExternalArray(Handle<Type> contained);
[email protected]
    88
    EnumType *newEnum(Handle<String> name);
[email protected]
    89
    
[email protected]
    90
    void accept(VirtualObjectVisitor *visitor);
[email protected]
    91
    void sweep();
[email protected]
    92
[email protected]
    93
    Type *qualify(Handle<Type> type, TypeQualifiers quals);
[email protected]
    94
[email protected]
    95
  private:
[email protected]
    96
    Zone *zone_;
[email protected]
    97
[email protected]
    98
    // Primitive type cache.
[email protected]
    99
    Unbarriered<Type> voidType_;
[email protected]
   100
    Unbarriered<Type> stringType_;
[email protected]
   101
    Unbarriered<Type> uncheckedType_;
[email protected]
   102
    Unbarriered<Type> importableType_;
[email protected]
   103
    Unbarriered<Type> primitiveTypes_[PrimitiveTypes_Total];
[email protected]
   104
    Unbarriered<ReferenceType> referenceTypes_[PrimitiveTypes_Total];
[email protected]
   105
[email protected]
   106
    TypeHashTable qualTable_;
[email protected]
   107
};
[email protected]
   108
[email protected]
   109
}
[email protected]
   110
[email protected]
   111
#endif // _include_jitcraft_type_manager_h_