src/Reference.cpp
author David Anderson <dvander@alliedmods.net>
Sat Aug 11 12:11:39 2012 -0700 (2012-08-11)
changeset 170 5e4570966ece
parent 168 4d0fff61d65e
child 188 bab29bcec7fe
permissions -rw-r--r--
Parser support for public variables.
     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::NewArray(Zone *zone, Handle<Array> base, 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     ref->location_ = base->slotPtr(index);
    60     ref->base_ = base;
    61     return ref;
    62 }
    63 
    64 Reference *
    65 Reference::NewField(Zone *zone, Handle<Struct> obj, size_t index, Heap::Tenure tenure)
    66 {
    67     Local<Reference> ref(zone, Reference::cast(zone->allocate(MapKind_Reference, sizeof(Reference), tenure)));
    68     if (!ref)
    69         return NULL;
    70 
    71     Descriptor *desc = Descriptor::cast(obj->map()->type()->fields()->at(index));
    72     ref->location_ = obj->ref(desc);
    73     ref->base_ = obj;
    74     return ref;
    75 }
    76