Skip to content

Commit 793563a

Browse files
committed
Simplify
1 parent b3dd47b commit 793563a

6 files changed

Lines changed: 53 additions & 24 deletions

File tree

src/TL_file_ref_map_schema.tl

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
11
// Root
2-
fileReferenceOrigins#fe633fe7 db_schema:string db_schema_json:string ctxs:Vector<Origin> = FileReferenceOrigins;
2+
fileReferenceOrigins#45a1a693 db_schema:string db_schema_json:string ctxs:Vector<Origin> skipped:Vector<SkippedOrigin>= FileReferenceOrigins;
33

4-
origin#72cc7c04 flags:# predicate:string is_constructor:flags.0?true action:ActionOp needs_parent:flags.3?string parent_is_constructor:flags.4?true = origin;
4+
origin#24443b33 flags:# predicate:string is_constructor:flags.0?true action:ActionOp stored_constructor:string skipped_flags:Vector<string> needs_parent:flags.3?string parent_is_constructor:flags.4?true = origin;
55

6-
// For string => TypedOp dictionaries
7-
typedOpArg#3a2930c2 key:string value:TypedOp = TypedOpArg;
6+
skippedOrigin#7c62809e flags:# predicate:string is_constructor:flags.0?true why:string = SkippedOrigin;
87

98
// Actions
10-
callOp#95a107ea method:string args:Vector<TypedOpArg> stored_constructor:string skipped_flags:Vector<string> = ActionOp;
11-
getMessageOp#defc2466 flags:# peer:TypedOp id:TypedOp from_scheduled:flags.0?TypedOp stored_constructor:string skipped_flags:Vector<string> = ActionOp;
12-
noOp#c4d8df73 why:string = ActionOp;
9+
callOp#c2ff3383 method:string args:Vector<TypedOpArg> = ActionOp;
10+
getMessageOp#84b69f70 flags:# peer:TypedOp id:TypedOp from_scheduled:flags.0?TypedOp = ActionOp;
11+
12+
// For string => TypedOp dictionaries
13+
typedOpArg#3a2930c2 key:string value:TypedOp = TypedOpArg;
1314

1415
// Field extraction path
1516
paramNotFlag#acd9d5cf = ParamFlag;

src/file_ref_map.dat

-44 Bytes
Binary file not shown.

src/file_ref_map.json

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

tools/FileRefExtractor/BuildMode/Ast.php

Lines changed: 27 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ final class Ast implements BuildMode
3939
public ?string $curKey = null;
4040

4141
private array $output = [];
42+
private array $skipped = [];
4243
private ?string $needsParent = null;
4344

4445
public function __construct(
@@ -67,6 +68,7 @@ public function finalize(string $refMapFile, string $refMapFileJson): void
6768
'db_schema' => $dbSchema,
6869
'db_schema_json' => json_encode($dbSchemaJSON, flags: JSON_THROW_ON_ERROR),
6970
'ctxs' => $this->output,
71+
'skipped' => $this->skipped,
7072
];
7173
Magic::start(false);
7274

