Commit d077ba29 authored by Oswald Buddenhagen's avatar Oswald Buddenhagen
Browse files

support custom functions: implement defineTest(), defineReplace(), defined(), return() & export()

parent 6ca93b31
......@@ -37,17 +37,18 @@ QT_BEGIN_NAMESPACE
struct AbstractProItemVisitor
{
virtual ~AbstractProItemVisitor() {}
virtual void visitBeginProBlock(ProBlock *block) = 0;
virtual ProItem::ProItemReturn visitBeginProBlock(ProBlock *block) = 0;
virtual void visitEndProBlock(ProBlock *block) = 0;
virtual void visitBeginProVariable(ProVariable *variable) = 0;
virtual void visitEndProVariable(ProVariable *variable) = 0;
virtual bool visitBeginProFile(ProFile *value) = 0;
virtual bool visitEndProFile(ProFile *value) = 0;
virtual ProItem::ProItemReturn visitBeginProFile(ProFile *value) = 0;
virtual ProItem::ProItemReturn visitEndProFile(ProFile *value) = 0;
virtual void visitProValue(ProValue *value) = 0;
virtual void visitProFunction(ProFunction *function) = 0;
virtual ProItem::ProItemReturn visitProFunction(ProFunction *function) = 0;
virtual void visitProOperator(ProOperator *function) = 0;
virtual void visitProCondition(ProCondition *function) = 0;
};
......
This diff is collapsed.
......@@ -46,15 +46,21 @@ QString ProItem::comment() const
}
// --------------- ProBlock ----------------
ProBlock::ProBlock(ProBlock *parent)
{
m_blockKind = 0;
m_parent = parent;
m_refCount = 1;
}
ProBlock::~ProBlock()
{
qDeleteAll(m_proitems);
foreach (ProItem *itm, m_proitems)
if (itm->kind() == BlockKind)
static_cast<ProBlock *>(itm)->deref();
else
delete itm;
}
void ProBlock::appendItem(ProItem *proitem)
......@@ -97,15 +103,16 @@ ProItem::ProItemKind ProBlock::kind() const
return ProItem::BlockKind;
}
bool ProBlock::Accept(AbstractProItemVisitor *visitor)
ProItem::ProItemReturn ProBlock::Accept(AbstractProItemVisitor *visitor)
{
visitor->visitBeginProBlock(this);
foreach (ProItem *item, m_proitems) {
if (!item->Accept(visitor))
return false;
}
if (visitor->visitBeginProBlock(this) == ReturnSkip)
return ReturnTrue;
ProItemReturn rt = ReturnTrue;
foreach (ProItem *item, m_proitems)
if ((rt = item->Accept(visitor)) != ReturnTrue && rt != ReturnFalse)
break;
visitor->visitEndProBlock(this);
return true;
return rt;
}
// --------------- ProVariable ----------------
......@@ -137,15 +144,13 @@ QString ProVariable::variable() const
return m_variable;
}
bool ProVariable::Accept(AbstractProItemVisitor *visitor)
ProItem::ProItemReturn ProVariable::Accept(AbstractProItemVisitor *visitor)
{
visitor->visitBeginProVariable(this);
foreach (ProItem *item, m_proitems) {
if (!item->Accept(visitor))
return false;
}
foreach (ProItem *item, m_proitems)
item->Accept(visitor); // cannot fail
visitor->visitEndProVariable(this);
return true;
return ReturnTrue;
}
// --------------- ProValue ----------------
......@@ -180,10 +185,10 @@ ProItem::ProItemKind ProValue::kind() const
return ProItem::ValueKind;
}
bool ProValue::Accept(AbstractProItemVisitor *visitor)
ProItem::ProItemReturn ProValue::Accept(AbstractProItemVisitor *visitor)
{
visitor->visitProValue(this);
return true;
return ReturnTrue;
}
// --------------- ProFunction ----------------
......@@ -207,10 +212,9 @@ ProItem::ProItemKind ProFunction::kind() const
return ProItem::FunctionKind;
}
bool ProFunction::Accept(AbstractProItemVisitor *visitor)
ProItem::ProItemReturn ProFunction::Accept(AbstractProItemVisitor *visitor)
{
visitor->visitProFunction(this);
return true;
return visitor->visitProFunction(this);
}
// --------------- ProCondition ----------------
......@@ -234,10 +238,10 @@ ProItem::ProItemKind ProCondition::kind() const
return ProItem::ConditionKind;
}
bool ProCondition::Accept(AbstractProItemVisitor *visitor)
ProItem::ProItemReturn ProCondition::Accept(AbstractProItemVisitor *visitor)
{
visitor->visitProCondition(this);
return true;
return ReturnTrue;
}
// --------------- ProOperator ----------------
......@@ -261,10 +265,10 @@ ProItem::ProItemKind ProOperator::kind() const
return ProItem::OperatorKind;
}
bool ProOperator::Accept(AbstractProItemVisitor *visitor)
ProItem::ProItemReturn ProOperator::Accept(AbstractProItemVisitor *visitor)
{
visitor->visitProOperator(this);
return true;
return ReturnTrue;
}
// --------------- ProFile ----------------
......@@ -309,13 +313,12 @@ bool ProFile::isModified() const
return m_modified;
}
bool ProFile::Accept(AbstractProItemVisitor *visitor)
ProItem::ProItemReturn ProFile::Accept(AbstractProItemVisitor *visitor)
{
visitor->visitBeginProFile(this);
foreach (ProItem *item, m_proitems) {
if (!item->Accept(visitor))
return false;
}
ProItemReturn rt;
if ((rt = visitor->visitBeginProFile(this)) != ReturnTrue)
return rt;
ProBlock::Accept(visitor); // cannot fail
return visitor->visitEndProFile(this);
}
......
......@@ -49,6 +49,13 @@ public:
BlockKind
};
enum ProItemReturn {
ReturnFalse,
ReturnTrue,
ReturnSkip,
ReturnReturn
};
ProItem() : m_lineNumber(0) {}
virtual ~ProItem() {}
......@@ -57,7 +64,7 @@ public:
void setComment(const QString &comment);
QString comment() const;
virtual bool Accept(AbstractProItemVisitor *visitor) = 0;
virtual ProItemReturn Accept(AbstractProItemVisitor *visitor) = 0;
int lineNumber() const { return m_lineNumber; }
void setLineNumber(int lineNumber) { m_lineNumber = lineNumber; }
......@@ -75,7 +82,8 @@ public:
ScopeContentsKind = 0x02,
VariableKind = 0x04,
ProFileKind = 0x08,
SingleLine = 0x10
FunctionBodyKind = 0x10,
SingleLine = 0x80
};
ProBlock(ProBlock *parent);
......@@ -91,14 +99,18 @@ public:
void setParent(ProBlock *parent);
ProBlock *parent() const;
void ref() { ++m_refCount; }
void deref() { if (!--m_refCount) delete this; }
ProItem::ProItemKind kind() const;
virtual bool Accept(AbstractProItemVisitor *visitor);
virtual ProItemReturn Accept(AbstractProItemVisitor *visitor);
protected:
QList<ProItem *> m_proitems;
private:
ProBlock *m_parent;
int m_blockKind;
int m_refCount;
};
class ProVariable : public ProBlock
......@@ -120,7 +132,7 @@ public:
void setVariable(const QString &name);
QString variable() const;
virtual bool Accept(AbstractProItemVisitor *visitor);
virtual ProItemReturn Accept(AbstractProItemVisitor *visitor);
private:
VariableOperator m_variableKind;
QString m_variable;
......@@ -139,7 +151,7 @@ public:
ProItem::ProItemKind kind() const;
virtual bool Accept(AbstractProItemVisitor *visitor);
virtual ProItemReturn Accept(AbstractProItemVisitor *visitor);
private:
QString m_value;
ProVariable *m_variable;
......@@ -155,7 +167,7 @@ public:
ProItem::ProItemKind kind() const;
virtual bool Accept(AbstractProItemVisitor *visitor);
virtual ProItemReturn Accept(AbstractProItemVisitor *visitor);
private:
QString m_text;
};
......@@ -170,7 +182,7 @@ public:
ProItem::ProItemKind kind() const;
virtual bool Accept(AbstractProItemVisitor *visitor);
virtual ProItemReturn Accept(AbstractProItemVisitor *visitor);
private:
QString m_text;
};
......@@ -190,7 +202,7 @@ public:
ProItem::ProItemKind kind() const;
virtual bool Accept(AbstractProItemVisitor *visitor);
virtual ProItemReturn Accept(AbstractProItemVisitor *visitor);
private:
OperatorKind m_operatorKind;
};
......@@ -210,7 +222,7 @@ public:
void setModified(bool modified);
bool isModified() const;
virtual bool Accept(AbstractProItemVisitor *visitor);
virtual ProItemReturn Accept(AbstractProItemVisitor *visitor);
private:
QString m_fileName;
......
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