diff --git a/.gitignore b/.gitignore index 2b45399..2d83890 100644 --- a/.gitignore +++ b/.gitignore @@ -5,7 +5,6 @@ examples/app/app examples/app/ns examples/bluetooth/bluetooth examples/bluetooth/ns -examples/bluetooth/old examples/foundation/foundation examples/foundation/ns examples/simple/simple diff --git a/ast/ast.go b/ast/ast.go index 9c032c1..1e92fb5 100644 --- a/ast/ast.go +++ b/ast/ast.go @@ -193,8 +193,6 @@ func Parse(fullline string) Node { return parseNotTailCalledAttr(line) case "ObjCCategoryDecl": return parseObjCCategoryDecl(line) - case "ObjCImplementation": - return parseObjCImplementation(line) case "ObjCInterface": return parseObjCInterface(line,false) case "super ObjCInterface": diff --git a/ast/ast_test.go b/ast/ast_test.go index b8ed479..6b5e07c 100644 --- a/ast/ast_test.go +++ b/ast/ast_test.go @@ -9,6 +9,10 @@ import ( "git.wow.st/gmp/nswrap/util" ) +func init() { + TrackPositions = true +} + func formatMultiLine(o interface{}) string { s := fmt.Sprintf("%#v", o) s = strings.Replace(s, "{", "{\n", -1) @@ -17,23 +21,26 @@ func formatMultiLine(o interface{}) string { return s } +func runNodeTest(t *testing.T, actual, expected Node, i int) { + testName := fmt.Sprintf("Example%d", i) + t.Run(testName, func(t *testing.T) { + if !reflect.DeepEqual(expected, actual) { + t.Errorf("%s", util.ShowDiff(formatMultiLine(expected), + formatMultiLine(actual))) + } + }) +} + func runNodeTests(t *testing.T, tests map[string]Node) { i := 1 for line, expected := range tests { - testName := fmt.Sprintf("Example%d", i) + // Append the name of the struct onto the front. This would + // make the complete line it would normally be parsing. + name := reflect.TypeOf(expected).Elem().Name() + actual := Parse(name + " " + line) + + runNodeTest(t,actual,expected,i) i++ - - t.Run(testName, func(t *testing.T) { - // Append the name of the struct onto the front. This would make the - // complete line it would normally be parsing. - name := reflect.TypeOf(expected).Elem().Name() - actual := Parse(name + " " + line) - - if !reflect.DeepEqual(expected, actual) { - t.Errorf("%s", util.ShowDiff(formatMultiLine(expected), - formatMultiLine(actual))) - } - }) } } diff --git a/ast/attributed_type_test.go b/ast/attributed_type_test.go new file mode 100644 index 0000000..94af40f --- /dev/null +++ b/ast/attributed_type_test.go @@ -0,0 +1,62 @@ +package ast + +import ( + "testing" +) + +func TestAttributedType(t *testing.T) { + nodes := map[string]Node{ + `0x10c0d6770 'CVDisplayLinkRef _Nonnull' sugar`: + &AttributedType{ + Addr: 0x10c0d6770, + Type: `CVDisplayLinkRef _Nonnull`, + Sugar: true, + ChildNodes: []Node{}, + }, + `0x10c0d68b0 'const CVTimeStamp * _Nonnull' sugar`: + &AttributedType{ + Addr: 0x10c0d68b0, + Type: `const CVTimeStamp * _Nonnull`, + Sugar: true, + ChildNodes: []Node{}, + }, + `0x10c0d6ab0 'CVOptionFlags * _Nonnull' sugar`: + &AttributedType{ + Addr: 0x10c0d6ab0, + Type: `CVOptionFlags * _Nonnull`, + Sugar: true, + ChildNodes: []Node{}, + }, + `0x10c0fc7d0 'CVPixelBufferRef _Nonnull' sugar`: + &AttributedType{ + Addr: 0x10c0fc7d0, + Type: `CVPixelBufferRef _Nonnull`, + Sugar: true, + ChildNodes: []Node{}, + }, + `0x7faa1906d680 'NSError * _Nullable' sugar`: + &AttributedType{ + Addr: 0x7faa1906d680, + Type: `NSError * _Nullable`, + Sugar: true, + ChildNodes: []Node{}, + }, + `0x7faa19085760 'id _Nullable' sugar`: + &AttributedType{ + Addr: 0x7faa19085760, + Type: `id _Nullable`, + Sugar: true, + ChildNodes: []Node{}, + }, + `0x7faa19085840 'NSError * _Null_unspecified' sugar`: + &AttributedType{ + Addr: 0x7faa19085840, + Type: `NSError * _Null_unspecified`, + Sugar: true, + ChildNodes: []Node{}, + }, + } + + + runNodeTests(t, nodes) +} diff --git a/ast/availability_attr_test.go b/ast/availability_attr_test.go index ab6dee6..a548c41 100644 --- a/ast/availability_attr_test.go +++ b/ast/availability_attr_test.go @@ -11,8 +11,8 @@ func TestAvailabilityAttr(t *testing.T) { Pos: NewPositionFromString("/usr/include/AvailabilityInternal.h:21697:88, col:124"), OS: "macos", Version: "10.10", - Unknown1: 0, - Unknown2: 0, + Unknown1: "0", + Unknown2: "0", IsUnavailable: false, Message1: "", Message2: "", @@ -24,8 +24,8 @@ func TestAvailabilityAttr(t *testing.T) { Pos: NewPositionFromString("/usr/include/Availability.h:215:81, col:115"), OS: "watchos", Version: "3.0", - Unknown1: 0, - Unknown2: 0, + Unknown1: "0", + Unknown2: "0", IsUnavailable: false, Message1: "", Message2: "", @@ -37,8 +37,8 @@ func TestAvailabilityAttr(t *testing.T) { Pos: NewPositionFromString("col:81, col:115"), OS: "tvos", Version: "10.0", - Unknown1: 0, - Unknown2: 0, + Unknown1: "0", + Unknown2: "0", IsUnavailable: false, Message1: "", Message2: "", @@ -50,8 +50,8 @@ func TestAvailabilityAttr(t *testing.T) { Pos: NewPositionFromString("col:81, col:115"), OS: "ios", Version: "10.0", - Unknown1: 0, - Unknown2: 0, + Unknown1: "0", + Unknown2: "0", IsUnavailable: false, Message1: "", Message2: "", @@ -63,8 +63,8 @@ func TestAvailabilityAttr(t *testing.T) { Pos: NewPositionFromString("/usr/include/sys/cdefs.h:275:50, col:99"), OS: "swift", Version: "0", - Unknown1: 0, - Unknown2: 0, + Unknown1: "0", + Unknown2: "0", IsUnavailable: true, Message1: "Use snprintf instead.", Message2: "", @@ -76,8 +76,8 @@ func TestAvailabilityAttr(t *testing.T) { Pos: NewPositionFromString("line:275:50, col:99"), OS: "swift", Version: "0", - Unknown1: 0, - Unknown2: 0, + Unknown1: "0", + Unknown2: "0", IsUnavailable: true, Message1: "Use mkstemp(3) instead.", Message2: "", @@ -89,8 +89,8 @@ func TestAvailabilityAttr(t *testing.T) { Pos: NewPositionFromString("/usr/include/AvailabilityInternal.h:14571:88, col:124"), OS: "macosx", Version: "10.10", - Unknown1: 0, - Unknown2: 0, + Unknown1: "0", + Unknown2: "0", IsUnavailable: false, Message1: "", Message2: "", @@ -102,8 +102,8 @@ func TestAvailabilityAttr(t *testing.T) { Pos: NewPositionFromString("/usr/include/gethostuuid.h:39:65, col:100"), OS: "macos", Version: "10.5", - Unknown1: 0, - Unknown2: 0, + Unknown1: "0", + Unknown2: "0", IsUnavailable: false, Message1: "", Message2: "", diff --git a/ast/binary_operator_test.go b/ast/binary_operator_test.go index f965650..bdbc24f 100644 --- a/ast/binary_operator_test.go +++ b/ast/binary_operator_test.go @@ -17,7 +17,7 @@ func TestBinaryOperator(t *testing.T) { Addr: 0x1ff95b8, Pos: NewPositionFromString("line:78:2, col:7"), Type: "T_ENUM", - Type2: "T_ENUM", + Type2: "", Operator: "=", ChildNodes: []Node{}, }, diff --git a/ast/block_pointer_type_test.go b/ast/block_pointer_type_test.go new file mode 100644 index 0000000..870825f --- /dev/null +++ b/ast/block_pointer_type_test.go @@ -0,0 +1,24 @@ +package ast + +import ( + "testing" +) + +func TestBlockPointerType(t *testing.T) { + nodes := map[string]Node{ + `0x7fa3b88bbb30 'void (^)(void)'`: + &BlockPointerType{ + Addr: 0x7fa3b88bbb30, + Type: `void (^)(void)`, + ChildNodes: []Node{}, + }, + `0x7fa3b88bbb30 'NSComparisonResult (^)(id _Nonnull, id _Nonnull)'`: + &BlockPointerType{ + Addr: 0x7fa3b88bbb30, + Type: `NSComparisonResult (^)(id _Nonnull, id _Nonnull)`, + ChildNodes: []Node{}, + }, + } + + runNodeTests(t, nodes) +} diff --git a/ast/c_style_cast_expr_test.go b/ast/c_style_cast_expr_test.go index 2745e90..2e5ec6f 100644 --- a/ast/c_style_cast_expr_test.go +++ b/ast/c_style_cast_expr_test.go @@ -17,7 +17,7 @@ func TestCStyleCastExpr(t *testing.T) { Addr: 0x2781518, Pos: NewPositionFromString("col:7, col:17"), Type: "T_ENUM", - Type2: "T_ENUM", + Type2: "", Kind: "IntegralCast", ChildNodes: []Node{}, }, diff --git a/ast/enum_constant_decl.go b/ast/enum_constant_decl.go index 8c2b2d4..74eede2 100644 --- a/ast/enum_constant_decl.go +++ b/ast/enum_constant_decl.go @@ -35,7 +35,7 @@ func parseEnumConstantDecl(line string) *EnumConstantDecl { return &EnumConstantDecl{ Addr: ParseAddress(groups["address"]), Pos: NewPositionFromString(groups["position"]), - //Position2: groups["position2"], + Position2: groups["position2"], Referenced: len(groups["referenced"]) > 0, Name: strings.TrimSpace(groups["name"]), Type: removeQuotes(groups["type"]), diff --git a/ast/enum_decl.go b/ast/enum_decl.go index 089db1a..adfdc94 100644 --- a/ast/enum_decl.go +++ b/ast/enum_decl.go @@ -34,7 +34,7 @@ func parseEnumDecl(line string) *EnumDecl { return &EnumDecl{ Addr: ParseAddress(groups["address"]), Pos: NewPositionFromString(groups["position"]), - //Position2: groups["position2"], + Position2: groups["position2"], Name: strings.TrimSpace(groups["name"]), Type: removeQuotes(groups["type"]), //Type2: type2, diff --git a/ast/objc_category_decl_test.go b/ast/objc_category_decl_test.go new file mode 100644 index 0000000..3d223e5 --- /dev/null +++ b/ast/objc_category_decl_test.go @@ -0,0 +1,20 @@ +package ast + +import ( + "testing" +) + +func TestObjCCategoryDecl(t *testing.T) { + nodes := map[string]Node{ + `0x7fdef0862430 col:16 NSObject`: + &ObjCCategoryDecl{ + Addr: 0x7fdef0862430, + Pos: NewPositionFromString("line:120:1, col:16"), + Position2: "", + Name: "NSObject", + ChildNodes: []Node{}, + }, + } + + runNodeTests(t, nodes) +} diff --git a/ast/objc_implementation.go b/ast/objc_implementation.go deleted file mode 100644 index b05d760..0000000 --- a/ast/objc_implementation.go +++ /dev/null @@ -1,44 +0,0 @@ -package ast - -// ObjCImplementation is an Objective-C implementation -type ObjCImplementation struct { - Addr Address - Name string - ChildNodes []Node -} - -func parseObjCImplementation(line string) *ObjCImplementation { - groups := groupsFromRegex( - "'(?P.*)'", - line, - ) - - return &ObjCImplementation{ - Addr: ParseAddress(groups["address"]), - Name: groups["name"], - ChildNodes: []Node{}, - } -} - -// AddChild adds a new child node. Child nodes can then be accessed with the -// Children attribute. -func (n *ObjCImplementation) AddChild(node Node) { - n.ChildNodes = append(n.ChildNodes, node) -} - -// Address returns the numeric address of the node. See the documentation for -// the Address type for more information. -func (n *ObjCImplementation) Address() Address { - return n.Addr -} - -// Children returns the child nodes. If this node does not have any children or -// this node does not support children it will always return an empty slice. -func (n *ObjCImplementation) Children() []Node { - return n.ChildNodes -} - -// Position returns the position in the original source code. -func (n *ObjCImplementation) Position() Position { - return Position{} -} diff --git a/ast/objc_interface_decl_test.go b/ast/objc_interface_decl_test.go new file mode 100644 index 0000000..cd4fe6f --- /dev/null +++ b/ast/objc_interface_decl_test.go @@ -0,0 +1,39 @@ +package ast + +import ( + "testing" +) + +func TestObjCInterfaceDecl(t *testing.T) { + nodes := map[string]Node{ + `0x7fdef0862430 col:16 NSObject`: + &ObjCInterfaceDecl{ + Addr: 0x7fdef0862430, + Pos: NewPositionFromString("line:120:1, col:16"), + Position2: "", + Name: "NSObject", + Implicit: false, + ChildNodes: []Node{}, + }, + `0x7fdef0862430 prev 0x7fca43341430 col:16 NSObject`: + &ObjCInterfaceDecl{ + Addr: 0x7fdef0862430, + Pos: NewPositionFromString("line:120:1, col:16"), + Position2: "", + Name: "NSObject", + Implicit: false, + ChildNodes: []Node{}, + }, + `0x7fdef0862430 <> implicit Protocol`: + &ObjCInterfaceDecl{ + Addr: 0x7fdef0862430, + Pos: Position{}, + Position2: "", + Name: "Protocol", + Implicit: true, + ChildNodes: []Node{}, + }, + } + + runNodeTests(t, nodes) +} diff --git a/ast/objc_interface_test.go b/ast/objc_interface_test.go new file mode 100644 index 0000000..d559427 --- /dev/null +++ b/ast/objc_interface_test.go @@ -0,0 +1,28 @@ +package ast + +import ( + "testing" +) + +func TestObjCInterface(t *testing.T) { + runNodeTest(t, + Parse(`ObjCInterface 0x7f84d10dc1d0 'NSObject'`), + &ObjCInterface{ + Addr: 0x7f84d10dc1d0, + Name: `NSObject`, + Super: false, + ChildNodes: []Node{}, + }, + 1, + ) + runNodeTest(t, + Parse(`super ObjCInterface 0x7f84d10dc1d0 'NSObject'`), + &ObjCInterface{ + Addr: 0x7f84d10dc1d0, + Name: `NSObject`, + Super: true, + ChildNodes: []Node{}, + }, + 2, + ) +} diff --git a/ast/objc_interface_type_test.go b/ast/objc_interface_type_test.go new file mode 100644 index 0000000..d25faf4 --- /dev/null +++ b/ast/objc_interface_type_test.go @@ -0,0 +1,18 @@ +package ast + +import ( + "testing" +) + +func TestObjCInterfaceType(t *testing.T) { + nodes := map[string]Node{ + `0x7fdef0862430 'NSObject'`: + &ObjCInterfaceType{ + Addr: 0x7fdef0862430, + Type: "NSObject", + ChildNodes: []Node{}, + }, + } + + runNodeTests(t, nodes) +} diff --git a/ast/objc_method.go b/ast/objc_method.go index 293b434..74d79ac 100644 --- a/ast/objc_method.go +++ b/ast/objc_method.go @@ -3,19 +3,19 @@ package ast // ObjCMethod is an Objective-C method type ObjCMethod struct { Addr Address - Type string + Name string ChildNodes []Node } func parseObjCMethod(line string) *ObjCMethod { groups := groupsFromRegex( - "'(?P.*)'", + "'(?P.*)'", line, ) return &ObjCMethod{ Addr: ParseAddress(groups["address"]), - Type: groups["type"], + Name: groups["name"], ChildNodes: []Node{}, } } diff --git a/ast/objc_method_decl_test.go b/ast/objc_method_decl_test.go new file mode 100644 index 0000000..51280d6 --- /dev/null +++ b/ast/objc_method_decl_test.go @@ -0,0 +1,90 @@ +package ast + +import ( + "testing" +) + +func TestObjCMethodDecl(t *testing.T) { + nodes := map[string]Node{ + `0x7f92a58a7570 col:1 - isEqual: 'BOOL':'signed char'`: + &ObjCMethodDecl{ + Addr: 0x7f92a58a7570, + Pos: NewPositionFromString("line:17:1, col:27"), + Position2: "", + Name: "isEqual", + Type: "BOOL", + Type2: "", + ClassMethod: false, + Parameters: []string{"isEqual"}, + Implicit: false, + ChildNodes: []Node{}, + }, + `0x7f92a58a7978 col:1 - self 'instancetype':'id'`: + &ObjCMethodDecl{ + Addr: 0x7f92a58a7978, + Pos: NewPositionFromString("/usr/include/objc/NSObject.h:22:1, col:21"), + Position2: "", + Name: "self", + Type: "instancetype", + Type2: "", + ClassMethod: false, + Parameters: []string{}, + Implicit: false, + ChildNodes: []Node{}, + }, + `0x7f92a58a82b0 col:1 - respondsToSelector: 'BOOL':'signed char'`: + &ObjCMethodDecl{ + Addr: 0x7f92a58a82b0, + Pos: NewPositionFromString("line:34:1, col:42"), + Position2: "", + Name: "respondsToSelector", + Type: "BOOL", + Type2: "", + ClassMethod: false, + Parameters: []string{"respondsToSelector"}, + Implicit: false, + ChildNodes: []Node{}, + }, + `0x7f92a58a82b0 col:1 + instancesRespondToSelector: 'BOOL':'signed char'`: + &ObjCMethodDecl{ + Addr: 0x7f92a58a82b0, + Pos: NewPositionFromString("line:34:1, col:42"), + Position2: "", + Name: "instancesRespondToSelector", + Type: "BOOL", + Type2: "", + ClassMethod: true, + Parameters: []string{"instancesRespondToSelector"}, + Implicit: false, + ChildNodes: []Node{}, + }, + `0x7f92a58a7cd8 col:1 - performSelector:withObject:withObject: 'id':'id'`: + &ObjCMethodDecl{ + Addr: 0x7f92a58a7cd8, + Pos: NewPositionFromString("line:26:1, col:83"), + Position2: "", + Name: "performSelector", + Type: "id", + Type2: "", + ClassMethod: false, + Parameters: []string{"performSelector","withObject","withObject"}, + Implicit: false, + ChildNodes: []Node{}, + }, + `0x7f92a4459318 col:71 implicit - writableTypeIdentifiersForItemProvider 'NSArray * _Nonnull':'NSArray *'`: + &ObjCMethodDecl{ + Addr: 0x7f92a4459318, + Pos: NewPositionFromString("line:41:71"), + Position2: "", + Name: "writableTypeIdentifiersForItemProvider", + Type: `NSArray * _Nonnull`, + Type2: "", + ClassMethod: false, + Parameters: []string{}, + Implicit: true, + ChildNodes: []Node{}, + }, + } + + runNodeTests(t, nodes) +} diff --git a/ast/objc_method_test.go b/ast/objc_method_test.go new file mode 100644 index 0000000..25186f7 --- /dev/null +++ b/ast/objc_method_test.go @@ -0,0 +1,26 @@ +package ast + +import ( + "testing" +) + +func TestObjCMethod(t *testing.T) { + runNodeTest(t, + Parse(`ObjCMethod 0x7f84d10dc1d0 'isValid'`), + &ObjCMethod{ + Addr: 0x7f84d10dc1d0, + Name: `isValid`, + ChildNodes: []Node{}, + }, + 1, + ) + runNodeTest(t, + Parse(`getter ObjCMethod 0x7f84d10dc1d0 'isValid'`), + &ObjCMethod{ + Addr: 0x7f84d10dc1d0, + Name: `isValid`, + ChildNodes: []Node{}, + }, + 2, + ) +} diff --git a/ast/objc_object_pointer_type_test.go b/ast/objc_object_pointer_type_test.go new file mode 100644 index 0000000..4cbf3f5 --- /dev/null +++ b/ast/objc_object_pointer_type_test.go @@ -0,0 +1,30 @@ +package ast + +import ( + "testing" +) + +func TestObjCObjectPointerType(t *testing.T) { + nodes := map[string]Node{ + `0x10c101ab0 'NSObject *'`: + &ObjCObjectPointerType{ + Addr: 0x10c101ab0, + Type: `NSObject *`, + ChildNodes: []Node{}, + }, + `0x7faa18805fc0 'id'`: + &ObjCObjectPointerType{ + Addr: 0x7faa18805fc0, + Type: `id`, + ChildNodes: []Node{}, + }, + `0x7fca45a08a60 'NSAppleEventDescriptor *'`: + &ObjCObjectPointerType{ + Addr: 0x7fca45a08a60, + Type: `NSAppleEventDescriptor *`, + ChildNodes: []Node{}, + }, + } + + runNodeTests(t, nodes) +} diff --git a/ast/objc_object_type_test.go b/ast/objc_object_type_test.go new file mode 100644 index 0000000..689a712 --- /dev/null +++ b/ast/objc_object_type_test.go @@ -0,0 +1,24 @@ +package ast + +import ( + "testing" +) + +func TestObjCObjectType(t *testing.T) { + nodes := map[string]Node{ + `0x10c101ab0 'NSObject'`: + &ObjCObjectType{ + Addr: 0x10c101ab0, + Type: `NSObject`, + ChildNodes: []Node{}, + }, + `0x7faa18805fc0 'id'`: + &ObjCObjectType{ + Addr: 0x7faa18805fc0, + Type: `id`, + ChildNodes: []Node{}, + }, + } + + runNodeTests(t, nodes) +} diff --git a/ast/objc_property_decl_test.go b/ast/objc_property_decl_test.go new file mode 100644 index 0000000..29bd183 --- /dev/null +++ b/ast/objc_property_decl_test.go @@ -0,0 +1,34 @@ +package ast + +import ( + "testing" +) + +func TestObjCPropertyDecl(t *testing.T) { + nodes := map[string]Node{ + `0x10a9be000 col:46 blueColor 'NSColor * _Nonnull':'NSColor *' readonly atomic strong class`: + &ObjCPropertyDecl{ + Addr: 0x10a9be000, + Pos: NewPositionFromString("line:157:1, col:46"), + Position2: "col:46", + Name: "blueColor", + Type: `NSColor * _Nonnull`, + Type2: "", + Attr: "readonly atomic strong class", + ChildNodes: []Node{}, + }, + `0x7fca44e4a180 col:61 undoRegistrationEnabled 'BOOL':'signed char' readonly atomic getter`: + &ObjCPropertyDecl{ + Addr: 0x7fca44e4a180, + Pos: NewPositionFromString("line:50:1, col:61"), + Position2: "col:61", + Name: "undoRegistrationEnabled", + Type: "BOOL", + Type2: "", + Attr: "readonly atomic getter", + ChildNodes: []Node{}, + }, + } + + runNodeTests(t, nodes) +} diff --git a/ast/objc_protocol.go b/ast/objc_protocol.go index 941df85..05119e5 100644 --- a/ast/objc_protocol.go +++ b/ast/objc_protocol.go @@ -4,7 +4,6 @@ package ast type ObjCProtocol struct { Addr Address Name string - Content string ChildNodes []Node } @@ -17,7 +16,6 @@ func parseObjCProtocol(line string) *ObjCProtocol { return &ObjCProtocol{ Addr: ParseAddress(groups["address"]), Name: groups["name"], - Content: groups["content"], ChildNodes: []Node{}, } } diff --git a/ast/objc_protocol_decl_test.go b/ast/objc_protocol_decl_test.go new file mode 100644 index 0000000..2ed0f37 --- /dev/null +++ b/ast/objc_protocol_decl_test.go @@ -0,0 +1,28 @@ +package ast + +import ( + "testing" +) + +func TestObjCProtocolDecl(t *testing.T) { + nodes := map[string]Node{ + `0x10a9da630 col:11 NSBrowserDelegate`: + &ObjCProtocolDecl{ + Addr: 0x10a9da630, + Pos: NewPositionFromString("line:22:1, col:11"), + Position2: "", + Name: "NSBrowserDelegate", + ChildNodes: []Node{}, + }, + `0x10c37fc70 line:58:11 NSPrintPanelAccessorizing`: + &ObjCProtocolDecl{ + Addr: 0x10c37fc70, + Pos: NewPositionFromString("/System/Library/Frameworks/AppKit.framework/Headers/NSPrintPanel.h:58:1, line:70:2"), + Position2: "", + Name: "NSPrintPanelAccessorizing", + ChildNodes: []Node{}, + }, + } + + runNodeTests(t, nodes) +} diff --git a/ast/objc_protocol_test.go b/ast/objc_protocol_test.go new file mode 100644 index 0000000..e6dca29 --- /dev/null +++ b/ast/objc_protocol_test.go @@ -0,0 +1,18 @@ +package ast + +import ( + "testing" +) + +func TestObjCProtocol(t *testing.T) { + nodes := map[string]Node{ + `0x10c26d630 'NSColorPickingDefault'`: + &ObjCProtocol{ + Addr: 0x10c26d630, + Name: "NSColorPickingDefault", + ChildNodes: []Node{}, + }, + } + + runNodeTests(t, nodes) +} diff --git a/ast/objc_type_param_decl_test.go b/ast/objc_type_param_decl_test.go new file mode 100644 index 0000000..bff7c72 --- /dev/null +++ b/ast/objc_type_param_decl_test.go @@ -0,0 +1,77 @@ +package ast + +import ( + "testing" +) + +func TestObjCTypeParamDecl(t *testing.T) { + nodes := map[string]Node{ + `0x10c2d1a78 col:27 AnchorType 'id':'id'`: + &ObjCTypeParamDecl{ + Addr: 0x10c2d1a78, + Pos: NewPositionFromString("col:27"), + Position2: "", + Name: "AnchorType", + Type: "id", + Type2: "", + IsReferenced: false, + IsCovariant: false, + IsBounded: false, + ChildNodes: []Node{}, + }, + `0x7faa181df328 col:16 ObjectType covariant 'id':'id'`: + &ObjCTypeParamDecl{ + Addr: 0x7faa181df328, + Pos: NewPositionFromString("col:16"), + Position2: "", + Name: "ObjectType", + Type: "id", + Type2: "", + IsReferenced: false, + IsCovariant: true, + IsBounded: false, + ChildNodes: []Node{}, + }, + `0x7faa18216cf0 col:26 referenced UnitType bounded 'NSUnit *'`: + &ObjCTypeParamDecl{ + Addr: 0x7faa18216cf0, + Pos: NewPositionFromString("col:26, col:43"), + Position2: "", + Name: "UnitType", + Type: "NSUnit *", + Type2: "", + IsReferenced: true, + IsCovariant: false, + IsBounded: true, + ChildNodes: []Node{}, + }, + `0x7faa18ba2ba8 col:25 referenced K covariant 'id':'id'`: + &ObjCTypeParamDecl{ + Addr: 0x7faa18ba2ba8, + Pos: NewPositionFromString("col:25"), + Position2: "", + Name: "K", + Type: "id", + Type2: "", + IsReferenced: true, + IsCovariant: true, + IsBounded: false, + ChildNodes: []Node{}, + }, + `0x7faa18ba2c18 col:28 V covariant 'id':'id'`: + &ObjCTypeParamDecl{ + Addr: 0x7faa18ba2c18, + Pos: NewPositionFromString("col:28"), + Position2: "", + Name: "V", + Type: "id", + Type2: "", + IsReferenced: false, + IsCovariant: true, + IsBounded: false, + ChildNodes: []Node{}, + }, + } + + runNodeTests(t, nodes) +} diff --git a/ast/parm_var_decl.go b/ast/parm_var_decl.go index bd42b2d..fac1a7b 100644 --- a/ast/parm_var_decl.go +++ b/ast/parm_var_decl.go @@ -37,15 +37,15 @@ func parseParmVarDecl(line string) *ParmVarDecl { type2 = type2[2 : len(type2)-1] }*/ - /*if strings.Index(groups["position"], "") > -1 { + if strings.Index(groups["position"], "") > -1 { groups["position"] = "" groups["position2"] = "" - }*/ + } return &ParmVarDecl{ Addr: ParseAddress(groups["address"]), Pos: NewPositionFromString(groups["position"]), - //Position2: strings.TrimSpace(groups["position2"]), + Position2: strings.TrimSpace(groups["position2"]), Name: strings.TrimSpace(groups["name"]), Type: groups["type"], //Type2: type2, diff --git a/ast/parm_var_decl_test.go b/ast/parm_var_decl_test.go index d2a71c1..9994866 100644 --- a/ast/parm_var_decl_test.go +++ b/ast/parm_var_decl_test.go @@ -59,7 +59,7 @@ func TestParmVarDecl(t *testing.T) { Position2: "col:47", Type: "size_t", Name: "__size", - Type2: "unsigned long", + Type2: "", IsUsed: false, IsReferenced: false, IsRegister: false, @@ -71,7 +71,7 @@ func TestParmVarDecl(t *testing.T) { Position2: "col:34", Type: "int (* _Nullable)(void *, char *, int)", Name: "", - Type2: "int (*)(void *, char *, int)", + Type2: "", IsUsed: false, IsReferenced: false, IsRegister: false, @@ -95,7 +95,7 @@ func TestParmVarDecl(t *testing.T) { Position2: "col:16", Type: "char *", Name: "foo", - Type2: "char *", + Type2: "", IsUsed: false, IsReferenced: true, IsRegister: false, diff --git a/ast/unavailable_attr_test.go b/ast/unavailable_attr_test.go new file mode 100644 index 0000000..77e31e6 --- /dev/null +++ b/ast/unavailable_attr_test.go @@ -0,0 +1,28 @@ +package ast + +import ( + "testing" +) + +func TestUnavailableAttr(t *testing.T) { + nodes := map[string]Node{ + `0x7faa18a445d8 "" IR_None`: + &UnavailableAttr{ + Addr: 0x7faa18a445d8, + Pos: NewPositionFromString("line:66:45"), + Position2: "", + Content: `"" IR_None`, + ChildNodes: []Node{}, + }, + `0x7faa18a289f8 "use a (__bridge id) cast instead" IR_None`: + &UnavailableAttr{ + Addr: 0x7faa18a289f8, + Pos: NewPositionFromString("line:150:54, col:70"), + Position2: "", + Content: `"use a (__bridge id) cast instead" IR_None`, + ChildNodes: []Node{}, + }, + } + + runNodeTests(t, nodes) +} diff --git a/ast/unknown_test.go b/ast/unknown_test.go new file mode 100644 index 0000000..c3b8619 --- /dev/null +++ b/ast/unknown_test.go @@ -0,0 +1,21 @@ +package ast + +import ( + "testing" +) + +func TestUnknown(t *testing.T) { + nodes := map[string]Node{ + `0x7faa18a445d8 "asdf" aoeu`: + &Unknown{ + Addr: 0x7faa18a445d8, + Name: "Unknown", + Pos: NewPositionFromString("line:66:45"), + Position2: "", + Content: ` "asdf" aoeu`, + ChildNodes: []Node{}, + }, + } + + runNodeTests(t, nodes) +} diff --git a/ast/variadic_test.go b/ast/variadic_test.go new file mode 100644 index 0000000..35cd7b7 --- /dev/null +++ b/ast/variadic_test.go @@ -0,0 +1,15 @@ +package ast + +import ( + "testing" +) + +func TestVariadic(t *testing.T) { + runNodeTest(t, + Parse(`...`), + &Variadic{ + ChildNodes: []Node{}, + }, + 1, + ) +} diff --git a/ast/vector_type_test.go b/ast/vector_type_test.go new file mode 100644 index 0000000..93e694d --- /dev/null +++ b/ast/vector_type_test.go @@ -0,0 +1,26 @@ +package ast + +import ( + "testing" +) + +func TestVectorType(t *testing.T) { + nodes := map[string]Node{ + `0x7faa18f2d520 '__attribute__((__vector_size__(1 * sizeof(long long)))) long long' 1`: + &VectorType{ + Addr: 0x7faa18f2d520, + Type: `__attribute__((__vector_size__(1 * sizeof(long long)))) long long`, + Length: 1, + ChildNodes: []Node{}, + }, + `0x7fca42b88f30 '__attribute__((__vector_size__(16 * sizeof(signed char)))) signed char' 16`: + &VectorType{ + Addr: 0x7fca42b88f30, + Type: `__attribute__((__vector_size__(16 * sizeof(signed char)))) signed char`, + Length: 16, + ChildNodes: []Node{}, + }, + } + + runNodeTests(t, nodes) +} diff --git a/examples/bluetooth/main.go b/examples/bluetooth/main.go index f774fcd..9bee4ee 100644 --- a/examples/bluetooth/main.go +++ b/examples/bluetooth/main.go @@ -120,6 +120,7 @@ func main() { hrm_uuid = ns.CBUUIDWithGoString("180D") hrv_uuid = ns.CBUUIDWithGoString("2A37") + //We defined our own queue because this won't work on the main queue. cm = ns.CBCentralManagerAlloc().InitWithDelegateQueue(cd,queue) select { }