public override AstNode VisitAssignmentExpression(AssignmentExpression assignmentExpression) { var rr = this.Resolver.ResolveNode(assignmentExpression, null); if (assignmentExpression.Operator != AssignmentOperatorType.Any && assignmentExpression.Operator != AssignmentOperatorType.Assign && (Helpers.IsIntegerType(rr.Type, this.Resolver))) { var clonAssignmentExpression = (AssignmentExpression)base.VisitAssignmentExpression(assignmentExpression); if (clonAssignmentExpression == null) { clonAssignmentExpression = (AssignmentExpression)assignmentExpression.Clone(); } var op = clonAssignmentExpression.Operator; clonAssignmentExpression.Operator = AssignmentOperatorType.Assign; BinaryOperatorType opType; switch (op) { case AssignmentOperatorType.Add: opType = BinaryOperatorType.Add; break; case AssignmentOperatorType.Subtract: opType = BinaryOperatorType.Subtract; break; case AssignmentOperatorType.Multiply: opType = BinaryOperatorType.Multiply; break; case AssignmentOperatorType.Divide: opType = BinaryOperatorType.Divide; break; case AssignmentOperatorType.Modulus: opType = BinaryOperatorType.Modulus; break; case AssignmentOperatorType.ShiftLeft: opType = BinaryOperatorType.ShiftLeft; break; case AssignmentOperatorType.ShiftRight: opType = BinaryOperatorType.ShiftRight; break; case AssignmentOperatorType.BitwiseAnd: opType = BinaryOperatorType.BitwiseAnd; break; case AssignmentOperatorType.BitwiseOr: opType = BinaryOperatorType.BitwiseOr; break; case AssignmentOperatorType.ExclusiveOr: opType = BinaryOperatorType.ExclusiveOr; break; default: throw new ArgumentOutOfRangeException(); } if (clonAssignmentExpression.Right is BinaryOperatorExpression) { clonAssignmentExpression.Right = new BinaryOperatorExpression(clonAssignmentExpression.Left.Clone(), opType, new ParenthesizedExpression(clonAssignmentExpression.Right.Clone())); } else { clonAssignmentExpression.Right = new BinaryOperatorExpression(clonAssignmentExpression.Left.Clone(), opType, clonAssignmentExpression.Right.Clone()); } return(clonAssignmentExpression); } return(base.VisitAssignmentExpression(assignmentExpression)); }
public virtual Differences VisitAssignmentExpression(AssignmentExpression assignment1, AssignmentExpression assignment2){ Differences differences = new Differences(assignment1, assignment2); if (assignment1 == null || assignment2 == null){ if (assignment1 != assignment2) differences.NumberOfDifferences++; else differences.NumberOfSimilarities++; return differences; } AssignmentExpression changes = (AssignmentExpression)assignment2.Clone(); AssignmentExpression deletions = (AssignmentExpression)assignment2.Clone(); AssignmentExpression insertions = (AssignmentExpression)assignment2.Clone(); Differences diff = this.VisitStatement(assignment1.AssignmentStatement, assignment2.AssignmentStatement); if (diff == null){Debug.Assert(false); return differences;} changes.AssignmentStatement = diff.Changes as AssignmentStatement; deletions.AssignmentStatement = diff.Deletions as AssignmentStatement; insertions.AssignmentStatement = diff.Insertions as AssignmentStatement; Debug.Assert(diff.Changes == changes.AssignmentStatement && diff.Deletions == deletions.AssignmentStatement && diff.Insertions == insertions.AssignmentStatement); differences.NumberOfDifferences += diff.NumberOfDifferences; differences.NumberOfSimilarities += diff.NumberOfSimilarities; if (differences.NumberOfDifferences == 0){ differences.Changes = null; differences.Deletions = null; differences.Insertions = null; }else{ differences.Changes = changes; differences.Deletions = deletions; differences.Insertions = insertions; } return differences; }
public override Expression VisitAssignmentExpression(AssignmentExpression assignment) { if (assignment == null) return null; return base.VisitAssignmentExpression((AssignmentExpression)assignment.Clone()); }
public override AstNode VisitAssignmentExpression(AssignmentExpression assignmentExpression) { var rr = this.Resolver.ResolveNode(assignmentExpression, null); bool found = false; var isInt = Helpers.IsIntegerType(rr.Type, this.Resolver); if (isInt || !(assignmentExpression.Parent is ExpressionStatement)) { found = true; } if (found && !isInt && assignmentExpression.Parent is ICSharpCode.NRefactory.CSharp.LambdaExpression) { var lambdarr = this.Resolver.ResolveNode(assignmentExpression.Parent, null) as LambdaResolveResult; if (lambdarr != null && lambdarr.ReturnType.Kind == TypeKind.Void) { found = false; } } if (assignmentExpression.Operator == AssignmentOperatorType.Add && rr.Type.IsKnownType(KnownTypeCode.String)) { found = true; } if (assignmentExpression.Operator != AssignmentOperatorType.Any && assignmentExpression.Operator != AssignmentOperatorType.Assign && found) { AssignmentExpression clonAssignmentExpression = (AssignmentExpression)base.VisitAssignmentExpression(assignmentExpression); if (clonAssignmentExpression == null) { clonAssignmentExpression = (AssignmentExpression)assignmentExpression.Clone(); } var op = clonAssignmentExpression.Operator; clonAssignmentExpression.Operator = AssignmentOperatorType.Assign; BinaryOperatorType opType; switch (op) { case AssignmentOperatorType.Add: opType = BinaryOperatorType.Add; break; case AssignmentOperatorType.Subtract: opType = BinaryOperatorType.Subtract; break; case AssignmentOperatorType.Multiply: opType = BinaryOperatorType.Multiply; break; case AssignmentOperatorType.Divide: opType = BinaryOperatorType.Divide; break; case AssignmentOperatorType.Modulus: opType = BinaryOperatorType.Modulus; break; case AssignmentOperatorType.ShiftLeft: opType = BinaryOperatorType.ShiftLeft; break; case AssignmentOperatorType.ShiftRight: opType = BinaryOperatorType.ShiftRight; break; case AssignmentOperatorType.BitwiseAnd: opType = BinaryOperatorType.BitwiseAnd; break; case AssignmentOperatorType.BitwiseOr: opType = BinaryOperatorType.BitwiseOr; break; case AssignmentOperatorType.ExclusiveOr: opType = BinaryOperatorType.ExclusiveOr; break; default: throw new ArgumentOutOfRangeException(); } var wrapRightExpression = AssigmentExpressionHelper.CheckIsRightAssigmentExpression(clonAssignmentExpression) ? clonAssignmentExpression.Right.Clone() : new ParenthesizedExpression(clonAssignmentExpression.Right.Clone()); clonAssignmentExpression.Right = new BinaryOperatorExpression( clonAssignmentExpression.Left.Clone(), opType, wrapRightExpression); return(clonAssignmentExpression); } return(base.VisitAssignmentExpression(assignmentExpression)); }
public override AstNode VisitAssignmentExpression(AssignmentExpression assignmentExpression) { var rr = this.Resolver.ResolveNode(assignmentExpression, null); var orr = rr as OperatorResolveResult; var simpleIndex = true; if (orr != null) { var accessrr = orr.Operands[0] as ArrayAccessResolveResult; if (accessrr != null) { foreach (var index in accessrr.Indexes) { var indexMemberTargetrr = index as MemberResolveResult; bool isIndexSimple = (indexMemberTargetrr != null && indexMemberTargetrr.Member is IField && (indexMemberTargetrr.TargetResult is ThisResolveResult || indexMemberTargetrr.TargetResult is LocalResolveResult)) || index is ThisResolveResult || index is LocalResolveResult || index is ConstantResolveResult; if (!isIndexSimple) { simpleIndex = false; } } } } bool found = false; var isInt = Helpers.IsIntegerType(rr.Type, this.Resolver); if (this.Rules.Integer == IntegerRule.Managed && isInt || !(assignmentExpression.Parent is ExpressionStatement)) { found = true; } if (found && !isInt && assignmentExpression.Parent is ICSharpCode.NRefactory.CSharp.LambdaExpression) { var lambdarr = this.Resolver.ResolveNode(assignmentExpression.Parent, null) as LambdaResolveResult; if (lambdarr != null && lambdarr.ReturnType.Kind == TypeKind.Void) { found = false; } } if (assignmentExpression.Operator == AssignmentOperatorType.Add && rr.Type.IsKnownType(KnownTypeCode.String)) { found = true; } if (assignmentExpression.Operator != AssignmentOperatorType.Any && assignmentExpression.Operator != AssignmentOperatorType.Assign && found) { AssignmentExpression clonAssignmentExpression = (AssignmentExpression)base.VisitAssignmentExpression(assignmentExpression); if (clonAssignmentExpression == null) { clonAssignmentExpression = (AssignmentExpression)assignmentExpression.Clone(); } var indexerExpr = clonAssignmentExpression.Left as IndexerExpression; List<Expression> leftIndexerArgs = null; List<Expression> rightIndexerArgs = null; var needReturnValue = false; if (indexerExpr != null && !simpleIndex) { leftIndexerArgs = new List<Expression>(); rightIndexerArgs = new List<Expression>(); foreach (var index in indexerExpr.Arguments) { var expr = new InvocationExpression(new MemberReferenceExpression(new MemberReferenceExpression(new TypeReferenceExpression(new MemberType(new SimpleType("global"), CS.NS.BRIDGE) { IsDoubleColon = true }), "Script"), "ToTemp"), new PrimitiveExpression("idx" + tempKey), index.Clone()); leftIndexerArgs.Add(expr); expr = new InvocationExpression(new MemberReferenceExpression(new MemberReferenceExpression(new TypeReferenceExpression(new MemberType(new SimpleType("global"), CS.NS.BRIDGE) { IsDoubleColon = true }), "Script"), "FromTemp"), new PrimitiveExpression("idx" + tempKey++), index.Clone()); rightIndexerArgs.Add(expr); } needReturnValue = !(assignmentExpression.Parent is ExpressionStatement); if (needReturnValue && assignmentExpression.Parent is LambdaExpression) { var lambdarr = this.Resolver.ResolveNode(assignmentExpression.Parent, null) as LambdaResolveResult; if (lambdarr != null && lambdarr.ReturnType.Kind == TypeKind.Void) { needReturnValue = false; } } clonAssignmentExpression.Left = new IndexerExpression(indexerExpr.Target.Clone(), needReturnValue ? rightIndexerArgs : leftIndexerArgs); } else { indexerExpr = null; } var op = clonAssignmentExpression.Operator; clonAssignmentExpression.Operator = AssignmentOperatorType.Assign; BinaryOperatorType opType; switch (op) { case AssignmentOperatorType.Add: opType = BinaryOperatorType.Add; break; case AssignmentOperatorType.Subtract: opType = BinaryOperatorType.Subtract; break; case AssignmentOperatorType.Multiply: opType = BinaryOperatorType.Multiply; break; case AssignmentOperatorType.Divide: opType = BinaryOperatorType.Divide; break; case AssignmentOperatorType.Modulus: opType = BinaryOperatorType.Modulus; break; case AssignmentOperatorType.ShiftLeft: opType = BinaryOperatorType.ShiftLeft; break; case AssignmentOperatorType.ShiftRight: opType = BinaryOperatorType.ShiftRight; break; case AssignmentOperatorType.BitwiseAnd: opType = BinaryOperatorType.BitwiseAnd; break; case AssignmentOperatorType.BitwiseOr: opType = BinaryOperatorType.BitwiseOr; break; case AssignmentOperatorType.ExclusiveOr: opType = BinaryOperatorType.ExclusiveOr; break; default: throw new ArgumentOutOfRangeException(); } var wrapRightExpression = AssigmentExpressionHelper.CheckIsRightAssigmentExpression(clonAssignmentExpression) ? clonAssignmentExpression.Right.Clone() : new ParenthesizedExpression(clonAssignmentExpression.Right.Clone()); clonAssignmentExpression.Right = new BinaryOperatorExpression( indexerExpr != null ? new IndexerExpression(indexerExpr.Target.Clone(), needReturnValue ? leftIndexerArgs : rightIndexerArgs) : clonAssignmentExpression.Left.Clone(), opType, wrapRightExpression); return clonAssignmentExpression; } return base.VisitAssignmentExpression(assignmentExpression); }