From fec37f0e9a9e4c18fd20f7b39919f08c7cb2139e Mon Sep 17 00:00:00 2001 From: Kent Hansen Date: Sat, 18 Feb 2012 18:51:46 +0100 Subject: moc: Get rid of implicit conversions to const char * moc mostly operates on QByteArrays. When an actual const char * is needed, it should be explicit. Change-Id: I0b3e262830128306688f4512a4b59ce8966c2579 Reviewed-by: Bradley T. Hughes Reviewed-by: Olivier Goffart --- src/tools/moc/generator.cpp | 18 ++++++++---------- src/tools/moc/generator.h | 2 +- src/tools/moc/main.cpp | 6 +++--- src/tools/moc/moc.cpp | 11 ++++++----- src/tools/moc/moc.pro | 2 +- src/tools/moc/preprocessor.cpp | 12 ++++++------ 6 files changed, 25 insertions(+), 26 deletions(-) (limited to 'src/tools') diff --git a/src/tools/moc/generator.cpp b/src/tools/moc/generator.cpp index 7355275587..937a62e87c 100644 --- a/src/tools/moc/generator.cpp +++ b/src/tools/moc/generator.cpp @@ -54,19 +54,19 @@ QT_BEGIN_NAMESPACE -uint qvariant_nameToType(const char* name) +uint qvariant_nameToType(const QByteArray &name) { - if (!name) + if (name.isEmpty()) return 0; - uint tp = QMetaType::type(name); + uint tp = QMetaType::type(name.constData()); return tp < QMetaType::User ? tp : 0; } /* Returns true if the type is a QVariant types. */ -bool isVariantType(const char* type) +bool isVariantType(const QByteArray &type) { return qvariant_nameToType(type) != 0; } @@ -74,9 +74,9 @@ bool isVariantType(const char* type) /*! Returns true if the type is qreal. */ -static bool isQRealType(const char *type) +static bool isQRealType(const QByteArray &type) { - return strcmp(type, "qreal") == 0; + return (type == "qreal"); } Generator::Generator(ClassDef *classDef, const QList &metaTypes, FILE *outfile) @@ -109,11 +109,9 @@ static inline int lengthOfEscapeSequence(const QByteArray &s, int i) return i - startPos; } -int Generator::strreg(const char *s) +int Generator::strreg(const QByteArray &s) { int idx = 0; - if (!s) - s = ""; for (int i = 0; i < strings.size(); ++i) { const QByteArray &str = strings.at(i); if (str == s) @@ -387,7 +385,7 @@ void Generator::generateCode() for (int i = 1; i < cdef->superclassList.size(); ++i) { // for all superclasses but the first one if (cdef->superclassList.at(i).second == FunctionDef::Private) continue; - const char *cname = cdef->superclassList.at(i).first; + const char *cname = cdef->superclassList.at(i).first.constData(); fprintf(out, " if (!strcmp(_clname, \"%s\"))\n return static_cast< %s*>(const_cast< %s*>(this));\n", cname, cname, cdef->classname.constData()); } diff --git a/src/tools/moc/generator.h b/src/tools/moc/generator.h index 6682e1a36a..4e96511695 100644 --- a/src/tools/moc/generator.h +++ b/src/tools/moc/generator.h @@ -65,7 +65,7 @@ private: void generateSignal(FunctionDef *def, int index); void generatePluginMetaData(); - int strreg(const char *); // registers a string and returns its id + int strreg(const QByteArray &); // registers a string and returns its id QList strings; QByteArray purestSuperClass; QList metaTypes; diff --git a/src/tools/moc/main.cpp b/src/tools/moc/main.cpp index 512d0212b7..772df1feec 100644 --- a/src/tools/moc/main.cpp +++ b/src/tools/moc/main.cpp @@ -63,7 +63,7 @@ QT_BEGIN_NAMESPACE /tmp/abc, xyz/klm -> /tmp/abc */ -static QByteArray combinePath(const char *infile, const char *outfile) +static QByteArray combinePath(const QByteArray &infile, const QByteArray &outfile) { QFileInfo inFileInfo(QDir::current(), QFile::decodeName(infile)); QFileInfo outFileInfo(QDir::current(), QFile::decodeName(outfile)); @@ -379,7 +379,7 @@ int runMoc(int _argc, char **_argv) in = fopen(filename.data(), "rb"); if (!in) { #endif - fprintf(stderr, "moc: %s: No such file\n", (const char*)filename); + fprintf(stderr, "moc: %s: No such file\n", filename.constData()); return 1; } moc.filename = filename; @@ -406,7 +406,7 @@ int runMoc(int _argc, char **_argv) if (!out) #endif { - fprintf(stderr, "moc: Cannot create %s\n", (const char*)output); + fprintf(stderr, "moc: Cannot create %s\n", output.constData()); return 1; } } else { // use stdout diff --git a/src/tools/moc/moc.cpp b/src/tools/moc/moc.cpp index 97316eedde..7b358c1ae8 100644 --- a/src/tools/moc/moc.cpp +++ b/src/tools/moc/moc.cpp @@ -54,9 +54,10 @@ QT_BEGIN_NAMESPACE // only moc needs this function -static QByteArray normalizeType(const char *s, bool fixScope = false) +static QByteArray normalizeType(const QByteArray &ba, bool fixScope = false) { - int len = qstrlen(s); + const char *s = ba.constData(); + int len = ba.size(); char stackbuf[64]; char *buf = (len >= 64 ? new char[len + 1] : stackbuf); char *d = buf; @@ -794,7 +795,7 @@ void Moc::generate(FILE *out) if (i >= 0) fn = filename.mid(i); fprintf(out, "/****************************************************************************\n" - "** Meta object code from reading C++ file '%s'\n**\n" , (const char*)fn); + "** Meta object code from reading C++ file '%s'\n**\n" , fn.constData()); fprintf(out, "** Created: %s\n" "** by: The Qt Meta Object Compiler version %d (Qt %s)\n**\n" , dstr.data(), mocOutputRevision, QT_VERSION_STR); fprintf(out, "** WARNING! All changes made in this file will be lost!\n" @@ -823,7 +824,7 @@ void Moc::generate(FILE *out) fprintf(out, "#include \n"); fprintf(out, "#if !defined(Q_MOC_OUTPUT_REVISION)\n" - "#error \"The header file '%s' doesn't include .\"\n", (const char *)fn); + "#error \"The header file '%s' doesn't include .\"\n", fn.constData()); fprintf(out, "#elif Q_MOC_OUTPUT_REVISION != %d\n", mocOutputRevision); fprintf(out, "#error \"This file was generated using the moc from %s." " It\"\n#error \"cannot be used with the include files from" @@ -1100,7 +1101,7 @@ void Moc::parsePluginData(ClassDef *def) } else if (l == "FILE") { next(STRING_LITERAL); QByteArray metaDataFile = unquotedLexem(); - QFileInfo fi(QFileInfo(QString::fromLocal8Bit(currentFilenames.top())).dir(), QString::fromLocal8Bit(metaDataFile)); + QFileInfo fi(QFileInfo(QString::fromLocal8Bit(currentFilenames.top().constData())).dir(), QString::fromLocal8Bit(metaDataFile.constData())); if (!fi.exists()) { QByteArray msg; msg += "Plugin Metadata file "; diff --git a/src/tools/moc/moc.pro b/src/tools/moc/moc.pro index 8e2e76d4b9..3ee507855c 100644 --- a/src/tools/moc/moc.pro +++ b/src/tools/moc/moc.pro @@ -1,7 +1,7 @@ TEMPLATE = app TARGET = moc -DEFINES += QT_MOC +DEFINES += QT_MOC QT_NO_CAST_FROM_BYTEARRAY DESTDIR = ../../../bin INCLUDEPATH += . DEPENDPATH += . diff --git a/src/tools/moc/preprocessor.cpp b/src/tools/moc/preprocessor.cpp index 07b9e4c500..07986a71e6 100644 --- a/src/tools/moc/preprocessor.cpp +++ b/src/tools/moc/preprocessor.cpp @@ -58,7 +58,7 @@ static QByteArray cleaned(const QByteArray &input) { QByteArray result; result.reserve(input.size()); - const char *data = input; + const char *data = input.constData(); char *output = result.data(); int newlines = 0; @@ -161,7 +161,7 @@ enum TokenizeMode { TokenizeCpp, TokenizePreprocessor, PreparePreprocessorStatem static Symbols tokenize(const QByteArray &input, int lineNum = 1, TokenizeMode mode = TokenizeCpp) { Symbols symbols; - const char *begin = input; + const char *begin = input.constData(); const char *data = begin; while (*data) { if (mode == TokenizeCpp) { @@ -799,7 +799,7 @@ void Preprocessor::preprocess(const QByteArray &filename, Symbols &preprocessed) // #### stringery QFileInfo fi; if (local) - fi.setFile(QFileInfo(QString::fromLocal8Bit(filename)).dir(), QString::fromLocal8Bit(include)); + 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) { @@ -808,9 +808,9 @@ void Preprocessor::preprocess(const QByteArray &filename, Symbols &preprocessed) continue; QByteArray frameworkCandidate = include.left(slashPos); frameworkCandidate.append(".framework/Headers/"); - fi.setFile(QString::fromLocal8Bit(QByteArray(p.path + '/' + frameworkCandidate)), QString::fromLocal8Bit(include.mid(slashPos + 1))); + fi.setFile(QString::fromLocal8Bit(QByteArray(p.path + '/' + frameworkCandidate).constData()), QString::fromLocal8Bit(include.mid(slashPos + 1).constData())); } else { - fi.setFile(QString::fromLocal8Bit(p.path), QString::fromLocal8Bit(include)); + 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) @@ -828,7 +828,7 @@ void Preprocessor::preprocess(const QByteArray &filename, Symbols &preprocessed) continue; Preprocessor::preprocessedIncludes.insert(include); - QFile file(QString::fromLocal8Bit(include)); + QFile file(QString::fromLocal8Bit(include.constData())); if (!file.open(QFile::ReadOnly)) continue; -- cgit v1.2.3