All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.shiftleft.codepropertygraph.schema.Operators.scala Maven / Gradle / Ivy

package io.shiftleft.codepropertygraph.schema

import flatgraph.schema.Property.ValueType
import flatgraph.schema._

object Operators extends SchemaBase {

  override def docIndex: Int = 17

  override def description: String =
    """
      |
      |""".stripMargin

  def apply(builder: SchemaBuilder) = new Schema(builder)

  class Schema(builder: SchemaBuilder) {
    implicit private val schemaInfo: SchemaInfo = SchemaInfo.forClass(getClass)

// constants
    /** TODO next time we have a breaking change, consider unifying the `operator` prefix - some entries have an `s`
      * appendix which should be dropped see https://github.com/joernio/joern/issues/1348 and
      * https://github.com/ShiftLeftSecurity/codepropertygraph/issues/1629
      */
    val operators = builder.addConstants(
      category = "Operators",
      Constant(name = "addition", value = ".addition", valueType = ValueType.String, comment = ""),
      Constant(name = "subtraction", value = ".subtraction", valueType = ValueType.String, comment = ""),
      Constant(
        name = "multiplication",
        value = ".multiplication",
        valueType = ValueType.String,
        comment = ""
      ),
      Constant(name = "division", value = ".division", valueType = ValueType.String, comment = ""),
      Constant(
        name = "exponentiation",
        value = ".exponentiation",
        valueType = ValueType.String,
        comment = ""
      ),
      Constant(name = "modulo", value = ".modulo", valueType = ValueType.String, comment = ""),
      Constant(name = "shiftLeft", value = ".shiftLeft", valueType = ValueType.String, comment = ""),
      Constant(
        name = "logicalShiftRight",
        value = ".logicalShiftRight",
        valueType = ValueType.String,
        comment = "Shift right padding with zeros"
      ),
      Constant(
        name = "arithmeticShiftRight",
        value = ".arithmeticShiftRight",
        valueType = ValueType.String,
        comment = "Shift right preserving the sign"
      ),
      Constant(name = "not", value = ".not", valueType = ValueType.String, comment = ""),
      Constant(name = "and", value = ".and", valueType = ValueType.String, comment = ""),
      Constant(name = "or", value = ".or", valueType = ValueType.String, comment = ""),
      Constant(name = "xor", value = ".xor", valueType = ValueType.String, comment = ""),
      Constant(
        name = "assignmentPlus",
        value = ".assignmentPlus",
        valueType = ValueType.String,
        comment = ""
      ),
      Constant(
        name = "assignmentMinus",
        value = ".assignmentMinus",
        valueType = ValueType.String,
        comment = ""
      ),
      Constant(
        name = "assignmentMultiplication",
        value = ".assignmentMultiplication",
        valueType = ValueType.String,
        comment = ""
      ),
      Constant(
        name = "assignmentDivision",
        value = ".assignmentDivision",
        valueType = ValueType.String,
        comment = ""
      ),
      Constant(
        name = "assignmentExponentiation",
        value = ".assignmentExponentiation",
        valueType = ValueType.String,
        comment = ""
      ),
      Constant(
        name = "assignmentModulo",
        value = ".assignmentModulo",
        valueType = ValueType.String,
        comment = ""
      ),
      Constant(
        name = "assignmentShiftLeft",
        value = ".assignmentShiftLeft",
        valueType = ValueType.String,
        comment = ""
      ),
      Constant(
        name = "assignmentLogicalShiftRight",
        value = ".assignmentLogicalShiftRight",
        valueType = ValueType.String,
        comment = ""
      ),
      Constant(
        name = "assignmentArithmeticShiftRight",
        value = ".assignmentArithmeticShiftRight",
        valueType = ValueType.String,
        comment = ""
      ),
      Constant(name = "assignmentAnd", value = ".assignmentAnd", valueType = ValueType.String, comment = ""),
      Constant(name = "assignmentOr", value = ".assignmentOr", valueType = ValueType.String, comment = ""),
      Constant(name = "assignmentXor", value = ".assignmentXor", valueType = ValueType.String, comment = ""),
      Constant(
        name = "arrayInitializer",
        value = ".arrayInitializer",
        valueType = ValueType.String,
        comment = ""
      ),
      Constant(name = "assignment", value = ".assignment", valueType = ValueType.String, comment = ""),
      Constant(name = "minus", value = ".minus", valueType = ValueType.String, comment = "E.g. `a = -b`"),
      Constant(name = "plus", value = ".plus", valueType = ValueType.String, comment = "E.g. `a = +b`"),
      Constant(name = "preIncrement", value = ".preIncrement", valueType = ValueType.String, comment = ""),
      Constant(name = "preDecrement", value = ".preDecrement", valueType = ValueType.String, comment = ""),
      Constant(name = "postIncrement", value = ".postIncrement", valueType = ValueType.String, comment = ""),
      Constant(name = "postDecrement", value = ".postDecrement", valueType = ValueType.String, comment = ""),
      Constant(name = "logicalNot", value = ".logicalNot", valueType = ValueType.String, comment = ""),
      Constant(name = "logicalOr", value = ".logicalOr", valueType = ValueType.String, comment = ""),
      Constant(name = "logicalAnd", value = ".logicalAnd", valueType = ValueType.String, comment = ""),
      Constant(name = "equals", value = ".equals", valueType = ValueType.String, comment = ""),
      Constant(name = "notEquals", value = ".notEquals", valueType = ValueType.String, comment = ""),
      Constant(name = "greaterThan", value = ".greaterThan", valueType = ValueType.String, comment = ""),
      Constant(name = "lessThan", value = ".lessThan", valueType = ValueType.String, comment = ""),
      Constant(
        name = "greaterEqualsThan",
        value = ".greaterEqualsThan",
        valueType = ValueType.String,
        comment = ""
      ),
      Constant(
        name = "lessEqualsThan",
        value = ".lessEqualsThan",
        valueType = ValueType.String,
        comment = ""
      ),
      Constant(name = "instanceOf", value = ".instanceOf", valueType = ValueType.String, comment = ""),
      Constant(
        name = "memberAccess",
        value = ".memberAccess",
        valueType = ValueType.String,
        comment = "Deprecated. Formerly in C: `a.b` but not! in Java"
      ),
      Constant(
        name = "indirectMemberAccess",
        value = ".indirectMemberAccess",
        valueType = ValueType.String,
        comment = "Deprecated. Formerly in C: `a->b` and `a.b` in Java"
      ),
      Constant(
        name = "computedMemberAccess",
        value = ".computedMemberAccess",
        valueType = ValueType.String,
        comment = "Deprecated. Formerly in C: `a[b]` but not! in Java"
      ),
      Constant(
        name = "indirectComputedMemberAccess",
        value = ".indirectComputedMemberAccess",
        valueType = ValueType.String,
        comment = "Deprecated. Formerly in C++: `a->*b` and a[b] in Java"
      ),
      Constant(
        name = "indirection",
        value = ".indirection",
        valueType = ValueType.String,
        comment =
          "Accesses through a pointer (load/store), i.e. dereferences it. Typically the star-operator in C/C++. Pairs of addressOf and indirection operators cancel each other. Handling of this operator is special-cased in the back-end"
      ),
      Constant(
        name = "delete",
        value = ".delete",
        valueType = ValueType.String,
        comment = "Deletes a property from a namespace. E.g. `a=3; delete a; a == undefined;"
      ),
      Constant(
        name = "conditional",
        value = ".conditional",
        valueType = ValueType.String,
        comment = "E.g. `a ? consequent : alternate`. In future probably also used for if statements"
      ),
      Constant(
        name = "elvis",
        value = ".elvis",
        valueType = ValueType.String,
        comment =
          "E.g. `x = f() ?: g()`. A binary operator that returns its first operand if that operand evaluates to a true value, and otherwise evaluates and returns its second operand."
      ),
      Constant(
        name = "cast",
        value = ".cast",
        valueType = ValueType.String,
        comment = "Type casts of any sort"
      ),
      Constant(
        name = "compare",
        value = ".compare",
        valueType = ValueType.String,
        comment =
          "Comparison between two arguments with the results: 0 == equal, negative == left < right, positive == left > right"
      ),
      Constant(
        name = "addressOf",
        value = ".addressOf",
        valueType = ValueType.String,
        comment =
          "Returns the address of a given object. Pairs of addressOf and indirection operators cancel each other. Handling of this operator is special-cased in the back-end"
      ),
      Constant(
        name = "sizeOf",
        value = ".sizeOf",
        valueType = ValueType.String,
        comment = "Returns the size of a given object"
      ),
      Constant(
        name = "fieldAccess",
        value = ".fieldAccess",
        valueType = ValueType.String,
        comment =
          "Returns or sets a field/member of a struct/class. Typically, the dot-operator. In terms of CPG, the first argument is the struct/class and the second argument is either a FIELD_IDENTIFIER node, a LITERAL node or an arbitrary expression. If it is a FIELD_IDENTIFIER, then the string contained in the CANONICAL_NAME field of this FIELD_IDENTIFIER node selects which field/member is accessed. If it is a LITERAL node, then its CODE selects which field/member is selected. In any other case the access is considered unpredictable by the backend, and we overtaint. indexAccess and fieldAccess live in the same space, such that e.g. obj.field and obj[\"field\"] refer to the same target (as is correct in e.g. javascript). Handling of this operator is special-cased in the back-end"
      ),
      Constant(
        name = "indirectFieldAccess",
        value = ".indirectFieldAccess",
        valueType = ValueType.String,
        comment =
          "Accesses (loads/stores) to a field/member through a pointer to a struct/class. Typically, C/C++ arrow-operator. The field selection works the same way as for fieldAccess. For the sake of data-flow tracking, this is the same as first dereferencing the pointer and then accessing the field. Handling of this operator is special-cased in the back-end"
      ),
      Constant(
        name = "indexAccess",
        value = ".indexAccess",
        valueType = ValueType.String,
        comment =
          "Accesses a container (e.g. array or associative array / dict / map) at an index. The index selection works the same way as for fieldAccess. Handling of this operator is special-cased in the back-end"
      ),
      Constant(
        name = "indirectIndexAccess",
        value = ".indirectIndexAccess",
        valueType = ValueType.String,
        comment =
          "Accesses an element of an Array through a pointer. The index selection works similar as for fieldAccess: However, the index must be an integer. If the second argument is a FIELD_ACCESS resp. LITERAL then its CANONICAL_NAME resp. CODE field is parsed as an integer; on parsing failure, the access is considered unpredictable and we overtaint. This is equivalent to a pointerShift followed by an indirection. This operator is currently only used by C-style languages. This behavior allows the backend to infer that ptr[0] and *ptr refer to the same object. Handling of this operator is special-cased in the back-end"
      ),
      Constant(
        name = "pointerShift",
        value = ".pointerShift",
        valueType = ValueType.String,
        comment =
          "Shifts a pointer. In terms of CPG, the first argument is the pointer and the second argument is the index. The index selection works the same way as for indirectIndexAccess. This operator is currently only used directly by the LLVM language, but it is also used internally for C. For example, pointerShift(ptr, 7) is equivalent to &(ptr[7]). Handling of this operator is special-cased in the back-end"
      ),
      Constant(
        name = "getElementPtr",
        value = ".getElementPtr",
        valueType = ValueType.String,
        comment =
          "Derives a pointer to a field of a struct from a pointer to the entire struct. This corresponds to the C idiom &(ptr->field), which does not access memory. The field selection works the same way as for fieldAccess. This operator is currently only used directly by the LLVM language. Handling of this operator is special-cased in the back-end"
      ),
      Constant(
        name = "formatString",
        value = ".formatString",
        valueType = ValueType.String,
        comment = "Defines a string literal which can replace containing expressions with their values."
      ),
      Constant(
        name = "formattedValue",
        value = ".formattedValue",
        valueType = ValueType.String,
        comment = "Replaces an expression with its string value."
      ),
      Constant(
        name = "range",
        value = ".range",
        valueType = ValueType.String,
        comment = "Defines a range of values, e.g. `for (i in 1..10) print(i)`."
      ),
      Constant(
        name = "in",
        value = ".in",
        valueType = ValueType.String,
        comment = "Checks the existence of a variable in a range or collection, e.g. `for (i in 1..10) print(i)`."
      ),
      Constant(
        name = "notIn",
        value = ".notIn",
        valueType = ValueType.String,
        comment = "Checks the non-existence of a variable in a range or collection, e.g. `print(5 not in [1, 2, 3, 4])`"
      ),
      Constant(
        name = "is",
        value = ".is",
        valueType = ValueType.String,
        comment = "Checks whether a variable is of a given type"
      ),
      Constant(
        name = "isNot",
        value = ".isNot",
        valueType = ValueType.String,
        comment = "Checks whether a variable is not of a given type"
      ),
      Constant(
        name = "notNullAssert",
        value = ".notNullAssert",
        valueType = ValueType.String,
        comment = "Converts any value to a not-null type"
      ),
      Constant(
        name = "lengthOf",
        value = ".lengthOf",
        valueType = ValueType.String,
        comment =
          "Returns the length of the given collection e.g. (new int[]{ 1, 2, 3 }).length in Java or len([1, 2, 3]) in Python"
      ),
      Constant(
        name = "safeNavigation",
        value = ".safeNavigation",
        valueType = ValueType.String,
        comment = "Returns null if the first operator is null, otherwise performs a dereferencing operation"
      ),
      Constant(
        name = "tryCatch",
        value = ".tryCatch",
        valueType = ValueType.String,
        comment =
          "Returns either the last expression in the `try`-block, or the last expression in one of the `catch`/`except`-blocks. The contents of the `finally`-block are ignored."
      ),
      Constant(
        name = "alloc",
        value = ".alloc",
        valueType = ValueType.String,
        comment = "Allocates memory for an object of a specific type"
      )
    )

  }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy