Affix
view release on metacpan or search on metacpan
lib/Affix/Wrap.pm view on Meta::CPAN
'unsigned long' => 'ULong',
'long long' => 'LongLong',
'unsigned long long' => 'ULongLong',
float => 'Float',
double => 'Double',
'long double' => 'LongDouble',
int8_t => 'Int8',
sint8_t => 'SInt8',
uint8_t => 'UInt8',
int16_t => 'Int16',
sint16_t => 'SInt16',
uint16_t => 'UInt16',
int32_t => 'Int32',
sint32_t => 'SInt32',
uint32_t => 'UInt32',
int64_t => 'Int64',
sint64_t => 'SInt64',
uint64_t => 'UInt64',
int128_t => 'Int128',
sint128_t => 'SInt128',
uint128_t => 'UInt128',
size_t => 'Size_t',
ssize_t => 'SSize_t',
ptrdiff_t => 'SSize_t',
wchar_t => 'WChar',
time_t => 'Int64',
'...' => 'VarArgs',
'va_list' => 'VarArgs',
'__builtin_va_list' => 'VarArgs', # Clang
#
'char[]' => 'String',
'file*' => 'File',
file => 'Void', # Fixes FILE* -> Pointer[Void]
'time_t' => 'Int64', # Standard timestamp
'jmp_buf' => 'Void', # Opaque handle for setjmp
'_jbtype' => 'Void', # Internal jmp_buf typedef
# 'tm' (struct tm) is undefined because we skip system headers.
# Mapping to Void ensures 'struct tm *' becomes 'Pointer[Void]'
'tm' => Affix::Pointer( [Void] ),
'struct tm' => Affix::Pointer( [Void] )
};
# Case-insensitive lookup (handled by existing code)
return $type_map->{ lc $t } if defined $type_map->{ lc $t };
return "'$t'" if $t =~ /^[a-z_]\w*$/i;
warn "WARNING: Unknown C type '$t' mapped to Void\n";
'Void';
}
method affix {
use Affix qw[Void];
my $type_str = $self->affix_type;
# Case 1: Simple named type (e.g. "Int", "UChar")
if ( $type_str =~ /^(\w+)$/ ) {
no strict 'refs';
my $fn = "Affix::$type_str";
return $fn->() if defined &{$fn}; # Return Affix::Int() object
return '@' . $type_str; # Return string "@png_byte"
}
# Case 2: Complex string (e.g. "Pointer[Void]")
# We return the string directly so Affix::affix() can parse it
return $type_str;
}
}
class #
Affix::Wrap::Type::Pointer : isa(Affix::Wrap::Type) {
use Affix qw[Pointer];
field $of : reader : param;
method name { $of->name . '*' }
method affix_type { 'Pointer[' . $of->affix_type . ']' }
method affix { Pointer [ $of->affix ] }
};
class #
Affix::Wrap::Type::Array : isa(Affix::Wrap::Type) {
use Affix qw[Array];
field $of : reader : param;
field $count : reader : param;
method name { $of->name . "[" . $count . "]" }
method affix_type { sprintf( 'Array[%s, %d]', $of->affix_type, $count ) }
method affix { Array [ $of->affix, $count ] }
};
class #
Affix::Wrap::Type::CodeRef : isa(Affix::Wrap::Type) {
use Affix qw[Callback];
field $ret : reader : param;
field $params : reader : param; # ArrayRef of Types
method name {
sprintf '%s (*)(%s)', $ret->name, join( ', ', map { $_->name } @$params );
}
method affix_type {
sprintf 'Callback[[%s] => %s]', join( ', ', map { $_->affix_type } @$params ), $ret->affix_type;
}
method affix {
Callback [ [ map { $_->affix } @$params ], $ret->affix ];
}
};
class #
Affix::Wrap::Argument {
field $type : reader : param;
field $name : reader : param //= '';
method to_string { length($name) ? $type->to_string . ' ' . $name : $type->to_string }
use overload '""' => 'to_string', fallback => 1;
method affix_type { $type->affix_type }
method affix { $type->affix }
}
class #
Affix::Wrap::Entity {
field $name : reader : param //= '';
field $doc : reader : param //= ();
field $file : reader : param //= '';
field $line : reader : param //= 0;
field $end_line : reader : param //= 0;
field $start_offset : reader : param //= 0;
field $end_offset : reader : param //= 0;
( run in 2.482 seconds using v1.01-cache-2.11-cpan-df04353d9ac )