Typo correction
This commit is contained in:
@@ -30,10 +30,10 @@ class Module
|
|||||||
$keys = explode('.', $keys);
|
$keys = explode('.', $keys);
|
||||||
}
|
}
|
||||||
|
|
||||||
$firstLevelSubGroupId = array_shift($keys);
|
$firstLevelSubgroupKey = array_shift($keys);
|
||||||
foreach ($this->registerGroups as $registerGroup) {
|
foreach ($this->registerGroups as $registerGroup) {
|
||||||
if ($registerGroup->key === $firstLevelSubGroupId) {
|
if ($registerGroup->key === $firstLevelSubgroupKey) {
|
||||||
return !empty($keys) ? $registerGroup->getSubGroup($keys) : $registerGroup;
|
return !empty($keys) ? $registerGroup->getSubgroup($keys) : $registerGroup;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -23,16 +23,16 @@ class PropertyGroup
|
|||||||
$this->properties = $properties;
|
$this->properties = $properties;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getSubGroup(array|string $subGroupKeys): ?PropertyGroup
|
public function getSubgroup(array|string $subgroupKeys): ?PropertyGroup
|
||||||
{
|
{
|
||||||
if (is_string($subGroupKeys)) {
|
if (is_string($subgroupKeys)) {
|
||||||
$subGroupKeys = explode('.', $subGroupKeys);
|
$subgroupKeys = explode('.', $subgroupKeys);
|
||||||
}
|
}
|
||||||
|
|
||||||
$firstLevelSubGroupKey = array_shift($subGroupKeys);
|
$firstLevelSubgroupKey = array_shift($subgroupKeys);
|
||||||
foreach ($this->subPropertyGroups as $subGroup) {
|
foreach ($this->subPropertyGroups as $subgroup) {
|
||||||
if ($subGroup->key === $firstLevelSubGroupKey) {
|
if ($subgroup->key === $firstLevelSubgroupKey) {
|
||||||
return !empty($subGroupKeys) ? $subGroup->getSubGroup($subGroupKeys) : $subGroup;
|
return !empty($subgroupKeys) ? $subgroup->getSubgroup($subgroupKeys) : $subgroup;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -17,25 +17,25 @@ class RegisterGroup
|
|||||||
public array $registers = [];
|
public array $registers = [];
|
||||||
|
|
||||||
/** @var RegisterGroup[] */
|
/** @var RegisterGroup[] */
|
||||||
public array $subGroups = [];
|
public array $subgroups = [];
|
||||||
|
|
||||||
/** @var RegisterGroupReference[] */
|
/** @var RegisterGroupReference[] */
|
||||||
public array $subGroupReferences = [];
|
public array $subgroupReferences = [];
|
||||||
|
|
||||||
public function __construct(
|
public function __construct(
|
||||||
?string $key,
|
?string $key,
|
||||||
?string $name,
|
?string $name,
|
||||||
?int $offset,
|
?int $offset,
|
||||||
array $registers,
|
array $registers,
|
||||||
array $subGroups,
|
array $subgroups,
|
||||||
array $subGroupReferences
|
array $subgroupReferences
|
||||||
) {
|
) {
|
||||||
$this->key = $key;
|
$this->key = $key;
|
||||||
$this->name = $name;
|
$this->name = $name;
|
||||||
$this->offset = $offset;
|
$this->offset = $offset;
|
||||||
$this->registers = $registers;
|
$this->registers = $registers;
|
||||||
$this->subGroups = $subGroups;
|
$this->subgroups = $subgroups;
|
||||||
$this->subGroupReferences = $subGroupReferences;
|
$this->subgroupReferences = $subgroupReferences;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getRegister(array|string $keys): ?Register
|
public function getRegister(array|string $keys): ?Register
|
||||||
@@ -45,7 +45,7 @@ class RegisterGroup
|
|||||||
}
|
}
|
||||||
|
|
||||||
$registerKey = array_pop($keys);
|
$registerKey = array_pop($keys);
|
||||||
$group = !empty($keys) > 1 ? $this->getSubGroup($keys) : $this;
|
$group = !empty($keys) > 1 ? $this->getSubgroup($keys) : $this;
|
||||||
|
|
||||||
if ($group instanceof RegisterGroup) {
|
if ($group instanceof RegisterGroup) {
|
||||||
foreach ($group->registers as $register) {
|
foreach ($group->registers as $register) {
|
||||||
@@ -58,16 +58,16 @@ class RegisterGroup
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getSubGroup(array|string $subGroupKeys): ?RegisterGroup
|
public function getSubgroup(array|string $subgroupKeys): ?RegisterGroup
|
||||||
{
|
{
|
||||||
if (is_string($subGroupKeys)) {
|
if (is_string($subgroupKeys)) {
|
||||||
$subGroupKeys = explode('.', $subGroupKeys);
|
$subgroupKeys = explode('.', $subgroupKeys);
|
||||||
}
|
}
|
||||||
|
|
||||||
$firstLevelSubGroupKey = array_shift($subGroupKeys);
|
$firstLevelSubgroupKey = array_shift($subgroupKeys);
|
||||||
foreach ($this->subGroups as $subGroup) {
|
foreach ($this->subgroups as $subgroup) {
|
||||||
if ($subGroup->key === $firstLevelSubGroupKey) {
|
if ($subgroup->key === $firstLevelSubgroupKey) {
|
||||||
return !empty($subGroupKeys) ? $subGroup->getSubGroup($subGroupKeys) : $subGroup;
|
return !empty($subgroupKeys) ? $subgroup->getSubgroup($subgroupKeys) : $subgroup;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -460,30 +460,30 @@ class ValidationService
|
|||||||
$processedChildKeys[] = $register->key;
|
$processedChildKeys[] = $register->key;
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach ($registerGroup->subGroups as $subGroup) {
|
foreach ($registerGroup->subgroups as $subgroup) {
|
||||||
$failures = array_merge(
|
$failures = array_merge(
|
||||||
$failures,
|
$failures,
|
||||||
$this->validateRegisterGroup($subGroup, $moduleKey, $tdf)
|
$this->validateRegisterGroup($subgroup, $moduleKey, $tdf)
|
||||||
);
|
);
|
||||||
|
|
||||||
if ($subGroup->key !== null && in_array($subGroup->key, $processedChildKeys)) {
|
if ($subgroup->key !== null && in_array($subgroup->key, $processedChildKeys)) {
|
||||||
$failures[] = 'Duplicate register sub group key ("' . $subGroup->key . '") detected';
|
$failures[] = 'Duplicate register sub group key ("' . $subgroup->key . '") detected';
|
||||||
}
|
}
|
||||||
|
|
||||||
$processedChildKeys[] = $subGroup->key;
|
$processedChildKeys[] = $subgroup->key;
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach ($registerGroup->subGroupReferences as $subGroupReference) {
|
foreach ($registerGroup->subgroupReferences as $subgroupReference) {
|
||||||
$failures = array_merge(
|
$failures = array_merge(
|
||||||
$failures,
|
$failures,
|
||||||
$this->validateRegisterGroupReference($subGroupReference, $moduleKey, $tdf)
|
$this->validateRegisterGroupReference($subgroupReference, $moduleKey, $tdf)
|
||||||
);
|
);
|
||||||
|
|
||||||
if ($subGroupReference->key !== null && in_array($subGroupReference->key, $processedChildKeys)) {
|
if ($subgroupReference->key !== null && in_array($subgroupReference->key, $processedChildKeys)) {
|
||||||
$failures[] = 'Duplicate register group reference key ("' . $subGroupReference->key . '") detected';
|
$failures[] = 'Duplicate register group reference key ("' . $subgroupReference->key . '") detected';
|
||||||
}
|
}
|
||||||
|
|
||||||
$processedChildKeys[] = $subGroupReference->key;
|
$processedChildKeys[] = $subgroupReference->key;
|
||||||
}
|
}
|
||||||
|
|
||||||
return array_map(
|
return array_map(
|
||||||
|
|||||||
@@ -241,12 +241,12 @@ class FromXmlService
|
|||||||
}
|
}
|
||||||
|
|
||||||
if ($childNode->nodeName === 'register-group') {
|
if ($childNode->nodeName === 'register-group') {
|
||||||
$output->subGroups[] = $this->registerGroupFromElement($childNode);
|
$output->subgroups[] = $this->registerGroupFromElement($childNode);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($childNode->nodeName === 'register-group-reference') {
|
if ($childNode->nodeName === 'register-group-reference') {
|
||||||
$output->subGroupReferences[] = $this->registerGroupReferenceFromElement($childNode);
|
$output->subgroupReferences[] = $this->registerGroupReferenceFromElement($childNode);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -208,8 +208,8 @@ class ToXmlService
|
|||||||
|
|
||||||
$children = array_merge(
|
$children = array_merge(
|
||||||
$registerGroup->registers,
|
$registerGroup->registers,
|
||||||
$registerGroup->subGroups,
|
$registerGroup->subgroups,
|
||||||
$registerGroup->subGroupReferences
|
$registerGroup->subgroupReferences
|
||||||
);
|
);
|
||||||
|
|
||||||
usort(
|
usort(
|
||||||
|
|||||||
@@ -89,7 +89,7 @@ class TargetDescriptionFile
|
|||||||
$firstLevelGroupKey = array_shift($keys);
|
$firstLevelGroupKey = array_shift($keys);
|
||||||
foreach ($this->propertyGroups as $propertyGroup) {
|
foreach ($this->propertyGroups as $propertyGroup) {
|
||||||
if ($propertyGroup->key === $firstLevelGroupKey) {
|
if ($propertyGroup->key === $firstLevelGroupKey) {
|
||||||
return !empty($keys) ? $propertyGroup->getSubGroup($keys) : $propertyGroup;
|
return !empty($keys) ? $propertyGroup->getSubgroup($keys) : $propertyGroup;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -280,16 +280,16 @@ class TargetDescriptionFile
|
|||||||
$addressOffset += $registerGroup->offset ?? 0;
|
$addressOffset += $registerGroup->offset ?? 0;
|
||||||
$output = new TargetRegisterGroup($registerGroup->key, $registerGroup->name, $addressOffset, [], []);
|
$output = new TargetRegisterGroup($registerGroup->key, $registerGroup->name, $addressOffset, [], []);
|
||||||
|
|
||||||
foreach ($registerGroup->subGroups as $subGroup) {
|
foreach ($registerGroup->subgroups as $subgroup) {
|
||||||
$output->subGroups[] = $this->targetRegisterGroupFromRegisterGroup($subGroup, $addressOffset, $moduleKey);
|
$output->subgroups[] = $this->targetRegisterGroupFromRegisterGroup($subgroup, $addressOffset, $moduleKey);
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach ($registerGroup->subGroupReferences as $subGroupReference) {
|
foreach ($registerGroup->subgroupReferences as $subgroupReference) {
|
||||||
$subGroup = $this->resolveRegisterGroupReference($subGroupReference, $moduleKey);
|
$subgroup = $this->resolveRegisterGroupReference($subgroupReference, $moduleKey);
|
||||||
|
|
||||||
if ($subGroup instanceof RegisterGroup) {
|
if ($subgroup instanceof RegisterGroup) {
|
||||||
$output->subGroups[] = $this->targetRegisterGroupFromRegisterGroup(
|
$output->subgroups[] = $this->targetRegisterGroupFromRegisterGroup(
|
||||||
$subGroup,
|
$subgroup,
|
||||||
$addressOffset,
|
$addressOffset,
|
||||||
$moduleKey
|
$moduleKey
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -36,11 +36,11 @@ class TargetPeripheral
|
|||||||
$keys = explode('.', $keys);
|
$keys = explode('.', $keys);
|
||||||
}
|
}
|
||||||
|
|
||||||
$firstLevelSubGroupId = array_shift($keys);
|
$firstLevelSubgroupId = array_shift($keys);
|
||||||
|
|
||||||
foreach ($this->registerGroups as $registerGroup) {
|
foreach ($this->registerGroups as $registerGroup) {
|
||||||
if ($registerGroup->key === $firstLevelSubGroupId) {
|
if ($registerGroup->key === $firstLevelSubgroupId) {
|
||||||
return !empty($keys) ? $registerGroup->getSubGroup($keys) : $registerGroup;
|
return !empty($keys) ? $registerGroup->getSubgroup($keys) : $registerGroup;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -23,17 +23,17 @@ class TargetRegisterGroup
|
|||||||
public ?int $baseAddress = null;
|
public ?int $baseAddress = null;
|
||||||
|
|
||||||
/** @var TargetRegisterGroup[] */
|
/** @var TargetRegisterGroup[] */
|
||||||
public array $subGroups = [];
|
public array $subgroups = [];
|
||||||
|
|
||||||
/** @var TargetRegister[] */
|
/** @var TargetRegister[] */
|
||||||
public array $registers = [];
|
public array $registers = [];
|
||||||
|
|
||||||
public function __construct(?string $key, ?string $name, ?int $baseAddress, array $subGroups, array $registers)
|
public function __construct(?string $key, ?string $name, ?int $baseAddress, array $subgroups, array $registers)
|
||||||
{
|
{
|
||||||
$this->key = $key;
|
$this->key = $key;
|
||||||
$this->name = $name;
|
$this->name = $name;
|
||||||
$this->baseAddress = $baseAddress;
|
$this->baseAddress = $baseAddress;
|
||||||
$this->subGroups = $subGroups;
|
$this->subgroups = $subgroups;
|
||||||
$this->registers = $registers;
|
$this->registers = $registers;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -44,7 +44,7 @@ class TargetRegisterGroup
|
|||||||
}
|
}
|
||||||
|
|
||||||
$registerKey = array_pop($keys);
|
$registerKey = array_pop($keys);
|
||||||
$group = !empty($keys) > 1 ? $this->getSubGroup($keys) : $this;
|
$group = !empty($keys) > 1 ? $this->getSubgroup($keys) : $this;
|
||||||
|
|
||||||
if ($group instanceof TargetRegisterGroup) {
|
if ($group instanceof TargetRegisterGroup) {
|
||||||
foreach ($group->registers as $register) {
|
foreach ($group->registers as $register) {
|
||||||
@@ -57,16 +57,16 @@ class TargetRegisterGroup
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getSubGroup(array|string $subGroupKeys): ?TargetRegisterGroup
|
public function getSubgroup(array|string $subgroupKeys): ?TargetRegisterGroup
|
||||||
{
|
{
|
||||||
if (is_string($subGroupKeys)) {
|
if (is_string($subgroupKeys)) {
|
||||||
$subGroupKeys = explode('.', $subGroupKeys);
|
$subgroupKeys = explode('.', $subgroupKeys);
|
||||||
}
|
}
|
||||||
|
|
||||||
$firstLevelSubGroupKey = array_shift($subGroupKeys);
|
$firstLevelSubgroupKey = array_shift($subgroupKeys);
|
||||||
foreach ($this->subGroups as $subGroup) {
|
foreach ($this->subgroups as $subgroup) {
|
||||||
if ($subGroup->key === $firstLevelSubGroupKey) {
|
if ($subgroup->key === $firstLevelSubgroupKey) {
|
||||||
return !empty($subGroupKeys) ? $subGroup->getSubGroup($subGroupKeys) : $subGroup;
|
return !empty($subgroupKeys) ? $subgroup->getSubgroup($subgroupKeys) : $subgroup;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -28,45 +28,45 @@ namespace Targets::TargetDescription
|
|||||||
{
|
{
|
||||||
std::string key;
|
std::string key;
|
||||||
std::map<std::string, Property, std::less<void>> propertiesMappedByKey;
|
std::map<std::string, Property, std::less<void>> propertiesMappedByKey;
|
||||||
std::map<std::string, PropertyGroup, std::less<void>> subGroupsMappedByKey;
|
std::map<std::string, PropertyGroup, std::less<void>> subgroupsMappedByKey;
|
||||||
|
|
||||||
PropertyGroup(
|
PropertyGroup(
|
||||||
const std::string& key,
|
const std::string& key,
|
||||||
const std::map<std::string, Property, std::less<void>>& propertiesMappedByKey,
|
const std::map<std::string, Property, std::less<void>>& propertiesMappedByKey,
|
||||||
const std::map<std::string, PropertyGroup, std::less<void>>& subGroupsMappedByKey
|
const std::map<std::string, PropertyGroup, std::less<void>>& subgroupsMappedByKey
|
||||||
)
|
)
|
||||||
: key(key)
|
: key(key)
|
||||||
, propertiesMappedByKey(propertiesMappedByKey)
|
, propertiesMappedByKey(propertiesMappedByKey)
|
||||||
, subGroupsMappedByKey(subGroupsMappedByKey)
|
, subgroupsMappedByKey(subgroupsMappedByKey)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
template <typename KeysType>
|
template <typename KeysType>
|
||||||
requires
|
requires
|
||||||
std::ranges::sized_range<KeysType>
|
std::ranges::sized_range<KeysType>
|
||||||
std::optional<std::reference_wrapper<const PropertyGroup>> tryGetSubGroup(KeysType keys) const {
|
std::optional<std::reference_wrapper<const PropertyGroup>> tryGetSubgroup(KeysType keys) const {
|
||||||
auto firstSubGroupIt = this->subGroupsMappedByKey.find(*(keys.begin()));
|
auto firstSubgroupIt = this->subgroupsMappedByKey.find(*(keys.begin()));
|
||||||
if (firstSubGroupIt == this->subGroupsMappedByKey.end()) {
|
if (firstSubgroupIt == this->subgroupsMappedByKey.end()) {
|
||||||
return std::nullopt;
|
return std::nullopt;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto subGroup = std::optional(std::cref(firstSubGroupIt->second));
|
auto subgroup = std::optional(std::cref(firstSubgroupIt->second));
|
||||||
for (const auto key : keys | std::ranges::views::drop(1)) {
|
for (const auto key : keys | std::ranges::views::drop(1)) {
|
||||||
subGroup = subGroup->get().tryGetSubGroup(key);
|
subgroup = subgroup->get().tryGetSubgroup(key);
|
||||||
|
|
||||||
if (!subGroup.has_value()) {
|
if (!subgroup.has_value()) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return subGroup;
|
return subgroup;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::optional<std::reference_wrapper<const PropertyGroup>> tryGetSubGroup(std::string_view keyStr) const {
|
std::optional<std::reference_wrapper<const PropertyGroup>> tryGetSubgroup(std::string_view keyStr) const {
|
||||||
return this->tryGetSubGroup(Services::StringService::split(keyStr, '.'));
|
return this->tryGetSubgroup(Services::StringService::split(keyStr, '.'));
|
||||||
}
|
}
|
||||||
|
|
||||||
std::optional<std::reference_wrapper<const PropertyGroup>> getSubGroup(std::string_view keyStr) const {
|
std::optional<std::reference_wrapper<const PropertyGroup>> getSubgroup(std::string_view keyStr) const {
|
||||||
const auto propertyGroup = this->tryGetSubGroup(keyStr);
|
const auto propertyGroup = this->tryGetSubgroup(keyStr);
|
||||||
if (!propertyGroup.has_value()) {
|
if (!propertyGroup.has_value()) {
|
||||||
throw Exceptions::Exception(
|
throw Exceptions::Exception(
|
||||||
"Failed to get subgroup \"" + std::string(keyStr)
|
"Failed to get subgroup \"" + std::string(keyStr)
|
||||||
|
|||||||
@@ -50,11 +50,11 @@ namespace Targets::TargetDescription
|
|||||||
) const {
|
) const {
|
||||||
auto keys = StringService::split(keyStr, '.');
|
auto keys = StringService::split(keyStr, '.');
|
||||||
|
|
||||||
const auto firstSubGroupIt = this->propertyGroupsMappedByKey.find(*keys.begin());
|
const auto firstSubgroupIt = this->propertyGroupsMappedByKey.find(*keys.begin());
|
||||||
return firstSubGroupIt != this->propertyGroupsMappedByKey.end()
|
return firstSubgroupIt != this->propertyGroupsMappedByKey.end()
|
||||||
? keys.size() > 1
|
? keys.size() > 1
|
||||||
? firstSubGroupIt->second.tryGetSubGroup(keys | std::ranges::views::drop(1))
|
? firstSubgroupIt->second.tryGetSubgroup(keys | std::ranges::views::drop(1))
|
||||||
: std::optional(std::cref(firstSubGroupIt->second))
|
: std::optional(std::cref(firstSubgroupIt->second))
|
||||||
: std::nullopt;
|
: std::nullopt;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -162,8 +162,8 @@ namespace Targets::TargetDescription
|
|||||||
!element.isNull();
|
!element.isNull();
|
||||||
element = element.nextSiblingElement("property-group")
|
element = element.nextSiblingElement("property-group")
|
||||||
) {
|
) {
|
||||||
auto subGroup = TargetDescriptionFile::propertyGroupFromXml(element);
|
auto subgroup = TargetDescriptionFile::propertyGroupFromXml(element);
|
||||||
output.subGroupsMappedByKey.insert(std::pair(subGroup.key, std::move(subGroup)));
|
output.subgroupsMappedByKey.insert(std::pair(subgroup.key, std::move(subgroup)));
|
||||||
}
|
}
|
||||||
|
|
||||||
return output;
|
return output;
|
||||||
|
|||||||
Reference in New Issue
Block a user