tagged release 0.6.4
[parrot.git] / languages / dotnet / pmc / dotnetclassmetadata.pmc
blobcaf46a717255389b307a1e8984041bf701425a1b
1 /*
2  * $Id$
3  * Copyright (C) 2006-2008, The Perl Foundation.
4  */
6 /* .NET CLI Class Metadata PMC */
9 #include "parrot/extend.h"
10 #include "tableinfo.h"
11 #include "structures.h"
14 pmclass DotNetClassMetadata 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 class. */
25     STRING* get_string()
26     {
27         dotnet_class *c = (dotnet_class *)PMC_struct_val(SELF);
29         /* Handle cases where we've an invalid PMC. */
30         if (c == NULL || c->str_name == NULL)
31             real_exception(INTERP, NULL, E_StandardError,
32                "Invalid DotNetClassMetadata PMC");
34         return c->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_class *c = (dotnet_class *)PMC_struct_val(SELF);
43         if (c) {
44             if (c->parent)
45                 pobject_lives(INTERP, (PObj *)c->parent);
46             if (c->str_name)
47                 pobject_lives(INTERP, (PObj *)c->str_name);
48             if (c->str_namespace)
49                 pobject_lives(INTERP, (PObj *)c->str_namespace);
50             if (c->str_fullname)
51                 pobject_lives(INTERP, (PObj *)c->str_fullname);
52             if (c->fields)
53                 pobject_lives(INTERP, (PObj *)c->fields);
54             if (c->methods)
55                 pobject_lives(INTERP, (PObj *)c->methods);
56             if (c->interface_types)
57                 pobject_lives(INTERP, (PObj *)c->interface_types);
58             if (c->interface_ids)
59                 pobject_lives(INTERP, (PObj *)c->interface_ids);
60         }
61     }
64     /* Destructor. */
65     void destroy()
66     {
67         /* Cleanup any memory we're using. */
68         if (PMC_struct_val(SELF))
69         {
70             mem_sys_free(PMC_struct_val(SELF));
71             PMC_struct_val(SELF) = NULL;
72         }
73     }
76     /* Get the namespace of the class. */
77         METHOD STRING* get_namespace()
78     {
79         dotnet_class *c = (dotnet_class *)PMC_struct_val(SELF);
80         STRING       *result;
82         /* Handle cases where we've an invalid PMC. */
83         if (!c)
84             real_exception(INTERP, NULL, E_StandardError,
85                "Invalid DotNetClassMetadata PMC");
86         result = c->str_namespace;
87         RETURN(STRING *result);
88     }
91     /* Get the fully qualified name of the class. */
92     METHOD STRING* get_fullname()
93     {
94         dotnet_class *c = (dotnet_class *)PMC_struct_val(SELF);
95         STRING       *result;
97         /* Handle cases where we've an invalid PMC. */
98         if (!c)
99             real_exception(INTERP, NULL, E_StandardError,
100                "Invalid DotNetClassMetadata PMC");
102         result = c->str_fullname;
103         RETURN(STRING *result);
104     }
107     /* Get the flags of the class. */
108     METHOD INTVAL get_flags()
109     {
110         dotnet_class *c = (dotnet_class *)PMC_struct_val(SELF);
111         INTVAL        result;
113         /* Handle cases where we've an invalid PMC. */
114         if (!c)
115             real_exception(INTERP, NULL, E_StandardError,
116                "Invalid DotNetClassMetadata PMC");
118         result = (INTVAL)c->flags;
119         RETURN(INTVAL result);
120     }
122     /* Get a PMC array of fields belonging to the class. */
123     METHOD PMC* get_fields()
124     {
125         dotnet_class *c = (dotnet_class *)PMC_struct_val(SELF);
126         PMC          *result;
128         /* Handle cases where we've an invalid PMC or no fields. */
129         if (!c)
130             real_exception(INTERP, NULL, E_StandardError,
131                "Invalid DotNetClassMetadata PMC");
133         if (c->fields)
134             result = c->fields;
135         else
136             result = pmc_new(INTERP, enum_class_FixedPMCArray);
138         RETURN(PMC *result);
139     }
142     /* Get a PMC array of methods belonging to the class. */
143     METHOD PMC* get_methods()
144     {
145         dotnet_class *c = (dotnet_class *)PMC_struct_val(SELF);
146         PMC          *result;
148         /* Handle cases where we've an invalid PMC or no methods. */
149         if (!c)
150             real_exception(INTERP, NULL, E_StandardError,
151                "Invalid DotNetClassMetadata PMC");
153         if (c->methods)
154             result = c->methods;
155         else
156             result = pmc_new(INTERP, enum_class_FixedPMCArray);
158         RETURN(PMC *result);
159     }
162     /* Get the id of the class that this one inherits. */
163     METHOD INTVAL get_parent_id()
164     {
165         dotnet_class *c = (dotnet_class *)PMC_struct_val(SELF);
166         INTVAL        result;
168         /* Handle cases where we've an invalid PMC. */
169         if (!c)
170             real_exception(INTERP, NULL, E_StandardError,
171                "Invalid DotNetClassMetadata PMC");
173         result = (INTVAL)c->parent_id;
174         RETURN(INTVAL result);
175     }
178     /* Get the type of the class that this one inherits. This is either a
179        type defined in this module or a reference to another module. */
180     METHOD INTVAL get_parent_type()
181     {
182         dotnet_class *c = (dotnet_class *)PMC_struct_val(SELF);
183         INTVAL        result;
185         /* Handle cases where we've an invalid PMC. */
186         if (!c)
187             real_exception(INTERP, NULL, E_StandardError,
188                "Invalid DotNetClassMetadata PMC");
190         result = (INTVAL)c->parent_type;
192         RETURN(INTVAL result);
193     }
196     /* Get the array of ids of the interfaces this class implements. */
197     METHOD PMC* get_interface_ids()
198     {
199         dotnet_class *c = (dotnet_class *)PMC_struct_val(SELF);
200         PMC          *result;
202         /* Handle cases where we've an invalid PMC. */
203         if (!c || !c->interface_ids)
204             real_exception(INTERP, NULL, E_StandardError,
205                "Invalid DotNetClassMetadata PMC");
207         result =  c->interface_ids;
208         RETURN(PMC *result);
209     }
212     /* Get the array of types of the interfaces this class implements. */
213     METHOD PMC* get_interface_types()
214     {
215         dotnet_class *c = (dotnet_class *)PMC_struct_val(SELF);
216         PMC          *result;
218         /* Handle cases where we've an invalid PMC. */
219         if (c == NULL || c->interface_types == NULL)
220             real_exception(INTERP, NULL, E_StandardError,
221                "Invalid DotNetClassMetadata PMC");
223         result = c->interface_types;
224         RETURN(PMC *result);
225     }
230  * Local variables:
231  *   c-file-style: "parrot"
232  * End:
233  * vim: expandtab shiftwidth=4:
234  */