Documentation ¶
Overview ¶
Package util implements utility functions for AST and types.
Index ¶
- Variables
- func ExprBarsNilness(pass *analysis.Pass, expr ast.Expr) bool
- func ExprIsAuthentic(pass *analysis.Pass, expr ast.Expr) bool
- func FuncIdentFromCallExpr(expr *ast.CallExpr) *ast.Ident
- func FuncIsErrReturning(fdecl *types.Func) bool
- func FuncIsOkReturning(fdecl *types.Func) bool
- func FuncNumResults(decl *types.Func) int
- func GetFieldVal(compElts []ast.Expr, fieldName string, numFields int, index int) ast.Expr
- func GetFunctionParamNode(funcDecl *ast.FuncDecl, searchParam *types.Var) ast.Expr
- func GetParamObjFromIndex(functionType *types.Func, argIdx int) *types.Var
- func GetSelectorExprHeadIdent(selExpr *ast.SelectorExpr) *ast.Ident
- func IsEmptyExpr(expr ast.Expr) bool
- func IsFieldSelectorChain(expr ast.Expr) bool
- func IsLiteral(expr ast.Expr, literals ...string) bool
- func IsSliceAppendCall(node *ast.CallExpr, pass *analysis.Pass) (*types.Slice, bool)
- func PartiallyQualifiedFuncName(f *types.Func) string
- func PortionAfterSep(input, sep string, occ int) string
- func PosToLocation(pos token.Pos, pass *analysis.Pass) token.Position
- func PrettyPrintErrorMessage(msg string) string
- func TruncatePosition(position token.Position) token.Position
- func TypeAsDeeplyStruct(typ types.Type) *types.Struct
- func TypeBarsNilness(t types.Type) bool
- func TypeIsDeep(t types.Type) bool
- func TypeIsDeeplyArray(t types.Type) bool
- func TypeIsDeeplyChan(t types.Type) bool
- func TypeIsDeeplyInterface(t types.Type) bool
- func TypeIsDeeplyMap(t types.Type) bool
- func TypeIsDeeplyPtr(t types.Type) bool
- func TypeIsDeeplySlice(t types.Type) bool
- func TypeIsSlice(t types.Type) bool
- func UnwrapPtr(t types.Type) types.Type
- type ExprNonceMap
- type GuardNonce
- type GuardNonceGenerator
- type GuardNonceSet
- func (g GuardNonceSet) Add(guards ...GuardNonce) GuardNonceSet
- func (g GuardNonceSet) Contains(n GuardNonce) bool
- func (g GuardNonceSet) Copy() GuardNonceSet
- func (g GuardNonceSet) Eq(other GuardNonceSet) bool
- func (g GuardNonceSet) Intersection(others ...GuardNonceSet) GuardNonceSet
- func (g GuardNonceSet) IsEmpty() bool
- func (g GuardNonceSet) Remove(guards ...GuardNonce) GuardNonceSet
- func (g GuardNonceSet) SubsetOf(other GuardNonceSet) bool
- func (g GuardNonceSet) Union(others ...GuardNonceSet) GuardNonceSet
Constants ¶
This section is empty.
Variables ¶
var BoolType = types.Universe.Lookup("bool").Type()
BoolType is the type of the builtin "bool" interface.
var BuiltinAppend = types.Universe.Lookup("append")
BuiltinAppend is the builtin "append" function object.
var BuiltinLen = types.Universe.Lookup("len")
BuiltinLen is the builtin "len" function object.
var BuiltinNew = types.Universe.Lookup("new")
BuiltinNew is the builtin "new" function object.
var ErrorType = types.Universe.Lookup("error").Type()
ErrorType is the type of the builtin "error" interface.
Functions ¶
func ExprBarsNilness ¶
ExprBarsNilness returns if the expression can never be nil for the simple reason that nil does not inhabit its type.
func ExprIsAuthentic ¶
ExprIsAuthentic aims to return true iff the passed expression is an AST node found in the source program of this pass - not one that we created as an intermediate value. There is no fully sound way to do this - but returning whether it is present in the `Types` map map is a good approximation. Right now, this is used only to decide whether to print the location of the producer expression in a full trigger.
func FuncIdentFromCallExpr ¶
FuncIdentFromCallExpr return a function identified from a call expression, nil otherwise nilable(result 0)
func FuncIsErrReturning ¶
FuncIsErrReturning encodes the conditions that a function is deemed "error-returning". This guards its results to require an `err` check before use as nonnil. A function is deemed "error-returning" iff it has a single result of type `error`, and that result is the last in the list of results.
func FuncIsOkReturning ¶
FuncIsOkReturning encodes the conditions that a function is deemed "ok-returning". This guards its results to require an `ok` check before use as nonnil. A function is deemed "ok-returning" iff it has a single result of type `bool`, and that result is the last in the list of results.
func FuncNumResults ¶
FuncNumResults looks at a function declaration and returns the number of results of that function
func GetFieldVal ¶
GetFieldVal returns the assigned value for the field at index. compElts holds the elements of the composite literal expression for struct initialization
func GetFunctionParamNode ¶
GetFunctionParamNode returns the ast param node matching the variable searchParam
func GetParamObjFromIndex ¶
GetParamObjFromIndex get the variable corresponding to the parameter from the function functionType
func GetSelectorExprHeadIdent ¶
func GetSelectorExprHeadIdent(selExpr *ast.SelectorExpr) *ast.Ident
GetSelectorExprHeadIdent gets the head of the chained selector expression if it is an ident. Returns nil otherwise
func IsEmptyExpr ¶
IsEmptyExpr checks if an expression is the empty identifier
func IsFieldSelectorChain ¶
IsFieldSelectorChain returns true if the expr is chain of idents. e.g, x.y.z It returns for false for expressions such as x.y().z
func IsLiteral ¶
IsLiteral returns true if `expr` is a literal that matches with one of the given literal values (e.g., "nil", "true", "false)
func IsSliceAppendCall ¶
IsSliceAppendCall checks if `node` represents the builtin append(slice []Type, elems ...Type) []Type call on a slice. The function checks 2 things, 1) Name of the called function is "builtin append" 2) The first argument to the function is a slice
func PartiallyQualifiedFuncName ¶
PartiallyQualifiedFuncName returns the name of the passed function, with the name of its receiver if defined
func PortionAfterSep ¶
PortionAfterSep returns the suffix of the passed string `input` containing at most `occ` occurrences of the separator `sep`
func PosToLocation ¶
PosToLocation converts a token.Pos as a real code location, of token.Position.
func PrettyPrintErrorMessage ¶
PrettyPrintErrorMessage is used in error reporting to post process and pretty print the output with colors
func TruncatePosition ¶
TruncatePosition truncates the prefix of the filename to keep it at the given depth (config.DirLevelsToPrintForTriggers)
func TypeAsDeeplyStruct ¶
TypeAsDeeplyStruct returns underlying struct type if the type is struct type or a pointer to a struct type returns nil otherwise
func TypeBarsNilness ¶
TypeBarsNilness returns false iff the type `t` is inhabited by nil.
func TypeIsDeep ¶
TypeIsDeep checks if a type is an expression that admits deep nilability, such as maps, slices, arrays, etc. Only consider pointers to deep types (e.g., `var x *[]int`) as deep type, not pointers to basic types (e.g., `var x *int`) or struct types (e.g., `var x *S`)
func TypeIsDeeplyArray ¶
TypeIsDeeplyArray returns true if `t` is of array type, including transitively through Named types
func TypeIsDeeplyChan ¶
TypeIsDeeplyChan returns true if `t` is of channel type, including transitively through Named types
func TypeIsDeeplyInterface ¶
TypeIsDeeplyInterface returns true if `t` is of struct type, including transitively through Named types
func TypeIsDeeplyMap ¶
TypeIsDeeplyMap returns true if `t` is of map type, including transitively through Named types
func TypeIsDeeplyPtr ¶
TypeIsDeeplyPtr returns true if `t` is of pointer type, including transitively through Named types
func TypeIsDeeplySlice ¶
TypeIsDeeplySlice returns true if `t` is of slice type, including transitively through Named types
func TypeIsSlice ¶
TypeIsSlice returns true if `t` is of slice type
Types ¶
type ExprNonceMap ¶
type ExprNonceMap = map[ast.Expr]GuardNonce
An ExprNonceMap maps AST nodes to nonces, to establish their canonical interpretation.
type GuardNonce ¶
type GuardNonce int
A GuardNonce is a unique token used to identify contracts that arise through the RichCheckEffect mechanism. GuardNonces are canonically tied to an AST node through the ExprNonceMap accumulated in their generator.
func (GuardNonce) Eq ¶
func (g GuardNonce) Eq(g2 GuardNonce) bool
Eq compares two GuardNonces for equality
type GuardNonceGenerator ¶
type GuardNonceGenerator struct {
// contains filtered or unexported fields
}
A GuardNonceGenerator is a stateful object used to ensure unique obtainment of nonces. It also keeps track of the expression with which they are associate, in a map of type ExprNonceMap to be later embedded into a RootAssertionNode nonnil(exprNonceMap)
func NewGuardNonceGenerator ¶
func NewGuardNonceGenerator() *GuardNonceGenerator
NewGuardNonceGenerator returns a fresh instance of GuardNonceGenerator that can be subsequently used to identify and track RichCheckEffects.
func (*GuardNonceGenerator) GetExprNonceMap ¶
func (g *GuardNonceGenerator) GetExprNonceMap() ExprNonceMap
GetExprNonceMap for a GuardNonceGenerator returns the underlying ExprNonceMap
func (*GuardNonceGenerator) Next ¶
func (g *GuardNonceGenerator) Next(expr ast.Expr) GuardNonce
Next for a GuardNonceGenerator returns the first nonce that has not already been output. The method also takes an AST expression, to be tied to this nonce as its interpretation.
type GuardNonceSet ¶
type GuardNonceSet map[GuardNonce]bool
GuardNonceSet is a set of GuardNonces
func NoGuards ¶
func NoGuards() GuardNonceSet
NoGuards returns an empty GuardNonceSet - to be used to indicate no guards
func (GuardNonceSet) Add ¶
func (g GuardNonceSet) Add(guards ...GuardNonce) GuardNonceSet
Add statefully adds one or more new GuardNonces to a GuardNonceSet nonnil(result 0)
func (GuardNonceSet) Contains ¶
func (g GuardNonceSet) Contains(n GuardNonce) bool
Contains returns true iff a given GuardNonceSet contains a passed GuardNonce
func (GuardNonceSet) Copy ¶
func (g GuardNonceSet) Copy() GuardNonceSet
Copy returns a copy of the passed GuardNonceSet without modifying the original nonnil(result 0)
func (GuardNonceSet) Eq ¶
func (g GuardNonceSet) Eq(other GuardNonceSet) bool
Eq returns true iff a given GuardNonceSet contains the same elements as a passed GuardNonceSet nonnil(other)
func (GuardNonceSet) Intersection ¶
func (g GuardNonceSet) Intersection(others ...GuardNonceSet) GuardNonceSet
Intersection returns a new GuardNonceSet that is the intersection of its two parameters without modifying either nonnil(others)
func (GuardNonceSet) IsEmpty ¶
func (g GuardNonceSet) IsEmpty() bool
IsEmpty returns true if a given GuardNonceSet is empty
func (GuardNonceSet) Remove ¶
func (g GuardNonceSet) Remove(guards ...GuardNonce) GuardNonceSet
Remove statefully removes one or more GuardNonces from a GuardNonceSet nonnil(result 0)
func (GuardNonceSet) SubsetOf ¶
func (g GuardNonceSet) SubsetOf(other GuardNonceSet) bool
SubsetOf returns true iff a given GuardNonceSet is a subset of a passed GuardNonceSet nonnil(other)
func (GuardNonceSet) Union ¶
func (g GuardNonceSet) Union(others ...GuardNonceSet) GuardNonceSet
Union returns a new GuardNonceSet that is the union of its two parameters without modifying either nonnil(result 0)
Directories ¶
Path | Synopsis |
---|---|
Package analysishelper provides helper functions for the `go/analysis` package.
|
Package analysishelper provides helper functions for the `go/analysis` package. |
Package asthelper implements utility functions for AST.
|
Package asthelper implements utility functions for AST. |
Package orderedmap implements a generic ordered map that supports iteration in insertion order.
|
Package orderedmap implements a generic ordered map that supports iteration in insertion order. |