Index: mojom/mojom_tool/mojom/user_defined_types.go |
diff --git a/mojom/mojom_tool/mojom/user_defined_types.go b/mojom/mojom_tool/mojom/user_defined_types.go |
index 92ae24fa7eeb0b872bb9833f906aa8314e693450..0234bfeb76366d3fa472e433dbf79ddfa34ecf3f 100644 |
--- a/mojom/mojom_tool/mojom/user_defined_types.go |
+++ b/mojom/mojom_tool/mojom/user_defined_types.go |
@@ -76,11 +76,6 @@ type UserDefinedType interface { |
TypeKey() string |
IsAssignmentCompatibleWith(value LiteralValue) bool |
- // FindReachableTypes returns the list of type keys of all UserDefinedTypes that are |
- // reachable from this UserDefinedType. This method must only be invoked |
- // after type resolution has succeeded. |
- FindReachableTypes() []string |
- |
// ComputeFinalData() is invoked on each user-defined type in a MojomDescriptor |
// after the resolution and type validation phases have completed successfully. |
// The method computes information that is useful for the code generators in the |
@@ -105,115 +100,6 @@ type UserDefinedTypeBase struct { |
typeKey string |
} |
-// UserDefinedTypeSet is a set of UserDefinedTypes |
-type UserDefinedTypeSet map[UserDefinedType]bool |
- |
-func MakeUserDefinedTypeSet() UserDefinedTypeSet { |
- return make(map[UserDefinedType]bool) |
-} |
- |
-func (s *UserDefinedTypeSet) Add(t UserDefinedType) { |
- (*s)[t] = true |
-} |
- |
-func (s *UserDefinedTypeSet) AddAll(s2 UserDefinedTypeSet) { |
- for t, _ := range s2 { |
- (*s)[t] = true |
- } |
-} |
- |
-func (s *UserDefinedTypeSet) Contains(t UserDefinedType) bool { |
- _, ok := (*s)[t] |
- return ok |
-} |
- |
-// Compare is used in tests. It returns |
-// a non-nil error in case expected is not equal to actual. |
-func (expected *UserDefinedTypeSet) Compare(actual *UserDefinedTypeSet) error { |
- for n, _ := range *expected { |
- if n == nil { |
- panic("expected contains a nil.") |
- } |
- if !actual.Contains(n) { |
- return fmt.Errorf("%s is in expected but not actual", n.TypeKey()) |
- } |
- } |
- for n, _ := range *actual { |
- if n == nil { |
- panic("actual contains a nil.") |
- } |
- if !expected.Contains(n) { |
- return fmt.Errorf("%s is in actual but not expected", n.TypeKey()) |
- } |
- } |
- return nil |
-} |
- |
-// See UserDefinedType interface. |
-func (b *UserDefinedTypeBase) FindReachableTypes() []string { |
- reachableSet := MakeUserDefinedTypeSet() |
- findReachableTypes(b.thisType, reachableSet) |
- typeKeys := make([]string, len(reachableSet)) |
- i := 0 |
- for t, _ := range reachableSet { |
- typeKeys[i] = t.TypeKey() |
- if typeKeys[i] == "" { |
- panic(fmt.Sprintf("Empty typeKey for %v", t)) |
- } |
- i++ |
- } |
- sort.Strings(typeKeys) |
- return typeKeys |
-} |
- |
-// findReachableTypes is a recursive helper function for FindReachableTypes. |
-// It performs a depth-first search through the type graph while populating |
-// |reachableSet| with the UserDefinedTypes encountered during the search. |
-func findReachableTypes(udt UserDefinedType, reachableSet UserDefinedTypeSet) { |
- if udt == nil { |
- panic("udt is nil") |
- } |
- if reachableSet.Contains(udt) { |
- return |
- } |
- // Synthetic request and response structs should not actually be added |
- // to the reachable set. |
- if strct, ok := udt.(*MojomStruct); !ok || strct.structType == StructTypeRegular { |
- reachableSet.Add(udt) |
- } |
- for _, object := range udt.GetDeclaredObjects() { |
- switch object := object.(type) { |
- case *MojomEnum: |
- // There is an edge in the type graph from this struct or interface |
- // type to a contained Enum. |
- findReachableTypes(object, reachableSet) |
- case *UserDefinedConstant: |
- // There is an edge in the type graph from this struct or interface |
- // type to the type of a contained constant. |
- for t, _ := range object.DeclaredType().ReferencedUserDefinedTypes() { |
- findReachableTypes(t, reachableSet) |
- } |
- case *StructField: |
- // There is an edge in the type graph from this struct type to the type of a field. |
- for t, _ := range object.FieldType.ReferencedUserDefinedTypes() { |
- findReachableTypes(t, reachableSet) |
- } |
- case *UnionField: |
- // There is an edge in the type graph from this union type to the type of a field. |
- for t, _ := range object.FieldType.ReferencedUserDefinedTypes() { |
- findReachableTypes(t, reachableSet) |
- } |
- case *MojomMethod: |
- // There is an edge in the type graph from this interface type to |
- // the type of a request or response parameter. |
- findReachableTypes(object.Parameters, reachableSet) |
- if object.ResponseParameters != nil { |
- findReachableTypes(object.ResponseParameters, reachableSet) |
- } |
- } |
- } |
-} |
- |
// This method is invoked from the constructors for the containing types: |
// NewMojomInterface, NewMojomStruct, NewMojomEnum, NewMojomUnion |
func (b *UserDefinedTypeBase) Init(declData DeclarationData, thisType UserDefinedType) { |