From 0ec8f954f4d37d3f9af58fcd0214870fd9a7b7c8 Mon Sep 17 00:00:00 2001 From: Abhilash Kuhikar Date: Tue, 27 Apr 2021 00:33:54 -0400 Subject: [PATCH] v0.1.5 Hotfix Release (#393) * Optimizes AST iterator (#391) * Prepare v0.1.5 release --- README.md | 2 +- build.gradle | 2 +- lang/src/org/partiql/lang/ast/ast.kt | 33 ++++++++++++++++------------ 3 files changed, 21 insertions(+), 16 deletions(-) diff --git a/README.md b/README.md index de4fa7ca6..59d19f624 100644 --- a/README.md +++ b/README.md @@ -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`: diff --git a/build.gradle b/build.gradle index 6ca1c0964..d9ee1f178 100644 --- a/build.gradle +++ b/build.gradle @@ -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) diff --git a/lang/src/org/partiql/lang/ast/ast.kt b/lang/src/org/partiql/lang/ast/ast.kt index bbd22f1f8..6259178d0 100644 --- a/lang/src/org/partiql/lang/ast/ast.kt +++ b/lang/src/org/partiql/lang/ast/ast.kt @@ -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 { @@ -32,10 +32,15 @@ sealed class AstNode : Iterable { * Depth first iterator over all nodes. */ override operator fun iterator(): Iterator { - fun depthFirstSequence(node: AstNode): Sequence = - sequenceOf(node) + node.children.asSequence().flatMap { depthFirstSequence(it) } - - return depthFirstSequence(this).iterator(); + val allNodes = mutableListOf() + + fun depthFirstSequence(node: AstNode) { + allNodes.add(node) + node.children.map { depthFirstSequence(it) } + } + + depthFirstSequence(this) + return allNodes.toList().iterator() } } @@ -44,7 +49,7 @@ sealed class AstNode : Iterable { * 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 @@ -113,7 +118,7 @@ data class Literal( data class LiteralMissing( override val metas: MetaContainer ) : ExprNode() { - + override val children: List = listOf() } @@ -366,15 +371,15 @@ sealed class SelectProjection : AstNode() data class SelectProjectionList( val items: List ) : SelectProjection() { - - override val children: List = items + + override val children: List = items } /** For `SELECT VALUE ` */ data class SelectProjectionValue( val expr: ExprNode ) : SelectProjection() { - + override val children: List = listOf(expr) } @@ -383,7 +388,7 @@ data class SelectProjectionPivot( val valueExpr: ExprNode, val nameExpr: ExprNode ) : SelectProjection() { - + override val children: List = listOf(valueExpr, nameExpr) } @@ -404,7 +409,7 @@ data class SelectListItemExpr( val expr: ExprNode, val asName: SymbolicName? = null ) : SelectListItem() { - + override val children: List = listOf(expr) } @@ -451,7 +456,7 @@ data class FromSourceJoin( val condition: ExprNode, override val metas: MetaContainer ) : FromSource(), HasMetas { - + override val children: List = listOf(leftRef, rightRef, condition) } @@ -469,7 +474,7 @@ data class FromSourceUnpivot( val atName: SymbolicName?, override val metas: MetaContainer ) : FromSource(), HasMetas { - + override val children: List = listOf(expr) }