src/TypeManager.h
changeset 263 ba85a47ee414
parent 261 219b49bf4a03
     1.1 --- a/src/TypeManager.h	Mon Jun 10 00:46:29 2013 +0100
     1.2 +++ b/src/TypeManager.h	Mon Jun 10 01:04:43 2013 +0100
     1.3 @@ -1,115 +1,115 @@
     1.4 -/* vim: set ts=4 sw=4 tw=99 et:
     1.5 - *
     1.6 - * Copyright (C) 2012 David Anderson
     1.7 - *
     1.8 - * This file is part of SourcePawn.
     1.9 - *
    1.10 - * SourcePawn is free software: you can redistribute it and/or modify it under
    1.11 - * the terms of the GNU General Public License as published by the Free
    1.12 - * Software Foundation, either version 3 of the License, or (at your option)
    1.13 - * any later version.
    1.14 - * 
    1.15 - * SourcePawn is distributed in the hope that it will be useful, but WITHOUT ANY
    1.16 - * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
    1.17 - * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
    1.18 - *
    1.19 - * You should have received a copy of the GNU General Public License along with
    1.20 - * SourcePawn. If not, see http://www.gnu.org/licenses/.
    1.21 - */
    1.22 -#ifndef _include_jitcraft_type_manager_h_
    1.23 -#define _include_jitcraft_type_manager_h_
    1.24 -
    1.25 -#include "Barriers.h"
    1.26 -#include "Types.h"
    1.27 -#include "HashTable.h"
    1.28 -#include "AllocatorPolicies.h"
    1.29 -#include "VirtualObjectVisitor.h"
    1.30 -
    1.31 -namespace ke {
    1.32 -
    1.33 -class String;
    1.34 -
    1.35 -class TypeManager
    1.36 -{
    1.37 -    struct LookupKey
    1.38 -    {
    1.39 -        Handle<Type> type;
    1.40 -        TypeQualifiers quals;
    1.41 -
    1.42 -        LookupKey(Handle<Type> type, TypeQualifiers quals)
    1.43 -          : type(type),
    1.44 -            quals(quals)
    1.45 -        {
    1.46 -        }
    1.47 -    };
    1.48 -
    1.49 -    struct Policy
    1.50 -    {
    1.51 -        typedef Type * Payload;
    1.52 -
    1.53 -        static uint32 hash(const LookupKey &key) {
    1.54 -            // We'll need to rehash with moving GC.
    1.55 -            return HashPointer(key.type);
    1.56 -        }
    1.57 -        
    1.58 -        static bool matches(const LookupKey &key, Type *type) {
    1.59 -            assert(type->hasTypeQualifiers());
    1.60 -            return key.type == type->unqualified() &&
    1.61 -                   key.quals == type->quals();                   
    1.62 -        }
    1.63 -    };
    1.64 -
    1.65 -    typedef HashTable<Policy, ZoneAllocatorPolicy> TypeHashTable;
    1.66 -
    1.67 -  public:
    1.68 -    TypeManager(Zone *zone);
    1.69 -
    1.70 -    bool initialize();
    1.71 -
    1.72 -    Type *getPrimitive(PrimitiveType type) {
    1.73 -        return primitiveTypes_[type];
    1.74 -    }
    1.75 -
    1.76 -    Type *getString() {
    1.77 -        return stringType_;
    1.78 -    }
    1.79 -    Type *getVoid() {
    1.80 -        return voidType_;
    1.81 -    }
    1.82 -    Type *getUnchecked() {
    1.83 -        return uncheckedType_;
    1.84 -    }
    1.85 -    Type *getImportable() {
    1.86 -        return importableType_;
    1.87 -    }
    1.88 -    Type *getType() {
    1.89 -        return typeType_;
    1.90 -    }
    1.91 -    ReferenceType *getReference(Handle<Type> type, bool isConst);
    1.92 -    ArrayType *newArray(Handle<Type> contained, int elements);
    1.93 -    ArrayType *newExternalArray(Handle<Type> contained);
    1.94 -    EnumType *newEnum(Handle<String> name);
    1.95 -    
    1.96 -    void accept(VirtualObjectVisitor *visitor);
    1.97 -    void sweep();
    1.98 -
    1.99 -    Type *qualify(Handle<Type> type, TypeQualifiers quals);
   1.100 -
   1.101 -  private:
   1.102 -    Zone *zone_;
   1.103 -
   1.104 -    // Primitive type cache.
   1.105 -    Unbarriered<Type> voidType_;
   1.106 -    Unbarriered<Type> stringType_;
   1.107 -    Unbarriered<Type> uncheckedType_;
   1.108 -    Unbarriered<Type> importableType_;
   1.109 -    Unbarriered<Type> typeType_;
   1.110 -    Unbarriered<Type> primitiveTypes_[PrimitiveTypes_Total];
   1.111 -    Unbarriered<ReferenceType> referenceTypes_[PrimitiveTypes_Total];
   1.112 -
   1.113 -    TypeHashTable qualTable_;
   1.114 -};
   1.115 -
   1.116 -}
   1.117 -
   1.118 -#endif // _include_jitcraft_type_manager_h_
   1.119 +/* vim: set ts=4 sw=4 tw=99 et:
   1.120 + *
   1.121 + * Copyright (C) 2012 David Anderson
   1.122 + *
   1.123 + * This file is part of SourcePawn.
   1.124 + *
   1.125 + * SourcePawn is free software: you can redistribute it and/or modify it under
   1.126 + * the terms of the GNU General Public License as published by the Free
   1.127 + * Software Foundation, either version 3 of the License, or (at your option)
   1.128 + * any later version.
   1.129 + * 
   1.130 + * SourcePawn is distributed in the hope that it will be useful, but WITHOUT ANY
   1.131 + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
   1.132 + * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
   1.133 + *
   1.134 + * You should have received a copy of the GNU General Public License along with
   1.135 + * SourcePawn. If not, see http://www.gnu.org/licenses/.
   1.136 + */
   1.137 +#ifndef _include_jitcraft_type_manager_h_
   1.138 +#define _include_jitcraft_type_manager_h_
   1.139 +
   1.140 +#include "Barriers.h"
   1.141 +#include "Types.h"
   1.142 +#include "HashTable.h"
   1.143 +#include "AllocatorPolicies.h"
   1.144 +#include "VirtualObjectVisitor.h"
   1.145 +
   1.146 +namespace ke {
   1.147 +
   1.148 +class String;
   1.149 +
   1.150 +class TypeManager
   1.151 +{
   1.152 +    struct LookupKey
   1.153 +    {
   1.154 +        Handle<Type> type;
   1.155 +        TypeQualifiers quals;
   1.156 +
   1.157 +        LookupKey(Handle<Type> type, TypeQualifiers quals)
   1.158 +          : type(type),
   1.159 +            quals(quals)
   1.160 +        {
   1.161 +        }
   1.162 +    };
   1.163 +
   1.164 +    struct Policy
   1.165 +    {
   1.166 +        typedef Type * Payload;
   1.167 +
   1.168 +        static uint32 hash(const LookupKey &key) {
   1.169 +            // We'll need to rehash with moving GC.
   1.170 +            return HashPointer(key.type);
   1.171 +        }
   1.172 +        
   1.173 +        static bool matches(const LookupKey &key, Type *type) {
   1.174 +            assert(type->hasTypeQualifiers());
   1.175 +            return key.type == type->unqualified() &&
   1.176 +                   key.quals == type->quals();                   
   1.177 +        }
   1.178 +    };
   1.179 +
   1.180 +    typedef HashTable<Policy, ZoneAllocatorPolicy> TypeHashTable;
   1.181 +
   1.182 +  public:
   1.183 +    TypeManager(Zone *zone);
   1.184 +
   1.185 +    bool initialize();
   1.186 +
   1.187 +    Type *getPrimitive(PrimitiveType type) {
   1.188 +        return primitiveTypes_[type];
   1.189 +    }
   1.190 +
   1.191 +    Type *getString() {
   1.192 +        return stringType_;
   1.193 +    }
   1.194 +    Type *getVoid() {
   1.195 +        return voidType_;
   1.196 +    }
   1.197 +    Type *getUnchecked() {
   1.198 +        return uncheckedType_;
   1.199 +    }
   1.200 +    Type *getImportable() {
   1.201 +        return importableType_;
   1.202 +    }
   1.203 +    Type *getType() {
   1.204 +        return typeType_;
   1.205 +    }
   1.206 +    ReferenceType *getReference(Handle<Type> type, bool isConst);
   1.207 +    ArrayType *newArray(Handle<Type> contained, int elements);
   1.208 +    ArrayType *newExternalArray(Handle<Type> contained);
   1.209 +    EnumType *newEnum(Handle<String> name);
   1.210 +    
   1.211 +    void accept(VirtualObjectVisitor *visitor);
   1.212 +    void sweep();
   1.213 +
   1.214 +    Type *qualify(Handle<Type> type, TypeQualifiers quals);
   1.215 +
   1.216 +  private:
   1.217 +    Zone *zone_;
   1.218 +
   1.219 +    // Primitive type cache.
   1.220 +    Unbarriered<Type> voidType_;
   1.221 +    Unbarriered<Type> stringType_;
   1.222 +    Unbarriered<Type> uncheckedType_;
   1.223 +    Unbarriered<Type> importableType_;
   1.224 +    Unbarriered<Type> typeType_;
   1.225 +    Unbarriered<Type> primitiveTypes_[PrimitiveTypes_Total];
   1.226 +    Unbarriered<ReferenceType> referenceTypes_[PrimitiveTypes_Total];
   1.227 +
   1.228 +    TypeHashTable qualTable_;
   1.229 +};
   1.230 +
   1.231 +}
   1.232 +
   1.233 +#endif // _include_jitcraft_type_manager_h_