示例#1
0
		private CommandLineParser(IEnumerable<string> args, CompilerParameters options)
		{
			_options = options;
			_options.GenerateInMemory = false;

			var tempLibPaths = _options.LibPaths.ToArray();
			_options.LibPaths.Clear();

			Parse(args);

			//move standard libpaths below any new ones:
			_options.LibPaths.Extend(tempLibPaths);

			if (_options.StdLib)
				_options.LoadDefaultReferences();
			else if (!_noConfig)
				_references.Insert(0, "mscorlib");

			LoadReferences();
			ConfigurePipeline();

			if (_options.TraceInfo)
			{
				_options.Pipeline.BeforeStep += OnBeforeStep;
				_options.Pipeline.AfterStep += OnAfterStep;
			}

		}
示例#2
0
		public void LibValueCanBeWrappedInDoubleQuotes()
		{
			var libPath = Path.GetTempPath();
			var compilerParameters = new CompilerParameters();
			CommandLineParser.ParseInto(compilerParameters, string.Format(@"-lib:""{0}""", libPath));
			Assert.AreEqual(libPath, compilerParameters.LibPaths[0]);
		}
示例#3
0
		public void SingleQuotesCanBeUsedAroundFileNames()
		{
			var fileName = "foo.boo";
			var compilerParameters = new CompilerParameters();
			CommandLineParser.ParseInto(compilerParameters, string.Format(@"'{0}'", fileName));
			Assert.AreEqual(fileName, compilerParameters.Input[0].Name);
		}
示例#4
0
		public void WorkaroundForNAntBugCausingAdditionalDoubleQuoteSuffixOnLibValue()
		{
			var libPath = Path.GetTempPath();
			var compilerParameters = new CompilerParameters();
			CommandLineParser.ParseInto(compilerParameters, string.Format(@"-lib:{0}""", libPath));
			Assert.AreEqual(libPath, compilerParameters.LibPaths[0]);
		}
示例#5
0
 public BooCompiler(CompilerParameters parameters)
 {
     if (null == parameters)
     {
         throw new ArgumentNullException("parameters");
     }
     _parameters = parameters;
 }
示例#6
0
        static void AddFilesForPath(string path, CompilerParameters options)
        {
            foreach (var fname in Directory.GetFiles(path, "*.boo"))
            {
                if (!fname.EndsWith(".boo")) continue;
                options.Input.Add(new FileInput(Path.GetFullPath(fname)));
            }

            foreach (var dirName in Directory.GetDirectories(path))
                AddFilesForPath(dirName, options);
        }
示例#7
0
文件: App.cs 项目: 0xb1dd1e/boo
		public int Run(string[] args)
		{
			int resultCode = 127;

			AppDomain.CurrentDomain.AssemblyResolve += AssemblyResolve;
			
			CheckBooCompiler();

			var parameters = new CompilerParameters(false);
			try
			{
				var setupTime = Stopwatch.StartNew();

				CommandLineParser.ParseInto(parameters, args);

				if (0 == parameters.Input.Count)
					throw new ApplicationException(StringResources.BooC_NoInputSpecified);
				
				var compiler = new BooCompiler(parameters);
				setupTime.Stop();

				var processingTime = Stopwatch.StartNew();
				var context = compiler.Run();
				processingTime.Stop();

				if (context.Warnings.Count > 0)
				{
					Console.Error.WriteLine(context.Warnings);
					Console.Error.WriteLine(StringResources.BooC_Warnings, context.Warnings.Count);
				}

				if (context.Errors.Count == 0)
					resultCode = 0;
				else
				{
					foreach (CompilerError error in context.Errors)
						Console.Error.WriteLine(error.ToString(parameters.TraceInfo));
					Console.Error.WriteLine(StringResources.BooC_Errors, context.Errors.Count);
				}

				if (parameters.TraceWarning)
					Console.Error.WriteLine(StringResources.BooC_ProcessingTime, parameters.Input.Count,
					                        processingTime.ElapsedMilliseconds, setupTime.ElapsedMilliseconds);
			}
			catch (Exception x)
			{
				var message = (parameters.TraceWarning) ? x : (object)x.Message;
				Console.Error.WriteLine(string.Format(Boo.Lang.Resources.StringResources.BooC_FatalError, message));
			}
			return resultCode;
		}
