IDriver

interface IDriver: AutoCloseable, Any

The minimal interface for all graph drivers.

Methods

addVertex

abstract fun addVertex(v: NewNodeBuilder)

Inserts a vertex in the graph database.

Parameters

Name Description
v: NewNodeBuilder

the NewNodeBuilder to insert.

ReturnValue

Name Description
Unit

exists

abstract fun exists(v: NewNodeBuilder): Boolean

Checks if the given NewNodeBuilder exists in the database.

Parameters

Name Description
v: NewNodeBuilder

the NewNodeBuilder to check existence of.

ReturnValue

Name Description
Boolean

true if the vertex exists, false if otherwise.

exists

abstract fun exists(src: NewNodeBuilder, tgt: NewNodeBuilder, edge: String): Boolean

Checks if there exists a directed edge of the given label between two NewNodeBuilder vertices.

Parameters

Name Description
src: NewNodeBuilder

the source NewNodeBuilder.

tgt: NewNodeBuilder

the target NewNodeBuilder.

edge: String

the edge label.

ReturnValue

Name Description
Boolean

true if the edge exists, false if otherwise.

addEdge

abstract fun addEdge(src: NewNodeBuilder, tgt: NewNodeBuilder, edge: String)

Creates an edge with the given label between two NewNodeBuilder vertices in the graph database. If the given vertices are not already present in the database, they are created. If the edge already exists it wil not be recreated.

Parameters

Name Description
src: NewNodeBuilder

the source NewNodeBuilder.

tgt: NewNodeBuilder

the target NewNodeBuilder.

edge: String

the edge label.

ReturnValue

Name Description
Unit

clearGraph

abstract fun clearGraph(): IDriver

Clears the graph of all vertices and edges.

ReturnValue

Name Description
IDriver

itself as so to be chained in method calls.

getWholeGraph

abstract fun getWholeGraph(): Graph

Returns the whole CPG as a Graph object. Depending on the size of the CPG, this may be very memory intensive and usually a bad idea to call.

ReturnValue

Name Description
Graph

The whole CPG in the graph database.

getMethod

abstract fun getMethod(fullName: String, includeBody: Boolean): Graph

Given the full signature of a method, returns the subgraph of the method body.

Parameters

Name Description
fullName: String

The fully qualified name with signature e.g. interprocedural.basic.Basic4.f:int(int,int)

includeBody: Boolean

True if the body should be included, false if only method head should be included.

ReturnValue

Name Description
Graph

The Graph containing the method graph.

getMethodNames

abstract fun getMethodNames(): List<String>

Obtains all method full names in the CPG. These can be used in IDriver.getMethod.

ReturnValue

Name Description
List<String>

A list of all method full names.

getProgramStructure

abstract fun getProgramStructure(): Graph

Obtains all program structure related vertices. These are NAMESPACE_BLOCK, FILE, and TYPE_DECL vertices.

ReturnValue

Name Description
Graph

The Graph containing the program structure related sub-graphs.

getProgramTypeData

abstract fun getProgramTypeData(): Graph

Obtains all the type references, declarations, and arguments of a program to their children and referenced vertices.

ReturnValue

Name Description
Graph

The Graph containing the type data of the CPG.

getNeighbours

abstract fun getNeighbours(v: NewNodeBuilder): Graph

Given a vertex, returns a Graph representation of neighbouring vertices.

Parameters

Name Description
v: NewNodeBuilder

The source vertex.

ReturnValue

Name Description
Graph

The Graph representation of the source vertex and its neighbouring vertices.

deleteVertex

abstract fun deleteVertex(id: Long, label: String?)

Given a vertex, will remove it from the graph if present.

Parameters

Name Description
id: Long

The id to remove.

label: String?

The label, if known.

ReturnValue

Name Description
Unit

deleteMethod

abstract fun deleteMethod(fullName: String)

Given the full signature of a method, removes the method and its body from the graph.

Parameters

Name Description
fullName: String

The fully qualified name with signature e.g. interprocedural.basic.Basic4.f:int(int,int)

ReturnValue

Name Description
Unit

deleteEdge

abstract fun deleteEdge(src: NewNodeBuilder, tgt: NewNodeBuilder, edge: String)

Given two vertices and an edge label.

Parameters

Name Description
src: NewNodeBuilder

Outgoing vertex.

tgt: NewNodeBuilder

Incoming vertex.

edge: String

The edge label of the edge to remove.

ReturnValue

Name Description
Unit

updateVertexProperty

abstract fun updateVertexProperty(id: Long, label: String?, key: String, value: Any)

Updates a vertex's property if the node exists.

Parameters

Name Description
id: Long

The ID of the vertex to update.

label: String?

The label of the node, if known.

key: String

The key of the property to update.

value: Any

The updated value.

ReturnValue

Name Description
Unit

getMetaData

abstract fun getMetaData(): NewMetaDataBuilder?

Obtains the graph meta data information, if found.

ReturnValue

Name Description
NewMetaDataBuilder?

A NewMetaDataBuilder containing the meta data information, false if no information found.

getVerticesByProperty

abstract fun getVerticesByProperty(propertyKey: String, propertyValue: Any, label: String?): List<NewNodeBuilder>

Attempts to get vertex by it's fullname property.

Parameters

Name Description
propertyKey: String

The key to match with.

propertyValue: Any

The value to match with.

label: String?

An optional vertex label if known to further filter results by.

ReturnValue

Name Description
List<NewNodeBuilder>

A list of all vertices which match the predicates.

getPropertyFromVertices

abstract fun <T : Any> getPropertyFromVertices(propertyKey: String, label: String?): List<T>

Get a list of the results from a given property in vertices.

Parameters

Name Description
propertyKey: String

The property to retrieve.

label: String?

An optional vertex label if known to further filter results by.

ReturnValue

Name Description
List<T>

A list of the values from the given key using the specified type.