boolangstudio /Dependencies/boo/src/booc/App.cs

Language C# Lines 902
MD5 Hash 2a8b05dd4765b3a2d5019c3c4d13d027 Estimated Cost $20,813 (why?)
Repository https://github.com/w4x/boolangstudio.git View Raw File View Project SPDX
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
#region license
// Copyright (c) 2004, Rodrigo B. de Oliveira (rbo@acm.org)
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without modification,
// are permitted provided that the following conditions are met:
//
//     * Redistributions of source code must retain the above copyright notice,
//     this list of conditions and the following disclaimer.
//     * Redistributions in binary form must reproduce the above copyright notice,
//     this list of conditions and the following disclaimer in the documentation
//     and/or other materials provided with the distribution.
//     * Neither the name of Rodrigo B. de Oliveira nor the names of its
//     contributors may be used to endorse or promote products derived from this
//     software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
// ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
// THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#endregion

using System;
using System.Text;
using System.Collections;
using System.Diagnostics;
using System.IO;
using System.Globalization;
using System.Threading;
using Boo.Lang.Compiler.Ast.Visitors;
using Assembly = System.Reflection.Assembly;
using Boo.Lang.Compiler;
using Boo.Lang.Compiler.IO;
using Boo.Lang.Compiler.Pipelines;
using Boo.Lang.Compiler.Resources;
using Boo.Lang;

namespace BooC
{
	/// <summary>
	///
	/// </summary>
	class App
	{
		ArrayList _responseFileList = new ArrayList();
		CompilerParameters _options = null;
		
		ArrayList _references = new ArrayList();
		ArrayList _packages = new ArrayList();
		bool _noConfig = false;
		string _pipelineName = null;
		bool _debugSteps = false;
		bool _whiteSpaceAgnostic = false;
		
		/// <summary>
		/// The main entry point for the application.
		/// </summary>
		[STAThread]
		static int Main(string[] args)
		{
			if (((IList)args).Contains("-utf8"))
			{
				using (StreamWriter writer = new StreamWriter(Console.OpenStandardError(), Encoding.UTF8))
				{
					// leave the byte order mark in its own line and out
					writer.WriteLine();
					
					Console.SetError(writer);
					return new App().Run(args);
				}
			}
			else
			{
				return new App().Run(args);
			}
		}
		
		public int Run(string[] args)
		{
			int resultCode = -1;
			
			AppDomain.CurrentDomain.AssemblyResolve += new ResolveEventHandler(AssemblyResolve);
			
			CheckBooCompiler();
			
			try
			{
				DateTime start = DateTime.Now;
				
				_options = new CompilerParameters(false); //false means no stdlib loading yet
				_options.GenerateInMemory = false;
				
				ArrayList tempLibPaths = _options.LibPaths.Clone() as ArrayList;
				_options.LibPaths.Clear();
				
				BooCompiler compiler = new BooCompiler(_options);
				
				ParseOptions(args);
				
				if (0 == _options.Input.Count)
				{
					throw new ApplicationException(Boo.Lang.ResourceManager.GetString("BooC.NoInputSpecified"));
				}
				
				//move standard libpaths below any new ones:
				foreach(object o in tempLibPaths)
					_options.LibPaths.Add(o);
				
				if (_options.StdLib)
				{
					_options.LoadDefaultReferences();
				}
				else if (!_noConfig)
				{
					_references.Insert(0, "mscorlib");
				}
				
				LoadReferences();
				ConfigurePipeline();
				
				if (_options.TraceSwitch.TraceInfo)
				{
					compiler.Parameters.Pipeline.BeforeStep += new CompilerStepEventHandler(OnBeforeStep);
					compiler.Parameters.Pipeline.AfterStep += new CompilerStepEventHandler(OnAfterStep);
				}
				
				TimeSpan setupTime = DateTime.Now - start;
				
				start = DateTime.Now;
				CompilerContext context = compiler.Run();
				TimeSpan processingTime = DateTime.Now - start;

				if (context.Warnings.Count > 0)
				{
					Console.Error.WriteLine(context.Warnings);
					Console.Error.WriteLine(Boo.Lang.ResourceManager.Format("BooC.Warnings", context.Warnings.Count));
				}
				
				if (context.Errors.Count > 0)
				{
					foreach (CompilerError error in context.Errors)
					{
						Console.Error.WriteLine(error.ToString(_options.TraceSwitch.TraceInfo));
					}
					Console.Error.WriteLine(Boo.Lang.ResourceManager.Format("BooC.Errors", context.Errors.Count));
				}
				else
				{
					resultCode = 0;
				}
				
				if (_options.TraceSwitch.TraceWarning)
				{
					Console.Error.WriteLine(Boo.Lang.ResourceManager.Format("BooC.ProcessingTime", _options.Input.Count, processingTime.TotalMilliseconds, setupTime.TotalMilliseconds));
				}
			}
			catch (Exception x)
			{
				object message = _options.TraceSwitch.TraceWarning ? (object)x : (object)x.Message;
				Console.Error.WriteLine(Boo.Lang.ResourceManager.Format("BooC.FatalError", message));
			}
			return resultCode;
		}
		
