internal bool Build(EditorCompilation editorCompilation) { if (editorCompilation.IsCompilationTaskCompiling()) { return(false); } if (status != AssemblyBuilderStatus.NotStarted) { throw new Exception(string.Format("Cannot start AssemblyBuilder with status {0}. Expected {1}", status, AssemblyBuilderStatus.NotStarted)); } var scriptAssembly = editorCompilation.CreateScriptAssembly(this); compilationTask = new CompilationTask(new ScriptAssembly[] { scriptAssembly }, scriptAssembly.OutputDirectory, EditorScriptCompilationOptions.BuildingEmpty, CompilationTaskOptions.StopOnFirstError, 1); compilationTask.OnCompilationStarted += (assembly, phase) => { editorCompilation.InvokeAssemblyCompilationStarted(assemblyPath); OnCompilationStarted(assembly, phase); }; compilationTask.OnCompilationFinished += (assembly, messages) => { editorCompilation.InvokeAssemblyCompilationFinished(assemblyPath, messages); OnCompilationFinished(assembly, messages); }; compilationTask.Poll(); editorCompilation.AddAssemblyBuilder(this); return(true); }
internal bool Build(EditorCompilation editorCompilation) { bool result; if (editorCompilation.IsCompilationTaskCompiling()) { result = false; } else { if (this.status != AssemblyBuilderStatus.NotStarted) { throw new Exception(string.Format("Cannot start AssemblyBuilder with status {0}. Expected {1}", this.status, AssemblyBuilderStatus.NotStarted)); } ScriptAssembly scriptAssembly = editorCompilation.CreateScriptAssembly(this); this.compilationTask = new CompilationTask(new ScriptAssembly[] { scriptAssembly }, scriptAssembly.OutputDirectory, EditorScriptCompilationOptions.BuildingEmpty, 1); this.compilationTask.OnCompilationStarted += delegate(ScriptAssembly assembly, int phase) { editorCompilation.InvokeAssemblyCompilationStarted(this.assemblyPath); this.OnCompilationStarted(assembly, phase); }; this.compilationTask.OnCompilationFinished += delegate(ScriptAssembly assembly, List <UnityEditor.Scripting.Compilers.CompilerMessage> messages) { editorCompilation.InvokeAssemblyCompilationFinished(this.assemblyPath, messages); this.OnCompilationFinished(assembly, messages); }; this.compilationTask.Poll(); editorCompilation.AddAssemblyBuilder(this); result = true; } return(result); }
private static CompilationTask BuildTask(HimeTaskOptions options) { CompilationTask task = new CompilationTask(); if (options.Assembly) { task.Mode = Mode.SourceAndAssembly; } if (options.Debug) { task.Mode = Mode.Debug; } if (!string.IsNullOrEmpty(options.Grammar)) { task.GrammarName = options.Grammar; } if (!string.IsNullOrEmpty(options.OutputPath)) { task.OutputPath = options.OutputPath; } if (!string.IsNullOrEmpty(options.Namespace)) { task.Namespace = options.Namespace; } if (options.RNGLR) { task.Method = ParsingMethod.RNGLALR1; } if (options.Public) { task.CodeAccess = Modifier.Public; } return(task); }
/// <summary> /// Executes the himecc program /// </summary> /// <param name="args">The command line arguments</param> /// <returns>The error code, or 0 if none</returns> public static int Main(string[] args) { // If no argument is given, print the help screen and return OK if (args == null || args.Length == 0) { PrintHelp(); return(ResultOK); } // Parse the arguments ParseResult result = CommandLine.ParseArguments(args); foreach (ParseError error in result.Errors) { Console.WriteLine(error.Message); } if (!result.IsSuccess || result.Errors.Count > 0) { Console.WriteLine(ErrorParsingArgs); Console.WriteLine(ErrorPointHelp); return(ResultErrorParsingArgs); } // Check for special switches string special = GetSpecialCommand(result.Root); if (special == ArgHelpShort || special == ArgHelpLong) { PrintHelp(); return(ResultOK); } else if (special == ArgRegenerateShort || special == ArgRegenerateLong) { GenerateCLParser(); GenerateCDParser(); UnicodeHelper.GenerateBlocksDB(); UnicodeHelper.GenerateCategoriesDB(); UnicodeHelper.GenerateBlocksTests(); return(ResultOK); } // Build the compilation task CompilationTask task = BuildTask(result.Root); if (task == null) { Console.WriteLine(ErrorBadArgs); Console.WriteLine(ErrorPointHelp); return(ResultErrorBadArgs); } // Execute the task Report report = task.Execute(); return(report.Errors.Count != 0 ? ResultErrorCompiling : ResultOK); }
/// <summary> /// Handles a compilation task end event. /// </summary> private static void CompilationEventEndHandler(string?parentTaskName, string taskName) { Debug.Assert(Monitor.IsEntered(GlobalLock)); var key = CompilationTask.GenerateKey(parentTaskName, taskName); if (!CompilationTasks.TryGetValue(key, out var task)) { throw new InvalidOperationException($"Attempt to stop task '{key}' which does not exist"); } task.Stop(); }
/// <summary> /// Handles a compilation task start event. /// </summary> private static void CompilationEventStartHandler(string?parentTaskName, string taskName) { Debug.Assert(Monitor.IsEntered(GlobalLock)); string key = CompilationTask.GenerateKey(parentTaskName, taskName); if (!CompilationTasks.TryGetValue(key, out var task)) { task = new CompilationTask(parentTaskName, taskName); CompilationTasks.Add(key, task); } task.Start(); }
/// <summary> /// Handles a compilation task start event. /// </summary> private static void CompilationEventStartHandler(CompilationLoader.CompilationTaskEventArgs eventArgs) { Debug.Assert(Monitor.IsEntered(GlobalLock)); string key = CompilationTask.GenerateKey(eventArgs.ParentTaskName, eventArgs.TaskName); if (CompilationTasks.ContainsKey(key)) { Warnings.Add(new Warning(WarningType.TaskAlreadyExists, key)); return; } CompilationTasks.Add(key, new CompilationTask(eventArgs.ParentTaskName, eventArgs.TaskName)); }
/// <summary> /// Adds an input to a compilation task /// </summary> /// <param name="task">The compilation task</param> /// <param name="node">The input as a parsed data in the command line</param> private static void AddInput(CompilationTask task, ASTNode node) { string value = node.Value; if (value == null) { return; } if (value.StartsWith("\"")) { value = value.Substring(1, value.Length - 2); } task.AddInputFile(value); }
/// <summary> /// Generates the parser for the command line /// </summary> /// <returns>The number of errors (should be 0)</returns> private static int GenerateCLParser() { Stream stream = typeof(Program).Assembly.GetManifestResourceStream("Hime.HimeCC.Sources.CommandLine.gram"); CompilationTask task = new CompilationTask(); task.Mode = Mode.Source; task.AddInputRaw(stream); task.Namespace = "Hime.HimeCC"; task.CodeAccess = Modifier.Internal; task.Method = ParsingMethod.LALR1; Report report = task.Execute(); return(report.Errors.Count); }
/// <summary> /// Builds the fixture parser /// </summary> /// <returns>The fixture parser assembly</returns> private static AssemblyReflection BuildFixtureParser() { Stream stream1 = typeof(Program).Assembly.GetManifestResourceStream("Hime.Tests.Driver.Resources.Fixture.gram"); Stream stream2 = typeof(CompilationTask).Assembly.GetManifestResourceStream("Hime.SDK.Sources.Input.HimeGrammar.gram"); CompilationTask task = new CompilationTask(); task.AddInputRaw(stream1); task.AddInputRaw(stream2); task.GrammarName = "Fixture"; task.CodeAccess = Modifier.Public; task.Method = ParsingMethod.LALR1; task.Mode = Mode.Assembly; task.Namespace = "Hime.Tests.Driver"; task.Execute(); return(new AssemblyReflection("Fixture.dll")); }
public bool AddTask(CompilationTask task) { try { var error = task(); if (error != null) { this.Tasks.Enqueue(task); } return(error == null); } catch (Exception) { this.Tasks.Enqueue(task); return(false); } }
/// <summary> /// Handles a compilation task end event. /// </summary> private static void CompilationEventEndHandler(CompilationLoader.CompilationTaskEventArgs eventArgs) { Debug.Assert(Monitor.IsEntered(GlobalLock)); var key = CompilationTask.GenerateKey(eventArgs.ParentTaskName, eventArgs.TaskName); if (!CompilationTasks.TryGetValue(key, out var task)) { Warnings.Add(new Warning(WarningType.TaskDoesNotExist, key)); return; } if (!task.IsInProgress()) { Warnings.Add(new Warning(WarningType.TaskAlreadyEnded, key)); return; } task.End(); }
public CompilationTaskNode(CompilationTask task) { Task = task; Children = new Dictionary <string, CompilationTaskNode>(); }
public override bool Execute() { if (string.IsNullOrEmpty(GrammarFile)) { Log.LogError("The grammar file name is not set"); return(false); } if (string.IsNullOrEmpty(Namespace)) { Log.LogError("The namespace is not set"); return(false); } if (string.IsNullOrEmpty(GrammarName)) { Log.LogError("The grammar name is not set"); return(false); } if (string.IsNullOrEmpty(OutputPath)) { Log.LogError("The output assembly path is not set"); return(false); } Mode outputMode; switch (OutputMode) { case "Assembly": case "assembly": outputMode = Mode.Assembly; break; case "Source": case "source": outputMode = Mode.Source; break; case "SourceAndAssembly": case "source-and-assembly": outputMode = Mode.SourceAndAssembly; break; default: Log.LogError("The output mode is incorrect, it should be Assembly, Source or SourceAndAssembly"); return(false); } Modifier codeAccess; switch (CodeAccess) { case "Public": case "public": codeAccess = Modifier.Public; break; case "Internal": case "internal": codeAccess = Modifier.Public; break; default: Log.LogError("The code access mode is incorrect, it should be either Public or Internal"); return(false); } CompilationTask task = new CompilationTask(); task.AddInputFile(GrammarFile); task.CodeAccess = codeAccess; task.GrammarName = GrammarName; task.Mode = outputMode; task.OutputPath = OutputPath; task.Namespace = Namespace; Report report = task.Execute(); if (report.Errors.Count == 0) { Log.LogMessage($"Grammar {GrammarName} compiled succesfully"); return(true); } Log.LogMessage($"Grammar {GrammarName} compilation failed"); for (int i = 0; i < report.Errors.Count; i++) { Log.LogError($"Error in {GrammarFile} : {report.Errors[i].ToString()}"); } return(false); }
public bool Compile(string currentDir, string inputFile, string outputFile, IFileLookup lookup, Context context, Options options, WriterMode writerMode) { Current.SetContext(context); Current.SetWriterMode(writerMode); Current.SetOptions(options); CompilationTask noop = (List <Block> blocks) => blocks; var tasks = new List <CompilationTask>() { Tasks.Using.Task, References.Task, Charsets.Task, Tasks.Import.Task, Reset.Task, Sprite.Task, Mixin.Task, UnrollNestedMedia.Task, UnrollNestedSelectors.Task, UnrollVerify.Task, Tasks.Media.Task, Includes.Task, ResetIncludes.Task, Evaluate.Task, Important.Task, NoOps.Task, FontFace.Task, ResetReOrder.Task, Verify.Task, Current.Options.HasFlag(Options.Minify) ? Minify.Task : noop, Collapse.Task, WriteSprites.Task, Current.Options.HasFlag(Options.GenerateCacheBreakers) ? CacheBreak.Task : noop, Current.Options.HasFlag(Options.AutomateVendorPrefixes) ? AutoPrefix.Task : noop, Write.Task }; try { Current.SetWorkingDirectory(currentDir); Current.SetFileLookup(lookup); inputFile = Path.IsPathRooted(inputFile) ? inputFile : inputFile.RebaseFile(); Current.SetInitialFile(inputFile); List <Block> blocks; using (var stream = lookup.Find(inputFile)) { blocks = Parse.Task(stream); } using (var output = lookup.OpenWrite(outputFile)) { Current.SetOutputStream(output); if (blocks == null) { return(false); } foreach (var task in tasks) { blocks = task(blocks); if (Current.HasErrors()) { return(false); } } } Current.Dependecies.FileCompiled(inputFile, blocks); return(true); } catch (StoppedCompilingException) { return(false); } }
public override int Execute(CommandContext context, CompileSettings settings, VeinProject project) { Log.Info($"Project [orange]'{project.Name}'[/]."); var targets = CompilationTask.Run(project.WorkDir, settings); foreach (var info in targets.SelectMany(x => x.Logs.Info).Reverse()) { MarkupLine(info.TrimEnd('\n')); } foreach (var info in Log.infos) { MarkupLine(info.TrimEnd('\n')); } if (new[] { Log.errors.Count, targets.Sum(x => x.Logs.Error.Count) }.Sum() > 0) { var rule1 = new Rule($"[yellow]{Log.errors.Count} error found[/]") { Style = Style.Parse("red rapidblink") }; Write(rule1); } foreach (var target in targets.SelectMany(x => x.Logs.Error).Reverse()) { MarkupLine(target); } foreach (var error in Log.errors) { MarkupLine(error); } if (new[] { Log.warnings.Count, targets.Sum(x => x.Logs.Warn.Count) }.Sum() > 0) { var rule2 = new Rule($"[yellow]{Log.warnings.Count} warning found[/]") { Style = Style.Parse("orange rapidblink") }; Write(rule2); } foreach (var warn in targets.SelectMany(x => x.Logs.Warn).Reverse()) { MarkupLine(warn); } foreach (var warn in Log.warnings) { MarkupLine(warn); } if (!Log.warnings.Any() && !Log.errors.Any()) { MarkupLine($"\n\n\n"); } if (new[] { Log.errors.Count, targets.Sum(x => x.Logs.Error.Count) }.Sum() > 0) { var rule3 = new Rule($"[red bold]COMPILATION FAILED[/]") { Style = Style.Parse("lime rapidblink") }; Write(rule3); MarkupLine($"\n"); return(-1); } else { var rule3 = new Rule($"[green bold]COMPILATION SUCCESS[/]") { Style = Style.Parse("lime rapidblink") }; Write(rule3); MarkupLine($"\n"); return(0); } }
/// <summary> /// Builds the compilation task corresponding to the given command line /// </summary> /// <param name="line">The parsed command line as an AST</param> /// <returns>The corresponding compilation task, or null if there is any error</returns> private static CompilationTask BuildTask(ASTNode line) { CompilationTask task = new CompilationTask(); // All single values before the arguments shall be inputs foreach (ASTNode value in line.Children[0].Children) { AddInput(task, value); } // Inspect each passed argument foreach (ASTNode arg in line.Children[1].Children) { switch (arg.Value) { case ArgOutputAssembly: if (task.Mode == Mode.Source) { task.Mode = Mode.SourceAndAssembly; } break; case ArgOutputNoSources: task.Mode = Mode.Assembly; break; case ArgOutputDebug: task.Mode = Mode.Debug; break; case ArgTargetJava: task.Target = Runtime.Java; break; case ArgTargetRust: task.Target = Runtime.Rust; if (arg.Children.Count >= 1) { task.TargetRustRuntime = arg.Children[0].Value; } break; case ArgGrammar: if (arg.Children.Count != 1) { return(null); } task.GrammarName = CommandLine.GetValue(arg); break; case ArgPath: if (arg.Children.Count != 1) { return(null); } task.OutputPath = CommandLine.GetValue(arg); break; case ArgMethodRNGLR: task.Method = ParsingMethod.RNGLALR1; break; case ArgNamespace: if (arg.Children.Count != 1) { return(null); } task.Namespace = CommandLine.GetValue(arg); break; case ArgAccessPublic: task.CodeAccess = Modifier.Public; break; default: Console.WriteLine("Unknown argument " + arg.Value); return(null); } } return(task); }