fix codetest failure - trailing whitespace
[parrot.git] / src / pmc / packfileannotation.pmc
blobe84ccfc958fc5f54e62e199e628793c7d46132ba
1 /*
2 Copyright (C) 2001-2008, Parrot Foundation.
3 $Id$
5 =head1 NAME
7 src/pmc/packfileannotation.pmc - PackfileAnnotation PMC
9 =head1 DESCRIPTION
11 This class implements a PackfileAnnotation object.  It is an element in the
12 PackfileAnnotations segment of the .pbc file.  See PDD13 for a design spec.
14 =head2 Methods
16 =over 4
18 =cut
22 pmclass PackfileAnnotation auto_attrs {
23     ATTR STRING    *name;
24     ATTR INTVAL     offset;
25     ATTR INTVAL     value_type;
26     /* This 3 attributes should be in single union. But Pmc2c isn't smart enough to handle it */
27     ATTR INTVAL     int_value;
28     ATTR FLOATVAL   num_value;
29     ATTR STRING    *str_value;
33 =item C<init>
35 Create empty PackfileAnnotation.
37 =cut
41     VTABLE void init() {
42         Parrot_PackfileAnnotation_attributes * attrs =
43                 PMC_data_typed(SELF, Parrot_PackfileAnnotation_attributes*);
45         PObj_custom_mark_SET(SELF);
46         PMC_data(SELF) = attrs;
47     }
51 =item C<void mark()>
53 Marks the object as live.
55 =cut
59     VTABLE void mark() {
60         Parrot_PackfileAnnotation_attributes * attrs =
61                 PARROT_PACKFILEANNOTATION(SELF);
63         Parrot_gc_mark_STRING_alive(interp, attrs->name);
64         Parrot_gc_mark_STRING_alive(interp, attrs->str_value);
65     }
70 =item C<INTVAL get_offset()>
72 Fetch the offset into the bytecode of the instruction that is being annotated.
74 =cut
77     METHOD get_offset() {
78         INTVAL offset = PARROT_PACKFILEANNOTATION(SELF)->offset;
79         RETURN(INTVAL offset);
80     }
85 =item C<void set_offset(INTVAL offset)>
87 Set the offset into the bytecode of the instruction that is being annotated.
89 =cut
92     METHOD set_offset(INTVAL offset) {
93         PARROT_PACKFILEANNOTATION(SELF)->offset = offset;
94     }
99 =item C<STRING* get_name()>
101 Fetch the name of the annotation.
103 =cut
106     METHOD get_name() {
107         STRING * name = PARROT_PACKFILEANNOTATION(SELF)->name;
108         RETURN(STRING * name);
109     }
114 =item C<void set_name(STRING* name)>
116 Set the name of the annotation.
118 =cut
121     METHOD set_name(STRING * name) {
122         PARROT_PACKFILEANNOTATION(SELF)->name = name;
123     }
128 =item C<INTVAL get_integer()>
130 Fetch the integer value of the annotation.
132 =cut
135     VTABLE INTVAL get_integer() {
136         Parrot_PackfileAnnotation_attributes * attrs = PARROT_PACKFILEANNOTATION(SELF);
137         if (attrs->value_type != PF_ANNOTATION_KEY_TYPE_INT)
138             Parrot_ex_throw_from_c_args(interp, NULL, EXCEPTION_INVALID_OPERATION,
139                 "Trying to fetch wrong type of value from annotation");
140         return attrs->int_value;
141     }
146 =item C<void set_integer_native(INTVAL value)>
148 Set the integer value of the annotation.
150 =cut
153     VTABLE void set_integer_native(INTVAL value) {
154         Parrot_PackfileAnnotation_attributes * attrs = PARROT_PACKFILEANNOTATION(SELF);
155         attrs->value_type = PF_ANNOTATION_KEY_TYPE_INT;
156         attrs->int_value  = value;
157     }
161 =item C<STRING * get_string()>
163 Fetch the string value of the annotation.
165 =cut
168     VTABLE STRING * get_string() {
169         Parrot_PackfileAnnotation_attributes * attrs = PARROT_PACKFILEANNOTATION(SELF);
170         if (attrs->value_type != PF_ANNOTATION_KEY_TYPE_STR)
171             Parrot_ex_throw_from_c_args(interp, NULL, EXCEPTION_INVALID_OPERATION,
172                 "Trying to fetch wrong type of value from annotation");
173         return attrs->str_value;
174     }
179 =item C<void set_string_native(STRING * value)>
181 Set the string value of the annotation.
183 =cut
186     VTABLE void set_string_native(STRING * value) {
187         Parrot_PackfileAnnotation_attributes * attrs = PARROT_PACKFILEANNOTATION(SELF);
188         attrs->value_type = PF_ANNOTATION_KEY_TYPE_STR;
189         attrs->str_value  = value;
190     }
194 =item C<INTVAL get_number()>
196 Fetch the float value of the annotation.
198 =cut
201     VTABLE FLOATVAL get_number() {
202         Parrot_PackfileAnnotation_attributes * attrs = PARROT_PACKFILEANNOTATION(SELF);
203         if (attrs->value_type != PF_ANNOTATION_KEY_TYPE_NUM)
204             Parrot_ex_throw_from_c_args(interp, NULL, EXCEPTION_INVALID_OPERATION,
205                 "Trying to fetch wrong type of value from annotation");
206         return attrs->num_value;
207     }
212 =item C<void set_number_native(INTVAL value)>
214 Set the float value of the annotation.
216 =cut
219     VTABLE void set_number_native(FLOATVAL value) {
220         Parrot_PackfileAnnotation_attributes * attrs = PARROT_PACKFILEANNOTATION(SELF);
221         attrs->value_type = PF_ANNOTATION_KEY_TYPE_NUM;
222         attrs->num_value  = value;
223     }
228 =back
230 =cut
235  * Local variables:
236  *   c-file-style: "parrot"
237  * End:
238  * vim: expandtab shiftwidth=4:
239  */