Commit 0c09acbb authored by Oswald Buddenhagen's avatar Oswald Buddenhagen
Browse files

refactor ProFileEvaluator, part 1: introduce handler interface

externalize the error message and evaluation notification callbacks into
an own handler interface.
parent 752c823d
......@@ -35,8 +35,38 @@
using namespace Qt4ProjectManager;
using namespace Qt4ProjectManager::Internal;
static QString format(const QString &fileName, int lineNo, const QString &msg)
{
if (lineNo)
return QString::fromLatin1("%1(%2): %3").arg(fileName, QString::number(lineNo), msg);
else
return msg;
}
void ProMessageHandler::parseError(const QString &fileName, int lineNo, const QString &msg)
{
emit errorFound(format(fileName, lineNo, msg));
}
void ProMessageHandler::configError(const QString &msg)
{
emit errorFound(msg);
}
void ProMessageHandler::evalError(const QString &fileName, int lineNo, const QString &msg)
{
if (m_verbose)
emit errorFound(format(fileName, lineNo, msg));
}
void ProMessageHandler::fileMessage(const QString &)
{
// we ignore these...
}
ProFileReader::ProFileReader(ProFileOption *option)
: ProFileEvaluator(option)
: ProFileEvaluator(option, this)
, m_ignoreLevel(0)
{
}
......@@ -79,23 +109,6 @@ QList<ProFile*> ProFileReader::includeFiles() const
return m_includeFiles.values();
}
void ProFileReader::fileMessage(const QString &message)
{
Q_UNUSED(message)
// we ignore these...
}
void ProFileReader::logMessage(const QString &message)
{
Q_UNUSED(message)
// we ignore these...
}
void ProFileReader::errorMessage(const QString &message)
{
emit errorFound(message);
}
ProFile *ProFileReader::proFileFor(const QString &name)
{
return m_includeFiles.value(name);
......
......@@ -39,7 +39,30 @@
namespace Qt4ProjectManager {
namespace Internal {
class ProFileReader : public QObject, public ProFileEvaluator
class ProMessageHandler : public QObject,
public ProFileEvaluatorHandler
{
Q_OBJECT
public:
ProMessageHandler(bool verbose = false) : m_verbose(verbose) {}
virtual ~ProMessageHandler() {}
virtual void aboutToEval(ProFile *, ProFile *, EvalFileType) {}
virtual void doneWithEval(ProFile *) {}
virtual void parseError(const QString &filename, int lineNo, const QString &msg);
virtual void configError(const QString &msg);
virtual void evalError(const QString &filename, int lineNo, const QString &msg);
virtual void fileMessage(const QString &msg);
signals:
void errorFound(const QString &error);
private:
bool m_verbose;
};
class ProFileReader : public ProMessageHandler, public ProFileEvaluator
{
Q_OBJECT
......@@ -52,15 +75,9 @@ public:
QList<ProFile*> includeFiles() const;
ProFile *proFileFor(const QString &name);
signals:
void errorFound(const QString &error);
private:
virtual void aboutToEval(ProFile *parent, ProFile *proFile, EvalFileType type);
virtual void doneWithEval(ProFile *parent);
virtual void logMessage(const QString &msg);
virtual void fileMessage(const QString &msg);
virtual void errorMessage(const QString &msg);
private:
QMap<QString, ProFile *> m_includeFiles;
......
This diff is collapsed.
......@@ -45,6 +45,24 @@ QT_BEGIN_NAMESPACE
struct ProFileOption;
class ProFileEvaluatorHandler
{
public:
// Some error during parsing
virtual void parseError(const QString &filename, int lineNo, const QString &msg) = 0;
// qmake/project configuration error
virtual void configError(const QString &msg) = 0;
// Some error during evaluation
virtual void evalError(const QString &filename, int lineNo, const QString &msg) = 0;
// error() and message() from .pro file
virtual void fileMessage(const QString &msg) = 0;
enum EvalFileType { EvalProjectFile, EvalIncludeFile, EvalConfigFile, EvalFeatureFile, EvalAuxFile };
virtual void aboutToEval(ProFile *parent, ProFile *proFile, EvalFileType type) = 0;
virtual void doneWithEval(ProFile *parent) = 0;
};
class ProFileEvaluator
{
class Private;
......@@ -71,11 +89,10 @@ public:
// Call this from a concurrency-free context
static void initialize();
ProFileEvaluator(ProFileOption *option);
virtual ~ProFileEvaluator();
ProFileEvaluator(ProFileOption *option, ProFileEvaluatorHandler *handler);
~ProFileEvaluator();
ProFileEvaluator::TemplateType templateType() const;
void setVerbose(bool on); // Default is false
void setCumulative(bool on); // Default is true!
void setOutputDir(const QString &dir); // Default is empty
......@@ -99,14 +116,6 @@ public:
const ProFile *pro) const;
QString propertyValue(const QString &val) const;
// for our descendents
enum EvalFileType { EvalProjectFile, EvalIncludeFile, EvalConfigFile, EvalFeatureFile, EvalAuxFile };
virtual void aboutToEval(ProFile *parent, ProFile *proFile, EvalFileType type);
virtual void doneWithEval(ProFile *parent);
virtual void logMessage(const QString &msg);
virtual void errorMessage(const QString &msg); // .pro parse errors
virtual void fileMessage(const QString &msg); // error() and message() from .pro file
private:
Private *d;
......
......@@ -39,6 +39,31 @@
#include <QtCore/QStringList>
#include <QtCore/QTextCodec>
static void print(const QString &fileName, int lineNo, const QString &msg)
{
if (lineNo)
qWarning("%s(%d): %s", qPrintable(fileName), lineNo, qPrintable(msg));
else
qWarning("%s", qPrintable(msg));
}
class EvalHandler : public ProFileEvaluatorHandler {
public:
virtual void parseError(const QString &fileName, int lineNo, const QString &msg)
{ print(fileName, lineNo, msg); }
virtual void configError(const QString &msg)
{ qWarning("%s", qPrintable(msg)); }
virtual void evalError(const QString &fileName, int lineNo, const QString &msg)
{ print(fileName, lineNo, msg); }
virtual void fileMessage(const QString &msg)
{ qWarning("%s", qPrintable(msg)); }
virtual void aboutToEval(ProFile *, ProFile *, EvalFileType) {}
virtual void doneWithEval(ProFile *) {}
};
static EvalHandler evalHandler;
static QString value(ProFileEvaluator &reader, const QString &variable)
{
QStringList vals = reader.values(variable);
......@@ -56,8 +81,7 @@ static int evaluate(const QString &fileName, const QString &in_pwd, const QStrin
return 0;
visited.insert(fileName);
ProFileEvaluator visitor(option);
visitor.setVerbose(true);
ProFileEvaluator visitor(option, &evalHandler);
visitor.setCumulative(cumulative);
visitor.setOutputDir(out_pwd);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment