public override bool Rename(string newName) { //Add .galaxy++ if not present if (!newName.EndsWith(".Dialog")) newName = newName + ".Dialog"; //Dont reneme if there is a clash foreach (FileSystemInfo dir in Parent.Dir.GetFileSystemInfos()) { if (dir.Name == newName + ".Dialog") return false; } File.Move(Parent.Dir.FullName + "\\" + Name, Parent.Dir.FullName + "\\" + newName); string oldName = Name; Name = newName; InvokeRenamed(this, oldName, newName); //Change other stuff string shortName = Name.Substring(0, Name.LastIndexOf(".Dialog")); CodeGUINode.Text = shortName + (CodeGUINode.Text.EndsWith("*") ? ".galaxy++*" : ".galaxy++"); DesignerGUINode.Text = shortName + (DesignerGUINode.Text.EndsWith("*") ? ".Designer.galaxy++*" : ".Designer.galaxy++"); if (OpenFileData != null) { if (OpenFileData.TabPage != null) OpenFileData.TabPage.Title = Name + (OpenFileData.TabPage.Title.EndsWith("*") ? "*" : ""); if (OpenFileData.CodeTabPage != null) OpenFileData.CodeTabPage.Title = shortName + (OpenFileData.CodeTabPage.Title.EndsWith("*") ? ".galaxy++*" : ".galaxy++"); if (OpenFileData.DesignerTabPage != null) OpenFileData.DesignerTabPage.Title = shortName + ".Designer.galaxy++"; } //Fix refferences to dialog try { DialogData data; if (OpenFileData != null) data = OpenFileData; else { data = DialogData.Load(FullName); data.DialogItem = this; } string code = data.ActualCode; Name = oldName; string oldIdentifier = data.DialogIdentiferName; Name = newName; string newIdentifier = data.DialogIdentiferName; Parser parser = new Parser(new Lexer(new StringReader(code))); AASourceFile start = (AASourceFile)parser.Parse().GetPSourceFile(); Renamer ren = new Renamer(oldIdentifier); start.Apply(ren); ren.types.Reverse();//To avoid changeing the position of stuff we must change string[] lines = code.Split('\n'); foreach (TIdentifier identifier in ren.types) { lines[identifier.Line - 1] = lines[identifier.Line - 1].Substring(0, identifier.Pos - 1) + newIdentifier + lines[identifier.Line - 1].Substring(identifier.Pos + oldIdentifier.Length - 1); } string newCode = ""; foreach (string line in lines) { newCode += line + "\n"; } newCode = newCode.Remove(code.Length); if (code != newCode) { if (OpenFileData == null) Form1.Form.OpenFile(this, CodeGUINode); OpenFileData.ActualCode = newCode; } } catch (Exception err) { //Or not.. } Form1.Form.compiler.DialogItemChanged(this, null, true); return true; }
private void CompileLoop() { while (!disposed) { try { while (!liteCompileSemaphore.WaitOne(5000)) { if (Form1.Form.F_Disposed) return; } if (disposed) return; while (liteCompileQueue.Count > 0 || liteCompileLibraryQueue.Count > 0) { List<string> sources = new List<string>(); List<SourceFileContents> contentList = new List<SourceFileContents>(); if (liteCompileQueue.Count > 0) { SourceFileContents contents = liteCompileQueue[0].Key; if (liteCompileQueue[0].Value == null) { /*StreamReader reader = contents.File.File.OpenText(); sources.Add(reader.ReadToEnd()); reader.Close();*/ sources.Add(contents.GetSource()); } else sources.Add(liteCompileQueue[0].Value.Text); if (disposed) return; liteCompileQueue.RemoveAt(0); contentList.Add(contents); } else { Library lib = liteCompileLibraryQueue[0]; liteCompileLibraryQueue.RemoveAt(0); AddSourceFiles(lib.Items, sources, contentList); foreach (SourceFileContents contents in contentList) { contents.Library = lib; } } while (sources.Count > 0) { string source = sources.Last(); sources.RemoveAt(sources.Count - 1); SourceFileContents contents = contentList.Last(); contentList.RemoveAt(contentList.Count - 1); //Parse + weeder Parser parser = new Parser(new Lexer(new StringReader(source))); Start ast; try { ast = parser.Parse(); SimpleTransformations.Parse(ast); } catch (Exception err) { //Critical erros continue; } bool hadChanges = contents.Parse(ast, this); hadChanges |= ConstantFolder.Fold(this); if (hadChanges) { FixStructBaseRefferences(); //MakeQuickSnapshot(); if (SourceFileContentsChanged != null) SourceFileContentsChanged(contents); } } } } catch (Exception err) { Program.ErrorHandeler(this, new ThreadExceptionEventArgs(err)); } } }
private void CompileThread() { Thread.CurrentThread.CurrentCulture = new CultureInfo(Form1.Language); Thread.CurrentThread.CurrentUICulture = new CultureInfo(Form1.Language); try { if (!compilingFromCommandLine) form.SetStatusText(LocRM.GetString("GC_Text3")); if (!compilingFromCommandLine) ClearErrorWindow(); //Build a tree with all sourcefiles AAProgram root = new AAProgram(); ErrorCollection errors = new ErrorCollection(); currentErrorCollection = errors; if (!compilingFromCommandLine) errors.ErrorAdded += errors_ErrorAdded; bool addedDeobfuscator = false; SharedData sharedData = new SharedData(); sharedData.AllowPrintouts = !compilingFromCommandLine; //Parse project files List<string> fileNames = new List<string>(); List<string> sources = new List<string>(); foreach ( FileItem sourceFile in Form1.GetSourceFiles(ProjectProperties.CurrentProjectPropperties.SrcFolder)) { if (sourceFile.Deactivated) continue; StreamReader reader = sourceFile.File.OpenText(); string filename = sourceFile.File.FullName; //Remove c:/.../projectDir/src filename = filename.Remove(0, (ProjectDir.FullName + "/src/").Length); //Remove .galaxy++ filename = filename.Remove(filename.Length - ".galaxy++".Length); fileNames.Add(filename); sources.Add(reader.ReadToEnd()); reader.Close(); continue; Parser parser = new Parser(new Lexer(reader)); try { Start start = parser.Parse(); AASourceFile sourceNode = (AASourceFile) start.GetPSourceFile(); reader.Close(); reader = sourceFile.File.OpenText(); int lineCount = 0; while (reader.ReadLine() != null) { lineCount++; } reader.Close(); sharedData.LineCounts[sourceNode] = lineCount; //Extract encryption function /* { AASourceFile file = (AASourceFile) start.GetPSourceFile(); if (file.GetDecl().Count > 0 && file.GetDecl()[0] is AMethodDecl) { AMethodDecl method = (AMethodDecl) file.GetDecl()[0]; if (method.GetName().Text == "Galaxy_pp_Deobfuscate") { FileInfo dobfuscateFile = new FileInfo("Deobfuscator.LibraryData"); IFormatter formatter = new BinaryFormatter(); Stream stream = dobfuscateFile.Open(FileMode.Create); formatter.Serialize(stream, method); stream.Close(); } } }*/ if (Options.Compiler.ObfuscateStrings) { HasStringConstExp checker = new HasStringConstExp(); start.Apply(checker); if (!addedDeobfuscator /* && checker.HasStringConst*/) { FileInfo dobfuscateFile = new FileInfo("Deobfuscator.LibraryData"); IFormatter formatter = new BinaryFormatter(); Stream stream = dobfuscateFile.Open(FileMode.Open); AASourceFile file = (AASourceFile) start.GetPSourceFile(); AMethodDecl method = (AMethodDecl) formatter.Deserialize(stream); sharedData.DeobfuscateMethod = method; method.GetName().Line = 0; HasStringConstExp checker2 = new HasStringConstExp(); method.Apply(checker2); file.GetDecl().Insert(0, method); stream.Close(); addedDeobfuscator = true; foreach (AStringConstExp stringConstExp in checker2.List) { int line = -sharedData.UnobfuscatedStrings.Count - 1; AFieldDecl field = new AFieldDecl(new APublicVisibilityModifier(), null, new TConst("const", line, 0), new ANamedType(new TIdentifier("string", line, 1), null), new TIdentifier("Galaxy_pp_stringU" + sharedData.UnobfuscatedStrings. Count), null); //If the strings are the same - point them to same field bool newField = true; foreach (AStringConstExp oldStringConstExp in sharedData.UnobfuscatedStrings.Keys) { if (stringConstExp.GetStringLiteral().Text == oldStringConstExp.GetStringLiteral().Text) { field = sharedData.UnobfuscatedStrings[oldStringConstExp]; newField = false; break; } } if (newField) { file.GetDecl().Insert(0, field); sharedData.ObfuscationFields.Add(field); } sharedData.UnobfuscatedStrings.Add(stringConstExp, field); } } foreach (AStringConstExp stringConstExp in checker.List) { int line = -sharedData.ObfuscatedStrings.Count - 1; AFieldDecl field = new AFieldDecl(new APublicVisibilityModifier(), null, new TConst("const", line, 0), new ANamedType(new TIdentifier("string", line, 1), null), new TIdentifier("Galaxy_pp_stringO" + sharedData.ObfuscatedStrings.Count), null); //If the strings are the same - point them to same field bool newField = true; foreach (AStringConstExp oldStringConstExp in sharedData.ObfuscatedStrings.Keys) { if (stringConstExp.GetStringLiteral().Text == oldStringConstExp.GetStringLiteral().Text) { field = sharedData.ObfuscatedStrings[oldStringConstExp]; newField = false; break; } } if (newField) { AASourceFile file = (AASourceFile) sharedData.DeobfuscateMethod.Parent(); file.GetDecl().Insert(file.GetDecl().IndexOf(sharedData.DeobfuscateMethod) + 1, field); sharedData.ObfuscationFields.Add(field); } sharedData.ObfuscatedStrings.Add(stringConstExp, field); } } sourceNode.SetName(new TIdentifier(filename)); root.GetSourceFiles().Add(start.GetPSourceFile()); } catch (ParserException err) { String errMsg = err.Message; //Remove [...] errMsg = errMsg.Substring(errMsg.IndexOf(']') + 1).TrimStart(); errors.Add(new ErrorCollection.Error(err.Token, filename, errMsg)); } reader.Close(); } //Parse project dialogs foreach ( DialogItem dialogItem in Form1.GetDialogsFiles(ProjectProperties.CurrentProjectPropperties.SrcFolder)) { if (dialogItem.Deactivated) continue; // List<string> fileNames = new List<string>(); // List<string> sources = new List<string>(); DialogData data; if (dialogItem.OpenFileData != null) { data = dialogItem.OpenFileData; data.Save(dialogItem.FullName); } else { data = DialogData.Load(dialogItem.FullName); data.DialogItem = dialogItem; } string filename = dialogItem.FullName; filename = filename.Remove(0, (ProjectDir.FullName + "/src/").Length); filename = filename.Remove(filename.Length - ".Dialog".Length); fileNames.Add(filename); sources.Add(data.Code ?? ""); fileNames.Add(filename + ".Designer"); sources.Add(data.DesignerCode ?? ""); continue; for (int i = 0; i < fileNames.Count; i++) { filename = fileNames[i]; StringReader reader = new StringReader(sources[i] ?? ""); Parser parser = new Parser(new Lexer(reader)); try { Start start = parser.Parse(); AASourceFile sourceNode = (AASourceFile) start.GetPSourceFile(); reader.Close(); reader.Dispose(); reader = new StringReader(sources[i] ?? ""); int lineCount = 0; while (reader.ReadLine() != null) { lineCount++; } reader.Close(); sharedData.LineCounts[sourceNode] = lineCount; if (Options.Compiler.ObfuscateStrings) { HasStringConstExp checker = new HasStringConstExp(); start.Apply(checker); if (!addedDeobfuscator /* && checker.HasStringConst*/) { FileInfo dobfuscateFile = new FileInfo("Deobfuscator.LibraryData"); IFormatter formatter = new BinaryFormatter(); Stream stream = dobfuscateFile.Open(FileMode.Open); AASourceFile file = (AASourceFile) start.GetPSourceFile(); AMethodDecl method = (AMethodDecl) formatter.Deserialize(stream); sharedData.DeobfuscateMethod = method; method.GetName().Line = 0; HasStringConstExp checker2 = new HasStringConstExp(); method.Apply(checker2); file.GetDecl().Insert(0, method); stream.Close(); addedDeobfuscator = true; foreach (AStringConstExp stringConstExp in checker2.List) { int line = -sharedData.UnobfuscatedStrings.Count - 1; AFieldDecl field = new AFieldDecl(new APublicVisibilityModifier(), null, new TConst("const", line, 0), new ANamedType( new TIdentifier("string", line, 1), null), new TIdentifier("Galaxy_pp_stringU" + sharedData.UnobfuscatedStrings . Count), null); //If the strings are the same - point them to same field bool newField = true; foreach ( AStringConstExp oldStringConstExp in sharedData.UnobfuscatedStrings.Keys) { if (stringConstExp.GetStringLiteral().Text == oldStringConstExp.GetStringLiteral().Text) { field = sharedData.UnobfuscatedStrings[oldStringConstExp]; newField = false; break; } } if (newField) { file.GetDecl().Insert(0, field); sharedData.ObfuscationFields.Add(field); } sharedData.UnobfuscatedStrings.Add(stringConstExp, field); } } foreach (AStringConstExp stringConstExp in checker.List) { int line = -sharedData.ObfuscatedStrings.Count - 1; AFieldDecl field = new AFieldDecl(new APublicVisibilityModifier(), null, new TConst("const", line, 0), new ANamedType(new TIdentifier("string", line, 1), null), new TIdentifier("Galaxy_pp_stringO" + sharedData.ObfuscatedStrings.Count), null); //If the strings are the same - point them to same field bool newField = true; foreach (AStringConstExp oldStringConstExp in sharedData.ObfuscatedStrings.Keys) { if (stringConstExp.GetStringLiteral().Text == oldStringConstExp.GetStringLiteral().Text) { field = sharedData.ObfuscatedStrings[oldStringConstExp]; newField = false; break; } } if (newField) { AASourceFile file = (AASourceFile) sharedData.DeobfuscateMethod.Parent(); file.GetDecl().Insert(file.GetDecl().IndexOf(sharedData.DeobfuscateMethod) + 1, field); sharedData.ObfuscationFields.Add(field); } sharedData.ObfuscatedStrings.Add(stringConstExp, field); } } sourceNode.SetName(new TIdentifier(filename)); root.GetSourceFiles().Add(start.GetPSourceFile()); } catch (ParserException err) { String errMsg = err.Message; //Remove [...] errMsg = errMsg.Substring(errMsg.IndexOf(']') + 1).TrimStart(); errors.Add(new ErrorCollection.Error(err.Token, filename, errMsg)); } reader.Close(); } } // Preprocessor.Parse(sources, errors); for (int i = 0; i < fileNames.Count; i++) { string filename = fileNames[i]; StringReader reader = new StringReader(sources[i] ?? ""); Parser parser = new Parser(new Lexer(reader)); try { Start start = parser.Parse(); AASourceFile sourceNode = (AASourceFile)start.GetPSourceFile(); reader.Close(); reader.Dispose(); reader = new StringReader(sources[i] ?? ""); int lineCount = 0; while (reader.ReadLine() != null) { lineCount++; } reader.Close(); sharedData.LineCounts[sourceNode] = lineCount; //Extract encryption function /*{ AASourceFile file = (AASourceFile) start.GetPSourceFile(); if (file.GetDecl().Count > 0 && file.GetDecl()[0] is AMethodDecl) { AMethodDecl method = (AMethodDecl) file.GetDecl()[0]; if (method.GetName().Text == "Galaxy_pp_Deobfuscate") { FileInfo dobfuscateFile = new FileInfo("Deobfuscator.LibraryData"); IFormatter formatter = new BinaryFormatter(); Stream stream = dobfuscateFile.Open(FileMode.Create); formatter.Serialize(stream, method); stream.Close(); } } }*/ if (Options.Compiler.ObfuscateStrings) { HasStringConstExp checker = new HasStringConstExp(); start.Apply(checker); if (!addedDeobfuscator /* && checker.HasStringConst*/) { FileInfo dobfuscateFile = new FileInfo("Deobfuscator.LibraryData"); IFormatter formatter = new BinaryFormatter(); Stream stream = dobfuscateFile.Open(FileMode.Open); AASourceFile file = (AASourceFile)start.GetPSourceFile(); AMethodDecl method = (AMethodDecl)formatter.Deserialize(stream); sharedData.DeobfuscateMethod = method; method.GetName().Line = 0; HasStringConstExp checker2 = new HasStringConstExp(); method.Apply(checker2); file.GetDecl().Insert(0, method); stream.Close(); addedDeobfuscator = true; foreach (AStringConstExp stringConstExp in checker2.List) { int line = -sharedData.UnobfuscatedStrings.Count - 1; AFieldDecl field = new AFieldDecl(new APublicVisibilityModifier(), null, new TConst("const", line, 0), new ANamedType( new TIdentifier("string", line, 1), null), new TIdentifier("Galaxy_pp_stringU" + sharedData.UnobfuscatedStrings . Count), null); //If the strings are the same - point them to same field bool newField = true; foreach ( AStringConstExp oldStringConstExp in sharedData.UnobfuscatedStrings.Keys) { if (stringConstExp.GetStringLiteral().Text == oldStringConstExp.GetStringLiteral().Text) { field = sharedData.UnobfuscatedStrings[oldStringConstExp]; newField = false; break; } } if (newField) { file.GetDecl().Insert(0, field); sharedData.ObfuscationFields.Add(field); } sharedData.UnobfuscatedStrings.Add(stringConstExp, field); } } foreach (AStringConstExp stringConstExp in checker.List) { int line = -sharedData.ObfuscatedStrings.Count - 1; AFieldDecl field = new AFieldDecl(new APublicVisibilityModifier(), null, new TConst("const", line, 0), new ANamedType(new TIdentifier("string", line, 1), null), new TIdentifier("Galaxy_pp_stringO" + sharedData.ObfuscatedStrings.Count), null); //If the strings are the same - point them to same field bool newField = true; foreach (AStringConstExp oldStringConstExp in sharedData.ObfuscatedStrings.Keys) { if (stringConstExp.GetStringLiteral().Text == oldStringConstExp.GetStringLiteral().Text) { field = sharedData.ObfuscatedStrings[oldStringConstExp]; newField = false; break; } } if (newField) { AASourceFile file = (AASourceFile)sharedData.DeobfuscateMethod.Parent(); file.GetDecl().Insert(file.GetDecl().IndexOf(sharedData.DeobfuscateMethod) + 1, field); sharedData.ObfuscationFields.Add(field); } sharedData.ObfuscatedStrings.Add(stringConstExp, field); } } sourceNode.SetName(new TIdentifier(filename)); root.GetSourceFiles().Add(start.GetPSourceFile()); } catch (ParserException err) { String errMsg = err.Message; //Remove [...] errMsg = errMsg.Substring(errMsg.IndexOf(']') + 1).TrimStart(); errors.Add(new ErrorCollection.Error(err.Token, filename, errMsg)); } reader.Close(); } //Load libraries foreach (Library lib in ProjectProperties.CurrentProjectPropperties.Libraries) { foreach (KeyValuePair<Library.File, string> sourceFile in lib.GetFiles()) { StringReader sReader = new StringReader(sourceFile.Key.Text); { Parser parser = new Parser(new Lexer(sReader)); try { Start start = parser.Parse(); AASourceFile sourceNode = (AASourceFile) start.GetPSourceFile(); sReader.Close(); sReader.Dispose(); sReader = new StringReader(sourceFile.Key.Text); int lineCount = 0; while (sReader.ReadLine() != null) { lineCount++; } sReader.Close(); sReader.Dispose(); sharedData.LineCounts[sourceNode] = lineCount; if (Options.Compiler.ObfuscateStrings) { HasStringConstExp checker = new HasStringConstExp(); start.Apply(checker); if (!addedDeobfuscator /* && checker.HasStringConst*/) { FileInfo dobfuscateFile = new FileInfo("Deobfuscator.LibraryData"); IFormatter formatter = new BinaryFormatter(); Stream stream = dobfuscateFile.Open(FileMode.Open); AASourceFile file = (AASourceFile) start.GetPSourceFile(); AMethodDecl method = (AMethodDecl) formatter.Deserialize(stream); sharedData.DeobfuscateMethod = method; method.GetName().Line = 0; HasStringConstExp checker2 = new HasStringConstExp(); method.Apply(checker2); file.GetDecl().Insert(0, method); stream.Close(); addedDeobfuscator = true; foreach (AStringConstExp stringConstExp in checker2.List) { int line = -sharedData.UnobfuscatedStrings.Count - 1; AFieldDecl field = new AFieldDecl(new APublicVisibilityModifier(), null, new TConst("const", line, 0), new ANamedType( new TIdentifier("string", line, 1), null), new TIdentifier("Galaxy_pp_stringU" + sharedData. UnobfuscatedStrings . Count), null); //If the strings are the same - point them to same field bool newField = true; foreach ( AStringConstExp oldStringConstExp in sharedData.UnobfuscatedStrings.Keys ) { if (stringConstExp.GetStringLiteral().Text == oldStringConstExp.GetStringLiteral().Text) { field = sharedData.UnobfuscatedStrings[oldStringConstExp]; newField = false; break; } } if (newField) { file.GetDecl().Insert(0, field); sharedData.ObfuscationFields.Add(field); } sharedData.UnobfuscatedStrings.Add(stringConstExp, field); } } foreach (AStringConstExp stringConstExp in checker.List) { int line = -sharedData.ObfuscatedStrings.Count - 1; AFieldDecl field = new AFieldDecl(new APublicVisibilityModifier(), null, new TConst("const", line, 0), new ANamedType( new TIdentifier("string", line, 1), null), new TIdentifier("Galaxy_pp_stringO" + sharedData.ObfuscatedStrings. Count), null); //If the strings are the same - point them to same field bool newField = true; foreach (AStringConstExp oldStringConstExp in sharedData.ObfuscatedStrings.Keys) { if (stringConstExp.GetStringLiteral().Text == oldStringConstExp.GetStringLiteral().Text) { field = sharedData.ObfuscatedStrings[oldStringConstExp]; newField = false; break; } } if (newField) { AASourceFile file = (AASourceFile) sharedData.DeobfuscateMethod.Parent(); file.GetDecl().Insert( file.GetDecl().IndexOf(sharedData.DeobfuscateMethod) + 1, field); sharedData.ObfuscationFields.Add(field); } sharedData.ObfuscatedStrings.Add(stringConstExp, field); } } sourceNode.SetName(new TIdentifier(sourceFile.Value)); root.GetSourceFiles().Add(start.GetPSourceFile()); } catch (ParserException err) { String errMsg = err.Message; //Remove [...] errMsg = errMsg.Substring(errMsg.IndexOf(']') + 1).TrimStart(); errors.Add(new ErrorCollection.Error(err.Token, sourceFile.Value, errMsg)); } } } } string rootFileName = ""; DirectoryInfo outputDir = ProjectDir.CreateSubdirectory("output"); try { if (!compilingFromCommandLine) form.SetStatusText(LocRM.GetString("GC_Text4")); sharedData.Libraries = libraryData; Weeder.Parse(root, errors, sharedData); if (!compilingFromCommandLine) form.SetStatusText(LocRM.GetString("GC_Text5")); if (!errors.HasErrors) EnviromentBuilding.Parse(root, errors, sharedData); if (!compilingFromCommandLine) form.SetStatusText(LocRM.GetString("GC_Text6")); if (!errors.HasErrors) EnviromentChecking.Parse(root, errors, sharedData); if (!compilingFromCommandLine) form.SetStatusText(LocRM.GetString("GC_Text7")); if (!errors.HasErrors) root.Apply(new LinkNamedTypes(errors, sharedData)); if (!compilingFromCommandLine) form.SetStatusText(LocRM.GetString("GC_Text8")); if (!errors.HasErrors) root.Apply(new FixGenerics(errors, sharedData)); if (!compilingFromCommandLine) form.SetStatusText(LocRM.GetString("GC_Text9")); if (!errors.HasErrors) root.Apply(new Enheritance(sharedData, errors)); if (!compilingFromCommandLine) form.SetStatusText(LocRM.GetString("GC_Text10")); if (!errors.HasErrors) TypeLinking.Parse(root, errors, sharedData); if (!compilingFromCommandLine) form.SetStatusText(LocRM.GetString("GC_Text11")); if (!errors.HasErrors) TypeChecking.Parse(root, errors, sharedData); if (!errors.HasErrors) root.Apply(new MakeEnrichmentLinks(sharedData, errors)); if (!errors.HasErrors) root.Apply(new SetArrayIndexes(sharedData, errors)); if (!compilingFromCommandLine) form.SetStatusText(LocRM.GetString("GC_Text12")); if (!errors.HasErrors) FinalTransformations.Parse(root, errors, sharedData, out rootFileName); if (!compilingFromCommandLine) form.SetStatusText(LocRM.GetString("GC_Text13")); if (!errors.HasErrors) CodeGeneration.Parse(root, errors, sharedData, outputDir); if (!errors.HasErrors) GenerateBankPreloadFile.Generate(sharedData, outputDir); } catch (ParserException err) { } Compiling = false; if (!errors.HasErrors) { if (!compilingFromCommandLine) form.SetStatusText(LocRM.GetString("GC_Text14")); ProjectProperties.CurrentProjectPropperties.RootFileName = rootFileName; ProjectProperties.CurrentProjectPropperties.CompileStatus = ProjectProperties.ECompileStatus.SuccessfullyCompiled; if (CompilationSuccessfull != null) CompilationSuccessfull(); } else { if (!compilingFromCommandLine) form.SetStatusText(LocRM.GetString("GC_Text15")); if (CompilationFailed != null) CompilationFailed(); } } #if DEBUG finally { } #else catch (Exception error) { Compiling = false; //Program.ErrorHandeler(this, new ThreadExceptionEventArgs(error)); new ExceptionForm(error, true).ShowDialog(); form.SetStatusText("Critical compile error"); if (CompilationFailed != null) CompilationFailed(); } #endif }
public void CompileLibrary(DirectoryInfo libraryDir, StreamWriter writer) { AAProgram root = new AAProgram(); ErrorCollection errors = new ErrorCollection(); foreach (FileInfo file in GetSourceFiles(libraryDir)) { //Replace keywords StreamReader reader = file.OpenText(); StringBuilder text = new StringBuilder(""); string[] keywords = new[] {"ref", "out", "InvokeSync", "InvokeAsync", "switch", "case", "default", "new", "delete", "this","delegate", "value", "base", "inline", "namespace", "using", "Trigger", "Initializer", "events", "conditions", "actions", "class", "typedef", "get", "set", "enrich", "public", "private", "protected", "LibraryName", "LibraryVersion", "SupportedVersions", "RequiredLibraries", "global"}; int i; StringBuilder currentIdentifier = new StringBuilder(""); while ((i = reader.Read()) != -1) { if (Util.IsIdentifierLetter((char)i)) { currentIdentifier.Append((char)i); } else { if (currentIdentifier.Length > 0) { string identifier = currentIdentifier.ToString(); currentIdentifier.Clear(); if (keywords.Contains(identifier)) { identifier = "_" + identifier; } text.Append(identifier); } text.Append((char) i); } } Parser parser = new Parser(new Lexer(new StringReader(text.ToString()))); try { Start start = parser.Parse(); AASourceFile srcFile = (AASourceFile) start.GetPSourceFile(); srcFile.SetName(new TIdentifier(file.FullName.Substring(libraryDir.FullName.Length + 1))); root.GetSourceFiles().Add(srcFile); } catch (ParserException err) { errors.Add(new ErrorCollection.Error(err.Token, file.Name, err.Message, false)); } reader.Close(); } try { Weeder.Parse(root, errors, new SharedData()); LibraryData lib = new LibraryData(root, writer); FileInfo precompFile = new FileInfo(libraryDir.FullName + "\\Precompiled.LibraryData"); IFormatter formatter = new BinaryFormatter(); Stream stream = precompFile.Open(FileMode.Create); formatter.Serialize(stream, lib); stream.Close(); } catch (Exception err) { } if (errors.HasErrors) MessageBox.Show("Errors in libray " + libraryDir.Name); }