Packages

  • package root
    Definition Classes
    root
  • package io
    Definition Classes
    root
  • package shiftleft
    Definition Classes
    io
  • package semanticcpg

    Domain specific language for querying code property graphs

    Domain specific language for querying code property graphs

    This is the API reference for the CPG query language, a language to mine code for defects and vulnerabilities both interactively on a code analysis shell (REPL), or using non-interactive scripts.

    Queries written in the CPG query language express graph traversals (see https://en.wikipedia.org/wiki/Graph_traversal). Similar to the standard graph traversal language "Gremlin" (see https://en.wikipedia.org/wiki/Gremlin_(programming_language))) these traversals are formulated as sequences of primitive language elements referred to as "steps". You can think of a step as a small program, similar to a unix shell utility, however, instead of processing lines one by one, the step processes nodes of the graph.

    Starting a traversal

    All traversals begin by selecting a set of start nodes, e.g.,

    cpg.method

    will start the traversal at all methods, while

    cpg.local

    will start at all local variables. The complete list of starting points can be found at

    io.shiftleft.codepropertygraph.Cpg

    Lazy evaluation

    Queries are lazily evaluated, e.g., cpg.method creates a traversal which you can add more steps to. You can, for example, evaluate the traversal by converting it to a list:

    cpg.method.toList

    Since toList is such a common operation, we provide the shorthand l, meaning that

    cpg.method.l

    provides the same result as the former query.

    Properties

    Nodes have "properties", key-value pairs where keys are strings and values are primitive data types such as strings, integers, or Booleans. Properties of nodes can be selected based on their key, e.g.,

    cpg.method.name

    traverses to all method names. Nodes can also be filtered based on properties, e.g.,

    cpg.method.name(".*exec.*")

    traverse to all methods where name matches the regular expression ".*exec.*". You can see a complete list of properties by browsing to the API documentation of the corresponding step. For example, you can find the properties of method nodes at io.shiftleft.semanticcpg.language.types.structure.MethodTraversal.

    Side effects

    Useful if you want to mutate something outside the traversal, or simply debug it: This prints all typeDecl names as it traverses the graph and increments i for each one.

    var i = 0
    cpg.typeDecl.sideEffect{typeTemplate => println(typeTemplate.name); i = i + 1}.exec

    [advanced] Selecting multiple things from your traversal

    If you are interested in multiple things along the way of your traversal, you label anything using the as modulator, and use select at the end. Note that the compiler automatically derived the correct return type as a tuple of the labelled steps, in this case with two elements.

    cpg.method.as("method").definingTypeDecl.as("classDef").select.toList
    // return type: List[(Method, TypeDecl)]

    [advanced] For comprehensions

    You can always start a new traversal from a node, e.g.,

    val someMethod = cpg.method.head
    someMethod.start.parameter.toList

    You can use this e.g. in a for comprehension, which is (in this context) essentially an alternative way to select multiple intermediate things. It is more expressive, but more computationally expensive.

    val query = for {
      method <- cpg.method
      param <- method.start.parameter
    } yield (method.name, param.name)
    
    query.toList
    Definition Classes
    shiftleft
  • package testing
    Definition Classes
    semanticcpg
  • DummyNodeImpl
  • MockCpg

trait DummyNodeImpl extends Node with StoredNode

mixin trait for test nodes

Linear Supertypes
StoredNode, Product, Equals, AbstractNode, Node, NodeOrDetachedNode, Element, AnyRef, Any
Ordering
  1. Alphabetic
  2. By Inheritance
Inherited
  1. DummyNodeImpl
  2. StoredNode
  3. Product
  4. Equals
  5. AbstractNode
  6. Node
  7. NodeOrDetachedNode
  8. Element
  9. AnyRef
  10. Any
  1. Hide All
  2. Show All
Visibility
  1. Public
  2. Protected

Abstract Value Members

  1. abstract def addEdgeImpl(arg0: String, arg1: Node, arg2: <repeated...>[AnyRef]): Edge
    Attributes
    protected[overflowdb]
    Definition Classes
    Node
    Annotations
    @transient()
  2. abstract def addEdgeSilentImpl(arg0: String, arg1: Node, arg2: <repeated...>[AnyRef]): Unit
    Attributes
    protected[overflowdb]
    Definition Classes
    Node
    Annotations
    @transient()
  3. abstract def both(arg0: <repeated...>[String]): Iterator[Node]
    Definition Classes
    Node
    Annotations
    @transient()
  4. abstract def bothE(arg0: <repeated...>[String]): Iterator[Edge]
    Definition Classes
    Node
    Annotations
    @transient()
  5. abstract def in(arg0: <repeated...>[String]): Iterator[Node]
    Definition Classes
    Node
    Annotations
    @transient()
  6. abstract def inE(arg0: <repeated...>[String]): Iterator[Edge]
    Definition Classes
    Node
    Annotations
    @transient()
  7. abstract def label: String
    Definition Classes
    AbstractNode
  8. abstract def out(arg0: <repeated...>[String]): Iterator[Node]
    Definition Classes
    Node
    Annotations
    @transient()
  9. abstract def outE(arg0: <repeated...>[String]): Iterator[Edge]
    Definition Classes
    Node
    Annotations
    @transient()

Concrete Value Members

  1. final def !=(arg0: Any): Boolean
    Definition Classes
    AnyRef → Any
  2. final def ##: Int
    Definition Classes
    AnyRef → Any
  3. final def ==(arg0: Any): Boolean
    Definition Classes
    AnyRef → Any
  4. def _aliasOfIn: Iterator[StoredNode]
    Definition Classes
    StoredNode
  5. def _aliasOfOut: Iterator[StoredNode]
    Definition Classes
    StoredNode
  6. def _argumentIn: Iterator[StoredNode]
    Definition Classes
    StoredNode
  7. def _argumentOut: Iterator[StoredNode]
    Definition Classes
    StoredNode
  8. def _astIn: Iterator[StoredNode]
    Definition Classes
    StoredNode
  9. def _astOut: Iterator[StoredNode]
    Definition Classes
    StoredNode
  10. def _bindsIn: Iterator[StoredNode]
    Definition Classes
    StoredNode
  11. def _bindsOut: Iterator[StoredNode]
    Definition Classes
    StoredNode
  12. def _bindsToIn: Iterator[StoredNode]
    Definition Classes
    StoredNode
  13. def _bindsToOut: Iterator[StoredNode]
    Definition Classes
    StoredNode
  14. def _callIn: Iterator[StoredNode]
    Definition Classes
    StoredNode
  15. def _callOut: Iterator[StoredNode]
    Definition Classes
    StoredNode
  16. def _captureIn: Iterator[StoredNode]
    Definition Classes
    StoredNode
  17. def _captureOut: Iterator[StoredNode]
    Definition Classes
    StoredNode
  18. def _capturedByIn: Iterator[StoredNode]
    Definition Classes
    StoredNode
  19. def _capturedByOut: Iterator[StoredNode]
    Definition Classes
    StoredNode
  20. def _cdgIn: Iterator[StoredNode]
    Definition Classes
    StoredNode
  21. def _cdgOut: Iterator[StoredNode]
    Definition Classes
    StoredNode
  22. def _cfgIn: Iterator[StoredNode]
    Definition Classes
    StoredNode
  23. def _cfgOut: Iterator[StoredNode]
    Definition Classes
    StoredNode
  24. def _conditionIn: Iterator[StoredNode]
    Definition Classes
    StoredNode
  25. def _conditionOut: Iterator[StoredNode]
    Definition Classes
    StoredNode
  26. def _containsIn: Iterator[StoredNode]
    Definition Classes
    StoredNode
  27. def _containsOut: Iterator[StoredNode]
    Definition Classes
    StoredNode
  28. def _dominateIn: Iterator[StoredNode]
    Definition Classes
    StoredNode
  29. def _dominateOut: Iterator[StoredNode]
    Definition Classes
    StoredNode
  30. def _evalTypeIn: Iterator[StoredNode]
    Definition Classes
    StoredNode
  31. def _evalTypeOut: Iterator[StoredNode]
    Definition Classes
    StoredNode
  32. def _inheritsFromIn: Iterator[StoredNode]
    Definition Classes
    StoredNode
  33. def _inheritsFromOut: Iterator[StoredNode]
    Definition Classes
    StoredNode
  34. def _initializeFromDetached(arg0: DetachedNodeData, arg1: Function[DetachedNodeData, Node]): Unit
    Attributes
    protected[overflowdb]
    Definition Classes
    Node
  35. def _parameterLinkIn: Iterator[StoredNode]
    Definition Classes
    StoredNode
  36. def _parameterLinkOut: Iterator[StoredNode]
    Definition Classes
    StoredNode
  37. def _pointsToIn: Iterator[StoredNode]
    Definition Classes
    StoredNode
  38. def _pointsToOut: Iterator[StoredNode]
    Definition Classes
    StoredNode
  39. def _postDominateIn: Iterator[StoredNode]
    Definition Classes
    StoredNode
  40. def _postDominateOut: Iterator[StoredNode]
    Definition Classes
    StoredNode
  41. def _reachingDefIn: Iterator[StoredNode]
    Definition Classes
    StoredNode
  42. def _reachingDefOut: Iterator[StoredNode]
    Definition Classes
    StoredNode
  43. def _receiverIn: Iterator[StoredNode]
    Definition Classes
    StoredNode
  44. def _receiverOut: Iterator[StoredNode]
    Definition Classes
    StoredNode
  45. def _refIn: Iterator[StoredNode]
    Definition Classes
    StoredNode
  46. def _refOut: Iterator[StoredNode]
    Definition Classes
    StoredNode
  47. def _sourceFileIn: Iterator[StoredNode]
    Definition Classes
    StoredNode
  48. def _sourceFileOut: Iterator[StoredNode]
    Definition Classes
    StoredNode
  49. def _taggedByIn: Iterator[StoredNode]
    Definition Classes
    StoredNode
  50. def _taggedByOut: Iterator[StoredNode]
    Definition Classes
    StoredNode
  51. def addEdgeImpl(label: String, inNode: Node, keyValues: Map[String, AnyRef]): Edge
    Definition Classes
    DummyNodeImpl → Node
  52. def addEdgeImpl(label: String, inNode: Node, keyValues: Any*): Edge
  53. def addEdgeSilentImpl(label: String, inNode: Node, keyValues: Map[String, AnyRef]): Unit
    Definition Classes
    DummyNodeImpl → Node
  54. def addEdgeSilentImpl(label: String, inNode: Node, keyValues: Any*): Unit
  55. final def asInstanceOf[T0]: T0
    Definition Classes
    Any
  56. def both(): Iterator[Node]
    Definition Classes
    DummyNodeImpl → Node
  57. def both(arg0: String*): Iterator[Node]
  58. def bothE(): Iterator[Edge]
    Definition Classes
    DummyNodeImpl → Node
  59. def bothE(arg0: String*): Iterator[Edge]
  60. def canEqual(that: Any): Boolean
    Definition Classes
    DummyNodeImpl → Equals
  61. def clone(): AnyRef
    Attributes
    protected[lang]
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.CloneNotSupportedException]) @native() @HotSpotIntrinsicCandidate()
  62. final def eq(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef
  63. def equals(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef → Any
  64. def fromNewNode(newNode: NewNode, mapping: (NewNode) => StoredNode): Unit
    Definition Classes
    StoredNode
  65. final def getClass(): Class[_ <: AnyRef]
    Definition Classes
    AnyRef → Any
    Annotations
    @native() @HotSpotIntrinsicCandidate()
  66. def graph(): Graph
    Definition Classes
    DummyNodeImpl → Element
  67. def hashCode(): Int
    Definition Classes
    AnyRef → Any
    Annotations
    @native() @HotSpotIntrinsicCandidate()
  68. def id(): Long
    Definition Classes
    DummyNodeImpl → Node
  69. def in(): Iterator[Node]
    Definition Classes
    DummyNodeImpl → Node
  70. def in(arg0: String*): Iterator[Node]
  71. def inE(): Iterator[Edge]
    Definition Classes
    DummyNodeImpl → Node
  72. def inE(arg0: String*): Iterator[Edge]
  73. final def isInstanceOf[T0]: Boolean
    Definition Classes
    Any
  74. final def ne(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef
  75. final def notify(): Unit
    Definition Classes
    AnyRef
    Annotations
    @native() @HotSpotIntrinsicCandidate()
  76. final def notifyAll(): Unit
    Definition Classes
    AnyRef
    Annotations
    @native() @HotSpotIntrinsicCandidate()
  77. def out(): Iterator[Node]
    Definition Classes
    DummyNodeImpl → Node
  78. def out(arg0: String*): Iterator[Node]
  79. def outE(): Iterator[Edge]
    Definition Classes
    DummyNodeImpl → Node
  80. def outE(arg0: String*): Iterator[Edge]
  81. def productArity: Int
    Definition Classes
    DummyNodeImpl → Product
  82. def productElement(n: Int): Any
    Definition Classes
    DummyNodeImpl → Product
  83. def productElementLabel(n: Int): String
    Definition Classes
    DummyNodeImpl → StoredNode
  84. def productElementName(n: Int): String
    Definition Classes
    Product
  85. def productElementNames: Iterator[String]
    Definition Classes
    Product
  86. def productIterator: Iterator[Any]
    Definition Classes
    Product
  87. def productPrefix: String
    Definition Classes
    Product
  88. def propertiesMap(): Map[String, AnyRef]
    Definition Classes
    DummyNodeImpl → Element
  89. def property(arg0: String): AnyRef
    Definition Classes
    DummyNodeImpl → Element
  90. def property[A](arg0: PropertyKey[A]): A
    Definition Classes
    DummyNodeImpl → Element
  91. def property[A <: AnyRef](arg0: PropertyKey[A], arg1: A): A
    Definition Classes
    Element
  92. def property[A <: AnyRef](arg0: String, arg1: A): A
    Definition Classes
    Element
  93. def propertyDefaultValue(arg0: String): AnyRef
    Definition Classes
    Element
  94. def propertyKeys(): Set[String]
    Definition Classes
    DummyNodeImpl → Element
  95. def propertyOption[A](arg0: PropertyKey[A]): Optional[A]
    Definition Classes
    DummyNodeImpl → Element
  96. def propertyOption(arg0: String): Optional[AnyRef]
    Definition Classes
    DummyNodeImpl → Element
  97. def removeImpl(): Unit
    Definition Classes
    DummyNodeImpl → Element
  98. def removePropertyImpl(key: String): Unit
    Definition Classes
    DummyNodeImpl → Element
  99. def setPropertyImpl(property: Property[_]): Unit
    Definition Classes
    DummyNodeImpl → Element
  100. def setPropertyImpl[A](key: PropertyKey[A], value: A): Unit
    Definition Classes
    DummyNodeImpl → Element
  101. def setPropertyImpl(key: String, value: Any): Unit
    Definition Classes
    DummyNodeImpl → Element
  102. final def synchronized[T0](arg0: => T0): T0
    Definition Classes
    AnyRef
  103. def toMap: Map[String, Any]
    Definition Classes
    StoredNode
  104. def toString(): String
    Definition Classes
    AnyRef → Any
  105. def underlying: Node
    Definition Classes
    StoredNode
  106. def valueMap: Map[String, AnyRef]
  107. final def wait(arg0: Long, arg1: Int): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.InterruptedException])
  108. final def wait(arg0: Long): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.InterruptedException]) @native()
  109. final def wait(): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.InterruptedException])

Deprecated Value Members

  1. final def addEdge(arg0: String, arg1: Node, arg2: Map[String, AnyRef]): Edge
    Definition Classes
    Node
    Annotations
    @Deprecated
    Deprecated
  2. final def addEdge(arg0: String, arg1: Node, arg2: <repeated...>[AnyRef]): Edge
    Definition Classes
    Node
    Annotations
    @transient() @Deprecated
    Deprecated
  3. final def addEdgeSilent(arg0: String, arg1: Node, arg2: Map[String, AnyRef]): Unit
    Definition Classes
    Node
    Annotations
    @Deprecated
    Deprecated
  4. final def addEdgeSilent(arg0: String, arg1: Node, arg2: <repeated...>[AnyRef]): Unit
    Definition Classes
    Node
    Annotations
    @transient() @Deprecated
    Deprecated
  5. def finalize(): Unit
    Attributes
    protected[lang]
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.Throwable]) @Deprecated
    Deprecated
  6. final def remove(): Unit
    Definition Classes
    Element
    Annotations
    @Deprecated
    Deprecated
  7. final def removeProperty(arg0: String): Unit
    Definition Classes
    Element
    Annotations
    @Deprecated
    Deprecated
  8. final def setProperty(arg0: Property[_ <: AnyRef]): Unit
    Definition Classes
    Element
    Annotations
    @Deprecated
    Deprecated
  9. final def setProperty[A <: AnyRef](arg0: PropertyKey[A], arg1: A): Unit
    Definition Classes
    Element
    Annotations
    @Deprecated
    Deprecated
  10. final def setProperty(arg0: String, arg1: AnyRef): Unit
    Definition Classes
    Element
    Annotations
    @Deprecated
    Deprecated

Inherited from StoredNode

Inherited from Product

Inherited from Equals

Inherited from AbstractNode

Inherited from Node

Inherited from NodeOrDetachedNode

Inherited from Element

Inherited from AnyRef

Inherited from Any

Ungrouped