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
.DynamicProxy
.Builder
.CodeBuilder
18 using System
.Reflection
;
19 using System
.Reflection
.Emit
;
20 using System
.Collections
;
22 using Castle
.DynamicProxy
.Builder
.CodeBuilder
.SimpleAST
;
25 /// Summary description for AbstractCodeBuilder.
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
;
44 protected ILGenerator Generator
46 get { return _generator; }
49 public void AddStatement( Statement stmt
)
55 public LocalReference
DeclareLocal( Type type
)
57 LocalReference local
= new LocalReference(type
);
58 _ilmarkers
.Add( local
);
62 public LabelReference
CreateLabel()
64 LabelReference label
= new LabelReference();
65 _ilmarkers
.Add(label
);
69 protected internal void SetNonEmpty()
76 get { return _isEmpty; }
79 internal void Generate( IEasyMember member
, ILGenerator il
)
81 foreach(Reference local
in _ilmarkers
)
86 foreach(Statement stmt
in _stmts
)
88 stmt
.Emit(member
, il
);