|
19 | 19 | namespace danog\MadelineProto\FileRefExtractor\Ops; |
20 | 20 |
|
21 | 21 | use danog\MadelineProto\FileRefExtractor\ActionOp; |
| 22 | +use danog\MadelineProto\FileRefExtractor\BuildMode\Ast; |
| 23 | +use danog\MadelineProto\FileRefExtractor\BuildMode\Flat; |
22 | 24 | use danog\MadelineProto\FileRefExtractor\TLContext; |
23 | 25 | use danog\MadelineProto\FileRefExtractor\TypedOp; |
24 | 26 | use Webmozart\Assert\Assert; |
@@ -64,48 +66,64 @@ public static function simple(string $method, string $constructor, array $args): |
64 | 66 | return new CallOp($method, $final); |
65 | 67 | } |
66 | 68 |
|
67 | | - public function build(TLContext $tl): array |
| 69 | + public function build(TLContext $tl): void |
68 | 70 | { |
69 | 71 | $final = []; |
70 | 72 | $tl->validateParams($this->method, false, $this->args); |
| 73 | + $types = []; |
71 | 74 | foreach ($this->args as $from => $to) { |
72 | 75 | $final[$from] = $to->build($tl); |
73 | | - } |
74 | | - $hasBackref = (bool) $tl->tl->backrefs; |
75 | | - if (!$hasBackref) { |
76 | | - $tl->tl->backrefs[$this->method] = true; |
| 76 | + $types[$from] = $to->getType($tl); |
77 | 77 | } |
78 | 78 |
|
79 | | - foreach ($tl->tl->backrefs as $cons => $_) { |
80 | | - $tl->tl->actionsPre[$cons] ??= []; |
81 | | - array_unshift($tl->tl->actionsPre[$cons], [ |
82 | | - 'op' => 'pushContext', |
83 | | - 'ctx' => $tl->contextName, |
84 | | - ]); |
| 79 | + $out = $tl->buildMode; |
| 80 | + if ($out instanceof Flat) { |
| 81 | + foreach ($out->backrefs as $cons => $type) { |
| 82 | + $out->actionsPre[$cons] ??= []; |
| 83 | + array_unshift($out->actionsPre[$cons], [ |
| 84 | + 'op' => 'pushContext', |
| 85 | + 'ctx' => $out->contextName, |
| 86 | + ]); |
85 | 87 |
|
86 | | - $tl->tl->actionsPost[$cons] ??= []; |
87 | | - array_push($tl->tl->actionsPost[$cons], [ |
88 | | - 'op' => 'popAndProcessContext', |
89 | | - 'ctx' => $tl->contextName, |
90 | | - ]); |
91 | | - } |
| 88 | + $out->actionsPost[$cons] ??= []; |
| 89 | + array_push($out->actionsPost[$cons], [ |
| 90 | + 'op' => 'processContext', |
| 91 | + 'ctx' => $out->contextName, |
| 92 | + 'method' => $this->method, |
| 93 | + 'args' => $final, |
| 94 | + ]); |
| 95 | + array_push($out->actionsPost[$cons], [ |
| 96 | + 'op' => 'popContext', |
| 97 | + 'ctx' => $out->contextName, |
| 98 | + ]); |
| 99 | + } |
92 | 100 |
|
93 | | - if ($hasBackref) { |
94 | | - $tl->tl->actionsPost[$cons][] = [ |
| 101 | + $out->actionsPost[$cons][] = [ |
95 | 102 | 'op' => 'processContext', |
96 | | - 'ctx' => $tl->contextName, |
| 103 | + 'ctx' => $out->contextName, |
| 104 | + 'method' => $this->method, |
| 105 | + 'args' => $final, |
97 | 106 | ]; |
98 | | - $tl->tl->actionsPost[$cons][] = [ |
99 | | - 'op' => 'deleteContextEntries', |
100 | | - 'ctx' => $tl->contextName, |
101 | | - 'entries' => array_keys($final), |
| 107 | + if ($hasBackref) { |
| 108 | + $out->actionsPost[$cons][] = [ |
| 109 | + 'op' => 'deleteContextEntries', |
| 110 | + 'ctx' => $out->contextName, |
| 111 | + 'entries' => array_keys($final), |
| 112 | + ]; |
| 113 | + } else { |
| 114 | + $out->actionsPost[$cons][] = [ |
| 115 | + 'op' => 'popContext', |
| 116 | + 'ctx' => $out->contextName, |
| 117 | + ]; |
| 118 | + } |
| 119 | + } else { |
| 120 | + assert($out instanceof Ast); |
| 121 | + $out->output[$tl->position][] = [ |
| 122 | + 'op' => 'call', |
| 123 | + 'method' => $this->method, |
| 124 | + 'args' => $final, |
| 125 | + 'needsMethod' => $out->needsMethod |
102 | 126 | ]; |
103 | 127 | } |
104 | | - |
105 | | - return [ |
106 | | - 'op' => 'call', |
107 | | - 'method' => $this->method, |
108 | | - 'args' => $final, |
109 | | - ]; |
110 | 128 | } |
111 | 129 | } |
0 commit comments