File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11<?php
22namespace PHPJava \Kernel \Mnemonics ;
33
4- use PHPJava \Exceptions \NotImplementedException ;
4+ use PHPJava \Packages \java \lang \ClassCastException ;
5+ use PHPJava \Utilities \Formatter ;
6+ use PHPJava \Utilities \TypeResolver ;
57
68final class _checkcast implements OperationInterface
79{
@@ -10,6 +12,28 @@ final class _checkcast implements OperationInterface
1012
1113 public function execute (): void
1214 {
13- throw new NotImplementedException (__CLASS__ );
15+ $ cp = $ this ->getConstantPool ();
16+ $ index = $ this ->readUnsignedShort ();
17+ $ objectref = $ this ->popFromOperandStack ();
18+
19+ if ($ objectref === null ) {
20+ return ;
21+ }
22+
23+ $ castTo = $ cp [$ cp [$ index ]->getClassIndex ()]->getString ();
24+
25+ $ fromObjectClass = Formatter::convertPHPNamespacesToJava (get_class ($ objectref ));
26+
27+ [$ classes , $ interfaces ] = TypeResolver::getExtendedClasses (
28+ 'L ' . str_replace ('/ ' , '. ' , $ castTo )
29+ )[0 ] ?? [[], []];
30+
31+ if (in_array ($ fromObjectClass , $ classes , true )) {
32+ return ;
33+ }
34+
35+ throw new ClassCastException (
36+ 'class \\' . get_class ($ objectref ) . ' cannot be cast to class ' . Formatter::convertJavaNamespaceToPHP ($ castTo )[1 ]
37+ );
1438 }
1539}
Original file line number Diff line number Diff line change 55use PHPJava \Kernel \Structures \_Integer ;
66use PHPJava \Kernel \Structures \_String ;
77use PHPJava \Kernel \Structures \_Utf8 ;
8+ use PHPJava \Kernel \Types \_Int ;
89
910final class _ldc implements OperationInterface
1011{
@@ -14,7 +15,6 @@ final class _ldc implements OperationInterface
1415 public function execute (): void
1516 {
1617 $ cpInfo = $ this ->getConstantPool ();
17-
1818 $ data = $ cpInfo [$ this ->readUnsignedByte ()];
1919
2020 $ value = null ;
@@ -25,8 +25,10 @@ public function execute(): void
2525 if ($ value instanceof _Utf8) {
2626 $ value = $ value ->getStringObject ();
2727 }
28- } elseif (($ data instanceof _Integer) || ($ data instanceof _Float)) {
29- $ value = $ data ->getBytes ();
28+ } elseif (($ data instanceof _Integer)) {
29+ $ value = _Int::get ($ data ->getBytes ());
30+ } elseif ($ data instanceof _Float) {
31+ $ value = _Float::get ($ data ->getBytes ());
3032 } else {
3133 $ value = $ cpInfo [$ data ->getStringIndex ()];
3234 }
Original file line number Diff line number Diff line change 11<?php
22namespace PHPJava \Kernel \Mnemonics ;
33
4+ use PHPJava \Kernel \Types \_Double ;
5+ use PHPJava \Kernel \Types \_Long ;
6+
47final class _ldc2_w implements OperationInterface
58{
69 use \PHPJava \Kernel \Core \Accumulator;
@@ -9,9 +12,15 @@ final class _ldc2_w implements OperationInterface
912 public function execute (): void
1013 {
1114 $ cpInfo = $ this ->getConstantPool ();
12-
1315 $ data = $ cpInfo [$ this ->readUnsignedShort ()];
1416
15- $ this ->pushToOperandStack ($ data ->getBytes ());
17+ $ value = null ;
18+ if (($ data instanceof \PHPJava \Kernel \Structures \_Long)) {
19+ $ value = _Long::get ($ data ->getBytes ());
20+ } elseif ($ data instanceof \PHPJava \Kernel \Structures \_Double) {
21+ $ value = _Double::get ($ data ->getBytes ());
22+ }
23+
24+ $ this ->pushToOperandStack ($ value );
1625 }
1726}
You can’t perform that action at this time.
0 commit comments