diff --git a/csym/c/type.go b/csym/c/type.go index 1c1045c..2c92551 100644 --- a/csym/c/type.go +++ b/csym/c/type.go @@ -344,6 +344,9 @@ func fakeUnionString(t *UnionType) string { // IsFakeTag reports whether the tag name is fake (generated by the compiler for // symbols lacking a tag name). func IsFakeTag(tag string) bool { + if i := strings.LastIndex(tag, "_duplicate_"); i > 0 { + tag = tag[:i] + } if strings.HasPrefix(tag, "_") && strings.HasSuffix(tag, "fake") { s := tag[len("_") : len(tag)-len("fake")] _, err := strconv.Atoi(s) diff --git a/csym/parse_fixups.go b/csym/parse_fixups.go index 68a5b25..8c27fcc 100644 --- a/csym/parse_fixups.go +++ b/csym/parse_fixups.go @@ -287,8 +287,8 @@ func UniqueName(name string, addr uint32) string { } // UniqueTag returns a unique tag based on the given tag and duplicate index. -func UniqueTag(tag string, idx int) string { - return fmt.Sprintf("%s_duplicate_%d", tag, idx) +func UniqueTag(tag string, typ string, idx int) string { + return fmt.Sprintf("%s_duplicate_%s%d", tag, typ, idx) } // UniqueVarName returns a unique variable name based on the given variable @@ -316,7 +316,7 @@ func UniqueStructTag(structTags map[string][]*c.StructType, t *c.StructType) str if !ok { break } // the tag is unique - done k := SliceIndex(len(structs), func(i int) bool { return structs[i] == t }) if k < 0 { k = len(structs) } - newTag = UniqueTag(newTag, k) + newTag = UniqueTag(newTag, "s", k) } return newTag } @@ -330,7 +330,7 @@ func UniqueUnionTag(unionTags map[string][]*c.UnionType, t *c.UnionType) string if !ok { break } // the tag is unique - done k := SliceIndex(len(unions), func(i int) bool { return unions[i] == t }) if k < 0 { k = len(unions) } - newTag = UniqueTag(newTag, k) + newTag = UniqueTag(newTag, "u", k) } return newTag } @@ -344,7 +344,7 @@ func UniqueEnumTag(EnumTags map[string][]*c.EnumType, t *c.EnumType) string { if !ok { break } // the tag is unique - done k := SliceIndex(len(enums), func(i int) bool { return enums[i] == t }) if k < 0 { k = len(enums) } - newTag = UniqueTag(newTag, k) + newTag = UniqueTag(newTag, "e", k) } return newTag } diff --git a/csym/parse_types.go b/csym/parse_types.go index ab04baa..36be948 100644 --- a/csym/parse_types.go +++ b/csym/parse_types.go @@ -235,20 +235,6 @@ func (p *Parser) parseTypedef(t sym.Type, dims []uint32, tag, name string) { // ### [ Helper functions ] #################################################### -// Duplicate tag format string. -const duplicateTagFormat = "%s_duplicate_%d" - -// uniqueTag returns a unique tag based on the given tag and set of present -// tags. -func uniqueTag(tag string, tags map[string]bool) string { - newTag := tag - for i := 0; tags[newTag]; i++ { - newTag = fmt.Sprintf(duplicateTagFormat, tag, i) - } - tags[newTag] = true - return newTag -} - // Duplicate enum member format string. const duplicateEnumFormat = "%s_DUPLICATE_%d"