BOO-988: Added else block to the for and while statements, and include a suite of...
[boo.git] / src / Boo.Lang.Compiler / CompilerContext.cs
bloba8b23491ee931176d22d52761f5fd5081ca72567
1 #region license
2 // Copyright (c) 2004, Rodrigo B. de Oliveira (rbo@acm.org)
3 // All rights reserved.
4 //
5 // Redistribution and use in source and binary forms, with or without modification,
6 // are permitted provided that the following conditions are met:
7 //
8 // * Redistributions of source code must retain the above copyright notice,
9 // this list of conditions and the following disclaimer.
10 // * Redistributions in binary form must reproduce the above copyright notice,
11 // this list of conditions and the following disclaimer in the documentation
12 // and/or other materials provided with the distribution.
13 // * Neither the name of Rodrigo B. de Oliveira nor the names of its
14 // contributors may be used to endorse or promote products derived from this
15 // software without specific prior written permission.
16 //
17 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
18 // ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19 // WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20 // DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
21 // FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 // DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
23 // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
24 // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
25 // OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 // THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 #endregion
29 using System;
30 using System.Diagnostics;
31 using Boo.Lang;
32 using Boo.Lang.Compiler.Ast;
33 using Assembly = System.Reflection.Assembly;
35 namespace Boo.Lang.Compiler
37 /// <summary>
38 /// boo compilation context.
39 /// </summary>
40 public class CompilerContext
42 protected CompilerParameters _parameters;
44 protected CompileUnit _unit;
46 protected AssemblyCollection _assemblyReferences;
48 protected CompilerErrorCollection _errors;
50 protected CompilerWarningCollection _warnings;
52 protected TypeSystem.TypeSystemServices _typeSystemServices;
54 protected readonly TypeSystem.NameResolutionService _nameResolutionService;
56 protected TraceSwitch _traceSwitch;
58 protected int _localIndex;
60 protected Assembly _generatedAssembly;
62 protected string _generatedAssemblyFileName;
64 protected Hash _properties;
66 public CompilerContext() : this(new CompileUnit())
70 public CompilerContext(CompileUnit unit) : this(new CompilerParameters(), unit)
74 public CompilerContext(bool stdlib) : this(new CompilerParameters(stdlib), new CompileUnit())
78 public CompilerContext(CompilerParameters options, CompileUnit unit)
80 if (null == options) throw new ArgumentNullException("options");
81 if (null == unit) throw new ArgumentNullException("unit");
83 _unit = unit;
84 _errors = new CompilerErrorCollection();
85 _warnings = new CompilerWarningCollection();
86 _assemblyReferences = options.References;
87 _parameters = options;
88 if (_parameters.Debug && !_parameters.Defines.ContainsKey("DEBUG"))
89 _parameters.Defines.Add("DEBUG", null);
90 _nameResolutionService = new TypeSystem.NameResolutionService(this);
91 _traceSwitch = _parameters.TraceSwitch;
92 _properties = new Hash();
95 public Hash Properties
97 get { return _properties; }
100 public string GeneratedAssemblyFileName
102 get { return _generatedAssemblyFileName; }
106 if (null == value || 0 == value.Length)
108 throw new ArgumentException("GeneratedAssemblyFileName");
110 _generatedAssemblyFileName = value;
114 public object this[object key]
116 get { return _properties[key]; }
118 set { _properties[key] = value; }
121 public CompilerParameters Parameters
123 get { return _parameters; }
126 public AssemblyCollection References
128 get { return _assemblyReferences; }
131 public CompilerErrorCollection Errors
133 get { return _errors; }
136 public CompilerWarningCollection Warnings
138 get { return _warnings; }
141 public CompileUnit CompileUnit
143 get { return _unit; }
146 public TypeSystem.TypeSystemServices TypeSystemServices
148 get { return _typeSystemServices; }
152 if (null == value) throw new ArgumentNullException("TypeSystemServices");
153 _typeSystemServices = value;
157 public TypeSystem.BooCodeBuilder CodeBuilder
159 get { return _typeSystemServices.CodeBuilder; }
162 public TypeSystem.NameResolutionService NameResolutionService
164 get { return _nameResolutionService; }
167 public Assembly GeneratedAssembly
169 get { return _generatedAssembly; }
171 set { _generatedAssembly = value; }
174 public int AllocIndex()
176 return ++_localIndex;
179 [Conditional("TRACE")]
180 public void TraceEnter(string format, object param)
182 if (_traceSwitch.TraceInfo)
184 Trace.WriteLine(string.Format(format, param));
185 ++Trace.IndentLevel;
189 [Conditional("TRACE")]
190 public void TraceLeave(string format, object param)
192 if (_traceSwitch.TraceInfo)
194 --Trace.IndentLevel;
195 Trace.WriteLine(string.Format(format, param));
199 [Conditional("TRACE")]
200 public void TraceInfo(string format, params object[] args)
202 if (_traceSwitch.TraceInfo)
204 Trace.WriteLine(string.Format(format, args));
208 [Conditional("TRACE")]
209 public void TraceInfo(string message)
211 if (_traceSwitch.TraceInfo)
213 Trace.WriteLine(message);
217 [Conditional("TRACE")]
218 public void TraceWarning(string message)
220 if (_traceSwitch.TraceWarning)
222 Trace.WriteLine(message);
226 [Conditional("TRACE")]
227 public void TraceWarning(string message, params object[] args)
229 if (_traceSwitch.TraceWarning)
231 Trace.WriteLine(string.Format(message, args));
235 [Conditional("TRACE")]
236 public void TraceVerbose(string format, params object[] args)
238 if (_traceSwitch.TraceVerbose)
240 Trace.WriteLine(string.Format(format, args));
244 [Conditional("TRACE")]
245 public void TraceVerbose(string format, object param1, object param2)
247 if (_traceSwitch.TraceVerbose)
249 Trace.WriteLine(string.Format(format, param1, param2));
253 [Conditional("TRACE")]
254 public void TraceVerbose(string format, object param1, object param2, object param3)
256 if (_traceSwitch.TraceVerbose)
258 Trace.WriteLine(string.Format(format, param1, param2, param3));
262 [Conditional("TRACE")]
263 public void TraceVerbose(string format, object param)
265 if (_traceSwitch.TraceVerbose)
267 Trace.WriteLine(string.Format(format, param));
271 [Conditional("TRACE")]
272 public void TraceVerbose(string message)
274 if (_traceSwitch.TraceVerbose)
276 Trace.WriteLine(message);
280 [Conditional("TRACE")]
281 public void TraceError(string message, params object[] args)
283 if (_traceSwitch.TraceError)
285 Trace.WriteLine(string.Format(message, args));
289 [Conditional("TRACE")]
290 public void TraceError(Exception x)
292 if (_traceSwitch.TraceError)
294 Trace.WriteLine(x);