@@ -76,6 +78,8 @@ public function finalize(string $refMapFile, string $refMapFileJson): void
7678
$TL->init($s);
7779
$serialized = $TL->serializeObject(['type' => 'FileReferenceOrigins'], $value, '');
7880
$valueDe = $TL->deserialize($serialized, ['type' => '', 'connection' => null, 'encrypted' => true]);
81+
file_put_contents('/tmp/a.json', json_encode($valueDe, flags: JSON_THROW_ON_ERROR));
82+
file_put_contents('/tmp/b.json', json_encode($value, flags: JSON_THROW_ON_ERROR));
7983
Assert::true($value == $valueDe);
8084
file_put_contents($refMapFile, $serialized);
8185
file_put_contents($refMapFileJson, json_encode($valueDe, flags: JSON_THROW_ON_ERROR));
@@ -104,21 +108,11 @@ private static function stringifySchema(string $constructor, array $params): str
104108
}
105109
public function addNode(TLContext $ctx, ?array $action = null, ?string $why = null): void
106110
{
107-
$out = [
108-
'_' => 'origin',
109-
'predicate' => $ctx->position,
110-
'is_constructor' => $ctx->isConstructor,
111-
'parent_is_constructor' => false,
112-
];
113-
if ($this->needsParent !== null) {
114-
$out['needs_parent'] = $this->needsParent;
115-
$out['parent_is_constructor'] = $ctx->tl->isConstructor($this->needsParent);
116-
}
117111
if ($action !== null) {
118112
Assert::keyExists($action, 'stored_constructor');
119113

120114
$constructor = $action['stored_constructor'];
121-
$action['skipped_flags'] = [];
115+
unset($action['stored_constructor']);
122116

123117
$names = $this->storedNames;
124118
$flags = [];
@@ -133,6 +127,7 @@ public function addNode(TLContext $ctx, ?array $action = null, ?string $why = nu
133127
...$names,
134128
];
135129
}
130+
$skipped = [];
136131

137132
if (isset($this->outputSchema[$constructor])) {
138133
$existing = $this->outputSchema[$constructor];
@@ -141,7 +136,7 @@ public function addNode(TLContext $ctx, ?array $action = null, ?string $why = nu
141136
if (isset($flags[$name])) {
142137
unset($flags[$name], $names[$name]);
143138
} else {
144-
$action['skipped_flags'][]= $name;
139+
$skipped[]= $name;
145140
}
146141
}
147142
}
@@ -166,22 +161,39 @@ public function addNode(TLContext $ctx, ?array $action = null, ?string $why = nu
166161
$this->outputSchema[$constructor] = $names;
167162
}
168163

169-
$out['action'] = $action;
164+
$out = [
165+
'_' => 'origin',
166+
'predicate' => $ctx->position,
167+
'is_constructor' => $ctx->isConstructor,
168+
'action' => $action,
169+
'stored_constructor' => $constructor,
170+
'skipped_flags' => $skipped,
171+
'parent_is_constructor' => false,
172+
];
173+
if ($this->needsParent !== null) {
174+
$out['needs_parent'] = $this->needsParent;
175+
$out['parent_is_constructor'] = $ctx->tl->isConstructor($this->needsParent);
176+
}
177+
$this->output[] = $out;
170178

171179
$this->storedFlags = 0;
172180
$this->stored = [];
173181
$this->storedNames = [];
174182
Assert::null($why);
175183
} elseif ($why !== null) {
176-
$out['action'] = ['_' => 'noOp', 'why' => $why];
184+
$this->skipped[] = [
185+
'_' => 'skippedOrigin',
186+
'why' => $why,
187+
'predicate' => $ctx->position,
188+
'is_constructor' => $ctx->isConstructor,
189+
];
177190
Assert::null($action);
178191
Assert::isEmpty($this->stored);
179192
Assert::isEmpty($this->storedNames);
180193
Assert::eq($this->storedFlags, 0);
181194
} else {
182195
throw new AssertionError("Either 'action' or 'why' must be provided.");
183196
}
184-
$this->output[] = $out;
185197
$this->needsParent = null;
186198
$this->curKey = null;
187199
}

tools/gen_filerefmap.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,20 @@ function generate(int $layer, string $schema) {
6060
);
6161
}
6262

63+
if (isset($argv[1])) {
64+
if (count($argv) < 4) {
65+
die("Usage:\n{$argv[0]} <inputSchema> <output> <outputJson>\nOR\n{$argv[0]} (no args, uses schemas in schemas folder)\n");
66+
}
67+
68+
FileRefGenerator::generate(
69+
$layer,
70+
$argv[1],
71+
$argv[2],
72+
$argv[3],
73+
);
74+
die;
75+
}
76+
6377
$res = [];
6478
foreach (glob(getcwd().'/schemas/TL_telegram_*_file_ref_map.json') as $file) {
6579
preg_match("/telegram_v(\d+)/", $file, $matches);
@@ -78,4 +92,6 @@ function generate(int $layer, string $schema) {
7892
}
7993
ksort($res);
8094

95+
generate($last, $schema);
96+
8197
file_put_contents(getcwd().'/schemas/list_file_ref_map.json', json_encode(array_keys($res)));

0 commit comments

Comments
 (0)