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

PHP TL GEN: PART 2 #60

Merged
merged 37 commits into from
Jan 22, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
259cb2e
add new flag + moved files to _php
Brat-vseznamus Dec 23, 2024
032f719
read draft
Brat-vseznamus Dec 28, 2024
af5012d
field mask and reset fix
Brat-vseznamus Dec 28, 2024
be0e711
fix basictl location
Brat-vseznamus Jan 9, 2025
97cb123
union and maybe fix in read
Brat-vseznamus Jan 9, 2025
77d4e82
add meta support
Brat-vseznamus Jan 12, 2025
5c21920
add factory
Brat-vseznamus Jan 12, 2025
901f63a
add write methods
Brat-vseznamus Jan 13, 2025
6ed793d
fix 64 long and true write
Brat-vseznamus Jan 13, 2025
616329e
success fix
Brat-vseznamus Jan 13, 2025
34cdbbb
move rpc stuff under feature, same for choosing to generate only used…
Brat-vseznamus Jan 14, 2025
848c3be
add simplication fature
Brat-vseznamus Jan 14, 2025
75fb0a7
fix tuple write + dictionary smth
Brat-vseznamus Jan 15, 2025
9128a3c
full include in factory, who cares
Brat-vseznamus Jan 15, 2025
1389ce8
fieldmask fix + tuple size
Brat-vseznamus Jan 15, 2025
d967b86
dictionary additional support
Brat-vseznamus Jan 15, 2025
b7e68dc
fix different read/write issues
Brat-vseznamus Jan 15, 2025
2debf9b
add cases gen to php
Brat-vseznamus Jan 15, 2025
f03af6c
push test on cases
Brat-vseznamus Jan 15, 2025
6b631d8
push makefile
Brat-vseznamus Jan 15, 2025
a72d11f
make more simple to use makefile + clen debug
Brat-vseznamus Jan 16, 2025
398b1a4
fix arguments push
Brat-vseznamus Jan 20, 2025
df10b53
removed debug
Brat-vseznamus Jan 20, 2025
27848dd
remove unnecessary inits
Brat-vseznamus Jan 20, 2025
97a90bd
make names for array objects more short + add comments below them
Brat-vseznamus Jan 20, 2025
a000495
fix colors in tests
Brat-vseznamus Jan 20, 2025
4d183e2
sort json
Brat-vseznamus Jan 21, 2025
9647fa3
change order
Brat-vseznamus Jan 21, 2025
9d10447
add system to add new tests for cases
Brat-vseznamus Jan 21, 2025
36ca8f5
fix in arguments for php
Brat-vseznamus Jan 21, 2025
c8b8b2b
add new tests
Brat-vseznamus Jan 21, 2025
2aa257d
update test
Brat-vseznamus Jan 21, 2025
7737a12
multi lang testing
Brat-vseznamus Jan 21, 2025
8628c27
fix multi lang testing with cpp
Brat-vseznamus Jan 21, 2025
a02a3fa
staticcheck fix
Brat-vseznamus Jan 21, 2025
1106272
add files
Brat-vseznamus Jan 21, 2025
1aa7084
return !== null to restore compatibility with og version
Brat-vseznamus Jan 22, 2025
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
4 changes: 4 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,10 @@ cpp:
$(MAKE) cpp_gen
$(MAKE) cpp_build

.PHONY: test_multi_lang_cases
test_multi_lang_cases:
@cd internal/tlcodegen/test/codegen_test/; \
$(MAKE) run-all-languages-tests;

