From aa345ed456cbc05db2baed83bc4b034e973ceeb6 Mon Sep 17 00:00:00 2001 From: Pavel Marek Date: Mon, 2 Dec 2024 14:35:16 +0100 Subject: [PATCH] Replace Scala Empty with Java Empty annotated with @IRNode --- .../java/org/enso/compiler/core/ir/Empty.java | 27 ++++++ .../org/enso/compiler/core/ir/Empty.scala | 89 ------------------- 2 files changed, 27 insertions(+), 89 deletions(-) create mode 100644 engine/runtime-parser/src/main/java/org/enso/compiler/core/ir/Empty.java delete mode 100644 engine/runtime-parser/src/main/scala/org/enso/compiler/core/ir/Empty.scala diff --git a/engine/runtime-parser/src/main/java/org/enso/compiler/core/ir/Empty.java b/engine/runtime-parser/src/main/java/org/enso/compiler/core/ir/Empty.java new file mode 100644 index 000000000000..96ec7dc8ce06 --- /dev/null +++ b/engine/runtime-parser/src/main/java/org/enso/compiler/core/ir/Empty.java @@ -0,0 +1,27 @@ +package org.enso.compiler.core.ir; + +import java.util.UUID; +import org.enso.compiler.core.IR; +import org.enso.runtime.parser.dsl.IRCopyMethod; +import org.enso.runtime.parser.dsl.IRNode; + +@IRNode +public interface Empty extends IR { + static Empty createEmpty() { + return EmptyGen.builder().build(); + } + + static Empty createFromLocation(IdentifiedLocation location) { + return EmptyGen.builder().location(location).build(); + } + + static Empty createFromLocationAndPassData(IdentifiedLocation location, MetadataStorage passData) { + return EmptyGen.builder() + .location(location) + .passData(passData) + .build(); + } + + @IRCopyMethod + Empty copy(IdentifiedLocation location, MetadataStorage passData, DiagnosticStorage diagnostics, UUID id); +} diff --git a/engine/runtime-parser/src/main/scala/org/enso/compiler/core/ir/Empty.scala b/engine/runtime-parser/src/main/scala/org/enso/compiler/core/ir/Empty.scala deleted file mode 100644 index 849d58cd9401..000000000000 --- a/engine/runtime-parser/src/main/scala/org/enso/compiler/core/ir/Empty.scala +++ /dev/null @@ -1,89 +0,0 @@ -package org.enso.compiler.core.ir - -import org.enso.compiler.core.Implicits.{ShowPassData, ToStringHelper} -import org.enso.compiler.core.{IR, Identifier} - -import java.util.UUID - -/** A node representing an empty IR construct that can be used in any place. - * - * @param identifiedLocation the source location that the node corresponds to - * @param passData the pass metadata associated with this node - */ -sealed case class Empty( - override val identifiedLocation: IdentifiedLocation, - override val passData: MetadataStorage = new MetadataStorage() -) extends IR - with Expression - with IRKind.Primitive - with LazyDiagnosticStorage - with LazyId { - - /** Creates a copy of `this` - * - * @param location the source location that the node corresponds to - * @param passData the pass metadata associated with this node - * @param diagnostics compiler diagnostics for this node - * @param id the identifier for the new node - * @return a copy of `this` with the specified fields updated - */ - def copy( - location: Option[IdentifiedLocation] = location, - passData: MetadataStorage = passData, - diagnostics: DiagnosticStorage = diagnostics, - id: UUID @Identifier = id - ): Empty = { - if ( - location != this.location - || (passData ne this.passData) - || diagnostics != this.diagnostics - || id != this.id - ) { - val res = Empty(location.orNull, passData) - res.diagnostics = diagnostics - res.id = id - res - } else this - } - - /** @inheritdoc */ - override def duplicate( - keepLocations: Boolean = true, - keepMetadata: Boolean = true, - keepDiagnostics: Boolean = true, - keepIdentifiers: Boolean = false - ): Empty = - copy( - location = if (keepLocations) location else None, - passData = - if (keepMetadata) passData.duplicate else new MetadataStorage(), - diagnostics = if (keepDiagnostics) diagnosticsCopy else null, - id = if (keepIdentifiers) id else null - ) - - /** @inheritdoc */ - override def setLocation(location: Option[IdentifiedLocation]): Empty = - copy(location = location) - - /** @inheritdoc */ - override def mapExpressions( - fn: java.util.function.Function[Expression, Expression] - ): Empty = this - - /** String representation. */ - override def toString: String = - s""" - |Empty( - |location = $location, - |passData = ${this.showPassData}, - |diagnostics = $diagnostics, - |id = $id - |) - |""".toSingleLine - - /** @inheritdoc */ - override def children: List[IR] = List() - - /** @inheritdoc */ - override def showCode(indent: Int): String = "IR.Empty" -}