public Error(Token pos, AASourceFile sourceFile, string message, bool warning = false, params TreeNode[] children) { this.pos = new TextPoint(pos.Line - 1, pos.Pos - 1); FileName = sourceFile == null || sourceFile.GetName() == null ? "Library file" : sourceFile.GetName().Text; Message = message; Warning = warning; Text = ToString(); if (children.Length > 0) Nodes.AddRange(children); SelectedImageIndex = ImageIndex = warning ? 1 : 0; }
public virtual void CaseAASourceFile(AASourceFile node) { DefaultCase(node); }
public override void InAASourceFile(AASourceFile node) { dependancies.Add(node, new List<AASourceFile>()); }
internal Decl_Cast(AASourceFile obj) { this.obj = obj; }
private static void GetReachable(AASourceFile node, Dictionary<AASourceFile, List<AASourceFile>> dependancies, ref List<AASourceFile> reachable) { if (reachable.Contains(node)) return; reachable.Add(node); if (node != null) foreach (AASourceFile file in dependancies[node]) { GetReachable(file, dependancies, ref reachable); } }
private static void RemoveCycles(AASourceFile file, Dictionary<AASourceFile, List<AASourceFile>> dependancies, List<AASourceFile> path) { if (file == null) return; for (int i = 0; i < dependancies[file].Count; i++) { AASourceFile nextFile = dependancies[file][i]; if (path.Contains(nextFile)) dependancies[file].RemoveAt(i--); else { path.Add(nextFile); RemoveCycles(nextFile, dependancies, path); path.Remove(nextFile); } } }
ArrayList New3() { ArrayList nodeList = new ArrayList(); ArrayList nodeArrayList2 = (ArrayList) Pop(); ArrayList nodeArrayList1 = (ArrayList) Pop(); TypedList listNode3 = new TypedList(); TypedList listNode6 = new TypedList(); TypedList listNode2 = (TypedList)nodeArrayList2[0]; if ( listNode2 != null ) { listNode3.AddAll(listNode2); } TypedList listNode5 = (TypedList)nodeArrayList1[0]; if ( listNode5 != null ) { listNode6.AddAll(listNode5); } AASourceFile psourcefileNode1 = new AASourceFile ( listNode3, null, listNode6 ); nodeList.Add(psourcefileNode1); return nodeList; }
public static void Apply(AAProgram ast, FinalTransformations finalTrans) { //Build list of file dependacies Phase1 phase1 = new Phase1(finalTrans); ast.Apply(phase1); var dependancies = phase1.dependancies; if (dependancies.Keys.Count == 0) return; AASourceFile root = Util.GetAncestor<AASourceFile>(finalTrans.mainEntry) ?? dependancies.Keys.FirstOrDefault(file => !file.GetName().Text.Contains("\\")) ?? dependancies.Keys.First(file => true); //Remove files unreachable from root //On second thought, dont. there might be static refferences the other way which needs to be included /*{ List<AASourceFile> reachable = GetReachable(root, dependancies); AASourceFile[] keys = new AASourceFile[dependancies.Count]; dependancies.Keys.CopyTo(keys, 0); foreach (AASourceFile key in keys) { if (!reachable.Contains(key)) dependancies.Remove(key); } }*/ //Push common depancies up /* * root -> (item1 -> (item3), item2 -> (item4 -> (item3))) * * root -> (item3, item1, item2 -> (item4)) */ //Add unreachable to the root while (true) { List<AASourceFile> reachable = new List<AASourceFile>(); GetReachable(root, dependancies, ref reachable); if (reachable.Count == dependancies.Count + (reachable.Contains(null) ? 1 : 0)) break; AASourceFile[] keys = new AASourceFile[dependancies.Count]; dependancies.Keys.CopyTo(keys, 0); foreach (AASourceFile key in keys) { if (!reachable.Contains(key)) { AASourceFile k = key; //See if you can find another unreachable file which need this file Dictionary<AASourceFile, int> decendantCounts = new Dictionary<AASourceFile, int>(); decendantCounts.Add(k, CountDecendants(k, dependancies, new List<AASourceFile>())); while (true) { AASourceFile file = null; foreach (KeyValuePair<AASourceFile, List<AASourceFile>> dependancy in dependancies) { if (decendantCounts.ContainsKey(dependancy.Key)) continue; if (!dependancy.Value.Contains(k)) continue; file = dependancy.Key; break; } //AASourceFile file = dependancies.FirstOrDefault(item => item.Value.Contains(k)).Key; if (file == null) break; decendantCounts.Add(file, CountDecendants(file, dependancies, new List<AASourceFile>())); k = file; } foreach (KeyValuePair<AASourceFile, int> decendantItem in decendantCounts) { if (decendantItem.Value > decendantCounts[k]) k = decendantItem.Key; } dependancies[root].Add(k); break; } } } //It is moved down here because cycles are not removed in unreachable RemoveCycles(root, dependancies, new List<AASourceFile> { root }); //Convert to tree to make it easier List<Item> allItems = new List<Item>(); IncludeItem rootIncludeItem = MakeTree(root, dependancies, allItems, null); bool[] removed = new bool[allItems.Count]; for (int i = 0; i < removed.Length; i++) removed[i] = false; int removedCount = 0; //Ensure that each include is only included one place for (int i = 0; i < allItems.Count; i++) { if (removed[i]) continue; IncludeItem item1 = (IncludeItem)allItems[i]; for (int j = i + 1; j < allItems.Count; j++) { if (removed[j]) continue; IncludeItem item2 = (IncludeItem)allItems[j]; if (item1.Current == item2.Current) { List<Item> path1 = item1.Path; List<Item> path2 = item2.Path; for (int k = 0; k < Math.Min(path1.Count, path2.Count); k++) { if (path1[k] != path2[k]) { int insertAt = Math.Min(path1[k - 1].Children.IndexOf(path1[k]), path2[k - 1].Children.IndexOf(path2[k])); item1.Parent.Children.Remove(item1); LinkedList<IncludeItem> toRemove = new LinkedList<IncludeItem>(); toRemove.AddLast(item2); while (toRemove.Count > 0) { IncludeItem item = toRemove.First.Value; toRemove.RemoveFirst(); item.Parent.Children.Remove(item); //allItems.Remove(item); removedCount++; removed[item.ListIndex] = true; foreach (IncludeItem child in item.Children) { toRemove.AddLast(child); } } //j--; path1[k - 1].Children.Insert(insertAt, item1); item1.Parent = path1[k - 1]; break; } } } } } List<Item> newAllItems = new List<Item>(allItems.Count - removedCount); for (int i = 0; i < allItems.Count; i++) if (!removed[i]) newAllItems.Add(allItems[i]); allItems = newAllItems; //Move the null node to nr [0] foreach (IncludeItem item in allItems) { if (item.Current == null) { int itemIndex = item.Parent.Children.IndexOf(item); Item item0 = item.Parent.Children[0]; item.Parent.Children[0] = item; item.Parent.Children[itemIndex] = item0; break; } } //Insert method decls and move structs & fields up as needed ast.Apply(new Phase2(finalTrans, allItems)); //Insert the headers in the files if (Options.Compiler.OneOutputFile) { //for (int i = 0; i < allItems.Count; i++) int i = 0; while (allItems.Count > 0) { if (allItems[i] is IncludeItem) { IncludeItem includeItem = (IncludeItem) allItems[i]; //Dont want the standard lib if (includeItem.Current == null) { i++; continue; } //If it has children with children, then pick another first if (includeItem.Children.Any(child => child.Children.Count > 0)) { i++; continue; } if (includeItem.Children.Count == 0) { if (includeItem.Parent == null) break; i++; continue; } i = 0; //Put all children into this while (includeItem.Children.Count > 0) { int childNr = includeItem.Children.Count - 1; allItems.Remove(includeItem.Children[childNr]); if (includeItem.Children[childNr] is FieldItem) { FieldItem aItem = (FieldItem)includeItem.Children[childNr]; Node node = aItem.FieldDecl; node.Parent().RemoveChild(node); includeItem.Current.GetDecl().Insert(0, node); } else if (includeItem.Children[childNr] is StructItem) { StructItem aItem = (StructItem)includeItem.Children[childNr]; Node node = aItem.StructDecl; node.Parent().RemoveChild(node); includeItem.Current.GetDecl().Insert(0, node); } else if (includeItem.Children[childNr] is MethodDeclItem) { MethodDeclItem aItem = (MethodDeclItem)includeItem.Children[childNr]; AMethodDecl aNode = new AMethodDecl(); if (aItem.RealDecl.GetStatic() != null) aNode.SetStatic(new TStatic("static")); aNode.SetReturnType(Util.MakeClone(aItem.RealDecl.GetReturnType(), finalTrans.data)); aNode.SetName(new TIdentifier(aItem.RealDecl.GetName().Text)); foreach (AALocalDecl formal in aItem.RealDecl.GetFormals()) { AALocalDecl clone = new AALocalDecl(new APublicVisibilityModifier(), null, null, null, null, Util.MakeClone(formal.GetType(), finalTrans.data), new TIdentifier(formal.GetName().Text), null); aNode.GetFormals().Add(clone); } includeItem.Current.GetDecl().Insert(0, aNode); } else if (includeItem.Children[childNr] is IncludeItem) { IncludeItem aChild = (IncludeItem)includeItem.Children[childNr]; if (aChild.Current == null) { AIncludeDecl node = new AIncludeDecl(new TInclude("include"), new TStringLiteral("\"TriggerLibs/NativeLib\"")); includeItem.Current.GetDecl().Insert(0, node); } else { PDecl[] decls = new PDecl[aChild.Current.GetDecl().Count]; aChild.Current.GetDecl().CopyTo(decls, 0); for (int k = decls.Length - 1; k >= 0; k--) { includeItem.Current.GetDecl().Insert(0, decls[k]); } aChild.Current.Parent().RemoveChild(aChild.Current); //i = -1; } } includeItem.Children.RemoveAt(childNr); } } } } else foreach (IncludeItem includeItem in allItems.OfType<IncludeItem>()) { for (int i = includeItem.Children.Count - 1; i >= 0; i--) { Node node; if (includeItem.Children[i] is IncludeItem) { IncludeItem aItem = (IncludeItem) includeItem.Children[i]; node = new AIncludeDecl(new TInclude("include"), new TStringLiteral("\"" + (aItem.Current == null ? "TriggerLibs/NativeLib" : aItem.Current.GetName().Text.Replace("\\", "/")) + "\"")); if (aItem.Current == null && finalTrans.mainEntry != null) { //Search for user defined initlib bool foundInvoke = false; foreach (ASimpleInvokeExp invokeExp in finalTrans.data.SimpleMethodLinks.Keys) { if(invokeExp.GetName().Text == "libNtve_InitLib" && invokeExp.GetArgs().Count == 0) { /*finalTrans.errors.Add(new ErrorCollection.Error(invokeExp.GetName(), Util.GetAncestor<AASourceFile>( invokeExp), "You are invoking libNtve_InitLib() yourself somewhere. It will not be auto inserted.", true));*/ foundInvoke = true; break; } } if (!foundInvoke) { //Init the lib ASimpleInvokeExp initExp = new ASimpleInvokeExp(); initExp.SetName(new TIdentifier("libNtve_InitLib")); finalTrans.data.ExpTypes[initExp] = new AVoidType(new TVoid("void")); foreach (AMethodDecl method in finalTrans.data.Libraries.Methods) { if (method.GetName().Text == "libNtve_InitLib" && method.GetFormals().Count == 0) { finalTrans.data.SimpleMethodLinks[initExp] = method; } } AABlock block = (AABlock) finalTrans.mainEntry.GetBlock(); block.GetStatements().Insert(0, new AExpStm(new TSemicolon(";"), initExp)); } } } else if (includeItem.Children[i] is FieldItem) { FieldItem aItem = (FieldItem)includeItem.Children[i]; node = aItem.FieldDecl; node.Parent().RemoveChild(node); } else if (includeItem.Children[i] is StructItem) { StructItem aItem = (StructItem)includeItem.Children[i]; node = aItem.StructDecl; node.Parent().RemoveChild(node); } else if (includeItem.Children[i] is MethodDeclItem) { MethodDeclItem aItem = (MethodDeclItem)includeItem.Children[i]; AMethodDecl aNode = new AMethodDecl(); if (aItem.RealDecl.GetStatic() != null) aNode.SetStatic(new TStatic("static")); aNode.SetReturnType(Util.MakeClone(aItem.RealDecl.GetReturnType(), finalTrans.data)); aNode.SetName(new TIdentifier(aItem.RealDecl.GetName().Text)); foreach (AALocalDecl formal in aItem.RealDecl.GetFormals()) { AALocalDecl clone = new AALocalDecl(new APublicVisibilityModifier(), null, null, null, null, Util.MakeClone(formal.GetType(), finalTrans.data), new TIdentifier(formal.GetName().Text), null); aNode.GetFormals().Add(clone); } node = aNode; } else throw new Exception("FixIncludes.Apply: Unexpected item type"); includeItem.Current.GetDecl().Insert(0, node); } } }
ArrayList New0() { ArrayList nodeList = new ArrayList(); TypedList listNode2 = new TypedList(); TypedList listNode4 = new TypedList(); AASourceFile psourcefileNode1 = new AASourceFile ( listNode2, null, listNode4 ); nodeList.Add(psourcefileNode1); return nodeList; }
ArrayList New1() { ArrayList nodeList = new ArrayList(); ArrayList nodeArrayList1 = (ArrayList) Pop(); TypedList listNode2 = new TypedList(); TypedList listNode5 = new TypedList(); TypedList listNode4 = (TypedList)nodeArrayList1[0]; if ( listNode4 != null ) { listNode5.AddAll(listNode4); } AASourceFile psourcefileNode1 = new AASourceFile ( listNode2, null, listNode5 ); nodeList.Add(psourcefileNode1); return nodeList; }
public override void CaseAASourceFile(AASourceFile node) { currentFile = node; base.CaseAASourceFile(node); /* return; if (!doChecks) { base.CaseAASourceFile(node); return; } //Check that there are no dublicates in visible files List<AASourceFile> visibleFiles = new List<AASourceFile>(); AAProgram program = (AAProgram) node.Parent(); foreach (AASourceFile sourceFile in program.GetSourceFiles()) { if (Util.IsVisible(node, sourceFile)) visibleFiles.Add(sourceFile); } List<AASourceFile> leftSide = new List<AASourceFile>(); Dictionary<AASourceFile, List<AASourceFile>> rightSides = new Dictionary<AASourceFile, List<AASourceFile>>(); for (int i = 0; i < visibleFiles.Count; i++) { AASourceFile file1 = visibleFiles[i]; List<AASourceFile> rightSide = new List<AASourceFile>(); if (file1 == node) { rightSide.AddRange(visibleFiles); } else { for (int j = i + 1; j < visibleFiles.Count; j++) { AASourceFile file2 = visibleFiles[j]; bool add = true; foreach (List<AASourceFile> files in handeledNamespaces) { if (files.Contains(file1) && files.Contains(file2)) { add = false; break; } } if (add) { rightSide.Add(file2); } } } if (rightSide.Count > 0) { leftSide.Add(file1); rightSides.Add(file1, rightSide); } } handeledNamespaces.Add(visibleFiles); //for (int i = 0; i < visibleFiles.Count; i++) foreach (AASourceFile file1 in leftSide) { PDecl[] decls1 = file1.GetDecl().OfType<PDecl>().ToArray(); // AASourceFile file1 = visibleFiles[i]; //for (int j = i + 1; j < visibleFiles.Count; j++) foreach (AASourceFile file2 in rightSides[file1]) { PDecl[] decls2 = file2.GetDecl().OfType<PDecl>().ToArray(); //AASourceFile file2 = visibleFiles[j]; for (int decl1Index = 0; decl1Index < decls1.Length; decl1Index++) { PDecl decl1 = decls1[decl1Index]; if (!Util.IsDeclVisible(decl1, node)) continue; for (int decl2Index = file1 == file2 ? decl1Index + 1 : 0; decl2Index < decls2.Length; decl2Index++) { PDecl decl2 = (PDecl)decls2[decl2Index]; if (data.ObfuscationFields.Contains(decl1) && data.ObfuscationFields.Contains(decl2)) continue; if (!Util.IsDeclVisible(decl2, node)) continue; if (decl1 == decl2) continue; if (file1 == file2 && file1.GetDecl().IndexOf(decl1) > file1.GetDecl().IndexOf(decl2)) continue; if (decl1 is AEnrichmentDecl && decl2 is AEnrichmentDecl) { AEnrichmentDecl aDecl1 = (AEnrichmentDecl)decl1; AEnrichmentDecl aDecl2 = (AEnrichmentDecl)decl2; if (Util.TypesEqual(aDecl1.GetType(), aDecl2.GetType(), data)) { //Only an error if they define something which is the same foreach (PDecl subDecl1 in aDecl1.GetDecl()) { foreach (PDecl subDecl2 in aDecl2.GetDecl()) { if (subDecl1.GetType() != subDecl2.GetType()) continue; if (subDecl1 is AMethodDecl) { AMethodDecl aSubDecl1 = (AMethodDecl)subDecl1; AMethodDecl aSubDecl2 = (AMethodDecl)subDecl2; if (Util.GetMethodSignature(aSubDecl1) == Util.GetMethodSignature(aSubDecl2)) { List<ErrorCollection.Error> subErrors = new List<ErrorCollection.Error>(); subErrors.Add(new ErrorCollection.Error(aSubDecl1.GetName(), file1, "Matching method declaration")); subErrors.Add(new ErrorCollection.Error(aSubDecl2.GetName(), file2, "Matching method declaration")); errors.Add(new ErrorCollection.Error(new TIdentifier("", 1, 1), node, "Two methods of same signature defined in the enrichment " + Util.TypeToString( aDecl1.GetType()) + ", and is visible from " + node.GetName().Text, false, subErrors.ToArray())); } } else if (subDecl1 is AConstructorDecl) { AConstructorDecl aSubDecl1 = (AConstructorDecl)subDecl1; AConstructorDecl aSubDecl2 = (AConstructorDecl)subDecl2; if (Util.GetConstructorSignature(aSubDecl1) == Util.GetConstructorSignature(aSubDecl2)) { List<ErrorCollection.Error> subErrors = new List<ErrorCollection.Error>(); subErrors.Add(new ErrorCollection.Error(aSubDecl1.GetName(), file1, "Matching constructor declaration")); subErrors.Add(new ErrorCollection.Error(aSubDecl2.GetName(), file2, "Matching constructor declaration")); errors.Add(new ErrorCollection.Error(new TIdentifier("", 1, 1), node, "Two constructors of same signature defined in the enrichment " + Util.TypeToString( aDecl1.GetType()) + ", and is visible from " + node.GetName().Text, false, subErrors.ToArray())); } } else if (subDecl1 is ADeconstructorDecl) { ADeconstructorDecl aSubDecl1 = (ADeconstructorDecl)subDecl1; ADeconstructorDecl aSubDecl2 = (ADeconstructorDecl)subDecl2; List<ErrorCollection.Error> subErrors = new List<ErrorCollection.Error>(); subErrors.Add(new ErrorCollection.Error(aSubDecl1.GetName(), file1, "Matching deconstructor declaration")); subErrors.Add(new ErrorCollection.Error(aSubDecl2.GetName(), file2, "Matching deconstructor declaration")); errors.Add(new ErrorCollection.Error(new TIdentifier("", 1, 1), node, "Two deconstructors is defined for the enrichment of " + Util.TypeToString( aDecl1.GetType()) + ", and is visible from " + node.GetName().Text, false, subErrors.ToArray())); } else if (subDecl1 is APropertyDecl) { APropertyDecl aSubDecl1 = (APropertyDecl)subDecl1; APropertyDecl aSubDecl2 = (APropertyDecl)subDecl2; if (aSubDecl1.GetName().Text == aSubDecl2.GetName().Text) { List<ErrorCollection.Error> subErrors = new List<ErrorCollection.Error>(); subErrors.Add(new ErrorCollection.Error(aSubDecl1.GetName(), file1, "Matching property declaration")); subErrors.Add(new ErrorCollection.Error(aSubDecl2.GetName(), file2, "Matching property declaration")); errors.Add(new ErrorCollection.Error(new TIdentifier("", 1, 1), node, "Two properties of same name defined in the enrichment " + Util.TypeToString( aDecl1.GetType()) + ", and is visible from " + node.GetName().Text, false, subErrors.ToArray())); } } } } /*List<ErrorCollection.Error> subErrors = new List<ErrorCollection.Error>(); subErrors.Add(new ErrorCollection.Error(aDecl1.GetToken(), file1, "Matching enrichment declaration")); subErrors.Add(new ErrorCollection.Error(aDecl2.GetToken(), file2, "Matching enrichment declaration")); errors.Add(new ErrorCollection.Error(new TIdentifier("", 1, 1), node, "Two enrichments on same type is visible from " + node.GetName().Text, false, subErrors.ToArray()));*//* }
public override void InAASourceFile(AASourceFile node) { namespacePrefix = ""; /*if (node.GetNamespace() != null) namespacePrefix = node.GetNamespace().Text + "_";*/ }
public override void CaseAASourceFile(AASourceFile node) { writer.WriteLine(node.GetName().Text + ":"); base.CaseAASourceFile(node); }
public virtual void InAASourceFile(AASourceFile node) { DefaultIn(node); }
ArrayList New4() { ArrayList nodeList = new ArrayList(); ArrayList nodeArrayList2 = (ArrayList) Pop(); ArrayList nodeArrayList1 = (ArrayList) Pop(); TypedList listNode8 = new TypedList(); TypedList listNode10 = new TypedList(); TypedList listNode5 = new TypedList(); TypedList listNode6 = new TypedList(); TNamespace tnamespaceNode3 = (TNamespace)nodeArrayList1[0]; TypedList listNode4 = (TypedList)nodeArrayList2[0]; if ( listNode4 != null ) { listNode5.AddAll(listNode4); } ATempNamespaceDecl pdeclNode2 = new ATempNamespaceDecl ( tnamespaceNode3, listNode5, listNode6, null ); if ( pdeclNode2 != null ) { listNode8.Add(pdeclNode2); } AASourceFile psourcefileNode1 = new AASourceFile ( listNode8, null, listNode10 ); nodeList.Add(psourcefileNode1); return nodeList; }
public virtual void OutAASourceFile(AASourceFile node) { DefaultOut(node); }
ArrayList New7() { ArrayList nodeList = new ArrayList(); ArrayList nodeArrayList4 = (ArrayList) Pop(); ArrayList nodeArrayList3 = (ArrayList) Pop(); ArrayList nodeArrayList2 = (ArrayList) Pop(); ArrayList nodeArrayList1 = (ArrayList) Pop(); TypedList listNode9 = new TypedList(); TypedList listNode12 = new TypedList(); TypedList listNode5 = new TypedList(); TypedList listNode7 = new TypedList(); TNamespace tnamespaceNode3 = (TNamespace)nodeArrayList1[0]; TypedList listNode4 = (TypedList)nodeArrayList2[0]; if ( listNode4 != null ) { listNode5.AddAll(listNode4); } TypedList listNode6 = (TypedList)nodeArrayList4[0]; if ( listNode6 != null ) { listNode7.AddAll(listNode6); } ATempNamespaceDecl pdeclNode2 = new ATempNamespaceDecl ( tnamespaceNode3, listNode5, listNode7, null ); if ( pdeclNode2 != null ) { listNode9.Add(pdeclNode2); } TypedList listNode11 = (TypedList)nodeArrayList3[0]; if ( listNode11 != null ) { listNode12.AddAll(listNode11); } AASourceFile psourcefileNode1 = new AASourceFile ( listNode9, null, listNode12 ); nodeList.Add(psourcefileNode1); return nodeList; }
private static int CountDecendants(AASourceFile file, Dictionary<AASourceFile, List<AASourceFile>> dependancies, List<AASourceFile> countedFiles) { if (file == null) return 1; countedFiles.Add(file); foreach (AASourceFile sourceFile in dependancies[file]) { if (!countedFiles.Contains(sourceFile)) CountDecendants(sourceFile, dependancies, countedFiles); } return countedFiles.Count; }
public override void CaseAASourceFile(AASourceFile node) { string name = outputDir.FullName + "\\"; /* if (Options.Compiler.OneOutputFile) name += "MapScript"; else*/ name += node.GetName().Text; name += ".galaxy"; FileInfo file = new FileInfo(name); if (!file.Directory.Exists) file.Directory.Create(); stream = new StreamWriter(file.Open(FileMode.Create)); foreach (PDecl decl in node.GetDecl()) { decl.Apply(this); } Write("", true); stream.Close(); }
private static IncludeItem MakeTree(AASourceFile node, Dictionary<AASourceFile, List<AASourceFile>> dependancies, List<Item> allItems, IncludeItem mainFile) { IncludeItem includeItem = new IncludeItem(node, allItems.Count, null, new List<Item>()); //Ensure that each include is only included one place IncludeItem item2 = includeItem; bool removed = false; for (int i = 0; i < allItems.Count; i++) { IncludeItem item1 = (IncludeItem)allItems[i]; if (item1.Current == item2.Current) { List<Item> path1 = item1.Path; List<Item> path2 = item2.Path; for (int k = 0; k < Math.Min(path1.Count, path2.Count); k++) { if (path1[k] != path2[k]) { int insertAt; IncludeItem insertIn; if (k != 0) { int index1 = path1[k - 1].Children.IndexOf(path1[k]); int index2 = path2[k - 1].Children.IndexOf(path2[k]); if (index2 == -1) index2 = path2[k - 1].Children.Count; insertAt = Math.Min(index1, index2); insertIn = (IncludeItem) path1[k - 1]; } else { if (path1[0] == mainFile) { int index1 = mainFile.Children.IndexOf(path1[1]); if (path2[0] == mainFile) { int index2 = mainFile.Children.IndexOf(path2[1]); if (index2 == -1) { index2 = mainFile.Children.Count; if (path1.Count == 2) index2--;//Since item1 will be removed } insertAt = Math.Min(index1, index2); } else insertAt = index1; } else if (path2[0] == mainFile) { int index2 = mainFile.Children.IndexOf(path2[1]); if (index2 == -1) index2 = mainFile.Children.Count; insertAt = index2; } else insertAt = mainFile.Children.Count; insertIn = mainFile; } if (item1.Parent != insertIn || insertIn.Children.IndexOf(item1) != insertAt) { item1.Parent.Children.Remove(item1); insertIn.Children.Insert(insertAt, item1); item1.Parent = insertIn; } removed = true; break; } } } } if (removed) return null; allItems.Add(includeItem); if (node != null) foreach (AASourceFile file in dependancies[node]) { IncludeItem child = MakeTree(file, dependancies, allItems, mainFile ?? includeItem); if (child == null) continue; child.Parent = includeItem; includeItem.Children.Add(child); } return includeItem; }
public override void OutAASourceFile(AASourceFile node) { if (reqRerun) { reqRerun = false; base.CaseAASourceFile(node); } }
public IncludeItem(AASourceFile current, int listIndex, IncludeItem parent, List<Item> children) : base(parent, children) { Current = current; ListIndex = listIndex; }
public override void CaseAASourceFile(AASourceFile node) { currentSourceFile = node; base.CaseAASourceFile(node); }
private void AddDepency(AASourceFile currentFile, AASourceFile requiredFile) { //If requiredFile is null, it is a part of the standard library //If it's the same file, no includes are required if (currentFile == requiredFile) return; if (dependancies[currentFile].Contains(requiredFile)) return; dependancies[currentFile].Add(requiredFile); }
public override void CaseAASourceFile(AASourceFile node) { InAASourceFile(node); { Object[] temp = new Object[node.GetUsings().Count]; node.GetUsings().CopyTo(temp, 0); for (int i = temp.Length - 1; i >= 0; i--) { ((PDecl)temp[i]).Apply(this); } } if (node.GetName() != null) { node.GetName().Apply(this); } { Object[] temp = new Object[node.GetDecl().Count]; node.GetDecl().CopyTo(temp, 0); for (int i = temp.Length - 1; i >= 0; i--) { ((PDecl)temp[i]).Apply(this); } } OutAASourceFile(node); }
internal Usings_Cast(AASourceFile obj) { this.obj = obj; }
private void Apply(AAProgram ast) { int stage = 1; int totalStages = 31; List<ANamedType> deleteUs = new List<ANamedType>(); foreach (KeyValuePair<ANamedType, AStructDecl> pair in data.StructTypeLinks) { ANamedType type = pair.Key; AStructDecl str = pair.Value; if (data.Enums.ContainsKey(str)) { type.SetName(new AAName(new ArrayList(){new TIdentifier(data.Enums[str] ? "int" : "byte")})); deleteUs.Add(type); } } foreach (ANamedType type in deleteUs) { data.StructTypeLinks.Remove(type); } if (data.AllowPrintouts) Form1.Form.SetStatusText(LocRM.GetString("FT_Text1") + stage + " / " + totalStages + LocRM.GetString("FT_Text2")); stage++; ast.Apply(new RemoveNamespaces()); if (data.AllowPrintouts) Form1.Form.SetStatusText(LocRM.GetString("FT_Text1") + stage + " / " + totalStages + LocRM.GetString("FT_Text3")); stage++; ast.Apply(new StaticStructMembers(data)); if (data.AllowPrintouts) Form1.Form.SetStatusText(LocRM.GetString("FT_Text1") + stage + " / " + totalStages + LocRM.GetString("FT_Text4")); stage++; ast.Apply(new RemoveConstants(data)); if (data.AllowPrintouts) Form1.Form.SetStatusText(LocRM.GetString("FT_Text1") + stage + " / " + totalStages + LocRM.GetString("FT_Text5")); stage++; ast.Apply(new MainEntryFinder(this)); if (mainEntry == null) { //errors.Add(new ErrorCollection.Error("No entry point found (void InitMap(){...})", true)); //Generate main entry AASourceFile file = ast.GetSourceFiles().Cast<AASourceFile>().FirstOrDefault( sourceFile => !Util.GetAncestor<AASourceFile>(sourceFile).GetName().Text.Contains("\\")); if (file == null) { //Make default sourcefile file = new AASourceFile(); file.SetName(new TIdentifier("MapScript")); ast.GetSourceFiles().Add(file); data.LineCounts[file] = 1; } mainEntry = new AMethodDecl(new APublicVisibilityModifier(), null, null, null, null, null, new AVoidType(new TVoid("void")), new TIdentifier("InitMap"), new ArrayList(), new AABlock()); file.GetDecl().Add(mainEntry); data.Methods.Add(new SharedData.DeclItem<AMethodDecl>(file, mainEntry)); } else if (Util.GetAncestor<AASourceFile>(mainEntry).GetName().Text.Contains("\\")) errors.Add(new ErrorCollection.Error(mainEntry.GetName(), Util.GetAncestor<AASourceFile>(mainEntry), LocRM.GetString("FT_Text6"), true)); ((AABlock)mainEntry.GetBlock()).GetStatements().Insert(0, mainEntryFieldInitBlock); if (data.AllowPrintouts) Form1.Form.SetStatusText(LocRM.GetString("FT_Text1") + stage + " / " + totalStages + LocRM.GetString("FT_Text7")); stage++; ast.Apply(new StructInitializer(this)); if (data.AllowPrintouts) Form1.Form.SetStatusText(LocRM.GetString("FT_Text1") + stage + " / " + totalStages + LocRM.GetString("FT_Text8")); stage++; ast.Apply(new TransformExpressionIfs(data)); if (data.AllowPrintouts) Form1.Form.SetStatusText(LocRM.GetString("FT_Text1") + stage + " / " + totalStages + LocRM.GetString("FT_Text9")); stage++; ast.Apply(new RenameUnicode(data)); if (data.AllowPrintouts) Form1.Form.SetStatusText(LocRM.GetString("FT_Text1") + stage + " / " + totalStages + LocRM.GetString("FT_Text10")); stage++; TransformProperties.Phase1.Parse(this); if (data.AllowPrintouts) Form1.Form.SetStatusText(LocRM.GetString("FT_Text1") + stage + " / " + totalStages + LocRM.GetString("FT_Text11")); stage++; ast.Apply(new RemoveDeadCode()); if (data.AllowPrintouts) Form1.Form.SetStatusText(LocRM.GetString("FT_Text1") + stage + " / " + totalStages + LocRM.GetString("FT_Text12")); stage++; ast.Apply(new TransformMethodDecls(this)); if (errors.HasErrors) return; if (data.AllowPrintouts) Form1.Form.SetStatusText(LocRM.GetString("FT_Text1") + stage + " / " + totalStages + LocRM.GetString("FT_Text13")); stage++; MakeInitializerInvokes(); if (data.AllowPrintouts) Form1.Form.SetStatusText(LocRM.GetString("FT_Text1") + stage + " / " + totalStages + LocRM.GetString("FT_Text14")); stage++; ast.Apply(new AssignFixup(this)); if (data.AllowPrintouts) Form1.Form.SetStatusText(LocRM.GetString("FT_Text1") + stage + " / " + totalStages + LocRM.GetString("FT_Text15")); stage++; TransformProperties.Phase2.Parse(this); if (data.AllowPrintouts) Form1.Form.SetStatusText(LocRM.GetString("FT_Text1") + stage + " / " + totalStages + LocRM.GetString("FT_Text16")); stage++; if (data.Invokes.Count > 0) Invokes.Parse(this); if (data.AllowPrintouts) Form1.Form.SetStatusText(LocRM.GetString("FT_Text1") + stage + " / " + totalStages + LocRM.GetString("FT_Text17")); stage++; ast.Apply(new RemoveEmptyStructs(this)); if (data.AllowPrintouts) Form1.Form.SetStatusText(LocRM.GetString("FT_Text1") + stage + " / " + totalStages + LocRM.GetString("FT_Text18")); stage++; ast.Apply(new Delegates(this)); if (data.AllowPrintouts) Form1.Form.SetStatusText(LocRM.GetString("FT_Text1") + stage + " / " + totalStages + LocRM.GetString("FT_Text19")); stage++; //ast.Apply(new AddUnneededRef(data)); ast.Apply(new FixInlineMethods(this, false)); if (data.AllowPrintouts) Form1.Form.SetStatusText(LocRM.GetString("FT_Text1") + stage + " / " + totalStages + LocRM.GetString("FT_Text20")); stage++; ast.Apply(new RemoveUnnededRef(data)); if (data.AllowPrintouts) Form1.Form.SetStatusText(LocRM.GetString("FT_Text1") + stage + " / " + totalStages + LocRM.GetString("FT_Text21")); stage++; ast.Apply(new SplitStructTests(data)); if (data.AllowPrintouts) Form1.Form.SetStatusText(LocRM.GetString("FT_Text1") + stage + " / " + totalStages + LocRM.GetString("FT_Text22")); stage++; new Pointers(data).Parse(ast); if (data.AllowPrintouts) Form1.Form.SetStatusText(LocRM.GetString("FT_Text1") + stage + " / " + totalStages + LocRM.GetString("FT_Text23")); stage++; ast.Apply(new FixInlineMethods(this, true)); if (data.AllowPrintouts) Form1.Form.SetStatusText(LocRM.GetString("FT_Text1") + stage + " / " + totalStages + LocRM.GetString("FT_Text24")); stage++; //Split local struct into primitives, to make optimizations easier ast.Apply(new StructSplitter(data)); //ast.Apply(new BulkCopyFixup(this)); //BulkCopyFixup.Parse(ast, this); if (data.AllowPrintouts) Form1.Form.SetStatusText(LocRM.GetString("FT_Text1") + stage + " / " + totalStages + LocRM.GetString("FT_Text25")); stage++; //Remove stupid assignments (assignments to a variable where that variable is not used before its next assignment ast.Apply(new RemoveUnusedVariables(this)); if (data.AllowPrintouts) Form1.Form.SetStatusText(LocRM.GetString("FT_Text1") + stage + " / " + totalStages + LocRM.GetString("FT_Text26")); stage++; ast.Apply(new ConstantFolding(data)); if (data.AllowPrintouts) Form1.Form.SetStatusText(LocRM.GetString("FT_Text1") + stage + " / " + totalStages + LocRM.GetString("FT_Text27")); stage++; //Assign fixup was here //Dahm grafiti painters //ast.Apply(new LivenessAnalysis(this)); ast.Apply(new Optimizations.OptimizePhase(this, LocRM.GetString("FT_Text1") + (stage - 1) + " / " + totalStages + LocRM.GetString("FT_Text27"))); ast.Apply(new FixByteArrayIndexes(data)); if (Options.Compiler.MakeShortNames) { if (data.AllowPrintouts) Form1.Form.SetStatusText(LocRM.GetString("FT_Text1") + stage + " / " + totalStages + LocRM.GetString("FT_Text28")); stage++; ast.Apply(new MakeShortNames(this)); } else { if (data.AllowPrintouts) Form1.Form.SetStatusText(LocRM.GetString("FT_Text1") + stage + " / " + totalStages + LocRM.GetString("FT_Text29")); stage++; //MakeUniqueNames.Parse(ast, this); ast.Apply(new MakeUniqueNamesV2()); } if (data.AllowPrintouts) Form1.Form.SetStatusText(LocRM.GetString("FT_Text1") + stage + " / " + totalStages + LocRM.GetString("FT_Text30")); stage++; //Remove uneeded blocks and check that names fit the decls ast.Apply(new RenameRefferences(this)); if (data.AllowPrintouts) Form1.Form.SetStatusText(LocRM.GetString("FT_Text1") + stage + " / " + totalStages + LocRM.GetString("FT_Text31")); stage++; //Obfuscate strings ast.Apply(new ObfuscateStrings(this)); if (data.AllowPrintouts) Form1.Form.SetStatusText(LocRM.GetString("FT_Text1") + stage + " / " + totalStages + LocRM.GetString("FT_Text32")); stage++; MergeSameMethods.Parse(this); if (data.AllowPrintouts) Form1.Form.SetStatusText(LocRM.GetString("FT_Text1") + stage + " / " + totalStages + LocRM.GetString("FT_Text33")); stage++; //Insert includes, and move methods, structs and fields around so they are visible FixIncludes.Apply(ast, this); if (Options.Compiler.OneOutputFile) ((AASourceFile)mainEntry.Parent()).SetName(new TIdentifier("MapScript")); }