Skip to content

Commit

Permalink
Tools: use _L1 for for creating Latin-1 string literals
Browse files Browse the repository at this point in the history
As a drive-by, fix qsizetype -> int narrowing conversion warnings for
the touched lines.

Task-number: QTBUG-98434
Change-Id: I6d4712a71b5ebf3f379f1f98ea476557bce963ef
Reviewed-by: Marc Mutz <[email protected]>
  • Loading branch information
Sona Kurazyan committed May 2, 2022
1 parent a0539ed commit 39a6307
Show file tree
Hide file tree
Showing 20 changed files with 326 additions and 303 deletions.
30 changes: 15 additions & 15 deletions src/tools/cmake_automoc_parser/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@

QT_BEGIN_NAMESPACE

using namespace Qt::StringLiterals;

using AutoGenHeaderMap = QMap<QString, QString>;
using AutoGenSourcesList = QList<QString>;

Expand All @@ -75,9 +77,9 @@ static bool readAutogenInfoJson(AutoGenHeaderMap &headers, AutoGenSourcesList &s
}

QJsonObject rootObject = doc.object();
QJsonValue headersValue = rootObject.value(QLatin1String("HEADERS"));
QJsonValue sourcesValue = rootObject.value(QLatin1String("SOURCES"));
QJsonValue headerExtValue = rootObject.value(QLatin1String("HEADER_EXTENSIONS"));
QJsonValue headersValue = rootObject.value("HEADERS"_L1);
QJsonValue sourcesValue = rootObject.value("SOURCES"_L1);
QJsonValue headerExtValue = rootObject.value("HEADER_EXTENSIONS"_L1);

if (!headersValue.isArray() || !sourcesValue.isArray() || !headerExtValue.isArray()) {
fprintf(stderr,
Expand Down Expand Up @@ -154,12 +156,12 @@ static bool readParseCache(ParseCacheMap &entries, const QString &parseCacheFile
// ....

QTextStream textStream(&file);
const QString mmcKey = QString(QLatin1String(" mmc:"));
const QString miuKey = QString(QLatin1String(" miu:"));
const QString uicKey = QString(QLatin1String(" uic:"));
const QString midKey = QString(QLatin1String(" mid:"));
const QString mdpKey = QString(QLatin1String(" mdp:"));
const QString udpKey = QString(QLatin1String(" udp:"));
const QString mmcKey = QString(" mmc:"_L1);
const QString miuKey = QString(" miu:"_L1);
const QString uicKey = QString(" uic:"_L1);
const QString midKey = QString(" mid:"_L1);
const QString mdpKey = QString(" mdp:"_L1);
const QString udpKey = QString(" udp:"_L1);
QString line;
bool mmc_key_found = false;
while (textStream.readLineInto(&line)) {
Expand Down Expand Up @@ -356,12 +358,11 @@ int main(int argc, char **argv)
}
}
// Add extra moc files
for (const auto &mocFile : it.value().mocFiles) {
jsonFileList.push_back(dir.filePath(mocFile) + QLatin1String(".json"));
}
for (const auto &mocFile : it.value().mocFiles)
jsonFileList.push_back(dir.filePath(mocFile) + ".json"_L1);
// Add main moc files
for (const auto &mocFile : it.value().mocIncludes) {
jsonFileList.push_back(dir.filePath(mocFile) + QLatin1String(".json"));
jsonFileList.push_back(dir.filePath(mocFile) + ".json"_L1);
// 1b) Locate this header and delete it
constexpr int mocKeyLen = 4; // length of "moc_"
const QString headerBaseName =
Expand Down Expand Up @@ -394,8 +395,7 @@ int main(int argc, char **argv)
const QString pathPrefix = !isMultiConfig
? QStringLiteral("../")
: QString();
const QString jsonPath =
dir.filePath(pathPrefix + mapIt.value() + QLatin1String(".json"));
const QString jsonPath = dir.filePath(pathPrefix + mapIt.value() + ".json"_L1);
jsonFileList.push_back(jsonPath);
}

Expand Down
14 changes: 6 additions & 8 deletions src/tools/macdeployqt/shared/shared.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ bool deployFramework = false;

using std::cout;
using std::endl;
using namespace Qt::StringLiterals;

bool operator==(const FrameworkInfo &a, const FrameworkInfo &b)
{
Expand Down Expand Up @@ -850,7 +851,7 @@ void changeInstallName(const QString &bundlePath, const FrameworkInfo &framework
for (const QString &binary : binaryPaths) {
QString deployedInstallName;
if (useLoaderPath) {
deployedInstallName = QLatin1String("@loader_path/")
deployedInstallName = "@loader_path/"_L1
+ QFileInfo(binary).absoluteDir().relativeFilePath(absBundlePath + u'/' + framework.binaryDestinationDirectory + u'/' + framework.binaryName);
} else {
deployedInstallName = framework.deployedInstallName;
Expand All @@ -873,9 +874,9 @@ void addRPath(const QString &rpath, const QString &binaryPath)
void deployRPaths(const QString &bundlePath, const QList<QString> &rpaths, const QString &binaryPath, bool useLoaderPath)
{
const QString absFrameworksPath = QFileInfo(bundlePath).absoluteFilePath()
+ QLatin1String("/Contents/Frameworks");
+ "/Contents/Frameworks"_L1;
const QString relativeFrameworkPath = QFileInfo(binaryPath).absoluteDir().relativeFilePath(absFrameworksPath);
const QString loaderPathToFrameworks = QLatin1String("@loader_path/") + relativeFrameworkPath;
const QString loaderPathToFrameworks = "@loader_path/"_L1 + relativeFrameworkPath;
bool rpathToFrameworksFound = false;
QStringList args;
QList<QString> binaryRPaths = getBinaryRPaths(binaryPath, false);
Expand Down Expand Up @@ -945,13 +946,10 @@ void stripAppBinary(const QString &bundlePath)
bool DeploymentInfo::containsModule(const QString &module, const QString &libInFix) const
{
// Check for framework first
if (deployedFrameworks.contains(QLatin1String("Qt") + module + libInFix +
QLatin1String(".framework"))) {
if (deployedFrameworks.contains("Qt"_L1 + module + libInFix + ".framework"_L1))
return true;
}
// Check for dylib
const QRegularExpression dylibRegExp(QLatin1String("libQt[0-9]+") + module +
libInFix + QLatin1String(".[0-9]+.dylib"));
const QRegularExpression dylibRegExp("libQt[0-9]+"_L1 + module + libInFix + ".[0-9]+.dylib"_L1);
return deployedFrameworks.filter(dylibRegExp).size() > 0;
}

Expand Down
20 changes: 11 additions & 9 deletions src/tools/moc/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@

QT_BEGIN_NAMESPACE

using namespace Qt::StringLiterals;

/*
This function looks at two file names and returns the name of the
infile with a path relative to outfile.
Expand Down Expand Up @@ -354,7 +356,7 @@ int runMoc(int argc, char **argv)
return collectJson(files, output, hasOptionFiles);

if (files.count() > 1) {
error(qPrintable(QLatin1String("Too many input files specified: '") + files.join(QLatin1String("' '")) + u'\''));
error(qPrintable("Too many input files specified: '"_L1 + files.join("' '"_L1) + u'\''));
parser.showHelp(1);
} else if (!files.isEmpty()) {
filename = files.first();
Expand Down Expand Up @@ -390,7 +392,7 @@ int runMoc(int argc, char **argv)
for (const QString &path : includePaths)
pp.includes += Preprocessor::IncludePath(QFile::encodeName(path));
QString compilerFlavor = parser.value(compilerFlavorOption);
if (compilerFlavor.isEmpty() || compilerFlavor == QLatin1String("unix")) {
if (compilerFlavor.isEmpty() || compilerFlavor == "unix"_L1) {
// traditional Unix compilers use both CPATH and CPLUS_INCLUDE_PATH
// $CPATH feeds to #include <...> and #include "...", whereas
// CPLUS_INCLUDE_PATH is equivalent to GCC's -isystem, so we parse later
Expand All @@ -400,14 +402,14 @@ int runMoc(int argc, char **argv)
const auto cplus_include_path = qgetenv("CPLUS_INCLUDE_PATH").split(QDir::listSeparator().toLatin1());
for (const QByteArray &p : cplus_include_path)
pp.includes += Preprocessor::IncludePath(p);
} else if (compilerFlavor == QLatin1String("msvc")) {
} else if (compilerFlavor == "msvc"_L1) {
// MSVC uses one environment variable: INCLUDE
const auto include = qgetenv("INCLUDE").split(QDir::listSeparator().toLatin1());
for (const QByteArray &p : include)
pp.includes += Preprocessor::IncludePath(p);
} else {
error(qPrintable(QLatin1String("Unknown compiler flavor '") + compilerFlavor +
QLatin1String("'; valid values are: msvc, unix.")));
error(qPrintable("Unknown compiler flavor '"_L1 + compilerFlavor +
"'; valid values are: msvc, unix."_L1));
parser.showHelp(1);
}

Expand Down Expand Up @@ -446,9 +448,9 @@ int runMoc(int argc, char **argv)
pp.macros.remove(macro);
}
const QStringList noNotesCompatValues = parser.values(noNotesWarningsCompatOption);
if (parser.isSet(noNotesOption) || noNotesCompatValues.contains(QLatin1String("n")))
if (parser.isSet(noNotesOption) || noNotesCompatValues.contains("n"_L1))
moc.displayNotes = false;
if (parser.isSet(noWarningsOption) || noNotesCompatValues.contains(QLatin1String("w")))
if (parser.isSet(noWarningsOption) || noNotesCompatValues.contains("w"_L1))
moc.displayWarnings = moc.displayNotes = false;

if (autoInclude) {
Expand Down Expand Up @@ -564,7 +566,7 @@ int runMoc(int argc, char **argv)
}

if (parser.isSet(jsonOption)) {
const QString jsonOutputFileName = output + QLatin1String(".json");
const QString jsonOutputFileName = output + ".json"_L1;
FILE *f;
#if defined(_MSC_VER)
if (_wfopen_s(&f, reinterpret_cast<const wchar_t *>(jsonOutputFileName.utf16()), L"w") != 0)
Expand Down Expand Up @@ -605,7 +607,7 @@ int runMoc(int argc, char **argv)
if (parser.isSet(depFilePathOption)) {
depOutputFileName = parser.value(depFilePathOption);
} else if (outputToFile) {
depOutputFileName = output + QLatin1String(".d");
depOutputFileName = output + ".d"_L1;
} else {
fprintf(stderr, "moc: Writing to stdout, but no depfile path specified.\n");
}
Expand Down
Loading

0 comments on commit 39a6307

Please sign in to comment.