Skip to content

Commit

Permalink
fix: swift output format support for class/struct 'where' info
Browse files Browse the repository at this point in the history
  • Loading branch information
blacktop committed Nov 7, 2023
1 parent 423525d commit 710d044
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 10 deletions.
17 changes: 15 additions & 2 deletions swift.go
Original file line number Diff line number Diff line change
Expand Up @@ -2527,8 +2527,21 @@ func (f *File) makeSymbolicMangledNameStringRef(addr uint64) (string, error) {
} else if strings.HasPrefix(part, "y") && strings.HasSuffix(part, "G") {
// part = fmt.Sprintf("<%s>", strings.TrimSuffix(strings.TrimPrefix(part, "y"), "G"))
part = strings.TrimSuffix(strings.TrimPrefix(part, "y"), "G")
} else if strings.HasSuffix(part, "G") && idx == len(parts)-1 {
part = strings.TrimSuffix(part, "G")
} else if idx == len(parts)-1 { // last part
if strings.HasSuffix(part, "G") {
part = strings.TrimSuffix(part, "G")
}
if part == "G" {
continue
}
if strings.HasPrefix(part, "_p") { // I believe this just means that it's a protocol
part = strings.TrimPrefix(part, "_p")
}
if (part == "Qz" || part == "Qy_" || part == "Qy0_") && len(out) == 2 {
tmp := out[0]
out[0] = out[1] + "." + tmp
out = out[:1]
}
}
}
if part == "" {
Expand Down
6 changes: 6 additions & 0 deletions types/swift/mangling.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ var MangledType = map[string]string{
"_pSg": "?",
"SgSg": "??",
"ypG": "Any",
"p": "Any",
"SSG": "String",
"SSGSg": "String?",
"SSSgG": "String?",
Expand All @@ -120,5 +121,10 @@ var MangledType = map[string]string{
"x": "A", // generic param, depth=0, idx=0
"q_": "B", // dependent generic parameter
"yxq_G": "<A, B>",
"xq_": "<A, B>",
"Sb": "Swift.Bool",
"Qz": "==",
"Qy_": "==",
"Qy0_": "==",
"SgXw": "?",
}
46 changes: 38 additions & 8 deletions types/swift/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -176,12 +176,27 @@ func (t Type) dump(verbose bool) string {
var size string
if t.Type.(Class).GenericContext != nil {
if len(t.Type.(Class).GenericContext.Requirements) > 0 {
var parts []string
var keyargs []string
var where []string
for _, req := range t.Type.(Class).GenericContext.Requirements {
parts = append(parts, fmt.Sprintf("%s: %s", req.Param, req.Kind))
if req.Flags.HasKeyArgument() {
keyargs = append(keyargs, fmt.Sprintf("%s: %s", req.Param, req.Kind))
} else {
switch req.Flags.Kind() {
case GRKindBaseClass:
keyargs = append(keyargs, fmt.Sprintf("%s: %s, B", req.Param, req.Kind))
case GRKindSameType:
where = append(where, fmt.Sprintf("%s %s", req.Param, req.Kind))
default:
fmt.Println(req.Flags.String())
}
}
}
if len(parts) > 0 {
ctx = fmt.Sprintf("<%s>", strings.Join(parts, ", "))
if len(keyargs) > 0 {
ctx = fmt.Sprintf("<%s>", strings.Join(keyargs, ", "))
}
if len(where) > 0 {
ctx += fmt.Sprintf("\n where %s", strings.Join(where, ", "))
}
}
if t.Type.(Class).GenericContext.GenericMetadataPattern != nil && t.Type.(Class).GenericContext.GenericMetadataPattern.ValueWitnessTable != nil {
Expand Down Expand Up @@ -248,12 +263,27 @@ func (t Type) dump(verbose bool) string {
var size string
if t.Type.(Struct).GenericContext != nil {
if len(t.Type.(Struct).GenericContext.Requirements) > 0 {
var parts []string
var keyargs []string
var where []string
for _, req := range t.Type.(Struct).GenericContext.Requirements {
parts = append(parts, fmt.Sprintf("%s: %s", req.Param, req.Kind))
if req.Flags.HasKeyArgument() {
keyargs = append(keyargs, fmt.Sprintf("%s: %s", req.Param, req.Kind))
} else {
switch req.Flags.Kind() {
case GRKindBaseClass:
keyargs = append(keyargs, fmt.Sprintf("%s: %s, B", req.Param, req.Kind))
case GRKindSameType:
where = append(where, fmt.Sprintf("%s %s", req.Param, req.Kind))
default:
fmt.Println(req.Flags.String())
}
}
}
if len(parts) > 0 {
ctx = fmt.Sprintf("<%s>", strings.Join(parts, ", "))
if len(keyargs) > 0 {
ctx = fmt.Sprintf("<%s>", strings.Join(keyargs, ", "))
}
if len(where) > 0 {
ctx += fmt.Sprintf("\n where %s", strings.Join(where, ", "))
}
}
if t.Type.(Struct).GenericContext.GenericMetadataPattern != nil && t.Type.(Struct).GenericContext.GenericMetadataPattern.ValueWitnessTable != nil {
Expand Down

0 comments on commit 710d044

Please sign in to comment.