Applied patch from Jan Limpens 'ReflectionBasedDictionaryAdapter needs to check if...
[castle.git] / Experiments / Attic / Rook / Castle.Rook.Compiler / Visitors / AbstractVisitor.cs
blob590d63173cdd4e9f3f350a7b7a27957034ebbab7
1 // Copyright 2004-2008 Castle Project - http://www.castleproject.org/
2 //
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
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
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
17 using System;
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);
35 return res;
38 public virtual bool VisitNodes(IList nodes)
40 foreach(IVisitableNode node in nodes)
42 VisitNode( node );
45 return true;
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);
59 return true;
62 public virtual bool VisitNamespace(NamespaceDescriptor ns)
64 if (VisitEnter(ns))
66 VisitNodes(ns.TypeDefinitions);
68 return VisitLeave(ns);
71 return true;
74 public virtual bool VisitEnter(NamespaceDescriptor ns)
76 return true;
79 public virtual bool VisitLeave(NamespaceDescriptor ns)
81 return true;
84 public virtual bool VisitTypeDefinitionStatement(TypeDefinitionStatement typeDef)
86 if (VisitEnter(typeDef))
88 VisitNodes(typeDef.Statements);
90 return VisitLeave(typeDef);
93 return false;
96 public virtual bool VisitEnter(TypeDefinitionStatement typeDef)
98 return true;
101 public virtual bool VisitLeave(TypeDefinitionStatement typeDef)
103 return true;
106 public virtual bool VisitMethodDefinitionStatement(MethodDefinitionStatement methodDef)
108 if (VisitEnter(methodDef))
110 VisitNodes(methodDef.Arguments);
111 VisitNodes(methodDef.Statements);
113 return VisitLeave(methodDef);
116 return false;
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)
132 return true;
135 public virtual bool VisitLeave(MethodDefinitionStatement methodDef)
137 return true;
141 // References
144 public virtual void VisitTypeReference(TypeReference reference)
148 public virtual bool VisitIdentifier(Identifier identifier)
150 VisitNode(identifier.TypeReference);
152 return true;
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);
168 // Statements
171 public virtual void VisitExpressionStatement(ExpressionStatement statement)
173 VisitNode(statement.InnerExpression);
177 // Expressions
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);
212 // Helpers
215 private void VisitCommonExpNodes(IExpression expression)
217 VisitNode(expression.PostfixCondition);
218 VisitNode(expression.Block);