fix codetest failure - ASSERT_ARGS does not have a ; after and
[parrot.git] / src / pmc / packfileannotation.pmc
blob0e697196a7abc3b92b52b8a5f1f1d8e5a9c2db47
1 /*
2 Copyright (C) 2001-2010, 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 /* HEADERIZER HFILE: none */
23 /* HEADERIZER BEGIN: static */
24 /* HEADERIZER END: static */
26 pmclass PackfileAnnotation auto_attrs {
27     ATTR STRING    *name;
28     ATTR INTVAL     offset;
29     ATTR INTVAL     value_type;
30     /* This 3 attributes should be in single union. But Pmc2c isn't smart enough to handle it */
31     ATTR INTVAL     int_value;
32     ATTR FLOATVAL   num_value;
33     ATTR STRING    *str_value;
37 =item C<init>
39 Create empty PackfileAnnotation.
41 =cut
45     VTABLE void init() {
46         Parrot_PackfileAnnotation_attributes * const attrs =
47                 PMC_data_typed(SELF, Parrot_PackfileAnnotation_attributes*);
49         PObj_custom_mark_SET(SELF);
50         PMC_data(SELF) = attrs;
51     }
55 =item C<void mark()>
57 Marks the object as live.
59 =cut
63     VTABLE void mark() {
64         Parrot_PackfileAnnotation_attributes * const attrs =
65                 PARROT_PACKFILEANNOTATION(SELF);
67         Parrot_gc_mark_STRING_alive(INTERP, attrs->name);
68         Parrot_gc_mark_STRING_alive(INTERP, attrs->str_value);
69     }
74 =item C<INTVAL get_offset()>
76 Fetch the offset into the bytecode of the instruction that is being annotated.
78 =cut
81     METHOD get_offset() {
82         INTVAL offset = PARROT_PACKFILEANNOTATION(SELF)->offset;
83         RETURN(INTVAL offset);
84     }
89 =item C<void set_offset(INTVAL offset)>
91 Set the offset into the bytecode of the instruction that is being annotated.
93 =cut
96     METHOD set_offset(INTVAL offset) {
97         PARROT_PACKFILEANNOTATION(SELF)->offset = offset;
98     }
103 =item C<STRING* get_name()>
105 Fetch the name of the annotation.
107 =cut
110     METHOD get_name() {
111         STRING * name = PARROT_PACKFILEANNOTATION(SELF)->name;
112         RETURN(STRING * name);
113     }
118 =item C<void set_name(STRING* name)>
120 Set the name of the annotation.
122 =cut
125     METHOD set_name(STRING * name) {
126         PARROT_PACKFILEANNOTATION(SELF)->name = name;
127     }
132 =item C<INTVAL get_integer()>
134 Fetch the integer value of the annotation.
136 =cut
139     VTABLE INTVAL get_integer() {
140         Parrot_PackfileAnnotation_attributes * const attrs = PARROT_PACKFILEANNOTATION(SELF);
141         if (attrs->value_type != PF_ANNOTATION_KEY_TYPE_INT)
142             Parrot_ex_throw_from_c_args(INTERP, NULL, EXCEPTION_INVALID_OPERATION,
143                 "Trying to fetch wrong type of value from annotation");
144         return attrs->int_value;
145     }
150 =item C<void set_integer_native(INTVAL value)>
152 Set the integer value of the annotation.
154 =cut
157     VTABLE void set_integer_native(INTVAL value) {
158         Parrot_PackfileAnnotation_attributes * const attrs = PARROT_PACKFILEANNOTATION(SELF);
159         attrs->value_type = PF_ANNOTATION_KEY_TYPE_INT;
160         attrs->int_value  = value;
161     }
165 =item C<STRING * get_string()>
167 Fetch the string value of the annotation.
169 =cut
172     VTABLE STRING * get_string() {
173         Parrot_PackfileAnnotation_attributes * const attrs = PARROT_PACKFILEANNOTATION(SELF);
174         if (attrs->value_type != PF_ANNOTATION_KEY_TYPE_STR)
175             Parrot_ex_throw_from_c_args(INTERP, NULL, EXCEPTION_INVALID_OPERATION,
176                 "Trying to fetch wrong type of value from annotation");
177         return attrs->str_value;
178     }
183 =item C<void set_string_native(STRING * value)>
185 Set the string value of the annotation.
187 =cut
190     VTABLE void set_string_native(STRING * value) {
191         Parrot_PackfileAnnotation_attributes * const attrs = PARROT_PACKFILEANNOTATION(SELF);
192         attrs->value_type = PF_ANNOTATION_KEY_TYPE_STR;
193         attrs->str_value  = value;
194     }
198 =item C<INTVAL get_number()>
200 Fetch the float value of the annotation.
202 =cut
205     VTABLE FLOATVAL get_number() {
206         Parrot_PackfileAnnotation_attributes * const attrs = PARROT_PACKFILEANNOTATION(SELF);
207         if (attrs->value_type != PF_ANNOTATION_KEY_TYPE_NUM)
208             Parrot_ex_throw_from_c_args(INTERP, NULL, EXCEPTION_INVALID_OPERATION,
209                 "Trying to fetch wrong type of value from annotation");
210         return attrs->num_value;
211     }
216 =item C<void set_number_native(INTVAL value)>
218 Set the float value of the annotation.
220 =cut
223     VTABLE void set_number_native(FLOATVAL value) {
224         Parrot_PackfileAnnotation_attributes * const attrs = PARROT_PACKFILEANNOTATION(SELF);
225         attrs->value_type = PF_ANNOTATION_KEY_TYPE_NUM;
226         attrs->num_value  = value;
227     }
232 =back
234 =cut
239  * Local variables:
240  *   c-file-style: "parrot"
241  * End:
242  * vim: expandtab shiftwidth=4:
243  */