Skip to content
KuechA edited this page Apr 11, 2022 · 2 revisions

What is a Pass?

Passes get a prebuilt CPG that at least contains the CPG-AST and output a modified graph. Their purpose is to extend the syntactic representation of code with additional nodes and edges to represent the semantics of the program. Passes can be executed in sequence, where the output of the previous pass serves as input of the next pass.

Creating a new Pass

The user of the cpg library can implement her own passes. Each pass needs to extend the class Pass and implement its base function accept(TranslationResult result). The remaining structure of the pass is free to be designed by the implementer.

Registering a Pass

A newly created pass has to be registered with the TranslationManager through its builder by calling TranslationConfiguration.builder(). ... .registerPass(...).

Modifying a Pass

A preexisting pass can be modified by extending it and overwriting its functions. For this purpose, all member functions of existing library passes have the visibility protected. Depending on the modified pass, internal constructs have to be respected.

For example, the EvaluationOrderGraphPass uses an internal handle structure. When extending this pass, it is necessary to add handlers of new Node types to the internal handler map. If a developer needs to override an exisiting handler, the handle has to be implemented with the same signature to use the polymorphism feature. Additionally the mapping of node type -> handler needs to be replaced by a new entry node type -> overridden handler.

Clone this wiki locally