Skip to content

Commit

Permalink
fix: struct fields with specifiers (#58)
Browse files Browse the repository at this point in the history
  • Loading branch information
t0rr3sp3dr0 committed Jun 2, 2024
1 parent 14c2bf4 commit 7c278cb
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 8 deletions.
32 changes: 26 additions & 6 deletions types/objc/type_encoding.go
Original file line number Diff line number Diff line change
Expand Up @@ -492,17 +492,27 @@ func skipFirstType(typStr string) string {
typ := []byte(typStr)
for {
switch typ[i] {
case '+': /* gnu register */
fallthrough
case 'A': /* _Atomic */
fallthrough
case 'N': /* inout */
fallthrough
case 'O': /* bycopy */
fallthrough
case 'R': /* byref */
fallthrough
case 'V': /* oneway */
fallthrough
case 'j': /* _Complex */
fallthrough
case 'n': /* in */
fallthrough
case 'o': /* out */
fallthrough
case 'N': /* inout */
fallthrough
case 'r': /* const */
fallthrough
case 'V': /* oneway */
case '|': /* gc invisible */
fallthrough
case '^': /* pointers */
i++
Expand Down Expand Up @@ -573,17 +583,27 @@ func CutType(typStr string) (string, string, bool) {
typ := []byte(typStr)
for {
switch typ[i] {
case '+': /* gnu register */
fallthrough
case 'A': /* _Atomic */
fallthrough
case 'N': /* inout */
fallthrough
case 'O': /* bycopy */
fallthrough
case 'R': /* byref */
fallthrough
case 'V': /* oneway */
fallthrough
case 'j': /* _Complex */
fallthrough
case 'n': /* in */
fallthrough
case 'o': /* out */
fallthrough
case 'N': /* inout */
fallthrough
case 'r': /* const */
fallthrough
case 'V': /* oneway */
case '|': /* gc invisible */
fallthrough
case '^': /* pointers */
i++
Expand Down
11 changes: 9 additions & 2 deletions types/objc/type_encoding_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ func Test_decodeType(t *testing.T) {
{
name: "Test all",
args: args{
encType: "^{OutterStruct=(InnerUnion=q{InnerStruct=ii})b1b2b10b1q[2^v]^![4,8c]}",
encType: "^{OutterStruct=(InnerUnion=q{InnerStruct=ii})b1b2b10b1q[2^v]^![4,8c]AQ}",
},
want: "struct OutterStruct { union InnerUnion { long long x0; struct InnerStruct { int x0; int x1; } x1; } x0; unsigned int x1:1; unsigned int x2:2; unsigned int x3:10; unsigned int x4:1; long long x5; void *x6[2]; signed char *x7 __attribute__((aligned(8), vector_size(4))); } *",
want: "struct OutterStruct { union InnerUnion { long long x0; struct InnerStruct { int x0; int x1; } x1; } x0; unsigned int x1:1; unsigned int x2:2; unsigned int x3:10; unsigned int x4:1; long long x5; void *x6[2]; signed char *x7 __attribute__((aligned(8), vector_size(4))); _Atomic unsigned long long x8; } *",
},
{
name: "Test array",
Expand Down Expand Up @@ -67,6 +67,13 @@ func Test_decodeType(t *testing.T) {
},
want: "void * /* struct */",
},
{
name: "Test struct 4",
args: args{
encType: "{__CFRuntimeBase=QAQ}",
},
want: "struct __CFRuntimeBase { unsigned long long x0; _Atomic unsigned long long x1; }",
},
{
name: "Test union 0",
args: args{
Expand Down

0 comments on commit 7c278cb

Please sign in to comment.