Example #1
0
        public static Expression CombineWithComma(IndexSpan span, JSParser parser, Expression operand1, Expression operand2)
        {
            var comma = new CommaOperator(parser.EncodeSpan(span));

            List<Expression> res = new List<Expression>();
            CommaOperator left = operand1 as CommaOperator;
            CommaOperator right = operand2 as CommaOperator;
            if (left != null)
            {
                res.AddRange(left.Expressions);
            }
            else
            {
                res.Add(operand1);
            }

            if (right != null)
            {
                res.AddRange(right.Expressions);
            }
            else
            {
                res.Add(operand2);
            }
            comma.Expressions = res.ToArray();
            return comma;
        }
 public void SwapOperands()
 {
     // swap the operands -- we don't need to go through ReplaceChild or the
     // property setters because we don't need to change the Parent pointers 
     // or anything like that.
     Expression temp = m_operand1;
     m_operand1 = m_operand2;
     m_operand2 = temp;
 }
 /// <summary>
 /// Gets the names which should be in a new scope for isinstance(...) checks.  We don't
 /// use a walker here because we only support a very limited set of assertions (e.g. isinstance(x, type) and ...
 /// or a bare isinstance(...).
 /// </summary>
 internal static void GetIsInstanceNamesAndExpressions(ref List<KeyValuePair<Lookup, Expression>> names, Expression node) {
     CallNode callExpr = node as CallNode;
     if (callExpr != null && callExpr.Arguments.Length == 2) {
         Lookup nameExpr = callExpr.Function as Lookup;
         if (nameExpr != null && nameExpr.Name == "isinstance") {
             nameExpr = callExpr.Arguments[0] as Lookup;
             if (nameExpr != null) {
                 if (names == null) {
                     names = new List<KeyValuePair<Lookup, Expression>>();
                 }
                 var type = callExpr.Arguments[1];
                 names.Add(new KeyValuePair<Lookup, Expression>(nameExpr, type));
             }
         }
     }
 }
 internal static KeyValuePair<Lookup, Expression>[] GetIsInstanceNamesAndExpressions(Expression node) {
     List<KeyValuePair<Lookup, Expression>> names = null;
     GetIsInstanceNamesAndExpressions(ref names, node);
     if (names != null) {
         return names.ToArray();
     }
     return null;
 }
 public void SwapBranches()
 {
     var temp = m_trueExpression;
     m_trueExpression = m_falseExpression;
     m_falseExpression = temp;
 }
Example #6
0
 private void EnsureSpacesAroundParenthesisedExpression(Expression expr) {
     ReplacePreceedingWhiteSpace(
         expr.GetStartIndex(_tree.LocationResolver),
         _options.SpaceAfterOpeningAndBeforeClosingNonEmptyParenthesis ? " " : "",
         _openParen
     );
     expr.Walk(this);
     ReplaceFollowingWhiteSpace(
         expr.GetEndIndex(_tree.LocationResolver),
         _options.SpaceAfterOpeningAndBeforeClosingNonEmptyParenthesis ? " " : ""
     );
 }