Example #1
0
        public void TestSimple()
        {
            // TODO: there must be a better way of setting up the whole CR test
            OptimizationLevelBase.Instance       = new OptimizationLevels();
            OptimizationLevelBase.OptimizerLevel = 2;
            OptimizationLevelBase.Instance.EnabledCategories.Add(OptimizationCategories.All);

            kernel = new StandardKernel(
                new CodeRefractorNInjectModule()
                );

            var cSharpCode =
                @"
                    public class C
                    {
                        public static void Main()
                        {
                            var message = ""test"";
                            message += ""other"";

                            System.Console.WriteLine(""main entered"");
                        }
                    }
                ";

            var dotNetAssembly  = CompilingProgramBase.CompileSource(cSharpCode);
            var closureEntities = kernel.Get <ClosureEntitiesUtils>()
                                  .BuildClosureEntities(
                dotNetAssembly.EntryPoint,
                typeof(CrString).Assembly);

            var sourceCode = closureEntities.BuildFullSourceCode();

            Console.WriteLine(sourceCode);
        }
Example #2
0
        public void TestCodeInMainIfCompiles()
        {
            var mainBody =
                @"var a = 30.0;
            var b = 9.0 - (int)a / 5;
           
            Console.WriteLine(b);";
            var fullCode = CompilingProgramBase.GenerateMainCode(mainBody);

            var csAssembly = CompilingProgramBase.CompileSource(fullCode);

            Assert.IsNotNull(csAssembly);

            var program    = kernel.Get <Program>();
            var outputFile = program.CallCompiler(csAssembly.Location);

            var pathToGpp = Path.Combine(PathOfCompilerTools, CompilerExe);
            //var outputFile =  @"c:\Oss\ClClean\bin\output.cpp";
            var arguments     = BuildArgs(outputFile);
            var resultCommand = pathToGpp.ExecuteCommand(arguments);

            Assert.IsTrue(!resultCommand.Contains("error"));
        }