Refactored TDF processing PHP code to confirm to new TDF format

This commit is contained in:
Nav
2024-02-09 23:30:47 +00:00
parent 09a5be91fd
commit c563443737
58 changed files with 1877 additions and 1762 deletions

View File

@@ -0,0 +1,63 @@
<?php
namespace Targets\TargetDescriptionFiles;
class MemorySegmentSection
{
public ?string $key = null;
public ?string $name = null;
public ?int $startAddress = null;
public ?int $size = null;
/** @var MemorySegmentSection[] */
public array $subSections = [];
public function __construct(
?string $key,
?string $name,
?int $startAddress,
?int $size,
array $subSections
) {
$this->key = $key;
$this->name = $name;
$this->startAddress = $startAddress;
$this->size = $size;
$this->subSections = $subSections;
}
public function contains(MemorySegment $other): bool
{
$endAddress = !is_null($this->startAddress) && !is_null($this->size)
? ($this->startAddress + $this->size - 1) : null;
$otherEndAddress = !is_null($other->startAddress) && !is_null($other->size)
? ($other->startAddress + $other->size - 1) : null;
return
$this->startAddress !== null
&& $endAddress !== null
&& $other->startAddress !== null
&& $otherEndAddress !== null
&& $this->startAddress <= $other->startAddress
&& $endAddress >= $otherEndAddress
;
}
public function intersectsWith(MemorySegmentSection $other): bool
{
$endAddress = !is_null($this->startAddress) && !is_null($this->size)
? ($this->startAddress + $this->size - 1) : null;
$otherEndAddress = !is_null($other->startAddress) && !is_null($other->size)
? ($other->startAddress + $other->size - 1) : null;
return
$this->startAddress !== null
&& $endAddress !== null
&& $other->startAddress !== null
&& $otherEndAddress !== null
&& (
($other->startAddress <= $this->startAddress && $otherEndAddress >= $this->startAddress)
|| ($other->startAddress >= $this->startAddress && $other->startAddress <= $endAddress)
)
;
}
}