Пример #1
0
			public override object Visit (CompoundAssign compoundAssign)
			{
				var result = new AssignmentExpression ();
				int opLength = 2;
				switch (compoundAssign.Op) {
				case Binary.Operator.Multiply:
					result.AssignmentOperatorType = AssignmentOperatorType.Multiply;
					break;
				case Binary.Operator.Division:
					result.AssignmentOperatorType = AssignmentOperatorType.Divide;
					break;
				case Binary.Operator.Modulus:
					result.AssignmentOperatorType = AssignmentOperatorType.Modulus;
					break;
				case Binary.Operator.Addition:
					result.AssignmentOperatorType = AssignmentOperatorType.Add;
					break;
				case Binary.Operator.Subtraction:
					result.AssignmentOperatorType = AssignmentOperatorType.Subtract;
					break;
				case Binary.Operator.LeftShift:
					result.AssignmentOperatorType = AssignmentOperatorType.ShiftLeft;
					opLength = 3;
					break;
				case Binary.Operator.RightShift:
					result.AssignmentOperatorType = AssignmentOperatorType.ShiftRight;
					opLength = 3;
					break;
				case Binary.Operator.BitwiseAnd:
					result.AssignmentOperatorType = AssignmentOperatorType.BitwiseAnd;
					break;
				case Binary.Operator.BitwiseOr:
					result.AssignmentOperatorType = AssignmentOperatorType.BitwiseOr;
					break;
				case Binary.Operator.ExclusiveOr:
					result.AssignmentOperatorType = AssignmentOperatorType.ExclusiveOr;
					break;
				}
				
				result.AddChild ((INode)compoundAssign.Target.Accept (this), AssignmentExpression.LeftExpressionRole);
				result.AddChild (new CSharpTokenNode (Convert (compoundAssign.Location), opLength), AssignmentExpression.OperatorRole);
				result.AddChild ((INode)compoundAssign.Source.Accept (this), AssignmentExpression.RightExpressionRole);
				return result;
			}
Пример #2
0
			public override object Visit (SimpleAssign simpleAssign)
			{
				var result = new AssignmentExpression ();
				
				result.AssignmentOperatorType = AssignmentOperatorType.Assign;
				if (simpleAssign.Target != null)
					result.AddChild ((INode)simpleAssign.Target.Accept (this), AssignmentExpression.LeftExpressionRole);
				result.AddChild (new CSharpTokenNode (Convert (simpleAssign.Location), 1), AssignmentExpression.OperatorRole);
				
				if (simpleAssign.Source != null) {
					result.AddChild ((INode)simpleAssign.Source.Accept (this), AssignmentExpression.RightExpressionRole);
				}
				return result;
			}
Пример #3
0
			public override object Visit(CompoundAssign compoundAssign)
			{
				var result = new AssignmentExpression();
				switch (compoundAssign.Op) {
					case Binary.Operator.Multiply:
						result.Operator = AssignmentOperatorType.Multiply;
						break;
					case Binary.Operator.Division:
						result.Operator = AssignmentOperatorType.Divide;
						break;
					case Binary.Operator.Modulus:
						result.Operator = AssignmentOperatorType.Modulus;
						break;
					case Binary.Operator.Addition:
						result.Operator = AssignmentOperatorType.Add;
						break;
					case Binary.Operator.Subtraction:
						result.Operator = AssignmentOperatorType.Subtract;
						break;
					case Binary.Operator.LeftShift:
						result.Operator = AssignmentOperatorType.ShiftLeft;
						break;
					case Binary.Operator.RightShift:
						result.Operator = AssignmentOperatorType.ShiftRight;
						break;
					case Binary.Operator.BitwiseAnd:
						result.Operator = AssignmentOperatorType.BitwiseAnd;
						break;
					case Binary.Operator.BitwiseOr:
						result.Operator = AssignmentOperatorType.BitwiseOr;
						break;
					case Binary.Operator.ExclusiveOr:
						result.Operator = AssignmentOperatorType.ExclusiveOr;
						break;
				}
				
				if (compoundAssign.Target != null)
					result.AddChild((Expression)compoundAssign.Target.Accept(this), AssignmentExpression.LeftRole);
				var location = LocationsBag.GetLocations(compoundAssign);
				if (location != null) {
					var r = AssignmentExpression.GetOperatorRole(result.Operator);
					result.AddChild(new CSharpTokenNode(Convert(location [0]), r), r);
				}
				if (compoundAssign.Source != null)
					result.AddChild((Expression)compoundAssign.Source.Accept(this), AssignmentExpression.RightRole);
				return result;
			}
