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

Add union flag to function #51

Merged
merged 16 commits into from
Oct 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
17 changes: 16 additions & 1 deletion internal/tlcodegen/qt_meta.qtpl
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,10 @@ type TLItem struct {
tag uint32
annotations uint32
tlName string

resultTypeContainsUnionTypes bool
argumentsTypesContainUnionTypes bool

createFunction func() Function
createFunctionLong func() Function
createObject func() Object
Expand All @@ -162,6 +166,9 @@ func (item TLItem) CreateObject() Object { return item.createObject() }
func (item TLItem) IsFunction() bool { return item.createFunction != nil }
func (item TLItem) CreateFunction() Function { return item.createFunction() }

func (item TLItem) HasUnionTypesInResult() bool { return item.resultTypeContainsUnionTypes }
func (item TLItem) HasUnionTypesInArguments() bool { return item.argumentsTypesContainUnionTypes }

// For transcoding short-long version during Long ID transition
func (item TLItem) HasFunctionLong() bool { return item.createFunctionLong != nil }
func (item TLItem) CreateFunctionLong() Function { return item.createFunctionLong() }
Expand Down Expand Up @@ -335,14 +342,22 @@ func init() {
{%- if wr.tlTag == 0 || !wr.IsTopLevel() -%} {%- continue -%} {%- endif -%}
{%- stripspace -%}
{%- if fun, ok := wr.trw.(*TypeRWStruct); ok && len(wr.NatParams) == 0 -%}
{%- code
resultTypeContainsUnionTypes := false
argumentsTypesContainUnionTypes := false
-%}
{%- if fun.ResultType != nil -%}
{%- code
resultTypeContainsUnionTypes = fun.wr.DoesReturnTypeContainUnionTypes()
argumentsTypesContainUnionTypes = fun.wr.DoArgumentsContainUnionTypes()
-%}
fillFunction(
{%- else -%}
fillObject(
{%- endif -%}
"{%= wr.tlName.String() %}#{%s= fmt.Sprintf("%08x", wr.tlTag) %}",
{%q= fmt.Sprintf("#%08x", wr.tlTag) %},
&TLItem{tag: {%s= fmt.Sprintf("0x%08x", wr.tlTag) %}, annotations: {%s= fmt.Sprintf("0x%x", wr.AnnotationsMask()) %}, tlName: "{%= wr.tlName.String() %}"})
&TLItem{tag: {%s= fmt.Sprintf("0x%08x", wr.tlTag) %}, annotations: {%s= fmt.Sprintf("0x%x", wr.AnnotationsMask()) %}, tlName: "{%= wr.tlName.String() %}", resultTypeContainsUnionTypes: {%v= resultTypeContainsUnionTypes %}, argumentsTypesContainUnionTypes: {%v= argumentsTypesContainUnionTypes %}})
{%- endif -%}
{%- endstripspace -%}

Expand Down
19 changes: 18 additions & 1 deletion internal/tlcodegen/qt_meta.qtpl.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package codegen

import (
"github.com/stretchr/testify/assert"
"testing"
)
import "github.com/vkcom/tl/internal/tlcodegen/test/gen/goldmaster/meta"

func TestFunctionHasUnion(t *testing.T) {
{
// test type which contains union in its recursive definition
fun := meta.FactoryItemByTLName("service5.insertList")
if assert.NotNil(t, fun) {
assert.True(t, fun.IsFunction())
assert.True(t, fun.HasUnionTypesInResult())
}
}
{
// test type which doesn't contain union in its recursive definition
fun := meta.FactoryItemByTLName("usefulService.getUserEntity")
if assert.NotNil(t, fun) {
assert.True(t, fun.IsFunction())
assert.True(t, !fun.HasUnionTypesInResult())
}
}
{
// test type which contains enum in its recursive definition
fun := meta.FactoryItemByTLName("ab.call10")
if assert.NotNil(t, fun) {
assert.True(t, fun.IsFunction())
assert.True(t, fun.HasUnionTypesInResult())
}
}
}

func TestFunctionHasUnionInArguments(t *testing.T) {
{
// test type which contains union in its recursive definition
fun := meta.FactoryItemByTLName("service5.insertList")
if assert.NotNil(t, fun) {
assert.True(t, fun.IsFunction())
assert.True(t, !fun.HasUnionTypesInArguments())
}
}
{
// test type which doesn't contain union in its recursive definition
fun := meta.FactoryItemByTLName("ab.call11")
if assert.NotNil(t, fun) {
assert.True(t, fun.IsFunction())
assert.True(t, fun.HasUnionTypesInArguments())
}
}
}
Loading
Loading