public static T Clone <T>(CloneContext cloneContext, T item) where T : class, IAst { if (item == null) { return(null); } var clone = (T)Activator.CreateInstance(item.GetType(), BindingFlags.Instance | BindingFlags.NonPublic); item.CloneTo(cloneContext, clone); LinkParents.Link(clone); return(clone); }
public static void Walk <T>(ref T node, AstVisitor prefix, AstVisitor postfix) where T : IAst { IAst first = node; IAst second = node; if (first == null) { return; } if (prefix(ref first)) { first.Walk(prefix, postfix); } if (second.Equals(first)) { postfix(ref first); } if (second.Equals(first)) { return; } if (!ReferenceEquals(first, null)) { if (!(first is T)) { throw new Exception( string.Format( "Node replaced not of the correct type {0}.", typeof(T).Name)); } LinkParents.Link(first); first.ParentAst = node.ParentAst; } node = (T)first; }
public static void Link(IAst node) { var parents = new LinkParents(); Ast.Walk(ref node, parents.Prefix, parents.Postfix); }