Beispiel #1
0
		public ThrowStatement(int pos, AstNode expr) : base(pos, expr.GetLength())
		{
			{
				type = Token.THROW;
			}
			SetExpression(expr);
		}
Beispiel #2
0
		/// <summary>Sets loop body.</summary>
		/// <remarks>
		/// Sets loop body.  Sets the parent of the body to this loop node,
		/// and updates its offset to be relative.  Extends the length of this
		/// node to include the body.
		/// </remarks>
		public virtual void SetBody(AstNode body)
		{
			this.body = body;
			int end = body.GetPosition() + body.GetLength();
			this.SetLength(end - this.GetPosition());
			body.SetParent(this);
		}
Beispiel #3
0
		public virtual void SetLeftAndRight(AstNode left, AstNode right)
		{
			AssertNotNull(left);
			AssertNotNull(right);
			// compute our bounds while children have absolute positions
			int beg = left.GetPosition();
			int end = right.GetPosition() + right.GetLength();
			SetBounds(beg, end);
			// this updates their positions to be parent-relative
			SetLeft(left);
			SetRight(right);
		}
Beispiel #4
0
		/// <summary>Sets function body, and sets its parent to this node.</summary>
		/// <remarks>
		/// Sets function body, and sets its parent to this node.
		/// Also sets the encoded source bounds based on the body bounds.
		/// Assumes the function node absolute position has already been set,
		/// and the body node's absolute position and length are set.<p>
		/// </remarks>
		/// <param name="body">
		/// function body.  Its parent is set to this node, and its
		/// position is updated to be relative to this node.
		/// </param>
		/// <exception cref="System.ArgumentException">
		/// if body is
		/// <code>null</code>
		/// </exception>
		public virtual void SetBody(AstNode body)
		{
			AssertNotNull(body);
			this.body = body;
			if (true.Equals(body.GetProp(Node.EXPRESSION_CLOSURE_PROP)))
			{
				SetIsExpressionClosure(true);
			}
			int absEnd = body.GetPosition() + body.GetLength();
			body.SetParent(this);
			this.SetLength(absEnd - this.position);
			SetEncodedSourceBounds(this.position, absEnd);
		}
		/// <summary>
		/// Constructs a new
		/// <code>ExpressionStatement</code>
		/// wrapping
		/// the specified expression.  Sets this node's position to the
		/// position of the wrapped node, and sets the wrapped node's
		/// position to zero.  Sets this node's length to the length of
		/// the wrapped node.
		/// </summary>
		/// <param name="expr">the wrapped expression</param>
		public ExpressionStatement(AstNode expr) : this(expr.GetPosition(), expr.GetLength(), expr)
		{
		}
Beispiel #6
0
		/// <summary>
		/// Constructs a new UnaryExpression with the specified operator
		/// and operand.
		/// </summary>
		/// <remarks>
		/// Constructs a new UnaryExpression with the specified operator
		/// and operand.  It sets the parent of the operand, and sets its own bounds
		/// to encompass the operator and operand.
		/// </remarks>
		/// <param name="operator">the node type</param>
		/// <param name="operatorPosition">the absolute position of the operator.</param>
		/// <param name="operand">the operand expression</param>
		/// <param name="postFix">true if the operator follows the operand.  Int</param>
		/// <exception cref="System.ArgumentException">
		/// } if
		/// <code>operand</code>
		/// is
		/// <code>null</code>
		/// </exception>
		public UnaryExpression(int @operator, int operatorPosition, AstNode operand, bool postFix)
		{
			AssertNotNull(operand);
			int beg = postFix ? operand.GetPosition() : operatorPosition;
			// JavaScript only has ++ and -- postfix operators, so length is 2
			int end = postFix ? operatorPosition + 2 : operand.GetPosition() + operand.GetLength();
			SetBounds(beg, end);
			SetOperator(@operator);
			SetOperand(operand);
			isPostfix = postFix;
		}
		public ParenthesizedExpression(AstNode expr) : this(expr != null ? expr.GetPosition() : 0, expr != null ? expr.GetLength() : 1, expr)
		{
		}
Beispiel #8
0
		/// <summary>Adds a statement to the end of the statement list.</summary>
		/// <remarks>
		/// Adds a statement to the end of the statement list.
		/// Sets the parent of the new statement to this node, updates
		/// its start offset to be relative to this node, and sets the
		/// length of this node to include the new child.
		/// </remarks>
		/// <param name="statement">a child statement</param>
		/// <exception cref="System.ArgumentException">
		/// } if statement is
		/// <code>null</code>
		/// </exception>
		public virtual void AddStatement(AstNode statement)
		{
			AssertNotNull(statement);
			if (statements == null)
			{
				statements = new List<AstNode>();
			}
			int end = statement.GetPosition() + statement.GetLength();
			this.SetLength(end - this.GetPosition());
			statements.Add(statement);
			statement.SetParent(this);
		}