Skip to content

Commit

Permalink
fix ast printing of arrays with duplicate elements
Browse files Browse the repository at this point in the history
  • Loading branch information
irmen committed Oct 13, 2024
1 parent 03412ca commit fa5479e
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
11 changes: 10 additions & 1 deletion codeCore/src/prog8/code/ast/AstPrinter.kt
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,16 @@ fun printAst(root: PtNode, skipLibraries: Boolean, output: (text: String) -> Uni
else
"&"
}
is PtArray -> "array len=${node.children.size} ${type(node.type)}"
is PtArray -> {
val valuelist = node.children.map {
when (it) {
is PtNumber -> it.number.toString()
is PtIdentifier -> it.name
else -> "?"
}
}.joinToString(", ")
"array len=${node.children.size} ${type(node.type)} [ $valuelist ]"
}
is PtArrayIndexer -> "<arrayindexer> ${type(node.type)} ${if(node.splitWords) "[splitwords]" else ""}"
is PtBinaryExpression -> "<expr> ${node.operator} ${type(node.type)}"
is PtBuiltinFunctionCall -> {
Expand Down
8 changes: 4 additions & 4 deletions compilerAst/src/prog8/ast/AstToSourceTextConverter.kt
Original file line number Diff line number Diff line change
Expand Up @@ -315,16 +315,16 @@ class AstToSourceTextConverter(val output: (text: String) -> Unit, val program:
}

override fun visit(array: ArrayLiteral) {
outputListMembers(array.value.asSequence())
outputListMembers(array.value)
}

private fun outputListMembers(array: Sequence<Expression>) {
private fun outputListMembers(array: Array<Expression>) {
var counter = 0
output("[")
scopelevel++
for (v in array) {
for ((idx, v) in array.withIndex()) {
v.accept(this)
if (v !== array.last())
if (idx != array.size-1)
output(", ")
counter++
if (counter > 16) {
Expand Down

0 comments on commit fa5479e

Please sign in to comment.