diff options
author | Tobias Hunger <tobias.hunger@qt.io> | 2018-06-14 15:46:33 +0200 |
---|---|---|
committer | Tobias Hunger <tobias.hunger@qt.io> | 2018-06-15 12:12:01 +0000 |
commit | 4ceed778f84ec2c04bcd64d873145a23f61a141c (patch) | |
tree | b1e4b0755a3167331a4fbd6538c4b1b9d964b870 /src/plugins/projectexplorer | |
parent | 35844008e21c9086ce0503e3639939dba960a3fa (diff) | |
download | qt-creator-4ceed778f84ec2c04bcd64d873145a23f61a141c.tar.gz |
Abi: Clean up constructors
Only have one constructor. Get rid of implicit conversion from QString
to Abi -- that seems rather non-obvious. Use Abi::fromString(...) instead.
Change-Id: Ic638d3d4022c465123449089b0679197a5eb445d
Reviewed-by: hjk <hjk@qt.io>
Reviewed-by: Eike Ziller <eike.ziller@qt.io>
Diffstat (limited to 'src/plugins/projectexplorer')
-rw-r--r-- | src/plugins/projectexplorer/abi.cpp | 77 | ||||
-rw-r--r-- | src/plugins/projectexplorer/abi.h | 12 | ||||
-rw-r--r-- | src/plugins/projectexplorer/abiwidget.cpp | 6 | ||||
-rw-r--r-- | src/plugins/projectexplorer/customtoolchain.cpp | 2 | ||||
-rw-r--r-- | src/plugins/projectexplorer/gcctoolchain.cpp | 4 | ||||
-rw-r--r-- | src/plugins/projectexplorer/msvctoolchain.cpp | 2 | ||||
-rw-r--r-- | src/plugins/projectexplorer/userfileaccessor.cpp | 2 |
7 files changed, 53 insertions, 52 deletions
diff --git a/src/plugins/projectexplorer/abi.cpp b/src/plugins/projectexplorer/abi.cpp index 4aff7c3a96..f1d23db623 100644 --- a/src/plugins/projectexplorer/abi.cpp +++ b/src/plugins/projectexplorer/abi.cpp @@ -381,42 +381,6 @@ Abi::Abi(const Architecture &a, const OS &o, } } -Abi::Abi(const QString &abiString) : - m_architecture(UnknownArchitecture), m_os(UnknownOS), - m_osFlavor(UnknownFlavor), m_binaryFormat(UnknownFormat), m_wordWidth(0) -{ - const QVector<QStringRef> abiParts = abiString.splitRef('-'); - if (abiParts.count() >= 1) { - m_architecture = architectureFromString(abiParts.at(0)); - if (abiParts.at(0) != toString(m_architecture)) - return; - } - - if (abiParts.count() >= 2) { - m_os = osFromString(abiParts.at(1)); - if (abiParts.at(1) != toString(m_os)) - return; - } - - if (abiParts.count() >= 3) { - m_osFlavor = osFlavorFromString(abiParts.at(2), m_os); - if (abiParts.at(2) != toString(m_osFlavor)) - return; - } - - if (abiParts.count() >= 4) { - m_binaryFormat = binaryFormatFromString(abiParts.at(3)); - if (abiParts.at(3) != toString(m_binaryFormat)) - return; - } - - if (abiParts.count() >= 5) { - m_wordWidth = wordWidthFromString(abiParts.at(4)); - if (abiParts.at(4) != toString(m_wordWidth)) - return; - } -} - Abi Abi::abiFromTargetTriplet(const QString &triple) { const QString machine = triple.toLower(); @@ -724,6 +688,47 @@ QString Abi::toString(int w) return QString::fromLatin1("%1bit").arg(w); } +Abi Abi::fromString(const QString &abiString) +{ + Abi::Architecture architecture = UnknownArchitecture; + const QVector<QStringRef> abiParts = abiString.splitRef('-'); + if (abiParts.count() >= 1) { + architecture = architectureFromString(abiParts.at(0)); + if (abiParts.at(0) != toString(architecture)) + return Abi(); + } + + Abi::OS os = UnknownOS; + if (abiParts.count() >= 2) { + os = osFromString(abiParts.at(1)); + if (abiParts.at(1) != toString(os)) + return Abi(architecture, UnknownOS, UnknownFlavor, UnknownFormat, 0); + } + + Abi::OSFlavor flavor = UnknownFlavor; + if (abiParts.count() >= 3) { + flavor = osFlavorFromString(abiParts.at(2), os); + if (abiParts.at(2) != toString(flavor)) + return Abi(architecture, os, UnknownFlavor, UnknownFormat, 0);; + } + + Abi::BinaryFormat format = UnknownFormat; + if (abiParts.count() >= 4) { + format = binaryFormatFromString(abiParts.at(3)); + if (abiParts.at(3) != toString(format)) + return Abi(architecture, os, flavor, UnknownFormat, 0);; + } + + unsigned char wordWidth = 0; + if (abiParts.count() >= 5) { + wordWidth = wordWidthFromString(abiParts.at(4)); + if (abiParts.at(4) != toString(wordWidth)) + return Abi(architecture, os, flavor, format, 0);; + } + + return Abi(architecture, os, flavor, format, wordWidth); +} + Abi::Architecture Abi::architectureFromString(const QStringRef &a) { if (a == "unknown") diff --git a/src/plugins/projectexplorer/abi.h b/src/plugins/projectexplorer/abi.h index 45702b0054..c78add7314 100644 --- a/src/plugins/projectexplorer/abi.h +++ b/src/plugins/projectexplorer/abi.h @@ -112,14 +112,9 @@ public: UnknownFormat }; - Abi() : - m_architecture(UnknownArchitecture), m_os(UnknownOS), - m_osFlavor(UnknownFlavor), m_binaryFormat(UnknownFormat), m_wordWidth(0) - { } - - Abi(const Architecture &a, const OS &o, - const OSFlavor &so, const BinaryFormat &f, unsigned char w); - Abi(const QString &abiString); + Abi(const Architecture &a = UnknownArchitecture, const OS &o = UnknownOS, + const OSFlavor &so = UnknownFlavor, const BinaryFormat &f = UnknownFormat, + unsigned char w = 0); static Abi abiFromTargetTriplet(const QString &machineTriple); @@ -153,6 +148,7 @@ public: static QList<OSFlavor> flavorsForOs(const OS &o); static OSFlavor flavorForMsvcVersion(int version); + static Abi fromString(const QString &abiString); static Abi hostAbi(); static QList<Abi> abisOfBinary(const Utils::FileName &path); diff --git a/src/plugins/projectexplorer/abiwidget.cpp b/src/plugins/projectexplorer/abiwidget.cpp index efff460634..577bd2e983 100644 --- a/src/plugins/projectexplorer/abiwidget.cpp +++ b/src/plugins/projectexplorer/abiwidget.cpp @@ -197,7 +197,7 @@ QList<Abi> AbiWidget::supportedAbis() const QList<Abi> result; result.reserve(d->m_abi->count()); for (int i = 1; i < d->m_abi->count(); ++i) - result << Abi(d->m_abi->itemData(i).toString()); + result << Abi::fromString(d->m_abi->itemData(i).toString()); return result; } @@ -240,7 +240,7 @@ void AbiWidget::mainComboBoxChanged() if (d->m_ignoreChanges.isLocked()) return; - const Abi newAbi = d->m_abi->currentData().toString(); + const Abi newAbi = Abi::fromString(d->m_abi->currentData().toString()); const bool customMode = d->isCustom(); d->m_architectureComboBox->setEnabled(customMode); @@ -254,7 +254,7 @@ void AbiWidget::mainComboBoxChanged() if (customMode) customComboBoxesChanged(); else - emitAbiChanged(Abi(d->m_abi->currentData().toString())); + emitAbiChanged(Abi::fromString(d->m_abi->currentData().toString())); } void AbiWidget::customComboBoxesChanged() diff --git a/src/plugins/projectexplorer/customtoolchain.cpp b/src/plugins/projectexplorer/customtoolchain.cpp index e8feb0b15f..68c663bbc9 100644 --- a/src/plugins/projectexplorer/customtoolchain.cpp +++ b/src/plugins/projectexplorer/customtoolchain.cpp @@ -336,7 +336,7 @@ bool CustomToolChain::fromMap(const QVariantMap &data) m_compilerCommand = FileName::fromString(data.value(QLatin1String(compilerCommandKeyC)).toString()); m_makeCommand = FileName::fromString(data.value(QLatin1String(makeCommandKeyC)).toString()); - m_targetAbi = Abi(data.value(QLatin1String(targetAbiKeyC)).toString()); + m_targetAbi = Abi::fromString(data.value(QLatin1String(targetAbiKeyC)).toString()); const QStringList macros = data.value(QLatin1String(predefinedMacrosKeyC)).toStringList(); m_predefinedMacros = Macro::toMacros(macros.join('\n').toUtf8()); setHeaderPaths(data.value(QLatin1String(headerPathsKeyC)).toStringList()); diff --git a/src/plugins/projectexplorer/gcctoolchain.cpp b/src/plugins/projectexplorer/gcctoolchain.cpp index 98b7825d5b..bf0434f926 100644 --- a/src/plugins/projectexplorer/gcctoolchain.cpp +++ b/src/plugins/projectexplorer/gcctoolchain.cpp @@ -831,12 +831,12 @@ bool GccToolChain::fromMap(const QVariantMap &data) m_compilerCommand = FileName::fromString(data.value(compilerCommandKeyC).toString()); m_platformCodeGenFlags = data.value(compilerPlatformCodeGenFlagsKeyC).toStringList(); m_platformLinkerFlags = data.value(compilerPlatformLinkerFlagsKeyC).toStringList(); - m_targetAbi = Abi(data.value(targetAbiKeyC).toString()); + m_targetAbi = Abi::fromString(data.value(targetAbiKeyC).toString()); m_originalTargetTriple = data.value(originalTargetTripleKeyC).toString(); const QStringList abiList = data.value(supportedAbisKeyC).toStringList(); m_supportedAbis.clear(); for (const QString &a : abiList) { - Abi abi(a); + Abi abi = Abi::fromString(a); if (!abi.isValid()) continue; m_supportedAbis.append(abi); diff --git a/src/plugins/projectexplorer/msvctoolchain.cpp b/src/plugins/projectexplorer/msvctoolchain.cpp index aead49aa6c..0d53518236 100644 --- a/src/plugins/projectexplorer/msvctoolchain.cpp +++ b/src/plugins/projectexplorer/msvctoolchain.cpp @@ -708,7 +708,7 @@ bool MsvcToolChain::fromMap(const QVariantMap &data) m_vcvarsBat = QDir::fromNativeSeparators(data.value(QLatin1String(varsBatKeyC)).toString()); m_varsBatArg = data.value(QLatin1String(varsBatArgKeyC)).toString(); const QString abiString = data.value(QLatin1String(supportedAbiKeyC)).toString(); - m_abi = Abi(abiString); + m_abi = Abi::fromString(abiString); m_environmentModifications = Utils::EnvironmentItem::itemsFromVariantList( data.value(QLatin1String(environModsKeyC)).toList()); diff --git a/src/plugins/projectexplorer/userfileaccessor.cpp b/src/plugins/projectexplorer/userfileaccessor.cpp index 085e2cf3a8..ee3c729e23 100644 --- a/src/plugins/projectexplorer/userfileaccessor.cpp +++ b/src/plugins/projectexplorer/userfileaccessor.cpp @@ -1588,7 +1588,7 @@ QVariantMap UserFileVersion11Upgrader::upgrade(const QVariantMap &map) Abi compilerAbi; int debuggerEngine = 1; // GDB for (int i = 1; i < split.count() - 1; ++i) { - compilerAbi = Abi(split.at(i)); + compilerAbi = Abi::fromString(split.at(i)); if (!compilerAbi.isValid()) continue; if (compilerAbi.os() == Abi::WindowsOS |