Skip to content

Commit ea335b8

Browse files
authored
Merge pull request #192 from php-java/add-type-filter
Filtering types and rename info structures
2 parents 2be6b02 + bfe0b26 commit ea335b8

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+199
-143
lines changed

src/Core/JVM/ConstantPool.php

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -6,22 +6,22 @@
66
use PHPJava\Exceptions\ReadOnlyException;
77
use PHPJava\Exceptions\RuntimeException;
88
use PHPJava\Kernel\Maps\ConstantPoolTag;
9-
use PHPJava\Kernel\Structures\_Class;
10-
use PHPJava\Kernel\Structures\_Double;
11-
use PHPJava\Kernel\Structures\_Fieldref;
12-
use PHPJava\Kernel\Structures\_Float;
13-
use PHPJava\Kernel\Structures\_Integer;
14-
use PHPJava\Kernel\Structures\_InterfaceMethodref;
15-
use PHPJava\Kernel\Structures\_InvokeDynamic;
16-
use PHPJava\Kernel\Structures\_Long;
17-
use PHPJava\Kernel\Structures\_MethodHandle;
18-
use PHPJava\Kernel\Structures\_Methodref;
19-
use PHPJava\Kernel\Structures\_MethodType;
20-
use PHPJava\Kernel\Structures\_NameAndType;
21-
use PHPJava\Kernel\Structures\_String;
22-
use PHPJava\Kernel\Structures\_Utf8;
9+
use PHPJava\Kernel\Structures\ClassInfo;
10+
use PHPJava\Kernel\Structures\DoubleInfo;
11+
use PHPJava\Kernel\Structures\FieldrefInfo;
12+
use PHPJava\Kernel\Structures\FloatInfo;
2313
use PHPJava\Kernel\Structures\FreezableInterface;
14+
use PHPJava\Kernel\Structures\IntegerInfo;
15+
use PHPJava\Kernel\Structures\InterfaceMethodrefInfo;
16+
use PHPJava\Kernel\Structures\InvokeDynamicInfo;
17+
use PHPJava\Kernel\Structures\LongInfo;
18+
use PHPJava\Kernel\Structures\MethodHandleInfo;
19+
use PHPJava\Kernel\Structures\MethodrefInfo;
20+
use PHPJava\Kernel\Structures\MethodTypeInfo;
21+
use PHPJava\Kernel\Structures\NameAndTypeInfo;
22+
use PHPJava\Kernel\Structures\StringInfo;
2423
use PHPJava\Kernel\Structures\StructureInterface;
24+
use PHPJava\Kernel\Structures\Utf8Info;
2525

