Permalink
Switch branches/tags
Find file
Fetching contributors…
Cannot retrieve contributors at this time
288 lines (186 sloc) 5.57 KB
/*
Copyright (C) 2001-2014, Parrot Foundation.
=head1 NAME
src/pmc/packfileannotation.pmc - PackfileAnnotation PMC
=head1 DESCRIPTION
This class implements a PackfileAnnotation object. It is an element in the
PackfileAnnotations segment of the .pbc file. See PDD13 for a design spec.
=head2 Methods
=over 4
=cut
*/
/* HEADERIZER HFILE: none */
/* HEADERIZER BEGIN: static */
/* HEADERIZER END: static */
pmclass PackfileAnnotation auto_attrs {
ATTR STRING *name;
ATTR INTVAL offset;
ATTR INTVAL value_type;
/* This 3 attributes should be in single union. But Pmc2c isn't smart enough to handle it */
ATTR INTVAL int_value;
ATTR STRING *str_value;
ATTR PMC *pmc_value;
/*
=item C<init>
Create empty PackfileAnnotation.
=cut
*/
VTABLE void init() {
Parrot_PackfileAnnotation_attributes * const attrs =
PMC_data_typed(SELF, Parrot_PackfileAnnotation_attributes*);
PObj_custom_mark_SET(SELF);
PMC_data(SELF) = attrs;
}
/*
=item C<void mark()>
Marks the object as live.
=cut
*/
VTABLE void mark() :no_wb {
const Parrot_PackfileAnnotation_attributes * const attrs =
PARROT_PACKFILEANNOTATION(SELF);
Parrot_gc_mark_STRING_alive(INTERP, attrs->name);
Parrot_gc_mark_STRING_alive(INTERP, attrs->str_value);
}
/*
=item C<INTVAL get_offset()>
Fetch the offset into the bytecode of the instruction that is being annotated.
=cut
*/
METHOD get_offset() :no_wb {
const INTVAL offset = PARROT_PACKFILEANNOTATION(SELF)->offset;
RETURN(INTVAL offset);
}
/*
=item C<void set_offset(INTVAL offset)>
Set the offset into the bytecode of the instruction that is being annotated.
=cut
*/
METHOD set_offset(INTVAL offset) {
PARROT_PACKFILEANNOTATION(SELF)->offset = offset;
}
/*
=item C<STRING* get_name()>
Fetch the name of the annotation.
=cut
*/
METHOD get_name() :no_wb {
STRING * const name = PARROT_PACKFILEANNOTATION(SELF)->name;
RETURN(STRING * name);
}
/*
=item C<void set_name(STRING* name)>
Set the name of the annotation.
=cut
*/
METHOD set_name(STRING * name) {
PARROT_PACKFILEANNOTATION(SELF)->name = name;
}
/*
=item C<PMC *get_pmc_value()>
Fetch the PMC value of the annotation.
=cut
*/
METHOD get_pmc_value() :no_wb {
const Parrot_PackfileAnnotation_attributes * const attrs = PARROT_PACKFILEANNOTATION(SELF);
if (attrs->value_type != PF_ANNOTATION_KEY_TYPE_PMC)
Parrot_ex_throw_from_c_noargs(INTERP, EXCEPTION_INVALID_OPERATION,
"Wrong type of value from annotation");
RETURN(PMC * attrs->pmc_value);
}
/*
=item C<void set_pmc_value(PMC *value)>
Set the PMC value of the annotation.
=cut
*/
METHOD set_pmc_value(PMC * value) {
Parrot_PackfileAnnotation_attributes * const attrs = PARROT_PACKFILEANNOTATION(SELF);
attrs->value_type = PF_ANNOTATION_KEY_TYPE_PMC;
attrs->pmc_value = value;
}
/*
=item C<INTVAL get_type()>
Get the type of the annotation.
=over 4
=item * 0 = Integer
=item * 1 = String
=item * 2 = PMC
=back
=cut
*/
METHOD get_type() :no_wb {
/* These values were chosen to match the type values for opcodes */
Parrot_PackfileAnnotation_attributes * const attrs = PARROT_PACKFILEANNOTATION(SELF);
INTVAL ret;
switch (attrs->value_type) {
case PF_ANNOTATION_KEY_TYPE_INT:
ret = 0;
break;
case PF_ANNOTATION_KEY_TYPE_STR:
ret = 1;
break;
case PF_ANNOTATION_KEY_TYPE_PMC:
ret = 2;
break;
default:
Parrot_ex_throw_from_c_noargs(INTERP, EXCEPTION_INVALID_OPERATION,
"Wrong type of value from annotation");
break;
}
RETURN(INTVAL ret);
}
/*
=item C<INTVAL get_integer()>
Fetch the integer value of the annotation.
=cut
*/
VTABLE INTVAL get_integer() :no_wb {
const Parrot_PackfileAnnotation_attributes * const attrs = PARROT_PACKFILEANNOTATION(SELF);
if (attrs->value_type != PF_ANNOTATION_KEY_TYPE_INT)
Parrot_ex_throw_from_c_noargs(INTERP, EXCEPTION_INVALID_OPERATION,
"Wrong type of value from annotation");
return attrs->int_value;
}
/*
=item C<void set_integer_native(INTVAL value)>
Set the integer value of the annotation.
=cut
*/
VTABLE void set_integer_native(INTVAL value) {
Parrot_PackfileAnnotation_attributes * const attrs = PARROT_PACKFILEANNOTATION(SELF);
attrs->value_type = PF_ANNOTATION_KEY_TYPE_INT;
attrs->int_value = value;
}
/*
=item C<STRING * get_string()>
Fetch the string value of the annotation.
=cut
*/
VTABLE STRING * get_string() :no_wb {
Parrot_PackfileAnnotation_attributes * const attrs = PARROT_PACKFILEANNOTATION(SELF);
if (attrs->value_type != PF_ANNOTATION_KEY_TYPE_STR)
Parrot_ex_throw_from_c_noargs(INTERP, EXCEPTION_INVALID_OPERATION,
"Wrong type of value from annotation");
return attrs->str_value;
}
/*
=item C<void set_string_native(STRING * value)>
Set the string value of the annotation.
=cut
*/
VTABLE void set_string_native(STRING * value) {
Parrot_PackfileAnnotation_attributes * const attrs = PARROT_PACKFILEANNOTATION(SELF);
attrs->value_type = PF_ANNOTATION_KEY_TYPE_STR;
attrs->str_value = value;
}
}
/*
=back
=cut
*/
/*
* Local variables:
* c-file-style: "parrot"
* End:
* vim: expandtab shiftwidth=4 cinoptions='\:2=2' :
*/