The joeq Visitors

Central to the joeq analysis system is the concept of the Visitor. Visitors are described fully in the Design Patterns book by Gamma et al., but the concept is fairly straightforward. Each Visitor class has a number of methods of the form void visitX (X argument), which are called by the analysis machinery upon encountering objects of that type. Each pass is defined by one or more Visitor classes. The granularity of the analysis is determined by what kind of Visitor the class uses.

The Visitor classes are all actually interfaces. However, since some of the interfaces specify many, many methods, each includes a static nested class called EmptyVisitor that implements each method with a no-op. This allows one to override only those methods that your pass requires.

joeq.Class.jq_TypeVisitor

The jq_TypeVisitor visits arrays, primitives, and classes. For our purposes, the visitClass (jq_Class c) method is the only one we'll ever really need to override.

joeq.Class.jq_MethodVisitor

This Visitor can distinguish between static and virtual methods, or between various sorts of initializers. All visited Methods will invoke their most specific method, then the generic visitMethod. For our purposes, we'll almost never use anything other than visitMethod.

joeq.Compiler.Quad.ControlFlowGraphVisitor

The only method in this interface is void visitCFG(ControlFlowGraph cfg). It's easy to implement.

joeq.Compiler.Quad.BasicBlockVisitor

The only method in this interface is void visitBasicBlock(BasicBlock bb). It's also easy to implement.

joeq.Compiler.Quad.QuadVisitor

The QuadVisitor is the bulkiest of the Visitor classes. There is one method for each of the major Operator subclasses (the left column in the chart on the Quad Representation page), and a generic visitQuad. When this visits a Quad, it first calls the appropriate specific visit routine, and then calls visitQuad.

You will often use QuadVisitors in conjunction with QuadIterators or with the BasicBlock.visitQuads function. This will allow you to adjust evaluation order to react to control flow or intermediate analysis results.

<-- previous home next -->