Skip to content

Architecture

Yuxin Wang edited this page Nov 28, 2023 · 5 revisions

For best performance and easier maintenance, NilAway consists of multiple levels of sub-analyzers that are all analysis.Analyzers, and they are connected by specifying dependencies (via Requires field) between them. Currently, the organization is as follows:

All the analyzers depend on config.Analyzer (config/config.go) to retrieve configurations.

The decoupling of error generation and error reporting logic makes it possible to apply custom error reporting to fit other needs. For example, it is possible to create another top-level analyzer nilaway-log that depends on the accumulation analyzer, which simply retrieves the NilAway errors and logs them to a local file or database for later auditing.

NilAway Analyzer

This is the top-level analyzer that simply reports the errors via analysis.Pass.Report.

Accumulation Analyzer

This analyzer collects the triggers from sub-analyzers, runs the inference algorithm, and returns the errors for higher-level analyzers.

Annotation Analyzer

Function Analyzer

This analyzer analyzes each function and creates triggers for it.

Anonymous Function Analyzer

This analyzer collects auxiliary information about function literals and reports to function analyzer.

Struct Field Analyzer

This analyzer collects auxiliary information about struct field accesses and reports to function analyzer.

Affiliation Analyzer

This analyzer creates triggers about interface-struct affiliations.

Global Analyzer

This analyzer creates triggers about global variables.

Config Analyzer

This analyzer does nothing but takes the Flags and makes the flags available for other sub-analyzers.