github.com/bir3/gocompiler@v0.9.2202/src/go/types/objset.go (about)

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