github.com/goplus/gop@v1.2.6/cl/recorder_test.go (about)

     1  package cl_test
     2  
     3  import (
     4  	"go/types"
     5  
     6  	"github.com/goplus/gop/ast"
     7  )
     8  
     9  type gopRecorder struct {
    10  }
    11  
    12  // Type maps expressions to their types, and for constant
    13  // expressions, also their values. Invalid expressions are
    14  // omitted.
    15  //
    16  // For (possibly parenthesized) identifiers denoting built-in
    17  // functions, the recorded signatures are call-site specific:
    18  // if the call result is not a constant, the recorded type is
    19  // an argument-specific signature. Otherwise, the recorded type
    20  // is invalid.
    21  //
    22  // The Types map does not record the type of every identifier,
    23  // only those that appear where an arbitrary expression is
    24  // permitted. For instance, the identifier f in a selector
    25  // expression x.f is found only in the Selections map, the
    26  // identifier z in a variable declaration 'var z int' is found
    27  // only in the Defs map, and identifiers denoting packages in
    28  // qualified identifiers are collected in the Uses map.
    29  func (info gopRecorder) Type(e ast.Expr, tv types.TypeAndValue) {
    30  }
    31  
    32  // Instantiate maps identifiers denoting generic types or functions to their
    33  // type arguments and instantiated type.
    34  //
    35  // For example, Instantiate will map the identifier for 'T' in the type
    36  // instantiation T[int, string] to the type arguments [int, string] and
    37  // resulting instantiated *Named type. Given a generic function
    38  // func F[A any](A), Instances will map the identifier for 'F' in the call
    39  // expression F(int(1)) to the inferred type arguments [int], and resulting
    40  // instantiated *Signature.
    41  //
    42  // Invariant: Instantiating Uses[id].Type() with Instances[id].TypeArgs
    43  // results in an equivalent of Instances[id].Type.
    44  func (info gopRecorder) Instantiate(id *ast.Ident, inst types.Instance) {
    45  }
    46  
    47  // Def maps identifiers to the objects they define (including
    48  // package names, dots "." of dot-imports, and blank "_" identifiers).
    49  // For identifiers that do not denote objects (e.g., the package name
    50  // in package clauses, or symbolic variables t in t := x.(type) of
    51  // type switch headers), the corresponding objects are nil.
    52  //
    53  // For an embedded field, Def maps the field *Var it defines.
    54  //
    55  // Invariant: Defs[id] == nil || Defs[id].Pos() == id.Pos()
    56  func (info gopRecorder) Def(id *ast.Ident, obj types.Object) {
    57  }
    58  
    59  // Use maps identifiers to the objects they denote.
    60  //
    61  // For an embedded field, Use maps the *TypeName it denotes.
    62  //
    63  // Invariant: Uses[id].Pos() != id.Pos()
    64  func (info gopRecorder) Use(id *ast.Ident, obj types.Object) {
    65  }
    66  
    67  // Implicit maps nodes to their implicitly declared objects, if any.
    68  // The following node and object types may appear:
    69  //
    70  //	node               declared object
    71  //
    72  //	*ast.ImportSpec    *PkgName for imports without renames
    73  //	*ast.CaseClause    type-specific *Var for each type switch case clause (incl. default)
    74  //	*ast.Field         anonymous parameter *Var (incl. unnamed results)
    75  func (info gopRecorder) Implicit(node ast.Node, obj types.Object) {
    76  }
    77  
    78  // Select maps selector expressions (excluding qualified identifiers)
    79  // to their corresponding selections.
    80  func (info gopRecorder) Select(e *ast.SelectorExpr, sel *types.Selection) {
    81  }
    82  
    83  // Scope maps ast.Nodes to the scopes they define. Package scopes are not
    84  // associated with a specific node but with all files belonging to a package.
    85  // Thus, the package scope can be found in the type-checked Package object.
    86  // Scopes nest, with the Universe scope being the outermost scope, enclosing
    87  // the package scope, which contains (one or more) files scopes, which enclose
    88  // function scopes which in turn enclose statement and function literal scopes.
    89  // Note that even though package-level functions are declared in the package
    90  // scope, the function scopes are embedded in the file scope of the file
    91  // containing the function declaration.
    92  //
    93  // The following node types may appear in Scopes:
    94  //
    95  //	*ast.File
    96  //	*ast.FuncType
    97  //	*ast.TypeSpec
    98  //	*ast.BlockStmt
    99  //	*ast.IfStmt
   100  //	*ast.SwitchStmt
   101  //	*ast.TypeSwitchStmt
   102  //	*ast.CaseClause
   103  //	*ast.CommClause
   104  //	*ast.ForStmt
   105  //	*ast.RangeStmt
   106  func (info gopRecorder) Scope(n ast.Node, scope *types.Scope) {
   107  }