analysis

package
v0.42.10 Latest Latest
Warning

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

Go to latest
Published: Apr 10, 2024 License: Apache-2.0 Imports: 10 Imported by: 9

Documentation

Index

Constants

This section is empty.

Variables

View Source
var InspectorAnalyzer = &Analyzer{
	Run: func(pass *Pass) interface{} {
		return ast.NewInspector(pass.Program.Program)
	},
}

Functions

This section is empty.

Types

type Analyzer

type Analyzer struct {
	Description string

	Run func(*Pass) interface{}

	// Requires is a set of analyzers that must run before this one.
	// This analyzer may inspect the outputs produced by each analyzer in Requires.
	// The graph over analyzers implied by Requires edges must be acyclic
	Requires []*Analyzer
}

Analyzer describes an analysis function and its options

type Config

type Config struct {
	// ResolveAddressContractNames is called to resolve the contract names of an address location
	ResolveAddressContractNames func(address common.Address) ([]string, error)
	// ResolveCode is called to resolve an import to its source code
	ResolveCode func(
		location common.Location,
		importingLocation common.Location,
		importRange ast.Range,
	) ([]byte, error)
	// Mode controls the level of information returned for each program
	Mode LoadMode
}

A Config specifies details about how programs should be loaded. The zero value is a valid configuration. Calls to Load do not modify this struct.

func NewSimpleConfig

func NewSimpleConfig(
	mode LoadMode,
	codes map[common.Location][]byte,
	contractNames map[common.Address][]string,
	resolveAddressContracts func(common.Address) (contracts map[string][]byte, err error),
) *Config

type Diagnostic

type Diagnostic struct {
	Location         common.Location
	Category         string
	Message          string
	SecondaryMessage string
	SuggestedFixes   []SuggestedFix
	ast.Range
}

func (Diagnostic) SuggestFixes added in v0.40.0

func (d Diagnostic) SuggestFixes(_ string) []SuggestedFix

type LoadMode

type LoadMode int

LoadMode controls the amount of detail to return when loading. The bits below can be combined to specify what information is required.

const (
	// NeedSyntax provides the AST.
	NeedSyntax LoadMode = 0

	// NeedTypes provides the elaboration.
	NeedTypes LoadMode = 1 << iota

	// NeedPositionInfo provides position information (e.g. occurrences).
	NeedPositionInfo

	// NeedExtendedElaboration provides an extended elaboration.
	NeedExtendedElaboration
)

type ParsingCheckingError

type ParsingCheckingError struct {
	// contains filtered or unexported fields
}

func (ParsingCheckingError) ChildErrors

func (e ParsingCheckingError) ChildErrors() []error

func (ParsingCheckingError) ImportLocation

func (e ParsingCheckingError) ImportLocation() common.Location

func (ParsingCheckingError) Unwrap

func (e ParsingCheckingError) Unwrap() error

type Pass

type Pass struct {
	Program *Program

	// Report reports a Diagnostic, a finding about a specific location
	// in the analyzed source code such as a potential mistake.
	// It may be called by the Analyzer.Run function.
	Report func(Diagnostic)

	// ResultOf provides the inputs to this analysis pass,
	// which are the corresponding results of its prerequisite analyzers.
	// The map keys are the elements of Analyzer.Requires.
	ResultOf map[*Analyzer]interface{}
}

Pass provides information to the Analyzer.Run function, which applies a specific analyzer to a single location.

type Program

type Program struct {
	Location    common.Location
	Program     *ast.Program
	Elaboration *sema.Elaboration
	Code        []byte
}

func (*Program) Run

func (program *Program) Run(analyzers []*Analyzer, report func(Diagnostic))

Run runs the given DAG of analyzers in parallel

type Programs

type Programs map[common.Location]*Program

func Load

func Load(config *Config, locations ...common.Location) (Programs, error)

func (Programs) Load

func (programs Programs) Load(config *Config, location common.Location) error

type SuggestedFix added in v0.39.6

type SuggestedFix = sema.SuggestedFix

type TextEdit added in v0.39.6

type TextEdit = sema.TextEdit

Jump to

Keyboard shortcuts

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