[Generator] Always put expression body on a new line

This commit is contained in:
Ilya Gorbunov
2023-08-29 04:43:07 +02:00
committed by Space Team
parent 68a9b9c312
commit 1c149925b7
13 changed files with 463 additions and 277 deletions
+33 -33
View File
@@ -370,35 +370,35 @@ class JsCharGenerator(writer: PrintWriter) : CharGenerator(writer) {
}
override fun MethodBuilder.modifyGeneratedCompareTo() {
"value - other.value".addAsSingleLineBody(bodyOnNewLine = false)
"value - other.value".setAsExpressionBody()
}
override fun MethodBuilder.modifyGeneratedPlus() {
"(value + other).toChar()".addAsSingleLineBody(bodyOnNewLine = false)
"(value + other).toChar()".setAsExpressionBody()
}
override fun MethodBuilder.modifyGeneratedMinusChar() {
"value - other.value".addAsSingleLineBody(bodyOnNewLine = false)
"value - other.value".setAsExpressionBody()
}
override fun MethodBuilder.modifyGeneratedMinusInt() {
"(value - other).toChar()".addAsSingleLineBody(bodyOnNewLine = false)
"(value - other).toChar()".setAsExpressionBody()
}
override fun MethodBuilder.modifyGeneratedInc() {
"(value + 1).toChar()".addAsSingleLineBody(bodyOnNewLine = false)
"(value + 1).toChar()".setAsExpressionBody()
}
override fun MethodBuilder.modifyGeneratedDec() {
"(value - 1).toChar()".addAsSingleLineBody(bodyOnNewLine = false)
"(value - 1).toChar()".setAsExpressionBody()
}
override fun MethodBuilder.modifyGeneratedRangeTo() {
"CharRange(this, other)".addAsSingleLineBody(bodyOnNewLine = false)
"CharRange(this, other)".setAsExpressionBody()
}
override fun MethodBuilder.modifyGeneratedRangeUntil() {
"this until other".addAsSingleLineBody(bodyOnNewLine = false)
"this until other".setAsExpressionBody()
}
override fun MethodBuilder.modifyGeneratedConversions(otherKind: PrimitiveType) {
@@ -407,25 +407,25 @@ class JsCharGenerator(writer: PrintWriter) : CharGenerator(writer) {
PrimitiveType.INT -> "value"
else -> "value.$methodName()"
}
body.addAsSingleLineBody(bodyOnNewLine = false)
body.setAsExpressionBody()
}
override fun MethodBuilder.modifyGeneratedEquals() {
"""
if (other !is Char) return false
return this.value == other.value
""".trimIndent().addAsMultiLineBody()
""".trimIndent().setAsBlockBody()
}
override fun MethodBuilder.modifyGeneratedToString() {
additionalComments = "TODO implicit usages of toString and valueOf must be covered in DCE"
annotations += "Suppress(\"JS_NAME_PROHIBITED_FOR_OVERRIDE\")"
annotations += "JsName(\"toString\")"
"return js(\"String\").fromCharCode(value).unsafeCast<String>()".addAsMultiLineBody()
"return js(\"String\").fromCharCode(value).unsafeCast<String>()".setAsBlockBody()
}
override fun MethodBuilder.modifyGeneratedHashCode() {
"value".addAsSingleLineBody(bodyOnNewLine = false)
"value".setAsExpressionBody()
}
}
@@ -489,40 +489,40 @@ class WasmCharGenerator(writer: PrintWriter) : CharGenerator(writer) {
}
override fun MethodBuilder.modifyGeneratedCompareTo() {
"wasm_i32_compareTo(this.code, other.code)".addAsSingleLineBody(bodyOnNewLine = true)
"wasm_i32_compareTo(this.code, other.code)".setAsExpressionBody()
}
override fun MethodBuilder.modifyGeneratedPlus() {
modifySignature { isInline = true }
"(this.code + other).toChar()".addAsSingleLineBody(bodyOnNewLine = true)
"(this.code + other).toChar()".setAsExpressionBody()
}
override fun MethodBuilder.modifyGeneratedMinusChar() {
modifySignature { isInline = true }
"(this.code - other.code)".addAsSingleLineBody(bodyOnNewLine = true)
"(this.code - other.code)".setAsExpressionBody()
}
override fun MethodBuilder.modifyGeneratedMinusInt() {
modifySignature { isInline = true }
"(this.code - other).toChar()".addAsSingleLineBody(bodyOnNewLine = true)
"(this.code - other).toChar()".setAsExpressionBody()
}
override fun MethodBuilder.modifyGeneratedInc() {
modifySignature { isInline = true }
"(this.code + 1).toChar()".addAsSingleLineBody(bodyOnNewLine = true)
"(this.code + 1).toChar()".setAsExpressionBody()
}
override fun MethodBuilder.modifyGeneratedDec() {
modifySignature { isInline = true }
"(this.code - 1).toChar()".addAsSingleLineBody(bodyOnNewLine = true)
"(this.code - 1).toChar()".setAsExpressionBody()
}
override fun MethodBuilder.modifyGeneratedRangeTo() {
"CharRange(this, other)".addAsSingleLineBody(bodyOnNewLine = true)
"CharRange(this, other)".setAsExpressionBody()
}
override fun MethodBuilder.modifyGeneratedRangeUntil() {
"this until other".addAsSingleLineBody(bodyOnNewLine = true)
"this until other".setAsExpressionBody()
}
override fun MethodBuilder.modifyGeneratedConversions(otherKind: PrimitiveType) {
@@ -535,7 +535,7 @@ class WasmCharGenerator(writer: PrintWriter) : CharGenerator(writer) {
}
else -> "this.code.$methodName()"
}
body.addAsSingleLineBody(bodyOnNewLine = true)
body.setAsExpressionBody()
}
override fun MethodBuilder.modifyGeneratedEquals() {
@@ -543,7 +543,7 @@ class WasmCharGenerator(writer: PrintWriter) : CharGenerator(writer) {
if (other is Char)
return wasm_i32_eq(this.code, other.code)
return false
""".trimIndent().addAsMultiLineBody()
""".trimIndent().setAsBlockBody()
}
override fun MethodBuilder.modifyGeneratedToString() {
@@ -552,12 +552,12 @@ class WasmCharGenerator(writer: PrintWriter) : CharGenerator(writer) {
val array = WasmCharArray(1)
array.set(0, this)
return array.createString()
""".trimIndent().addAsMultiLineBody()
""".trimIndent().setAsBlockBody()
}
override fun MethodBuilder.modifyGeneratedHashCode() {
modifySignature { visibility = null }
"this.code.hashCode()".addAsSingleLineBody(bodyOnNewLine = true)
"this.code.hashCode()".setAsExpressionBody()
}
}
@@ -642,17 +642,17 @@ class NativeCharGenerator(writer: PrintWriter) : CharGenerator(writer) {
override fun MethodBuilder.modifyGeneratedPlus() {
modifySignature { isInline = true }
"(this.code + other).toChar()".addAsSingleLineBody(bodyOnNewLine = true)
"(this.code + other).toChar()".setAsExpressionBody()
}
override fun MethodBuilder.modifyGeneratedMinusChar() {
modifySignature { isInline = true }
"this.code - other.code".addAsSingleLineBody(bodyOnNewLine = true)
"this.code - other.code".setAsExpressionBody()
}
override fun MethodBuilder.modifyGeneratedMinusInt() {
modifySignature { isInline = true }
"(this.code - other).toChar()".addAsSingleLineBody(bodyOnNewLine = true)
"(this.code - other).toChar()".setAsExpressionBody()
}
override fun MethodBuilder.modifyGeneratedInc() {
@@ -664,11 +664,11 @@ class NativeCharGenerator(writer: PrintWriter) : CharGenerator(writer) {
}
override fun MethodBuilder.modifyGeneratedRangeTo() {
"CharRange(this, other)".addAsSingleLineBody(bodyOnNewLine = true)
"CharRange(this, other)".setAsExpressionBody()
}
override fun MethodBuilder.modifyGeneratedRangeUntil() {
"this until other".addAsSingleLineBody(bodyOnNewLine = true)
"this until other".setAsExpressionBody()
}
override fun MethodBuilder.modifyGeneratedConversions(otherKind: PrimitiveType) {
@@ -677,7 +677,7 @@ class NativeCharGenerator(writer: PrintWriter) : CharGenerator(writer) {
PrimitiveType.BYTE -> annotations += "TypedIntrinsic(IntrinsicType.INT_TRUNCATE)"
PrimitiveType.CHAR -> {
modifySignature { isInline = true }
"this".addAsSingleLineBody(bodyOnNewLine = true)
"this".setAsExpressionBody()
}
PrimitiveType.SHORT, PrimitiveType.INT, PrimitiveType.LONG -> annotations += "TypedIntrinsic(IntrinsicType.ZERO_EXTEND)"
PrimitiveType.FLOAT, PrimitiveType.DOUBLE -> annotations += "TypedIntrinsic(IntrinsicType.UNSIGNED_TO_FLOAT)"
@@ -686,7 +686,7 @@ class NativeCharGenerator(writer: PrintWriter) : CharGenerator(writer) {
}
override fun MethodBuilder.modifyGeneratedEquals() {
"other is Char && this.code == other.code".addAsSingleLineBody(bodyOnNewLine = true)
"other is Char && this.code == other.code".setAsExpressionBody()
}
override fun MethodBuilder.modifyGeneratedToString() {
@@ -707,12 +707,12 @@ class NativeCharGenerator(writer: PrintWriter) : CharGenerator(writer) {
returnType = PrimitiveType.BOOLEAN.capitalized
}
"this == other".addAsSingleLineBody(bodyOnNewLine = false)
"this == other".setAsExpressionBody()
}
}
override fun MethodBuilder.modifyGeneratedHashCode() {
"return this.code".addAsMultiLineBody()
"return this.code".setAsBlockBody()
}
override fun ClassBuilder.generateAdditionalMethods() {