/*
 * $Id: /mirror/trunk/languages/dotnet/pmc/dotnetmemberrefmetadata.pmc 29983 2008-08-02T22:45:13.271765Z allison  $
 * Copyright (C) 2006-2008, The Perl Foundation.
 */

/* .NET CLI MemberRef Metadata PMC */


#include "parrot/extend.h"
#include "tableinfo.h"
#include "structures.h"


pmclass DotNetMemberRefMetadata dynpmc group dotnet {

    /* Instance initialization. We need a custom DOD marking and destroy. */
    void init()
    {
        PObj_custom_mark_SET(SELF);
        PObj_active_destroy_SET(SELF);
    }


    /* Get string vtable function; returns the name of the member. */
    STRING* get_string()
    {
        dotnet_memberref *c = (dotnet_memberref *)PMC_struct_val(SELF);

        /* Handle cases where we've an invalid PMC. */
        if (!c || !c->str_name)
            Parrot_ex_throw_from_c_args(INTERP, NULL, EXCEPTION_INVALID_OPERATION,
               "Invalid DotNetMemberRefMetadata PMC");

        return c->str_name;
    }


    /* Garbage Collection mark routine. */
    void mark()
    {
        /* Tell the GC about stuff we're holding on to. */
        dotnet_memberref *c = (dotnet_memberref *)PMC_struct_val(SELF);

        if (c && c->str_name)
            pobject_lives(INTERP, (PObj*)c->str_name);
    }


    /* Destructor. */
    void destroy()
    {
        /* Cleanup any memory we're using. */
        if (PMC_struct_val(SELF)) {
            mem_sys_free(PMC_struct_val(SELF));
            PMC_struct_val(SELF) = NULL;
        }
    }


    /* Get the location of the signature blob for this member. */
    METHOD INTVAL get_signature()
    {
        dotnet_memberref *c = (dotnet_memberref *)PMC_struct_val(SELF);
        INTVAL            result;

        /* Handle cases where we've an invalid PMC. */
        if (!c)
            Parrot_ex_throw_from_c_args(INTERP, NULL, EXCEPTION_INVALID_OPERATION,
               "Invalid DotNetMemberRefMetadata PMC");

        result = c->signature;
        RETURN(INTVAL result);
    }


    /* Get the type of "class" that the member belongs to. */
    METHOD INTVAL get_class_type()
    {
        dotnet_memberref *c = (dotnet_memberref *)PMC_struct_val(SELF);
        INTVAL            result;

        /* Handle cases where we've an invalid PMC. */
        if (!c)
            Parrot_ex_throw_from_c_args(INTERP, NULL, EXCEPTION_INVALID_OPERATION,
               "Invalid DotNetMemberRefMetadata PMC");

        result = c->class_type;
        RETURN(INTVAL result);
    }


    /* Get the id of "class" that the member belongs to. */
    METHOD INTVAL get_class_id()
    {
        dotnet_memberref *c = (dotnet_memberref *)PMC_struct_val(SELF);
        INTVAL            result;

        /* Handle cases where we've an invalid PMC. */
        if (!c)
            Parrot_ex_throw_from_c_args(INTERP, NULL, EXCEPTION_INVALID_OPERATION,
               "Invalid DotNetMemberRefMetadata PMC");

        result = c->class_id;
        RETURN(INTVAL result);
    }
}


/*
 * Local variables:
 *   c-file-style: "parrot"
 * End:
 * vim: expandtab shiftwidth=4:
 */
