55void error(
const char *msg =
"Invalid argument")
58 fprintf(stderr,
"moc: %s\n", msg);
67{
return (
i < symbols.
size()); }
70{
return symbols.
at(
i++); }
77 Token secondlast = last;
101 case MOC_INCLUDE_BEGIN:
104 case MOC_INCLUDE_END:
113 const int padding = sym.
lineNum - lineNum;
116 memset(
output.data() +
output.size() - padding,
'\n', padding);
129 hasOptionFiles =
false;
137 error(
"The @ option requires an input file");
142 error(
"Cannot open options file specified with @");
145 hasOptionFiles =
true;
149 allArguments <<
line;
163 bool autoInclude =
true;
164 bool defaultInclude =
true;
171 Macro dummyVariadicFunctionMacro;
175 pp.
macros[
"__attribute__"] = dummyVariadicFunctionMacro;
176 pp.
macros[
"__declspec"] = dummyVariadicFunctionMacro;
268 parser.
addOption(noNotesWarningsCompatOption);
279 ignoreConflictsOption.
setDescription(
QStringLiteral(
"Ignore all options that conflict with compilers, like -pthread conflicting with moc's -p option."));
283 jsonOption.
setDescription(
QStringLiteral(
"In addition to generating C++ code, create a machine-readable JSON file in a file that matches the output file and an extra .json extension."));
291 collectOption.
setDescription(
QStringLiteral(
"Instead of processing C++ code, collect previously generated JSON output into a single file."));
296 QStringLiteral(
"Output a Make-style dep file for build system consumption."));
312 parser.
addOption(requireCompleTypesOption);
321 bool hasOptionFiles =
false;
330 if (parser.
isSet(collectOption))
333 if (
files.size() > 1) {
336 }
else if (!
files.isEmpty()) {
337 filename =
files.first();
340 const bool ignoreConflictingOptions = parser.
isSet(ignoreConflictsOption);
343 if (parser.
isSet(noIncludeOption)) {
344 moc.noInclude =
true;
347 if (parser.
isSet(requireCompleTypesOption))
348 moc.requireCompleteTypes =
true;
349 if (!ignoreConflictingOptions) {
350 if (parser.
isSet(forceIncludeOption)) {
351 moc.noInclude =
false;
353 const auto forceIncludes = parser.
values(forceIncludeOption);
354 for (
const QString &include : forceIncludes) {
356 defaultInclude =
false;
359 const auto prependIncludes = parser.
values(prependIncludeOption);
360 for (
const QString &include : prependIncludes)
362 if (parser.
isSet(pathPrefixOption))
366 const auto includePaths = parser.
values(includePathOption);
369 QString compilerFlavor = parser.
value(compilerFlavorOption);
370 if (compilerFlavor.
isEmpty() || compilerFlavor ==
"unix"_L1) {
380 }
else if (compilerFlavor ==
"msvc"_L1) {
387 "'; valid values are: msvc, unix."_L1));
391 const auto macFrameworks = parser.
values(macFrameworkOption);
395 p.isFrameworkPath =
true;
398 const auto defines = parser.
values(defineOption);
407 if (
name.isEmpty()) {
408 error(
"Missing macro name");
416 const auto undefines = parser.
values(undefineOption);
420 error(
"Missing macro name");
425 const QStringList noNotesCompatValues = parser.
values(noNotesWarningsCompatOption);
426 if (parser.
isSet(noNotesOption) || noNotesCompatValues.contains(
"n"_L1))
427 moc.displayNotes =
false;
428 if (parser.
isSet(noWarningsOption) || noNotesCompatValues.contains(
"w"_L1))
429 moc.displayWarnings =
moc.displayNotes =
false;
435 moc.noInclude = (ppos > spos && filename.
at(ppos + 1).
toLower() != u
'h');
437 if (defaultInclude) {
439 if (filename.
size()) {
454 in.setFileName(filename);
456 fprintf(stderr,
"moc: %s: No such file\n",
qPrintable(filename));
462 const auto metadata = parser.
values(metadataOption);
463 for (
const QString &md : metadata) {
469 error(
"missing key or value for option '-M'");
470 }
else if (
key.indexOf(u
'.') != -1) {
473 error(
"A key cannot contain the letter '.' for option '-M'");
485 fprintf(stderr,
"debug-includes: include search list:\n");
487 for (
auto &includePath : pp.
includes) {
488 fprintf(stderr,
"debug-includes: '%s' framework: %d \n",
489 includePath.path.constData(),
490 includePath.isFrameworkPath);
492 fprintf(stderr,
"debug-includes: end of search list.\n");
496 const auto includeFiles = parser.
values(includeOption);
498 for (
const QString &includeName : includeFiles) {
501 fprintf(stderr,
"Warning: Failed to resolve include \"%s\" for moc file %s\n",
502 includeName.toLocal8Bit().constData(),
507 moc.symbols +=
Symbol(0, MOC_INCLUDE_BEGIN, rawName);
509 moc.symbols +=
Symbol(0, MOC_INCLUDE_END, rawName);
510 validIncludesFiles.append(includeName);
512 fprintf(stderr,
"Warning: Cannot open %s included by moc file %s: %s\n",
515 f.errorString().toLocal8Bit().constData());
530 bool outputToFile =
true;
533 if (_wfopen_s(&
out,
reinterpret_cast<const wchar_t *
>(
output.utf16()), L
"w") != 0)
543 if (parser.
isSet(jsonOption)) {
547 if (_wfopen_s(&
f,
reinterpret_cast<const wchar_t *
>(jsonOutputFileName.
utf16()), L
"w") != 0)
552 fprintf(stderr,
"moc: Cannot create JSON output file %s. %s\n",
559 outputToFile =
false;
566 moc.note(
"No relevant classes found. No output generated.");
574 if (parser.
isSet(depFileOption)) {
579 if (parser.
isSet(depFileRuleNameOption))
580 depRuleName = parser.
value(depFileRuleNameOption);
582 if (parser.
isSet(depFilePathOption)) {
583 depOutputFileName = parser.
value(depFilePathOption);
584 }
else if (outputToFile) {
585 depOutputFileName =
output +
".d"_L1;
587 fprintf(stderr,
"moc: Writing to stdout, but no depfile path specified.\n");
591 FILE *depFileHandleRaw;
593 if (_wfopen_s(&depFileHandleRaw,
594 reinterpret_cast<const wchar_t *
>(depOutputFileName.
utf16()), L
"w") != 0)
597 if (!depFileHandleRaw)
599 fprintf(stderr,
"moc: Cannot create dep output file '%s'. %s\n",
602 depFileHandle.
reset(depFileHandleRaw);
604 if (!depFileHandle.
isNull()) {
606 fprintf(depFileHandle.
data(),
"%s: ",
617 for (
const QString &includeName : validIncludesFiles) {
623 for (
const QString &pluginMetadataFile :
moc.parsedPluginMetadataFiles) {
638 fprintf(depFileHandle.
data(),
"%s\n", dependenciesJoined.constData());
647int main(
int _argc,
char **_argv)
QList< IncludePath > includes
QSet< QByteArray > preprocessedIncludes
void setDebugIncludes(bool value)
Symbols preprocessed(const QByteArray &filename, QFile *device)
static bool preprocessOnly
QByteArray resolveInclude(const QByteArray &filename, const QByteArray &relativeTo)
static Symbols tokenize(const QByteArray &input, int lineNum=1, TokenizeMode mode=TokenizeCpp)
const char * constData() const noexcept
Returns a pointer to the const data stored in the byte array.
QList< QByteArray > split(char sep) const
Splits the byte array into subarrays wherever sep occurs, and returns the list of those arrays.
qsizetype length() const noexcept
Same as size().
bool isEmpty() const noexcept
Returns true if the byte array has size 0; otherwise returns false.
QByteArray mid(qsizetype index, qsizetype len=-1) const
Returns a byte array containing len bytes from this byte array, starting at position pos.
QChar toLower() const noexcept
Returns the lowercase equivalent if the character is uppercase or titlecase; otherwise returns the ch...
The QCommandLineOption class defines a possible command-line option. \inmodule QtCore.
void setDescription(const QString &description)
Sets the description used for this option to description.
void setFlags(Flags aflags)
Set the set of flags that affect this command-line option to flags.
void setValueName(const QString &name)
Sets the name of the expected value, for the documentation, to valueName.
The QCommandLineParser class provides a means for handling the command line options.
QString value(const QString &name) const
Returns the option value found for the given option name optionName, or an empty string if not found.
void addPositionalArgument(const QString &name, const QString &description, const QString &syntax=QString())
Defines an additional argument to the application, for the benefit of the help text.
QStringList positionalArguments() const
Returns a list of positional arguments.
void setSingleDashWordOptionMode(SingleDashWordOptionMode parsingMode)
Sets the parsing mode to singleDashWordOptionMode.
QStringList values(const QString &name) const
Returns a list of option values found for the given option name optionName, or an empty list if not f...
void setApplicationDescription(const QString &description)
Sets the application description shown by helpText().
bool addOption(const QCommandLineOption &commandLineOption)
Adds the option option to look for while parsing.
Q_NORETURN void showHelp(int exitCode=0)
Displays the help information, and exits the application.
bool isSet(const QString &name) const
Checks whether the option name was passed to the application.
void process(const QStringList &arguments)
Processes the command line arguments.
QCommandLineOption addVersionOption()
Adds the {-v} / {–version} option, which displays the version string of the application.
QCommandLineOption addHelpOption()
Adds help options to the command-line parser.
static void setApplicationVersion(const QString &version)
static QStringList arguments()
static QDir current()
Returns the application's current directory.
static QChar separator()
Returns the native directory separator: "/" under Unix and "\\" under Windows.
QString absolutePath() const
Returns the absolute path (a path that starts with "/" or with a drive specification),...
QString relativeFilePath(const QString &fileName) const
Returns the path to fileName relative to the directory.
static constexpr QChar listSeparator() noexcept
\inmodule QtCore \reentrant
QString absoluteFilePath() const
Returns an absolute path including the file name.
QDir dir() const
Returns the path of the object's parent directory as a QDir object.
QString filePath() const
Returns the file name, including the path (which may be absolute or relative).
static QByteArray encodeName(const QString &fileName)
Converts fileName to an 8-bit encoding that you can use in native APIs.
static QString decodeName(const QByteArray &localFileName)
This does the reverse of QFile::encodeName() using localFileName.
bool remove(const Key &key)
Removes the item that has the key from the hash.
iterator insert(const Key &key, const T &value)
Inserts a new item with the key and a value of value.
\inmodule QtCore\reentrant
qsizetype size() const noexcept
bool isEmpty() const noexcept
const_reference at(qsizetype i) const noexcept
void removeLast() noexcept
T * data() const noexcept
Returns the value of the pointer referenced by this object.
bool isNull() const noexcept
Returns true if this object refers to \nullptr.
void reset(T *other=nullptr) noexcept(noexcept(Cleanup::cleanup(std::declval< T * >())))
Deletes the existing object it is pointing to (if any), and sets its pointer to other.
QList< T > values() const
\macro QT_RESTRICTED_CAST_FROM_ASCII
qsizetype lastIndexOf(QChar c, Qt::CaseSensitivity cs=Qt::CaseSensitive) const noexcept
static QString fromLatin1(QByteArrayView ba)
This is an overloaded member function, provided for convenience. It differs from the above function o...
const ushort * utf16() const
Returns the QString as a '\0\'-terminated array of unsigned shorts.
static QString fromLocal8Bit(QByteArrayView ba)
This is an overloaded member function, provided for convenience. It differs from the above function o...
const QChar * constData() const
Returns a pointer to the data stored in the QString.
qsizetype size() const
Returns the number of characters in this string.
QString mid(qsizetype position, qsizetype n=-1) const
Returns a string that contains n characters of this string, starting at the specified position index.
const QChar at(qsizetype i) const
Returns the character at the given index position in the string.
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
QString & insert(qsizetype i, QChar c)
QByteArray toLocal8Bit() const &
QString & append(QChar c)
QString left(qsizetype n) const
Returns a substring that contains the n leftmost characters of the string.
QString & remove(qsizetype i, qsizetype len)
Removes n characters from the string, starting at the given position index, and returns a reference t...
QString & prepend(QChar c)
qsizetype length() const
Returns the number of characters in this string.
int collectJson(const QStringList &jsonFiles, const QString &outputFile, bool skipStdIn)
StringType escapeDependencyPath(const StringType &path)
static QByteArray escapeAndEncodeDependencyPath(const QString &path)
QList< QVariant > arguments
Combined button and popup list for selecting options.
#define QByteArrayLiteral(str)
DBusConnection const char DBusError * error
static const char includeList[]
static QString moc(const QString &name)
EGLOutputLayerEXT EGLint EGLAttrib value
[5]
GLuint64 GLenum void * handle
GLsizei const GLchar *const * path
static void split(QT_FT_Vector *b)
#define qPrintable(string)
#define QStringLiteral(str)
static QByteArray combinePath(const QString &infile, const QString &outfile)
static bool hasNext(const Symbols &symbols, int i)
int runMoc(int argc, char **argv)
static QStringList argumentsFromCommandLineAndFile(const QStringList &arguments, bool &hasOptionFiles)
QByteArray composePreprocessorOutput(const Symbols &symbols)
Q_CORE_EXPORT QByteArray qgetenv(const char *varName)
QT_BEGIN_NAMESPACE typedef uchar * output
QT_END_NAMESPACE typedef QT_PREPEND_NAMESPACE(quintptr) WId
QTextStream out(stdout)
[7]
QApplication app(argc, argv)
[0]
static void cleanup(FILE *handle)