summaryrefslogtreecommitdiffstats
path: root/src/tools
diff options
context:
space:
mode:
Diffstat (limited to 'src/tools')
-rw-r--r--src/tools/bootstrap/bootstrap.pro6
-rw-r--r--src/tools/moc/generator.cpp7
-rw-r--r--src/tools/moc/main.cpp70
-rw-r--r--src/tools/moc/preprocessor.cpp65
-rw-r--r--src/tools/moc/preprocessor.h1
-rw-r--r--src/tools/uic/cpp/cppwriteinitialization.cpp40
6 files changed, 134 insertions, 55 deletions
diff --git a/src/tools/bootstrap/bootstrap.pro b/src/tools/bootstrap/bootstrap.pro
index a43105297f..f763d0c8fe 100644
--- a/src/tools/bootstrap/bootstrap.pro
+++ b/src/tools/bootstrap/bootstrap.pro
@@ -119,12 +119,12 @@ mac {
LIBS += -framework Foundation
osx: LIBS_PRIVATE += -framework CoreServices
- ios: LIBS_PRIVATE += -framework UIKit
+ uikit: LIBS_PRIVATE += -framework UIKit
}
macx {
OBJECTIVE_SOURCES += \
- ../../corelib/tools/qstring_mac.mm \
+ ../../corelib/kernel/qcore_foundation.mm \
../../corelib/io/qstandardpaths_mac.mm
} else:unix {
SOURCES += \
@@ -134,7 +134,7 @@ macx {
../../corelib/io/qstandardpaths_win.cpp
}
-contains(QT_CONFIG, zlib)|cross_compile {
+!contains(QT_CONFIG, system-zlib)|cross_compile {
include(../../3rdparty/zlib.pri)
} else {
CONFIG += no_core_dep
diff --git a/src/tools/moc/generator.cpp b/src/tools/moc/generator.cpp
index 7de6fe632f..ccc6d795d7 100644
--- a/src/tools/moc/generator.cpp
+++ b/src/tools/moc/generator.cpp
@@ -878,9 +878,14 @@ void Generator::generateEnums(int index)
int i;
for (i = 0; i < cdef->enumList.count(); ++i) {
const EnumDef &e = cdef->enumList.at(i);
+ int flags = 0;
+ if (cdef->enumDeclarations.value(e.name))
+ flags |= EnumIsFlag;
+ if (e.isEnumClass)
+ flags |= EnumIsScoped;
fprintf(out, " %4d, 0x%.1x, %4d, %4d,\n",
stridx(e.name),
- cdef->enumDeclarations.value(e.name) ? 1 : 0,
+ flags,
e.values.count(),
index);
index += e.values.count() * 2;
diff --git a/src/tools/moc/main.cpp b/src/tools/moc/main.cpp
index 0734a92d5a..55cf7ed872 100644
--- a/src/tools/moc/main.cpp
+++ b/src/tools/moc/main.cpp
@@ -1,6 +1,7 @@
/****************************************************************************
**
** Copyright (C) 2016 The Qt Company Ltd.
+** Copyright (C) 2016 Intel Corporation.
** Contact: https://www.qt.io/licensing/
**
** This file is part of the tools applications of the Qt Toolkit.
@@ -200,20 +201,24 @@ int runMoc(int argc, char **argv)
.arg(mocOutputRevision).arg(QString::fromLatin1(QT_VERSION_STR)));
parser.addHelpOption();
parser.addVersionOption();
+ parser.setSingleDashWordOptionMode(QCommandLineParser::ParseAsLongOptions);
QCommandLineOption outputOption(QStringLiteral("o"));
outputOption.setDescription(QStringLiteral("Write output to file rather than stdout."));
outputOption.setValueName(QStringLiteral("file"));
+ outputOption.setFlags(QCommandLineOption::ShortOptionStyle);
parser.addOption(outputOption);
QCommandLineOption includePathOption(QStringLiteral("I"));
includePathOption.setDescription(QStringLiteral("Add dir to the include path for header files."));
includePathOption.setValueName(QStringLiteral("dir"));
+ includePathOption.setFlags(QCommandLineOption::ShortOptionStyle);
parser.addOption(includePathOption);
QCommandLineOption macFrameworkOption(QStringLiteral("F"));
macFrameworkOption.setDescription(QStringLiteral("Add Mac framework to the include path for header files."));
macFrameworkOption.setValueName(QStringLiteral("framework"));
+ macFrameworkOption.setFlags(QCommandLineOption::ShortOptionStyle);
parser.addOption(macFrameworkOption);
QCommandLineOption preprocessOption(QStringLiteral("E"));
@@ -223,18 +228,26 @@ int runMoc(int argc, char **argv)
QCommandLineOption defineOption(QStringLiteral("D"));
defineOption.setDescription(QStringLiteral("Define macro, with optional definition."));
defineOption.setValueName(QStringLiteral("macro[=def]"));
+ defineOption.setFlags(QCommandLineOption::ShortOptionStyle);
parser.addOption(defineOption);
QCommandLineOption undefineOption(QStringLiteral("U"));
undefineOption.setDescription(QStringLiteral("Undefine macro."));
undefineOption.setValueName(QStringLiteral("macro"));
+ undefineOption.setFlags(QCommandLineOption::ShortOptionStyle);
parser.addOption(undefineOption);
QCommandLineOption metadataOption(QStringLiteral("M"));
metadataOption.setDescription(QStringLiteral("Add key/value pair to plugin meta data"));
metadataOption.setValueName(QStringLiteral("key=value"));
+ metadataOption.setFlags(QCommandLineOption::ShortOptionStyle);
parser.addOption(metadataOption);
+ QCommandLineOption compilerFlavorOption(QStringLiteral("compiler-flavor"));
+ compilerFlavorOption.setDescription(QStringLiteral("Set the compiler flavor: either \"msvc\" or \"unix\"."));
+ compilerFlavorOption.setValueName(QStringLiteral("flavor"));
+ parser.addOption(compilerFlavorOption);
+
QCommandLineOption noIncludeOption(QStringLiteral("i"));
noIncludeOption.setDescription(QStringLiteral("Do not generate an #include statement."));
parser.addOption(noIncludeOption);
@@ -242,11 +255,13 @@ int runMoc(int argc, char **argv)
QCommandLineOption pathPrefixOption(QStringLiteral("p"));
pathPrefixOption.setDescription(QStringLiteral("Path prefix for included file."));
pathPrefixOption.setValueName(QStringLiteral("path"));
+ pathPrefixOption.setFlags(QCommandLineOption::ShortOptionStyle);
parser.addOption(pathPrefixOption);
QCommandLineOption forceIncludeOption(QStringLiteral("f"));
forceIncludeOption.setDescription(QStringLiteral("Force #include <file> (overwrite default)."));
forceIncludeOption.setValueName(QStringLiteral("file"));
+ forceIncludeOption.setFlags(QCommandLineOption::ShortOptionStyle);
parser.addOption(forceIncludeOption);
QCommandLineOption prependIncludeOption(QStringLiteral("b"));
@@ -254,9 +269,15 @@ int runMoc(int argc, char **argv)
prependIncludeOption.setValueName(QStringLiteral("file"));
parser.addOption(prependIncludeOption);
+ QCommandLineOption includeOption(QStringLiteral("include"));
+ includeOption.setDescription(QStringLiteral("Parse <file> as an #include before the main source(s)."));
+ includeOption.setValueName(QStringLiteral("file"));
+ parser.addOption(includeOption);
+
QCommandLineOption noNotesWarningsCompatOption(QStringLiteral("n"));
noNotesWarningsCompatOption.setDescription(QStringLiteral("Do not display notes (-nn) or warnings (-nw). Compatibility option."));
noNotesWarningsCompatOption.setValueName(QStringLiteral("which"));
+ noNotesWarningsCompatOption.setFlags(QCommandLineOption::ShortOptionStyle);
parser.addOption(noNotesWarningsCompatOption);
QCommandLineOption noNotesOption(QStringLiteral("no-notes"));
@@ -313,9 +334,32 @@ int runMoc(int argc, char **argv)
if (parser.isSet(pathPrefixOption))
moc.includePath = QFile::encodeName(parser.value(pathPrefixOption));
}
+
const auto includePaths = parser.values(includePathOption);
for (const QString &path : includePaths)
pp.includes += Preprocessor::IncludePath(QFile::encodeName(path));
+ QString compilerFlavor = parser.value(compilerFlavorOption);
+ if (compilerFlavor.isEmpty() || compilerFlavor == QLatin1String("unix")) {
+ // 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
+ const auto cpath = qgetenv("CPATH").split(QDir::listSeparator().toLatin1());
+ for (const QByteArray &p : cpath)
+ pp.includes += Preprocessor::IncludePath(p);
+ 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")) {
+ // 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.")));
+ parser.showHelp(1);
+ }
+
const auto macFrameworks = parser.values(macFrameworkOption);
for (const QString &path : macFrameworks) {
// minimalistic framework support for the mac
@@ -410,7 +454,31 @@ int runMoc(int argc, char **argv)
moc.includes = pp.includes;
// 1. preprocess
- moc.symbols = pp.preprocessed(moc.filename, &in);
+ const auto includeFiles = parser.values(includeOption);
+ for (const QString &includeName : includeFiles) {
+ QByteArray rawName = pp.resolveInclude(QFile::encodeName(includeName), moc.filename);
+ if (rawName.isEmpty()) {
+ fprintf(stderr, "Warning: Failed to resolve include \"%s\" for moc file %s\n",
+ includeName.toLocal8Bit().constData(),
+ moc.filename.isEmpty() ? "<standard input>" : moc.filename.constData());
+ } else {
+ QFile f(QFile::decodeName(rawName));
+ if (f.open(QIODevice::ReadOnly)) {
+ moc.symbols += Symbol(0, MOC_INCLUDE_BEGIN, rawName);
+ moc.symbols += pp.preprocessed(rawName, &f);
+ moc.symbols += Symbol(0, MOC_INCLUDE_END, rawName);
+ } else {
+ fprintf(stderr, "Warning: Cannot open %s included by moc file %s: %s\n",
+ rawName.constData(),
+ moc.filename.isEmpty() ? "<standard input>" : moc.filename.constData(),
+ f.errorString().toLocal8Bit().constData());
+ }
+ }
+ }
+ moc.symbols += pp.preprocessed(moc.filename, &in);
+
+ // We obviously do not support MS extensions
+ pp.macros.remove("_MSC_EXTENSIONS");
if (!pp.preprocessOnly) {
// 2. parse
diff --git a/src/tools/moc/preprocessor.cpp b/src/tools/moc/preprocessor.cpp
index 74c75eda5b..415003e6b1 100644
--- a/src/tools/moc/preprocessor.cpp
+++ b/src/tools/moc/preprocessor.cpp
@@ -696,13 +696,10 @@ Symbols Preprocessor::macroExpandIdentifier(Preprocessor *that, SymbolStack &sym
next = arg.at(0);
}
- if (!expansion.isEmpty() && expansion.constLast().token == s.token) {
- Symbol last = expansion.constLast();
+ Symbol last = expansion.constLast();
+ if (!expansion.isEmpty() && last.token == s.token && last.token != STRING_LITERAL) {
expansion.pop_back();
- if (last.token == STRING_LITERAL || s.token == STRING_LITERAL)
- that->error("Can't concatenate non identifier tokens");
-
QByteArray lexem = last.lexem() + next.lexem();
expansion += Symbol(lineNum, last.token, lexem);
} else {
@@ -1008,6 +1005,36 @@ static void mergeStringLiterals(Symbols *_symbols)
}
}
+QByteArray Preprocessor::resolveInclude(const QByteArray &include, const QByteArray &relativeTo)
+{
+ // #### stringery
+ QFileInfo fi;
+ if (!relativeTo.isEmpty())
+ fi.setFile(QFileInfo(QString::fromLocal8Bit(relativeTo.constData())).dir(), QString::fromLocal8Bit(include.constData()));
+ for (int j = 0; j < Preprocessor::includes.size() && !fi.exists(); ++j) {
+ const IncludePath &p = Preprocessor::includes.at(j);
+ if (p.isFrameworkPath) {
+ const int slashPos = include.indexOf('/');
+ if (slashPos == -1)
+ continue;
+ fi.setFile(QString::fromLocal8Bit(p.path + '/' + include.left(slashPos) + ".framework/Headers/"),
+ QString::fromLocal8Bit(include.mid(slashPos + 1).constData()));
+ } else {
+ fi.setFile(QString::fromLocal8Bit(p.path.constData()), QString::fromLocal8Bit(include.constData()));
+ }
+ // try again, maybe there's a file later in the include paths with the same name
+ // (186067)
+ if (fi.isDir()) {
+ fi = QFileInfo();
+ continue;
+ }
+ }
+
+ if (!fi.exists() || fi.isDir())
+ return QByteArray();
+ return fi.canonicalFilePath().toLocal8Bit();
+}
+
void Preprocessor::preprocess(const QByteArray &filename, Symbols &preprocessed)
{
currentFilenames.push(filename);
@@ -1028,32 +1055,9 @@ void Preprocessor::preprocess(const QByteArray &filename, Symbols &preprocessed)
continue;
until(PP_NEWLINE);
- // #### stringery
- QFileInfo fi;
- if (local)
- fi.setFile(QFileInfo(QString::fromLocal8Bit(filename.constData())).dir(), QString::fromLocal8Bit(include.constData()));
- for (int j = 0; j < Preprocessor::includes.size() && !fi.exists(); ++j) {
- const IncludePath &p = Preprocessor::includes.at(j);
- if (p.isFrameworkPath) {
- const int slashPos = include.indexOf('/');
- if (slashPos == -1)
- continue;
- fi.setFile(QString::fromLocal8Bit(p.path + '/' + include.left(slashPos) + ".framework/Headers/"),
- QString::fromLocal8Bit(include.mid(slashPos + 1).constData()));
- } else {
- fi.setFile(QString::fromLocal8Bit(p.path.constData()), QString::fromLocal8Bit(include.constData()));
- }
- // try again, maybe there's a file later in the include paths with the same name
- // (186067)
- if (fi.isDir()) {
- fi = QFileInfo();
- continue;
- }
- }
-
- if (!fi.exists() || fi.isDir())
+ include = resolveInclude(include, local ? filename : QByteArray());
+ if (include.isNull())
continue;
- include = fi.canonicalFilePath().toLocal8Bit();
if (Preprocessor::preprocessedIncludes.contains(include))
continue;
@@ -1208,6 +1212,7 @@ Symbols Preprocessor::preprocessed(const QByteArray &filename, QFile *file)
input = cleaned(input);
// phase 2: tokenize for the preprocessor
+ index = 0;
symbols = tokenize(input);
#if 0
diff --git a/src/tools/moc/preprocessor.h b/src/tools/moc/preprocessor.h
index 9a49751eb0..a7eb1a19e1 100644
--- a/src/tools/moc/preprocessor.h
+++ b/src/tools/moc/preprocessor.h
@@ -62,6 +62,7 @@ public:
QList<QByteArray> frameworks;
QSet<QByteArray> preprocessedIncludes;
Macros macros;
+ QByteArray resolveInclude(const QByteArray &filename, const QByteArray &relativeTo);
Symbols preprocessed(const QByteArray &filename, QFile *device);
void parseDefineArguments(Macro *m);
diff --git a/src/tools/uic/cpp/cppwriteinitialization.cpp b/src/tools/uic/cpp/cppwriteinitialization.cpp
index f08de35de2..ade3c5db35 100644
--- a/src/tools/uic/cpp/cppwriteinitialization.cpp
+++ b/src/tools/uic/cpp/cppwriteinitialization.cpp
@@ -770,22 +770,22 @@ void WriteInitialization::acceptWidget(DomWidget *node)
//
// Special handling for qtableview/qtreeview fake header attributes
//
- static const QStringList realPropertyNames =
- (QStringList() << QLatin1String("visible")
- << QLatin1String("cascadingSectionResizes")
- << QLatin1String("defaultSectionSize")
- << QLatin1String("highlightSections")
- << QLatin1String("minimumSectionSize")
- << QLatin1String("showSortIndicator")
- << QLatin1String("stretchLastSection"));
+ static const QLatin1String realPropertyNames[] = {
+ QLatin1String("visible"),
+ QLatin1String("cascadingSectionResizes"),
+ QLatin1String("defaultSectionSize"),
+ QLatin1String("highlightSections"),
+ QLatin1String("minimumSectionSize"),
+ QLatin1String("showSortIndicator"),
+ QLatin1String("stretchLastSection"),
+ };
if (m_uic->customWidgetsInfo()->extends(className, QLatin1String("QTreeView"))
|| m_uic->customWidgetsInfo()->extends(className, QLatin1String("QTreeWidget"))) {
DomPropertyList headerProperties;
- for (const QString &realPropertyName : realPropertyNames) {
- const QString upperPropertyName = realPropertyName.at(0).toUpper()
- + realPropertyName.mid(1);
- const QString fakePropertyName = QLatin1String("header") + upperPropertyName;
+ for (auto realPropertyName : realPropertyNames) {
+ const QString fakePropertyName = QLatin1String("header")
+ + QChar(realPropertyName.at(0)).toUpper() + realPropertyName.mid(1);
if (DomProperty *fakeProperty = attributes.value(fakePropertyName)) {
fakeProperty->setAttributeName(realPropertyName);
headerProperties << fakeProperty;
@@ -797,16 +797,16 @@ void WriteInitialization::acceptWidget(DomWidget *node)
} else if (m_uic->customWidgetsInfo()->extends(className, QLatin1String("QTableView"))
|| m_uic->customWidgetsInfo()->extends(className, QLatin1String("QTableWidget"))) {
- static const QStringList headerPrefixes =
- (QStringList() << QLatin1String("horizontalHeader")
- << QLatin1String("verticalHeader"));
+ static const QLatin1String headerPrefixes[] = {
+ QLatin1String("horizontalHeader"),
+ QLatin1String("verticalHeader"),
+ };
- for (const QString &headerPrefix : headerPrefixes) {
+ for (auto headerPrefix : headerPrefixes) {
DomPropertyList headerProperties;
- for (const QString &realPropertyName : realPropertyNames) {
- const QString upperPropertyName = realPropertyName.at(0).toUpper()
- + realPropertyName.mid(1);
- const QString fakePropertyName = headerPrefix + upperPropertyName;
+ for (auto realPropertyName : realPropertyNames) {
+ const QString fakePropertyName = headerPrefix
+ + QChar(realPropertyName.at(0)).toUpper() + realPropertyName.mid(1);
if (DomProperty *fakeProperty = attributes.value(fakePropertyName)) {
fakeProperty->setAttributeName(realPropertyName);
headerProperties << fakeProperty;