		void LoadReferences()
		{
			foreach (string r in _references)
			{
				_options.References.Add(_options.LoadAssembly(r, true));
			}
			foreach (string p in _packages)
			{
				_options.LoadReferencesFromPackage(p);
			}
		}
		
		void CheckBooCompiler()
		{
			string path = Path.Combine(Path.GetDirectoryName(
						Assembly.GetExecutingAssembly().Location),
					"Boo.Lang.Compiler.dll");
			if (File.Exists(path))
			{
				foreach (Assembly a in AppDomain.CurrentDomain.GetAssemblies())
				{
					if (a.FullName.StartsWith("Boo.Lang.Compiler"))
					{
						if (string.Compare(a.Location, path, true) != 0)
						{
							//can't use ResourceManager, boo.lang.dll may be out of date
							string msg=string.Format("WARNING: booc is not using the Boo.Lang.Compiler.dll next to booc.exe.  Using '{0}' instead of '{1}'.  You may need to remove boo dlls from the GAC using gacutil or Mscorcfg.",
									a.Location, path);
							//has to be all 1 line for things like msbuild that parse booc output.
							Console.Error.WriteLine(msg);
						}
						break;
					}
				}
			}
		}
		
		string Consume(TextReader reader)
		{
			StringWriter writer = new StringWriter();
			string line = reader.ReadLine();
			while (null != line)
			{
				writer.WriteLine(line);
				line = reader.ReadLine();
			}
			return writer.ToString();
		}
		
		void DoLogo()
		{
			Console.Write("Boo Compiler version "+Builtins.BooVersion.ToString());
			Console.WriteLine(" (CLR v"+Environment.Version.ToString()+")");
		}
		
