Skip to content

Commit 6d44f57

Browse files
owen-mcmbg
authored andcommitted
Factor out extractTypeObject
1 parent 6a42fa8 commit 6d44f57

File tree

1 file changed

+15
-18
lines changed

1 file changed

+15
-18
lines changed

go/extractor/extractor.go

Lines changed: 15 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1607,15 +1607,7 @@ func extractType(tw *trap.Writer, tp types.Type) trap.Label {
16071607
extractUnderlyingType(tw, lbl, underlying)
16081608
trackInstantiatedStructFields(tw, tp, origintp)
16091609

1610-
entitylbl, exists := tw.Labeler.LookupObjectID(origintp.Obj(), lbl)
1611-
if entitylbl == trap.InvalidLabel {
1612-
log.Printf("Omitting type-object binding for unknown object %v.\n", origintp.Obj())
1613-
} else {
1614-
if !exists {
1615-
extractObject(tw, origintp.Obj(), entitylbl)
1616-
}
1617-
dbscheme.TypeObjectTable.Emit(tw, lbl, entitylbl)
1618-
}
1610+
extractTypeObject(tw, lbl, origintp.Obj())
16191611

16201612
// ensure all methods have labels - note that methods do not have a
16211613
// parent scope, so they are not dealt with by `extractScopes`
@@ -1652,15 +1644,7 @@ func extractType(tw *trap.Writer, tp types.Type) trap.Label {
16521644
dbscheme.TypeNameTable.Emit(tw, lbl, tp.Obj().Name())
16531645
dbscheme.AliasRhsTable.Emit(tw, lbl, extractType(tw, tp.Rhs()))
16541646

1655-
entitylbl, exists := tw.Labeler.LookupObjectID(tp.Obj(), lbl)
1656-
if entitylbl == trap.InvalidLabel {
1657-
log.Printf("Omitting type-object binding for unknown object %v.\n", tp.Obj())
1658-
} else {
1659-
if !exists {
1660-
extractObject(tw, tp.Obj(), entitylbl)
1661-
}
1662-
dbscheme.TypeObjectTable.Emit(tw, lbl, entitylbl)
1663-
}
1647+
extractTypeObject(tw, lbl, tp.Obj())
16641648
default:
16651649
log.Fatalf("unexpected type %T", tp)
16661650
}
@@ -1820,6 +1804,19 @@ func getTypeLabel(tw *trap.Writer, tp types.Type) (trap.Label, bool) {
18201804
return lbl, exists
18211805
}
18221806

1807+
// extractTypeObject extracts a single type object and emits it to the type object table.
1808+
func extractTypeObject(tw *trap.Writer, lbl trap.Label, entity *types.TypeName) {
1809+
entitylbl, exists := tw.Labeler.LookupObjectID(entity, lbl)
1810+
if entitylbl == trap.InvalidLabel {
1811+
log.Printf("Omitting type-object binding for unknown object %v.\n", entity)
1812+
} else {
1813+
if !exists {
1814+
extractObject(tw, entity, entitylbl)
1815+
}
1816+
dbscheme.TypeObjectTable.Emit(tw, lbl, entitylbl)
1817+
}
1818+
}
1819+
18231820
// extractKeyType extracts `key` as the key type of the map type `mp`
18241821
func extractKeyType(tw *trap.Writer, mp trap.Label, key types.Type) {
18251822
dbscheme.KeyTypeTable.Emit(tw, mp, extractType(tw, key))

0 commit comments

Comments
 (0)