make ProFileParser API less bug-prone

QString::isNull() vs. isEmpty() discrimination is a time bomb ...
This commit is contained in:
Oswald Buddenhagen
2010-09-02 18:06:11 +02:00
parent 34a8a57d81
commit 7322900692
5 changed files with 12 additions and 10 deletions

View File

@@ -227,7 +227,7 @@ void MaemoProFileWrapper::parseProFile(ParseType type) const
m_proFileReader->setCumulative(false);
// TODO: Set output dir to build dir?
if (type == ParseFromLines) {
m_proFile = m_proFileReader->parsedProFile(m_proFileName, false,
m_proFile = m_proFileReader->parsedProBlock(m_proFileName,
m_proFileContents.join("\n"));
} else {
m_proFileContents.clear();

View File

@@ -1050,7 +1050,7 @@ void Qt4PriFileNode::changeFiles(const FileType fileType,
ProMessageHandler handler;
ProFileParser parser(0, &handler);
includeFile = parser.parsedProFile(m_projectFilePath, false, contents);
includeFile = parser.parsedProBlock(m_projectFilePath, contents);
}
const QStringList vars = varNames(fileType);

View File

@@ -1274,8 +1274,8 @@ ProFileEvaluator::Private::VisitReturn ProFileEvaluator::Private::visitProFile(
tgt.append(ProString(QFileInfo(pro->fileName()).baseName(), NoHash));
if (!m_cmdArgs.isEmpty()) {
if (ProFile *pro = m_parser->parsedProFile(
fL1S("(command line)"), false, m_cmdArgs.join(fL1S("\n")))) {
if (ProFile *pro = m_parser->parsedProBlock(
fL1S("(command line)"), m_cmdArgs.join(fL1S("\n")))) {
m_locationStack.push(m_current);
visitProBlock(pro, pro->tokPtr());
m_current = m_locationStack.pop();
@@ -2420,8 +2420,8 @@ ProFileEvaluator::Private::VisitReturn ProFileEvaluator::Private::evaluateCondit
case T_REQUIRES:
#endif
case T_EVAL: {
ProFile *pro = m_parser->parsedProFile(fL1S("(eval)"), false,
args.join(statics.field_sep));
ProFile *pro = m_parser->parsedProBlock(fL1S("(eval)"),
args.join(statics.field_sep));
if (!pro)
return ReturnFalse;
m_locationStack.push(m_current);

View File

@@ -124,7 +124,7 @@ ProFileParser::ProFileParser(ProFileCache *cache, ProFileParserHandler *handler)
initialize();
}
ProFile *ProFileParser::parsedProFile(const QString &fileName, bool cache, const QString &contents)
ProFile *ProFileParser::parsedProFile(const QString &fileName, bool cache, const QString *contents)
{
ProFile *pro;
if (cache && m_cache) {
@@ -156,7 +156,7 @@ ProFile *ProFileParser::parsedProFile(const QString &fileName, bool cache, const
locker.unlock();
#endif
pro = new ProFile(fileName);
if (!(contents.isNull() ? read(pro) : read(pro, contents))) {
if (!(!contents ? read(pro) : read(pro, *contents))) {
delete pro;
pro = 0;
} else {
@@ -176,7 +176,7 @@ ProFile *ProFileParser::parsedProFile(const QString &fileName, bool cache, const
}
} else {
pro = new ProFile(fileName);
if (!(contents.isNull() ? read(pro) : read(pro, contents))) {
if (!(!contents ? read(pro) : read(pro, *contents))) {
delete pro;
pro = 0;
}

View File

@@ -70,7 +70,9 @@ public:
// fileName is expected to be absolute and cleanPath()ed.
// If contents is non-null, it will be used instead of the file's actual content
ProFile *parsedProFile(const QString &fileName, bool cache = false,
const QString &contents = QString());
const QString *contents = 0);
ProFile *parsedProBlock(const QString &name, const QString &contents)
{ return parsedProFile(name, false, &contents); }
private:
struct BlockScope {