1 // Copyright 2004-2007 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 class BreadthFirstVisitor
: AbstractVisitor
25 private bool nowQueue
= false;
26 private Queue nodesToBeVisited
= new Queue();
28 public override bool VisitNode(IVisitableNode node
)
37 return base.VisitNode(node
);
41 public override void VisitCompilationUnit(CompilationUnit compilationUnit
)
43 base.VisitCompilationUnit(compilationUnit
);
45 ProcessNodesInQueue();
48 public override bool VisitSourceUnit(SourceUnit unit
)
50 base.VisitSourceUnit(unit
);
52 ProcessNodesInQueue();
57 public override bool VisitEnter(NamespaceDescriptor ns
)
60 return base.VisitEnter(ns
);
63 public override bool VisitLeave(NamespaceDescriptor ns
)
66 return base.VisitLeave(ns
);
69 public override bool VisitEnter(TypeDefinitionStatement typeDef
)
72 return base.VisitEnter(typeDef
);
75 public override bool VisitLeave(TypeDefinitionStatement typeDef
)
78 return base.VisitLeave(typeDef
);
81 public override bool VisitEnter(MethodDefinitionStatement methodDef
)
84 return base.VisitEnter(methodDef
);
87 public override bool VisitLeave(MethodDefinitionStatement methodDef
)
90 return base.VisitLeave(methodDef
);
93 private void EnqueueNode(IVisitableNode node
)
95 nodesToBeVisited
.Enqueue(node
);
98 private void ProcessNodesInQueue()
100 while(nodesToBeVisited
.Count
!= 0)
102 VisitNode(nodesToBeVisited
.Dequeue() as IVisitableNode
);