1
0
mirror of https://github.com/TomHarte/CLK.git synced 2024-11-26 08:49:37 +00:00

Merge pull request #1310 from TomHarte/MoreUniquePtr

Remove macros and raw pointers from static analyser.
This commit is contained in:
Thomas Harte 2024-01-18 13:32:30 -05:00 committed by GitHub
commit e8917cd294
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 61 additions and 48 deletions

View File

@ -110,15 +110,15 @@ class MediaAccumulator {
/// Adds @c instance to the media collection and adds @c platforms to the set of potentials. /// Adds @c instance to the media collection and adds @c platforms to the set of potentials.
/// If @c instance is an @c TargetPlatform::TypeDistinguisher then it is given an opportunity to restrict the set of potentials. /// If @c instance is an @c TargetPlatform::TypeDistinguisher then it is given an opportunity to restrict the set of potentials.
template <typename InstanceT> template <typename InstanceT>
void insert(TargetPlatform::IntType platforms, InstanceT *instance) { void insert(TargetPlatform::IntType platforms, std::shared_ptr<InstanceT> instance) {
if constexpr (std::is_base_of_v<Storage::Disk::Disk, InstanceT>) { if constexpr (std::is_base_of_v<Storage::Disk::Disk, InstanceT>) {
media.disks.emplace_back(instance); media.disks.push_back(instance);
} else if constexpr (std::is_base_of_v<Storage::Tape::Tape, InstanceT>) { } else if constexpr (std::is_base_of_v<Storage::Tape::Tape, InstanceT>) {
media.tapes.emplace_back(instance); media.tapes.push_back(instance);
} else if constexpr (std::is_base_of_v<Storage::Cartridge::Cartridge, InstanceT>) { } else if constexpr (std::is_base_of_v<Storage::Cartridge::Cartridge, InstanceT>) {
media.cartridges.emplace_back(instance); media.cartridges.push_back(instance);
} else if constexpr (std::is_base_of_v<Storage::MassStorage::MassStorageDevice, InstanceT>) { } else if constexpr (std::is_base_of_v<Storage::MassStorage::MassStorageDevice, InstanceT>) {
media.mass_storage_devices.emplace_back(instance); media.mass_storage_devices.push_back(instance);
} else { } else {
static_assert(always_false_v<InstanceT>, "Unexpected type encountered."); static_assert(always_false_v<InstanceT>, "Unexpected type encountered.");
} }
@ -127,14 +127,14 @@ class MediaAccumulator {
// Check whether the instance itself has any input on target platforms. // Check whether the instance itself has any input on target platforms.
TargetPlatform::TypeDistinguisher *const distinguisher = TargetPlatform::TypeDistinguisher *const distinguisher =
dynamic_cast<TargetPlatform::TypeDistinguisher *>(instance); dynamic_cast<TargetPlatform::TypeDistinguisher *>(instance.get());
if(distinguisher) potential_platforms_ &= distinguisher->target_platform_type(); if(distinguisher) potential_platforms_ &= distinguisher->target_platform_type();
} }
/// Concstructs a new instance of @c InstanceT supplying @c args and adds it to the back of @c list using @c insert_instance. /// Concstructs a new instance of @c InstanceT supplying @c args and adds it to the back of @c list using @c insert_instance.
template <typename InstanceT, typename... Args> template <typename InstanceT, typename... Args>
void insert(TargetPlatform::IntType platforms, Args &&... args) { void insert(TargetPlatform::IntType platforms, Args &&... args) {
insert(platforms, new InstanceT(std::forward<Args>(args)...)); insert(platforms, std::make_shared<InstanceT>(std::forward<Args>(args)...));
} }
/// Calls @c insert with the specified parameters, ignoring any exceptions thrown. /// Calls @c insert with the specified parameters, ignoring any exceptions thrown.
@ -182,10 +182,10 @@ static Media GetMediaAndPlatforms(const std::string &file_name, TargetPlatform::
if constexpr (std::is_same<Type, nullptr_t>::value) { if constexpr (std::is_same<Type, nullptr_t>::value) {
// It's valid for no media to be returned. // It's valid for no media to be returned.
} else if constexpr (std::is_same<Type, Disk::DiskImageHolderBase *>::value) { } else if constexpr (std::is_same<Type, Disk::DiskImageHolderBase *>::value) {
accumulator.insert(TargetPlatform::DiskII, arg); accumulator.insert(TargetPlatform::DiskII, std::shared_ptr<Disk::DiskImageHolderBase>(arg));
} else if constexpr (std::is_same<Type, MassStorage::MassStorageDevice *>::value) { } else if constexpr (std::is_same<Type, MassStorage::MassStorageDevice *>::value) {
// TODO: or is it Apple IIgs? // TODO: or is it Apple IIgs?
accumulator.insert(TargetPlatform::AppleII, arg); accumulator.insert(TargetPlatform::AppleII, std::shared_ptr<MassStorage::MassStorageDevice>(arg));
} else { } else {
static_assert(always_false_v<Type>, "Unexpected type encountered."); static_assert(always_false_v<Type>, "Unexpected type encountered.");
} }
@ -303,26 +303,28 @@ Media Analyser::Static::GetMedia(const std::string &file_name) {
} }
TargetList Analyser::Static::GetTargets(const std::string &file_name) { TargetList Analyser::Static::GetTargets(const std::string &file_name) {
TargetList targets;
const std::string extension = get_extension(file_name); const std::string extension = get_extension(file_name);
TargetList targets;
// Check whether the file directly identifies a target; if so then just return that. // Check whether the file directly identifies a target; if so then just return that.
#define Format(ext, class) \ const auto try_snapshot = [&](const char *ext, auto loader) -> bool {
if(extension == ext) { \ if(extension != ext) {
try { \ return false;
auto target = Storage::State::class::load(file_name); \ }
if(target) { \ try {
targets.push_back(std::move(target)); \ auto target = loader(file_name);
return targets; \ if(target) {
} \ targets.push_back(std::move(target));
} catch(...) {} \ return true;
} }
} catch(...) {}
Format("sna", SNA); return false;
Format("szx", SZX); };
Format("z80", Z80);
#undef TryInsert if(try_snapshot("sna", Storage::State::SNA::load)) return targets;
if(try_snapshot("szx", Storage::State::SZX::load)) return targets;
if(try_snapshot("z80", Storage::State::Z80::load)) return targets;
// Otherwise: // Otherwise:
// //
@ -333,30 +335,33 @@ TargetList Analyser::Static::GetTargets(const std::string &file_name) {
// Hand off to platform-specific determination of whether these // Hand off to platform-specific determination of whether these
// things are actually compatible and, if so, how to load them. // things are actually compatible and, if so, how to load them.
#define Append(x) if(potential_platforms & TargetPlatform::x) {\ const auto append = [&](TargetPlatform::IntType platform, auto evaluator) {
auto new_targets = x::GetTargets(media, file_name, potential_platforms);\ if(!(potential_platforms & platform)) {
std::move(new_targets.begin(), new_targets.end(), std::back_inserter(targets));\ return;
} }
Append(Acorn); auto new_targets = evaluator(media, file_name, potential_platforms);
Append(AmstradCPC); std::move(new_targets.begin(), new_targets.end(), std::back_inserter(targets));
Append(AppleII); };
Append(AppleIIgs);
Append(Amiga); append(TargetPlatform::Acorn, Acorn::GetTargets);
Append(Atari2600); append(TargetPlatform::AmstradCPC, AmstradCPC::GetTargets);
Append(AtariST); append(TargetPlatform::AppleII, AppleII::GetTargets);
Append(Coleco); append(TargetPlatform::AppleIIgs, AppleIIgs::GetTargets);
Append(Commodore); append(TargetPlatform::Amiga, Amiga::GetTargets);
Append(DiskII); append(TargetPlatform::Atari2600, Atari2600::GetTargets);
Append(Enterprise); append(TargetPlatform::AtariST, AtariST::GetTargets);
Append(FAT12); append(TargetPlatform::Coleco, Coleco::GetTargets);
Append(Macintosh); append(TargetPlatform::Commodore, Commodore::GetTargets);
Append(MSX); append(TargetPlatform::DiskII, DiskII::GetTargets);
Append(Oric); append(TargetPlatform::Enterprise, Enterprise::GetTargets);
Append(PCCompatible); append(TargetPlatform::FAT12, FAT12::GetTargets);
Append(Sega); append(TargetPlatform::Macintosh, Macintosh::GetTargets);
Append(ZX8081); append(TargetPlatform::MSX, MSX::GetTargets);
Append(ZXSpectrum); append(TargetPlatform::Oric, Oric::GetTargets);
#undef Append append(TargetPlatform::PCCompatible, PCCompatible::GetTargets);
append(TargetPlatform::Sega, Sega::GetTargets);
append(TargetPlatform::ZX8081, ZX8081::GetTargets);
append(TargetPlatform::ZXSpectrum, ZXSpectrum::GetTargets);
// Reset any tapes to their initial position. // Reset any tapes to their initial position.
for(const auto &target : targets) { for(const auto &target : targets) {

View File

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>IDEDidComputeMac32BitWarning</key>
<true/>
</dict>
</plist>