structinit

package
v0.4.6-alpha Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 26, 2025 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Overview

Package structinit implements the struct initialization syntactic analysis.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FormattedReport

func FormattedReport(res AnalysisResult) (string, bool)

FormattedReport writes res to a string and returns true if the analysis should fail.

Types

type AnalysisReqs

type AnalysisReqs struct {
	// Tag is the tag of the problem to analyze
	Tag string
}

AnalysisReqs groups the options of the analysis together

type AnalysisResult

type AnalysisResult struct {
	// InitInfos is a mapping from the named struct type to its initialization
	// information.
	InitInfos map[*types.Named]InitInfo
}

AnalysisResult is the result of the struct-init analysis.

func Analyze

func Analyze(state *ptr.State, reqs AnalysisReqs) (AnalysisResult, error)

Analyze runs the analysis on prog.

type BadReinit

type BadReinit struct {
	// Call is the function call instruction.
	Call ssa.Instruction
	// Pos is the position of the instruction.
	Pos token.Position
}

BadReinit is a function call resulting in a struct that should have specific fields reinitialized, but it hasn't.

type InitInfo

type InitInfo struct {
	// Tag is the tag of the problem this initinfo corresponds to
	Tag string
	// ZeroAllocs is a list of the zero-value allocations of the struct.
	ZeroAllocs []ZeroAlloc
	// InvalidWrites is a mapping of the struct field to all the invalid writes
	// to that field.
	InvalidWrites map[*types.Var][]InvalidWrite
	// BadReinits is a list of bad reinitializations
	BadReinits []BadReinit
	// contains filtered or unexported fields
}

InitInfo is the initialization information for a struct.

type InvalidWrite

type InvalidWrite struct {
	// Got is the value actually written.
	Got ssa.Value
	// Want is the configured value that should have been written.
	Want ssa.Value
	// Instr is the instruction performing the write.
	Instr ssa.Instruction
	// Pos is the position of the instruction.
	Pos token.Position
}

InvalidWrite is a write to a field of the struct of value Got that is not the configured value (Want).

type ZeroAlloc

type ZeroAlloc struct {
	// Alloc is the allocation instruction.
	Alloc ssa.Instruction
	// Pos is the position of the instruction.
	Pos token.Position
}

ZeroAlloc is an empty (zero) allocation of a struct.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL