Skip to content

Commit

Permalink
Refactor some code from within Parrot::Headerizer::Object into intern…
Browse files Browse the repository at this point in the history
…al method

check_pointer_return_type().  Test it in 02_methods.t.  Replace repetitive
test setup code with a subroutine.
  • Loading branch information
jkeenan committed Dec 9, 2010
1 parent b1f035b commit 3129b83
Show file tree
Hide file tree
Showing 2 changed files with 328 additions and 64 deletions.
45 changes: 33 additions & 12 deletions lib/Parrot/Headerizer/Object.pm
Expand Up @@ -335,18 +335,12 @@ sub function_components_from_declaration {
$is_ignorable = 1;
}
}
if ( $return_type =~ /\*/ ) {
if ( !$macros{PARROT_CAN_RETURN_NULL} && !$macros{PARROT_CANNOT_RETURN_NULL} ) {
if ( $name !~ /^yy/ ) { # Don't complain about lexer-created functions
$self->squawk( $file, $name,
'Returns a pointer, but no PARROT_CAN(NOT)_RETURN_NULL macro found.' );
}
}
elsif ( $macros{PARROT_CAN_RETURN_NULL} && $macros{PARROT_CANNOT_RETURN_NULL} ) {
$self->squawk( $file, $name,
q{Can't have both PARROT_CAN_RETURN_NULL and PARROT_CANNOT_RETURN_NULL together.} );
}
}
$self->check_pointer_return_type( {
return_type => $return_type,
macros => \%macros,
name => $name,
file => $file,
} );

return {
file => $file,
Expand All @@ -361,6 +355,33 @@ sub function_components_from_declaration {
};
}

=head2 C<check_pointer_return_type()>
$self->check_pointer_return_type( {
return_type => $return_type,
macros => \%macros,
name => $name,
file => $file,
} );
=cut

sub check_pointer_return_type {
my ($self, $args) = @_;
if ( $args->{return_type} =~ /\*/ ) {
if ( !$args->{macros}->{PARROT_CAN_RETURN_NULL} && !$args->{macros}->{PARROT_CANNOT_RETURN_NULL} ) {
if ( $args->{name} !~ /^yy/ ) { # Don't complain about lexer-created functions
$self->squawk( $args->{file}, $args->{name},
'Returns a pointer, but no PARROT_CAN(NOT)_RETURN_NULL macro found.' );
}
}
elsif ( $args->{macros}->{PARROT_CAN_RETURN_NULL} && $args->{macros}->{PARROT_CANNOT_RETURN_NULL} ) {
$self->squawk( $args->{file}, $args->{name},
q{Can't have both PARROT_CAN_RETURN_NULL and PARROT_CANNOT_RETURN_NULL together.} );
}
}
}

=head2 C<generate_documentation_signature>
Given an extracted function signature, return a modified
Expand Down

0 comments on commit 3129b83

Please sign in to comment.