1 // Copyright 2004-2008 Castle Project - http://www.castleproject.org/
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
7 // http://www.apache.org/licenses/LICENSE-2.0
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
15 namespace Castle
.Rook
.Compiler
.Visitors
18 using System
.Collections
;
20 using Castle
.Rook
.Compiler
.AST
;
23 public abstract class AbstractVisitor
: IASTVisitor
25 public AbstractVisitor()
29 public virtual bool VisitNode(IVisitableNode node
)
31 if (node
== null) return true;
33 bool res
= node
.Accept(this);
38 public virtual bool VisitNodes(IList nodes
)
40 foreach(IVisitableNode node
in nodes
)
48 public virtual void VisitCompilationUnit(CompilationUnit compilationUnit
)
50 VisitNode(compilationUnit
.EntryPointSourceUnit
);
51 VisitNodes(compilationUnit
.SourceUnits
);
54 public virtual bool VisitSourceUnit(SourceUnit unit
)
56 VisitNodes(unit
.Namespaces
);
57 VisitNodes(unit
.Statements
);
62 public virtual bool VisitNamespace(NamespaceDescriptor ns
)
66 VisitNodes(ns
.TypeDefinitions
);
68 return VisitLeave(ns
);
74 public virtual bool VisitEnter(NamespaceDescriptor ns
)
79 public virtual bool VisitLeave(NamespaceDescriptor ns
)
84 public virtual bool VisitTypeDefinitionStatement(TypeDefinitionStatement typeDef
)
86 if (VisitEnter(typeDef
))
88 VisitNodes(typeDef
.Statements
);
90 return VisitLeave(typeDef
);
96 public virtual bool VisitEnter(TypeDefinitionStatement typeDef
)
101 public virtual bool VisitLeave(TypeDefinitionStatement typeDef
)
106 public virtual bool VisitMethodDefinitionStatement(MethodDefinitionStatement methodDef
)
108 if (VisitEnter(methodDef
))
110 VisitNodes(methodDef
.Arguments
);
111 VisitNodes(methodDef
.Statements
);
113 return VisitLeave(methodDef
);
119 public virtual void VisitConstructorDefinitionStatement(ConstructorDefinitionStatement statement
)
121 if (VisitEnter(statement
))
123 VisitNodes(statement
.Arguments
);
124 VisitNodes(statement
.Statements
);
126 VisitLeave(statement
);
130 public virtual bool VisitEnter(MethodDefinitionStatement methodDef
)
135 public virtual bool VisitLeave(MethodDefinitionStatement methodDef
)
144 public virtual void VisitTypeReference(TypeReference reference
)
148 public virtual bool VisitIdentifier(Identifier identifier
)
150 VisitNode(identifier
.TypeReference
);
155 public virtual void VisitParameterVarIdentifier(ParameterVarIdentifier parameterIdentifier
)
157 VisitNode(parameterIdentifier
.TypeReference
);
158 VisitNode(parameterIdentifier
.InitExpression
);
161 public virtual void VisitOpaqueIdentifier(OpaqueIdentifier opaqueIdentifier
)
163 VisitNode(opaqueIdentifier
.TypeReference
);
171 public virtual void VisitExpressionStatement(ExpressionStatement statement
)
173 VisitNode(statement
.InnerExpression
);
180 public virtual void VisitMethodInvocationExpression(MethodInvocationExpression invocationExpression
)
182 VisitNode(invocationExpression
.Designator
);
183 VisitNodes(invocationExpression
.Arguments
);
184 VisitCommonExpNodes(invocationExpression
);
187 public virtual void VisitVariableReferenceExpression(VariableReferenceExpression expression
)
189 VisitNode(expression
.Identifier
);
190 VisitCommonExpNodes(expression
);
193 public virtual void VisitConstExpression(ConstExpression expression
)
195 VisitCommonExpNodes(expression
);
198 public virtual void VisitBlockExpression(BlockExpression expression
)
200 VisitNodes(expression
.Parameters
);
201 VisitNodes(expression
.Statements
);
202 VisitCommonExpNodes(expression
);
205 public virtual void VisitMemberAccessExpression(MemberAccessExpression accessExpression
)
207 VisitNode(accessExpression
.Inner
);
208 VisitCommonExpNodes(accessExpression
);
215 private void VisitCommonExpNodes(IExpression expression
)
217 VisitNode(expression
.PostfixCondition
);
218 VisitNode(expression
.Block
);