public void NoLeftHandSideExpressionsInAssignment()
		{
			List<Expression> lhs = new List<Expression>();
			AssignmentStatement assign = new AssignmentStatement(lhs.ToArray(), null);
			PythonComponentWalker walker = new PythonComponentWalker(this);
			walker.Walk(assign);
		}
コード例 #2
0
 public override bool Walk(AssignmentStatement node)
 {
     foreach (var expr in node.Left)
     {
         WalkAssignmentTarget(expr);
     }
     node.Right?.Walk(this);
     return(false);
 }
コード例 #3
0
 // AssignmentStatement
 public override bool Walk(AssignmentStatement node)
 {
     node.Parent = _currentScope;
     foreach (Expression e in node.Left)
     {
         e.Walk(_define);
     }
     return(true);
 }
コード例 #4
0
 // AssignStmt
 public override bool Walk(AssignmentStatement node)
 {
     node.Right.Walk(this);
     foreach (Expression e in node.Left)
     {
         e.Walk(_fdef);
     }
     return(false);
 }
コード例 #5
0
		public override bool Walk(AssignmentStatement node)
		{
			PythonLocalVariableAssignment localVariableAssignment = new PythonLocalVariableAssignment(node);
			if (localVariableAssignment.IsLocalVariableAssignment()) {
				if (localVariableAssignment.VariableName == variableName) {
					typeName = localVariableAssignment.TypeName;
				}
			}
			return base.Walk(node);
		}
コード例 #6
0
 public override bool Walk(AssignmentStatement node)
 {
     foreach (Expression lhs in node.Left)
     {
         if (lhs is MemberExpression me)
         {
             if (IsSelfReference(me.Target))
             {
                 _names[me.Name] = true;
             }
         }
     }
     return(true);
 }
コード例 #7
0
		public void TypeName_CallExpressionTargetIsNotNameOrMemberExpression_ReturnsEmptyStringAndDoesNotGetStuckInInfiniteLoop()
		{
			string code = "a = 2";
			AssignmentStatement statement = PythonParserHelper.GetAssignmentStatement(code);
			Expression constantExpression = statement.Right;
			
			CallExpression callExpression = new CallExpression(constantExpression, new Arg[0]);
			List<Expression> expressions = new List<Expression>(statement.Left);
			statement = new AssignmentStatement(expressions.ToArray(), callExpression);
			
			PythonLocalVariableAssignment localVariableAssignment = new PythonLocalVariableAssignment(statement);
			string typeName = localVariableAssignment.TypeName;
			
			Assert.AreEqual(String.Empty, typeName);
		}
コード例 #8
0
ファイル: JavascriptGenerator.cs プロジェクト: valdisz/PyToJs
        public override bool Walk(AssignmentStatement node)
        {
            if (node.Left.Any(item => item is TupleExpression)
                && node.Right is ConstantExpression)
            {
                sink.Add(src, "Cannot assign CONSTANT to TUPLE", node.Span, TUPLE_ASSIGNMENT, Severity.Error);
            }

            if (node.Right is TupleExpression && node.Left.Any(item => item is TupleExpression))
            {
                TupleExpression rightTuple = (TupleExpression)node.Right;
                int count = node.Left.Sum(item => item is TupleExpression
                    ? ((TupleExpression)item).Items.Count
                    : 1
                );

                if (count != rightTuple.Items.Count)
                {
                    sink.Add(src, "Tuple item count on LEFT and RIGHT side differs", node.Span, TUPLE_COUNT_DIFFERS, Severity.Error);
                }
            }

            foreach (var tuple in node.Left.OfType<TupleExpression>())
            {
                string[] names = tuple.Items.OfType<NameExpression>().Select(item => item.Name).ToArray();
                if (names.Length <= 1)
                {
                    continue;
                }

                for (int i = 0; i < names.Length - 1; i++)
                {
                    string cName = names[i];

                    for (int j = i + 1; j < names.Length; j++)
                    {
                        if (cName == names[j])
                        {
                            sink.Add(src, String.Format("Tuple definition already declares item with name {0}", cName), node.Span, TOKEN_ALREADY_DECLARED, Severity.Error);
                        }
                    }
                }
            }

            CommonWalk(node);
            return true;
        }
