Skip to content

Commit

Permalink
generate traversal filter steps for 'property does not equal' (#158)
Browse files Browse the repository at this point in the history
  • Loading branch information
mpollmeier authored Mar 11, 2024
1 parent bc38b02 commit 7cbc49b
Show file tree
Hide file tree
Showing 10 changed files with 630 additions and 43 deletions.
15 changes: 15 additions & 0 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,21 @@ lazy val odbConvert = project
)
)

/** temporarily we still want to keep the generated files for the cpg domain in here,
* in order to be able to quickly see the differences in the generated files if we
* change the codegen
* n.b. relies on a manually published version of cpg-schema from https://github.com/ShiftLeftSecurity/codepropertygraph/tree/michael/flatgraph
*/
lazy val domainClassesGeneratorJoern = project
.in(file("domain-classes-generator-joern"))
.dependsOn(domainClassesGenerator_3)
.settings(
name := "domain-classes-generator-joern",
scalaVersion := scala3,
publish / skip := true,
libraryDependencies += "io.shiftleft" %% "codepropertygraph-schema" % "1.6.6+21-c6774ab5"
)

lazy val joernGenerated = project
.in(file("joern-generated"))
.dependsOn(core)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,20 @@ object CodeSnippets {
|}
|
|/**
| * Traverse to nodes where the $nameCamelCase is not equal to the given `value`
| * */
|def ${nameCamelCase}Not(value: $baseType): Iterator[NodeType] =
| traversal.filter{_.$nameCamelCase != value}
|
|/**
| * Traverse to nodes where the $nameCamelCase is not equal to any of the given `values`
| * */
|def ${nameCamelCase}Not(values: $baseType*): Iterator[NodeType] = {
| val vset = values.toSet
| traversal.filter{node => !vset.contains(node.$nameCamelCase)}
|}
|
|/**
| * Traverse to nodes where the $nameCamelCase is greater than the given `value`
| * */
|def ${nameCamelCase}Gt(value: $baseType): Iterator[NodeType] =
Expand Down Expand Up @@ -203,6 +217,20 @@ object CodeSnippets {
|}
|
|/**
| * Traverse to nodes where the $nameCamelCase is not equal to the given `value`
| * */
|def ${nameCamelCase}Not(value: $baseType): Iterator[NodeType] =
| traversal.filter{node => val tmp = node.$nameCamelCase; tmp.isEmpty || tmp.get != value}
|
|/**
| * Traverse to nodes where the $nameCamelCase does not equal any one of the given `values`
| * */
|def ${nameCamelCase}Not(values: $baseType*): Iterator[NodeType] = {
| val vset = values.toSet
| traversal.filter{node => val tmp = node.$nameCamelCase; tmp.isEmpty || !vset.contains(tmp.get)}
|}
|
|/**
| * Traverse to nodes where the $nameCamelCase is greater than the given `value`
| * */
|def ${nameCamelCase}Gt(value: $baseType): Iterator[NodeType] =
Expand Down Expand Up @@ -241,9 +269,22 @@ object CodeSnippets {
| * */
|def $nameCamelCase(values: $baseType*): Iterator[NodeType] = {
| val vset = values.toSet
| traversal.filter{node => !vset.contains(node.$nameCamelCase)}
| traversal.filter{node => vset.contains(node.$nameCamelCase)}
|}
|
|/**
| * Traverse to nodes where the $nameCamelCase does not equal the given `value`
| * */
|def ${nameCamelCase}Not(value: $baseType): Iterator[NodeType] =
| traversal.filter{_.$nameCamelCase != value}
|
|/**
| * Traverse to nodes where the $nameCamelCase does not equal any one of the given `values`
| * */
|def ${nameCamelCase}Not(values: $baseType*): Iterator[NodeType] = {
| val vset = values.toSet
| traversal.filter{node => !vset.contains(node.$nameCamelCase)}
|}
|""".stripMargin
}

Expand All @@ -259,7 +300,21 @@ object CodeSnippets {
| * */
|def $nameCamelCase(values: $baseType*): Iterator[NodeType] = {
| val vset = values.toSet
| traversal.filter{node => node.$nameCamelCase.isDefined && !vset.contains(node.$nameCamelCase.get)}
| traversal.filter{node => node.$nameCamelCase.isDefined && vset.contains(node.$nameCamelCase.get)}
|}
|
|/**
| * Traverse to nodes where the $nameCamelCase does not equal the given `value`
| * */
|def ${nameCamelCase}Not(value: $baseType): Iterator[NodeType] =
| traversal.filter{node => node.$nameCamelCase.empty || node.$nameCamelCase.get != value}
|
|/**
| * Traverse to nodes where the $nameCamelCase does not equal any one of the given `values`
| * */
|def ${nameCamelCase}Not(values: $baseType*): Iterator[NodeType] = {
| val vset = values.toSet
| traversal.filter{node => node.$nameCamelCase.empty || !vset.contains(node.$nameCamelCase.get)}
|}
|""".stripMargin
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -778,6 +778,14 @@ object Accessors {
case stored: nodes.StoredNode => new Access_Property_NAME(stored).name
case newNode: nodes.NewTypeDecl => newNode.name
}
def offset: Option[Int] = node match {
case stored: nodes.StoredNode => new Access_Property_OFFSET(stored).offset
case newNode: nodes.NewTypeDecl => newNode.offset
}
def offsetEnd: Option[Int] = node match {
case stored: nodes.StoredNode => new Access_Property_OFFSET_END(stored).offsetEnd
case newNode: nodes.NewTypeDecl => newNode.offsetEnd
}
}
final class Access_TypeParameterBase(val node: nodes.TypeParameterBase) extends AnyVal {
def name: String = node match {
Expand Down
Loading

0 comments on commit 7cbc49b

Please sign in to comment.