Bug fix in Objective-C method signature parsing.

This commit is contained in:
Greg 2019-06-04 13:01:51 -04:00
parent 773886e0f1
commit f93a893060
4 changed files with 22 additions and 15 deletions

View File

@ -8,7 +8,7 @@ subclasses:
ClassTwo: ClassTwo:
- geti1 - geti1
- -(void)myMethod1:(int)a - -(void)myMethod1:(int)a
- +(const NSObject* _Nonnull)myMethod2:(int)a:(NSDictionary<NSString*,NSObject*> *)options - +(const NSObject* _Nonnull)myMethod2:(int)a options:(NSDictionary<NSString*,NSObject*> *)opt
imports: [ simple.h ] imports: [ simple.h ]
frameworks: [ Foundation ] frameworks: [ Foundation ]

View File

@ -35,24 +35,24 @@ func init() {
func MethodSignature(s string, n *Node) (string, *Node) { func MethodSignature(s string, n *Node) (string, *Node) {
return ChildOf(NewNode("MethodSignature"),Seq( return ChildOf(NewNode("MethodSignature"),Seq(
Parenthesized(TypeName), Parenthesized(TypeName),
MethodName, Identifier,
Opt(MethodParameterList), Opt(MethodParameterList),
))(s,n) ))(s,n)
} }
func MethodName(s string, n *Node) (string, *Node) { func MethodParameterList(s string, n *Node) (string, *Node) {
return Seq( return Seq(
Identifier, FirstMethodParameter,
Opt(Seq( ZeroOrMore(MethodParameter),
Lit(":"),
Parenthesized(TypeName),
Identifier,
)),
)(s,n) )(s,n)
} }
func MethodParameterList(s string, n *Node) (string, *Node) { func FirstMethodParameter(s string, n *Node) (string, *Node) {
return OneOrMore(MethodParameter)(s,n) return ChildOf(NewNode("MethodParameter"),Seq(
Lit(":"),
Parenthesized(TypeName),
Identifier,
))(s,n)
} }
func MethodParameter(s string, n *Node) (string, *Node) { func MethodParameter(s string, n *Node) (string, *Node) {

View File

@ -396,9 +396,10 @@ func TestParse(t *testing.T) {
-<TypeName> '' -<TypeName> ''
--<TypeSpecifier> 'void' --<TypeSpecifier> 'void'
-<Identifier> 'performSelector' -<Identifier> 'performSelector'
-<TypeName> '' -<MethodParameter> ''
--<TypedefName> 'SEL' --<TypeName> ''
-<Identifier> 'aSelector' ---<TypedefName> 'SEL'
--<Identifier> 'aSelector'
-<MethodParameter> '' -<MethodParameter> ''
--<Identifier> 'target' --<Identifier> 'target'
--<TypeName> '' --<TypeName> ''

View File

@ -1108,6 +1108,7 @@ func (w *Wrapper) MethodFromSig(sig,class string) *Method {
fmt.Printf("Failed to parse method signature %s (%s)\n",sig,rem) fmt.Printf("Failed to parse method signature %s (%s)\n",sig,rem)
os.Exit(-1) os.Exit(-1)
} }
i := 0 // count MethodParameters
for _,c := range n.Children { for _,c := range n.Children {
switch c.Kind { switch c.Kind {
case "TypeName": case "TypeName":
@ -1124,9 +1125,14 @@ func (w *Wrapper) MethodFromSig(sig,class string) *Method {
tp := types.NewType(d,class) tp := types.NewType(d,class)
p.Type = tp p.Type = tp
case "Identifier": case "Identifier":
if i == 0 || p.Pname != "" {
p.Vname = d.Content p.Vname = d.Content
} else {
p.Pname = d.Content
} }
} }
}
i++
ret.Parameters = append(ret.Parameters,p) ret.Parameters = append(ret.Parameters,p)
} }
} }