1
/******************************************************************************
2
Copyright (c) 2007 netAllied GmbH, Tettnang
4
Permission is hereby granted, free of charge, to any person
5
obtaining a copy of this software and associated documentation
6
files (the "Software"), to deal in the Software without
7
restriction, including without limitation the rights to use,
8
copy, modify, merge, publish, distribute, sublicense, and/or sell
9
copies of the Software, and to permit persons to whom the
10
Software is furnished to do so, subject to the following
13
The above copyright notice and this permission notice shall be
14
included in all copies or substantial portions of the Software.
16
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
18
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
20
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
21
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
22
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
23
OTHER DEALINGS IN THE SOFTWARE.
24
******************************************************************************/
26
#ifndef __MATHML_AST_VISITOR_H___
27
#define __MATHML_AST_VISITOR_H___
29
#include "MathMLSolverPrerequisites.h"
30
#include "MathMLASTNode.h"
31
#include "MathMLASTArithmeticExpression.h"
32
#include "MathMLASTLogicExpression.h"
33
#include "MathMLASTBinaryComparisionExpression.h"
34
#include "MathMLASTConstantExpression.h"
35
#include "MathMLASTUnaryArithmeticExpression.h"
36
#include "MathMLASTFragmentExpression.h"
37
#include "MathMLASTVariableExpression.h"
38
#include "MathMLASTFunctionExpression.h"
46
/** Interface of AST node visitor. */
48
class _MATHML_SOLVER_EXPORT IVisitor
53
/** Virtual D-tor to make sure sub class D-tors are called. */
57
/** Callback for visiting of (specialized) arithmetic node.
58
@param node The arithmetic expression node.
60
virtual void visit( const ArithmeticExpression* const node ) = 0;
62
/** Callback for visiting of (specialized) binary comparision node.
63
@param node The binary comparision expression node.
65
virtual void visit( const BinaryComparisonExpression* const node ) = 0;
67
/** Callback for visiting of (specialized) fragment node.
68
@param node The fragment expression node.
70
virtual void visit( const FragmentExpression* const node ) = 0;
72
/** Callback for visiting of (specialized) logic node.
73
@param node The logic expression node.
75
virtual void visit( const LogicExpression* const node ) = 0;
77
/** Callback for visiting of (specialized) constant node.
78
@param node The constant expression node.
80
virtual void visit( const ConstantExpression* const node ) = 0;
82
/** Callback for visiting of (specialized) function node.
83
@param node The function expression node.
85
virtual void visit( const FunctionExpression* const node ) = 0;
87
/** Callback for visiting of (specialized) unary arithmetic node.
88
@param node The unary arithmetic expression node.
90
virtual void visit( const UnaryExpression* const node ) = 0;
92
/** Callback for visiting of (specialized) variable node.
93
@param node The variable expression node.
95
virtual void visit( const VariableExpression* const node ) = 0;
97
virtual void visit( const INode* const node)
99
switch(node->getNodeType())
101
case INode::FRAGMENT:
102
visit(static_cast<const FragmentExpression* const>(node));
105
case INode::ARITHMETIC:
106
visit(static_cast<const ArithmeticExpression* const>(node));
109
case INode::COMPARISON:
110
visit(static_cast<const BinaryComparisonExpression* const>(node));
113
case INode::CONSTANT:
114
visit(static_cast<const ConstantExpression* const>(node));
117
case INode::FUNCTION:
118
visit(static_cast<const FunctionExpression* const>(node));
122
visit(static_cast<const LogicExpression* const>(node));
126
visit(static_cast<const UnaryExpression* const>(node));
129
case INode::VARIABLE:
130
visit(static_cast<const VariableExpression* const>(node));
132
//to prevent WARNING for unusued enum USERDEFINED
133
case INode::USERDEFINED:
141
/** Default expression node visitor implementing AST-Node-Interface ('INode').
142
@par Does nothing. Specialized Visitors have to implement/override the methods.
145
class _MATHML_SOLVER_EXPORT DefaultVisitor : public IVisitor
149
// see IVisitor::visit(const ArithmeticExpression&)
150
virtual void visit( const ArithmeticExpression* const node )
153
// see IVisitor::visit(const BinaryComparisionExpression&)
154
virtual void visit( const BinaryComparisonExpression* const node )
157
// see IVisitor::visit(const FragmentExpression&)
158
virtual void visit( const FragmentExpression* const node )
161
// see IVisitor::visit(const LogicExpression&)
162
virtual void visit( const LogicExpression* const node )
165
// see IVisitor::visit(const ConstantExpression&)
166
virtual void visit( const ConstantExpression* const node )
169
// see IVisitor::visit(const FunctionExpression&)
170
virtual void visit( const FunctionExpression* const node )
173
// see IVisitor::visit(const UnaryArithmeticExpression&)
174
virtual void visit( const UnaryExpression* const node )
177
// see IVisitor::visit(const VariableExpression&)
178
virtual void visit( const VariableExpression* const node )
189
#endif //__MATHML_AST_VISITOR_H___