		void Help ()
		{
			Console.WriteLine(
					"Usage is: booc [options] file1 ...\n" +
					"Options:\n" +
					" -c:CULTURE           Sets the UI culture to be CULTURE\n" +
					" -debug[+|-]          Generate debugging information (default: +)\n" +
					" -define:S1[,Sn]      Defines symbols S1..Sn with optional values (=val) (-d:)\n" +
					" -delaysign           Delays assembly signing\n" +
					" -ducky               Turns on duck typing by default\n" +
					" -checked[+|-]        Turns on or off checked operations (default: +)\n" +
					" -embedres:FILE[,ID]  Embeds FILE with the optional ID\n"+
					" -lib:DIRS            Adds the comma-separated DIRS to the assembly search path\n" +
					" -noconfig            Does not load the standard configuration\n" +
					" -nostdlib            Does not reference any of the default libraries\n" +
					" -nologo              Does not display the compiler logo\n" +
					" -p:PIPELINE          Sets the pipeline to PIPELINE\n" +
					" -o:FILE              Sets the output file name to FILE\n" +
					" -keyfile:FILE        The strongname key file used to strongname the assembly\n" +
					" -keycontainer:NAME   The key pair container used to strongname the assembly\n" +
					" -reference:ASS       References the specified assembly (-r:ASS)\n" +
					" -srcdir:DIR          Adds DIR as a directory where sources can be found\n" +
					" -target:TYPE         Sets the target type (exe, library or winexe)\n" +
					" -resource:FILE[,ID]  Embeds FILE as a resource\n" +
					" -pkg:P1[,Pn]         References packages P1..Pn (on supported platforms)\n" +
					" -utf8                Source file(s) are in utf8 format\n" +
					" -v, -vv, -vvv        Sets verbosity level from warnings to very detailed\n" +
					" -wsa                 Enables white-space-agnostic build\n"
					);
		}

		
		void ParseOptions(string[] args)
		{
			bool noLogo = false;		
			
			ArrayList arglist = new ArrayList(args);
			ExpandResponseFiles(ref arglist);
			AddDefaultResponseFile(ref arglist);
			foreach (string arg in arglist)
			{
				if ("-" == arg)
				{
					_options.Input.Add(new StringInput("<stdin>", Consume(Console.In)));
					continue;
				}
				if (!IsFlag(arg))
				{
					_options.Input.Add(new FileInput(StripQuotes(arg)));
					continue;
				}
				if ("-utf8" == arg) continue;
				
				switch (arg[1])
				{
					case 'h':
					{
						if (arg == "-help" || arg == "-h")
						{
							Help();
						}
						break;
					}
					
					case 'w':
					{
						if (arg == "-wsa")
						{
							_options.WhiteSpaceAgnostic = _whiteSpaceAgnostic = true;
						}
						else
						{
							InvalidOption(arg);
						}
						break;
					}
					
					case 'v':
					{
						_options.TraceSwitch.Level = TraceLevel.Warning;
						Trace.Listeners.Add(new TextWriterTraceListener(Console.Error));
						if (arg.Length > 2)
						{
							switch (arg.Substring(1))
							{
								case "vv":
								{
									_options.TraceSwitch.Level = TraceLevel.Info;
									MonitorAppDomain();
									break;
								}
								
								case "vvv":
								{
									_options.TraceSwitch.Level = TraceLevel.Verbose;
									break;
								}
							}
						}
						else
						{
							_options.TraceSwitch.Level = TraceLevel.Warning;
						}
						break;
					}

					case 'r':
					{
						if (arg.IndexOf(":") > 2 && arg.Substring(1, 9) != "reference")
						{
							switch (arg.Substring(1, 8))
							{
								case "resource":
								{	
									int start = arg.IndexOf(":") + 1;
									AddResource(StripQuotes(arg.Substring(start)));
									break;
								}

								default:
								{
									InvalidOption(arg);
									break;
								}
							}
						}
						else
						{
							string assemblyName = StripQuotes(arg.Substring(arg.IndexOf(":")+1));
							_references.Add(assemblyName);
						}
						break;
					}
					
					case 'l':
					{
						switch (arg.Substring(1, 3))
						{
							case "lib":
							{
								string paths = arg.Substring(arg.IndexOf(":")+1);
								if (paths == "")
								{
									Console.Error.WriteLine(Boo.Lang.ResourceManager.Format("BooC.BadLibPath", arg));
									break;
								}
								
								foreach(string dir in paths.Split(new Char[] {','}))
								{
									if (Directory.Exists(dir))
									{
										_options.LibPaths.Add(dir);
									}
									else
									{
										Console.Error.WriteLine(Boo.Lang.ResourceManager.Format("BooC.BadLibPath", dir));
									}
								}
								break;
							}

							default:
							{
								InvalidOption(arg);
								break;
							}
						}
						break;
					}
					
					case 'n':
					{
						if (arg == "-nologo")
						{
							noLogo = true;
						}
						else if (arg == "-noconfig")
						{
							_noConfig = true;
						}
						else if (arg == "-nostdlib")
						{
							_options.StdLib = false;
						}
						else
						{
							InvalidOption(arg);
						}
						break;
					}
					
					case 'o':
					{
						_options.OutputAssembly = StripQuotes(arg.Substring(arg.IndexOf(":")+1));
						break;
					}
					
					case 't':
					{
						string targetType = arg.Substring(arg.IndexOf(":")+1);
						switch (targetType)
						{
							case "library":
							{
								_options.OutputType = CompilerOutputType.Library;
								break;
							}
							
							case "exe":
							{
								_options.OutputType = CompilerOutputType.ConsoleApplication;
								break;
							}
							
							case "winexe":
							{
								_options.OutputType = CompilerOutputType.WindowsApplication;
								break;
							}
							
							default:
							{
								InvalidOption(arg);
								break;
							}
						}
						break;
					}

					case 'p':
					{
						if (arg.StartsWith("-pkg:"))
						{
							string packages = StripQuotes(arg.Substring(arg.IndexOf(":")+1));
							_packages.Add(packages);
						}
						else { 
							_pipelineName = StripQuotes(arg.Substring(3));
						}
						break;
					}

					case 'c':
					{
						switch (arg.Substring(1))
						{
							case "checked":
							case "checked+":
							{
								_options.Checked = true;
								break;
							}
							
							case "checked-":
							{
								_options.Checked = false;
								break;
							}
							
							default:
							{							
								string culture = arg.Substring(3);
								Thread.CurrentThread.CurrentUICulture = CultureInfo.CreateSpecificCulture(culture);
								break;
							}
						}
						break;					
					}

					case 's':
					{
						switch (arg.Substring(1, 6))
						{
							case "srcdir":
							{
								string path = StripQuotes(arg.Substring(8));
								AddFilesForPath(path, _options);
								break;
							}

							default:
							{
								InvalidOption(arg);
								break;
							}
						}
						break;
					}
					
					case 'k':
					{
						if (arg.Substring(1, 7) == "keyfile")
						{
							_options.KeyFile = StripQuotes(arg.Substring(9));
						}
						else if (arg.Substring(1, 12) == "keycontainer")
						{
							_options.KeyContainer = StripQuotes(arg.Substring(14));
						}	
						else
						{
							InvalidOption(arg);
						}
						break;
					}
					
					case 'd':
					{
						switch (arg.Substring(1))
						{
							case "debug":
							case "debug+":
							{
								_options.Debug = true;
								break;
							}
							
							case "debug-":
							{
								_options.Debug = false;
								break;
							}
							
							case "ducky":
							{
								_options.Ducky = true;
								break;
							}

							case "debug-steps":
							{
								_debugSteps = true;
								break;
							}
							
							case "delaysign":
							{
								_options.DelaySign = true;
								break;
							}
							
							default:
							{
								if (arg.StartsWith("-d:") || arg.StartsWith("-define:"))
								{
									int skip = arg.StartsWith("-d:") ? 3 : 8;
									string[] symbols = StripQuotes(arg.Substring(skip)).Split(",".ToCharArray());
									foreach (string symbol in symbols)
									{
										string[] s_v = symbol.Split("=".ToCharArray(), 2);
										if (s_v[0].Length < 1) continue;
										if (_options.Defines.ContainsKey(s_v[0]))
										{
											_options.Defines[s_v[0]] = (s_v.Length > 1) ? s_v[1] : null;
											Trace.WriteLine("REPLACED DEFINE '"+s_v[0]+"' WITH VALUE '"+((s_v.Length > 1) ? s_v[1] : string.Empty) +"'");
										}
										else
										{
											_options.Defines.Add(s_v[0], (s_v.Length > 1) ? s_v[1] : null);
											Trace.WriteLine("ADDED DEFINE '"+s_v[0]+"' WITH VALUE '"+((s_v.Length > 1) ? s_v[1] : string.Empty) +"'");
										}
									}
								}
								else
								{							
									InvalidOption(arg);
								}
								break;
							}
						}
						break;
					}
					
					case 'e':
					{
						switch (arg.Substring(1,8))
						{
							case "embedres":
							{
								if (!IsMono)
								{
									throw new ApplicationException("-embedres is only supported on mono. Try -resource.");
								}
								int start = arg.IndexOf(":") + 1;
								EmbedResource(StripQuotes(arg.Substring(start)));
								break;
							}

							default:
							{
								InvalidOption(arg);
								break;
							}
						}
						break;
					}
					
					default:
					{
						if (arg == "--help")
						{
							Help();
						}
						else
						{
							InvalidOption(arg);
						}
						break;
					}
				}
			}
			
			if (!noLogo)
			{
				DoLogo();
			}
		}

