forked from qt-creator/qt-creator
remove visitor pattern
it's overengineered for our purpose and would just get in the way of planned optimizations.
This commit is contained in:
@@ -1,59 +0,0 @@
|
||||
/**************************************************************************
|
||||
**
|
||||
** This file is part of Qt Creator
|
||||
**
|
||||
** Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
|
||||
**
|
||||
** Contact: Nokia Corporation (qt-info@nokia.com)
|
||||
**
|
||||
** Commercial Usage
|
||||
**
|
||||
** Licensees holding valid Qt Commercial licenses may use this file in
|
||||
** accordance with the Qt Commercial License Agreement provided with the
|
||||
** Software or, alternatively, in accordance with the terms contained in
|
||||
** a written agreement between you and Nokia.
|
||||
**
|
||||
** GNU Lesser General Public License Usage
|
||||
**
|
||||
** Alternatively, this file may be used under the terms of the GNU Lesser
|
||||
** General Public License version 2.1 as published by the Free Software
|
||||
** Foundation and appearing in the file LICENSE.LGPL included in the
|
||||
** packaging of this file. Please review the following information to
|
||||
** ensure the GNU Lesser General Public License version 2.1 requirements
|
||||
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
||||
**
|
||||
** If you are unsure which license is appropriate for your use, please
|
||||
** contact the sales department at http://qt.nokia.com/contact.
|
||||
**
|
||||
**************************************************************************/
|
||||
|
||||
#ifndef ABSTRACTPROITEMVISITOR
|
||||
#define ABSTRACTPROITEMVISITOR
|
||||
|
||||
#include "proitems.h"
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
|
||||
struct AbstractProItemVisitor
|
||||
{
|
||||
virtual ~AbstractProItemVisitor() {}
|
||||
|
||||
virtual ProItem::ProItemReturn visitBeginProBlock(ProBlock *block) = 0;
|
||||
virtual void visitEndProBlock(ProBlock *block) = 0;
|
||||
|
||||
virtual ProItem::ProItemReturn visitProLoopIteration() = 0;
|
||||
virtual void visitProLoopCleanup() = 0;
|
||||
|
||||
virtual ProItem::ProItemReturn visitBeginProFile(ProFile *value) = 0;
|
||||
virtual ProItem::ProItemReturn visitEndProFile(ProFile *value) = 0;
|
||||
|
||||
virtual void visitProVariable(ProVariable *variable) = 0;
|
||||
virtual ProItem::ProItemReturn visitProFunction(ProFunction *function) = 0;
|
||||
virtual void visitProOperator(ProOperator *function) = 0;
|
||||
virtual void visitProCondition(ProCondition *function) = 0;
|
||||
};
|
||||
|
||||
QT_END_NAMESPACE
|
||||
|
||||
#endif // ABSTRACTPROITEMVISITOR
|
||||
|
||||
@@ -180,7 +180,7 @@ QString ProFileOption::field_sep;
|
||||
//
|
||||
///////////////////////////////////////////////////////////////////////
|
||||
|
||||
class ProFileEvaluator::Private : public AbstractProItemVisitor
|
||||
class ProFileEvaluator::Private
|
||||
{
|
||||
public:
|
||||
Private(ProFileEvaluator *q_, ProFileOption *option);
|
||||
@@ -210,13 +210,11 @@ public:
|
||||
|
||||
/////////////// Evaluating pro file contents
|
||||
|
||||
// implementation of AbstractProItemVisitor
|
||||
ProItem::ProItemReturn visitBeginProBlock(ProBlock *block);
|
||||
void visitEndProBlock(ProBlock *block);
|
||||
ProItem::ProItemReturn visitProFile(ProFile *pro);
|
||||
ProItem::ProItemReturn visitProBlock(ProBlock *block);
|
||||
ProItem::ProItemReturn visitProItem(ProItem *item);
|
||||
ProItem::ProItemReturn visitProLoopIteration();
|
||||
void visitProLoopCleanup();
|
||||
ProItem::ProItemReturn visitBeginProFile(ProFile *value);
|
||||
ProItem::ProItemReturn visitEndProFile(ProFile *value);
|
||||
void visitProVariable(ProVariable *variable);
|
||||
ProItem::ProItemReturn visitProFunction(ProFunction *function);
|
||||
void visitProOperator(ProOperator *oper);
|
||||
@@ -812,7 +810,27 @@ static QString fixPathToLocalOS(const QString &str)
|
||||
|
||||
//////// Evaluator /////////
|
||||
|
||||
ProItem::ProItemReturn ProFileEvaluator::Private::visitBeginProBlock(ProBlock *block)
|
||||
ProItem::ProItemReturn ProFileEvaluator::Private::visitProItem(ProItem *item)
|
||||
{
|
||||
switch (item->kind()) {
|
||||
case ProItem::BlockKind: // This is never a ProFile
|
||||
return visitProBlock(static_cast<ProBlock*>(item));
|
||||
case ProItem::VariableKind:
|
||||
visitProVariable(static_cast<ProVariable*>(item));
|
||||
break;
|
||||
case ProItem::ConditionKind:
|
||||
visitProCondition(static_cast<ProCondition*>(item));
|
||||
break;
|
||||
case ProItem::FunctionKind:
|
||||
return visitProFunction(static_cast<ProFunction*>(item));
|
||||
case ProItem::OperatorKind:
|
||||
visitProOperator(static_cast<ProOperator*>(item));
|
||||
break;
|
||||
}
|
||||
return ProItem::ReturnTrue;
|
||||
}
|
||||
|
||||
ProItem::ProItemReturn ProFileEvaluator::Private::visitProBlock(ProBlock *block)
|
||||
{
|
||||
if (block->blockKind() & ProBlock::ScopeContentsKind) {
|
||||
if (!m_definingFunc.isEmpty()) {
|
||||
@@ -827,7 +845,7 @@ ProItem::ProItemReturn ProFileEvaluator::Private::visitBeginProBlock(ProBlock *b
|
||||
block->setBlockKind(block->blockKind() | ProBlock::FunctionBodyKind);
|
||||
}
|
||||
m_definingFunc.clear();
|
||||
return ProItem::ReturnSkip;
|
||||
return ProItem::ReturnTrue;
|
||||
} else if (!(block->blockKind() & ProBlock::FunctionBodyKind)) {
|
||||
if (!m_sts.condition) {
|
||||
if (m_skipLevel || m_hadCondition)
|
||||
@@ -847,11 +865,32 @@ ProItem::ProItemReturn ProFileEvaluator::Private::visitBeginProBlock(ProBlock *b
|
||||
Q_ASSERT(!m_sts.condition);
|
||||
}
|
||||
}
|
||||
return ProItem::ReturnTrue;
|
||||
}
|
||||
|
||||
void ProFileEvaluator::Private::visitEndProBlock(ProBlock *block)
|
||||
{
|
||||
ProItem::ProItemReturn rt = ProItem::ReturnTrue;
|
||||
QList<ProItem *> items = block->items();
|
||||
for (int i = 0; i < items.count(); ++i) {
|
||||
rt = visitProItem(items.at(i));
|
||||
if (rt != ProItem::ReturnTrue && rt != ProItem::ReturnFalse) {
|
||||
if (rt == ProItem::ReturnLoop) {
|
||||
rt = ProItem::ReturnTrue;
|
||||
while (visitProLoopIteration())
|
||||
for (int j = i; ++j < items.count(); ) {
|
||||
rt = visitProItem(items.at(j));
|
||||
if (rt != ProItem::ReturnTrue && rt != ProItem::ReturnFalse) {
|
||||
if (rt == ProItem::ReturnNext) {
|
||||
rt = ProItem::ReturnTrue;
|
||||
break;
|
||||
}
|
||||
if (rt == ProItem::ReturnBreak)
|
||||
rt = ProItem::ReturnTrue;
|
||||
goto do_break;
|
||||
}
|
||||
}
|
||||
do_break:
|
||||
visitProLoopCleanup();
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
if ((block->blockKind() & ProBlock::ScopeContentsKind)
|
||||
&& !(block->blockKind() & ProBlock::FunctionBodyKind)) {
|
||||
if (m_skipLevel) {
|
||||
@@ -863,6 +902,7 @@ void ProFileEvaluator::Private::visitEndProBlock(ProBlock *block)
|
||||
m_sts.condition = true;
|
||||
}
|
||||
}
|
||||
return rt;
|
||||
}
|
||||
|
||||
ProItem::ProItemReturn ProFileEvaluator::Private::visitProLoopIteration()
|
||||
@@ -1001,7 +1041,7 @@ void ProFileEvaluator::Private::visitProCondition(ProCondition *cond)
|
||||
m_invertNext = false;
|
||||
}
|
||||
|
||||
ProItem::ProItemReturn ProFileEvaluator::Private::visitBeginProFile(ProFile * pro)
|
||||
ProItem::ProItemReturn ProFileEvaluator::Private::visitProFile(ProFile *pro)
|
||||
{
|
||||
m_lineNo = pro->lineNumber();
|
||||
|
||||
@@ -1124,11 +1164,8 @@ ProItem::ProItemReturn ProFileEvaluator::Private::visitBeginProFile(ProFile * pr
|
||||
}
|
||||
}
|
||||
|
||||
return ProItem::ReturnTrue;
|
||||
}
|
||||
visitProBlock(pro);
|
||||
|
||||
ProItem::ProItemReturn ProFileEvaluator::Private::visitEndProFile(ProFile * pro)
|
||||
{
|
||||
m_lineNo = pro->lineNumber();
|
||||
|
||||
if (m_profileStack.count() == 1) {
|
||||
@@ -1668,7 +1705,7 @@ QStringList ProFileEvaluator::Private::evaluateFunction(
|
||||
m_valuemap[QString::number(i+1)] = argumentsList[i];
|
||||
}
|
||||
m_valuemap[QLatin1String("ARGS")] = args;
|
||||
oki = (funcPtr->Accept(this) != ProItem::ReturnFalse); // True || Return
|
||||
oki = (visitProBlock(funcPtr) != ProItem::ReturnFalse); // True || Return
|
||||
ret = m_returnValue;
|
||||
m_returnValue.clear();
|
||||
|
||||
@@ -2237,7 +2274,7 @@ ProItem::ProItemReturn ProFileEvaluator::Private::evaluateConditionalFunction(
|
||||
delete pro;
|
||||
return ProItem::ReturnFalse;
|
||||
}
|
||||
bool ret = pro->Accept(this);
|
||||
bool ret = visitProBlock(pro);
|
||||
pro->deref();
|
||||
return returnBool(ret);
|
||||
}
|
||||
@@ -2813,7 +2850,7 @@ bool ProFileEvaluator::Private::evaluateFile(const QString &fileName)
|
||||
}
|
||||
if (ProFile *pro = parsedProFile(fileName, true)) {
|
||||
q->aboutToEval(pro);
|
||||
bool ok = (pro->Accept(this) == ProItem::ReturnTrue);
|
||||
bool ok = (visitProFile(pro) == ProItem::ReturnTrue);
|
||||
pro->deref();
|
||||
return ok;
|
||||
} else {
|
||||
@@ -2869,7 +2906,7 @@ bool ProFileEvaluator::Private::evaluateFeatureFile(
|
||||
// The path is fully normalized already.
|
||||
bool ok = false;
|
||||
if (ProFile *pro = parsedProFile(fn, true)) {
|
||||
ok = (pro->Accept(this) == ProItem::ReturnTrue);
|
||||
ok = (visitProFile(pro) == ProItem::ReturnTrue);
|
||||
pro->deref();
|
||||
}
|
||||
|
||||
@@ -3039,7 +3076,7 @@ ProFile *ProFileEvaluator::parsedProFile(const QString &fileName, const QString
|
||||
|
||||
bool ProFileEvaluator::accept(ProFile *pro)
|
||||
{
|
||||
return pro->Accept(d);
|
||||
return d->visitProFile(pro);
|
||||
}
|
||||
|
||||
QString ProFileEvaluator::propertyValue(const QString &name) const
|
||||
|
||||
@@ -31,7 +31,6 @@
|
||||
#define PROFILEEVALUATOR_H
|
||||
|
||||
#include "proitems.h"
|
||||
#include "abstractproitemvisitor.h"
|
||||
|
||||
#include <QtCore/QIODevice>
|
||||
#include <QtCore/QHash>
|
||||
|
||||
@@ -28,7 +28,6 @@
|
||||
**************************************************************************/
|
||||
|
||||
#include "proitems.h"
|
||||
#include "abstractproitemvisitor.h"
|
||||
|
||||
#include <QtCore/QFileInfo>
|
||||
|
||||
@@ -92,39 +91,6 @@ ProItem::ProItemKind ProBlock::kind() const
|
||||
return ProItem::BlockKind;
|
||||
}
|
||||
|
||||
ProItem::ProItemReturn ProBlock::Accept(AbstractProItemVisitor *visitor)
|
||||
{
|
||||
if (visitor->visitBeginProBlock(this) == ReturnSkip)
|
||||
return ReturnTrue;
|
||||
ProItemReturn rt = ReturnTrue;
|
||||
for (int i = 0; i < m_proitems.count(); ++i) {
|
||||
rt = m_proitems.at(i)->Accept(visitor);
|
||||
if (rt != ReturnTrue && rt != ReturnFalse) {
|
||||
if (rt == ReturnLoop) {
|
||||
rt = ReturnTrue;
|
||||
while (visitor->visitProLoopIteration())
|
||||
for (int j = i; ++j < m_proitems.count(); ) {
|
||||
rt = m_proitems.at(j)->Accept(visitor);
|
||||
if (rt != ReturnTrue && rt != ReturnFalse) {
|
||||
if (rt == ReturnNext) {
|
||||
rt = ReturnTrue;
|
||||
break;
|
||||
}
|
||||
if (rt == ReturnBreak)
|
||||
rt = ReturnTrue;
|
||||
goto do_break;
|
||||
}
|
||||
}
|
||||
do_break:
|
||||
visitor->visitProLoopCleanup();
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
visitor->visitEndProBlock(this);
|
||||
return rt;
|
||||
}
|
||||
|
||||
// --------------- ProVariable ----------------
|
||||
ProVariable::ProVariable(const QString &name)
|
||||
{
|
||||
@@ -167,12 +133,6 @@ ProItem::ProItemKind ProVariable::kind() const
|
||||
return ProItem::VariableKind;
|
||||
}
|
||||
|
||||
ProItem::ProItemReturn ProVariable::Accept(AbstractProItemVisitor *visitor)
|
||||
{
|
||||
visitor->visitProVariable(this);
|
||||
return ReturnTrue;
|
||||
}
|
||||
|
||||
// --------------- ProFunction ----------------
|
||||
ProFunction::ProFunction(const QString &text)
|
||||
{
|
||||
@@ -194,11 +154,6 @@ ProItem::ProItemKind ProFunction::kind() const
|
||||
return ProItem::FunctionKind;
|
||||
}
|
||||
|
||||
ProItem::ProItemReturn ProFunction::Accept(AbstractProItemVisitor *visitor)
|
||||
{
|
||||
return visitor->visitProFunction(this);
|
||||
}
|
||||
|
||||
// --------------- ProCondition ----------------
|
||||
ProCondition::ProCondition(const QString &text)
|
||||
{
|
||||
@@ -220,12 +175,6 @@ ProItem::ProItemKind ProCondition::kind() const
|
||||
return ProItem::ConditionKind;
|
||||
}
|
||||
|
||||
ProItem::ProItemReturn ProCondition::Accept(AbstractProItemVisitor *visitor)
|
||||
{
|
||||
visitor->visitProCondition(this);
|
||||
return ReturnTrue;
|
||||
}
|
||||
|
||||
// --------------- ProOperator ----------------
|
||||
ProOperator::ProOperator(OperatorKind operatorKind)
|
||||
{
|
||||
@@ -247,12 +196,6 @@ ProItem::ProItemKind ProOperator::kind() const
|
||||
return ProItem::OperatorKind;
|
||||
}
|
||||
|
||||
ProItem::ProItemReturn ProOperator::Accept(AbstractProItemVisitor *visitor)
|
||||
{
|
||||
visitor->visitProOperator(this);
|
||||
return ReturnTrue;
|
||||
}
|
||||
|
||||
// --------------- ProFile ----------------
|
||||
ProFile::ProFile(const QString &fileName)
|
||||
: ProBlock(0)
|
||||
@@ -286,13 +229,4 @@ QString ProFile::directoryName() const
|
||||
return m_directoryName;
|
||||
}
|
||||
|
||||
ProItem::ProItemReturn ProFile::Accept(AbstractProItemVisitor *visitor)
|
||||
{
|
||||
ProItemReturn rt;
|
||||
if ((rt = visitor->visitBeginProFile(this)) != ReturnTrue)
|
||||
return rt;
|
||||
ProBlock::Accept(visitor); // cannot fail
|
||||
return visitor->visitEndProFile(this);
|
||||
}
|
||||
|
||||
QT_END_NAMESPACE
|
||||
|
||||
@@ -35,8 +35,6 @@
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
|
||||
struct AbstractProItemVisitor;
|
||||
|
||||
class ProItem
|
||||
{
|
||||
public:
|
||||
@@ -64,7 +62,6 @@ public:
|
||||
|
||||
virtual ProItemKind kind() const = 0;
|
||||
|
||||
virtual ProItemReturn Accept(AbstractProItemVisitor *visitor) = 0;
|
||||
int lineNumber() const { return m_lineNumber; }
|
||||
void setLineNumber(int lineNumber) { m_lineNumber = lineNumber; }
|
||||
|
||||
@@ -102,11 +99,9 @@ public:
|
||||
|
||||
ProItem::ProItemKind kind() const;
|
||||
|
||||
virtual ProItemReturn Accept(AbstractProItemVisitor *visitor);
|
||||
protected:
|
||||
QList<ProItem *> m_proitems;
|
||||
private:
|
||||
ProBlock *m_parent;
|
||||
QList<ProItem *> m_proitems;
|
||||
int m_blockKind;
|
||||
int m_refCount;
|
||||
};
|
||||
@@ -135,7 +130,6 @@ public:
|
||||
|
||||
ProItem::ProItemKind kind() const;
|
||||
|
||||
virtual ProItemReturn Accept(AbstractProItemVisitor *visitor);
|
||||
private:
|
||||
VariableOperator m_variableKind;
|
||||
QString m_variable;
|
||||
@@ -152,7 +146,6 @@ public:
|
||||
|
||||
ProItem::ProItemKind kind() const;
|
||||
|
||||
virtual ProItemReturn Accept(AbstractProItemVisitor *visitor);
|
||||
private:
|
||||
QString m_text;
|
||||
};
|
||||
@@ -167,7 +160,6 @@ public:
|
||||
|
||||
ProItem::ProItemKind kind() const;
|
||||
|
||||
virtual ProItemReturn Accept(AbstractProItemVisitor *visitor);
|
||||
private:
|
||||
QString m_text;
|
||||
};
|
||||
@@ -187,7 +179,6 @@ public:
|
||||
|
||||
ProItem::ProItemKind kind() const;
|
||||
|
||||
virtual ProItemReturn Accept(AbstractProItemVisitor *visitor);
|
||||
private:
|
||||
OperatorKind m_operatorKind;
|
||||
};
|
||||
@@ -202,8 +193,6 @@ public:
|
||||
QString fileName() const;
|
||||
QString directoryName() const;
|
||||
|
||||
virtual ProItemReturn Accept(AbstractProItemVisitor *visitor);
|
||||
|
||||
private:
|
||||
QString m_fileName;
|
||||
QString m_displayFileName;
|
||||
|
||||
@@ -6,7 +6,6 @@ DEPENDPATH *= $$PWD $$PWD/..
|
||||
|
||||
# Input
|
||||
HEADERS += \
|
||||
abstractproitemvisitor.h \
|
||||
profileevaluator.h \
|
||||
proitems.h \
|
||||
prowriter.h \
|
||||
|
||||
@@ -15,6 +15,6 @@ build_all:!build_pass {
|
||||
}
|
||||
|
||||
SOURCES = main.cpp profileevaluator.cpp proitems.cpp ioutils.cpp
|
||||
HEADERS = profileevaluator.h proitems.h abstractproitemvisitor.h ioutils.h
|
||||
HEADERS = profileevaluator.h proitems.h ioutils.h
|
||||
|
||||
DEFINES += QT_NO_CAST_TO_ASCII QT_NO_CAST_FROM_ASCII
|
||||
|
||||
Reference in New Issue
Block a user