Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

[logos] Support automatic generation of %new type encodings

(cherry picked from commit e88376e)

git-svn-id: http://svn.howett.net/svn/theos/trunk@422 4410221e-0ddf-4ce3-99c0-2db6c0dbc727
  • Loading branch information...
commit 3ea0b009ec3f7fcdd13d82cb5e6033a65a11c713 1 parent 86194e7
@DHowett DHowett authored
View
13 bin/lib/Logos/Generator/MobileSubstrate/Method.pm
@@ -70,7 +70,18 @@ sub initializers {
if(!$self->{NEW}) {
return "MSHookMessageEx(\$\$".$self->classname.", \@selector(".$self->selector."), (IMP)&".$self->newFunctionName.", (IMP*)&".$self->originalFunctionName.");";
} else {
- return "class_addMethod(\$\$".$self->classname.", \@selector(".$self->selector."), (IMP)&".$self->newFunctionName.", \"".$self->{TYPE}."\");";
+ my $r = "";
+ $r .= "{ ";
+ if(!$self->{TYPE}) {
+ $r .= "char _typeEncoding[1024]; unsigned int i = 0; ";
+ map $r .= "memcpy(_typeEncoding + i, \@encode($_), strlen(\@encode($_))); i += strlen(\@encode($_)); ", ($self->{RETURN}, "id", "SEL", @{$self->{ARGTYPES}});
+ $r .= "_typeEncoding[i] = '\\0'; ";
+ } else {
+ $r .= "const char *_typeEncoding = \"".$self->{TYPE}."\"; ";
+ }
+ $r .= "class_addMethod(\$\$".$self->classname.", \@selector(".$self->selector."), (IMP)&".$self->newFunctionName.", _typeEncoding); ";
+ $r .= "}";
+ return $r;
}
}
View
5 bin/logos.pl
@@ -311,9 +311,8 @@
next if fallsBetween($-[0], @quotes);
nestingMustContain($lineno, "%new", \@nestingstack, "hook", "subclass");
- my $xtype = "v\@:";
+ my $xtype = "";
$xtype = $2 if $2;
- fileWarning($lineno, "%new without a type specifier, assuming v\@: (void return, id and SEL args)") if !$2;
$isNewMethod = $xtype;
$line = $`.$';
@@ -347,7 +346,7 @@
$currentMethod->scope($scope);
$currentMethod->return($return);
- if($isNewMethod) {
+ if(defined $isNewMethod) {
$currentMethod->setNew(1);
$currentMethod->type($isNewMethod);
$isNewMethod = undef;
View
1  extras/vim/syntax/logos.vim
@@ -19,6 +19,7 @@ syn match logosDirective '%log' display contained containedin=logosHook,logosSub
syn match logosDirective '%orig' display contained containedin=logosHook,logosSubclass,logosGroup
syn match logosDirective '%init' display
+syn match logosDirective '%new' display
syn region logosInit matchgroup=logosDirective start='%init(' end=')' contains=cParen
syn region logosNew oneline matchgroup=logosNew start='%new(' end=')' contains=logosTypeEncoding,logosTypeEncodingUnion

0 comments on commit 3ea0b00

Please sign in to comment.
Something went wrong with that request. Please try again.