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:
- geti1
- -(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 ]
frameworks: [ Foundation ]

View File

@ -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) {

View File

@ -396,9 +396,10 @@ func TestParse(t *testing.T) {
-<TypeName> ''
--<TypeSpecifier> 'void'
-<Identifier> 'performSelector'
-<TypeName> ''
--<TypedefName> 'SEL'
-<Identifier> 'aSelector'
-<MethodParameter> ''
--<TypeName> ''
---<TypedefName> 'SEL'
--<Identifier> 'aSelector'
-<MethodParameter> ''
--<Identifier> 'target'
--<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)
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":
if i == 0 || p.Pname != "" {
p.Vname = d.Content
} else {
p.Pname = d.Content
}
}
}
i++
ret.Parameters = append(ret.Parameters,p)
}
}