2 Copyright (C) 2001-2010, Parrot Foundation.
7 src/pmc/packfileannotation.pmc - PackfileAnnotation PMC
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.
22 /* HEADERIZER HFILE: none */
23 /* HEADERIZER BEGIN: static */
24 /* HEADERIZER END: static */
26 pmclass PackfileAnnotation auto_attrs {
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;
39 Create empty PackfileAnnotation.
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;
57 Marks the object as live.
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);
74 =item C<INTVAL get_offset()>
76 Fetch the offset into the bytecode of the instruction that is being annotated.
82 INTVAL offset = PARROT_PACKFILEANNOTATION(SELF)->offset;
83 RETURN(INTVAL offset);
89 =item C<void set_offset(INTVAL offset)>
91 Set the offset into the bytecode of the instruction that is being annotated.
96 METHOD set_offset(INTVAL offset) {
97 PARROT_PACKFILEANNOTATION(SELF)->offset = offset;
103 =item C<STRING* get_name()>
105 Fetch the name of the annotation.
111 STRING * name = PARROT_PACKFILEANNOTATION(SELF)->name;
112 RETURN(STRING * name);
118 =item C<void set_name(STRING* name)>
120 Set the name of the annotation.
125 METHOD set_name(STRING * name) {
126 PARROT_PACKFILEANNOTATION(SELF)->name = name;
132 =item C<INTVAL get_integer()>
134 Fetch the integer value of the annotation.
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;
150 =item C<void set_integer_native(INTVAL value)>
152 Set the integer value of the annotation.
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;
165 =item C<STRING * get_string()>
167 Fetch the string value of the annotation.
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;
183 =item C<void set_string_native(STRING * value)>
185 Set the string value of the annotation.
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;
198 =item C<INTVAL get_number()>
200 Fetch the float value of the annotation.
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;
216 =item C<void set_number_native(INTVAL value)>
218 Set the float value of the annotation.
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;
240 * c-file-style: "parrot"
242 * vim: expandtab shiftwidth=4: