Пример #1
0
        public static ThemaCompilerContext Compile(string code, Action <ThemaProject> prepareProject = null)
        {
            var project = new ThemaProject {
                ErrorLevel = ErrorLevel.Error, UseEcoOptimization = true, UseEcoProcess = true
            };

            project.SetSelfLog(LogLevel.Debug);
            project.NonResolvedProcessThemaRefIsError = true;
            project.CustomCompiler           = new ApplyEcoProcesses();
            project.DirectSource["main.bxl"] = code;
            if (null != prepareProject)
            {
                prepareProject(project);
            }
            var compiler = new ThemaCompiler();

            var context = compiler.Compile(project);

            Console.WriteLine(project.GetLog());
            foreach (var e in context.Errors)
            {
                Console.WriteLine(e);
            }
            return(context);
        }
Пример #2
0
		public void full_non_strict_compilation() {
			var proj = new ThemaProject();
			proj.SourceFiles = new[] {"~/systh", "~/usrth"};
			proj.UseEcoOptimization = true;
			proj.AnalyzeSubsetUsage = true;
			proj.AnalyzeParamUsage = true;
			proj.KeepAbstractThemas = true;
			var result = execute<GenerateXml>(proj, LogLevel.All);
			Assert.True(result.IsComplete);
		}
Пример #3
0
		public void save_to_disk_usual_mode() {
			var proj = new ThemaProject();
			proj.SourceFiles = new[] {"~/systh", "~/usrth"};
			proj.OutputFolder = "~/bigout";
			proj.UseEcoOptimization = true;
			proj.AnalyzeSubsetUsage = false;
			proj.AnalyzeParamUsage = false;
			proj.KeepAbstractThemas = false;
			proj.NonResolvedImportIsError = true;
			var result = execute<CompileToXml>(proj, LogLevel.All);
			Assert.True(result.IsComplete);
		}
Пример #4
0
		public void error_if_no_target_folder() {
			var proj = new ThemaProject();
			proj.SourceFiles = new[] {"~/systh", "~/usrth"};
			proj.OutputFolder = "";
			proj.UseEcoOptimization = true;
			proj.AnalyzeSubsetUsage = false;
			proj.AnalyzeParamUsage = false;
			proj.KeepAbstractThemas = false;
			proj.NonResolvedImportIsError = true;
			var result = execute<CompileToXml>(proj, LogLevel.Error);
			Assert.False(result.IsComplete);
		}
Пример #5
0
        public void full_non_strict_compilation()
        {
            var proj = new ThemaProject();

            proj.SourceFiles        = new[] { "~/systh", "~/usrth" };
            proj.UseEcoOptimization = true;
            proj.AnalyzeSubsetUsage = true;
            proj.AnalyzeParamUsage  = true;
            proj.KeepAbstractThemas = true;
            var result = execute <GenerateXml>(proj, LogLevel.All);

            Assert.True(result.IsComplete);
        }
Пример #6
0
        public void usual_compilation()
        {
            var proj = new ThemaProject();

            proj.SourceFiles              = new[] { "~/systh", "~/usrth" };
            proj.UseEcoOptimization       = true;
            proj.AnalyzeSubsetUsage       = false;
            proj.AnalyzeParamUsage        = false;
            proj.KeepAbstractThemas       = false;
            proj.NonResolvedImportIsError = true;
            var result = execute <GenerateXml>(proj, LogLevel.Error);

            Assert.True(result.IsComplete);
        }
Пример #7
0
        public void save_to_disk_usual_mode()
        {
            var proj = new ThemaProject();

            proj.SourceFiles              = new[] { "~/systh", "~/usrth" };
            proj.OutputFolder             = "~/bigout";
            proj.UseEcoOptimization       = true;
            proj.AnalyzeSubsetUsage       = false;
            proj.AnalyzeParamUsage        = false;
            proj.KeepAbstractThemas       = false;
            proj.NonResolvedImportIsError = true;
            var result = execute <CompileToXml>(proj, LogLevel.All);

            Assert.True(result.IsComplete);
        }
