github.com/shogo82148/std@v1.22.1-0.20240327122250-4e474527810c/cmd/compile/internal/types2/object.go (about)

     1  // Copyright 2013 The Go Authors. All rights reserved.
     2  // Use of this source code is governed by a BSD-style
     3  // license that can be found in the LICENSE file.
     4  
     5  package types2
     6  
     7  import (
     8  	"github.com/shogo82148/std/cmd/compile/internal/syntax"
     9  	"github.com/shogo82148/std/go/constant"
    10  )
    11  
    12  // An Object describes a named language entity such as a package,
    13  // constant, type, variable, function (incl. methods), or label.
    14  // All objects implement the Object interface.
    15  type Object interface {
    16  	Parent() *Scope
    17  	Pos() syntax.Pos
    18  	Pkg() *Package
    19  	Name() string
    20  	Type() Type
    21  	Exported() bool
    22  	Id() string
    23  
    24  	String() string
    25  
    26  	order() uint32
    27  
    28  	color() color
    29  
    30  	setType(Type)
    31  
    32  	setOrder(uint32)
    33  
    34  	setColor(color color)
    35  
    36  	setParent(*Scope)
    37  
    38  	sameId(pkg *Package, name string, foldCase bool) bool
    39  
    40  	scopePos() syntax.Pos
    41  
    42  	setScopePos(pos syntax.Pos)
    43  }
    44  
    45  // Id returns name if it is exported, otherwise it
    46  // returns the name qualified with the package path.
    47  func Id(pkg *Package, name string) string
    48  
    49  // A PkgName represents an imported Go package.
    50  // PkgNames don't have a type.
    51  type PkgName struct {
    52  	object
    53  	imported *Package
    54  	used     bool
    55  }
    56  
    57  // NewPkgName returns a new PkgName object representing an imported package.
    58  // The remaining arguments set the attributes found with all Objects.
    59  func NewPkgName(pos syntax.Pos, pkg *Package, name string, imported *Package) *PkgName
    60  
    61  // Imported returns the package that was imported.
    62  // It is distinct from Pkg(), which is the package containing the import statement.
    63  func (obj *PkgName) Imported() *Package
    64  
    65  // A Const represents a declared constant.
    66  type Const struct {
    67  	object
    68  	val constant.Value
    69  }
    70  
    71  // NewConst returns a new constant with value val.
    72  // The remaining arguments set the attributes found with all Objects.
    73  func NewConst(pos syntax.Pos, pkg *Package, name string, typ Type, val constant.Value) *Const
    74  
    75  // Val returns the constant's value.
    76  func (obj *Const) Val() constant.Value
    77  
    78  // A TypeName represents a name for a (defined or alias) type.
    79  type TypeName struct {
    80  	object
    81  }
    82  
    83  // NewTypeName returns a new type name denoting the given typ.
    84  // The remaining arguments set the attributes found with all Objects.
    85  //
    86  // The typ argument may be a defined (Named) type or an alias type.
    87  // It may also be nil such that the returned TypeName can be used as
    88  // argument for NewNamed, which will set the TypeName's type as a side-
    89  // effect.
    90  func NewTypeName(pos syntax.Pos, pkg *Package, name string, typ Type) *TypeName
    91  
    92  // NewTypeNameLazy returns a new defined type like NewTypeName, but it
    93  // lazily calls resolve to finish constructing the Named object.
    94  func NewTypeNameLazy(pos syntax.Pos, pkg *Package, name string, load func(named *Named) (tparams []*TypeParam, underlying Type, methods []*Func)) *TypeName
    95  
    96  // IsAlias reports whether obj is an alias name for a type.
    97  func (obj *TypeName) IsAlias() bool
    98  
    99  // A Variable represents a declared variable (including function parameters and results, and struct fields).
   100  type Var struct {
   101  	object
   102  	embedded bool
   103  	isField  bool
   104  	used     bool
   105  	origin   *Var
   106  }
   107  
   108  // NewVar returns a new variable.
   109  // The arguments set the attributes found with all Objects.
   110  func NewVar(pos syntax.Pos, pkg *Package, name string, typ Type) *Var
   111  
   112  // NewParam returns a new variable representing a function parameter.
   113  func NewParam(pos syntax.Pos, pkg *Package, name string, typ Type) *Var
   114  
   115  // NewField returns a new variable representing a struct field.
   116  // For embedded fields, the name is the unqualified type name
   117  // under which the field is accessible.
   118  func NewField(pos syntax.Pos, pkg *Package, name string, typ Type, embedded bool) *Var
   119  
   120  // Anonymous reports whether the variable is an embedded field.
   121  // Same as Embedded; only present for backward-compatibility.
   122  func (obj *Var) Anonymous() bool
   123  
   124  // Embedded reports whether the variable is an embedded field.
   125  func (obj *Var) Embedded() bool
   126  
   127  // IsField reports whether the variable is a struct field.
   128  func (obj *Var) IsField() bool
   129  
   130  // Origin returns the canonical Var for its receiver, i.e. the Var object
   131  // recorded in Info.Defs.
   132  //
   133  // For synthetic Vars created during instantiation (such as struct fields or
   134  // function parameters that depend on type arguments), this will be the
   135  // corresponding Var on the generic (uninstantiated) type. For all other Vars
   136  // Origin returns the receiver.
   137  func (obj *Var) Origin() *Var
   138  
   139  // A Func represents a declared function, concrete method, or abstract
   140  // (interface) method. Its Type() is always a *Signature.
   141  // An abstract method may belong to many interfaces due to embedding.
   142  type Func struct {
   143  	object
   144  	hasPtrRecv_ bool
   145  	origin      *Func
   146  }
   147  
   148  // NewFunc returns a new function with the given signature, representing
   149  // the function's type.
   150  func NewFunc(pos syntax.Pos, pkg *Package, name string, sig *Signature) *Func
   151  
   152  // FullName returns the package- or receiver-type-qualified name of
   153  // function or method obj.
   154  func (obj *Func) FullName() string
   155  
   156  // Scope returns the scope of the function's body block.
   157  // The result is nil for imported or instantiated functions and methods
   158  // (but there is also no mechanism to get to an instantiated function).
   159  func (obj *Func) Scope() *Scope
   160  
   161  // Origin returns the canonical Func for its receiver, i.e. the Func object
   162  // recorded in Info.Defs.
   163  //
   164  // For synthetic functions created during instantiation (such as methods on an
   165  // instantiated Named type or interface methods that depend on type arguments),
   166  // this will be the corresponding Func on the generic (uninstantiated) type.
   167  // For all other Funcs Origin returns the receiver.
   168  func (obj *Func) Origin() *Func
   169  
   170  // Pkg returns the package to which the function belongs.
   171  //
   172  // The result is nil for methods of types in the Universe scope,
   173  // like method Error of the error built-in interface type.
   174  func (obj *Func) Pkg() *Package
   175  
   176  // A Label represents a declared label.
   177  // Labels don't have a type.
   178  type Label struct {
   179  	object
   180  	used bool
   181  }
   182  
   183  // NewLabel returns a new label.
   184  func NewLabel(pos syntax.Pos, pkg *Package, name string) *Label
   185  
   186  // A Builtin represents a built-in function.
   187  // Builtins don't have a valid type.
   188  type Builtin struct {
   189  	object
   190  	id builtinId
   191  }
   192  
   193  // Nil represents the predeclared value nil.
   194  type Nil struct {
   195  	object
   196  }
   197  
   198  // ObjectString returns the string form of obj.
   199  // The Qualifier controls the printing of
   200  // package-level objects, and may be nil.
   201  func ObjectString(obj Object, qf Qualifier) string
   202  
   203  func (obj *PkgName) String() string
   204  func (obj *Const) String() string
   205  func (obj *TypeName) String() string
   206  func (obj *Var) String() string
   207  func (obj *Func) String() string
   208  func (obj *Label) String() string
   209  func (obj *Builtin) String() string
   210  func (obj *Nil) String() string