Example #1
0
 public override void AugmentAssign(AugmentedAssignStatement node, AnalysisUnit unit, ISet<Namespace> value)
 {
     base.AugmentAssign(node, unit, value);
     var args = GetEventInvokeArgs(ProjectState,  _type);
     foreach (var r in value) {
         r.Call(node, unit, args, ArrayUtils.EmptyStrings);
     }
 }
        public void Visit(PyAst.AugmentedAssignStatement node)
        {
            string op;

            switch (node.Operator)
            {
            case IronPython.Compiler.PythonOperator.Add: op = "+="; break;

            case IronPython.Compiler.PythonOperator.Subtract: op = "-="; break;

            case IronPython.Compiler.PythonOperator.Multiply: op = "*="; break;

            case IronPython.Compiler.PythonOperator.Divide: op = "/="; break;

            default:
                throw CreateNotImplementedEx();
            }
            AppendLineWithIndentation($"{Visit(node.Left)} {op} {Visit(node.Right)}");
        }
Example #3
0
 public override void PostWalk(AugmentedAssignStatement node)
 {
     node.Left.Walk(_fdef);
 }
Example #4
0
 // AugAssignStmt
 public override bool Walk(AugmentedAssignStatement node)
 {
     return(true);
 }
Example #5
0
        // expr_stmt: expression_list
        // expression_list: expression ( "," expression )* [","] 
        // assignment_stmt: (target_list "=")+ (expression_list | yield_expression) 
        // augmented_assignment_stmt ::= target augop (expression_list | yield_expression) 
        // augop: '+=' | '-=' | '*=' | '/=' | '%=' | '**=' | '>>=' | '<<=' | '&=' | '^=' | '|=' | '//='
        private Statement ParseExprStmt() {
            Expression ret = ParseTestListAsExpr();
            if (ret is ErrorExpression) {
                NextToken();
            }

            if (PeekToken(TokenKind.Assign)) {
                return FinishAssignments(ret);
            } else {
                PythonOperator op = GetAssignOperator(PeekToken());
                if (op != PythonOperator.None) {
                    NextToken();
                    Expression rhs;

                    if (MaybeEat(TokenKind.KeywordYield)) {
                        rhs = ParseYieldExpression();
                    } else {
                        rhs = ParseTestListAsExpr();
                    }

                    string assignError = ret.CheckAugmentedAssign();
                    if (assignError != null) {
                        ReportSyntaxError(assignError);
                    }

                    AugmentedAssignStatement aug = new AugmentedAssignStatement(op, ret, rhs);
                    aug.SetLoc(_globalParent, ret.StartIndex, GetEnd());
                    return aug;
                } else {
                    Statement stmt = new ExpressionStatement(ret);
                    stmt.SetLoc(_globalParent, ret.IndexSpan);
                    return stmt;
                }
            }
        }
Example #6
0
 internal AugAssign(AugmentedAssignStatement stmt)
     : this() {
     _target = Convert(stmt.Left, Store.Instance);
     _value = Convert(stmt.Right);
     _op = (@operator)Convert(stmt.Operator);
 }
Example #7
0
 public override bool Walk(AugmentedAssignStatement node)
 {
     node.Parent = _currentScope;
     node.Left.Walk(_define);
     return true;
 }
		/// <summary>
		/// Walks a statement of the form:
		/// 
		/// self.a += self.b
		/// </summary>
		public override bool Walk(AugmentedAssignStatement node)
		{
			if (!FoundInitializeComponentMethod) {
				return false;
			}
			
			MemberExpression eventExpression = node.Left as MemberExpression;
			string eventName = eventExpression.Name.ToString();
			fieldExpression = PythonControlFieldExpression.Create(eventExpression);
			
			MemberExpression eventHandlerExpression = node.Right as MemberExpression;
			string eventHandlerName = eventHandlerExpression.Name.ToString();
			
			IComponent currentComponent = fieldExpression.GetObject(componentCreator) as IComponent;
			
			EventDescriptor eventDescriptor = TypeDescriptor.GetEvents(currentComponent).Find(eventName, false);
			PropertyDescriptor propertyDescriptor = componentCreator.GetEventProperty(eventDescriptor);
			propertyDescriptor.SetValue(currentComponent, eventHandlerName);
			return false;
		}		
Example #9
0
 public override bool Walk(AugmentedAssignStatement node)
 {
     node.Parent = _currentScope;
     node.Left.Walk(_define);
     return(true);
 }
Example #10
0
        public override void PostWalk(AugmentedAssignStatement node)
        {
            string right = Content();
            string left = Content();

            switch (node.Operator)
            {
                case IronPython.Compiler.PythonOperator.Add:
                    Content("{0} += {1}", left, right);
                    break;

                case IronPython.Compiler.PythonOperator.BitwiseAnd:
                    Content("{0} &= {1}", left, right);
                    break;

                case IronPython.Compiler.PythonOperator.BitwiseOr:
                    Content("{0} |= {1}", left, right);
                    break;

                case IronPython.Compiler.PythonOperator.Divide:
                    Content("{0} /= {1}", left, right);
                    break;

                case IronPython.Compiler.PythonOperator.Xor:
                    //case IronPython.Compiler.PythonOperator.ExclusiveOr:
                    Content("{0} ^= {1}", left, right);
                    break;

                case IronPython.Compiler.PythonOperator.FloorDivide:
                    Content("{0} = Math.floor({0} / {1})", left, right);
                    break;

                case IronPython.Compiler.PythonOperator.LeftShift:
                    Content("{0} <<= {1}", left, right);
                    break;

                case IronPython.Compiler.PythonOperator.Mod:
                    Content("{0} %= {1}", left, right);
                    break;

                case IronPython.Compiler.PythonOperator.Multiply:
                    Content("{0} = Python.mul({0}, {1})", left, right);
                    break;

                case IronPython.Compiler.PythonOperator.Pos:
                    break;

                case IronPython.Compiler.PythonOperator.Power:
                    Content("{0} = Math.pow({0}, {1})", left, right);
                    break;

                case IronPython.Compiler.PythonOperator.RightShift:
                    Content("{0} >>= {1}", left, right);
                    break;

                case IronPython.Compiler.PythonOperator.Subtract:
                    Content("{0} -= {1}", left, right);
                    break;

                case IronPython.Compiler.PythonOperator.TrueDivide:
                    break;

                case IronPython.Compiler.PythonOperator.Negate:
                case IronPython.Compiler.PythonOperator.None:
                case IronPython.Compiler.PythonOperator.Not:
                case IronPython.Compiler.PythonOperator.NotIn:
                case IronPython.Compiler.PythonOperator.LessThan:
                case IronPython.Compiler.PythonOperator.LessThanOrEqual:
                case IronPython.Compiler.PythonOperator.GreaterThan:
                case IronPython.Compiler.PythonOperator.GreaterThanOrEqual:
                case IronPython.Compiler.PythonOperator.In:
                case IronPython.Compiler.PythonOperator.Invert:
                case IronPython.Compiler.PythonOperator.Is:
                case IronPython.Compiler.PythonOperator.IsNot:
                case IronPython.Compiler.PythonOperator.NotEqual:
                //case IronPython.Compiler.PythonOperator.NotEquals:
                case IronPython.Compiler.PythonOperator.Equal:
                //case IronPython.Compiler.PythonOperator.Equals:
                default:
                    sink.Add(src, String.Format("Operator {0} is not supported.", node.Operator), node.Span, UNSUPPORTED_OPERATOR, Severity.FatalError);
                    break;
            }

            CommonPostWalk(node);
        }
Example #11
0
 public override bool Walk(AugmentedAssignStatement node)
 {
     CommonWalk(node);
     return true;
 }
Example #12
0
        // expr_stmt: expression_list
        // expression_list: expression ( "," expression )* [","] 
        // assignment_stmt: (target_list "=")+ (expression_list | yield_expression) 
        // augmented_assignment_stmt ::= target augop (expression_list | yield_expression) 
        // augop: '+=' | '-=' | '*=' | '/=' | '%=' | '**=' | '>>=' | '<<=' | '&=' | '^=' | '|=' | '//='
        private Statement ParseExprStmt() {
            Expression ret = ParseTestListAsExpr(false);
            if (ret is ErrorExpression) {
                NextToken();
            }

            if (PeekToken(TokenKind.Assign)) {
                return FinishAssignments(ret);
            } else {
                PythonOperator op = GetAssignOperator(PeekToken());
                if (op != PythonOperator.None) {
                    NextToken();
                    Expression rhs;
                    
                    if (MaybeEat(TokenKind.KeywordYield)) {
                        rhs = ParseYieldExpression();
                    } else {
                        rhs = ParseTestListAsExpr(false);
                    }

                    if (ret is ListExpression || ret is TupleExpression) {
                        ReportSyntaxError(ret.Start, ret.End, "illegal expression for augmented assignment");
                    }

                    AugmentedAssignStatement aug = new AugmentedAssignStatement(op, ret, rhs);
                    aug.SetLoc(ret.Start, GetEnd());
                    return aug;
                } else {
                    Statement stmt = new ExpressionStatement(ret);
                    stmt.SetLoc(ret.Span);
                    return stmt;
                }
            }
        }
Example #13
0
 public override void PostWalk(AugmentedAssignStatement node) {
     node.Left.Walk(_fdef);
 }
Example #14
0
 // AugAssignStmt
 public override bool Walk(AugmentedAssignStatement node) { return true; }
Example #15
0
 /// <summary>
 /// Performs an augmented assignment propagating the value into the object.
 /// </summary>
 public static void AugmentAssign(this ISet<Namespace> self, AugmentedAssignStatement node, AnalysisUnit unit, ISet<Namespace> value)
 {
     foreach (var ns in self) {
         ns.AugmentAssign(node, unit, value);
     }
 }
Example #16
0
		public override bool Walk(AugmentedAssignStatement node)
		{
			writer.WriteLine("AugmentedAssignStatement");
			return base.Walk(node);
		}