Skip to content

Commit

Permalink
v0.1.5 Hotfix Release (#393)
Browse files Browse the repository at this point in the history
* Optimizes AST iterator (#391)

* Prepare v0.1.5 release
  • Loading branch information
abhikuhikar authored Apr 27, 2021
1 parent f6782f2 commit 0ec8f95
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 16 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ This project is published to [Maven Central](https://search.maven.org/artifact/o

| Group ID | Artifact ID | Recommended Version |
|----------|-------------|---------------------|
| `org.partiql` | `partiql-lang-kotlin` | `0.1.4`
| `org.partiql` | `partiql-lang-kotlin` | `0.1.5`


For Maven builds, add this to your `pom.xml`:
Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ allprojects {

subprojects {
group = 'org.partiql'
version = '0.1.4'
version = '0.1.5'
}

buildDir = new File(rootProject.projectDir, "gradle-build/" + project.name)
Expand Down
33 changes: 19 additions & 14 deletions lang/src/org/partiql/lang/ast/ast.kt
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import org.partiql.lang.util.*
import java.util.*

/**
* Base type for all AST nodes.
* Base type for all AST nodes.
*/
sealed class AstNode : Iterable<AstNode> {

Expand All @@ -32,10 +32,15 @@ sealed class AstNode : Iterable<AstNode> {
* Depth first iterator over all nodes.
*/
override operator fun iterator(): Iterator<AstNode> {
fun depthFirstSequence(node: AstNode): Sequence<AstNode> =
sequenceOf(node) + node.children.asSequence().flatMap { depthFirstSequence(it) }

return depthFirstSequence(this).iterator();
val allNodes = mutableListOf<AstNode>()

fun depthFirstSequence(node: AstNode) {
allNodes.add(node)
node.children.map { depthFirstSequence(it) }
}

depthFirstSequence(this)
return allNodes.toList().iterator()
}
}

Expand All @@ -44,7 +49,7 @@ sealed class AstNode : Iterable<AstNode> {
* place a value is allowed.
*/
sealed class ExprNode : AstNode(), HasMetas {

fun copy(newMetas: MetaContainer? = null): ExprNode {
// This looks like duplication but really isn't: each branch executes a different compiler-generated `copy` function.
val metas = newMetas ?: this.metas
Expand Down Expand Up @@ -113,7 +118,7 @@ data class Literal(
data class LiteralMissing(
override val metas: MetaContainer
) : ExprNode() {

override val children: List<AstNode> = listOf()
}

Expand Down Expand Up @@ -366,15 +371,15 @@ sealed class SelectProjection : AstNode()
data class SelectProjectionList(
val items: List<SelectListItem>
) : SelectProjection() {
override val children: List<AstNode> = items

override val children: List<AstNode> = items
}

/** For `SELECT VALUE <expr>` */
data class SelectProjectionValue(
val expr: ExprNode
) : SelectProjection() {

override val children: List<AstNode> = listOf(expr)
}

Expand All @@ -383,7 +388,7 @@ data class SelectProjectionPivot(
val valueExpr: ExprNode,
val nameExpr: ExprNode
) : SelectProjection() {

override val children: List<AstNode> = listOf(valueExpr, nameExpr)
}

Expand All @@ -404,7 +409,7 @@ data class SelectListItemExpr(
val expr: ExprNode,
val asName: SymbolicName? = null
) : SelectListItem() {

override val children: List<AstNode> = listOf(expr)
}

Expand Down Expand Up @@ -451,7 +456,7 @@ data class FromSourceJoin(
val condition: ExprNode,
override val metas: MetaContainer
) : FromSource(), HasMetas {

override val children: List<AstNode> = listOf(leftRef, rightRef, condition)
}

Expand All @@ -469,7 +474,7 @@ data class FromSourceUnpivot(
val atName: SymbolicName?,
override val metas: MetaContainer
) : FromSource(), HasMetas {

override val children: List<AstNode> = listOf(expr)
}

Expand Down

0 comments on commit 0ec8f95

Please sign in to comment.