All but interpreter support for getting and setting struct fields.
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/.
23 #include "Structures.h"
29 Type::NewVoid(Zone *zone)
31 Local<Type> type(zone, Type::cast(zone->allocate(MapKind_Type, sizeof(Type), Heap::Tenure_Old)));
36 type->contained_ = NULL;
37 type->returnType_ = NULL;
38 type->parameters_ = NULL;
45 Type::NewPrimitive(Zone *zone, PrimitiveType prim)
47 Local<Type> type(zone, Type::cast(zone->allocate(MapKind_Type, sizeof(Type), Heap::Tenure_Old)));
51 type->kind_ = PRIMITIVE;
53 type->contained_ = NULL;
54 type->returnType_ = NULL;
55 type->parameters_ = NULL;
59 type->primitive_ = prim;
64 Type::NewArray(Zone *zone, Handle<Type> contained, int elements, bool isConst)
66 Local<Type> type(zone, Type::cast(zone->allocate(MapKind_Type, sizeof(Type), Heap::Tenure_Old)));
72 type->contained_ = contained;
73 type->returnType_ = NULL;
74 type->parameters_ = NULL;
77 type->elements_ = elements;
78 if (!contained->isArray())
81 type->levels_ = contained->levels() + 1;
82 type->const_ = isConst;
87 Type::NewReference(Zone *zone, Handle<Type> contained, bool isConst)
89 Local<Type> type(zone, Type::cast(zone->allocate(MapKind_Type, sizeof(Type), Heap::Tenure_Old)));
93 type->kind_ = REFERENCE;
95 type->contained_ = contained;
96 type->returnType_ = NULL;
97 type->parameters_ = NULL;
100 type->const_ = isConst;
105 Type::NewFunction(Zone *zone, Handle<Type> returnType, Handle<FixedArray> parameters)
107 Local<Type> type(zone, Type::cast(zone->allocate(MapKind_Type, sizeof(Type), Heap::Tenure_Old)));
111 type->kind_ = FUNCTION;
113 type->contained_ = NULL;
114 type->fields_ = NULL;
115 type->newMap_ = NULL;
116 type->returnType_ = returnType;
117 type->parameters_ = parameters;
122 Type::NewEnum(Zone *zone, Handle<String> name)
124 Local<Type> type(zone, Type::cast(zone->allocate(MapKind_Type, sizeof(Type), Heap::Tenure_Old)));
130 type->contained_ = NULL;
131 type->returnType_ = NULL;
132 type->parameters_ = NULL;
133 type->fields_ = NULL;
134 type->newMap_ = NULL;
139 Type::NewStruct(Zone *zone, Handle<String> name, Handle<FixedArray> fields, Handle<Map> newMap)
141 Local<Type> type(zone, Type::cast(zone->allocate(MapKind_Type, sizeof(Type), Heap::Tenure_Old)));
145 type->kind_ = STRUCT;
147 type->contained_ = NULL;
148 type->returnType_ = NULL;
149 type->parameters_ = NULL;
150 type->newMap_ = newMap;
151 type->fields_ = fields;
156 Type::NewNative(Zone *zone, Handle<Type> returnType, Handle<FixedArray> parameters, bool variadic)
158 Local<Type> type(zone, Type::cast(zone->allocate(MapKind_Type, sizeof(Type), Heap::Tenure_Old)));
162 type->kind_ = NATIVE;
164 type->contained_ = NULL;
165 type->fields_ = NULL;
166 type->newMap_ = NULL;
167 type->returnType_ = returnType;
168 type->parameters_ = parameters;
169 type->variadicNative_ = variadic;
174 Type::Compare(Type *left, Type *right)
179 if (left->kind() != right->kind())
182 switch (left->kind()) {
183 case Type::PRIMITIVE:
184 return left->primitive() == right->primitive();
188 if (left->levels() != right->levels())
190 if (left->elements() != right->elements())
192 return Compare(left->contained(), right->contained());
197 if (!Compare(left->returnType(), right->returnType()))
199 if (left->parameters()->length() != right->parameters()->length())
201 if (left->isNative() != right->isNative())
203 if (left->isNative() && (left->isNativeVariadic() != right->isNativeVariadic()))
205 for (unsigned i = 0; i < left->parameters()->length(); i++) {
206 Type *leftparam = left->parameterAt(i);
207 Type *rightparam = right->parameterAt(i);
208 if (!Compare(leftparam, rightparam))
221 assert(left->kind() == Type::REFERENCE);
222 return Compare(left->contained(), right->contained());
227 Type::lookupField(Handle<String> name, unsigned *index)
231 for (unsigned i = 0; i < fields_->length(); i++) {
232 Descriptor *desc = Descriptor::cast(fields_->at(i));
233 if (desc->name() == name) {