		private bool IsMono
		{
			get { return Type.GetType("System.MonoType", false) != null;  }
		}

		private void EmbedResource(string resourceFile)
		{

			int comma = resourceFile.LastIndexOf(',');
			if (comma >= 0)
			{
				string resourceName = resourceFile.Substring(comma+1);
				resourceFile = resourceFile.Substring(0, comma);
				_options.Resources.Add(new NamedEmbeddedFileResource(resourceFile, resourceName));
			}
			else
			{
				_options.Resources.Add(new EmbeddedFileResource(resourceFile));
			}
		}

		private void AddResource(string resourceFile)
		{
			int comma = resourceFile.LastIndexOf(',');
			if (comma >= 0)
			{
				string resourceName = resourceFile.Substring(comma+1);
				resourceFile = resourceFile.Substring(0, comma);
				_options.Resources.Add(new NamedFileResource(resourceFile, resourceName));
			}
			else
			{
				_options.Resources.Add(new FileResource(resourceFile));
			}
		}

		private void ConfigurePipeline()
		{
			if (null != _pipelineName)
			{
				_options.Pipeline = CompilerPipeline.GetPipeline(_pipelineName);
			}
			else
			{
				_options.Pipeline = new CompileToFile();
			}			
			if (_whiteSpaceAgnostic)
			{
				_options.Pipeline[0] = new Boo.Lang.Parser.WSABooParsingStep();
			}
			if (_debugSteps)
			{
				_options.Pipeline.AfterStep += new CompilerStepEventHandler(new StepDebugger().AfterStep);
			}
		}
		
		private string StripQuotes(string s)
		{
			if (s.Length > 1 && s.StartsWith("\"") && s.EndsWith("\""))
			{
				return s.Substring(1,s.Length-2);
			}
			return s;
		}
		
		private class StepDebugger
		{
			string _last;
			
			public void AfterStep(object sender, CompilerStepEventArgs args)
			{
				Console.WriteLine("********* {0} *********", args.Step);
				
				StringWriter writer = new StringWriter();				
				args.Context.CompileUnit.Accept(new BooPrinterVisitor(writer, BooPrinterVisitor.PrintOptions.PrintLocals));
				string code = writer.ToString();
				if (code != _last)
				{
					Console.WriteLine(code);
				}
				else
				{
					Console.WriteLine("no changes");
				}
				_last = code;
			}
		}

		ArrayList LoadResponseFile(string file)
		{
			file = Path.GetFullPath(file);
			if (_responseFileList.Contains(file))
			{
				throw new ApplicationException(
						Boo.Lang.ResourceManager.Format("BCE0500", file));
			}
			_responseFileList.Add(file);
			if (!File.Exists(file))
			{
				throw new ApplicationException(Boo.Lang.ResourceManager.Format("BCE0501", file));
			}
			ArrayList arglist = new ArrayList();
			try
			{
				using (StreamReader sr = new StreamReader(file))
				{
					string line;
					while ((line = sr.ReadLine()) != null)
					{
						line = line.Trim();
						if (line.Length > 0 && line[0] != '#')
						{
							if (line.StartsWith("@") && line.Length > 2)
							{
								arglist.AddRange(LoadResponseFile(line.Substring(1)));
							}
							else
							{
								arglist.Add(line);
							}
						}
					}
				}
			}
			catch (ApplicationException)
			{
				throw;
			}
			catch (Exception x)
			{
				throw new ApplicationException(
								Boo.Lang.ResourceManager.Format("BCE0502", file),
								x);
			}
			return	arglist;
		}
		