示例#8
0
		public void CustomTypeInferenceRuleAttribute()
		{
			var customAttributeName = typeof(CustomAttribute).FullName.Replace('+', '.');
			
			var parameters = new CompilerParameters();
			parameters.References.Add(typeof(CustomAttribute).Assembly);

			CommandLineParser.ParseInto(parameters, "-x-type-inference-rule-attribute:" + customAttributeName);
			ActiveEnvironment.With(new CompilerContext(parameters).Environment, () =>
			{
				var m = Methods.Of<object>(MethodWithCustomTypeInferenceRule);
				Assert.AreEqual("custom", My<TypeInferenceRuleProvider>.Instance.TypeInferenceRuleFor(m));	
			});
		}
示例#9
0
		public void MacroMacroCompilation()
		{
			CompilerParameters parameters = new CompilerParameters(false);
			parameters.References.Add(typeof(IEnumerable<>).Assembly);
			
			parameters.Input.Add(BooLangExtensionsSource("Macros/MacroMacro.boo"));
			parameters.Input.Add(BooLangExtensionsSource("Macros/AssertMacro.boo"));

			parameters.Pipeline = new Boo.Lang.Compiler.Pipelines.ResolveExpressions();

			Boo.Lang.Compiler.BooCompiler compiler = new Boo.Lang.Compiler.BooCompiler(parameters);
			CompilerContext results = compiler.Run();
			Assert.AreEqual(0, results.Errors.Count, results.Errors.ToString());
		}
示例#10
0
        public CompilerContext(CompilerParameters options, CompileUnit unit)
        {
            if (null == options) throw new ArgumentNullException("options");
            if (null == unit) throw new ArgumentNullException("unit");

            _unit = unit;
            _errors = new CompilerErrorCollection();
            _warnings = new CompilerWarningCollection();
            _assemblyReferences = options.References;
            _parameters = options;
            if (_parameters.Debug && !_parameters.Defines.ContainsKey("DEBUG"))
                _parameters.Defines.Add("DEBUG", null);
            _nameResolutionService = new TypeSystem.NameResolutionService(this);
            _properties = new Hash();
        }
示例#11
0
		public void NameMatchingCanBeCustomized()
		{
			var parameters = new CompilerParameters();
			const string code = @"
l = []
l.ADD(42)
l.add(42)
print JOIN(l, "", "")
";
			parameters.Input.Add(new StringInput("code", code));
			parameters.Pipeline = new ResolveExpressions();
			parameters.Pipeline.Insert(0, new ActionStep(
			                           	() => My<NameResolutionService>.Instance.EntityNameMatcher = MatchIgnoringCase));
			CompilerContext result = new Boo.Lang.Compiler.BooCompiler(parameters).Run();
			Assert.AreEqual(0, result.Errors.Count, result.Errors.ToString());
		}
