Skip to content

Commit 5122f4b

Browse files
committed
Finalize
1 parent 652d9d5 commit 5122f4b

14 files changed

+153
-101
lines changed

src/TL/TL.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ public function &getDescriptionsRef(): array
160160
*/
161161
public function init(TLSchema $files, array $objects = []): void
162162
{
163-
$this->API?->logger?->logger('Loading TL schemes...', Logger::VERBOSE);
163+
//$this->API?->logger?->logger('Loading TL schemes...', Logger::VERBOSE);
164164
$this->updateCallbacks($objects);
165165
$this->constructors = new TLConstructors();
166166
$this->methods = new TLMethods();
@@ -171,7 +171,7 @@ public function init(TLSchema $files, array $objects = []): void
171171
'secret' => $files->getSecretSchema(),
172172
...$files->getOther(),
173173
]) as $scheme_type => $file) {
174-
$this->API?->logger?->logger(sprintf(Lang::$current_lang['file_parsing'], basename($file)), Logger::VERBOSE);
174+
//$this->API?->logger?->logger(sprintf(Lang::$current_lang['file_parsing'], basename($file)), Logger::VERBOSE);
175175
$filec = file_get_contents(Tools::absolute($file));
176176
$TL_dict = json_decode($filec, true);
177177
if ($TL_dict === null) {
@@ -195,14 +195,14 @@ public function init(TLSchema $files, array $objects = []): void
195195
if (empty($TL_dict) || empty($TL_dict['constructors']) || !isset($TL_dict['methods'])) {
196196
throw new Exception(Lang::$current_lang['src_file_invalid'].$file);
197197
}
198-
$this->API?->logger?->logger('Translating objects...', Logger::ULTRA_VERBOSE);
198+
//$this->API?->logger?->logger('Translating objects...', Logger::ULTRA_VERBOSE);
199199
foreach ($TL_dict['constructors'] as $elem) {
200200
if ($scheme_type === 'secret') {
201201
$this->secretLayer = max($this->secretLayer, $elem['layer']);
202202
}
203203
$this->constructors->add($elem, $scheme_type);
204204
}
205-
$this->API?->logger?->logger('Translating methods...', Logger::ULTRA_VERBOSE);
205+
//$this->API?->logger?->logger('Translating methods...', Logger::ULTRA_VERBOSE);
206206
foreach ($TL_dict['methods'] as $elem) {
207207
$this->methods->add($elem, $scheme_type);
208208
if ($scheme_type === 'secret') {

src/TL_filerefs.tl

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
// Root
2+
fileReferenceOrigins ctxs:Vector<Origin> = FileReferenceOrigins;
3+
4+
origin flags:# predicate:string is_constructor:flags.0?true action:flags.1?ActionOp noop:flags.2?string = origin;
5+
6+
// For string => TypedOp dictionaries
7+
typedOpArg key:string value:TypedOp = TypedOpArg;
8+
9+
// Actions
10+
callOp method:string args:Vector<TypedOpArg> = ActionOp;
11+
getMessageOp flags:# peer:TypedOp id:TypedOp from_scheduled:flags.0?TypedOp = ActionOp;
12+
13+
// Field extraction path
14+
pathPart flags:# constructor:string param:string flag_abort_if_empty:flags.0?true flag_fallback_if_empty:flags.1?TypedOp flag_passthrough:flags.2?true unpack_vector:flags.3?true = PathPart;
15+
16+
path parts:Vector<PathPart> = Path;
17+
18+
// Typed constructors, the type is specified to simplify codegen,
19+
// but isn't strictly necessary as it can be inferred from the TypedOpOp.
20+
// It is fully pre-validated during the generation of the definition file.
21+
typedOp type:string op:TypedOpOp = TypedOp;
22+
23+
copyOp path:Path = TypedOpOp;
24+
25+
getInputChannelByIdOp path:Path = TypedOpOp;
26+
getInputUserByIdOp path:Path = TypedOpOp;
27+
28+
getInputPeerOp path:Path = TypedOpOp;
29+
getInputUserOp path:Path = TypedOpOp;
30+
getInputChannelOp path:Path = TypedOpOp;
31+
32+
getStickerSetFromDocumentAttributesOp path:Path = TypedOpOp;
33+
34+
// Literals & constructors (methods not allowed or needed here)
35+
constructorOp constructor:string args:Vector<TypedOpArg> = TypedOpOp;
36+
37+
vectorOp values:Vector<TypedOp> = TypedOpOp;
38+
39+
intLiteralOp value:int = TypedOpOp;
40+
longLiteralOp value:long = TypedOpOp;
41+
stringLiteralOp value:string = TypedOpOp;
42+
boolLiteralOp value:Bool = TypedOpOp;
43+
floatLiteralOp value:float = TypedOpOp;
44+
themeFormatLiteralOp = TypedOpOp;

src/file_ref_map.json

Lines changed: 0 additions & 1 deletion
Large diffs are not rendered by default.

tools/FileRefExtractor/BuildMode/Ast.php

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@
2424
use danog\MadelineProto\Magic;
2525
use danog\MadelineProto\MTProto;
2626
use danog\MadelineProto\Settings\TLSchema;
27-
use danog\MadelineProto\SettingsEmpty;
2827
use danog\MadelineProto\TL\TL;
28+
use ReflectionClass;
2929
use Webmozart\Assert\Assert;
3030

3131
final class Ast implements BuildMode
@@ -45,18 +45,19 @@ public function getOutput(): array
4545

4646
$s = new TLSchema;
4747
$s = $s->setOther(['filerefs' => __DIR__ . '/../../../src/TL_filerefs.tl']);
48-
$TL = new TL(new MTProto(new SettingsEmpty));
48+
$TL = new TL((new ReflectionClass(MTProto::class))->newInstanceWithoutConstructor());
4949
$TL->init($s);
5050
$serialized = $TL->serializeObject(['type' => 'FileReferenceOrigins'], $value, '');
5151
$value = $TL->deserialize($serialized, ['type' => '', 'connection' => null, 'encrypted' => true]);
52-
return $value;
52+
return [$serialized, json_encode($value)];
5353
}
5454

5555
public function addNode(TLContext $ctx, ?array $action = null, ?string $why = null): void
5656
{
5757
$out = [
58-
'_' => $ctx->isConstructor ? 'originConstructor' : 'originMethod',
59-
$ctx->isConstructor ? 'constructor' : 'method' => $ctx->position,
58+
'_' => 'origin',
59+
'predicate' => $ctx->position,
60+
'is_constructor' => $ctx->isConstructor,
6061
//'needsParent' => $this->needsParent,
6162
];
6263
if ($action !== null) {

tools/FileRefExtractor/FieldExtractorOp.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
namespace danog\MadelineProto\FileRefExtractor;
2020

2121
use AssertionError;
22-
use danog\MadelineProto\FileRefExtractor\Ops\ExtractFromHereOp;
22+
use danog\MadelineProto\FileRefExtractor\Ops\CopyOp;
2323
use Webmozart\Assert\Assert;
2424

2525
abstract readonly class FieldExtractorOp implements TypedOp
@@ -84,7 +84,7 @@ final protected function buildPath(TLContext $tl): array
8484
final public function getType(TLContext $tl): string
8585
{
8686
$path = $this;
87-
if ($path instanceof ExtractFromHereOp) {
87+
if ($path instanceof CopyOp) {
8888
Assert::eq($tl->position, $path->path[0][0], "getTypeAtPosition: Current constructor {$tl->position} does not match expected constructor {$path->path[0][0]}");
8989
}
9090
$path = $path->path;

tools/FileRefExtractor/Ops/ArrayOp.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ public function build(TLContext $tl): array
6868
'_' => 'typedOp',
6969
'type' => $this->getType($tl),
7070
'op' => [
71-
'_' => 'arrayOp',
71+
'_' => 'vectorOp',
7272
'values' => $arr,
7373
],
7474
];

tools/FileRefExtractor/Ops/CallOp.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ public static function simple(string $method, string $constructor, array $args):
5959
$final = [];
6060
foreach ($args as $from => $to) {
6161
if (!$to instanceof TypedOp) {
62-
$to = new ExtractFromHereOp([[$constructor, $to]]);
62+
$to = new CopyOp([[$constructor, $to]]);
6363
}
6464
$final[$from] = $to;
6565
}

tools/FileRefExtractor/Ops/ConstructorOp.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ public function build(TLContext $tl): array
6767
'_' => 'typedOp',
6868
'type' => $this->getType($tl),
6969
'op' => [
70-
'_' => 'constructor',
70+
'_' => 'constructorOp',
7171
'constructor' => $this->constructor,
7272
'args' => $final,
7373
],

tools/FileRefExtractor/Ops/CopyMethodCallOp.php

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,15 +39,23 @@ public function normalize(array $stack, string $current, bool $ignoreFlag): ?\da
3939
public function build(TLContext $tl): void
4040
{
4141
Assert::eq($tl->position, $this->method, "Current constructor {$tl->position} does not match expected method {$this->method}");
42-
$tl->tl->tl->getMethods()->findByMethod($this->method)['type']; // Validate type
42+
$method = $tl->tl->tl->getMethods()->findByMethod($this->method);
4343
$out = $tl->buildMode;
4444
if ($out instanceof Ast) {
45-
$out->addNode(
46-
$tl,
47-
[
48-
'_' => 'copyMethodCall',
49-
]
45+
$args = [];
46+
foreach ($method['params'] as $arg) {
47+
if (isset($arg['pow'])) {
48+
$args[$arg['name']] = new CopyOp([[$this->method, $arg['name'], CopyOp::FLAG_PASSTHROUGH]]);
49+
} else {
50+
$args[$arg['name']] = new CopyOp([[$this->method, $arg['name']]]);
51+
}
52+
}
53+
$result = new CallOp(
54+
$this->method,
55+
$args
5056
);
57+
58+
$result->build($tl);
5159
}
5260

5361
}

tools/FileRefExtractor/Ops/ExtractFromHereOp.php renamed to tools/FileRefExtractor/Ops/CopyOp.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,13 @@
2323
use danog\MadelineProto\FileRefExtractor\TypedOp;
2424
use Webmozart\Assert\Assert;
2525

26-
final readonly class ExtractFromHereOp extends FieldExtractorOp
26+
final readonly class CopyOp extends FieldExtractorOp
2727
{
2828
public function normalize(array $stack, string $current, bool $ignoreFlag): ?\danog\MadelineProto\FileRefExtractor\TypedOp
2929
{
3030
$new = [];
3131
foreach ($this->path as $i => $part) {
32-
if ($ignoreFlag && \array_key_exists(2, $part) && \is_int($part[2]) && ($part[2] & ExtractFromHereOp::FLAG_IF_ABSENT_ABORT)) {
32+
if ($ignoreFlag && \array_key_exists(2, $part) && \is_int($part[2]) && ($part[2] & CopyOp::FLAG_IF_ABSENT_ABORT)) {
3333
return null;
3434
}
3535
if (isset($part[2]) && $part[2] instanceof TypedOp) {

0 commit comments

Comments
 (0)