-
Notifications
You must be signed in to change notification settings - Fork 36
Expand file tree
/
Copy pathCodeAttribute.php
More file actions
112 lines (94 loc) Β· 2.69 KB
/
CodeAttribute.php
File metadata and controls
112 lines (94 loc) Β· 2.69 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
<?php
declare(strict_types=1);
namespace PHPJava\Kernel\Attributes;
final class CodeAttribute implements AttributeInterface
{
use \PHPJava\Kernel\Core\BinaryReader;
use \PHPJava\Kernel\Core\ConstantPool;
use \PHPJava\Kernel\Core\AttributeReference;
use \PHPJava\Kernel\Core\DebugTool;
/**
* @var int
*/
private $maxStack;
/**
* @var int
*/
private $maxLocals;
/**
* @var int
*/
private $codeLength;
/**
* @var string
*/
private $rawCode = '';
/**
* @var int[]
*/
private $code = [];
/**
* @var int
*/
private $exceptionTableLength;
/**
* @var \PHPJava\Kernel\Structures\ExceptionTable[]
*/
private $exceptionTables = [];
/**
* @var \PHPJava\Kernel\Attributes\AttributeInfo[]
*/
private $attributeInfo = [];
/**
* @var int
*/
private $attributeCount = 0;
public function execute(): void
{
$this->maxStack = $this->readUnsignedShort();
$this->maxLocals = $this->readUnsignedShort();
$this->codeLength = $this->readUnsignedInt();
// read Mnemonics
$this->code = [];
for ($i = 0; $i < $this->codeLength; $i++) {
$this->code[$i] = $this->readUnsignedByte();
$this->rawCode .= chr($this->code[$i]);
}
// read exception table
$this->exceptionTableLength = $this->readUnsignedShort();
for ($i = 0; $i < $this->exceptionTableLength; $i++) {
$exceptionTable = new \PHPJava\Kernel\Structures\ExceptionTable($this->reader);
$exceptionTable->setConstantPool($this->getConstantPool());
$exceptionTable->setDebugTool($this->getDebugTool());
$exceptionTable->execute();
$this->exceptionTables[] = $exceptionTable;
}
$this->attributeCount = $this->readUnsignedShort();
for ($i = 0; $i < $this->attributeCount; $i++) {
$attributeInfo = new \PHPJava\Kernel\Attributes\AttributeInfo($this->reader);
$attributeInfo->setConstantPool($this->getConstantPool());
$attributeInfo->setDebugTool($this->getDebugTool());
$attributeInfo->execute();
$this->attributeInfo[] = $attributeInfo;
}
}
/**
* @return \PHPJava\Kernel\Structures\ExceptionTable[]
*/
public function getExceptionTables(): array
{
return $this->exceptionTables;
}
public function getCode(): string
{
return $this->rawCode;
}
public function getOpCodes(): int
{
return $this->code;
}
public function getOpCodeLength(): int
{
return (int) $this->codeLength;
}
}