Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove importresolver package #5

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
7beadd7
Use 4 spaces instead of 2 for default indent
pranjalvachaspati-toast Oct 12, 2021
5665e73
Remove message.stg
pranjalvachaspati-toast Oct 13, 2021
2cc5b3a
Remove Descriptor template
pranjalvachaspati-toast Oct 13, 2021
7ecc79f
Remove Descriptor template
pranjalvachaspati-toast Oct 13, 2021
14bd064
Remove dead code in header template and most of services template.
pranjalvachaspati-toast Oct 13, 2021
0861dcd
Set locale for decapitalize to get rid of compiler warning.
pranjalvachaspati-toast Oct 13, 2021
1cca8d0
Remove unused templates
pranjalvachaspati-toast Oct 13, 2021
151e25c
Create subpackage for annotators.
pranjalvachaspati-toast Oct 13, 2021
945b990
Merge branch 'kotlinpoet' of https://github.com/andrewparmet/protokt …
pranjalvachaspati-toast Oct 13, 2021
e24fb1d
Move methodType to kotlinpoet and get rid of services.stg
pranjalvachaspati-toast Oct 13, 2021
0369624
Remove Oneof stringtemplates.
pranjalvachaspati-toast Oct 13, 2021
5964ab4
Get rid of a couple renderers
pranjalvachaspati-toast Oct 13, 2021
46839ce
Migrate boxing & default value renderers away from StringTemplate.
pranjalvachaspati-toast Oct 14, 2021
f12ca3c
Remove sizeof stringtemplates.
pranjalvachaspati-toast Oct 15, 2021
9981c53
Add non-stringtemplate serializer generation
pranjalvachaspati-toast Oct 15, 2021
ec526a1
Get rid of renderers stringtemplate
pranjalvachaspati-toast Oct 15, 2021
91accd6
Remove options stringtemplate
pranjalvachaspati-toast Oct 15, 2021
8aec02e
--amend
pranjalvachaspati-toast Oct 15, 2021
8223782
Merge branch 'kotlinpoet' of https://github.com/andrewparmet/protokt …
pranjalvachaspati-toast Oct 15, 2021
4f4d40a
Convert deserializer to use kotlinpoet
pranjalvachaspati-toast Oct 16, 2021
d4af5e5
Create packages for import resolution and descriptor stuff
pranjalvachaspati-toast Oct 16, 2021
f38ffed
Create packages for import resolution and descriptor stuff
pranjalvachaspati-toast Oct 16, 2021
2125158
This merge required some additional changes - mostly changing Strings…
pranjalvachaspati-toast Oct 18, 2021
9b264a3
Additional changes from Strings to CodeBlocks
pranjalvachaspati-toast Oct 18, 2021
8bb76ce
Disable non-kotlinpoet import resolution
pranjalvachaspati-toast Oct 18, 2021
db9d992
Remove importresolution package
pranjalvachaspati-toast Oct 18, 2021
764782c
Merge branch 'kotlinpoet' of https://github.com/andrewparmet/protokt …
pranjalvachaspati-toast Oct 18, 2021
1f53989
Make fixes for PR comments
pranjalvachaspati-toast Oct 19, 2021
e84eae0
Use DSL typename in DeserializerAnnotator
pranjalvachaspati-toast Oct 19, 2021
a4193df
Remove dependency on stringtemplate
pranjalvachaspati-toast Oct 19, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Make fixes for PR comments
  • Loading branch information
