src/Reference.cpp
author David Anderson <dvander@alliedmods.net>
Sun Sep 16 21:59:26 2012 -0700 (2012-09-16)
changeset 190 dd04fce774cd
parent 188 bab29bcec7fe
child 195 c1ba166f3fc4
permissions -rw-r--r--
Enable dynamic array declarations.
     1 /* vim: set ts=4 sw=4 tw=99 et:
     2  *
     3  * Copyright (C) 2012 David Anderson
     4  *
     5  * This file is part of SourcePawn.
     6  *
     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)
    10  * any later version.
    11  * 
    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.
    15  *
    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/.
    18  */
    19 #include "Reference.h"
    20 #include "Zone.h"
    21 #include "Array.h"
    22 #include "Structures.h"
    23 #include "Heap-inl.h"
    24 
    25 using namespace ke;
    26 
    27 Reference *
    28 Reference::NewStack(Zone *zone, void *location, Heap::Tenure tenure)
    29 {
    30     Local<Reference> ref(zone, Reference::cast(zone->allocate(MapKind_Reference, sizeof(Reference), tenure)));
    31     if (!ref)
    32         return NULL;
    33 
    34     ref->location_ = location;
    35     ref->base_ = NULL;
    36     return ref;
    37 }
    38 
    39 Reference *
    40 Reference::NewStack(Zone *zone, const LocalSlot &slot, Heap::Tenure tenure)
    41 {
    42     Local<Reference> ref(zone, Reference::cast(zone->allocate(MapKind_Reference, sizeof(Reference), tenure)));
    43     if (!ref)
    44         return NULL;
    45 
    46     ref->location_ = &ref->slot_;
    47     ref->slot_ = slot;
    48     ref->base_ = NULL;
    49     return ref;
    50 }
    51 
    52 Reference *
    53 Reference::NewField(Zone *zone, Handle<Struct> obj, size_t index, Heap::Tenure tenure)
    54 {
    55     Local<Reference> ref(zone, Reference::cast(zone->allocate(MapKind_Reference, sizeof(Reference), tenure)));
    56     if (!ref)
    57         return NULL;
    58 
    59     Descriptor *desc = Descriptor::cast(obj->map()->type()->fields()->at(index));
    60     ref->location_ = obj->ref(desc);
    61     ref->base_ = obj;
    62     return ref;
    63 }
    64