public void NoLeftHandSideExpressionsInAssignment() { List<Expression> lhs = new List<Expression>(); AssignmentStatement assign = new AssignmentStatement(lhs.ToArray(), null); PythonComponentWalker walker = new PythonComponentWalker(this); walker.Walk(assign); }
public override bool Walk(AssignmentStatement node) { foreach (var expr in node.Left) { WalkAssignmentTarget(expr); } node.Right?.Walk(this); return(false); }
// AssignmentStatement public override bool Walk(AssignmentStatement node) { node.Parent = _currentScope; foreach (Expression e in node.Left) { e.Walk(_define); } return(true); }
// AssignStmt public override bool Walk(AssignmentStatement node) { node.Right.Walk(this); foreach (Expression e in node.Left) { e.Walk(_fdef); } return(false); }
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); }
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); }
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); }
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; }
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; }
public override void PostWalk(AssignmentStatement node) { }
public void Visit(PyAst.AssignmentStatement node) { AppendLineWithIndentation($"{VisitExpressionsList(node.Left)} = {Visit(node.Right)}"); }
public override bool Walk(AssignmentStatement node) { currentAssignStatement = node; foundVariableAssignment = false; return base.Walk(node); }
public override bool Walk(AssignmentStatement node) { string fieldName = GetFieldName(node); AddFieldToDeclaringType(fieldName); return false; }
// 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); }
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; }
public PythonPropertyAssignment(AssignmentStatement assignmentStatement) { this.assignmentStatement = assignmentStatement; }
public PythonLocalVariableAssignment(AssignmentStatement assignment) { this.assignment = assignment; ParseAssignment(); }
string GetFieldName(AssignmentStatement node) { string[] memberNames = PythonControlFieldExpression.GetMemberNames(node.Left[0] as MemberExpression); return GetFieldName(memberNames); }
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); }
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; } }
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); }
public static string Format(AssignmentStatement node) { return(node.Left.Format() + " = " + Format(node.Right)); }
// AssignmentStatement public override bool Walk(AssignmentStatement node) { node.Parent = _currentScope; foreach (Expression e in node.Left) { e.Walk(_define); } return true; }
public override bool Walk(AssignmentStatement node) { if (currentClass != null) { FindProperty(node); return false; } return base.Walk(node); }
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; }
void FindProperty(AssignmentStatement node) { PythonPropertyAssignment propertyAssignment = new PythonPropertyAssignment(node); propertyAssignment.CreateProperty(currentClass); }
// AssignStmt public override bool Walk(AssignmentStatement node) { node.Right.Walk(this); foreach (Expression e in node.Left) { e.Walk(_fdef); } return false; }
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; }
public override bool Walk(AssignmentStatement node) { writer.WriteLine("AssignmentStatement"); return base.Walk(node); }