Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Requires to Analyzer struct to consume results from previously run analyzers #157

Open
sourya-deepsource opened this issue Mar 5, 2025 · 0 comments
Assignees
Labels
enhancement New feature or request
Milestone

Comments

@sourya-deepsource
Copy link
Contributor

sourya-deepsource commented Mar 5, 2025

type Analyzer struct {
	// Requires is a set of analyzers that must run successfully
	// before this one on a given package. This analyzer may inspect
	// the outputs produced by each analyzer in Requires.
	// The graph over analyzers implied by Requires edges must be acyclic.
	//
	// Requires establishes a "horizontal" dependency between
	// analysis passes (different analyzers, same package).
	Requires []*Analyzer
}

Requires analyzers may be run to compute scope trees, CFGs etc before analysis begins.

For the Run function of dependency analyzers to be able to return value, they must be able to specify the return type. For example, the following analyzer:

var ScopeTreeBuilder = &analysis.Analyzer{
	Run: func(pass *analysis.Pass) (interface{}, error) {
		// calculate scope tree
		// ......
		return scopeTree, nil
	},
}

In the above example, we need to know the concrete type of the value returned, so that we can use it. Thus, the struct needs a new field, ReturnType, of type reflect.Type.

type Analyzer struct {
	Requires []*Analyzer
	ReturnType reflect.Type
}
@sourya-deepsource sourya-deepsource added the enhancement New feature or request label Mar 5, 2025
@sourya-deepsource sourya-deepsource added this to the v0.5.0 milestone Mar 5, 2025
@sourya-deepsource sourya-deepsource self-assigned this Mar 5, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant