Example #1
0
        public TryStmt(Text.Span p, IList<Statement>/*!*/ statements, List<CatchItem> catches, FinallyItem finallyItem)
			: base(p)
		{
            Debug.Assert(statements != null);
            
			this.statements = statements.AsArray();
			this.catches = catches.AsArray();
            this.finallyItem = finallyItem;
		}
Example #2
0
        public static AstNode ReplaceMeWith(this AstNode old, Func<AstNode> newf)
        {
            var parset = typeof(AstNode).GetProperty("Parent").GetSetMethod(true);
            var chiset = typeof(AstNode).GetProperty("Children").GetSetMethod(true);
            var chiiset = typeof(AstNode).GetProperty("ChildIndex").GetSetMethod(true);

            var parent = old.Parent;
            var chiindex = old.ChildIndex;

            // if you uncomment this, something will crash, namely Extract fx for a direct child of a root expression
//            parset.Invoke(old, new object[] { null });
//            chiiset.Invoke(old, ((object)-1).AsArray());
            var @new = newf();

            var head = parent.Children.Take(chiindex);
            var tail = parent.Children.Skip(chiindex + 1);
            var newchi = new List<AstNode>(head.Concat(@new.AsArray()).Concat(tail)).AsReadOnly();

            chiset.Invoke(parent, newchi.AsArray());
            parset.Invoke(@new, parent.AsArray());
            chiiset.Invoke(@new, ((object)chiindex).AsArray());

            return @new;
        }