Skip to content

Commit

Permalink
Add OFFSET and OFFSET_END properties to TYPE_DECL nodes. (#1751)
Browse files Browse the repository at this point in the history
  • Loading branch information
ml86 authored Jan 23, 2024
1 parent 162a50c commit 3c4440a
Show file tree
Hide file tree
Showing 6 changed files with 192 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,7 @@ set to the version of the specification ("1.1"). The language field indicates
`LINE_NUMBER`, `COLUMN_NUMBER`, `LINE_NUMBER_END`, and `COLUMN_NUMBER_END` and
the name of the source file is specified in `FILENAME`. An optional hash value
MAY be calculated over the function contents and included in the `HASH` field.
The optional `OFFSET` and `OFFSET_END` specify the start
and exclusive end position of the code belonging to a method within the corresponding
`FILE` nodes `CONTENT` property.
Expand Down Expand Up @@ -298,6 +299,10 @@ same way an (actual) arguments provides concrete values for a parameter
known to be an alias of another type (as for example introduced via the C
`typedef` statement), the name of the alias is stored in `ALIAS_TYPE_FULL_NAME`.
The optional `OFFSET` and `OFFSET_END` specify the start
and exclusive end position of the code belonging to a `TYPE_DECL` within the corresponding
`FILE` nodes `CONTENT` property.
Finally, the fully qualified name of the program constructs that the type declaration
is immediately contained in is stored in the `AST_PARENT_FULL_NAME` field
and its type is indicated in the `AST_PARENT_TYPE` field to be one of
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41768,6 +41768,8 @@ class NewTypeDecl extends NewNode with TypeDeclBase with AstNodeNew {
type StoredType = TypeDecl

var order: scala.Int = -1: Int
var offsetEnd: Option[Integer] = None
var offset: Option[Integer] = None
var name: String = "<empty>"
var lineNumber: Option[Integer] = None
var isExternal: Boolean = false
Expand Down Expand Up @@ -41795,6 +41797,8 @@ class NewTypeDecl extends NewNode with TypeDeclBase with AstNodeNew {
newInstance.isExternal = this.isExternal
newInstance.lineNumber = this.lineNumber
newInstance.name = this.name
newInstance.offset = this.offset
newInstance.offsetEnd = this.offsetEnd
newInstance.order = this.order
newInstance.asInstanceOf[this.type]
}
Expand Down Expand Up @@ -41860,6 +41864,20 @@ class NewTypeDecl extends NewNode with TypeDeclBase with AstNodeNew {
this
}

def offset(value: Integer): this.type = {
this.offset = Option(value)
this
}

def offset(value: Option[Integer]): this.type = offset(value.orNull)

def offsetEnd(value: Integer): this.type = {
this.offsetEnd = Option(value)
this
}

def offsetEnd(value: Option[Integer]): this.type = offsetEnd(value.orNull)

def order(value: scala.Int): this.type = {
this.order = value
this
Expand All @@ -41880,6 +41898,8 @@ class NewTypeDecl extends NewNode with TypeDeclBase with AstNodeNew {
if (!((false) == isExternal)) { res += "IS_EXTERNAL" -> isExternal }
lineNumber.map { value => res += "LINE_NUMBER" -> value }
if (!(("<empty>") == name)) { res += "NAME" -> name }
offset.map { value => res += "OFFSET" -> value }
offsetEnd.map { value => res += "OFFSET_END" -> value }
if (!((-1: Int) == order)) { res += "ORDER" -> order }
res
}
Expand All @@ -41895,39 +41915,43 @@ class NewTypeDecl extends NewNode with TypeDeclBase with AstNodeNew {
override def productElement(n: Int): Any =
n match {
case 0 => this.order
case 1 => this.name
case 2 => this.lineNumber
case 3 => this.isExternal
case 4 => this.inheritsFromTypeFullName
case 5 => this.fullName
case 6 => this.filename
case 7 => this.columnNumber
case 8 => this.code
case 9 => this.astParentType
case 10 => this.astParentFullName
case 11 => this.aliasTypeFullName
case 1 => this.offsetEnd
case 2 => this.offset
case 3 => this.name
case 4 => this.lineNumber
case 5 => this.isExternal
case 6 => this.inheritsFromTypeFullName
case 7 => this.fullName
case 8 => this.filename
case 9 => this.columnNumber
case 10 => this.code
case 11 => this.astParentType
case 12 => this.astParentFullName
case 13 => this.aliasTypeFullName
case _ => null
}

override def productElementName(n: Int): String =
n match {
case 0 => "order"
case 1 => "name"
case 2 => "lineNumber"
case 3 => "isExternal"
case 4 => "inheritsFromTypeFullName"
case 5 => "fullName"
case 6 => "filename"
case 7 => "columnNumber"
case 8 => "code"
case 9 => "astParentType"
case 10 => "astParentFullName"
case 11 => "aliasTypeFullName"
case 1 => "offsetEnd"
case 2 => "offset"
case 3 => "name"
case 4 => "lineNumber"
case 5 => "isExternal"
case 6 => "inheritsFromTypeFullName"
case 7 => "fullName"
case 8 => "filename"
case 9 => "columnNumber"
case 10 => "code"
case 11 => "astParentType"
case 12 => "astParentFullName"
case 13 => "aliasTypeFullName"
case _ => ""
}

override def productPrefix = "NewTypeDecl"
override def productArity = 12
override def productArity = 14

override def canEqual(that: Any): Boolean = that != null && that.isInstanceOf[NewTypeDecl]
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ object TypeDecl {
val IsExternal = "IS_EXTERNAL"
val LineNumber = "LINE_NUMBER"
val Name = "NAME"
val Offset = "OFFSET"
val OffsetEnd = "OFFSET_END"
val Order = "ORDER"
val all: Set[String] = Set(
AliasTypeFullName,
Expand All @@ -33,6 +35,8 @@ object TypeDecl {
IsExternal,
LineNumber,
Name,
Offset,
OffsetEnd,
Order
)
val allAsJava: java.util.Set[String] = all.asJava
Expand All @@ -50,6 +54,8 @@ object TypeDecl {
val IsExternal = new overflowdb.PropertyKey[Boolean]("IS_EXTERNAL")
val LineNumber = new overflowdb.PropertyKey[Integer]("LINE_NUMBER")
val Name = new overflowdb.PropertyKey[String]("NAME")
val Offset = new overflowdb.PropertyKey[Integer]("OFFSET")
val OffsetEnd = new overflowdb.PropertyKey[Integer]("OFFSET_END")
val Order = new overflowdb.PropertyKey[scala.Int]("ORDER")

}
Expand Down Expand Up @@ -113,6 +119,8 @@ trait TypeDeclBase extends AbstractNode with AstNodeBase {
def isExternal: Boolean
def lineNumber: Option[Integer]
def name: String
def offset: Option[Integer]
def offsetEnd: Option[Integer]
def order: scala.Int

}
Expand All @@ -133,6 +141,8 @@ class TypeDecl(graph_4762: Graph, id_4762: Long /*cf https://github.com/scala/bu
override def isExternal: Boolean = get().isExternal
override def lineNumber: Option[Integer] = get().lineNumber
override def name: String = get().name
override def offset: Option[Integer] = get().offset
override def offsetEnd: Option[Integer] = get().offsetEnd
override def order: scala.Int = get().order
override def propertyDefaultValue(propertyKey: String) =
propertyKey match {
Expand Down Expand Up @@ -279,7 +289,9 @@ class TypeDecl(graph_4762: Graph, id_4762: Long /*cf https://github.com/scala/bu
case 9 => "isExternal"
case 10 => "lineNumber"
case 11 => "name"
case 12 => "order"
case 12 => "offset"
case 13 => "offsetEnd"
case 14 => "order"
}

override def productElement(n: Int): Any =
Expand All @@ -296,11 +308,13 @@ class TypeDecl(graph_4762: Graph, id_4762: Long /*cf https://github.com/scala/bu
case 9 => isExternal
case 10 => lineNumber
case 11 => name
case 12 => order
case 12 => offset
case 13 => offsetEnd
case 14 => order
}

override def productPrefix = "TypeDecl"
override def productArity = 13
override def productArity = 15
}

class TypeDeclDb(ref: NodeRef[NodeDb]) extends NodeDb(ref) with StoredNode with AstNode with TypeDeclBase {
Expand Down Expand Up @@ -329,6 +343,10 @@ class TypeDeclDb(ref: NodeRef[NodeDb]) extends NodeDb(ref) with StoredNode with
def lineNumber: Option[Integer] = Option(_lineNumber)
private var _name: String = TypeDecl.PropertyDefaults.Name
def name: String = _name
private var _offset: Integer = null
def offset: Option[Integer] = Option(_offset)
private var _offsetEnd: Integer = null
def offsetEnd: Option[Integer] = Option(_offsetEnd)
private var _order: scala.Int = TypeDecl.PropertyDefaults.Order
def order: scala.Int = _order

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

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

properties
Expand Down Expand Up @@ -441,7 +463,9 @@ class TypeDeclDb(ref: NodeRef[NodeDb]) extends NodeDb(ref) with StoredNode with
case 9 => "isExternal"
case 10 => "lineNumber"
case 11 => "name"
case 12 => "order"
case 12 => "offset"
case 13 => "offsetEnd"
case 14 => "order"
}

override def productElement(n: Int): Any =
Expand All @@ -458,11 +482,13 @@ class TypeDeclDb(ref: NodeRef[NodeDb]) extends NodeDb(ref) with StoredNode with
case 9 => isExternal
case 10 => lineNumber
case 11 => name
case 12 => order
case 12 => offset
case 13 => offsetEnd
case 14 => order
}

override def productPrefix = "TypeDecl"
override def productArity = 13
override def productArity = 15

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

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

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

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

graph.indexManager.putIfIndexed("FULL_NAME", newNode.asInstanceOf[NewTypeDecl].fullName, this.ref)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -527,6 +527,102 @@ class TypeDeclTraversalExtGen[NodeType <: TypeDecl](val traversal: Iterator[Node
overflowdb.traversal.filter.StringPropertyFilter.regexpNotMultiple(traversal)(_.name, patterns)
}

/** Traverse to offset property */
def offset: Iterator[Integer] =
traversal.flatMap(_.offset)

/** Traverse to nodes where the offset equals the given `value`
*/
def offset(value: Integer): Iterator[NodeType] =
traversal.filter { node => node.offset.isDefined && node.offset.get == value }

/** Traverse to nodes where the offset equals at least one of the given `values`
*/
def offset(values: Integer*): Iterator[NodeType] = {
val vset = values.toSet
traversal.filter { node => node.offset.isDefined && vset.contains(node.offset.get) }
}

/** Traverse to nodes where the offset is greater than the given `value`
*/
def offsetGt(value: Integer): Iterator[NodeType] =
traversal.filter { node => node.offset.isDefined && node.offset.get > value }

/** Traverse to nodes where the offset is greater than or equal the given `value`
*/
def offsetGte(value: Integer): Iterator[NodeType] =
traversal.filter { node => node.offset.isDefined && node.offset.get >= value }

/** Traverse to nodes where the offset is less than the given `value`
*/
def offsetLt(value: Integer): Iterator[NodeType] =
traversal.filter { node => node.offset.isDefined && node.offset.get < value }

/** Traverse to nodes where the offset is less than or equal the given `value`
*/
def offsetLte(value: Integer): Iterator[NodeType] =
traversal.filter { node => node.offset.isDefined && node.offset.get <= value }

/** Traverse to nodes where offset is not equal to the given `value`.
*/
def offsetNot(value: Integer): Iterator[NodeType] =
traversal.filter { node => !node.offset.isDefined || node.offset.get != value }

/** Traverse to nodes where offset is not equal to any of the given `values`.
*/
def offsetNot(values: Integer*): Iterator[NodeType] = {
val vset = values.toSet
traversal.filter { node => !node.offset.isDefined || !vset.contains(node.offset.get) }
}

/** Traverse to offsetEnd property */
def offsetEnd: Iterator[Integer] =
traversal.flatMap(_.offsetEnd)

/** Traverse to nodes where the offsetEnd equals the given `value`
*/
def offsetEnd(value: Integer): Iterator[NodeType] =
traversal.filter { node => node.offsetEnd.isDefined && node.offsetEnd.get == value }

/** Traverse to nodes where the offsetEnd equals at least one of the given `values`
*/
def offsetEnd(values: Integer*): Iterator[NodeType] = {
val vset = values.toSet
traversal.filter { node => node.offsetEnd.isDefined && vset.contains(node.offsetEnd.get) }
}

/** Traverse to nodes where the offsetEnd is greater than the given `value`
*/
def offsetEndGt(value: Integer): Iterator[NodeType] =
traversal.filter { node => node.offsetEnd.isDefined && node.offsetEnd.get > value }

/** Traverse to nodes where the offsetEnd is greater than or equal the given `value`
*/
def offsetEndGte(value: Integer): Iterator[NodeType] =
traversal.filter { node => node.offsetEnd.isDefined && node.offsetEnd.get >= value }

/** Traverse to nodes where the offsetEnd is less than the given `value`
*/
def offsetEndLt(value: Integer): Iterator[NodeType] =
traversal.filter { node => node.offsetEnd.isDefined && node.offsetEnd.get < value }

/** Traverse to nodes where the offsetEnd is less than or equal the given `value`
*/
def offsetEndLte(value: Integer): Iterator[NodeType] =
traversal.filter { node => node.offsetEnd.isDefined && node.offsetEnd.get <= value }

/** Traverse to nodes where offsetEnd is not equal to the given `value`.
*/
def offsetEndNot(value: Integer): Iterator[NodeType] =
traversal.filter { node => !node.offsetEnd.isDefined || node.offsetEnd.get != value }

/** Traverse to nodes where offsetEnd is not equal to any of the given `values`.
*/
def offsetEndNot(values: Integer*): Iterator[NodeType] = {
val vset = values.toSet
traversal.filter { node => !node.offsetEnd.isDefined || !vset.contains(node.offsetEnd.get) }
}

/** Traverse to order property */
def order: Iterator[scala.Int] =
traversal.map(_.order)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ object Method extends SchemaBase {
|`LINE_NUMBER`, `COLUMN_NUMBER`, `LINE_NUMBER_END`, and `COLUMN_NUMBER_END` and
|the name of the source file is specified in `FILENAME`. An optional hash value
|MAY be calculated over the function contents and included in the `HASH` field.
|
|The optional `OFFSET` and `OFFSET_END` specify the start
|and exclusive end position of the code belonging to a method within the corresponding
|`FILE` nodes `CONTENT` property.
Expand Down
Loading

0 comments on commit 3c4440a

Please sign in to comment.