forked from qt-creator/qt-creator
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>
This commit is contained in:
@@ -95,7 +95,7 @@ DebuggerItem::DebuggerItem(const QVariantMap &data)
|
||||
m_lastModified = data.value(QLatin1String(DEBUGGER_INFORMATION_LASTMODIFIED)).toDateTime();
|
||||
|
||||
foreach (const QString &a, data.value(QLatin1String(DEBUGGER_INFORMATION_ABIS)).toStringList()) {
|
||||
Abi abi(a);
|
||||
Abi abi = Abi::fromString(a);
|
||||
if (!abi.isNull())
|
||||
m_abis.append(abi);
|
||||
}
|
||||
|
||||
@@ -356,7 +356,7 @@ DebuggerItem DebuggerItemConfigWidget::item() const
|
||||
foreach (const QString &a, m_abis->text().split(QRegExp(QLatin1String("[^A-Za-z0-9-_]+")))) {
|
||||
if (a.isNull())
|
||||
continue;
|
||||
abiList << a;
|
||||
abiList << Abi::fromString(a);
|
||||
}
|
||||
item.setAbis(abiList);
|
||||
item.setVersion(m_versionLabel->text());
|
||||
|
||||
@@ -3754,12 +3754,12 @@ void DebuggerUnitTests::testDebuggerMatching()
|
||||
|
||||
QList<Abi> debuggerAbis;
|
||||
foreach (const QString &abi, debugger)
|
||||
debuggerAbis << Abi(abi);
|
||||
debuggerAbis << Abi::fromString(abi);
|
||||
|
||||
DebuggerItem item;
|
||||
item.setAbis(debuggerAbis);
|
||||
|
||||
DebuggerItem::MatchLevel level = item.matchTarget(Abi(target));
|
||||
DebuggerItem::MatchLevel level = item.matchTarget(Abi::fromString(target));
|
||||
if (level == DebuggerItem::MatchesPerfectly)
|
||||
level = DebuggerItem::MatchesWell;
|
||||
|
||||
|
||||
@@ -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")
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
@@ -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()
|
||||
|
||||
@@ -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());
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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());
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user