Skip to content

Commit

Permalink
Addressed some review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
oxisto committed Aug 23, 2023
1 parent e97e62f commit dfcf6b1
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -535,10 +535,6 @@ val Node?.namespaces: List<NamespaceDeclaration>
val Node?.variables: List<VariableDeclaration>
get() = this.allChildren()

/** Returns all [TupleDeclaration] children in this graph, starting with this [Node]. */
val Node?.tuples: List<TupleDeclaration>
get() = this.allChildren()

/** Returns all [Literal] children in this graph, starting with this [Node]. */
val Node?.literals: List<Literal<*>>
get() = this.allChildren()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,9 @@ import de.fraunhofer.aisec.cpg.graph.types.TupleType

/**
* This declaration models a tuple of different [VariableDeclaration] nodes. This is primarily used
* in languages that support multiple assignments, such as Go as part of a top-level declaration.
* The tuple is needed because the initializer of this declaration is flowing into the tuple (and
* then split among its elements) rather than flowing into the declarations individually. For
* example the following code
* in languages that support multiple assignments in a declaration, such as Go. The tuple is needed
* because the initializer of this declaration is flowing into the tuple (and then split among its
* elements) rather than flowing into the declarations individually. For example the following code
*
* ```go
* var a,b = call()
Expand All @@ -49,8 +48,12 @@ import de.fraunhofer.aisec.cpg.graph.types.TupleType
* and `b`
* - an [TupleDeclaration.initializer] that holds a [CallExpression] to `call`.
*
* Note: Currently, we only support [TupleDeclaration] with an initial [AutoType] (set in
* [newTupleDeclaration]); its actual [TupleType] will be inferred by the
* Implementation Note #1: The [VariableDeclaration.initializer] of the element variables MUST be
* empty; only the [TupleDeclaration.initializer] must be set. Otherwise we are potentially parsing
* the initializer twice.
*
* Implementation Note #2: Currently, we only support [TupleDeclaration] with an initial [AutoType]
* (set in [newTupleDeclaration]); its actual [TupleType] will be inferred by the
* [TupleDeclaration.initializer] (see [VariableDeclaration.typeChanged] for the implementation).
*
* The same applies to the elements in the tuple. They also need to have an [AutoType], and their
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,9 @@ class TupleDeclarationTest {
val main = result.functions["main"]
assertNotNull(main)

val tuple = result.tuples["(a,b)"]
val tuple = result.variables["(a,b)"]
assertNotNull(tuple)
assertIs<TupleDeclaration>(tuple)
assertIs<TupleType>(tuple.type)

val call = tuple.initializer as? CallExpression
Expand Down Expand Up @@ -158,8 +159,9 @@ class TupleDeclarationTest {
val main = result.functions["main"]
assertNotNull(main)

val tuple = main.tuples["(a,b)"]
val tuple = main.variables["(a,b)"]
assertNotNull(tuple)
assertIs<TupleDeclaration>(tuple)
assertIs<TupleType>(tuple.type)

val call = tuple.initializer as? CallExpression
Expand Down

0 comments on commit dfcf6b1

Please sign in to comment.