refactor relation between parsedProBlock() & parsedProFile()

this is clearer and not necessarily more code.

Change-Id: Ic698a8076658ae986d0dbdeebb1f4760dd806e35
Reviewed-by: Daniel Teske <daniel.teske@nokia.com>
Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@nokia.com>
This commit is contained in:
Oswald Buddenhagen
2012-06-28 14:59:36 +02:00
parent 8d7546d006
commit 9067399e37
3 changed files with 20 additions and 13 deletions

View File

@@ -131,7 +131,7 @@ QMakeParser::QMakeParser(ProFileCache *cache, QMakeParserHandler *handler)
initialize();
}
ProFile *QMakeParser::parsedProFile(const QString &fileName, bool cache, const QString *contents)
ProFile *QMakeParser::parsedProFile(const QString &fileName, bool cache)
{
ProFile *pro;
if (cache && m_cache) {
@@ -163,7 +163,7 @@ ProFile *QMakeParser::parsedProFile(const QString &fileName, bool cache, const Q
locker.unlock();
#endif
pro = new ProFile(fileName);
if (!(!contents ? read(pro) : read(pro, *contents))) {
if (!read(pro)) {
delete pro;
pro = 0;
} else {
@@ -183,7 +183,7 @@ ProFile *QMakeParser::parsedProFile(const QString &fileName, bool cache, const Q
}
} else {
pro = new ProFile(fileName);
if (!(!contents ? read(pro) : read(pro, *contents))) {
if (!read(pro)) {
delete pro;
pro = 0;
}
@@ -191,6 +191,16 @@ ProFile *QMakeParser::parsedProFile(const QString &fileName, bool cache, const Q
return pro;
}
ProFile *QMakeParser::parsedProBlock(const QString &name, const QString &contents)
{
ProFile *pro = new ProFile(name);
if (!read(pro, contents)) {
delete pro;
pro = 0;
}
return pro;
}
bool QMakeParser::read(ProFile *pro)
{
QFile file(pro->fileName());

View File

@@ -61,11 +61,8 @@ public:
QMakeParser(ProFileCache *cache, QMakeParserHandler *handler);
// 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 = 0);
ProFile *parsedProBlock(const QString &name, const QString &contents)
{ return parsedProFile(name, false, &contents); }
ProFile *parsedProFile(const QString &fileName, bool cache = false);
ProFile *parsedProBlock(const QString &name, const QString &contents);
private:
struct BlockScope {

View File

@@ -451,7 +451,7 @@ void tst_ProFileWriter::adds()
QString var = QLatin1String("SOURCES");
QMakeParser parser(0, &parseHandler);
ProFile *proFile = parser.parsedProFile(QLatin1String(BASE_DIR "/test.pro"), false, &input);
ProFile *proFile = parser.parsedProBlock(QLatin1String(BASE_DIR "/test.pro"), input);
QVERIFY(proFile);
PW::putVarValues(proFile, &lines, values, var, PW::PutFlags(flags), scope);
proFile->deref();
@@ -621,7 +621,7 @@ void tst_ProFileWriter::removes()
QStringList vars; vars << QLatin1String("SOURCES");
QMakeParser parser(0, &parseHandler);
ProFile *proFile = parser.parsedProFile(QLatin1String(BASE_DIR "/test.pro"), false, &input);
ProFile *proFile = parser.parsedProBlock(QLatin1String(BASE_DIR "/test.pro"), input);
QVERIFY(proFile);
Qt4ProjectManager::Internal::ProWriter::removeVarValues(proFile, &lines, values, vars);
proFile->deref();
@@ -649,7 +649,7 @@ void tst_ProFileWriter::multiVar()
QStringList vars; vars << QLatin1String("SOURCES") << QLatin1String("HEADERS");
QMakeParser parser(0, &parseHandler);
ProFile *proFile = parser.parsedProFile(QLatin1String(BASE_DIR "/test.pro"), false, &input);
ProFile *proFile = parser.parsedProBlock(QLatin1String(BASE_DIR "/test.pro"), input);
QVERIFY(proFile);
Qt4ProjectManager::Internal::ProWriter::removeFiles(proFile, &lines, baseDir, files, vars);
proFile->deref();
@@ -669,7 +669,7 @@ void tst_ProFileWriter::addFiles()
);
QMakeParser parser(0, &parseHandler);
ProFile *proFile = parser.parsedProFile(QLatin1String(BASE_DIR "/test.pro"), false, &input);
ProFile *proFile = parser.parsedProBlock(QLatin1String(BASE_DIR "/test.pro"), input);
QVERIFY(proFile);
Qt4ProjectManager::Internal::ProWriter::addFiles(proFile, &lines, QDir(BASE_DIR),
QStringList() << QString::fromLatin1(BASE_DIR "/sub/bar.cpp"),
@@ -690,7 +690,7 @@ void tst_ProFileWriter::removeFiles()
);
QMakeParser parser(0, &parseHandler);
ProFile *proFile = parser.parsedProFile(QLatin1String(BASE_DIR "/test.pro"), false, &input);
ProFile *proFile = parser.parsedProBlock(QLatin1String(BASE_DIR "/test.pro"), input);
QVERIFY(proFile);
Qt4ProjectManager::Internal::ProWriter::removeFiles(proFile, &lines, QDir(BASE_DIR),
QStringList() << QString::fromLatin1(BASE_DIR "/sub/bar.cpp"),