.PHONY: test
test:
Expand Down
17 changes: 17 additions & 0 deletions cmd/tlgen/main2.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,23 @@ func parseFlags(opt *tlcodegen.Gen2Options) {
flag.StringVar(&opt.RootCPPNamespace, "cpp-namespace", "",
`c++ root namespace, separated by '::' if more than 1 element`)

// PHP
flag.BoolVar(&opt.AddFunctionBodies, "php-serialization-bodies", false,
`whether to generate body to write/read generated structs and functions`)
flag.BoolVar(&opt.AddMetaData, "php-generate-meta", false,
`whether to generate methods to get meta information about tl objects`)
flag.BoolVar(&opt.AddFactoryData, "php-generate-factory", false,
`whether to generate factory of tl objects`)
flag.BoolVar(&opt.IgnoreUnusedInFunctionsTypes, "php-ignore-unused-types", true,
`whether to not generate types without usages in functions`)
flag.BoolVar(&opt.AddRPCTypes, "php-rpc-support", true,
`whether to generate special rpc types`)
flag.BoolVar(&opt.InplaceSimpleStructs, "php-inplace-simple-structs", true,
`whether to avoid generation of structs with no arguments and only 1 field`)

if opt.AddFactoryData {
opt.AddFunctionBodies = true
}
// .tlo
flag.StringVar(&opt.TLOPath, "tloPath", "",
"whether to serialize TL schema in binary form")
Expand Down
79 changes: 73 additions & 6 deletions internal/tlcodegen/helpers_php.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package tlcodegen

const BasicTlPathPhp = "basictl.php"
const BasicTLCodePHP = `
<?php
include "run.php";
const BasicTlPathPHP = "tl_streams.php"
const BasicTLCodePHP = `<?php

namespace VK\TL;

class tl_constants {
const tinyStringLen = 253;
Expand Down Expand Up @@ -54,6 +54,17 @@ class tl_input_stream {
}
}

/** @return tuple(int, bool) */
public function read_int64() {
$data = unpack('q', $this->data, $this->offset);
if (!$data) {
return [0, false];
} else {
$this->offset += 8;
return [$data[1], true];
}
}

/** @return tuple(bool, bool) */
public function read_bool(int $false_tag, $true_tag) {
[$tag, $success] = $this->read_uint32();
Expand Down Expand Up @@ -117,7 +128,7 @@ class tl_input_stream {
return ["", false];
}
$l64 = (ord($this->data[$this->offset + 7]) << 48) + (ord($this->data[$this->offset + 6]) << 40) + (ord($this->data[$this->offset + 5]) << 32) + (ord($this->data[$this->offset + 4]) << 24) + (ord($this->data[$this->offset + 3]) << 16) + (ord($this->data[$this->offset + 2]) << 8) + (ord($this->data[$this->offset + 1]) << 0);
// TODO: check l64 > maxint
// TODO: check l64 > max int
$l = $l64;
$this->offset += 8;
$p = $l;
Expand Down Expand Up @@ -157,31 +168,48 @@ class tl_output_stream {
public function get_data(): string {
return $this->data;
}


/** @return bool */
public function write_uint32(int $value) {
$this->data .= pack('V', $value);
return true;
}

/** @return bool */
public function write_int32(int $value) {
$this->data .= pack('l', $value);
return true;
}

/** @return bool */
public function write_int64(int $value) {
$this->data .= pack('q', $value);
return true;
}

/** @return bool */
public function write_bool(bool $value, int $false_tag, $true_tag) {
if ($value) {
$this->data .= pack('V', $true_tag);
} else {
$this->data .= pack('V', $false_tag);
}
return true;
}

/** @return bool */
public function write_float(float $value) {
$this->data .= pack('f', $value);
return true;
}

/** @return bool */
public function write_double(float $value) {
$this->data .= pack('d', $value);
return true;
}

/** @return bool */
public function write_string(string $value) {
$l = strlen($value);
$p = 0;
Expand Down Expand Up @@ -220,6 +248,7 @@ class tl_output_stream {
} else if ($p % 4 == 3) {
$this->data .= chr(0);
}
return true;
}
}
?>
Expand Down Expand Up @@ -297,3 +326,41 @@ interface RpcResponse {

#endif
`

const TLInterfacesPathPHP = "tl_interfaces.php"
const TLInterfacesCodePHP = `<?php

namespace VK\TL;

use VK\TL;

interface Readable {
/**
* @param TL\tl_input_stream $stream
* @return bool
*/
public function read($stream);

/**
* @param TL\tl_input_stream $stream
* @return bool
*/
public function read_boxed($stream);
}

interface Writeable {
/**
* @param TL\tl_output_stream $stream
* @return bool
*/
public function write($stream);

/**
* @param TL\tl_output_stream $stream
* @return bool
*/
public function write_boxed($stream);
}

interface TL_Object extends Readable, Writeable {}
`
16 changes: 16 additions & 0 deletions internal/tlcodegen/test/codegen_test/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@

run-all-languages-tests:
make run-php-tests; \
make run-cpp-tests; \
make run-golang-tests;

run-php-tests:
cd php && make run-all-tests

run-cpp-tests:
cd cpp && make run-all-tests

run-golang-tests:
cd ../../../.. && make goldmaster_nocompile;
cd golang;
go test ./...
184 changes: 0 additions & 184 deletions internal/tlcodegen/test/codegen_test/casetests/bytes_read_test.go

This file was deleted.

12 changes: 9 additions & 3 deletions internal/tlcodegen/test/codegen_test/cpp/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,16 @@ SCHEMA_DIR = $(CPP_DIR)/schema_cpp
CC = g++
CFLAGS = -std=c++17 -O3 -Wno-noexcept-type -g -Wall -Wextra -Werror=return-type -Wno-unused-parameter

build-test-gen:
@cd ../../../../../; \
$(MAKE) build; \
$(MAKE) cpp_gen_test_data;

# run in project root "make cpp_gen_test_data"
run-all-tests:
make run-objects-test
make run-functions-test
run-all-tests: build-test-gen
make run-objects-test; \
make run-functions-test; \
make clean-build;

clean-build:
rm -rf build
Expand Down
Loading
Loading