Description

Function represents the parameters, results, and code of a function or method.

If Blocks is nil, this indicates an external function for which no Go source code is available. In this case, FreeVars and Locals are nil too. Clients performing whole-program analysis must handle external functions specially.

Blocks contains the function's control-flow graph (CFG). Blocks[0] is the function entry point; block order is not otherwise semantically significant, though it may affect the readability of the disassembly. To iterate over the blocks in dominance order, use DomPreorder().

Recover is an optional second entry point to which control resumes after a recovered panic. The Recover block may contain only a return statement, preceded by a load of the function's named return parameters, if any.

A nested function (Parent()!=nil) that refers to one or more lexically enclosing local variables ("free variables") has FreeVars. Such functions cannot be called directly but require a value created by MakeClosure which, via its Bindings, supplies values for these parameters.

If the function is a method (Signature.Recv() != nil) then the first element of Params is the receiver parameter.

A Go package may declare many functions called "init". For each one, Object().Name() returns "init" but Name() returns "init#1", etc, in declaration order.

Pos() returns the declaring ast.FuncLit.Type.Func or the position of the ast.FuncDecl.Name, if the function was explicit in the source. Synthetic wrappers, for which Synthetic != "", may share the same position as the function they wrap. Syntax.Pos() always returns the position of the declaring "func" token.

Type() returns the function's Signature.