Skip to content

Commit 0f70915

Browse files
committed
Use ArrayTool::concat instead of array_push
1 parent a64d8df commit 0f70915

File tree

14 files changed

+70
-48
lines changed

14 files changed

+70
-48
lines changed

src/Compiler/Lang/Assembler/MethodAssembler.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
use PHPJava\Compiler\Lang\Assembler\Traits\StatementParseable;
1515
use PHPJava\Kernel\Maps\OpCode;
1616
use PHPJava\Kernel\Types\_Void;
17+
use PHPJava\Utilities\ArrayTool;
1718

1819
/**
1920
* @method ClassAssembler getParentAssembler()
@@ -117,7 +118,7 @@ public function assemble(): void
117118
);
118119

119120
if (!empty($parsed)) {
120-
array_push(
121+
ArrayTool::concat(
121122
$operations,
122123
...$parsed
123124
);

src/Compiler/Lang/Assembler/Processors/ExpressionProcessor.php

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
use PHPJava\Kernel\Resolvers\MnemonicResolver;
2626
use PHPJava\Kernel\Types\_Int;
2727
use PHPJava\Packages\java\lang\Integer;
28+
use PHPJava\Utilities\ArrayTool;
2829

2930
class ExpressionProcessor extends AbstractProcessor implements ProcessorInterface
3031
{
@@ -55,31 +56,31 @@ public function execute(array $expressions, ?callable $callback = null): array
5556
$nodeType = get_class($expression);
5657
switch ($nodeType) {
5758
case \PhpParser\Node\Expr\Assign::class:
58-
array_push(
59+
ArrayTool::concat(
5960
$operations,
6061
...$this->assembleAssignFromNode($expression)
6162
);
6263
break;
6364
case \PhpParser\Node\Expr\PostInc::class:
64-
array_push(
65+
ArrayTool::concat(
6566
$operations,
6667
...$this->assemblePostIncFromNode($expression)
6768
);
6869
break;
6970
case \PhpParser\Node\Expr\PostDec::class:
70-
array_push(
71+
ArrayTool::concat(
7172
$operations,
7273
...$this->assemblePostDecFromNode($expression)
7374
);
7475
break;
7576
case \PhpParser\Node\Expr\Print_::class:
76-
array_push(
77+
ArrayTool::concat(
7778
$operations,
7879
...$this->assemblePrintFromNode($expression)
7980
);
8081
break;
8182
case \PhpParser\Node\Scalar\String_::class:
82-
array_push(
83+
ArrayTool::concat(
8384
$operations,
8485
...$this->assembleLoadStringFromNode(
8586
$expression,
@@ -88,7 +89,7 @@ public function execute(array $expressions, ?callable $callback = null): array
8889
);
8990
break;
9091
case \PhpParser\Node\Scalar\LNumber::class:
91-
array_push(
92+
ArrayTool::concat(
9293
$operations,
9394
...$this->assembleLoadNumber(
9495
$expression->value,
@@ -97,7 +98,7 @@ public function execute(array $expressions, ?callable $callback = null): array
9798
);
9899
break;
99100
case \PhpParser\Node\Expr\Variable::class:
100-
array_push(
101+
ArrayTool::concat(
101102
$operations,
102103
...$this->assembleLoadVariableFromNode(
103104
$expression,
@@ -106,7 +107,7 @@ public function execute(array $expressions, ?callable $callback = null): array
106107
);
107108
break;
108109
case \PhpParser\Node\Expr\ConstFetch::class:
109-
array_push(
110+
ArrayTool::concat(
110111
$operations,
111112
...$this->assembleLoadConstFromNode(
112113
$expression,
@@ -122,7 +123,7 @@ public function execute(array $expressions, ?callable $callback = null): array
122123
case \PhpParser\Node\Scalar\MagicConst\Function_::class: // __FUNCTION__
123124
case \PhpParser\Node\Scalar\MagicConst\Trait_::class: // __TRAIT__
124125
case \PhpParser\Node\Scalar\MagicConst\Line::class: // __LINE__
125-
array_push(
126+
ArrayTool::concat(
126127
$operations,
127128
...$this
128129
->assembleLoadMagicConstFromNode(
@@ -132,7 +133,7 @@ public function execute(array $expressions, ?callable $callback = null): array
132133
);
133134
break;
134135
case \PhpParser\Node\Expr\BinaryOp\Concat::class:
135-
array_push(
136+
ArrayTool::concat(
136137
$operations,
137138
...$this->execute(
138139
[
@@ -151,7 +152,7 @@ public function execute(array $expressions, ?callable $callback = null): array
151152
);
152153
break;
153154
case \PhpParser\Node\Expr\BinaryOp\BooleanAnd::class:
154-
array_push(
155+
ArrayTool::concat(
155156
$operations,
156157
...$this->assembleCalculateOperationFromNode(
157158
$expression->left,
@@ -162,7 +163,7 @@ public function execute(array $expressions, ?callable $callback = null): array
162163
);
163164
break;
164165
case \PhpParser\Node\Expr\BinaryOp\Mul::class:
165-
array_push(
166+
ArrayTool::concat(
166167
$operations,
167168
...$this->assembleCalculateOperationFromNode(
168169
$expression->left,
@@ -174,7 +175,7 @@ public function execute(array $expressions, ?callable $callback = null): array
174175
break;
175176
case \PhpParser\Node\Expr\BinaryOp\Div::class:
176177
// TODO: Add float converter
177-
array_push(
178+
ArrayTool::concat(
178179
$operations,
179180
...$this->assembleCalculateOperationFromNode(
180181
$expression->left,
@@ -185,7 +186,7 @@ public function execute(array $expressions, ?callable $callback = null): array
185186
);
186187
break;
187188
case \PhpParser\Node\Expr\BinaryOp\Minus::class:
188-
array_push(
189+
ArrayTool::concat(
189190
$operations,
190191
...$this->assembleCalculateOperationFromNode(
191192
$expression->left,
@@ -196,7 +197,7 @@ public function execute(array $expressions, ?callable $callback = null): array
196197
);
197198
break;
198199
case \PhpParser\Node\Expr\BinaryOp\Plus::class:
199-
array_push(
200+
ArrayTool::concat(
200201
$operations,
201202
...$this->assembleCalculateOperationFromNode(
202203
$expression->left,
@@ -207,7 +208,7 @@ public function execute(array $expressions, ?callable $callback = null): array
207208
);
208209
break;
209210
case \PhpParser\Node\Expr\BinaryOp\Mod::class:
210-
array_push(
211+
ArrayTool::concat(
211212
$operations,
212213
...$this->assembleCalculateOperationFromNode(
213214
$expression->left,
@@ -237,13 +238,13 @@ public function execute(array $expressions, ?callable $callback = null): array
237238
$lastRightOperand = array_slice($rightOperands, -1, 1)[0];
238239
switch ([MnemonicResolver::resolveTypeByOpCode($lastLeftOperand), MnemonicResolver::resolveTypeByOpCode($lastRightOperand)]) {
239240
case [_Int::class, _Int::class]:
240-
array_push(
241+
ArrayTool::concat(
241242
$operations,
242243
...$leftOperands,
243244
...$rightOperands
244245
);
245246

246-
array_push(
247+
ArrayTool::concat(
247248
$operations,
248249
...$this->assembleStaticCallMethodOperations(
249250
Integer::class,
@@ -256,7 +257,7 @@ public function execute(array $expressions, ?callable $callback = null): array
256257
)
257258
);
258259

259-
array_push(
260+
ArrayTool::concat(
260261
$operations,
261262
...$this->assembleConditions(
262263
[

src/Compiler/Lang/Assembler/Processors/Traits/AssignableFromNode.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
use PHPJava\Compiler\Lang\Assembler\Enhancer\ConstantPoolEnhancer;
66
use PHPJava\Compiler\Lang\Assembler\Processors\ExpressionProcessor;
77
use PHPJava\Compiler\Lang\Assembler\Store\Store;
8+
use PHPJava\Utilities\ArrayTool;
89
use PhpParser\Node;
910

1011
/**
@@ -41,7 +42,7 @@ function (array &$operations, string $nodeType, ?string $classType) use (&$expre
4142
current($expressionTypes)
4243
);
4344

44-
array_push(
45+
ArrayTool::concat(
4546
$operations,
4647
...$expressions,
4748
...$localVariableAssignOperation

src/Compiler/Lang/Assembler/Processors/Traits/OperationCalculatableFromNode.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
use PHPJava\Compiler\Builder\Attributes\Architects\Operation;
55
use PHPJava\Compiler\Builder\Finder\ConstantPoolFinder;
66
use PHPJava\Compiler\Lang\Assembler\Enhancer\ConstantPoolEnhancer;
7+
use PHPJava\Utilities\ArrayTool;
78
use PhpParser\Node;
89

910
/**
@@ -17,7 +18,7 @@ private function assembleCalculateOperationFromNode(Node $left, Node $right, int
1718
//
1819
// Right operator.
1920
$operations = [];
20-
array_push(
21+
ArrayTool::concat(
2122
$operations,
2223
...$this->execute(
2324
[

src/Compiler/Lang/Assembler/Statements/IfStatementAssembler.php

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
use PHPJava\Compiler\Lang\Assembler\Traits\ParentRecurseable;
2424
use PHPJava\Compiler\Lang\Assembler\Traits\StatementParseable;
2525
use PHPJava\Kernel\Maps\OpCode;
26+
use PHPJava\Utilities\ArrayTool;
2627

2728
/**
2829
* @method MethodAssembler getParentAssembler()
@@ -65,7 +66,7 @@ public function assemble(): array
6566
$operations
6667
);
6768

68-
array_push(
69+
ArrayTool::concat(
6970
$operations,
7071
...[
7172
ReplaceMarker::create(OpCode::_ifeq, Int16::class),
@@ -77,14 +78,14 @@ public function assemble(): array
7778
->stmts
7879
);
7980
if (!empty($nodes)) {
80-
array_push(
81+
ArrayTool::concat(
8182
$operations,
8283
...$nodes
8384
);
8485
}
8586

8687
// Jump to finish
87-
array_push(
88+
ArrayTool::concat(
8889
$operations,
8990
...[
9091
ReplaceMarker::create(OpCode::_goto, Int16::class),
@@ -105,7 +106,7 @@ public function assemble(): array
105106
$elseIfStatementOperations = [];
106107

107108
// Add condition
108-
array_push(
109+
ArrayTool::concat(
109110
$elseIfStatementOperations,
110111
...$this->bindRequired(ExpressionProcessor::factory())
111112
->execute(
@@ -118,7 +119,7 @@ public function assemble(): array
118119
$elseIfStatementOperations
119120
);
120121

121-
array_push(
122+
ArrayTool::concat(
122123
$elseIfStatementOperations,
123124
...[
124125
ReplaceMarker::create(OpCode::_ifeq, Int16::class),
@@ -133,7 +134,7 @@ public function assemble(): array
133134
]
134135
);
135136

136-
array_push(
137+
ArrayTool::concat(
137138
$operations,
138139
...$elseIfStatementOperations
139140
);
@@ -149,7 +150,7 @@ public function assemble(): array
149150
->else
150151
->stmts
151152
);
152-
array_push(
153+
ArrayTool::concat(
153154
$operations,
154155
...$elseStatementOperations
155156
);

src/Compiler/Lang/Assembler/Traits/Enhancer/Operation/Castable.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
use PHPJava\Exceptions\AssembleStructureException;
99
use PHPJava\Kernel\Types\_Int;
1010
use PHPJava\Kernel\Types\_Void;
11+
use PHPJava\Utilities\ArrayTool;
1112

1213
/**
1314
* @method ConstantPoolEnhancer getEnhancedConstantPool()
@@ -39,7 +40,7 @@ public function assembleCastToString(
3940

4041
$operations = [];
4142

42-
array_push(
43+
ArrayTool::concat(
4344
$operations,
4445
...$this->assembleClassConstructor(
4546
$objectClass,

src/Compiler/Lang/Assembler/Traits/Enhancer/Operation/ClassConstractable.php

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
use PHPJava\Compiler\Builder\Types\Uint16;
77
use PHPJava\Compiler\Lang\Assembler\Enhancer\ConstantPoolEnhancer;
88
use PHPJava\Kernel\Maps\OpCode;
9+
use PHPJava\Utilities\ArrayTool;
910

1011
/**
1112
* @method ConstantPoolEnhancer getEnhancedConstantPool()
@@ -43,12 +44,10 @@ public function assembleClassConstructor(string $classPath, string $descriptor,
4344
);
4445
}
4546

46-
if (!empty($arguments)) {
47-
array_push(
48-
$operations,
49-
...$arguments
50-
);
51-
}
47+
ArrayTool::concat(
48+
$operations,
49+
...$arguments
50+
);
5251

5352
// Call <init>
5453
$operations[] = \PHPJava\Compiler\Builder\Generator\Operation\Operation::create(

src/Compiler/Lang/Assembler/Traits/Enhancer/Operation/Conditionable.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
use PHPJava\Compiler\Builder\Types\Int16;
88
use PHPJava\Compiler\Lang\Assembler\Enhancer\ConstantPoolEnhancer;
99
use PHPJava\Kernel\Maps\OpCode;
10+
use PHPJava\Utilities\ArrayTool;
1011

1112
/**
1213
* @method ConstantPoolEnhancer getEnhancedConstantPool()
@@ -22,7 +23,7 @@ public function assembleConditions(array $ifStatementOperations, array $elseStat
2223
$operations
2324
);
2425

25-
array_push(
26+
ArrayTool::concat(
2627
$operations,
2728
...[
2829
ReplaceMarker::create(OpCode::_ifne, Int16::class),
@@ -39,7 +40,7 @@ public function assembleConditions(array $ifStatementOperations, array $elseStat
3940
) - $startOffset,
4041
];
4142

42-
array_push(
43+
ArrayTool::concat(
4344
$operations,
4445
...$elseStatementOperations
4546
);

src/Compiler/Lang/Assembler/Traits/Enhancer/Operation/MethodConstantValueReturnable.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
use PHPJava\Compiler\Lang\Assembler\Enhancer\ConstantPoolEnhancer;
99
use PHPJava\Exceptions\AssembleStructureException;
1010
use PHPJava\Kernel\Maps\OpCode;
11+
use PHPJava\Utilities\ArrayTool;
1112

1213
/**
1314
* @method ConstantPoolEnhancer getEnhancedConstantPool()
@@ -41,7 +42,7 @@ public function assembleSimpleMethodConstantValueReturn($value)
4142
);
4243
} elseif (is_int($value)) {
4344
$returnOperation = OpCode::_ireturn;
44-
array_push(
45+
ArrayTool::concat(
4546
$operations,
4647
...$this->assembleLoadNumber(
4748
$value

src/Compiler/Lang/Assembler/Traits/Enhancer/Operation/Outputable.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
use PHPJava\Compiler\Lang\Assembler\Store\Store;
1313
use PHPJava\Kernel\Maps\OpCode;
1414
use PHPJava\Kernel\Types\_Void;
15+
use PHPJava\Utilities\ArrayTool;
1516
use PHPJava\Utilities\Formatter;
1617

1718
/**
@@ -52,7 +53,7 @@ public function assembleOutput(array $expressions): array
5253
)
5354
);
5455

55-
array_push(
56+
ArrayTool::concat(
5657
$operations,
5758
...$stringConcatOperations
5859
);

0 commit comments

Comments
 (0)