public override void CaseANamedType(ANamedType node) { //Remember.. if you are the child of a fieldDecl, that field may have been moved if (!node.IsPrimitive())//GalaxyKeywords.Primitives.words.Any(word => word == node.GetName().Text))) { AStructDecl decl = finalTrans.data.StructTypeLinks[node]; Item currentItem = GetIncludeItem(node); if (Util.GetAncestor<AFieldDecl>(node) != null) { Item i = allItems.OfType<FieldItem>().FirstOrDefault(item => item.FieldDecl == Util.GetAncestor<AFieldDecl>(node)); if (i != null) currentItem = i; } if (Util.GetAncestor<AStructDecl>(node) != null) { Item i = allItems.OfType<StructItem>().FirstOrDefault( item => item.StructDecl == Util.GetAncestor<AStructDecl>(node)); if (i != null) currentItem = i; } Item declItem = ((Item)allItems.OfType<StructItem>().FirstOrDefault(item => item.StructDecl == decl)) ?? allItems.OfType<IncludeItem>().First( item => item.Current == Util.GetAncestor<AASourceFile>(decl)); List<Item> cPath = currentItem.Path; List<Item> dPath = declItem.Path; for (int i = 0; i < Math.Min(cPath.Count, dPath.Count); i++) { if (cPath[i] != dPath[i]) {//FORK!!!! //We have a fork. make sure that the field is visible int cI = cPath[i - 1].Children.IndexOf(cPath[i]); int dI = dPath[i - 1].Children.IndexOf(dPath[i]); if (dI < cI) {//The decl is okay break; } //Move the decl up if (declItem is StructItem) { declItem.Parent.Children.Remove(declItem); declItem.Parent = cPath[i - 1]; } else { declItem = new StructItem(decl, cPath[i - 1], new List<Item>()); allItems.Add(declItem); } cPath[i - 1].Children.Insert(cI, declItem); break; } if (i == cPath.Count - 1) { if (i == dPath.Count - 1) { //The decl and use is in same file. Ensure that the decl is before if (Util.TokenLessThan(decl.GetName(), node.GetToken())) break; //Add the decl item declItem = new StructItem(decl, cPath[i], new List<Item>()); allItems.Add(declItem); cPath[i].Children.Add(declItem); break; } else { //The decl is included here or somewhere deeper. But above the use break; } } else if (i == dPath.Count - 1) { //We have reached the file where the decl is, but the use is included deeper, so it is above. Insert decl int cI = cPath[i].Children.IndexOf(cPath[i + 1]); declItem = new StructItem(decl, cPath[i], new List<Item>()); allItems.Add(declItem); cPath[i].Children.Insert(cI, declItem); break; } } } base.CaseANamedType(node); }
public override void OutANamedType(ANamedType node) { if (!node.IsPrimitive())//!GalaxyKeywords.Primitives.words.Contains(node.GetName().Text)) node.SetName( new AAName(new List<TIdentifier>() {new TIdentifier(finalTrans.data.StructTypeLinks[node].GetName().Text)})); }
public override void InANamedType(ANamedType node) { if (!node.IsPrimitive())// !GalaxyKeywords.Primitives.words.Any(word => word == node.GetName().Text)) { AStructDecl decl = finalTrans.data.StructTypeLinks[node]; AddDepency(Util.GetAncestor<AASourceFile>(node), Util.GetAncestor<AASourceFile>(decl)); } }