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
Remove sizeof stringtemplates.
  • Loading branch information
pranjalvachaspati-toast committed Oct 15, 2021
commit f12ca3ce4b8d74149b41431041162a9766181452
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,6 @@ import com.toasttab.protokt.codegen.protoc.Oneof
import com.toasttab.protokt.codegen.protoc.StandardField
import com.toasttab.protokt.codegen.template.ConditionalParams
import com.toasttab.protokt.codegen.template.Message.Message.SizeofInfo
import com.toasttab.protokt.codegen.template.Renderers.IterationVar
import com.toasttab.protokt.codegen.template.Renderers.Sizeof
import com.toasttab.protokt.codegen.template.Renderers.Sizeof.Options

internal class MessageSizeAnnotator
private constructor(
Expand Down Expand Up @@ -158,18 +155,29 @@ private constructor(
} else {
interceptSizeof(f, f.fieldName, ctx)
}
return Sizeof.render(
name = name,
field = f,
type = f.unqualifiedNestedTypeName(ctx),
options = Options(
fieldSizeof = interceptFieldSizeof(f, name, ctx),
fieldAccess = interceptValueAccess(f, ctx, IterationVar.render()),
keyAccess = mapKeyConverter(f, ctx),
valueAccess = mapValueConverter(f, ctx),
valueType = f.mapEntry?.value?.type
)
)

return when {
f.map -> sizeOfMap(f, name)
f.repeated && f.packed -> """
|sizeof(Tag(${f.number})) +
| $name
| .sumOf { sizeof(${f.box("it")}) }
| .let { it + sizeof(UInt32(it)) }
""".trimMargin()
f.repeated ->
"(sizeof(Tag(${f.number})) * $name.size) + " +
"$name.sumOf { sizeof(${f.box(interceptValueAccess(f, ctx, "it"))}) }"
else -> "sizeof(Tag(${f.number})) + ${interceptFieldSizeof(f, name, ctx)}"
}
}

private fun sizeOfMap(f: StandardField, name: String): String {
val key = mapKeyConverter(f, ctx)?.let { "$it.unwrap(k)" } ?: "k"
val value = mapValueConverter(f, ctx)?.let { "$it.unwrap(v)" }?.let { f.maybeConstructBytes(it) } ?: "v"
return """
|sizeofMap($name, Tag(${f.number})) { k, v ->
| ${f.unqualifiedNestedTypeName(ctx)}.sizeof($key, $value)
|}""".trimMargin()
}

private fun oneofSize(f: Oneof, type: String) =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ internal fun StandardField.boxMap(ctx: Context): String {
return "${unqualifiedNestedTypeName(ctx)}($keyParam, $valParam)"
}

private fun StandardField.maybeConstructBytes(arg: String) = when (mapEntry!!.value.type) {
internal fun StandardField.maybeConstructBytes(arg: String) = when (mapEntry!!.value.type) {
FieldType.BYTES -> "Bytes($arg)"
else -> arg
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import arrow.core.Option
import arrow.core.Some
import arrow.core.memoize
import com.toasttab.protokt.codegen.annotators.Annotator.Context
import com.toasttab.protokt.codegen.annotators.box
import com.toasttab.protokt.codegen.impl.ClassLookup.converters
import com.toasttab.protokt.codegen.impl.ClassLookup.getClass
import com.toasttab.protokt.codegen.impl.WellKnownTypes.wrapWithWellKnownInterception
Expand All @@ -35,7 +36,6 @@ import com.toasttab.protokt.codegen.template.Options.DefaultBytesSlice
import com.toasttab.protokt.codegen.template.Options.ReadBytesSlice
import com.toasttab.protokt.codegen.template.Options.Sizeof
import com.toasttab.protokt.codegen.template.Options.WrapField
import com.toasttab.protokt.codegen.template.Renderers.FieldSizeof
import com.toasttab.protokt.ext.OptimizedSizeofConverter
import kotlin.reflect.KClass

Expand Down Expand Up @@ -122,10 +122,7 @@ object Wrapper {
f.foldFieldWrap(
ctx,
{
FieldSizeof.render(
field = f,
name = s
)
"sizeof(${f.box(s)})"
},
{ wrapper, wrapped ->
if (
Expand All @@ -134,10 +131,7 @@ object Wrapper {
) {
"${unqualifiedConverterWrap(wrapper, wrapped, ctx)}.${Sizeof.render(arg = s)}"
} else {
FieldSizeof.render(
field = f,
name = s
)
"sizeof(${f.box(s)})"
}
}
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ abstract class RenderersTemplate : StTemplate(StGroup.Renderers)

object Renderers {


object IterationVar : NoParamStTemplate(StGroup.Renderers)

object Serialize : RenderersTemplate() {
Expand Down
2 changes: 2 additions & 0 deletions protokt-codegen/src/main/resources/renderers.stg
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,8 @@ deserialize(field, read, lhs, options, packed) ::= <%
<endif>
%>

box(type, def) ::= "<if (type.boxed)><type.boxer>(<def>)<else><def><endif>"

deserializeMap() ::= <%
(<lhs> ?: mutableMapOf()).apply {<\n>
<\ ><\ ><t()><t()>deserializer.readRepeated(false) {<\n>
Expand Down