示例#12
0
		[TestFixtureSetUp]
		public virtual void SetUpFixture()
		{
			System.Threading.Thread.CurrentThread.CurrentCulture = System.Globalization.CultureInfo.InvariantCulture;

			_baseTestCasesPath = Path.Combine(BooTestCaseUtil.TestCasesPath, GetRelativeTestCasesPath());
			_compiler = new BooCompiler();
			_parameters = _compiler.Parameters;
			_parameters.OutputWriter = _output = new StringWriter();
			_parameters.Pipeline = SetUpCompilerPipeline();
			_parameters.References.Add(typeof(AbstractCompilerTestCase).Assembly);
			_parameters.References.Add(typeof(BooCompiler).Assembly);
			Directory.CreateDirectory(TestOutputPath);
			_parameters.OutputAssembly = Path.Combine(TestOutputPath, "testcase.exe");
			_parameters.Defines.Add("BOO_COMPILER_TESTS_DEFINED_CONDITIONAL", null);
			CustomizeCompilerParameters();
示例#13
0
        public CompilerErrorCollection Run(params string[] args){
            var referencedAssemblies = ExtractAssemblies();
            var pipeline = ExtractPipeline() ?? new CompileToFile();

            var parameters = new CompilerParameters(true);

            //parameters.Ducky = true;

            parameters.LibPaths.Add(Environment.CurrentDirectory);
            parameters.LibPaths.Add(Path.Combine(Environment.CurrentDirectory, "bin"));
            parameters.OutputAssembly = "script.dll";

            foreach (var assembly in referencedAssemblies){
                parameters.AddAssembly(assembly);
                parameters.References.Add(assembly);
            }
            parameters.Pipeline = pipeline;
            var compiler = new BooCompiler(parameters);
            parameters.Input.Add(new ReaderInput("script", new StringReader(BooScript)));
            var result = compiler.Run();

            if (result.Errors.yes()) return result.Errors;

            var resultAssembly = result.GeneratedAssembly;


            var global__ = resultAssembly.getTypesWithAttribute<GlobalsHandlingClassAttribute>();
            var global = global__.no() ? null : global__.FirstOrDefault();


            if (global.yes() && Globals.Count != 0){
                foreach (var pair in Globals){
                    var pi = global.GetProperty(pair.Key, BindingFlags.Static | BindingFlags.Public | BindingFlags.SetProperty);
                    if (null == pi) throw new Exception("Нет статического свойства с именем " + pair.Key);
                    pi.SetValue(null, pair.Key, null);
                }
            }

            resultAssembly.EntryPoint.Invoke(null, new[]{args});

            return null;
        }
示例#14
0
		public void TestWithDocPath()
		{
			var parameters = new CompilerParameters();
			CommandLineParser.ParseInto(parameters,
				new string[] { "/doc:TestDoc.xml", "/target:library", "/o:TestDoc.dll", "TestDoc.boo" });
			var compiler = new BooCompiler(parameters);
			var context=compiler.Run();
			if (context.Errors.Count > 0)
			{
				Console.WriteLine(context.Errors);
				throw new AssertionException(context.Errors[0].ToString());
			}
			
			var reference = new XmlDocument();
			reference.Load("TestDocReference.xml");
			var result = new XmlDocument();
			result.Load("TestDoc.xml");
			
			Assert.AreEqual(reference.ToString(), result.ToString());
		}
示例#15
0
 public BooCompiler()
 {
     _parameters = new CompilerParameters();
 }
示例#16
0
		public static void ParseInto(CompilerParameters options, params string[] commandLine)
		{
			new CommandLineParser(commandLine, options);
		}
示例#17
0
        public CompilerResults CompileAssemblyFromSourceBatch(
            CompilerParameters options, string [] sources)
        {
            if (null == options)
            {
                throw new ArgumentNullException("options");
            }
            if (null == sources)
            {
                throw new ArgumentNullException("fileNames");
            }

            CompilerResults results = new CompilerResults(options.TempFiles);

            BooC.BooCompiler        compiler   = new BooC.BooCompiler();
            BooC.CompilerParameters parameters = compiler.Parameters;

            if (options.OutputAssembly == null)
            {
                options.OutputAssembly = GetTempFileNameWithExtension(options.TempFiles, "dll");
            }
            parameters.OutputAssembly = options.OutputAssembly;

            // set compile options
            if (options.GenerateInMemory)
            {
                parameters.Pipeline = new CompileToMemory();
            }
            else
            {
                parameters.Pipeline = new CompileToFile();
            }

            if (options.GenerateExecutable)
            {
                parameters.OutputType = BooC.CompilerOutputType.ConsoleApplication;                 // winexe ??
            }
            else
            {
                parameters.OutputType = BooC.CompilerOutputType.Library;
            }
            parameters.Debug = options.IncludeDebugInformation;

            if (null != options.ReferencedAssemblies)
            {
                foreach (string import in options.ReferencedAssemblies)
                {
                    parameters.References.Add(Assembly.LoadFrom(import));
                }
            }

            foreach (string source in sources)
            {
                parameters.Input.Add(new StringInput("source", source));
            }
            // run the compiler
            BooC.CompilerContext context = compiler.Run();

            bool loadIt = processCompileResult(context, results);

            if (loadIt)
            {
                results.CompiledAssembly = context.GeneratedAssembly;
                //results.CompiledAssembly = Assembly.LoadFrom(options.OutputAssembly);
            }
            else
            {
                results.CompiledAssembly = null;
            }

            return(results);
        }
示例#18
0
 /// <summary>
 /// Tries the add the speicifed assemblies to the compiler's references
 /// In a late bound way
 /// </summary>
 /// <param name="cp">The compiler parameters.</param>
 /// <param name="assembliesToAdd">The assemblies to add.</param>
 private static void TryAddAssembliesReferences(CompilerParameters cp, params string[] assembliesToAdd)
 {
     foreach (string assembly in assembliesToAdd)
     {
         try
         {
             cp.References.Add(Assembly.Load(assembly));
         }
         catch
         {
             // we don't worry if we can't load the assemblies
         }
     }
 }
 protected virtual void prepareCompiler(CompilerParameters parameters) {
     
 }
        /// <summary>
        /// This creates a copy of the passed compiler parameters, without the stuff
        /// that make a compilation unique, like input, output assembly, etc
        /// </summary>
        /// <param name="parameters"></param>
        /// <returns></returns>
        private static CompilerParameters SafeCloneParameters(CompilerParameters parameters)
        {
            CompilerParameters cloned = new CompilerParameters();
            cloned.BooAssembly = parameters.BooAssembly;
            cloned.Checked = parameters.Checked;
            cloned.Debug = parameters.Debug;
            cloned.DelaySign = parameters.DelaySign;
            cloned.Ducky = parameters.Ducky;
            cloned.GenerateInMemory = parameters.GenerateInMemory;

            // cloned.Input - we don't want to copy that
            cloned.KeyContainer = parameters.KeyContainer;
            cloned.KeyFile = parameters.KeyFile;
            cloned.LibPaths.AddRange(parameters.LibPaths);
            // cloned.OutputAssembly - we don't want that either

            // always want that, since we are compiling to add a reference
            cloned.OutputType = CompilerOutputType.Library;
            cloned.OutputWriter = parameters.OutputWriter;
            cloned.Pipeline = parameters.Pipeline;
            cloned.References = parameters.References;
            // cloned.Resources - probably won't have that, but in any case, not relevant
            cloned.StdLib = parameters.StdLib;

            return cloned;
        }
示例#21
0
 public void SetupForCompilation(CompilerParameters compilerParameters)
 {
     if (CompileUnit == null)
             compilerParameters.Input.Add(new StringInput(urlGetter(), sourceGetter()));
         else
             compilerParameters.References.Add(CompileUnit);
     Initialize();
 }
示例#22
0
		private IEnvironment CompilerContextEnvironmentWith(Mock<MacroCompiler> compiler)
		{
			var parameters = new CompilerParameters(false) { Environment = new ClosedEnvironment(compiler.Object) };
			return new CompilerContext(parameters).Environment;
		}
示例#23
0
文件: App.cs 项目: w4x/boolangstudio
        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;
        }
 protected override void prepareCompiler(CompilerParameters parameters) {
     base.prepareCompiler(parameters);
     parameters.References.Add(typeof(IRegistryLoader).Assembly);
     parameters.References.Add(typeof(IDictionary<string,string>).Assembly);
 }