⚑ Sangsakala Proxy 🏠 Home
Skip to content

Commit a5cd230

Browse files
committed
Refactor parseSignature
1 parent 4bc9f18 commit a5cd230

17 files changed

Lines changed: 106 additions & 93 deletions

File tree

β€Žsrc/Compiler/Builder/Signatures/Descriptor.phpβ€Ž

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
use PHPJava\Kernel\Types\_Int;
1111
use PHPJava\Kernel\Types\_Long;
1212
use PHPJava\Kernel\Types\_Short;
13+
use PHPJava\Kernel\Types\_Void;
1314
use PHPJava\Utilities\Formatter;
1415

1516
class Descriptor implements DescriptorInterface
@@ -50,6 +51,7 @@ static function (array $argument) {
5051
case _Long::class:
5152
case _Short::class:
5253
case _Int::class:
54+
case _Void::class:
5355
$string .= TypeResolver::resolveSignatureByType($type);
5456
break;
5557
default:

β€Žsrc/Compiler/Emulator/Traits/GeneralProcessor.phpβ€Ž

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@
88
use PHPJava\Exceptions\AssembleStructureException;
99
use PHPJava\Kernel\Maps\OpCode;
1010
use PHPJava\Kernel\Maps\VerificationTypeTag;
11+
use PHPJava\Kernel\Resolvers\TypeResolver;
12+
use PHPJava\Kernel\Types\_Int;
13+
use PHPJava\Kernel\Types\_Void;
1114
use PHPJava\Utilities\Formatter;
1215

1316
/**
@@ -35,7 +38,7 @@ public function getSignature(int $index): array
3538

3639
public function getClassName(): ?string
3740
{
38-
return $this->getSignature(2)[0]['class_name'] ?? null;
41+
return $this->getSignature(2)[0]['type'] ?? null;
3942
}
4043

4144
public function getReturnType(): ?string
@@ -45,26 +48,27 @@ public function getReturnType(): ?string
4548

4649
public function pushToOperandStackByType(string $type, string $className = null): void
4750
{
51+
if (!TypeResolver::isPrimitive($type)) {
52+
$this->accumulator->pushToOperandStack(
53+
[
54+
VerificationTypeTag::ITEM_Object,
55+
$this->getEnhancedConstantPool()
56+
->findClass($className),
57+
]
58+
);
59+
return;
60+
}
4861
// TODO: Rename parseSignature
4962
switch ($type) {
50-
case 'void':
63+
case _Void::class:
5164
break;
52-
case 'int':
65+
case _Int::class:
5366
$this->accumulator->pushToOperandStack(
5467
[
5568
VerificationTypeTag::ITEM_Integer,
5669
]
5770
);
5871
break;
59-
case 'class':
60-
$this->accumulator->pushToOperandStack(
61-
[
62-
VerificationTypeTag::ITEM_Object,
63-
$this->getEnhancedConstantPool()
64-
->findClass($className),
65-
]
66-
);
67-
break;
6872
default:
6973
throw new AssembleStructureException(
7074
'Invalid signature type: ' . $this->getReturnType()

β€Žsrc/Core/JVM/Invoker/Extended/JavaMethodFindable.phpβ€Ž

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,9 +66,7 @@ protected function findMethod(string $name, ...$arguments): _MethodInfo
6666
}
6767
if (($this->options['validation']['method']['arguments_count_only'] ?? GlobalOptions::get('validation.method.arguments_count_only') ?? Runtime::VALIDATION_METHOD_ARGUMENTS_COUNT_ONLY) === true) {
6868
$size = count($formattedArguments);
69-
$passedArgumentsSize = count(
70-
$arguments
71-
);
69+
$passedArgumentsSize = count($arguments);
7270

7371
if ($size === $passedArgumentsSize) {
7472
return $methodReference;

β€Žsrc/Core/JavaClass.phpβ€Ž

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,8 +96,7 @@ public function __toString(): string
9696
public static function load(string $classPath, array $options = [], bool $enableInstantiated = true): JavaClass
9797
{
9898
static $loaded = [];
99-
100-
$classPath = str_replace('/', '.', $classPath);
99+
$classPath = str_replace('/', '.', Formatter::convertPHPNamespacesToJava($classPath));
101100

102101
if (isset($loaded[$classPath]) && !$enableInstantiated) {
103102
return $loaded[$classPath];

β€Žsrc/Kernel/Filters/Normalizer.phpβ€Ž

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,11 @@ public static function normalizeValues($values, array $normalizeTypes)
4343
);
4444
continue;
4545
}
46-
if ($realType['type'] === 'class') {
46+
if (!TypeResolver::isPrimitive($realType['type'])) {
4747
// TODO: implements up-cast and down-cast
4848
continue;
4949
}
50-
$initiateClass = TypeResolver::TYPES_MAP[$realType['type']];
50+
$initiateClass = $realType['type'];
5151
if ($value instanceof $initiateClass) {
5252
continue;
5353
}

β€Žsrc/Kernel/Mnemonics/_bastore.phpβ€Ž

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public function execute(): void
2727
* @var Collection $arrayref
2828
*/
2929
$arrayref = $this->popFromOperandStack();
30-
if ($arrayref->getType() === 'boolean') {
30+
if ($arrayref->getType() === _Boolean::class) {
3131
$value = _Boolean::get(
3232
Normalizer::getPrimitiveValue(
3333
$value

β€Žsrc/Kernel/Mnemonics/_invokedynamic.phpβ€Ž

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
use PHPJava\Kernel\Structures\_BootstrapMethod;
1111
use PHPJava\Kernel\Structures\MethodHandleInfo;
1212
use PHPJava\Kernel\Structures\NameAndTypeInfo;
13+
use PHPJava\Kernel\Types\_Void;
1314
use PHPJava\Packages\java\lang\invoke\MethodHandles;
1415
use PHPJava\Packages\java\lang\invoke\MethodHandles\Lookup;
1516
use PHPJava\Packages\java\lang\invoke\MethodType;
@@ -119,7 +120,7 @@ public function execute(): void
119120
$methodHandledDescriptor = $cp[$methodHandleNameAndTypeConstant->getDescriptorIndex()]->getString();
120121

121122
// NOTE: Must be a class name.
122-
$methodHandleType = MethodType::methodType($signature[0]['class_name']);
123+
$methodHandleType = MethodType::methodType($signature[0]['type']);
123124

124125
$arguments = array_merge(
125126
[
@@ -175,7 +176,7 @@ public function execute(): void
175176
throw new NotImplementedException($methodHandle->getReferenceKind() . ' is not implemented in ' . __METHOD__);
176177
}
177178

178-
if ($signature[0]['type'] !== 'void') {
179+
if ($signature[0]['type'] !== _Void::class) {
179180
$this->pushToOperandStack(
180181
Normalizer::normalizeReturnValue(
181182
$result,

β€Žsrc/Kernel/Mnemonics/_invokeinterface.phpβ€Ž

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
use PHPJava\Exceptions\NoSuchCodeAttributeException;
77
use PHPJava\Kernel\Filters\Normalizer;
88
use PHPJava\Kernel\Internal\Lambda;
9+
use PHPJava\Kernel\Types\_Void;
910
use PHPJava\Packages\java\lang\NoSuchMethodException;
1011
use PHPJava\Utilities\Formatter;
1112

@@ -111,7 +112,7 @@ public function execute(): void
111112
}
112113
}
113114

114-
if ($signature[0]['type'] !== 'void') {
115+
if ($signature[0]['type'] !== _Void::class) {
115116
$this->pushToOperandStack(
116117
Normalizer::normalizeReturnValue(
117118
$result,

β€Žsrc/Kernel/Mnemonics/_invokespecial.phpβ€Ž

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
use PHPJava\Core\JavaClassInterface;
66
use PHPJava\Kernel\Filters\Normalizer;
77
use PHPJava\Kernel\Resolvers\MethodNameResolver;
8+
use PHPJava\Kernel\Types\_Void;
89
use PHPJava\Utilities\CompareTool;
910
use PHPJava\Utilities\Formatter;
1011

@@ -121,7 +122,7 @@ public function execute(): void
121122
return;
122123
}
123124

124-
if ($parsedSignature[0]['type'] !== 'void') {
125+
if ($parsedSignature[0]['type'] !== _Void::class) {
125126
$this->pushToOperandStack(
126127
Normalizer::normalizeReturnValue(
127128
$result,

β€Žsrc/Kernel/Mnemonics/_invokestatic.phpβ€Ž

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
use PHPJava\Core\JavaClass;
55
use PHPJava\Kernel\Filters\Normalizer;
6+
use PHPJava\Kernel\Types\_Void;
67
use PHPJava\Utilities\Formatter;
78

89
final class _invokestatic extends AbstractOperationCode implements OperationCodeInterface
@@ -83,7 +84,7 @@ public function execute(): void
8384
return;
8485
}
8586

86-
if ($signature[0]['type'] !== 'void') {
87+
if ($signature[0]['type'] !== _Void::class) {
8788
$this->pushToOperandStack(
8889
Normalizer::normalizeReturnValue(
8990
$result,

0 commit comments

Comments
Β (0)