Пример #4
0
			public override object Visit(SimpleAssign simpleAssign)
			{
				var result = new AssignmentExpression();
				
				result.Operator = AssignmentOperatorType.Assign;
				if (simpleAssign.Target != null)
					result.AddChild((Expression)simpleAssign.Target.Accept(this), AssignmentExpression.LeftRole);
				var location = LocationsBag.GetLocations(simpleAssign);
				if (location != null)
					result.AddChild(new CSharpTokenNode(Convert(location [0]), AssignmentExpression.AssignRole), AssignmentExpression.AssignRole);
				if (simpleAssign.Source != null) {
					result.AddChild((Expression)simpleAssign.Source.Accept(this), AssignmentExpression.RightRole);
				}
				return result;
			}
Пример #5
0
        public override void ExitAssignmentExpression(AssignmentExpression assignmentExpression)
        {
            if (assignmentExpression.Operator.Value != "=")
            {
                var rightSide = assignmentExpression.Right;
                rightSide.Remove();
                var leftClone = AstCloner.Clone(assignmentExpression.Left);
                switch (leftClone)
                {
                case SimpleNameExpression simpleNameExpression:
                    if (simpleNameExpression.Declaration is SetterDeclaration)
                    {
                        var classDeclaration = (ClassDeclaration)simpleNameExpression.Declaration.Parent;
                        var getterSetter     = classDeclaration.GettersAndSetters.Single(x => x.Setter == simpleNameExpression.Declaration);
                        simpleNameExpression.Declaration = getterSetter.Getter;
                    }
                    break;

                case MemberExpression memberExpression:
                    if (memberExpression.Declaration is SetterDeclaration)
                    {
                        var classDeclaration = (ClassDeclaration)memberExpression.Declaration.Parent;
                        var getterSetter     = classDeclaration.GettersAndSetters.Single(x => x.Setter == memberExpression.Declaration);
                        memberExpression.Declaration = getterSetter.Getter;
                    }
                    break;
                }
                assignmentExpression.AddChild(
                    new BinaryExpression(assignmentExpression.Context,
                                         new INode[]
                {
                    leftClone,
                    new Token(assignmentExpression.Context, assignmentExpression.Operator.Value.Substring(0, assignmentExpression.Operator.Value.Length - 1)),
                    rightSide
                }));
                assignmentExpression.Operator.Value = "=";
            }

            if (!(assignmentExpression.Parent is ExpressionStatement || assignmentExpression.Parent is ForStatement || assignmentExpression.Parent is ForeachStatement))
            {
                var statement = assignmentExpression.NearestAncestorOfType <IStatement>();
                var block     = (BlockStatement)statement.Parent;
                var variable  = new VariableDeclaration(assignmentExpression.Context,
                                                        "var" + NumberWheel.Next(),
                                                        new INode[]
                {
                    assignmentExpression.Type.Wrap(assignmentExpression.Context),
                    assignmentExpression.Right
                })
                {
                    VariableType = VariableType.Const
                };
                block.VariableDeclarations.Add(variable);
                block.AddChildBefore(statement, new VariableDeclarationStatement(assignmentExpression.Context, variable));
                block.AddChildBefore(statement, new ExpressionStatement(assignmentExpression.Context,
                                                                        new AssignmentExpression(
                                                                            assignmentExpression.Context,
                                                                            new INode[]
                {
                    assignmentExpression.Left,
                    assignmentExpression.Operator,
                    new SimpleNameExpression(assignmentExpression.Context, variable.Name)
                    {
                        Declaration = variable,
                        Type        = variable.Type
                    },
                })
                {
                    Type = assignmentExpression.Type
                })
                                     );
                assignmentExpression.ReplaceWith(
                    new SimpleNameExpression(assignmentExpression.Context, variable.Name)
                {
                    Declaration = variable,
                    Type        = variable.Type
                });
            }
        }
Пример #6
0
			IEnumerable<Attribute> GetAttributes (List<Mono.CSharp.Attribute> optAttributes)
			{
				if (optAttributes == null)
					yield break;
				foreach (var attr in optAttributes) {
					Attribute result = new Attribute ();
					result.Type = ConvertToType (attr.TypeNameExpression);
					
					if (attr.PosArguments != null) {
						foreach (var arg in attr.PosArguments) {
							result.AddChild ((Expression)arg.Expr.Accept (this), Attribute.Roles.Argument);
						}
					}
					if (attr.NamedArguments != null) { 
						foreach (NamedArgument na in attr.NamedArguments) {
							var newArg = new AssignmentExpression ();
							newArg.Operator = AssignmentOperatorType.Assign;
							newArg.AddChild (new IdentifierExpression (na.Name, Convert (na.Location)), AssignmentExpression.LeftRole);
							
							var loc = LocationsBag.GetLocations (na);
							if (loc != null)
								newArg.AddChild (new CSharpTokenNode (Convert (loc[0]), 1), AssignmentExpression.Roles.Assign);
							newArg.AddChild ((Expression)na.Expr.Accept (this), AssignmentExpression.RightRole);
							result.AddChild (newArg, Attribute.Roles.Argument);
						}
					}
					yield return result;
				}
			}