1 # Copyright (C) 2004-2008, Parrot Foundation.
3 package Parrot
::Pmc2c
::Method
;
6 use constant VTABLE_ENTRY
=> 'VTABLE_ENTRY';
7 use constant VTABLE
=> 'VTABLE';
8 use constant NON_VTABLE
=> 'NON_VTABLE';
9 use constant MULTI
=> 'MULTI';
10 use Parrot
::Pmc2c
::UtilFunctions
qw( args_from_parameter_list passable_args_from_parameter_list );
13 my ( $class, $self_hash ) = @_;
28 # this is usually wrong, but *something* calls new on an object somewhere
29 bless $self, ref $class || $class;
35 my ( $self, $self_hash ) = @_;
36 return $self->new( { ( %{$self}, %{ $self_hash || {} } ) } );
40 my ( $self, $value ) = @_;
41 push @
{ $self->{mmd_rights
} }, $value;
48 return $self->{mmd_rights
};
52 for my $x qw( name parent_name type return_type body mmds symbol mmd_prefix mmd_table mmd_name
53 right attrs decorators parameters ) {
56 my ( $self, $value ) = @_;
57 $self->{REPLACE} = $value if defined $value;
58 return $self->{REPLACE}
61 $code =~ s/REPLACE/$x/g;
67 my $type = $self->type;
68 return $type eq VTABLE
|| $type eq VTABLE_ENTRY
;
74 return 1 if $self->{mmd_name
};
75 return 1 if $self->mmds and scalar @
{ $self->mmds };
82 return 1 if $self->{MULTI
};
89 return $self->{pmc_unused
};
92 =head1 C<trans($type)>
94 Used in C<signature()> to normalize argument types.
99 my ( $self, $type ) = @_;
101 return 'v' unless $type;
103 my $char = substr $type, 0, 1;
105 return $1 if $char =~ /([ISP])/;
106 return 'N' if $char eq 'F';
107 return 'V' if $type =~ /void\s*\*/;
108 return 'v' if $type =~ /void\s*$/;
109 return 'P' if $type =~ /opcode_t\*/;
110 return 'I' if $type =~ /int(val)?/i;
114 =head1 C<signature()>
116 Returns the method signature for the methods $parameters
123 my $args = passable_args_from_parameter_list
( $self->parameters );
124 my ($types, $vars) = args_from_parameter_list
( $self->parameters );
125 my $return_type = $self->return_type;
126 my $return_type_char = $self->trans($return_type);
127 my $sig = $self->trans($return_type) .
128 join '', map { $self->trans($_) } @
{$types};
129 my $return_prefix = '';
130 my $method_suffix = '';
132 if ( $return_type ne 'void' ) {
133 $return_prefix = "return ($return_type)";
135 # PMC* and STRING* don't need a special suffix
136 if ( $return_type !~ /\*/ ) {
137 $method_suffix = "_ret" . lc substr $return_type, 0, 1;
139 # change UINTVAl type to reti
140 $method_suffix =~ s/_retu/_reti/;
144 my $null_return = '';
145 $null_return = "return ($return_type) NULL;" if $return_type_char =~ /P|I|S|V/;
146 $null_return = 'return (FLOATVAL) 0;' if $return_type_char =~ /N/;
147 $null_return = 'return;' if $return_type_char =~ /v/;
149 return ( $return_prefix, $method_suffix, $args, $sig, $return_type_char, $null_return );
156 # cperl-indent-level: 4
159 # vim: expandtab shiftwidth=4: