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, Element, AnyRef, Any
Ordering
  1. Alphabetic
  2. By Inheritance
Inherited
  1. DummyNodeImpl
  2. StoredNode
  3. Product
  4. Equals
  5. AbstractNode
  6. Node
  7. Element
  8. AnyRef
  9. Any
  1. Hide All
  2. Show All
Visibility
  1. Public
  2. Protected

Abstract Value Members

  1. abstract def addEdge(arg0: String, arg1: Node, arg2: <repeated...>[AnyRef]): Edge
    Definition Classes
    Node
    Annotations
    @transient()
  2. abstract def addEdgeSilent(arg0: String, arg1: Node, arg2: <repeated...>[AnyRef]): Unit
    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 out(arg0: <repeated...>[String]): Iterator[Node]
    Definition Classes
    Node
    Annotations
    @transient()
  8. 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 _parameterLinkIn: Iterator[StoredNode]
    Definition Classes
    StoredNode
  35. def _parameterLinkOut: Iterator[StoredNode]
    Definition Classes
    StoredNode
  36. def _postDominateIn: Iterator[StoredNode]
    Definition Classes
    StoredNode
  37. def _postDominateOut: Iterator[StoredNode]
    Definition Classes
    StoredNode
  38. def _reachingDefIn: Iterator[StoredNode]
    Definition Classes
    StoredNode
  39. def _reachingDefOut: Iterator[StoredNode]
    Definition Classes
    StoredNode
  40. def _receiverIn: Iterator[StoredNode]
    Definition Classes
    StoredNode
  41. def _receiverOut: Iterator[StoredNode]
    Definition Classes
    StoredNode
  42. def _refIn: Iterator[StoredNode]
    Definition Classes
    StoredNode
  43. def _refOut: Iterator[StoredNode]
    Definition Classes
    StoredNode
  44. def _sourceFileIn: Iterator[StoredNode]
    Definition Classes
    StoredNode
  45. def _sourceFileOut: Iterator[StoredNode]
    Definition Classes
    StoredNode
  46. def _taggedByIn: Iterator[StoredNode]
    Definition Classes
    StoredNode
  47. def _taggedByOut: Iterator[StoredNode]
    Definition Classes
    StoredNode
  48. def addEdge(arg0: String, arg1: Node, arg2: AnyRef*): Edge
  49. def addEdge(arg0: String, arg1: Node, arg2: Map[String, AnyRef]): Edge
    Definition Classes
    DummyNodeImpl → Node
  50. def addEdgeSilent(arg0: String, arg1: Node, arg2: AnyRef*): Unit
  51. def addEdgeSilent(arg0: String, arg1: Node, arg2: Map[String, AnyRef]): Unit
    Definition Classes
    DummyNodeImpl → Node
  52. final def asInstanceOf[T0]: T0
    Definition Classes
    Any
  53. def both(): Iterator[Node]
    Definition Classes
    DummyNodeImpl → Node
  54. def both(arg0: String*): Iterator[Node]
  55. def bothE(): Iterator[Edge]
    Definition Classes
    DummyNodeImpl → Node
  56. def bothE(arg0: String*): Iterator[Edge]
  57. def canEqual(that: Any): Boolean
    Definition Classes
    DummyNodeImpl → Equals
  58. def clone(): AnyRef
    Attributes
    protected[lang]
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.CloneNotSupportedException]) @native() @HotSpotIntrinsicCandidate()
  59. final def eq(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef
  60. def equals(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef → Any
  61. def fromNewNode(newNode: NewNode, mapping: (NewNode) => StoredNode): Unit
    Definition Classes
    StoredNode
  62. final def getClass(): Class[_ <: AnyRef]
    Definition Classes
    AnyRef → Any
    Annotations
    @native() @HotSpotIntrinsicCandidate()
  63. def graph(): Graph
    Definition Classes
    DummyNodeImpl → Element
  64. def hashCode(): Int
    Definition Classes
    AnyRef → Any
    Annotations
    @native() @HotSpotIntrinsicCandidate()
  65. def id(): Long
    Definition Classes
    DummyNodeImpl → Node
  66. def in(): Iterator[Node]
    Definition Classes
    DummyNodeImpl → Node
  67. def in(arg0: String*): Iterator[Node]
  68. def inE(): Iterator[Edge]
    Definition Classes
    DummyNodeImpl → Node
  69. def inE(arg0: String*): Iterator[Edge]
  70. final def isInstanceOf[T0]: Boolean
    Definition Classes
    Any
  71. def label: String
    Definition Classes
    DummyNodeImpl → AbstractNode → Element
  72. final def ne(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef
  73. final def notify(): Unit
    Definition Classes
    AnyRef
    Annotations
    @native() @HotSpotIntrinsicCandidate()
  74. final def notifyAll(): Unit
    Definition Classes
    AnyRef
    Annotations
    @native() @HotSpotIntrinsicCandidate()
  75. def out(): Iterator[Node]
    Definition Classes
    DummyNodeImpl → Node
  76. def out(arg0: String*): Iterator[Node]
  77. def outE(): Iterator[Edge]
    Definition Classes
    DummyNodeImpl → Node
  78. def outE(arg0: String*): Iterator[Edge]
  79. def productArity: Int
    Definition Classes
    DummyNodeImpl → Product
  80. def productElement(n: Int): Any
    Definition Classes
    DummyNodeImpl → Product
  81. def productElementLabel(n: Int): String
    Definition Classes
    DummyNodeImpl → StoredNode
  82. def productElementName(n: Int): String
    Definition Classes
    Product
  83. def productElementNames: Iterator[String]
    Definition Classes
    Product
  84. def productIterator: Iterator[Any]
    Definition Classes
    Product
  85. def productPrefix: String
    Definition Classes
    Product
  86. def propertiesMap(): Map[String, AnyRef]
    Definition Classes
    DummyNodeImpl → Element
  87. def property(arg0: String): AnyRef
    Definition Classes
    DummyNodeImpl → Element
  88. def property[A](arg0: PropertyKey[A]): A
    Definition Classes
    DummyNodeImpl → Element
  89. def property[A <: AnyRef](arg0: PropertyKey[A], arg1: A): A
    Definition Classes
    Element
  90. def property[A <: AnyRef](arg0: String, arg1: A): A
    Definition Classes
    Element
  91. def propertyDefaultValue(arg0: String): AnyRef
    Definition Classes
    Element
  92. def propertyKeys(): Set[String]
    Definition Classes
    DummyNodeImpl → Element
  93. def propertyOption[A](arg0: PropertyKey[A]): Optional[A]
    Definition Classes
    DummyNodeImpl → Element
  94. def propertyOption(arg0: String): Optional[AnyRef]
    Definition Classes
    DummyNodeImpl → Element
  95. def remove(): Unit
    Definition Classes
    DummyNodeImpl → Element
  96. def removeProperty(arg0: String): Unit
    Definition Classes
    DummyNodeImpl → Element
  97. def setProperty(arg0: String, arg1: AnyRef): Unit
    Definition Classes
    DummyNodeImpl → Element
  98. def setProperty[A](arg0: PropertyKey[A], arg1: A): Unit
    Definition Classes
    DummyNodeImpl → Element
  99. def setProperty(arg0: Property[_]): Unit
    Definition Classes
    DummyNodeImpl → Element
  100. final def synchronized[T0](arg0: => T0): T0
    Definition Classes
    AnyRef
  101. def toMap: Map[String, Any]
    Definition Classes
    StoredNode
  102. def toString(): String
    Definition Classes
    AnyRef → Any
  103. def underlying: Node
    Definition Classes
    StoredNode
  104. def valueMap: Map[String, AnyRef]
  105. final def wait(arg0: Long, arg1: Int): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.InterruptedException])
  106. final def wait(arg0: Long): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.InterruptedException]) @native()
  107. final def wait(): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.InterruptedException])

Deprecated Value Members

  1. def finalize(): Unit
    Attributes
    protected[lang]
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.Throwable]) @Deprecated
    Deprecated

Inherited from StoredNode

Inherited from Product

Inherited from Equals

Inherited from AbstractNode

Inherited from Node

Inherited from Element

Inherited from AnyRef

Inherited from Any

Ungrouped