pranjalvachaspati-toast committed Oct 19, 2021
commit 1f539892b7b0249b4eea2448e308c5be0eb18f8c
Original file line number Diff line number Diff line change
Expand Up @@ -69,13 +69,11 @@ private constructor(
val properties = annotateProperties(msg, ctx)

return TypeSpec.companionObjectBuilder("Deserializer")
// KtDeserializer<MessageType>
.addSuperinterface(
KtDeserializer::class
.asTypeName()
.parameterizedBy(msg.typeName)
)
// (MessageTypeDsl.() -> Unit) -> Message
.addSuperinterface(
LambdaTypeName.get(
null,
Expand Down Expand Up @@ -216,7 +214,6 @@ fun deserializeString(f: StandardField, ctx: Context, packed: Boolean): String {
val wrappedRead = options?.let { wrapField(it.wrapName, read, it.type, it.oneof) } ?: read.toString()
return when {
f.map -> deserializeMap(f, options, read)
// · is a non-wrapping space
f.repeated -> """
|(${f.fieldName} ?: mutableListOf()).apply·{
| deserializer.readRepeated($packed)·{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ class DslAnnotator(
setter(
FunSpec.setterBuilder()
.addParameter("newValue", List::class)
.addCode("field = %M(newValue)", runtimeFunction("finishList"))
.addCode("field = %M(newValue)", runtimeFunction("copyList"))
.build()
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -164,10 +164,11 @@ private constructor(
return when {
f.map -> sizeOfMap(f, name)
f.repeated && f.packed -> {
val map = LinkedHashMap<String, Any>()
map += "sizeof" to runtimeFunction("sizeof")
map += "tag" to Tag::class
map += "uInt32" to UInt32::class
val map = mutableMapOf<String, Any>(
"sizeof" to runtimeFunction("sizeof"),
"tag" to Tag::class,
"uInt32" to UInt32::class
)
buildCodeBlock {
addNamed(
"%sizeof:M(%tag:T(${f.number})) + " +
Expand All @@ -177,10 +178,11 @@ private constructor(
}
}
f.repeated -> {
val map = LinkedHashMap<String, Any>()
map += "sizeof" to runtimeFunction("sizeof")
map += "tag" to Tag::class
map += "boxedAccess" to f.box(interceptValueAccess(f, ctx, "it"))
val map = mutableMapOf(
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can these be declared in line as non-mutable maps?

"sizeof" to runtimeFunction("sizeof"),
"tag" to Tag::class,
"boxedAccess" to f.box(interceptValueAccess(f, ctx, "it"))
)
buildCodeBlock {
addNamed(
"(%sizeof:M(%tag:T(${f.number})) * $name.size) + " +
Expand All @@ -190,10 +192,11 @@ private constructor(
}
}
else -> {
val map = LinkedHashMap<String, Any>()
map += "sizeof" to runtimeFunction("sizeof")
map += "tag" to Tag::class
map += "access" to interceptFieldSizeof(f, name, ctx)
val map = mutableMapOf(
"sizeof" to runtimeFunction("sizeof"),
"tag" to Tag::class,
"access" to interceptFieldSizeof(f, name, ctx)
)
buildCodeBlock {
addNamed("%sizeof:M(%tag:T(${f.number})) + %access:L", map)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import com.toasttab.protokt.codegen.impl.Nullability.propertyType
import com.toasttab.protokt.codegen.impl.Wrapper.interceptDefaultValue
import com.toasttab.protokt.codegen.impl.Wrapper.interceptTypeName
import com.toasttab.protokt.codegen.impl.Wrapper.wrapped
import com.toasttab.protokt.codegen.impl.defaultValue
import com.toasttab.protokt.codegen.model.FieldType
import com.toasttab.protokt.codegen.protoc.Field
import com.toasttab.protokt.codegen.protoc.Message
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,11 +138,12 @@ private constructor(
}
)

val map = LinkedHashMap<String, Any>()
map += "tag" to Tag::class
map += "uInt32" to UInt32::class
map += "name" to f.fieldName
map += "sizeof" to runtimeFunction("sizeof")
val map = mutableMapOf(
"tag" to Tag::class,
"uInt32" to UInt32::class,
"name" to f.fieldName,
"sizeof" to runtimeFunction("sizeof")
)
return when {

f.repeated && f.packed -> buildCodeBlock {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import com.toasttab.protokt.codegen.annotators.Annotator.Context
import com.toasttab.protokt.codegen.impl.Wrapper.interceptValueAccess
import com.toasttab.protokt.codegen.impl.Wrapper.mapKeyConverter
import com.toasttab.protokt.codegen.impl.Wrapper.mapValueConverter
import com.toasttab.protokt.codegen.impl.defaultValue
import com.toasttab.protokt.codegen.impl.stripRootMessageNamePrefix
import com.toasttab.protokt.codegen.model.FieldType
import com.toasttab.protokt.codegen.protoc.StandardField
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package com.toasttab.protokt.codegen.impl

import com.squareup.kotlinpoet.CodeBlock
import com.toasttab.protokt.codegen.model.FieldType

val FieldType.defaultValue: CodeBlock
get() = when (this) {
FieldType.MESSAGE -> CodeBlock.of("null")
FieldType.ENUM -> throw IllegalAccessException(
"|An Enum type doesn't have a standard default value. " +
"If you have `enum Foo`, you can use Foo.from(0)"
)
FieldType.BOOL -> CodeBlock.of("false")
FieldType.FIXED32, FieldType.INT32, FieldType.SFIXED32, FieldType.SINT32, FieldType.UINT32 -> CodeBlock.of("0")
FieldType.FIXED64, FieldType.INT64, FieldType.SFIXED64, FieldType.SINT64, FieldType.UINT64 -> CodeBlock.of("0L")
FieldType.FLOAT -> CodeBlock.of("0.0F")
FieldType.DOUBLE -> CodeBlock.of("0.0")
FieldType.BYTES -> CodeBlock.of("%T.empty()", com.toasttab.protokt.rt.Bytes::class)
FieldType.STRING -> CodeBlock.of("\"\"")
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@

package com.toasttab.protokt.codegen.model

import com.squareup.kotlinpoet.CodeBlock
import com.toasttab.protokt.rt.Bytes
import com.toasttab.protokt.rt.KtEnum
import com.toasttab.protokt.rt.KtMessage
Expand Down Expand Up @@ -79,21 +78,12 @@ enum class FieldType(

val inlineRepresentation
get() = type.inlineRepresentation

val isGeneratedType
get() = type.isGeneratedType

val defaultValue
get() = type.defaultValue
}

private sealed class TypeImpl {
open val kotlinRepresentation: KClass<*>? = null
open val inlineRepresentation: KClass<*>? = null
open val ktRepresentation: KClass<*>? = null
open val isGeneratedType: Boolean = false
open val defaultValue: CodeBlock
get() = CodeBlock.of("null")

abstract val scalar: Boolean

Expand All @@ -106,56 +96,45 @@ private sealed class TypeImpl {
private sealed class Nonscalar(
override val kotlinRepresentation: KClass<*>? = null,
override val ktRepresentation: KClass<*>? = null,
override val isGeneratedType: Boolean = false,
override val defaultValue: CodeBlock = CodeBlock.of("null")
) : TypeImpl() {
override val scalar = false

object Enum : Nonscalar(ktRepresentation = KtEnum::class, isGeneratedType = true) {
override val defaultValue: CodeBlock
get() = throw IllegalAccessException(
"|An Enum type doesn't have a standard default value. " +
"If you have `enum Foo`, you can use Foo.from(0)"
)
}
object Message : Nonscalar(ktRepresentation = KtMessage::class, isGeneratedType = true)
object String : Nonscalar(kotlin.String::class, defaultValue = CodeBlock.of("\"\""))
object Enum : Nonscalar(ktRepresentation = KtEnum::class)
object Message : Nonscalar(ktRepresentation = KtMessage::class)
object String : Nonscalar(kotlin.String::class)
object Bytes : Nonscalar(
ByteArray::class,
com.toasttab.protokt.rt.Bytes::class,
defaultValue = CodeBlock.of("%T.empty()", com.toasttab.protokt.rt.Bytes::class)
com.toasttab.protokt.rt.Bytes::class
)
}

private sealed class Scalar(
override val kotlinRepresentation: KClass<*>? = null,
override val defaultValue: CodeBlock = CodeBlock.of("null")
override val kotlinRepresentation: KClass<*>? = null
) : TypeImpl() {
override val scalar = true

object Bool : Scalar(Boolean::class, defaultValue = CodeBlock.of("false"))
object Double : Scalar(kotlin.Double::class, defaultValue = CodeBlock.of("0.0"))
object Float : Scalar(kotlin.Float::class, defaultValue = CodeBlock.of("0.0F"))
object Bool : Scalar(Boolean::class)
object Double : Scalar(kotlin.Double::class)
object Float : Scalar(kotlin.Float::class)
}

private sealed class Boxed(
override val inlineRepresentation: KClass<*>,
override val defaultValue: CodeBlock = CodeBlock.of("null")
override val inlineRepresentation: KClass<*>
) : Scalar() {
override val kotlinRepresentation
get() = inlineRepresentation.declaredMemberProperties
.single { it.name == com.toasttab.protokt.rt.Fixed32::value.name }
.returnType
.classifier as KClass<*>

object Fixed32 : Boxed(com.toasttab.protokt.rt.Fixed32::class, defaultValue = CodeBlock.of("0"))
object Fixed64 : Boxed(com.toasttab.protokt.rt.Fixed64::class, defaultValue = CodeBlock.of("0L"))
object Int32 : Boxed(com.toasttab.protokt.rt.Int32::class, defaultValue = CodeBlock.of("0"))
object Int64 : Boxed(com.toasttab.protokt.rt.Int64::class, defaultValue = CodeBlock.of("0L"))
object SFixed32 : Boxed(com.toasttab.protokt.rt.SFixed32::class, defaultValue = CodeBlock.of("0"))
object SFixed64 : Boxed(com.toasttab.protokt.rt.SFixed64::class, defaultValue = CodeBlock.of("0L"))
object SInt32 : Boxed(com.toasttab.protokt.rt.SInt32::class, defaultValue = CodeBlock.of("0"))
object SInt64 : Boxed(com.toasttab.protokt.rt.SInt64::class, defaultValue = CodeBlock.of("0L"))
object UInt32 : Boxed(com.toasttab.protokt.rt.UInt32::class, defaultValue = CodeBlock.of("0"))
object UInt64 : Boxed(com.toasttab.protokt.rt.UInt64::class, defaultValue = CodeBlock.of("0L"))
object Fixed32 : Boxed(com.toasttab.protokt.rt.Fixed32::class)
object Fixed64 : Boxed(com.toasttab.protokt.rt.Fixed64::class)
object Int32 : Boxed(com.toasttab.protokt.rt.Int32::class)
object Int64 : Boxed(com.toasttab.protokt.rt.Int64::class)
object SFixed32 : Boxed(com.toasttab.protokt.rt.SFixed32::class)
object SFixed64 : Boxed(com.toasttab.protokt.rt.SFixed64::class)
object SInt32 : Boxed(com.toasttab.protokt.rt.SInt32::class)
object SInt64 : Boxed(com.toasttab.protokt.rt.SInt64::class)
object UInt32 : Boxed(com.toasttab.protokt.rt.UInt32::class)
object UInt64 : Boxed(com.toasttab.protokt.rt.UInt64::class)
}