introduce QMakeHandler

this is QMakeEvaluatorHandler, but derived from QMakeParserHandler.
the idea is that the parser can be used stand-alone, while the evaluator
needs the parser as well.
we will need it in QMakeGlobals as well, so put it there, as that is the
most central place.

Change-Id: I6ee46c0e4b2e044bf3bfc6e4235b53525ddfc875
Reviewed-by: Daniel Teske <daniel.teske@nokia.com>
This commit is contained in:
Oswald Buddenhagen
2012-06-11 20:28:16 +02:00
parent 6d63786f92
commit ac297f8e6b
7 changed files with 28 additions and 35 deletions

View File

@@ -48,8 +48,7 @@ namespace Internal {
class QtSupportPlugin; class QtSupportPlugin;
} }
class QTSUPPORT_EXPORT ProMessageHandler : public QObject, class QTSUPPORT_EXPORT ProMessageHandler : public QObject, public QMakeHandler
public QMakeParserHandler, public QMakeEvaluatorHandler
{ {
Q_OBJECT Q_OBJECT

View File

@@ -46,7 +46,7 @@ void ProFileEvaluator::initialize()
} }
ProFileEvaluator::ProFileEvaluator(QMakeGlobals *option, QMakeParser *parser, ProFileEvaluator::ProFileEvaluator(QMakeGlobals *option, QMakeParser *parser,
QMakeEvaluatorHandler *handler) QMakeHandler *handler)
: d(new QMakeEvaluator(option, parser, handler)) : d(new QMakeEvaluator(option, parser, handler))
{ {
} }
@@ -187,7 +187,7 @@ ProFileEvaluator::TemplateType ProFileEvaluator::templateType() const
bool ProFileEvaluator::accept(ProFile *pro, QMakeEvaluator::LoadFlags flags) bool ProFileEvaluator::accept(ProFile *pro, QMakeEvaluator::LoadFlags flags)
{ {
return d->visitProFile(pro, QMakeEvaluatorHandler::EvalProjectFile, flags) == QMakeEvaluator::ReturnTrue; return d->visitProFile(pro, QMakeHandler::EvalProjectFile, flags) == QMakeEvaluator::ReturnTrue;
} }
QString ProFileEvaluator::propertyValue(const QString &name) const QString ProFileEvaluator::propertyValue(const QString &name) const

View File