		void ExpandResponseFiles(ref ArrayList arglist)
		{
			ArrayList result = new ArrayList();
			foreach (string arg in arglist)
			{
				if (arg.StartsWith("@") && arg.Length > 2)
				{
					result.AddRange(LoadResponseFile(arg.Substring(1)));
				}
				else
				{
					result.Add(arg);
				}
			}
			arglist = result;
		}

		void AddDefaultResponseFile(ref ArrayList arglist)
		{
			ArrayList result = new ArrayList();
			foreach (string arg in arglist)
			{
				if (arg == "-noconfig")
				{
					_noConfig = true;
				}
				else
				{
					result.Add(arg);
				}
			}
			if (!_noConfig)
			{
				string file = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "booc.rsp");
				if (File.Exists(file))
				{
					result.InsertRange(0, LoadResponseFile(file));
				}
			}
			arglist = result;
		}
		
		void OnBeforeStep(object sender, CompilerStepEventArgs args)
		{
			args.Context.TraceEnter("Entering {0}", args.Step);
		}
		
		void OnAfterStep(object sender, CompilerStepEventArgs args)
		{
			args.Context.TraceLeave("Leaving {0}", args.Step);
		}
		
		void InvalidOption(string arg)
		{
			Console.Error.WriteLine(Boo.Lang.ResourceManager.Format("BooC.InvalidOption", arg));
		}

		bool IsFlag(string arg)
		{
			return arg[0] == '-';
		}

		void AddFilesForPath(string path, CompilerParameters _options)
		{
			foreach (string fname in Directory.GetFiles(path, "*.boo"))
			{
				if (!fname.EndsWith(".boo")) continue;
				_options.Input.Add(new FileInput(Path.GetFullPath(fname)));
			}
								
			foreach (string dirName in Directory.GetDirectories(path))
			{
				AddFilesForPath(dirName, _options);
			}
		}
		
		void MonitorAppDomain()
		{
			if (_options.TraceSwitch.TraceInfo)
			{
				AppDomain.CurrentDomain.AssemblyLoad += new AssemblyLoadEventHandler(OnAssemblyLoad);
				foreach(Assembly a in AppDomain.CurrentDomain.GetAssemblies())
				{
					Trace.WriteLine("ASSEMBLY AT STARTUP: "+GetAssemblyLocation(a));
				}
			}
		}
		
		static void OnAssemblyLoad(object sender, AssemblyLoadEventArgs args)
		{
			Trace.WriteLine("ASSEMBLY LOADED: " + GetAssemblyLocation(args.LoadedAssembly));
		}
		
		static string GetAssemblyLocation(Assembly a)
		{
			string loc;
			try
			{
				loc = a.Location;
			}
			catch (Exception)
			{
				loc = "<dynamic>"+a.FullName;
			}
			return loc;
		}
		
		static Assembly AssemblyResolve(object sender, ResolveEventArgs args)
		{
			string simpleName = args.Name.Split(',')[0];
			string fileName = Path.Combine(Environment.CurrentDirectory, 
							simpleName + ".dll");
			if (File.Exists(fileName))
			{
				return Assembly.LoadFile(fileName);
			}
			return null;
		}
		
	}
}
Back to Top