Source file src/go/types/objset.go

     1  // Code generated by "go test -run=Generate -write=all"; DO NOT EDIT.
     2  // Source: ../../cmd/compile/internal/types2/objset.go
     3  
     4  // Copyright 2013 The Go Authors. All rights reserved.
     5  // Use of this source code is governed by a BSD-style
     6  // license that can be found in the LICENSE file.
     7  
     8  // This file implements objsets.
     9  //
    10  // An objset is similar to a Scope but objset elements
    11  // are identified by their unique id, instead of their
    12  // object name.
    13  
    14  package types
    15  
    16  // An objset is a set of objects identified by their unique id.
    17  // The zero value for objset is a ready-to-use empty objset.
    18  type objset map[string]Object // initialized lazily
    19  
    20  // insert attempts to insert an object obj into objset s.
    21  // If s already contains an alternative object alt with
    22  // the same name, insert leaves s unchanged and returns alt.
    23  // Otherwise it inserts obj and returns nil.
    24  func (s *objset) insert(obj Object) Object {
    25  	id := obj.Id()
    26  	if alt := (*s)[id]; alt != nil {
    27  		return alt
    28  	}
    29  	if *s == nil {
    30  		*s = make(map[string]Object)
    31  	}
    32  	(*s)[id] = obj
    33  	return nil
    34  }
    35  

View as plain text