Skip to content

Commit 3c4440a

Browse files
authored
Add OFFSET and OFFSET_END properties to TYPE_DECL nodes. (#1751)
1 parent 162a50c commit 3c4440a

6 files changed

Lines changed: 192 additions & 29 deletions

File tree

domainClasses/src/main/generated/io/shiftleft/codepropertygraph/generated/NodeTypes.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,7 @@ set to the version of the specification ("1.1"). The language field indicates
191191
`LINE_NUMBER`, `COLUMN_NUMBER`, `LINE_NUMBER_END`, and `COLUMN_NUMBER_END` and
192192
the name of the source file is specified in `FILENAME`. An optional hash value
193193
MAY be calculated over the function contents and included in the `HASH` field.
194+
194195
The optional `OFFSET` and `OFFSET_END` specify the start
195196
and exclusive end position of the code belonging to a method within the corresponding
196197
`FILE` nodes `CONTENT` property.
@@ -298,6 +299,10 @@ same way an (actual) arguments provides concrete values for a parameter
298299
known to be an alias of another type (as for example introduced via the C
299300
`typedef` statement), the name of the alias is stored in `ALIAS_TYPE_FULL_NAME`.
300301
302+
The optional `OFFSET` and `OFFSET_END` specify the start
303+
and exclusive end position of the code belonging to a `TYPE_DECL` within the corresponding
304+
`FILE` nodes `CONTENT` property.
305+
301306
Finally, the fully qualified name of the program constructs that the type declaration
302307
is immediately contained in is stored in the `AST_PARENT_FULL_NAME` field
303308
and its type is indicated in the `AST_PARENT_TYPE` field to be one of

domainClasses/src/main/generated/io/shiftleft/codepropertygraph/generated/nodes/NewNodes.scala

Lines changed: 47 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -41768,6 +41768,8 @@ class NewTypeDecl extends NewNode with TypeDeclBase with AstNodeNew {
4176841768
type StoredType = TypeDecl
4176941769

4177041770
var order: scala.Int = -1: Int
41771+
var offsetEnd: Option[Integer] = None
41772+
var offset: Option[Integer] = None
4177141773
var name: String = "<empty>"
4177241774
var lineNumber: Option[Integer] = None
4177341775
var isExternal: Boolean = false
@@ -41795,6 +41797,8 @@ class NewTypeDecl extends NewNode with TypeDeclBase with AstNodeNew {
4179541797
newInstance.isExternal = this.isExternal
4179641798
newInstance.lineNumber = this.lineNumber
4179741799
newInstance.name = this.name
41800+
newInstance.offset = this.offset
41801+
newInstance.offsetEnd = this.offsetEnd
4179841802
newInstance.order = this.order
4179941803
newInstance.asInstanceOf[this.type]
4180041804
}
@@ -41860,6 +41864,20 @@ class NewTypeDecl extends NewNode with TypeDeclBase with AstNodeNew {
4186041864
this
4186141865
}
4186241866

41867+
def offset(value: Integer): this.type = {
41868+
this.offset = Option(value)
41869+
this
41870+
}
41871+
41872+
def offset(value: Option[Integer]): this.type = offset(value.orNull)
41873+
41874+
def offsetEnd(value: Integer): this.type = {
41875+
this.offsetEnd = Option(value)
41876+
this
41877+
}
41878+
41879+
def offsetEnd(value: Option[Integer]): this.type = offsetEnd(value.orNull)
41880+
4186341881
def order(value: scala.Int): this.type = {
4186441882
this.order = value
4186541883
this
@@ -41880,6 +41898,8 @@ class NewTypeDecl extends NewNode with TypeDeclBase with AstNodeNew {
4188041898
if (!((false) == isExternal)) { res += "IS_EXTERNAL" -> isExternal }
4188141899
lineNumber.map { value => res += "LINE_NUMBER" -> value }
4188241900
if (!(("<empty>") == name)) { res += "NAME" -> name }
41901+
offset.map { value => res += "OFFSET" -> value }
41902+
offsetEnd.map { value => res += "OFFSET_END" -> value }
4188341903
if (!((-1: Int) == order)) { res += "ORDER" -> order }
4188441904
res
4188541905
}
@@ -41895,39 +41915,43 @@ class NewTypeDecl extends NewNode with TypeDeclBase with AstNodeNew {
4189541915
override def productElement(n: Int): Any =
4189641916
n match {
4189741917
case 0 => this.order
41898-
case 1 => this.name
41899-
case 2 => this.lineNumber
41900-
case 3 => this.isExternal
41901-
case 4 => this.inheritsFromTypeFullName
41902-
case 5 => this.fullName
41903-
case 6 => this.filename
41904-
case 7 => this.columnNumber
41905-
case 8 => this.code
41906-
case 9 => this.astParentType
41907-
case 10 => this.astParentFullName
41908-
case 11 => this.aliasTypeFullName
41918+
case 1 => this.offsetEnd
41919+
case 2 => this.offset
41920+
case 3 => this.name
41921+
case 4 => this.lineNumber
41922+
case 5 => this.isExternal
41923+
case 6 => this.inheritsFromTypeFullName
41924+
case 7 => this.fullName
41925+
case 8 => this.filename
41926+
case 9 => this.columnNumber
41927+
case 10 => this.code
41928+
case 11 => this.astParentType
41929+
case 12 => this.astParentFullName
41930+
case 13 => this.aliasTypeFullName
4190941931
case _ => null
4191041932
}
4191141933

4191241934
override def productElementName(n: Int): String =
4191341935
n match {
4191441936
case 0 => "order"
41915-
case 1 => "name"
41916-
case 2 => "lineNumber"
41917-
case 3 => "isExternal"
41918-
case 4 => "inheritsFromTypeFullName"
41919-
case 5 => "fullName"
41920-
case 6 => "filename"
41921-
case 7 => "columnNumber"
41922-
case 8 => "code"
41923-
case 9 => "astParentType"
41924-
case 10 => "astParentFullName"
41925-
case 11 => "aliasTypeFullName"
41937+
case 1 => "offsetEnd"
41938+
case 2 => "offset"
41939+
case 3 => "name"
41940+
case 4 => "lineNumber"
41941+
case 5 => "isExternal"
41942+
case 6 => "inheritsFromTypeFullName"
41943+
case 7 => "fullName"
41944+
case 8 => "filename"
41945+
case 9 => "columnNumber"
41946+
case 10 => "code"
41947+
case 11 => "astParentType"
41948+
case 12 => "astParentFullName"
41949+
case 13 => "aliasTypeFullName"
4192641950
case _ => ""
4192741951
}
4192841952

4192941953
override def productPrefix = "NewTypeDecl"
41930-
override def productArity = 12
41954+
override def productArity = 14
4193141955

4193241956
override def canEqual(that: Any): Boolean = that != null && that.isInstanceOf[NewTypeDecl]
4193341957
}

domainClasses/src/main/generated/io/shiftleft/codepropertygraph/generated/nodes/TypeDecl.scala

Lines changed: 38 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ object TypeDecl {
2020
val IsExternal = "IS_EXTERNAL"
2121
val LineNumber = "LINE_NUMBER"
2222
val Name = "NAME"
23+
val Offset = "OFFSET"
24+
val OffsetEnd = "OFFSET_END"
2325
val Order = "ORDER"
2426
val all: Set[String] = Set(
2527
AliasTypeFullName,
@@ -33,6 +35,8 @@ object TypeDecl {
3335
IsExternal,
3436
LineNumber,
3537
Name,
38+
Offset,
39+
OffsetEnd,
3640
Order
3741
)
3842
val allAsJava: java.util.Set[String] = all.asJava
@@ -50,6 +54,8 @@ object TypeDecl {
5054
val IsExternal = new overflowdb.PropertyKey[Boolean]("IS_EXTERNAL")
5155
val LineNumber = new overflowdb.PropertyKey[Integer]("LINE_NUMBER")
5256
val Name = new overflowdb.PropertyKey[String]("NAME")
57+
val Offset = new overflowdb.PropertyKey[Integer]("OFFSET")
58+
val OffsetEnd = new overflowdb.PropertyKey[Integer]("OFFSET_END")
5359
val Order = new overflowdb.PropertyKey[scala.Int]("ORDER")
5460

5561
}
@@ -113,6 +119,8 @@ trait TypeDeclBase extends AbstractNode with AstNodeBase {
113119
def isExternal: Boolean
114120
def lineNumber: Option[Integer]
115121
def name: String
122+
def offset: Option[Integer]
123+
def offsetEnd: Option[Integer]
116124
def order: scala.Int
117125

118126
}
@@ -133,6 +141,8 @@ class TypeDecl(graph_4762: Graph, id_4762: Long /*cf https://github.com/scala/bu
133141
override def isExternal: Boolean = get().isExternal
134142
override def lineNumber: Option[Integer] = get().lineNumber
135143
override def name: String = get().name
144+
override def offset: Option[Integer] = get().offset
145+
override def offsetEnd: Option[Integer] = get().offsetEnd
136146
override def order: scala.Int = get().order
137147
override def propertyDefaultValue(propertyKey: String) =
138148
propertyKey match {
@@ -279,7 +289,9 @@ class TypeDecl(graph_4762: Graph, id_4762: Long /*cf https://github.com/scala/bu
279289
case 9 => "isExternal"
280290
case 10 => "lineNumber"
281291
case 11 => "name"
282-
case 12 => "order"
292+
case 12 => "offset"
293+
case 13 => "offsetEnd"
294+
case 14 => "order"
283295
}
284296

285297
override def productElement(n: Int): Any =
@@ -296,11 +308,13 @@ class TypeDecl(graph_4762: Graph, id_4762: Long /*cf https://github.com/scala/bu
296308
case 9 => isExternal
297309
case 10 => lineNumber
298310
case 11 => name
299-
case 12 => order
311+
case 12 => offset
312+
case 13 => offsetEnd
313+
case 14 => order
300314
}
301315

302316
override def productPrefix = "TypeDecl"
303-
override def productArity = 13
317+
override def productArity = 15
304318
}
305319

306320
class TypeDeclDb(ref: NodeRef[NodeDb]) extends NodeDb(ref) with StoredNode with AstNode with TypeDeclBase {
@@ -329,6 +343,10 @@ class TypeDeclDb(ref: NodeRef[NodeDb]) extends NodeDb(ref) with StoredNode with
329343
def lineNumber: Option[Integer] = Option(_lineNumber)
330344
private var _name: String = TypeDecl.PropertyDefaults.Name
331345
def name: String = _name
346+
private var _offset: Integer = null
347+
def offset: Option[Integer] = Option(_offset)
348+
private var _offsetEnd: Integer = null
349+
def offsetEnd: Option[Integer] = Option(_offsetEnd)
332350
private var _order: scala.Int = TypeDecl.PropertyDefaults.Order
333351
def order: scala.Int = _order
334352

@@ -348,6 +366,8 @@ class TypeDeclDb(ref: NodeRef[NodeDb]) extends NodeDb(ref) with StoredNode with
348366
properties.put("IS_EXTERNAL", isExternal)
349367
lineNumber.map { value => properties.put("LINE_NUMBER", value) }
350368
properties.put("NAME", name)
369+
offset.map { value => properties.put("OFFSET", value) }
370+
offsetEnd.map { value => properties.put("OFFSET_END", value) }
351371
properties.put("ORDER", order)
352372

353373
properties
@@ -369,6 +389,8 @@ class TypeDeclDb(ref: NodeRef[NodeDb]) extends NodeDb(ref) with StoredNode with
369389
if (!((false) == isExternal)) { properties.put("IS_EXTERNAL", isExternal) }
370390
lineNumber.map { value => properties.put("LINE_NUMBER", value) }
371391
if (!(("<empty>") == name)) { properties.put("NAME", name) }
392+
offset.map { value => properties.put("OFFSET", value) }
393+
offsetEnd.map { value => properties.put("OFFSET_END", value) }
372394
if (!((-1: Int) == order)) { properties.put("ORDER", order) }
373395

374396
properties
@@ -441,7 +463,9 @@ class TypeDeclDb(ref: NodeRef[NodeDb]) extends NodeDb(ref) with StoredNode with
441463
case 9 => "isExternal"
442464
case 10 => "lineNumber"
443465
case 11 => "name"
444-
case 12 => "order"
466+
case 12 => "offset"
467+
case 13 => "offsetEnd"
468+
case 14 => "order"
445469
}
446470

447471
override def productElement(n: Int): Any =
@@ -458,11 +482,13 @@ class TypeDeclDb(ref: NodeRef[NodeDb]) extends NodeDb(ref) with StoredNode with
458482
case 9 => isExternal
459483
case 10 => lineNumber
460484
case 11 => name
461-
case 12 => order
485+
case 12 => offset
486+
case 13 => offsetEnd
487+
case 14 => order
462488
}
463489

464490
override def productPrefix = "TypeDecl"
465-
override def productArity = 13
491+
override def productArity = 15
466492

467493
override def canEqual(that: Any): Boolean = that != null && that.isInstanceOf[TypeDeclDb]
468494

@@ -479,6 +505,8 @@ class TypeDeclDb(ref: NodeRef[NodeDb]) extends NodeDb(ref) with StoredNode with
479505
case "IS_EXTERNAL" => this._isExternal
480506
case "LINE_NUMBER" => this._lineNumber
481507
case "NAME" => this._name
508+
case "OFFSET" => this._offset
509+
case "OFFSET_END" => this._offsetEnd
482510
case "ORDER" => this._order
483511

484512
case _ => null
@@ -515,6 +543,8 @@ class TypeDeclDb(ref: NodeRef[NodeDb]) extends NodeDb(ref) with StoredNode with
515543
case "IS_EXTERNAL" => this._isExternal = value.asInstanceOf[Boolean]
516544
case "LINE_NUMBER" => this._lineNumber = value.asInstanceOf[Integer]
517545
case "NAME" => this._name = value.asInstanceOf[String]
546+
case "OFFSET" => this._offset = value.asInstanceOf[Integer]
547+
case "OFFSET_END" => this._offsetEnd = value.asInstanceOf[Integer]
518548
case "ORDER" => this._order = value.asInstanceOf[scala.Int]
519549

520550
case _ => PropertyErrorRegister.logPropertyErrorIfFirst(getClass, key)
@@ -545,6 +575,8 @@ class TypeDeclDb(ref: NodeRef[NodeDb]) extends NodeDb(ref) with StoredNode with
545575
this._isExternal = newNode.asInstanceOf[NewTypeDecl].isExternal
546576
this._lineNumber = newNode.asInstanceOf[NewTypeDecl].lineNumber.orNull
547577
this._name = newNode.asInstanceOf[NewTypeDecl].name
578+
this._offset = newNode.asInstanceOf[NewTypeDecl].offset.orNull
579+
this._offsetEnd = newNode.asInstanceOf[NewTypeDecl].offsetEnd.orNull
548580
this._order = newNode.asInstanceOf[NewTypeDecl].order
549581

550582
graph.indexManager.putIfIndexed("FULL_NAME", newNode.asInstanceOf[NewTypeDecl].fullName, this.ref)

domainClasses/src/main/generated/io/shiftleft/codepropertygraph/generated/traversal/TypeDecl.scala

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -527,6 +527,102 @@ class TypeDeclTraversalExtGen[NodeType <: TypeDecl](val traversal: Iterator[Node
527527
overflowdb.traversal.filter.StringPropertyFilter.regexpNotMultiple(traversal)(_.name, patterns)
528528
}
529529

530+
/** Traverse to offset property */
531+
def offset: Iterator[Integer] =
532+
traversal.flatMap(_.offset)
533+
534+
/** Traverse to nodes where the offset equals the given `value`
535+
*/
536+
def offset(value: Integer): Iterator[NodeType] =
537+
traversal.filter { node => node.offset.isDefined && node.offset.get == value }
538+
539+
/** Traverse to nodes where the offset equals at least one of the given `values`
540+
*/
541+
def offset(values: Integer*): Iterator[NodeType] = {
542+
val vset = values.toSet
543+
traversal.filter { node => node.offset.isDefined && vset.contains(node.offset.get) }
544+
}
545+
546+
/** Traverse to nodes where the offset is greater than the given `value`
547+
*/
548+
def offsetGt(value: Integer): Iterator[NodeType] =
549+
traversal.filter { node => node.offset.isDefined && node.offset.get > value }
550+
551+
/** Traverse to nodes where the offset is greater than or equal the given `value`
552+
*/
553+
def offsetGte(value: Integer): Iterator[NodeType] =
554+
traversal.filter { node => node.offset.isDefined && node.offset.get >= value }
555+
556+
/** Traverse to nodes where the offset is less than the given `value`
557+
*/
558+
def offsetLt(value: Integer): Iterator[NodeType] =
559+
traversal.filter { node => node.offset.isDefined && node.offset.get < value }
560+
561+
/** Traverse to nodes where the offset is less than or equal the given `value`
562+
*/
563+
def offsetLte(value: Integer): Iterator[NodeType] =
564+
traversal.filter { node => node.offset.isDefined && node.offset.get <= value }
565+
566+
/** Traverse to nodes where offset is not equal to the given `value`.
567+
*/
568+
def offsetNot(value: Integer): Iterator[NodeType] =
569+
traversal.filter { node => !node.offset.isDefined || node.offset.get != value }
570+
571+
/** Traverse to nodes where offset is not equal to any of the given `values`.
572+
*/
573+
def offsetNot(values: Integer*): Iterator[NodeType] = {
574+
val vset = values.toSet
575+
traversal.filter { node => !node.offset.isDefined || !vset.contains(node.offset.get) }
576+
}
577+
578+
/** Traverse to offsetEnd property */
579+
def offsetEnd: Iterator[Integer] =
580+
traversal.flatMap(_.offsetEnd)
581+
582+
/** Traverse to nodes where the offsetEnd equals the given `value`
583+
*/
584+
def offsetEnd(value: Integer): Iterator[NodeType] =
585+
traversal.filter { node => node.offsetEnd.isDefined && node.offsetEnd.get == value }
586+
587+
/** Traverse to nodes where the offsetEnd equals at least one of the given `values`
588+
*/
589+
def offsetEnd(values: Integer*): Iterator[NodeType] = {
590+
val vset = values.toSet
591+
traversal.filter { node => node.offsetEnd.isDefined && vset.contains(node.offsetEnd.get) }
592+
}
593+
594+
/** Traverse to nodes where the offsetEnd is greater than the given `value`
595+
*/
596+
def offsetEndGt(value: Integer): Iterator[NodeType] =
597+
traversal.filter { node => node.offsetEnd.isDefined && node.offsetEnd.get > value }
598+
599+
/** Traverse to nodes where the offsetEnd is greater than or equal the given `value`
600+
*/
601+
def offsetEndGte(value: Integer): Iterator[NodeType] =
602+
traversal.filter { node => node.offsetEnd.isDefined && node.offsetEnd.get >= value }
603+
604+
/** Traverse to nodes where the offsetEnd is less than the given `value`
605+
*/
606+
def offsetEndLt(value: Integer): Iterator[NodeType] =
607+
traversal.filter { node => node.offsetEnd.isDefined && node.offsetEnd.get < value }
608+
609+
/** Traverse to nodes where the offsetEnd is less than or equal the given `value`
610+
*/
611+
def offsetEndLte(value: Integer): Iterator[NodeType] =
612+
traversal.filter { node => node.offsetEnd.isDefined && node.offsetEnd.get <= value }
613+
614+
/** Traverse to nodes where offsetEnd is not equal to the given `value`.
615+
*/
616+
def offsetEndNot(value: Integer): Iterator[NodeType] =
617+
traversal.filter { node => !node.offsetEnd.isDefined || node.offsetEnd.get != value }
618+
619+
/** Traverse to nodes where offsetEnd is not equal to any of the given `values`.
620+
*/
621+
def offsetEndNot(values: Integer*): Iterator[NodeType] = {
622+
val vset = values.toSet
623+
traversal.filter { node => !node.offsetEnd.isDefined || !vset.contains(node.offsetEnd.get) }
624+
}
625+
530626
/** Traverse to order property */
531627
def order: Iterator[scala.Int] =
532628
traversal.map(_.order)

schema/src/main/scala/io/shiftleft/codepropertygraph/schema/Method.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ object Method extends SchemaBase {
6060
|`LINE_NUMBER`, `COLUMN_NUMBER`, `LINE_NUMBER_END`, and `COLUMN_NUMBER_END` and
6161
|the name of the source file is specified in `FILENAME`. An optional hash value
6262
|MAY be calculated over the function contents and included in the `HASH` field.
63+
|
6364
|The optional `OFFSET` and `OFFSET_END` specify the start
6465
|and exclusive end position of the code belonging to a method within the corresponding
6566
|`FILE` nodes `CONTENT` property.

0 commit comments

Comments
 (0)