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 <bradley.hughes@nokia.com>
Reviewed-by: Olivier Goffart <ogoffart@woboq.com>
This commit is contained in:
Kent Hansen 2012-02-18 18:51:46 +01:00 committed by Qt by Nokia
parent cbe21c59a0
commit fec37f0e9a
6 changed files with 25 additions and 26 deletions

View File

@ -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<QByteArray> &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());
}

View File

@ -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<QByteArray> strings;
QByteArray purestSuperClass;
QList<QByteArray> metaTypes;

View File

@ -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

View File

@ -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 <QtCore/qplugin.h>\n");
fprintf(out, "#if !defined(Q_MOC_OUTPUT_REVISION)\n"
"#error \"The header file '%s' doesn't include <QObject>.\"\n", (const char *)fn);
"#error \"The header file '%s' doesn't include <QObject>.\"\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 ";

View File

@ -1,7 +1,7 @@
TEMPLATE = app
TARGET = moc
DEFINES += QT_MOC
DEFINES += QT_MOC QT_NO_CAST_FROM_BYTEARRAY
DESTDIR = ../../../bin
INCLUDEPATH += .
DEPENDPATH += .

View File

@ -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;