diff --git a/examples/simple/nswrap.yaml b/examples/simple/nswrap.yaml index 9f9384d..acb993a 100644 --- a/examples/simple/nswrap.yaml +++ b/examples/simple/nswrap.yaml @@ -8,7 +8,7 @@ subclasses: ClassTwo: - geti1 - -(void)myMethod1:(int)a - - +(const NSObject* _Nonnull)myMethod2:(int)a:(NSDictionary *)options + - +(const NSObject* _Nonnull)myMethod2:(int)a options:(NSDictionary *)opt imports: [ simple.h ] frameworks: [ Foundation ] diff --git a/types/cparser.go b/types/cparser.go index 255d9a9..d2e9080 100644 --- a/types/cparser.go +++ b/types/cparser.go @@ -35,24 +35,24 @@ func init() { func MethodSignature(s string, n *Node) (string, *Node) { return ChildOf(NewNode("MethodSignature"),Seq( Parenthesized(TypeName), - MethodName, + Identifier, Opt(MethodParameterList), ))(s,n) } -func MethodName(s string, n *Node) (string, *Node) { +func MethodParameterList(s string, n *Node) (string, *Node) { return Seq( - Identifier, - Opt(Seq( - Lit(":"), - Parenthesized(TypeName), - Identifier, - )), + FirstMethodParameter, + ZeroOrMore(MethodParameter), )(s,n) } -func MethodParameterList(s string, n *Node) (string, *Node) { - return OneOrMore(MethodParameter)(s,n) +func FirstMethodParameter(s string, n *Node) (string, *Node) { + return ChildOf(NewNode("MethodParameter"),Seq( + Lit(":"), + Parenthesized(TypeName), + Identifier, + ))(s,n) } func MethodParameter(s string, n *Node) (string, *Node) { diff --git a/types/main_test.go b/types/main_test.go index fbd3ed4..13708b6 100644 --- a/types/main_test.go +++ b/types/main_test.go @@ -396,9 +396,10 @@ func TestParse(t *testing.T) { - '' -- 'void' - 'performSelector' -- '' --- 'SEL' -- 'aSelector' +- '' +-- '' +--- 'SEL' +-- 'aSelector' - '' -- 'target' -- '' diff --git a/wrap/main.go b/wrap/main.go index 33e340a..c110dae 100644 --- a/wrap/main.go +++ b/wrap/main.go @@ -1108,6 +1108,7 @@ func (w *Wrapper) MethodFromSig(sig,class string) *Method { fmt.Printf("Failed to parse method signature %s (%s)\n",sig,rem) os.Exit(-1) } + i := 0 // count MethodParameters for _,c := range n.Children { switch c.Kind { case "TypeName": @@ -1124,9 +1125,14 @@ func (w *Wrapper) MethodFromSig(sig,class string) *Method { tp := types.NewType(d,class) p.Type = tp case "Identifier": - p.Vname = d.Content + if i == 0 || p.Pname != "" { + p.Vname = d.Content + } else { + p.Pname = d.Content + } } } + i++ ret.Parameters = append(ret.Parameters,p) } }