@@ -12,89 +12,7 @@ import java.util.function.{BiConsumer, Supplier}
1212import scala .concurrent .duration .DurationLong
1313import scala .util .{Failure , Success , Try }
1414
15- /** Base class for CPG pass - a program, which receives an input graph and outputs a sequence of additive diff graphs.
16- * These diff graphs can be merged into the original graph ("applied"), they can be serialized into a binary format,
17- * and finally, they can be added to an existing cpg.bin.zip file.
18- *
19- * A pass is provided by inheriting from this class and implementing `run`, a method, which creates the sequence of
20- * diff graphs from an input graph.
21- *
22- * Overview of steps and their meaning:
23- *
24- * 1. Create: A sequence of diff graphs is created from the source graph 2. Apply: Each diff graph can be applied to
25- * the source graph 3. Serialize: After applying a diff graph, the diff graph can be serialized into a CPG overlay
26- * 4. Store: The CPG overlay can be stored in a serialized CPG.
27- *
28- * @param cpg
29- * the source CPG this pass traverses
30- */
31- @ deprecated(message = " Please use SimpleCpgPass as a replacement." , since = " v1.3.508" )
32- abstract class CpgPass (cpg : Cpg , outName : String = " " , keyPool : Option [KeyPool ] = None ) extends CpgPassBase {
33-
34- /** Main method of pass - to be implemented by child class
35- */
36- def run (): Iterator [DiffGraph ]
37-
38- /** Execute the pass and apply result to the underlying graph
39- */
40- override def createAndApply (): Unit =
41- withStartEndTimesLogged {
42- run().foreach(diffGraph => DiffGraph .Applier .applyDiff(diffGraph, cpg, undoable = false , keyPool))
43- }
44-
45- /** Execute and create a serialized overlay
46- * @param inverse
47- * invert the diffgraph before serializing
48- */
49- def createApplyAndSerialize (inverse : Boolean = false ): Iterator [GeneratedMessageV3 ] =
50- withStartEndTimesLogged {
51- val overlays = run().map { diffGraph =>
52- val appliedDiffGraph = DiffGraph .Applier .applyDiff(diffGraph, cpg, inverse, keyPool)
53- serialize(appliedDiffGraph, inverse)
54- }
55- overlays
56- }
57-
58- /** Run a CPG pass to create diff graphs, apply diff graphs, create corresponding overlays and add them to the
59- * serialized CPG. The name of the overlay is derived from the class name of the pass.
60- *
61- * @param serializedCpg
62- * the destination serialized CPG to add overlays to
63- * @param inverse
64- * invert the diffgraph before serializing
65- * @param prefix
66- * a prefix to add to the output name
67- */
68- override def createApplySerializeAndStore (
69- serializedCpg : SerializedCpg ,
70- inverse : Boolean = false ,
71- prefix : String = " "
72- ): Unit = {
73- if (serializedCpg.isEmpty) {
74- createAndApply()
75- } else {
76- val overlays = createApplyAndSerialize(inverse)
77- overlays.zipWithIndex.foreach {
78- case (overlay, index) => {
79- val name = generateOutFileName(prefix, outName, index)
80- store(overlay, name, serializedCpg)
81- }
82- }
83- }
84- }
85-
86- override def runWithBuilder (builder : BatchedUpdate .DiffGraphBuilder ): Int = {
87- var nParts = 0
88- for (diff <- run()) {
89- diff.convertToOdbStyle(cpg, builder)
90- nParts += 1
91- }
92- nParts
93- }
94-
95- }
96-
97- /* SimpleCpgPass is a possible replacement for CpgPass.
15+ /* SimpleCpgPass is a replacement for CpgPass.
9816 *
9917 * Instead of returning an Iterator[DiffGraph], the `run` fuction gets a DiffGraphBuilder as input, and can attach its
10018 * modifications to it (i.e. mutate the builder).
@@ -108,6 +26,26 @@ abstract class CpgPass(cpg: Cpg, outName: String = "", keyPool: Option[KeyPool]
10826 * Initialization and cleanup of external resources or large datastructures can be done in the `init()` and `finish()`
10927 * methods. This may be better than using the constructor or GC, because e.g. SCPG chains of passes construct
11028 * passes eagerly, and releases them only when the entire chain has run.
29+ *
30+ * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
31+ * // description of now-removed `CpgPass` class
32+ *
33+ * Base class for CPG pass - a program, which receives an input graph and outputs a sequence of additive diff graphs.
34+ * These diff graphs can be merged into the original graph ("applied"), they can be serialized into a binary format,
35+ * and finally, they can be added to an existing cpg.bin.zip file.
36+ *
37+ * A pass is provided by inheriting from this class and implementing `run`, a method, which creates the sequence of
38+ * diff graphs from an input graph.
39+ *
40+ * Overview of steps and their meaning:
41+ *
42+ * 1. Create: A sequence of diff graphs is created from the source graph 2. Apply: Each diff graph can be applied to
43+ * the source graph 3. Serialize: After applying a diff graph, the diff graph can be serialized into a CPG overlay
44+ * 4. Store: The CPG overlay can be stored in a serialized CPG.
45+ *
46+ * @param cpg
47+ * the source CPG this pass traverses
48+ *
11149 * */
11250
11351abstract class SimpleCpgPass (cpg : Cpg , outName : String = " " , keyPool : Option [KeyPool ] = None )
@@ -266,7 +204,7 @@ abstract class NewStyleCpgPassBase[T <: AnyRef] extends CpgPassBase {
266204}
267205
268206object CpgPassBase {
269- private val baseLogger : Logger = LoggerFactory .getLogger(classOf [CpgPass ])
207+ private val baseLogger : Logger = LoggerFactory .getLogger(classOf [CpgPassBase ])
270208}
271209
272210trait CpgPassBase {
0 commit comments