Simple impl to MockRailsEngineContext.Url
[castle.git] / Tools / DynamicProxy / Castle.DynamicProxy / Builder / CodeBuilder / AbstractCodeBuilder.cs
blob594053d4a37b9bf0588993b6f2c0b7fe98a3752a
1 // Copyright 2004-2007 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.DynamicProxy.Builder.CodeBuilder
17 using System;
18 using System.Reflection;
19 using System.Reflection.Emit;
20 using System.Collections;
22 using Castle.DynamicProxy.Builder.CodeBuilder.SimpleAST;
24 /// <summary>
25 /// Summary description for AbstractCodeBuilder.
26 /// </summary>
27 [CLSCompliant(false)]
28 public abstract class AbstractCodeBuilder
30 private ILGenerator _generator;
31 private bool _isEmpty;
32 private ArrayList _stmts;
33 private ArrayList _ilmarkers;
35 protected AbstractCodeBuilder( ILGenerator generator )
37 _stmts = new ArrayList();
38 _ilmarkers = new ArrayList();
40 _generator = generator;
41 _isEmpty = true;
44 protected ILGenerator Generator
46 get { return _generator; }
49 public void AddStatement( Statement stmt )
51 SetNonEmpty();
52 _stmts.Add( stmt );
55 public LocalReference DeclareLocal( Type type )
57 LocalReference local = new LocalReference(type);
58 _ilmarkers.Add( local );
59 return local;
62 public LabelReference CreateLabel()
64 LabelReference label = new LabelReference();
65 _ilmarkers.Add(label);
66 return label;
69 protected internal void SetNonEmpty()
71 _isEmpty = false;
74 internal bool IsEmpty
76 get { return _isEmpty; }
79 internal void Generate( IEasyMember member, ILGenerator il )
81 foreach(Reference local in _ilmarkers)
83 local.Generate(il);
86 foreach(Statement stmt in _stmts)
88 stmt.Emit(member, il);