analysis

package
v0.25.2 Latest Latest
Warning

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

Go to latest
Published: Sep 20, 2022 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 {
	// Mode controls the level of information returned for each program.
	Mode LoadMode

	// 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,
	) (string, error)
}

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]string,
	contractNames map[common.Address][]string,
	resolveAddressContracts func(common.Address) (contracts map[string]string, err error),
) *Config

type Diagnostic

type Diagnostic struct {
	ast.Range
	Location         common.Location
	Category         string // optional
	Message          string
	SecondaryMessage string // optional
}

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
)

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
	Code        string
	Program     *ast.Program
	Elaboration *sema.Elaboration
}

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

Jump to

Keyboard shortcuts

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