Typo correction

This commit is contained in:
Nav
2024-02-12 19:39:21 +00:00
parent 8474867563
commit 4b6e21e43f
11 changed files with 80 additions and 80 deletions

View File

@@ -30,10 +30,10 @@ class Module
$keys = explode('.', $keys);
}
$firstLevelSubGroupId = array_shift($keys);
$firstLevelSubgroupKey = array_shift($keys);
foreach ($this->registerGroups as $registerGroup) {
if ($registerGroup->key === $firstLevelSubGroupId) {
return !empty($keys) ? $registerGroup->getSubGroup($keys) : $registerGroup;
if ($registerGroup->key === $firstLevelSubgroupKey) {
return !empty($keys) ? $registerGroup->getSubgroup($keys) : $registerGroup;
}
}

View File

@@ -23,16 +23,16 @@ class PropertyGroup
$this->properties = $properties;
}
public function getSubGroup(array|string $subGroupKeys): ?PropertyGroup
public function getSubgroup(array|string $subgroupKeys): ?PropertyGroup
{
if (is_string($subGroupKeys)) {
$subGroupKeys = explode('.', $subGroupKeys);
if (is_string($subgroupKeys)) {
$subgroupKeys = explode('.', $subgroupKeys);
}
$firstLevelSubGroupKey = array_shift($subGroupKeys);
foreach ($this->subPropertyGroups as $subGroup) {
if ($subGroup->key === $firstLevelSubGroupKey) {
return !empty($subGroupKeys) ? $subGroup->getSubGroup($subGroupKeys) : $subGroup;
$firstLevelSubgroupKey = array_shift($subgroupKeys);
foreach ($this->subPropertyGroups as $subgroup) {
if ($subgroup->key === $firstLevelSubgroupKey) {
return !empty($subgroupKeys) ? $subgroup->getSubgroup($subgroupKeys) : $subgroup;
}
}

View File

@@ -17,25 +17,25 @@ class RegisterGroup
public array $registers = [];
/** @var RegisterGroup[] */
public array $subGroups = [];
public array $subgroups = [];
/** @var RegisterGroupReference[] */
public array $subGroupReferences = [];
public array $subgroupReferences = [];
public function __construct(
?string $key,
?string $name,
?int $offset,
array $registers,
array $subGroups,
array $subGroupReferences
array $subgroups,
array $subgroupReferences
) {
$this->key = $key;
$this->name = $name;
$this->offset = $offset;
$this->registers = $registers;
$this->subGroups = $subGroups;
$this->subGroupReferences = $subGroupReferences;
$this->subgroups = $subgroups;
$this->subgroupReferences = $subgroupReferences;
}
public function getRegister(array|string $keys): ?Register
@@ -45,7 +45,7 @@ class RegisterGroup
}
$registerKey = array_pop($keys);
$group = !empty($keys) > 1 ? $this->getSubGroup($keys) : $this;
$group = !empty($keys) > 1 ? $this->getSubgroup($keys) : $this;
if ($group instanceof RegisterGroup) {
foreach ($group->registers as $register) {
@@ -58,16 +58,16 @@ class RegisterGroup
return null;
}
public function getSubGroup(array|string $subGroupKeys): ?RegisterGroup
public function getSubgroup(array|string $subgroupKeys): ?RegisterGroup
{
if (is_string($subGroupKeys)) {
$subGroupKeys = explode('.', $subGroupKeys);
if (is_string($subgroupKeys)) {
$subgroupKeys = explode('.', $subgroupKeys);
}
$firstLevelSubGroupKey = array_shift($subGroupKeys);
foreach ($this->subGroups as $subGroup) {
if ($subGroup->key === $firstLevelSubGroupKey) {
return !empty($subGroupKeys) ? $subGroup->getSubGroup($subGroupKeys) : $subGroup;
$firstLevelSubgroupKey = array_shift($subgroupKeys);
foreach ($this->subgroups as $subgroup) {
if ($subgroup->key === $firstLevelSubgroupKey) {
return !empty($subgroupKeys) ? $subgroup->getSubgroup($subgroupKeys) : $subgroup;
}
}

View File

@@ -460,30 +460,30 @@ class ValidationService
$processedChildKeys[] = $register->key;
}
foreach ($registerGroup->subGroups as $subGroup) {
foreach ($registerGroup->subgroups as $subgroup) {
$failures = array_merge(
$failures,
$this->validateRegisterGroup($subGroup, $moduleKey, $tdf)
$this->validateRegisterGroup($subgroup, $moduleKey, $tdf)
);
if ($subGroup->key !== null && in_array($subGroup->key, $processedChildKeys)) {
$failures[] = 'Duplicate register sub group key ("' . $subGroup->key . '") detected';
if ($subgroup->key !== null && in_array($subgroup->key, $processedChildKeys)) {
$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,
$this->validateRegisterGroupReference($subGroupReference, $moduleKey, $tdf)
$this->validateRegisterGroupReference($subgroupReference, $moduleKey, $tdf)
);
if ($subGroupReference->key !== null && in_array($subGroupReference->key, $processedChildKeys)) {
$failures[] = 'Duplicate register group reference key ("' . $subGroupReference->key . '") detected';
if ($subgroupReference->key !== null && in_array($subgroupReference->key, $processedChildKeys)) {
$failures[] = 'Duplicate register group reference key ("' . $subgroupReference->key . '") detected';
}
$processedChildKeys[] = $subGroupReference->key;
$processedChildKeys[] = $subgroupReference->key;
}
return array_map(

View File

@@ -241,12 +241,12 @@ class FromXmlService
}
if ($childNode->nodeName === 'register-group') {
$output->subGroups[] = $this->registerGroupFromElement($childNode);
$output->subgroups[] = $this->registerGroupFromElement($childNode);
continue;
}
if ($childNode->nodeName === 'register-group-reference') {
$output->subGroupReferences[] = $this->registerGroupReferenceFromElement($childNode);
$output->subgroupReferences[] = $this->registerGroupReferenceFromElement($childNode);
}
}

View File

@@ -208,8 +208,8 @@ class ToXmlService
$children = array_merge(
$registerGroup->registers,
$registerGroup->subGroups,
$registerGroup->subGroupReferences
$registerGroup->subgroups,
$registerGroup->subgroupReferences
);
usort(

View File

@@ -89,7 +89,7 @@ class TargetDescriptionFile
$firstLevelGroupKey = array_shift($keys);
foreach ($this->propertyGroups as $propertyGroup) {
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;
$output = new TargetRegisterGroup($registerGroup->key, $registerGroup->name, $addressOffset, [], []);
foreach ($registerGroup->subGroups as $subGroup) {
$output->subGroups[] = $this->targetRegisterGroupFromRegisterGroup($subGroup, $addressOffset, $moduleKey);
foreach ($registerGroup->subgroups as $subgroup) {
$output->subgroups[] = $this->targetRegisterGroupFromRegisterGroup($subgroup, $addressOffset, $moduleKey);
}
foreach ($registerGroup->subGroupReferences as $subGroupReference) {
$subGroup = $this->resolveRegisterGroupReference($subGroupReference, $moduleKey);
foreach ($registerGroup->subgroupReferences as $subgroupReference) {
$subgroup = $this->resolveRegisterGroupReference($subgroupReference, $moduleKey);
if ($subGroup instanceof RegisterGroup) {
$output->subGroups[] = $this->targetRegisterGroupFromRegisterGroup(
$subGroup,
if ($subgroup instanceof RegisterGroup) {
$output->subgroups[] = $this->targetRegisterGroupFromRegisterGroup(
$subgroup,
$addressOffset,
$moduleKey
);

View File

@@ -36,11 +36,11 @@ class TargetPeripheral
$keys = explode('.', $keys);
}
$firstLevelSubGroupId = array_shift($keys);
$firstLevelSubgroupId = array_shift($keys);
foreach ($this->registerGroups as $registerGroup) {
if ($registerGroup->key === $firstLevelSubGroupId) {
return !empty($keys) ? $registerGroup->getSubGroup($keys) : $registerGroup;
if ($registerGroup->key === $firstLevelSubgroupId) {
return !empty($keys) ? $registerGroup->getSubgroup($keys) : $registerGroup;
}
}

View File

@@ -23,17 +23,17 @@ class TargetRegisterGroup
public ?int $baseAddress = null;
/** @var TargetRegisterGroup[] */
public array $subGroups = [];
public array $subgroups = [];
/** @var TargetRegister[] */
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->name = $name;
$this->baseAddress = $baseAddress;
$this->subGroups = $subGroups;
$this->subgroups = $subgroups;
$this->registers = $registers;
}
@@ -44,7 +44,7 @@ class TargetRegisterGroup
}
$registerKey = array_pop($keys);
$group = !empty($keys) > 1 ? $this->getSubGroup($keys) : $this;
$group = !empty($keys) > 1 ? $this->getSubgroup($keys) : $this;
if ($group instanceof TargetRegisterGroup) {
foreach ($group->registers as $register) {
@@ -57,16 +57,16 @@ class TargetRegisterGroup
return null;
}
public function getSubGroup(array|string $subGroupKeys): ?TargetRegisterGroup
public function getSubgroup(array|string $subgroupKeys): ?TargetRegisterGroup
{
if (is_string($subGroupKeys)) {
$subGroupKeys = explode('.', $subGroupKeys);
if (is_string($subgroupKeys)) {
$subgroupKeys = explode('.', $subgroupKeys);
}
$firstLevelSubGroupKey = array_shift($subGroupKeys);
foreach ($this->subGroups as $subGroup) {
if ($subGroup->key === $firstLevelSubGroupKey) {
return !empty($subGroupKeys) ? $subGroup->getSubGroup($subGroupKeys) : $subGroup;
$firstLevelSubgroupKey = array_shift($subgroupKeys);
foreach ($this->subgroups as $subgroup) {
if ($subgroup->key === $firstLevelSubgroupKey) {
return !empty($subgroupKeys) ? $subgroup->getSubgroup($subgroupKeys) : $subgroup;
}
}

View File

@@ -28,45 +28,45 @@ namespace Targets::TargetDescription
{
std::string key;
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(
const std::string& key,
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)
, propertiesMappedByKey(propertiesMappedByKey)
, subGroupsMappedByKey(subGroupsMappedByKey)
, subgroupsMappedByKey(subgroupsMappedByKey)
{}
template <typename KeysType>
requires
std::ranges::sized_range<KeysType>
std::optional<std::reference_wrapper<const PropertyGroup>> tryGetSubGroup(KeysType keys) const {
auto firstSubGroupIt = this->subGroupsMappedByKey.find(*(keys.begin()));
if (firstSubGroupIt == this->subGroupsMappedByKey.end()) {
std::optional<std::reference_wrapper<const PropertyGroup>> tryGetSubgroup(KeysType keys) const {
auto firstSubgroupIt = this->subgroupsMappedByKey.find(*(keys.begin()));
if (firstSubgroupIt == this->subgroupsMappedByKey.end()) {
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)) {
subGroup = subGroup->get().tryGetSubGroup(key);
subgroup = subgroup->get().tryGetSubgroup(key);
if (!subGroup.has_value()) {
if (!subgroup.has_value()) {
break;
}
}
return subGroup;
return subgroup;
}
std::optional<std::reference_wrapper<const PropertyGroup>> tryGetSubGroup(std::string_view keyStr) const {
return this->tryGetSubGroup(Services::StringService::split(keyStr, '.'));
std::optional<std::reference_wrapper<const PropertyGroup>> tryGetSubgroup(std::string_view keyStr) const {
return this->tryGetSubgroup(Services::StringService::split(keyStr, '.'));
}
std::optional<std::reference_wrapper<const PropertyGroup>> getSubGroup(std::string_view keyStr) const {
const auto propertyGroup = this->tryGetSubGroup(keyStr);
std::optional<std::reference_wrapper<const PropertyGroup>> getSubgroup(std::string_view keyStr) const {
const auto propertyGroup = this->tryGetSubgroup(keyStr);
if (!propertyGroup.has_value()) {
throw Exceptions::Exception(
"Failed to get subgroup \"" + std::string(keyStr)

View File

@@ -50,11 +50,11 @@ namespace Targets::TargetDescription
) const {
auto keys = StringService::split(keyStr, '.');
const auto firstSubGroupIt = this->propertyGroupsMappedByKey.find(*keys.begin());
return firstSubGroupIt != this->propertyGroupsMappedByKey.end()
const auto firstSubgroupIt = this->propertyGroupsMappedByKey.find(*keys.begin());
return firstSubgroupIt != this->propertyGroupsMappedByKey.end()
? keys.size() > 1
? firstSubGroupIt->second.tryGetSubGroup(keys | std::ranges::views::drop(1))
: std::optional(std::cref(firstSubGroupIt->second))
? firstSubgroupIt->second.tryGetSubgroup(keys | std::ranges::views::drop(1))
: std::optional(std::cref(firstSubgroupIt->second))
: std::nullopt;
}
@@ -162,8 +162,8 @@ namespace Targets::TargetDescription
!element.isNull();
element = element.nextSiblingElement("property-group")
) {
auto subGroup = TargetDescriptionFile::propertyGroupFromXml(element);
output.subGroupsMappedByKey.insert(std::pair(subGroup.key, std::move(subGroup)));
auto subgroup = TargetDescriptionFile::propertyGroupFromXml(element);
output.subgroupsMappedByKey.insert(std::pair(subgroup.key, std::move(subgroup)));
}
return output;