@@ -45,7 +45,7 @@ QT_BEGIN_NAMESPACE
class QMakeGlobals; class QMakeGlobals;
class QMakeParser; class QMakeParser;
class QMakeEvaluator; class QMakeEvaluator;
class QMakeEvaluatorHandler; class QMakeHandler;
class QMAKE_EXPORT ProFileEvaluator class QMAKE_EXPORT ProFileEvaluator
{ {
@@ -62,7 +62,7 @@ public:
// Call this from a concurrency-free context // Call this from a concurrency-free context
static void initialize(); static void initialize();
ProFileEvaluator(QMakeGlobals *option, QMakeParser *parser, QMakeEvaluatorHandler *handler); ProFileEvaluator(QMakeGlobals *option, QMakeParser *parser, QMakeHandler *handler);
~ProFileEvaluator(); ~ProFileEvaluator();
ProFileEvaluator::TemplateType templateType() const; ProFileEvaluator::TemplateType templateType() const;

View File

@@ -416,7 +416,7 @@ ProStringList QMakeEvaluator::evaluateExpandFunction(
QHash<ProString, ProStringList> vars; QHash<ProString, ProStringList> vars;
QString fn = resolvePath(m_option->expandEnvVars(args.at(0).toQString(m_tmp1))); QString fn = resolvePath(m_option->expandEnvVars(args.at(0).toQString(m_tmp1)));
fn.detach(); fn.detach();
if (evaluateFileInto(fn, QMakeEvaluatorHandler::EvalAuxFile, if (evaluateFileInto(fn, QMakeHandler::EvalAuxFile,
&vars, &m_functionDefs, EvalWithDefaults)) &vars, &m_functionDefs, EvalWithDefaults))
ret = vars.value(map(args.at(1))); ret = vars.value(map(args.at(1)));
} }
@@ -704,7 +704,7 @@ QMakeEvaluator::VisitReturn QMakeEvaluator::evaluateConditionalFunction(
QHash<ProString, ProStringList> vars; QHash<ProString, ProStringList> vars;
QString fn = resolvePath(m_option->expandEnvVars(args.at(0).toQString(m_tmp1))); QString fn = resolvePath(m_option->expandEnvVars(args.at(0).toQString(m_tmp1)));
fn.detach(); fn.detach();
if (!evaluateFileInto(fn, QMakeEvaluatorHandler::EvalAuxFile, if (!evaluateFileInto(fn, QMakeHandler::EvalAuxFile,
&vars, &m_functionDefs, EvalWithDefaults)) &vars, &m_functionDefs, EvalWithDefaults))
return ReturnFalse; return ReturnFalse;
if (args.count() == 2) if (args.count() == 2)
@@ -991,10 +991,10 @@ QMakeEvaluator::VisitReturn QMakeEvaluator::evaluateConditionalFunction(
fn.detach(); fn.detach();
bool ok; bool ok;
if (parseInto.isEmpty()) { if (parseInto.isEmpty()) {
ok = evaluateFile(fn, QMakeEvaluatorHandler::EvalIncludeFile, LoadProOnly); ok = evaluateFile(fn, QMakeHandler::EvalIncludeFile, LoadProOnly);
} else { } else {
QHash<ProString, ProStringList> symbols; QHash<ProString, ProStringList> symbols;
if ((ok = evaluateFileInto(fn, QMakeEvaluatorHandler::EvalAuxFile, if ((ok = evaluateFileInto(fn, QMakeHandler::EvalAuxFile,
&symbols, 0, EvalWithSetup))) { &symbols, 0, EvalWithSetup))) {
QHash<ProString, ProStringList> newMap; QHash<ProString, ProStringList> newMap;
for (QHash<ProString, ProStringList>::ConstIterator for (QHash<ProString, ProStringList>::ConstIterator

View File

@@ -150,7 +150,7 @@ const ProString &QMakeEvaluator::map(const ProString &var)
QMakeEvaluator::QMakeEvaluator(QMakeGlobals *option, QMakeEvaluator::QMakeEvaluator(QMakeGlobals *option,
QMakeParser *parser, QMakeEvaluatorHandler *handler) QMakeParser *parser, QMakeHandler *handler)
: m_option(option), m_parser(parser), m_handler(handler) : m_option(option), m_parser(parser), m_handler(handler)
{ {
// So that single-threaded apps don't have to call initialize() for now. // So that single-threaded apps don't have to call initialize() for now.
@@ -834,7 +834,7 @@ void QMakeEvaluator::visitCmdLine(const QString &cmds)
} }
QMakeEvaluator::VisitReturn QMakeEvaluator::visitProFile( QMakeEvaluator::VisitReturn QMakeEvaluator::visitProFile(
ProFile *pro, QMakeEvaluatorHandler::EvalFileType type, LoadFlags flags) ProFile *pro, QMakeHandler::EvalFileType type, LoadFlags flags)
{ {
if (!m_cumulative && !pro->isOk()) if (!m_cumulative && !pro->isOk())
return ReturnFalse; return ReturnFalse;
@@ -882,7 +882,7 @@ QMakeEvaluator::VisitReturn QMakeEvaluator::visitProFile(
if (!qmake_cache.isEmpty()) { if (!qmake_cache.isEmpty()) {
qmake_cache = resolvePath(qmake_cache); qmake_cache = resolvePath(qmake_cache);
QHash<ProString, ProStringList> cache_valuemap; QHash<ProString, ProStringList> cache_valuemap;
if (evaluateFileInto(qmake_cache, QMakeEvaluatorHandler::EvalConfigFile, if (evaluateFileInto(qmake_cache, QMakeHandler::EvalConfigFile,
&cache_valuemap, 0, EvalProOnly)) { &cache_valuemap, 0, EvalProOnly)) {
if (m_option->qmakespec.isEmpty()) { if (m_option->qmakespec.isEmpty()) {
const ProStringList &vals = cache_valuemap.value(ProString("QMAKESPEC")); const ProStringList &vals = cache_valuemap.value(ProString("QMAKESPEC"));
@@ -939,13 +939,12 @@ QMakeEvaluator::VisitReturn QMakeEvaluator::visitProFile(
m_option->qmakespec = QDir::cleanPath(qmakespec); m_option->qmakespec = QDir::cleanPath(qmakespec);
QString spec = m_option->qmakespec + QLatin1String("/qmake.conf"); QString spec = m_option->qmakespec + QLatin1String("/qmake.conf");
if (!evaluateFileDirect(spec, if (!evaluateFileDirect(spec, QMakeHandler::EvalConfigFile, LoadProOnly)) {
QMakeEvaluatorHandler::EvalConfigFile, LoadProOnly)) {
m_handler->configError( m_handler->configError(
fL1S("Could not read qmake configuration file %1").arg(spec)); fL1S("Could not read qmake configuration file %1").arg(spec));
} else if (!m_option->cachefile.isEmpty()) { } else if (!m_option->cachefile.isEmpty()) {
evaluateFileDirect(m_option->cachefile, evaluateFileDirect(m_option->cachefile,
QMakeEvaluatorHandler::EvalConfigFile, LoadProOnly); QMakeHandler::EvalConfigFile, LoadProOnly);
} }
m_option->qmakespec_name = IoUtils::fileName(m_option->qmakespec).toString(); m_option->qmakespec_name = IoUtils::fileName(m_option->qmakespec).toString();
if (m_option->qmakespec_name == QLatin1String("default")) { if (m_option->qmakespec_name == QLatin1String("default")) {
@@ -1884,7 +1883,7 @@ ProString QMakeEvaluator::first(const ProString &variableName) const
} }
bool QMakeEvaluator::evaluateFileDirect( bool QMakeEvaluator::evaluateFileDirect(
const QString &fileName, QMakeEvaluatorHandler::EvalFileType type, LoadFlags flags) const QString &fileName, QMakeHandler::EvalFileType type, LoadFlags flags)
{ {
if (ProFile *pro = m_parser->parsedProFile(fileName, true)) { if (ProFile *pro = m_parser->parsedProFile(fileName, true)) {
m_locationStack.push(m_current); m_locationStack.push(m_current);
@@ -1898,7 +1897,7 @@ bool QMakeEvaluator::evaluateFileDirect(
} }
bool QMakeEvaluator::evaluateFile( bool QMakeEvaluator::evaluateFile(
const QString &fileName, QMakeEvaluatorHandler::EvalFileType type, LoadFlags flags) const QString &fileName, QMakeHandler::EvalFileType type, LoadFlags flags)
{ {
if (fileName.isEmpty()) if (fileName.isEmpty())
return false; return false;
@@ -1955,7 +1954,7 @@ bool QMakeEvaluator::evaluateFeatureFile(const QString &fileName)
#endif #endif
// The path is fully normalized already. // The path is fully normalized already.
bool ok = evaluateFileDirect(fn, QMakeEvaluatorHandler::EvalFeatureFile, LoadProOnly); bool ok = evaluateFileDirect(fn, QMakeHandler::EvalFeatureFile, LoadProOnly);
#ifdef PROEVALUATOR_CUMULATIVE #ifdef PROEVALUATOR_CUMULATIVE
m_cumulative = cumulative; m_cumulative = cumulative;
@@ -1964,7 +1963,7 @@ bool QMakeEvaluator::evaluateFeatureFile(const QString &fileName)
} }
bool QMakeEvaluator::evaluateFileInto( bool QMakeEvaluator::evaluateFileInto(
const QString &fileName, QMakeEvaluatorHandler::EvalFileType type, const QString &fileName, QMakeHandler::EvalFileType type,
QHash<ProString, ProStringList> *values, ProFunctionDefs *funcs, EvalIntoMode mode) QHash<ProString, ProStringList> *values, ProFunctionDefs *funcs, EvalIntoMode mode)
{ {
ProFileEvaluator visitor(m_option, m_parser, m_handler); ProFileEvaluator visitor(m_option, m_parser, m_handler);

View File

@@ -33,6 +33,7 @@
#ifndef QMAKEEVALUATOR_H #ifndef QMAKEEVALUATOR_H
#define QMAKEEVALUATOR_H #define QMAKEEVALUATOR_H
#include "qmakeparser.h"
#include "qmakeglobals.h" #include "qmakeglobals.h"
#include "ioutils.h" #include "ioutils.h"
@@ -44,9 +45,7 @@
QT_BEGIN_NAMESPACE QT_BEGIN_NAMESPACE
class QMakeParser; class QMAKE_EXPORT QMakeHandler : public QMakeParserHandler
class QMAKE_EXPORT QMakeEvaluatorHandler
{ {
public: public:
// qmake/project configuration error // qmake/project configuration error
@@ -75,7 +74,7 @@ public:
static void initStatics(); static void initStatics();
static void initFunctionStatics(); static void initFunctionStatics();
QMakeEvaluator(QMakeGlobals *option, QMakeParser *parser, QMakeEvaluator(QMakeGlobals *option, QMakeParser *parser,
QMakeEvaluatorHandler *handler); QMakeHandler *handler);
~QMakeEvaluator(); ~QMakeEvaluator();
ProStringList values(const ProString &variableName) const; ProStringList values(const ProString &variableName) const;
@@ -103,7 +102,7 @@ public:
void skipExpression(const ushort *&tokPtr); void skipExpression(const ushort *&tokPtr);
void visitCmdLine(const QString &cmds); void visitCmdLine(const QString &cmds);
VisitReturn visitProFile(ProFile *pro, QMakeEvaluatorHandler::EvalFileType type, VisitReturn visitProFile(ProFile *pro, QMakeHandler::EvalFileType type,
LoadFlags flags); LoadFlags flags);
VisitReturn visitProBlock(ProFile *pro, const ushort *tokPtr); VisitReturn visitProBlock(ProFile *pro, const ushort *tokPtr);
VisitReturn visitProBlock(const ushort *tokPtr); VisitReturn visitProBlock(const ushort *tokPtr);
@@ -127,13 +126,13 @@ public:
QString resolvePath(const QString &fileName) const QString resolvePath(const QString &fileName) const
{ return ProFileEvaluatorInternal::IoUtils::resolvePath(currentDirectory(), fileName); } { return ProFileEvaluatorInternal::IoUtils::resolvePath(currentDirectory(), fileName); }
bool evaluateFileDirect(const QString &fileName, QMakeEvaluatorHandler::EvalFileType type, bool evaluateFileDirect(const QString &fileName, QMakeHandler::EvalFileType type,
LoadFlags flags); LoadFlags flags);
bool evaluateFile(const QString &fileName, QMakeEvaluatorHandler::EvalFileType type, bool evaluateFile(const QString &fileName, QMakeHandler::EvalFileType type,
LoadFlags flags); LoadFlags flags);
bool evaluateFeatureFile(const QString &fileName); bool evaluateFeatureFile(const QString &fileName);
enum EvalIntoMode { EvalProOnly, EvalWithDefaults, EvalWithSetup }; enum EvalIntoMode { EvalProOnly, EvalWithDefaults, EvalWithSetup };
bool evaluateFileInto(const QString &fileName, QMakeEvaluatorHandler::EvalFileType type, bool evaluateFileInto(const QString &fileName, QMakeHandler::EvalFileType type,
QHash<ProString, ProStringList> *values, ProFunctionDefs *defs, QHash<ProString, ProStringList> *values, ProFunctionDefs *defs,
EvalIntoMode mode); // values are output-only, defs are input-only EvalIntoMode mode); // values are output-only, defs are input-only
void evalError(const QString &msg) const; void evalError(const QString &msg) const;
@@ -201,7 +200,7 @@ public:
QMakeGlobals *m_option; QMakeGlobals *m_option;
QMakeParser *m_parser; QMakeParser *m_parser;
QMakeEvaluatorHandler *m_handler; QMakeHandler *m_handler;
enum VarName { enum VarName {
V_LITERAL_DOLLAR, V_LITERAL_HASH, V_LITERAL_WHITESPACE, V_LITERAL_DOLLAR, V_LITERAL_HASH, V_LITERAL_WHITESPACE,

View File

@@ -53,14 +53,11 @@ static void print(const QString &fileName, int lineNo, const QString &msg)
qWarning("%s", qPrintable(msg)); qWarning("%s", qPrintable(msg));
} }
class ParseHandler : public QMakeParserHandler { class EvalHandler : public QMakeHandler {
public: public:
virtual void parseError(const QString &fileName, int lineNo, const QString &msg) virtual void parseError(const QString &fileName, int lineNo, const QString &msg)
{ print(fileName, lineNo, msg); } { print(fileName, lineNo, msg); }
};
class EvalHandler : public QMakeEvaluatorHandler {
public:
virtual void configError(const QString &msg) virtual void configError(const QString &msg)
{ qWarning("%s", qPrintable(msg)); } { qWarning("%s", qPrintable(msg)); }
virtual void evalError(const QString &fileName, int lineNo, const QString &msg) virtual void evalError(const QString &fileName, int lineNo, const QString &msg)
@@ -72,7 +69,6 @@ public:
virtual void doneWithEval(ProFile *) {} virtual void doneWithEval(ProFile *) {}
}; };
static ParseHandler parseHandler;
static EvalHandler evalHandler; static EvalHandler evalHandler;
static QString value(ProFileEvaluator &reader, const QString &variable) static QString value(ProFileEvaluator &reader, const QString &variable)
@@ -165,7 +161,7 @@ int main(int argc, char **argv)
option.initProperties(QLibraryInfo::location(QLibraryInfo::BinariesPath) + QLatin1String("/qmake")); option.initProperties(QLibraryInfo::location(QLibraryInfo::BinariesPath) + QLatin1String("/qmake"));
if (args.count() >= 4) if (args.count() >= 4)
option.setCommandLineArguments(args.mid(3)); option.setCommandLineArguments(args.mid(3));
QMakeParser parser(0, &parseHandler); QMakeParser parser(0, &evalHandler);
bool cumulative = args[0] == QLatin1String("true"); bool cumulative = args[0] == QLatin1String("true");
QFileInfo infi(args[1]); QFileInfo infi(args[1]);