tagged release 0.6.4
[parrot.git] / languages / dotnet / pmc / dotnetmethodmetadata.pmc
blob7dbb8d903fbf87cf401229d4064325926fdc1c3f
1 /*
2  * $Id$
3  * Copyright (C) 2006-2008, The Perl Foundation.
4  */
6 /* .NET CLI Method Metadata PMC */
9 #include "parrot/extend.h"
10 #include "tableinfo.h"
11 #include "structures.h"
14 pmclass DotNetMethodMetadata dynpmc group dotnet {
16     /* Instance initialization. We need a custom DOD marking and destroy. */
17     void init()
18     {
19         PObj_custom_mark_SET(SELF);
20         PObj_active_destroy_SET(SELF);
21     }
24     /* Get string vtable function; returns the name of the method. */
25     STRING* get_string()
26     {
27         dotnet_method *m = (dotnet_method *)PMC_struct_val(SELF);
29         /* Handle cases where we've an invalid PMC. */
30         if (!m || !m->str_name)
31             real_exception(INTERP, NULL, E_StandardError,
32                "Invalid DotNetMethodMetadata PMC");
34         return m->str_name;
35     }
38     /* Garbage Collection mark routine. */
39     void mark()
40     {
41         /* Tell the GC about stuff we're holding on to. */
42         dotnet_method *m = (dotnet_method *)PMC_struct_val(SELF);
43         if (m)
44         {
45             if (m->parent)
46                 pobject_lives(INTERP, (PObj*)m->parent);
47             if (m->str_name)
48                 pobject_lives(INTERP, (PObj*)m->str_name);
49             if (m->params)
50                 pobject_lives(INTERP, (PObj*)m->params);
51             if (m->bytecode)
52                 pobject_lives(INTERP, (PObj*)m->bytecode);
53         }
54     }
57     /* Destructor. */
58     void destroy()
59     {
60         /* Cleanup any memory we're using. */
61         if (PMC_struct_val(SELF)) {
62             mem_sys_free(PMC_struct_val(SELF));
63             PMC_struct_val(SELF) = NULL;
64         }
65     }
68     /* Get flags of the method. */
69     METHOD INTVAL get_flags()
70     {
71         dotnet_method *m = (dotnet_method *)PMC_struct_val(SELF);
72         INTVAL         result;
74         /* Handle cases where we've an invalid PMC. */
75         if (!m)
76             real_exception(INTERP, NULL, E_StandardError,
77                "Invalid DotNetMethodMetadata PMC");
79         result = (INTVAL)m->flags;
80         RETURN(INTVAL result);
81     }
84     /* Get implementation flags of the method. */
85     METHOD INTVAL get_impl_flags()
86     {
87         dotnet_method *m = (dotnet_method *)PMC_struct_val(SELF);
88         INTVAL         result;
90         /* Handle cases where we've an invalid PMC. */
91         if (!m)
92             real_exception(INTERP, NULL, E_StandardError,
93                "Invalid DotNetMethodMetadata PMC");
95         result = (INTVAL)m->implFlags;
96         RETURN(INTVAL result);
97     }
100     /* Get the position of the blob holding the signature for the method. */
101     METHOD INTVAL get_signature()
102     {
103         dotnet_method *m = (dotnet_method *)PMC_struct_val(SELF);
104         INTVAL         result;
106         /* Handle cases where we've an invalid PMC. */
107         if (!m)
108             real_exception(INTERP, NULL, E_StandardError,
109                "Invalid DotNetMethodMetadata PMC");
111         result = (INTVAL)m->signature;
112         RETURN(INTVAL result);
113     }
116     /* Get bytecode PMC for the method. */
117     METHOD PMC* get_bytecode()
118     {
119         dotnet_method *m = (dotnet_method *)PMC_struct_val(SELF);
120         PMC           *result;
122         /* Handle cases where we've an invalid PMC. */
123         if (!m || m->bytecode == NULL)
124             real_exception(INTERP, NULL, E_StandardError,
125                "Invalid DotNetMethodMetadata PMC");
127         result = m->bytecode;
128         RETURN(PMC *result);
129     }
132     /* Get parameters PMC array for the method. */
133     METHOD PMC* get_params()
134     {
135         dotnet_method *m = (dotnet_method *)PMC_struct_val(SELF);
136         PMC           *result;
138         /* Handle cases where we've an invalid PMC. */
139         if (!m || !m->params)
140             real_exception(INTERP, NULL, E_StandardError,
141                "Invalid DotNetMethodMetadata PMC");
143         result = m->params;
144         RETURN(PMC *result);
145     }
148     /* Get the class meta-data PMC for the method. */
149     METHOD PMC* get_class()
150     {
151         dotnet_method *m = (dotnet_method *)PMC_struct_val(SELF);
152         PMC           *result;
154         /* Handle cases where we've an invalid PMC. */
155         if (!m || !m->parent)
156             real_exception(INTERP, NULL, E_StandardError,
157                "Invalid DotNetMethodMetadata PMC");
159         result = m->parent;
160         RETURN(PMC *result);
161     }
166  * Local variables:
167  *   c-file-style: "parrot"
168  * End:
169  * vim: expandtab shiftwidth=4:
170  */