Permalink
Browse files

Move the logic from PackfileView.all_subs() to a new pf api routine P…

…arrot_pf_all_subs, to try and keep all logic in the api and out of the pmc
  • Loading branch information...
Whiteknight committed Aug 10, 2012
1 parent 1403dd4 commit 26ed7835452ad7608a6ad8c99dabf0ff2f41aeca
Showing with 44 additions and 11 deletions.
  1. +9 −0 include/parrot/packfile.h
  2. +34 −0 src/packfile/api.c
  3. +1 −11 src/pmc/packfileview.pmc
@@ -754,6 +754,12 @@ PMC * PackFile_Annotations_lookup(PARROT_INTERP,
__attribute__nonnull__(1)
__attribute__nonnull__(2);
PARROT_CANNOT_RETURN_NULL
PARROT_WARN_UNUSED_RESULT
PMC * Parrot_pf_all_subs(PARROT_INTERP, ARGIN(PMC *pfpmc))
__attribute__nonnull__(1)
__attribute__nonnull__(2);
PARROT_CANNOT_RETURN_NULL
PARROT_WARN_UNUSED_RESULT
PMC * Parrot_pf_all_tags_list(PARROT_INTERP, ARGIN(PMC * pfpmc))
@@ -891,6 +897,9 @@ void Parrot_pf_mark_packfile(PARROT_INTERP, ARGMOD_NULLOK(PackFile * pf))
#define ASSERT_ARGS_PackFile_Annotations_lookup __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
PARROT_ASSERT_ARG(interp) \
, PARROT_ASSERT_ARG(self))
#define ASSERT_ARGS_Parrot_pf_all_subs __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
PARROT_ASSERT_ARG(interp) \
, PARROT_ASSERT_ARG(pfpmc))
#define ASSERT_ARGS_Parrot_pf_all_tags_list __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
PARROT_ASSERT_ARG(interp) \
, PARROT_ASSERT_ARG(pfpmc))
@@ -545,6 +545,40 @@ Parrot_pf_all_tags_list(PARROT_INTERP, ARGIN(PMC * pfpmc))
/*
=item C<PMC * Parrot_pf_all_subs(PARROT_INTERP, PMC *pfpmc)>
Return an array of all Sub PMCs from the packfile
=cut
*/
PARROT_CANNOT_RETURN_NULL
PARROT_WARN_UNUSED_RESULT
PMC *
Parrot_pf_all_subs(PARROT_INTERP, ARGIN(PMC *pfpmc))
{
ASSERT_ARGS(Parrot_pf_all_subs)
PackFile * const pf = (PackFile*)VTABLE_get_pointer(interp, pfpmc);
if (!pf || !pf->cur_cs || !pf->cur_cs->const_table)
Parrot_ex_throw_from_c_args(interp, NULL, EXCEPTION_UNEXPECTED_NULL,
"NULL or invalid packfile");
{
PackFile_ConstTable * const ct = pf->cur_cs->const_table;
PMC * const array = Parrot_pmc_new(interp, enum_class_ResizablePMCArray);
INTVAL i;
STRING * const SUB = CONST_STRING(interp, "Sub");
for (i = 0; i < ct->pmc.const_count; ++i) {
PMC * const x = ct->pmc.constants[i];
if (VTABLE_isa(interp, x, SUB))
VTABLE_push_pmc(interp, array, x);
}
return array;
}
}
/*
=item C<static int sub_pragma(PARROT_INTERP, pbc_action_enum_t action, const PMC
*sub_pmc)
@@ -387,17 +387,7 @@ Determine if the given tag has been marked initialized
}
METHOD all_subs() {
PMC * const array = Parrot_pmc_new(INTERP, enum_class_ResizablePMCArray);
PackFile_ConstTable * const ct = get_const_table(INTERP, SELF);
if (ct) {
INTVAL i;
STRING * const SUB = CONST_STRING(interp, "Sub");
for (i = 0; i < ct->pmc.const_count; ++i) {
PMC * const x = ct->pmc.constants[i];
if (VTABLE_isa(interp, x, SUB))
VTABLE_push_pmc(INTERP, array, x);
}
}
PMC * const array = Parrot_pf_all_subs(INTERP, SELF);
RETURN(PMC *array);
}

0 comments on commit 26ed783

Please sign in to comment.