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

     1  // Copyright 2020 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 ir
     6  
     7  import (
     8  	"github.com/shogo82148/std/cmd/compile/internal/types"
     9  	"github.com/shogo82148/std/cmd/internal/obj"
    10  	"github.com/shogo82148/std/cmd/internal/src"
    11  
    12  	"github.com/shogo82148/std/go/constant"
    13  )
    14  
    15  // An Ident is an identifier, possibly qualified.
    16  type Ident struct {
    17  	miniExpr
    18  	sym *types.Sym
    19  }
    20  
    21  func NewIdent(pos src.XPos, sym *types.Sym) *Ident
    22  
    23  func (n *Ident) Sym() *types.Sym
    24  
    25  // Name holds Node fields used only by named nodes (ONAME, OTYPE, some OLITERAL).
    26  type Name struct {
    27  	miniExpr
    28  	BuiltinOp Op
    29  	Class     Class
    30  	pragma    PragmaFlag
    31  	flags     bitset16
    32  	DictIndex uint16
    33  	sym       *types.Sym
    34  	Func      *Func
    35  	Offset_   int64
    36  	val       constant.Value
    37  	Opt       interface{}
    38  	Embed     *[]Embed
    39  
    40  	// For a local variable (not param) or extern, the initializing assignment (OAS or OAS2).
    41  	// For a closure var, the ONAME node of the original (outermost) captured variable.
    42  	// For the case-local variables of a type switch, the type switch guard (OTYPESW).
    43  	// For a range variable, the range statement (ORANGE)
    44  	// For a recv variable in a case of a select statement, the receive assignment (OSELRECV2)
    45  	// For the name of a function, points to corresponding Func node.
    46  	Defn Node
    47  
    48  	// The function, method, or closure in which local variable or param is declared.
    49  	Curfn *Func
    50  
    51  	Heapaddr *Name
    52  
    53  	// Outer points to the immediately enclosing function's copy of this
    54  	// closure variable. If not a closure variable, then Outer is nil.
    55  	Outer *Name
    56  }
    57  
    58  // RecordFrameOffset records the frame offset for the name.
    59  // It is used by package types when laying out function arguments.
    60  func (n *Name) RecordFrameOffset(offset int64)
    61  
    62  // NewNameAt returns a new ONAME Node associated with symbol s at position pos.
    63  // The caller is responsible for setting Curfn.
    64  func NewNameAt(pos src.XPos, sym *types.Sym, typ *types.Type) *Name
    65  
    66  // NewBuiltin returns a new Name representing a builtin function,
    67  // either predeclared or from package unsafe.
    68  func NewBuiltin(sym *types.Sym, op Op) *Name
    69  
    70  // NewLocal returns a new function-local variable with the given name and type.
    71  func (fn *Func) NewLocal(pos src.XPos, sym *types.Sym, typ *types.Type) *Name
    72  
    73  // NewDeclNameAt returns a new Name associated with symbol s at position pos.
    74  // The caller is responsible for setting Curfn.
    75  func NewDeclNameAt(pos src.XPos, op Op, sym *types.Sym) *Name
    76  
    77  // NewConstAt returns a new OLITERAL Node associated with symbol s at position pos.
    78  func NewConstAt(pos src.XPos, sym *types.Sym, typ *types.Type, val constant.Value) *Name
    79  
    80  func (n *Name) Name() *Name
    81  func (n *Name) Sym() *types.Sym
    82  func (n *Name) SetSym(x *types.Sym)
    83  func (n *Name) SubOp() Op
    84  func (n *Name) SetSubOp(x Op)
    85  func (n *Name) SetFunc(x *Func)
    86  func (n *Name) FrameOffset() int64
    87  func (n *Name) SetFrameOffset(x int64)
    88  
    89  func (n *Name) Linksym() *obj.LSym
    90  func (n *Name) LinksymABI(abi obj.ABI) *obj.LSym
    91  
    92  func (*Name) CanBeNtype()
    93  func (*Name) CanBeAnSSASym()
    94  func (*Name) CanBeAnSSAAux()
    95  
    96  // Pragma returns the PragmaFlag for p, which must be for an OTYPE.
    97  func (n *Name) Pragma() PragmaFlag
    98  
    99  // SetPragma sets the PragmaFlag for p, which must be for an OTYPE.
   100  func (n *Name) SetPragma(flag PragmaFlag)
   101  
   102  // Alias reports whether p, which must be for an OTYPE, is a type alias.
   103  func (n *Name) Alias() bool
   104  
   105  // SetAlias sets whether p, which must be for an OTYPE, is a type alias.
   106  func (n *Name) SetAlias(alias bool)
   107  
   108  func (n *Name) Readonly() bool
   109  func (n *Name) Needzero() bool
   110  func (n *Name) AutoTemp() bool
   111  func (n *Name) Used() bool
   112  func (n *Name) IsClosureVar() bool
   113  func (n *Name) IsOutputParamHeapAddr() bool
   114  func (n *Name) IsOutputParamInRegisters() bool
   115  func (n *Name) Addrtaken() bool
   116  func (n *Name) InlFormal() bool
   117  func (n *Name) InlLocal() bool
   118  func (n *Name) OpenDeferSlot() bool
   119  func (n *Name) Libfuzzer8BitCounter() bool
   120  func (n *Name) CoverageCounter() bool
   121  func (n *Name) CoverageAuxVar() bool
   122  
   123  func (n *Name) SetNeedzero(b bool)
   124  func (n *Name) SetAutoTemp(b bool)
   125  func (n *Name) SetUsed(b bool)
   126  func (n *Name) SetIsClosureVar(b bool)
   127  func (n *Name) SetIsOutputParamHeapAddr(b bool)
   128  func (n *Name) SetIsOutputParamInRegisters(b bool)
   129  func (n *Name) SetAddrtaken(b bool)
   130  func (n *Name) SetInlFormal(b bool)
   131  func (n *Name) SetInlLocal(b bool)
   132  func (n *Name) SetOpenDeferSlot(b bool)
   133  func (n *Name) SetLibfuzzer8BitCounter(b bool)
   134  func (n *Name) SetCoverageCounter(b bool)
   135  func (n *Name) SetCoverageAuxVar(b bool)
   136  
   137  // OnStack reports whether variable n may reside on the stack.
   138  func (n *Name) OnStack() bool
   139  
   140  // MarkReadonly indicates that n is an ONAME with readonly contents.
   141  func (n *Name) MarkReadonly()
   142  
   143  // Val returns the constant.Value for the node.
   144  func (n *Name) Val() constant.Value
   145  
   146  // SetVal sets the constant.Value for the node.
   147  func (n *Name) SetVal(v constant.Value)
   148  
   149  // Canonical returns the logical declaration that n represents. If n
   150  // is a closure variable, then Canonical returns the original Name as
   151  // it appears in the function that immediately contains the
   152  // declaration. Otherwise, Canonical simply returns n itself.
   153  func (n *Name) Canonical() *Name
   154  
   155  func (n *Name) SetByval(b bool)
   156  
   157  func (n *Name) Byval() bool
   158  
   159  // NewClosureVar returns a new closure variable for fn to refer to
   160  // outer variable n.
   161  func NewClosureVar(pos src.XPos, fn *Func, n *Name) *Name
   162  
   163  // NewHiddenParam returns a new hidden parameter for fn with the given
   164  // name and type.
   165  func NewHiddenParam(pos src.XPos, fn *Func, sym *types.Sym, typ *types.Type) *Name
   166  
   167  // SameSource reports whether two nodes refer to the same source
   168  // element.
   169  //
   170  // It exists to help incrementally migrate the compiler towards
   171  // allowing the introduction of IdentExpr (#42990). Once we have
   172  // IdentExpr, it will no longer be safe to directly compare Node
   173  // values to tell if they refer to the same Name. Instead, code will
   174  // need to explicitly get references to the underlying Name object(s),
   175  // and compare those instead.
   176  //
   177  // It will still be safe to compare Nodes directly for checking if two
   178  // nodes are syntactically the same. The SameSource function exists to
   179  // indicate code that intentionally compares Nodes for syntactic
   180  // equality as opposed to code that has yet to be updated in
   181  // preparation for IdentExpr.
   182  func SameSource(n1, n2 Node) bool
   183  
   184  // Uses reports whether expression x is a (direct) use of the given
   185  // variable.
   186  func Uses(x Node, v *Name) bool
   187  
   188  // DeclaredBy reports whether expression x refers (directly) to a
   189  // variable that was declared by the given statement.
   190  func DeclaredBy(x, stmt Node) bool
   191  
   192  // The Class of a variable/function describes the "storage class"
   193  // of a variable or function. During parsing, storage classes are
   194  // called declaration contexts.
   195  type Class uint8
   196  
   197  //go:generate stringer -type=Class name.go
   198  const (
   199  	Pxxx Class = iota
   200  	PEXTERN
   201  	PAUTO
   202  	PAUTOHEAP
   203  	PPARAM
   204  	PPARAMOUT
   205  	PTYPEPARAM
   206  	PFUNC
   207  
   208  	// Careful: Class is stored in three bits in Node.flags.
   209  	_ = uint((1 << 3) - iota)
   210  )
   211  
   212  type Embed struct {
   213  	Pos      src.XPos
   214  	Patterns []string
   215  }