2626
class ConstantPool implements \ArrayAccess, \Countable, \IteratorAggregate
2727
{
@@ -51,8 +51,8 @@ public function __construct(ReaderInterface $reader, int $entries)
5151
$this->entries[$i]->execute();
5252

5353
// Java's Long and Double problem.
54-
if ($this->entries[$i] instanceof _Long ||
55-
$this->entries[$i] instanceof _Double) {
54+
if ($this->entries[$i] instanceof LongInfo ||
55+
$this->entries[$i] instanceof DoubleInfo) {
5656
$i++;
5757
}
5858
}
@@ -73,33 +73,33 @@ private function read(int $entryTag): ?StructureInterface
7373
{
7474
switch ($entryTag) {
7575
case ConstantPoolTag::CONSTANT_Class:
76-
return new _Class($this->reader);
76+
return new ClassInfo($this->reader);
7777
case ConstantPoolTag::CONSTANT_Fieldref:
78-
return new _Fieldref($this->reader);
78+
return new FieldrefInfo($this->reader);
7979
case ConstantPoolTag::CONSTANT_Methodref:
80-
return new _Methodref($this->reader);
80+
return new MethodrefInfo($this->reader);
8181
case ConstantPoolTag::CONSTANT_String:
82-
return new _String($this->reader);
82+
return new StringInfo($this->reader);
8383
case ConstantPoolTag::CONSTANT_Integer:
84-
return new _Integer($this->reader);
84+
return new IntegerInfo($this->reader);
8585
case ConstantPoolTag::CONSTANT_Float:
86-
return new _Float($this->reader);
86+
return new FloatInfo($this->reader);
8787
case ConstantPoolTag::CONSTANT_Long:
88-
return new _Long($this->reader);
88+
return new LongInfo($this->reader);
8989
case ConstantPoolTag::CONSTANT_Double:
90-
return new _Double($this->reader);
90+
return new DoubleInfo($this->reader);
9191
case ConstantPoolTag::CONSTANT_NameAndType:
92-
return new _NameAndType($this->reader);
92+
return new NameAndTypeInfo($this->reader);
9393
case ConstantPoolTag::CONSTANT_Utf8:
94-
return new _Utf8($this->reader);
94+
return new Utf8Info($this->reader);
9595
case ConstantPoolTag::CONSTANT_InterfaceMethodref:
96-
return new _InterfaceMethodref($this->reader);
96+
return new InterfaceMethodrefInfo($this->reader);
9797
case ConstantPoolTag::CONSTANT_InvokeDynamic:
98-
return new _InvokeDynamic($this->reader);
98+
return new InvokeDynamicInfo($this->reader);
9999
case ConstantPoolTag::CONSTANT_MethodHandle:
100-
return new _MethodHandle($this->reader);
100+
return new MethodHandleInfo($this->reader);
101101
case ConstantPoolTag::CONSTANT_MethodType:
102-
return new _MethodType($this->reader);
102+
return new MethodTypeInfo($this->reader);
103103
case ConstantPoolTag::CONSTANT_Module:
104104
case ConstantPoolTag::CONSTANT_Package:
105105
throw new ReadEntryException('Entry tag ' . sprintf('0x%04X', $entryTag) . ' is not implemented.');

src/Core/JavaCompiledClass.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
use PHPJava\Kernel\Resolvers\ClassResolver;
2222
use PHPJava\Kernel\Resolvers\SDKVersionResolver;
2323
use PHPJava\Kernel\Structures\_MethodInfo;
24-
use PHPJava\Kernel\Structures\_Utf8;
24+
use PHPJava\Kernel\Structures\Utf8Info;
2525
use PHPJava\Utilities\DebugTool;
2626
use PHPJava\Utilities\Formatter;
2727

@@ -84,7 +84,7 @@ class JavaCompiledClass implements JavaGenericClassInterface, JavaClassInterface
8484
private $superClassIndex = 0;
8585

8686
/**
87-
* @var null|_Utf8
87+
* @var null|Utf8Info
8888
*/
8989
private $className;
9090

src/Core/JavaSimpleClass.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
use PHPJava\Exceptions\ValidatorException;
1515
use PHPJava\Kernel\Maps\ClassAccessFlag;
1616
use PHPJava\Kernel\Resolvers\ClassResolver;
17-
use PHPJava\Kernel\Structures\_Utf8;
17+
use PHPJava\Kernel\Structures\Utf8Info;
1818
use PHPJava\Utilities\DebugTool;
1919
use PHPJava\Utilities\Formatter;
2020

@@ -42,7 +42,7 @@ class JavaSimpleClass implements JavaGenericClassInterface, JavaClassInterface
4242
private $accessFlag = 0;
4343

4444
/**
45-
* @var null|_Utf8
45+
* @var null|Utf8Info
4646
*/
4747
private $className;
4848

src/Kernel/Attributes/StackMapTableAttribute.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,15 @@ final class StackMapTableAttribute implements AttributeInterface
1414
private $numberOfEntries;
1515

1616
/**
17-
* @var \PHPJava\Kernel\Structures\_StackMapFrame[]
17+
* @var \PHPJava\Kernel\Structures\StackMapFrameInfo[]
1818
*/
1919
private $stackMapFrames = [];
2020

2121
public function execute(): void
2222
{
2323
$this->numberOfEntries = $this->readUnsignedShort();
2424
for ($i = 0; $i < $this->numberOfEntries; $i++) {
25-
$stackMapFrame = new \PHPJava\Kernel\Structures\_StackMapFrame($this->reader);
25+
$stackMapFrame = new \PHPJava\Kernel\Structures\StackMapFrameInfo($this->reader);
2626
$stackMapFrame->setConstantPool($this->getConstantPool());
2727
$stackMapFrame->setDebugTool($this->getDebugTool());
2828
$stackMapFrame->execute();
@@ -31,7 +31,7 @@ public function execute(): void
3131
}
3232

3333
/**
34-
* @return \PHPJava\Kernel\Structures\_StackMapFrame[]
34+
* @return \PHPJava\Kernel\Structures\StackMapFrameInfo[]
3535
*/
3636
public function getStackMapFrames(): array
3737
{

src/Kernel/Frames/AppendFrame.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ class AppendFrame implements FrameInterface
1717
private $offsetDelta;
1818

1919
/**
20-
* @var \PHPJava\Kernel\Structures\_VerificationTypeInfo[]
20+
* @var \PHPJava\Kernel\Structures\VerificationTypeInfo[]
2121
*/
2222
private $locals = [];
2323

@@ -26,7 +26,7 @@ public function execute(): void
2626
$this->frameType = $this->readUnsignedByte();
2727
$this->offsetDelta = $this->readUnsignedShort();
2828
for ($i = 0, $s = $this->frameType - 251; $i < $s; $i++) {
29-
$local = new \PHPJava\Kernel\Structures\_VerificationTypeInfo($this->reader);
29+
$local = new \PHPJava\Kernel\Structures\VerificationTypeInfo($this->reader);
3030
$local->execute();
3131
$this->locals[] = $local;
3232
}

src/Kernel/Frames/FullFrame.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,12 @@ class FullFrame implements FrameInterface
2727
private $numberOfStackItems;
2828

2929
/**
30-
* @var \PHPJava\Kernel\Structures\_VerificationTypeInfo
30+
* @var \PHPJava\Kernel\Structures\VerificationTypeInfo
3131
*/
3232
private $locals = [];
3333

3434
/**
35-
* @var \PHPJava\Kernel\Structures\_VerificationTypeInfo
35+
* @var \PHPJava\Kernel\Structures\VerificationTypeInfo
3636
*/
3737
private $stack = [];
3838

@@ -42,13 +42,13 @@ public function execute(): void
4242
$this->offsetDelta = $this->readUnsignedShort();
4343
$this->numberOfLocals = $this->readUnsignedShort();
4444
for ($i = 0; $i < $this->numberOfLocals; $i++) {
45-
$local = new \PHPJava\Kernel\Structures\_VerificationTypeInfo($this->reader);
45+
$local = new \PHPJava\Kernel\Structures\VerificationTypeInfo($this->reader);
4646
$local->execute();
4747
$this->locals = $local;
4848
}
4949
$this->numberOfStackItems = $this->readUnsignedShort();
5050
for ($i = 0; $i < $this->numberOfStackItems; $i++) {
51-
$stack = new \PHPJava\Kernel\Structures\_VerificationTypeInfo($this->reader);
51+
$stack = new \PHPJava\Kernel\Structures\VerificationTypeInfo($this->reader);
5252
$stack->execute();
5353
$this->stack[] = $stack;
5454
}

src/Kernel/Frames/SameLocals1StackItemFrame.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,14 @@ class SameLocals1StackItemFrame implements FrameInterface
1212
private $frameType;
1313

1414
/**
15-
* @var \PHPJava\Kernel\Structures\_VerificationTypeInfo[]
15+
* @var \PHPJava\Kernel\Structures\VerificationTypeInfo[]
1616
*/
1717
private $stack = [];
1818

1919
public function execute(): void
2020
{
2121
$this->frameType = $this->readUnsignedByte();
22-
$stack = new \PHPJava\Kernel\Structures\_VerificationTypeInfo($this->reader);
22+
$stack = new \PHPJava\Kernel\Structures\VerificationTypeInfo($this->reader);
2323
$stack->execute();
2424
$this->stack[] = $stack;
2525
}

src/Kernel/Frames/SameLocals1StackItemFrameExtended.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,15 @@ class SameLocals1StackItemFrameExtended implements FrameInterface
1717
private $offsetDelta;
1818

1919
/**
20-
* @var \PHPJava\Kernel\Structures\_VerificationTypeInfo[]
20+
* @var \PHPJava\Kernel\Structures\VerificationTypeInfo[]
2121
*/
2222
private $locals = [];
2323

2424
public function execute(): void
2525
{
2626
$this->frameType = $this->readUnsignedByte();
2727
$this->offsetDelta = $this->readUnsignedShort();
28-
$local = new \PHPJava\Kernel\Structures\_VerificationTypeInfo($this->reader);
28+
$local = new \PHPJava\Kernel\Structures\VerificationTypeInfo($this->reader);
2929
$local->execute();
3030
$this->locals[] = $local;
3131
}

src/Kernel/Mnemonics/_bastore.php

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22
namespace PHPJava\Kernel\Mnemonics;
33

44
use PHPJava\Kernel\Filters\Normalizer;
5-
use PHPJava\Kernel\Types\Type;
5+
use PHPJava\Kernel\Types\_Array\Collection;
6+
use PHPJava\Kernel\Types\_Boolean;
7+
use PHPJava\Kernel\Types\_Byte;
68

79
final class _bastore implements OperationInterface
810
{
@@ -15,9 +17,22 @@ public function execute(): void
1517
$index = Normalizer::getPrimitiveValue($this->popFromOperandStack());
1618

1719
/**
18-
* @var Type $arrayref
20+
* @var Collection $arrayref
1921
*/
2022
$arrayref = $this->popFromOperandStack();
23+
if ($arrayref->getType() === 'boolean') {
24+
$value = _Boolean::get(
25+
Normalizer::getPrimitiveValue(
26+
$value
27+
)
28+
);
29+
} else {
30+
$value = _Byte::get(
31+
Normalizer::getPrimitiveValue(
32+
$value
33+
)
34+
);
35+
}
2136

2237
// The value is a ref.
2338
$arrayref[$index] = $value;

src/Kernel/Mnemonics/_if_acmpeq.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
namespace PHPJava\Kernel\Mnemonics;
33

44
use PHPJava\Core\JavaClass;
5-
use PHPJava\Kernel\Structures\_String;
6-
use PHPJava\Kernel\Structures\_Utf8;
5+
use PHPJava\Kernel\Structures\StringInfo;
6+
use PHPJava\Kernel\Structures\Utf8Info;
77

88
final class _if_acmpeq implements OperationInterface
99
{
@@ -15,8 +15,8 @@ public function execute(): void
1515
$offset = $this->readShort();
1616

1717
/**
18-
* @var _String|_Utf8|JavaClass $rightOperand
19-
* @var _String|_Utf8|JavaClass $leftOperand
18+
* @var JavaClass|StringInfo|Utf8Info $rightOperand
19+
* @var JavaClass|StringInfo|Utf8Info $leftOperand
2020
*/
2121
$rightOperand = $this->popFromOperandStack();
2222
$leftOperand = $this->popFromOperandStack();

0 commit comments

Comments
 (0)