Skip to content

refactor AbstractDetector to use the visitor pattern  #1751

Open
@0xalpharush

Description

@0xalpharush

Describe the desired feature

Right now, each detector implements its own ad-hoc approach to iterating over a compilation unit. This leaves the analysis author to understand and decide between contracts vs contracts_derived and functions vs functions_top_level vs functions_and_modifiers (even more if we consider inherited vs declared). While for some detectors there is a need for specialization, the vast majority of analyses could reuse a visitor from the AbstractDetector like visit_all_contracts_derived_functions. There are several benefits to this approach:

  1. These visitors require less understanding of the core API and can be clearly documented with guidance on when they should be used.
  2. It will make it easier to survey which detectors and analyze what and update changes to detectors en masse e.g. some detectors likely need to be update to support top level functions.
  3. I believe this would greatly impact performance positively. Rather than N detectors iterating over every comp. unit, contract, function, AbstractDetector would iterator over these and invoke each detector's visitor, reducing complexity.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions