forked from qt-creator/qt-creator
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:
@@ -131,7 +131,7 @@ QMakeParser::QMakeParser(ProFileCache *cache, QMakeParserHandler *handler)
|
|||||||
initialize();
|
initialize();
|
||||||
}
|
}
|
||||||
|
|
||||||
ProFile *QMakeParser::parsedProFile(const QString &fileName, bool cache, const QString *contents)
|
ProFile *QMakeParser::parsedProFile(const QString &fileName, bool cache)
|
||||||
{
|
{
|
||||||
ProFile *pro;
|
ProFile *pro;
|
||||||
if (cache && m_cache) {
|
if (cache && m_cache) {
|
||||||
@@ -163,7 +163,7 @@ ProFile *QMakeParser::parsedProFile(const QString &fileName, bool cache, const Q
|
|||||||
locker.unlock();
|
locker.unlock();
|
||||||
#endif
|
#endif
|
||||||
pro = new ProFile(fileName);
|
pro = new ProFile(fileName);
|
||||||
if (!(!contents ? read(pro) : read(pro, *contents))) {
|
if (!read(pro)) {
|
||||||
delete pro;
|
delete pro;
|
||||||
pro = 0;
|
pro = 0;
|
||||||
} else {
|
} else {
|
||||||
@@ -183,7 +183,7 @@ ProFile *QMakeParser::parsedProFile(const QString &fileName, bool cache, const Q
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
pro = new ProFile(fileName);
|
pro = new ProFile(fileName);
|
||||||
if (!(!contents ? read(pro) : read(pro, *contents))) {
|
if (!read(pro)) {
|
||||||
delete pro;
|
delete pro;
|
||||||
pro = 0;
|
pro = 0;
|
||||||
}
|
}
|
||||||
@@ -191,6 +191,16 @@ ProFile *QMakeParser::parsedProFile(const QString &fileName, bool cache, const Q
|
|||||||
return pro;
|
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)
|
bool QMakeParser::read(ProFile *pro)
|
||||||
{
|
{
|
||||||
QFile file(pro->fileName());
|
QFile file(pro->fileName());
|
||||||
|
@@ -61,11 +61,8 @@ public:
|
|||||||
QMakeParser(ProFileCache *cache, QMakeParserHandler *handler);
|
QMakeParser(ProFileCache *cache, QMakeParserHandler *handler);
|
||||||
|
|
||||||
// fileName is expected to be absolute and cleanPath()ed.
|
// 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);
|
||||||
ProFile *parsedProFile(const QString &fileName, bool cache = false,
|
ProFile *parsedProBlock(const QString &name, const QString &contents);
|
||||||
const QString *contents = 0);
|
|
||||||
ProFile *parsedProBlock(const QString &name, const QString &contents)
|
|
||||||
{ return parsedProFile(name, false, &contents); }
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
struct BlockScope {
|
struct BlockScope {
|
||||||
|
@@ -451,7 +451,7 @@ void tst_ProFileWriter::adds()
|
|||||||
QString var = QLatin1String("SOURCES");
|
QString var = QLatin1String("SOURCES");
|
||||||
|
|
||||||
QMakeParser parser(0, &parseHandler);
|
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);
|
QVERIFY(proFile);
|
||||||
PW::putVarValues(proFile, &lines, values, var, PW::PutFlags(flags), scope);
|
PW::putVarValues(proFile, &lines, values, var, PW::PutFlags(flags), scope);
|
||||||
proFile->deref();
|
proFile->deref();
|
||||||
@@ -621,7 +621,7 @@ void tst_ProFileWriter::removes()
|
|||||||
QStringList vars; vars << QLatin1String("SOURCES");
|
QStringList vars; vars << QLatin1String("SOURCES");
|
||||||
|
|
||||||
QMakeParser parser(0, &parseHandler);
|
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);
|
QVERIFY(proFile);
|
||||||
Qt4ProjectManager::Internal::ProWriter::removeVarValues(proFile, &lines, values, vars);
|
Qt4ProjectManager::Internal::ProWriter::removeVarValues(proFile, &lines, values, vars);
|
||||||
proFile->deref();
|
proFile->deref();
|
||||||
@@ -649,7 +649,7 @@ void tst_ProFileWriter::multiVar()
|
|||||||
QStringList vars; vars << QLatin1String("SOURCES") << QLatin1String("HEADERS");
|
QStringList vars; vars << QLatin1String("SOURCES") << QLatin1String("HEADERS");
|
||||||
|
|
||||||
QMakeParser parser(0, &parseHandler);
|
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);
|
QVERIFY(proFile);
|
||||||
Qt4ProjectManager::Internal::ProWriter::removeFiles(proFile, &lines, baseDir, files, vars);
|
Qt4ProjectManager::Internal::ProWriter::removeFiles(proFile, &lines, baseDir, files, vars);
|
||||||
proFile->deref();
|
proFile->deref();
|
||||||
@@ -669,7 +669,7 @@ void tst_ProFileWriter::addFiles()
|
|||||||
);
|
);
|
||||||
|
|
||||||
QMakeParser parser(0, &parseHandler);
|
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);
|
QVERIFY(proFile);
|
||||||
Qt4ProjectManager::Internal::ProWriter::addFiles(proFile, &lines, QDir(BASE_DIR),
|
Qt4ProjectManager::Internal::ProWriter::addFiles(proFile, &lines, QDir(BASE_DIR),
|
||||||
QStringList() << QString::fromLatin1(BASE_DIR "/sub/bar.cpp"),
|
QStringList() << QString::fromLatin1(BASE_DIR "/sub/bar.cpp"),
|
||||||
@@ -690,7 +690,7 @@ void tst_ProFileWriter::removeFiles()
|
|||||||
);
|
);
|
||||||
|
|
||||||
QMakeParser parser(0, &parseHandler);
|
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);
|
QVERIFY(proFile);
|
||||||
Qt4ProjectManager::Internal::ProWriter::removeFiles(proFile, &lines, QDir(BASE_DIR),
|
Qt4ProjectManager::Internal::ProWriter::removeFiles(proFile, &lines, QDir(BASE_DIR),
|
||||||
QStringList() << QString::fromLatin1(BASE_DIR "/sub/bar.cpp"),
|
QStringList() << QString::fromLatin1(BASE_DIR "/sub/bar.cpp"),
|
||||||
|
Reference in New Issue
Block a user