Пример #8
0
        public void error_if_no_target_folder()
        {
            var proj = new ThemaProject();

            proj.SourceFiles              = new[] { "~/systh", "~/usrth" };
            proj.OutputFolder             = "";
            proj.UseEcoOptimization       = true;
            proj.AnalyzeSubsetUsage       = false;
            proj.AnalyzeParamUsage        = false;
            proj.KeepAbstractThemas       = false;
            proj.NonResolvedImportIsError = true;
            var result = execute <CompileToXml>(proj, LogLevel.Error);

            Assert.False(result.IsComplete);
        }
		private ThemaCompilerContext exec(params string[] clusters) {
			var proj = new ThemaProject();
			proj.DirectSource["main.bxl"] = code;
			proj.SetSelfLog();
			proj.CustomCompiler = new GenerateXml();
			if (null != clusters) {
				foreach (var cluster in clusters) {
					proj.Clusters.Add(cluster);
				}
			}
			var result = new ThemaCompiler().Compile(proj);
			foreach (var t in result.Themas) {
				Console.WriteLine(t.Value.Xml);
			}
			return result;
		}
		/// <summary>
		/// </summary>
		/// <param name="args"> </param>
		/// <exception cref="Exception"></exception>
		public void Run(string[] args) {
			//	Contract.Requires<ArgumentException>(args!=null && args.Length!=0);
			var project = new ThemaProject();
			var projfile = Path.GetFullPath(args[0]);
			var dir = Path.GetDirectoryName(projfile);
			if (null == dir) {
				throw new Exception("не могу определить рабочую директорию");
			}
			Environment.CurrentDirectory = dir;
			var projfilexml = Application.Current.Bxl.Parse(File.ReadAllText(projfile), Path.GetFileName(projfile));
			IList<string> targets = new List<string>();
			if (args.Length > 1) {
				for (var i = 1; i < args.Length; i++) {
					targets.Add(args[i]);
				}
			}
			project.ConfigureFromXml(projfilexml, string.Join(",", targets.ToArray()));

			Console.WriteLine("Project loaded from " + projfile);
			var compiler = new ThemaCompiler();
			Console.WriteLine("Start of compilation");
			Result = compiler.Compile(project);

			if (ErrorLevel.Warning <= project.ErrorLevel) {
				Console.ForegroundColor = ConsoleColor.Yellow;
				foreach (var warn in Result.Errors.Where(x => x.Level <= ErrorLevel.Warning)) {
					Console.WriteLine(warn);
				}
				Console.ResetColor();
			}
			Console.ForegroundColor = ConsoleColor.Red;
			foreach (var error in Result.Errors.Where(x => x.Level > ErrorLevel.Warning)) {
				Console.WriteLine(error);
			}
			Console.ResetColor();

			if (Result.IsComplete) {
				Console.ForegroundColor = ConsoleColor.Green;
				Console.WriteLine("compilation complete");
			}
			else {
				Console.ForegroundColor = ConsoleColor.Red;
				Console.WriteLine("compilation failed!");
			}
			Console.ResetColor();
		}
Пример #11
0
        protected ThemaCompilerContext execute <T>(ThemaProject proj = null, LogLevel level = LogLevel.Trace)
            where T : IThemaCompilerSetup, new()
        {
            sw                  = new StringWriter();
            proj                = proj ?? getDefaultProject();
            proj.UserLog        = proj.UserLog ?? BaseTextWriterLogWriter.CreateLog("default", sw, level);
            proj.CustomCompiler = proj.CustomCompiler ?? new T();
            var compiler = new ThemaCompiler();
            var result   = compiler.Compile(proj);

            Console.WriteLine(sw.ToString());
            foreach (var e in result.Errors)
            {
                Console.WriteLine(e);
            }
            return(result);
        }
Пример #12
0
		public static ThemaCompilerContext Compile(string code, Action<ThemaProject> prepareProject = null) {
			var project = new ThemaProject {ErrorLevel = ErrorLevel.Error, UseEcoOptimization = true, UseEcoProcess = true};
			project.SetSelfLog(LogLevel.Debug);
			project.NonResolvedProcessThemaRefIsError = true;
			project.CustomCompiler = new ApplyEcoProcesses();
			project.DirectSource["main.bxl"] = code;
			if (null != prepareProject) {
				prepareProject(project);
			}
			var compiler = new ThemaCompiler();

			var context = compiler.Compile(project);
			Console.WriteLine(project.GetLog());
			foreach (var e in context.Errors) {
				Console.WriteLine(e);
			}
			return context;
		}
Пример #13
0
        private ThemaCompilerContext exec(params string[] clusters)
        {
            var proj = new ThemaProject();

            proj.DirectSource["main.bxl"] = code;
            proj.SetSelfLog();
            proj.CustomCompiler = new GenerateXml();
            if (null != clusters)
            {
                foreach (var cluster in clusters)
                {
                    proj.Clusters.Add(cluster);
                }
            }
            var result = new ThemaCompiler().Compile(proj);

            foreach (var t in result.Themas)
            {
                Console.WriteLine(t.Value.Xml);
            }
            return(result);
        }
Пример #14
0
		public void usual_compilation() {
			var proj = new ThemaProject();
			proj.SourceFiles = new[] {"~/systh", "~/usrth"};
			proj.UseEcoOptimization = true;
			proj.AnalyzeSubsetUsage = false;
			proj.AnalyzeParamUsage = false;
			proj.KeepAbstractThemas = false;
			proj.NonResolvedImportIsError = true;
			var result = execute<GenerateXml>(proj, LogLevel.Error);
			Assert.True(result.IsComplete);
		}