Normalise line endings.
1 /* vim: set ts=4 sw=4 tw=99 et:
3 * Copyright (C) 2012 David Anderson
5 * This file is part of SourcePawn.
7 * SourcePawn is free software: you can redistribute it and/or modify it under
8 * the terms of the GNU General Public License as published by the Free
9 * Software Foundation, either version 3 of the License, or (at your option)
12 * SourcePawn is distributed in the hope that it will be useful, but WITHOUT ANY
13 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
14 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License along with
17 * SourcePawn. If not, see http://www.gnu.org/licenses/.
21 #include "TypeManager.h"
24 #include "Spaces-inl.h"
30 TypeManager::TypeManager(Zone *zone)
32 qualTable_(ZoneAllocatorPolicy())
37 TypeManager::initialize()
39 voidType_ = Type::NewVoid(zone_);
43 uncheckedType_ = Type::NewUnchecked(zone_);
47 stringType_ = Type::NewString(zone_);
51 importableType_ = Type::NewImportable(zone_);
55 typeType_ = Type::NewType(zone_);
59 if ((primitiveTypes_[PrimitiveType_Int32] = Type::NewPrimitive(zone_, PrimitiveType_Int32)) == NULL)
61 if ((primitiveTypes_[PrimitiveType_Float] = Type::NewPrimitive(zone_, PrimitiveType_Float)) == NULL)
63 if ((primitiveTypes_[PrimitiveType_Native] = Type::NewPrimitive(zone_, PrimitiveType_Native)) == NULL)
65 if ((primitiveTypes_[PrimitiveType_Char] = Type::NewPrimitive(zone_, PrimitiveType_Char)) == NULL)
67 if ((primitiveTypes_[PrimitiveType_Bool] = Type::NewPrimitive(zone_, PrimitiveType_Bool)) == NULL)
70 Local<Type> type(zone_);
71 for (unsigned i = 0; i < PrimitiveTypes_Total; i++) {
72 type = primitiveTypes_[i];
73 if ((referenceTypes_[i] = ReferenceType::New(zone_, type)) == NULL)
77 if (!qualTable_.init(32))
84 TypeManager::newArray(Handle<Type> contained, int elements)
87 return ArrayType::New(zone_, contained, elements);
91 TypeManager::newExternalArray(Handle<Type> contained)
93 return ArrayType::NewExternal(zone_, contained);
97 TypeManager::getReference(Handle<Type> type, bool isConst)
99 if (!isConst && type->isPrimitive())
100 return referenceTypes_[type->primitive()];
102 // :TODO: cache this.
103 return ReferenceType::New(zone_, type);
107 TypeManager::newEnum(Handle<String> name)
109 return EnumType::New(zone_, name);
113 TypeManager::qualify(Handle<Type> argType, TypeQualifiers quals)
115 Local<Type> type(zone_, argType->unqualified());
120 LookupKey key(type, quals);
122 // We can't use findForAdd because a GC could rehash the table.
123 TypeHashTable::Result r = qualTable_.find(key);
127 Type *quald = Type::NewQualified(zone_, quals, type);
131 // :TODO: assert-no-gc
132 TypeHashTable::Insert i = qualTable_.findForAdd(key);
135 if (!qualTable_.add(i, quald))
142 TypeManager::accept(VirtualObjectVisitor *visitor)
144 visitor->visit(voidType_.address());
145 visitor->visit(uncheckedType_.address());
146 visitor->visit(stringType_.address());
147 visitor->visit(importableType_.address());
148 visitor->visit(typeType_.address());
149 for (unsigned i = 0; i < PrimitiveTypes_Total; i++) {
150 visitor->visit(primitiveTypes_[i].address());
151 visitor->visit(referenceTypes_[i].address());
158 for (TypeHashTable::iterator i(&qualTable_); !i.empty(); i.next()) {
160 MarkBit bits = HeapChunk::GetMarkBit(obj);
161 if (HeapChunk::IsWhite(bits))
164 assert(HeapChunk::IsBlack(bits));
166 qualTable_.checkDensity();