Fixing an issue with output parameters that are of type IntPtr
[castle.git] / Experiments / Attic / Rook / Castle.Rook.Compiler / Visitors / BreadthFirstVisitor.cs
blob46f06f4261db70f5911621b60b16edf07d40d6d1
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 class BreadthFirstVisitor : AbstractVisitor
25 private bool nowQueue = false;
26 private Queue nodesToBeVisited = new Queue();
28 public override bool VisitNode(IVisitableNode node)
30 if (nowQueue)
32 EnqueueNode(node);
33 return true;
35 else
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();
54 return true;
57 public override bool VisitEnter(NamespaceDescriptor ns)
59 nowQueue = true;
60 return base.VisitEnter(ns);
63 public override bool VisitLeave(NamespaceDescriptor ns)
65 nowQueue = false;
66 return base.VisitLeave(ns);
69 public override bool VisitEnter(TypeDefinitionStatement typeDef)
71 nowQueue = true;
72 return base.VisitEnter(typeDef);
75 public override bool VisitLeave(TypeDefinitionStatement typeDef)
77 nowQueue = false;
78 return base.VisitLeave(typeDef);
81 public override bool VisitEnter(MethodDefinitionStatement methodDef)
83 nowQueue = true;
84 return base.VisitEnter(methodDef);
87 public override bool VisitLeave(MethodDefinitionStatement methodDef)
89 nowQueue = false;
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);