コード例 #9
0
ファイル: Parser.cs プロジェクト: tnachen/ironruby
        private Statement FinishAssignments(Expression right) {
            List<Expression> left = new List<Expression>();

            while (MaybeEat(TokenKind.Assign)) {
                left.Add(right);

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

            Debug.Assert(left.Count > 0);

            AssignmentStatement assign = new AssignmentStatement(left.ToArray(), right);
            assign.SetLoc(left[0].Start, right.End);
            return assign;
        }
コード例 #10
0
 public override void PostWalk(AssignmentStatement node)
 {
 }
コード例 #11
0
 public void Visit(PyAst.AssignmentStatement node)
 {
     AppendLineWithIndentation($"{VisitExpressionsList(node.Left)} = {Visit(node.Right)}");
 }
コード例 #12
0
		public override bool Walk(AssignmentStatement node)
		{
			currentAssignStatement = node;
			foundVariableAssignment = false;
			return base.Walk(node);
		}		
コード例 #13
0
		public override bool Walk(AssignmentStatement node)
		{
			string fieldName = GetFieldName(node);
			AddFieldToDeclaringType(fieldName);
			return false;
		}
コード例 #14
0
        // Need an explanation/note here.
        public override bool Walk(AssignmentStatement node)
        {
            var container = containers.Peek ();

            foreach (Expression expr in node.Left) {
                switch (expr.NodeName) {
                case "NameExpression":
                    string identifier = ((NameExpression)expr).Name;
                    if (container is PythonFunction)
                        ((PythonFunction)container).Locals.Add (new PythonLocal () {
                            Name = identifier,
                            Region = GetDomRegion (node)
                        });
                    else
                        container.Attributes.Add (new PythonAttribute () {
                            Name = identifier,
                            Type = PythonAttributeType.Static,
                            Region = GetDomRegion (node)
                        });

                    break;
                case "MemberExpression":
                    string attrIdentifier;
                    if (!(container is PythonFunction) ||
                        !IsSelfAttr ((PythonFunction)container, (MemberExpression)expr, out attrIdentifier))
                        continue;

                    var parent = FindParentClass ();
                    if (parent != null)
                        parent.Attributes.Add (new PythonAttribute () {
                            Name = attrIdentifier,
                            Type = PythonAttributeType.Instance,
                            Region = GetDomRegion (expr)
                        });

                    break;
                }
            }

            return base.Walk (node);
        }
コード例 #15
0
		public override bool Walk(AssignmentStatement node)
		{			
			if (!FoundInitializeComponentMethod) {
				return false;
			}
			
			if (node.Left.Count > 0) {
				MemberExpression lhsMemberExpression = node.Left[0] as MemberExpression;
				NameExpression lhsNameExpression = node.Left[0] as NameExpression;
				if (lhsMemberExpression != null) {
					fieldExpression = PythonControlFieldExpression.Create(lhsMemberExpression);
					WalkMemberExpressionAssignmentRhs(node.Right);
				} else if (lhsNameExpression != null) {
					CallExpression callExpression = node.Right as CallExpression;
					if (callExpression != null) {
						object instance = CreateInstance(lhsNameExpression.Name.ToString(), callExpression);
						if (instance == null) {
							ThrowCouldNotFindTypeException(callExpression.Target as MemberExpression);
						}
					}
				}
			}
			return false;
		}
コード例 #16
0
		public PythonPropertyAssignment(AssignmentStatement assignmentStatement)
		{
			this.assignmentStatement = assignmentStatement;
		}
コード例 #17
0
		public PythonLocalVariableAssignment(AssignmentStatement assignment)
		{
			this.assignment = assignment;
			ParseAssignment();
		}
コード例 #18
0
		string GetFieldName(AssignmentStatement node)
		{
			string[] memberNames = PythonControlFieldExpression.GetMemberNames(node.Left[0] as MemberExpression);
			return GetFieldName(memberNames);
		}
コード例 #19
0
ファイル: JavascriptGenerator.cs プロジェクト: valdisz/PyToJs
        public override void PostWalk(AssignmentStatement node)
        {
            string right = Content();
            bool isInClass = Parent() is ClassDefinition || Parent(2) is ClassDefinition;
            bool isTuple = node.Right is TupleExpression || node.Left.Any(item => item is TupleExpression);

            List<string> left = new List<string>();
            for (int i = 0; i < node.Left.Sum(item => item is TupleExpression
                ? ((TupleExpression)item).Items.Count
                : 1); i++)
            {
                left.Add(Content());
            }
            left.Reverse();

            StringBuilder sb = new StringBuilder();
            string ind = isInClass
                ? String.Empty
                : Indent();

            int idx = 0;
            foreach (var item in node.Left)
            {
                bool varIsDefined = false;
                int count = 1;

                if (item is MemberExpression)
                {
                    varIsDefined = true;
                }
                else
                {
                    if (item is TupleExpression)
                    {
                        count = ((TupleExpression)item).Items.Count;
                    }
                }

                if (count > 1)
                {
                    string first = left[idx++];
                    InsertAssignment(IsDefined(first) || isInClass, sb, ind, first, right);

                    for (int i = 1; i < count; i++)
                    {
                        if (i > 0)
                        {
                            sb.AppendLine();
                        }

                        string name = left[idx++];
                        string value = String.Format("{0}[{1}]", first, idx - 1);

                        InsertAssignment(IsDefined(name) || isInClass, sb, ind, name, value);
                    }

                    sb.AppendLine();
                    InsertAssignment(true, sb, ind, first, String.Format("{0}[0]", first, idx - 1));
                }
                else
                {
                    if (idx > 0)
                    {
                        sb.AppendLine();
                    }

                    string name = left[idx++];
                    varIsDefined |= IsDefined(name) || isInClass;

                    InsertAssignment(varIsDefined, sb, ind, name, right);

                    right = name;
                }
            }

            Content(sb.ToString());

            CommonPostWalk(node, true);
        }
コード例 #20
0
ファイル: Parser.cs プロジェクト: bdoot/IronLanguages
        private Statement FinishAssignments(Expression right) {
            List<Expression> left = null;
            Expression singleLeft = null;

            while (MaybeEat(TokenKind.Assign)) {
                string assignError = right.CheckAssign();
                if (assignError != null) {
                    ReportSyntaxError(right.StartIndex, right.EndIndex, assignError, ErrorCodes.SyntaxError | ErrorCodes.NoCaret);
                }

                if (singleLeft == null) {
                    singleLeft = right;
                } else {
                    if (left == null) {
                        left = new List<Expression>();
                        left.Add(singleLeft);
                    }
                    left.Add(right);
                }

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

            if (left != null) {
                Debug.Assert(left.Count > 0);

                AssignmentStatement assign = new AssignmentStatement(left.ToArray(), right);
                assign.SetLoc(_globalParent, left[0].StartIndex, right.EndIndex);
                return assign;
            } else {
                Debug.Assert(singleLeft != null);

                AssignmentStatement assign = new AssignmentStatement(new[] { singleLeft }, right);
                assign.SetLoc(_globalParent, singleLeft.StartIndex, right.EndIndex);
                return assign;
            }
        }
コード例 #21
0
ファイル: _ast.cs プロジェクト: rchandrashekara/main
            internal Assign(AssignmentStatement stmt)
                : this() {
                _targets = PythonOps.MakeEmptyList(stmt.Left.Count);
                foreach (Compiler.Ast.Expression expr in stmt.Left)
                    _targets.Add(Convert(expr, Store.Instance));

                _value = Convert(stmt.Right);
            }
コード例 #22
0
 public static string Format(AssignmentStatement node)
 {
     return(node.Left.Format() + " = " + Format(node.Right));
 }
コード例 #23
0
ファイル: PythonNameBinder.cs プロジェクト: TerabyteX/main
 // AssignmentStatement
 public override bool Walk(AssignmentStatement node)
 {
     node.Parent = _currentScope;
     foreach (Expression e in node.Left) {
         e.Walk(_define);
     }
     return true;
 }
コード例 #24
0
		public override bool Walk(AssignmentStatement node)
		{
			if (currentClass != null) {
				FindProperty(node);
				return false;
			}
			return base.Walk(node);
		}
コード例 #25
0
ファイル: Parser.cs プロジェクト: techarch/ironruby
        private Statement FinishAssignments(Expression right) {
            List<Expression> left = new List<Expression>();

            while (MaybeEat(TokenKind.Assign)) {
                string assignError = right.CheckAssign();
                if (assignError != null) {
                    ReportSyntaxError(right.Span.Start, right.Span.End, assignError, ErrorCodes.SyntaxError);
                }

                left.Add(right);

                if (MaybeEat(TokenKind.KeywordYield)) {
                    right = ParseYieldExpression();
                } else {
                    bool trailingComma;
                    var exprs = ParseExpressionList(out trailingComma);
                    if (exprs.Count == 0) {
                        ReportSyntaxError(left[0].Start, left[0].End, "invalid syntax");
                    }
                    right = MakeTupleOrExpr(exprs, trailingComma);
                }
            }

            Debug.Assert(left.Count > 0);

            AssignmentStatement assign = new AssignmentStatement(left.ToArray(), right);
            assign.SetLoc(left[0].Start, right.End);
            return assign;
        }
コード例 #26
0
		void FindProperty(AssignmentStatement node)
		{
			PythonPropertyAssignment propertyAssignment = new PythonPropertyAssignment(node);
			propertyAssignment.CreateProperty(currentClass);
		}
コード例 #27
0
ファイル: FlowChecker.cs プロジェクト: CookieEaters/FireHTTP
 // AssignStmt
 public override bool Walk(AssignmentStatement node) {
     node.Right.Walk(this);
     foreach (Expression e in node.Left) {
         e.Walk(_fdef);
     }
     return false;
 }
コード例 #28
0
ファイル: FlowChecker.cs プロジェクト: CookieEaters/FireHTTP
 public override void PostWalk(AssignmentStatement node) { }
コード例 #29
0
 public override bool Walk(AssignmentStatement node) {
     foreach (Expression lhs in node.Left) {
         MemberExpression me = lhs as MemberExpression;
         if (me != null) {
             if (IsSelfReference(me.Target)) {
                 _names[me.Name] = true;
             }
         }
     }
     return true;
 }
コード例 #30
0
ファイル: ResolveWalker.cs プロジェクト: Rpinski/SharpDevelop
		public override bool Walk(AssignmentStatement node)
		{
			writer.WriteLine("AssignmentStatement");
			return base.Walk(node);
		}