Example #1
0
        /// <summary>
        /// Applies the transformation
        /// </summary>
        /// <returns>The transformed item.</returns>
        /// <param name="item">The item to visit.</param>
        public virtual ASTItem Transform(ASTItem item)
        {
            var exp = item as Expression;

            if (exp == null)
            {
                return(item);
            }

            // If this is top-level, we do not want a wrapping
            if (exp.Parent is Statement || exp.Parent is ParenthesizedExpression)
            {
                return(item);
            }

            if (!SIMPLE_TYPES.Any(x => exp.GetType().IsAssignableFrom(x)) && !(exp.Parent is AssignmentExpression))
            {
                var np = new ParenthesizedExpression()
                {
                    Expression       = exp,
                    Parent           = exp.Parent,
                    Name             = exp.Name,
                    SourceExpression = exp.SourceExpression,
                    SourceResultType = exp.SourceResultType
                };

                exp.ReplaceWith(np);
                exp.Parent = np;

                return(np);
            }

            return(item);
        }
Example #2
0
        protected override IPhpValue VisitParenthesizedExpression(ParenthesizedExpression src)
        {
            var e = TransValue(src.Expression);
            var a = new PhpParenthesizedExpression(e);

            return(SimplifyPhpExpression(a));
        }
Example #3
0
 public virtual void VisitParenthesizedExpression(ParenthesizedExpression parenthesizedExpression)
 {
     if (this.ThrowException)
     {
         throw (System.Exception) this.CreateException(parenthesizedExpression);
     }
 }
        private static INode ModifyLambdaForSelectMany(LambdaExpression lambdaExpression,
                                                       ParenthesizedExpression parenthesizedlambdaExpression,
                                                       InvocationExpression invocationExpression)
        {
            INode node   = lambdaExpression;
            var   argPos = invocationExpression.Arguments.IndexOf(lambdaExpression);

            switch (argPos)
            {
            case 0:                     // first one, select the collection
                                        // need to enter a cast for (IEnumerable<dynamic>) on the end of the lambda body
                var selectManyExpression = new LambdaExpression
                {
                    ExpressionBody =
                        new CastExpression(new TypeReference("IEnumerable<dynamic>"),
                                           new ParenthesizedExpression(lambdaExpression.ExpressionBody), CastType.Cast),
                    Parameters = lambdaExpression.Parameters,
                };
                node = new CastExpression(new TypeReference("Func<dynamic, IEnumerable<dynamic>>"),
                                          new ParenthesizedExpression(selectManyExpression), CastType.Cast);
                break;

            case 1:                     // the transformation func
                node = new CastExpression(new TypeReference("Func<dynamic, dynamic, dynamic>"), parenthesizedlambdaExpression,
                                          CastType.Cast);
                break;
            }
            return(node);
        }
Example #5
0
        public void Resolved(AstNode node, ResolveResult result)
        {
            if (ParenthesizedExpression.ActsAsParenthesizedExpression(node))
            {
                return;
            }

            MemberResolveResult mrr = result as MemberResolveResult;

            if (mrr != null)
            {
                memberReferenceFound(node, mrr.Member);
            }
            TypeResolveResult trr = result as TypeResolveResult;

            if (trr != null)
            {
                typeReferenceFound(node, trr.Type);
            }
            ForEachResolveResult ferr = result as ForEachResolveResult;

            if (ferr != null)
            {
                Resolved(node, ferr.GetEnumeratorCall);
                if (ferr.CurrentProperty != null)
                {
                    memberReferenceFound(node, ferr.CurrentProperty);
                }
                if (ferr.MoveNextMethod != null)
                {
                    memberReferenceFound(node, ferr.MoveNextMethod);
                }
            }
        }
Example #6
0
        public JNode VisitParenthesizedExpression(ParenthesizedExpression node)
        {
            var res   = node.Resolve();
            var node2 = Visit(res);

            return(node2);
        }
Example #7
0
 public virtual void VisitParenthesizedExpression(ParenthesizedExpression parenthesizedExpression)
 {
     if (ThrowException)
     {
         throw (Exception)CreateException(parenthesizedExpression);
     }
 }
        private static AstNode ModifyLambdaForSelectMany(LambdaExpression lambdaExpression,
                                                         ParenthesizedExpression parenthesizedlambdaExpression,
                                                         InvocationExpression invocationExpression)
        {
            AstNode node = lambdaExpression;

            if (invocationExpression.Arguments.Count > 0 && invocationExpression.Arguments.ElementAt(0) == lambdaExpression)           // first one, select the collection
            {
                // need to enter a cast for (IEnumerable<dynamic>) on the end of the lambda body
                var selectManyExpression = new LambdaExpression
                {
                    Body =
                        new CastExpression(new SimpleType("IEnumerable<dynamic>"),
                                           new ParenthesizedExpression((Expression)lambdaExpression.Body.Clone())),
                };
                selectManyExpression.Parameters.AddRange(lambdaExpression.Parameters.Select(x => (ParameterDeclaration)x.Clone()));

                node = new CastExpression(new SimpleType("Func<dynamic, IEnumerable<dynamic>>"),
                                          new ParenthesizedExpression(selectManyExpression.Clone()));
            }
            else if (invocationExpression.Arguments.Count > 1 && invocationExpression.Arguments.ElementAt(1) == lambdaExpression)            // first one, select the collection
            {
                node = new CastExpression(new SimpleType("Func<dynamic, dynamic, dynamic>"), parenthesizedlambdaExpression.Clone());
            }
            return(node);
        }
        public override object VisitLambdaExpression(ICSharpCode.NRefactory.Ast.LambdaExpression lambdaExpression, object data)
        {
            var invocationExpression = lambdaExpression.Parent as InvocationExpression;

            if (invocationExpression == null)
            {
                return(base.VisitLambdaExpression(lambdaExpression, data));
            }

            var target = invocationExpression.TargetObject as MemberReferenceExpression;

            if (target == null)
            {
                return(base.VisitLambdaExpression(lambdaExpression, data));
            }

            INode node = lambdaExpression;
            var   parenthesizedlambdaExpression = new ParenthesizedExpression(lambdaExpression);

            switch (target.MemberName)
            {
            case "Sum":
            case "Average":
                node = ModifyLambdaForNumerics(lambdaExpression, parenthesizedlambdaExpression);
                break;

            case "Max":
            case "Min":
                node = ModifyLambdaForMinMax(lambdaExpression, parenthesizedlambdaExpression);
                break;

            case "OrderBy":
            case "OrderByDescending":
            case "GroupBy":
            case "Recurse":
            case "Select":
                node = ModifyLambdaForSelect(parenthesizedlambdaExpression, target);
                break;

            case "SelectMany":
                node = ModifyLambdaForSelectMany(lambdaExpression, parenthesizedlambdaExpression, invocationExpression);
                break;

            case "Any":
            case "all":
            case "First":
            case "FirstOrDefault":
            case "Last":
            case "LastOfDefault":
            case "Single":
            case "Where":
            case "Count":
            case "SingleOrDefault":
                node = new CastExpression(new TypeReference("Func<dynamic, bool>"), parenthesizedlambdaExpression, CastType.Cast);
                break;
            }
            ReplaceCurrentNode(node);

            return(base.VisitLambdaExpression(lambdaExpression, data));
        }
Example #10
0
        protected virtual void Visit(ParenthesizedExpression parenthesizedExpression)
        {
            Visit((Node)parenthesizedExpression);

            // Get the type from the last item
            parenthesizedExpression.TypeInference = (TypeInference)parenthesizedExpression.Content.TypeInference.Clone();
        }
 public object VisitParenthesizedExpression(ParenthesizedExpression parenthesizedExpression, object data)
 {
     this.builder.Append("(");
     parenthesizedExpression.Expression.AcceptVisitor(this, data);
     this.builder.Append(")");
     return(data);
 }
 public override object Visit(ParenthesizedExpression parenthesizedExpression, object data)
 {
     if (parenthesizedExpression == null) {
         return null;
     }
     return parenthesizedExpression.Expression.AcceptVisitor(this, data);
 }
        public override void VisitParenthesizedExpression(ParenthesizedExpression parenthesizedExpression)
        {
            base.VisitParenthesizedExpression(parenthesizedExpression);

            if (parenthesizedExpression.Expression is PrimitiveExpression)
                parenthesizedExpression.ReplaceWith(parenthesizedExpression.Expression);
        }
Example #14
0
            public override void VisitParenthesizedExpression(ParenthesizedExpression node)
            {
                base.VisitParenthesizedExpression(node);

                // nested expressions should not see outer path scope
                _binder._pathScope            = null;
                _binder._implicitArgumentType = null;
            }
Example #15
0
        /// <summary>
        /// Visits the specified parenthesized expression.
        /// </summary>
        /// <param name="parenthesizedExpression">The parenthesized expression.</param>
        public override Node Visit(ParenthesizedExpression parenthesizedExpression)
        {
            base.Visit(parenthesizedExpression);

            // Get the type from the last item
            parenthesizedExpression.TypeInference = (TypeInference)parenthesizedExpression.Content.TypeInference.Clone();
            return(parenthesizedExpression);
        }
        public void VBNetPrimitiveParenthesizedExpression()
        {
            ParenthesizedExpression p = ParseUtilVBNet.ParseExpression <ParenthesizedExpression>("((1))");

            Assert.IsTrue(p.Expression is ParenthesizedExpression);
            p = p.Expression as ParenthesizedExpression;;
            Assert.IsTrue(p.Expression is PrimitiveExpression);
        }
 public override object VisitParenthesizedExpression(ParenthesizedExpression parenthesizedExpression, object data)
 {
     if (parenthesizedExpression == null)
     {
         return(null);
     }
     return(parenthesizedExpression.Expression.AcceptVisitor(this, data));
 }
 private void Visit(
     ParenthesizedExpression expression,
     QualifiedModuleName module,
     Declaration scope,
     Declaration parent)
 {
     Visit(expression.Expression, module, scope, parent);
 }
Example #19
0
        public void PrimitiveParenthesizedExpression()
        {
            ParenthesizedExpression p = ParseUtilCSharp.ParseExpression <ParenthesizedExpression>("((1))");

            Assert.IsTrue(p.Expression is ParenthesizedExpression);
            p = (ParenthesizedExpression)p.Expression;
            Assert.IsTrue(p.Expression is PrimitiveExpression);
        }
Example #20
0
        private CastExpression GetCastExpression(BinaryOperatorExpression binaryOperatorExpression)
        {
            TypeReference leftType = GetExpressionType(binaryOperatorExpression.Left);

            CastExpression          castedUnsignedShift = new CastExpression(new TypeReference("u" + leftType.Type), binaryOperatorExpression, CastType.Cast);
            ParenthesizedExpression parenthesizedCastedUnsignedShift = new ParenthesizedExpression(castedUnsignedShift);

            return(new CastExpression(new TypeReference(leftType.Type), parenthesizedCastedUnsignedShift, CastType.Cast));
        }
Example #21
0
            public override StringBuilder VisitParenthesizedExpression(ParenthesizedExpression parenthesizedExpression, int data)
            {
                var result = new StringBuilder();

                result.Append("(");
                result.Append(parenthesizedExpression.Expression.AcceptVisitor(this, data));
                result.Append(")");
                return(result);
            }
Example #22
0
        /// <summary>
        /// Checks the given parenthesized expression to make sure that it is not unnecessary.
        /// </summary>
        /// <param name="element">The element containing the expression.</param>
        /// <param name="parenthesizedExpression">The parenthesized expression to check.</param>
        private void CheckParenthesizedExpression(CsElement element, ParenthesizedExpression parenthesizedExpression)
        {
            Param.AssertNotNull(element, "element");
            Param.AssertNotNull(parenthesizedExpression, "parenthesizedExpression");

            // Check the type of the inner expression to determine if it is one of types allowed to be wrapped within parenthesis.
            if (parenthesizedExpression.InnerExpression != null)
            {
                // The following types of expressions are allowed to be placed within a set of parenthesis.
                Expression innerExpression = parenthesizedExpression.InnerExpression;
                if (innerExpression.ExpressionType != ExpressionType.Arithmetic &&
                    innerExpression.ExpressionType != ExpressionType.As &&
                    innerExpression.ExpressionType != ExpressionType.Assignment &&
                    innerExpression.ExpressionType != ExpressionType.Cast &&
                    innerExpression.ExpressionType != ExpressionType.Conditional &&
                    innerExpression.ExpressionType != ExpressionType.ConditionalLogical &&
                    innerExpression.ExpressionType != ExpressionType.Decrement &&
                    innerExpression.ExpressionType != ExpressionType.Increment &&
                    innerExpression.ExpressionType != ExpressionType.Is &&
                    innerExpression.ExpressionType != ExpressionType.Lambda &&
                    innerExpression.ExpressionType != ExpressionType.Logical &&
                    innerExpression.ExpressionType != ExpressionType.New &&
                    innerExpression.ExpressionType != ExpressionType.NewArray &&
                    innerExpression.ExpressionType != ExpressionType.NullCoalescing &&
                    innerExpression.ExpressionType != ExpressionType.Query &&
                    innerExpression.ExpressionType != ExpressionType.Relational &&
                    innerExpression.ExpressionType != ExpressionType.Unary &&
                    innerExpression.ExpressionType != ExpressionType.UnsafeAccess)
                {
                    this.AddViolation(element, parenthesizedExpression.Location, Rules.StatementMustNotUseUnnecessaryParenthesis);
                }
                else
                {
                    // These types of expressions are allowed in some cases to be surrounded by parenthesis,
                    // as long as the parenthesized expression is within another expression. They are not allowed
                    // to be within parenthesis within a variable declarator expression. For example:
                    // int x = (2 + 3);
                    if (!(parenthesizedExpression.Parent is Expression) ||
                        parenthesizedExpression.Parent is VariableDeclaratorExpression ||
                        parenthesizedExpression.Parent is CheckedExpression ||
                        parenthesizedExpression.Parent is UncheckedExpression ||
                        parenthesizedExpression.Parent is MethodInvocationExpression)
                    {
                        this.AddViolation(element, parenthesizedExpression.Location, Rules.StatementMustNotUseUnnecessaryParenthesis);
                    }
                    else
                    {
                        // This is also not allowed when the expression is on the right-hand side of an assignment.
                        AssignmentExpression assignment = parenthesizedExpression.Parent as AssignmentExpression;
                        if (assignment != null && assignment.RightHandSide == parenthesizedExpression)
                        {
                            this.AddViolation(element, parenthesizedExpression.Location, Rules.StatementMustNotUseUnnecessaryParenthesis);
                        }
                    }
                }
            }
        }
Example #23
0
 public override object VisitParenthesizedExpression(ParenthesizedExpression parenthesizedExpression, object data)
 {
     base.VisitParenthesizedExpression(parenthesizedExpression, data);
     if (parenthesizedExpression.Expression is CastExpression)
     {
         ReplaceCurrentNode(parenthesizedExpression.Expression);                 // remove parenthesis
     }
     return(null);
 }
        protected override CodeAction GetAction(RefactoringContext context, InvocationExpression node)
        {
            var mRef = node.Target as MemberReferenceExpression;

            if (mRef == null)
            {
                return(null);
            }
            var rr = context.Resolve(node) as CSharpInvocationResolveResult;

            if (rr == null || rr.IsError)
            {
                return(null);
            }
            if (rr.Member.Name != "HasFlag" || rr.Member.DeclaringType.GetDefinition().KnownTypeCode != ICSharpCode.NRefactory.TypeSystem.KnownTypeCode.Enum)
            {
                return(null);
            }
            var arg = node.Arguments.First().Clone();

            if (!arg.DescendantsAndSelf.All(x => !(x is BinaryOperatorExpression) || ((BinaryOperatorExpression)x).Operator == BinaryOperatorType.BitwiseOr))
            {
                return(null);
            }
            arg = ConvertBitwiseFlagComparisonToHasFlagsAction.MakeFlatExpression(arg, BinaryOperatorType.BitwiseAnd);
            if (arg is BinaryOperatorExpression)
            {
                arg = new ParenthesizedExpression(arg);
            }
            return(new CodeAction(
                       context.TranslateString("Replace with bitwise flag comparison"),
                       script => {
                var uOp = node.Parent as UnaryOperatorExpression;
                if (uOp != null && uOp.Operator == UnaryOperatorType.Not)
                {
                    script.Replace(uOp,
                                   new BinaryOperatorExpression(
                                       new ParenthesizedExpression(new BinaryOperatorExpression(mRef.Target.Clone(), BinaryOperatorType.BitwiseAnd, arg)),
                                       BinaryOperatorType.Equality,
                                       new PrimitiveExpression(0)
                                       )
                                   );
                }
                else
                {
                    script.Replace(node,
                                   new BinaryOperatorExpression(
                                       new ParenthesizedExpression(new BinaryOperatorExpression(mRef.Target.Clone(), BinaryOperatorType.BitwiseAnd, arg)),
                                       BinaryOperatorType.InEquality,
                                       new PrimitiveExpression(0)
                                       )
                                   );
                }
            },
                       node
                       ));
        }
Example #25
0
 private void Visit(
     ParenthesizedExpression expression,
     QualifiedModuleName module,
     Declaration scope,
     Declaration parent,
     bool isAssignmentTarget,
     bool hasExplicitLetStatement)
 {
     Visit((dynamic)expression.Expression, module, scope, parent, false, false);
 }
Example #26
0
        public override void GenerateCode(List <AbstractNode> nodes, IList items)
        {
            TypeReference     intReference = new TypeReference("System.Int32");
            MethodDeclaration method       = new MethodDeclaration("GetHashCode", Modifiers.Public | Modifiers.Override, intReference, null, null);
            Expression        expr         = CallGetHashCode(new IdentifierExpression(currentClass.Fields[0].Name));

            for (int i = 1; i < currentClass.Fields.Count; i++)
            {
                IdentifierExpression identifier = new IdentifierExpression(currentClass.Fields[i].Name);
                expr = new BinaryOperatorExpression(expr, BinaryOperatorType.ExclusiveOr,
                                                    CallGetHashCode(identifier));
            }
            method.Body = new BlockStatement();
            method.Body.AddChild(new ReturnStatement(expr));
            nodes.Add(method);

            TypeReference boolReference   = new TypeReference("System.Boolean");
            TypeReference objectReference = new TypeReference("System.Object");

            method = new MethodDeclaration("Equals", Modifiers.Public | Modifiers.Override, boolReference, null, null);
            method.Parameters.Add(new ParameterDeclarationExpression(objectReference, "obj"));
            method.Body = new BlockStatement();

            TypeReference currentType = ConvertType(currentClass.DefaultReturnType);

            expr = new TypeOfIsExpression(new IdentifierExpression("obj"), currentType);
            expr = new ParenthesizedExpression(expr);
            expr = new UnaryOperatorExpression(expr, UnaryOperatorType.Not);
            method.Body.AddChild(new IfElseStatement(expr, new ReturnStatement(new PrimitiveExpression(false, "false"))));

            expr = new BinaryOperatorExpression(new ThisReferenceExpression(),
                                                BinaryOperatorType.Equality,
                                                new IdentifierExpression("obj"));
            method.Body.AddChild(new IfElseStatement(expr, new ReturnStatement(new PrimitiveExpression(true, "true"))));

            VariableDeclaration var = new VariableDeclaration("my" + currentClass.Name,
                                                              new CastExpression(currentType, new IdentifierExpression("obj"), CastType.Cast),
                                                              currentType);

            method.Body.AddChild(new LocalVariableDeclaration(var));

            expr = TestEquality(var.Name, currentClass.Fields[0]);
            for (int i = 1; i < currentClass.Fields.Count; i++)
            {
                expr = new BinaryOperatorExpression(expr, BinaryOperatorType.LogicalAnd,
                                                    TestEquality(var.Name, currentClass.Fields[i]));
            }

            method.Body.AddChild(new ReturnStatement(expr));

            nodes.Add(method);
        }
        private static AstNode ModifyLambdaForMinMax(LambdaExpression lambdaExpression,
                                                     ParenthesizedExpression parenthesizedlambdaExpression)
        {
            var node           = new CastExpression(new SimpleType("Func<dynamic, IComparable>"), parenthesizedlambdaExpression.Clone());
            var castExpression = GetAsCastExpression(lambdaExpression.Body);

            if (castExpression != null)
            {
                var castToType = new SimpleType("Func", new SimpleType("dynamic"), castExpression.Type.Clone());
                node = new CastExpression(castToType, parenthesizedlambdaExpression.Clone());
            }
            return(node);
        }
Example #28
0
        /// <summary>
        /// Applies the transformation
        /// </summary>
        /// <returns>The transformed item.</returns>
        /// <param name="_item">The item to visit.</param>
        public virtual ASTItem Transform(ASTItem _item)
        {
            var item = _item as Expression;

            if (item == null)
            {
                return(_item);
            }

            // This fixes a case where the NRefactory code injects a cast to UIntPtr,
            // even though none is present in the code, nor the IL

            var wrap = false;
            var self = item;

            if (self is ParenthesizedExpression)
            {
                self = (self as ParenthesizedExpression).Expression;
                wrap = true;
            }

            if (self is CastExpression && (self as CastExpression).SourceResultType.IsSameTypeReference(typeof(UIntPtr)))
            {
                self = (self as CastExpression).Expression;
            }
            else
            {
                self = item;
            }

            if (wrap && self != item)
            {
                var p = self;
                self = new ParenthesizedExpression()
                {
                    Expression       = p as Expression,
                    SourceExpression = (p as Expression).SourceExpression,
                    SourceResultType = (p as Expression).SourceResultType,
                    Parent           = p.Parent,
                };

                p.Parent = self;
            }

            if (self != item)
            {
                return(item.ReplaceWith(self));
            }

            return(item);
        }
        public void CSharpDereferenceAfterCast()
        {
            UnaryOperatorExpression uoe = ParseUtilCSharp.ParseExpression <UnaryOperatorExpression>("*((SomeType*) &w)");

            Assert.AreEqual(UnaryOperatorType.Dereference, uoe.Op);
            ParenthesizedExpression pe = (ParenthesizedExpression)uoe.Expression;
            CastExpression          ce = (CastExpression)pe.Expression;

            Assert.AreEqual("SomeType", ce.CastTo.Type);
            Assert.AreEqual(1, ce.CastTo.PointerNestingLevel);
            UnaryOperatorExpression adrOf = (UnaryOperatorExpression)ce.Expression;

            Assert.AreEqual(UnaryOperatorType.AddressOf, adrOf.Op);
        }
Example #30
0
        Expression Factor()
        {
            try {
                trace.Enter();
                Expression expr;

                switch (current.Type)
                {
                case TokenType.StringLiteral:
                case TokenType.VerbatimStringLiteral:
                case TokenType.InterpolatedStringLiteral:
                case TokenType.CharLiteral:
                    expr = new LiteralExpression {
                        Value = current.Value
                    };
                    Read();
                    return(expr);

                case TokenType.UnknownChar:
                    expr = new LiteralExpression {
                        Value = current.UnknownChar.ToString()
                    };
                    Read();
                    return(expr);

                case TokenType.RawLiteral:
                    expr = new LiteralExpression {
                        Value = current.Value
                    };
                    Read();
                    if (current.Type == TokenType.LeftParen)
                    {
                        expr = Invoke(expr);
                    }
                    return(expr);

                case TokenType.LeftParen:
                    Read();
                    expr = new ParenthesizedExpression();
                    expr.AddChild(Expr());
                    Match(TokenType.RightParen);
                    return(expr);

                default:
                    throw new SyntaxException(tokenizer, current);
                }
            } finally {
                trace.Leave();
            }
        }
Example #31
0
        public static Expression OptimizeExpression(Expression node)
        {
            var root = new ParenthesizedExpression(node.Clone());
            var visitors = GetVisitors();
            string oldText = null;
            while (root.GetText() != oldText)
            {
                oldText = root.GetText();
                foreach (var visitor in visitors)
                    root.Expression.AcceptVisitor(visitor);
            }

            return root.Expression;
        }
Example #32
0
            internal override bool CanMatch(AstNode node)
            {
                if (specialNodeType != null && node.GetType() == specialNodeType)
                {
                    return(true);
                }

                Expression expr = node as Expression;

                if (expr == null)
                {
                    return(node is MethodDeclaration);
                }

                InvocationExpression ie = node as InvocationExpression;

                if (ie != null)
                {
                    Expression target = ParenthesizedExpression.UnpackParenthesizedExpression(ie.Target);

                    IdentifierExpression ident = target as IdentifierExpression;
                    if (ident != null)
                    {
                        return(ident.Identifier == method.Name);
                    }

                    MemberReferenceExpression mre = target as MemberReferenceExpression;
                    if (mre != null)
                    {
                        return(mre.MemberName == method.Name);
                    }

                    PointerReferenceExpression pre = target as PointerReferenceExpression;
                    if (pre != null)
                    {
                        return(pre.MemberName == method.Name);
                    }
                }
                else if (expr.Role != InvocationExpression.Roles.TargetExpression)
                {
                    // MemberReferences & Identifiers that aren't used in an invocation can still match the method
                    // as delegate name.
                    if (expr.GetChildByRole(AstNode.Roles.Identifier).Name == method.Name)
                    {
                        potentialMethodGroupConversions.Add(expr);
                    }
                }
                return(node is MethodDeclaration);
            }
        private static AstNode ModifyLambdaForSelect(ParenthesizedExpression parenthesizedlambdaExpression,
                                                     MemberReferenceExpression target)
        {
            var parentInvocation = target.Target as InvocationExpression;

            if (parentInvocation != null)
            {
                var parentTarget = parentInvocation.Target as MemberReferenceExpression;
                if (parentTarget != null && parentTarget.MemberName == "GroupBy")
                {
                    return(new CastExpression(new SimpleType("Func<IGrouping<dynamic,dynamic>, dynamic>"), parenthesizedlambdaExpression.Clone()));
                }
            }
            return(new CastExpression(new SimpleType("Func<dynamic, dynamic>"), parenthesizedlambdaExpression.Clone()));
        }
 public void VisitParenthesizedExpression(ParenthesizedExpression parensExpr)
 {
     parensExpr.Expression.AcceptWalker(this);
 }
 // ParenthesizedExpression
 protected internal virtual bool Walk(ParenthesizedExpression node) { return true; }
Example #36
0
		AstNode TransformByteCode(ILExpression byteCode)
		{
			object operand = byteCode.Operand;
			AstType operandAsTypeRef = AstBuilder.ConvertType(operand as Cecil.TypeReference);

			List<Ast.Expression> args = new List<Expression>();
			foreach(ILExpression arg in byteCode.Arguments) {
				args.Add((Ast.Expression)TransformExpression(arg));
			}
			Ast.Expression arg1 = args.Count >= 1 ? args[0] : null;
			Ast.Expression arg2 = args.Count >= 2 ? args[1] : null;
			Ast.Expression arg3 = args.Count >= 3 ? args[2] : null;
			
			switch (byteCode.Code) {
					#region Arithmetic
				case ILCode.Add:
				case ILCode.Add_Ovf:
				case ILCode.Add_Ovf_Un:
					{
						BinaryOperatorExpression boe;
						if (byteCode.InferredType is PointerType) {
							if (byteCode.Arguments[0].ExpectedType is PointerType) {
								arg2 = DivideBySize(arg2, ((PointerType)byteCode.InferredType).ElementType);
								boe = new Ast.BinaryOperatorExpression(arg1, BinaryOperatorType.Add, arg2);
								boe.AddAnnotation(IntroduceUnsafeModifier.PointerArithmeticAnnotation);
							} else if (byteCode.Arguments[1].ExpectedType is PointerType) {
								arg1 = DivideBySize(arg1, ((PointerType)byteCode.InferredType).ElementType);
								boe = new Ast.BinaryOperatorExpression(arg1, BinaryOperatorType.Add, arg2);
								boe.AddAnnotation(IntroduceUnsafeModifier.PointerArithmeticAnnotation);
							} else {
								boe = new Ast.BinaryOperatorExpression(arg1, BinaryOperatorType.Add, arg2);
							}
						} else {
							boe = new Ast.BinaryOperatorExpression(arg1, BinaryOperatorType.Add, arg2);
						}
						boe.AddAnnotation(byteCode.Code == ILCode.Add ? AddCheckedBlocks.UncheckedAnnotation : AddCheckedBlocks.CheckedAnnotation);
						return boe;
					}
				case ILCode.Sub:
				case ILCode.Sub_Ovf:
				case ILCode.Sub_Ovf_Un:
					{
						BinaryOperatorExpression boe;
						if (byteCode.InferredType is PointerType) {
							if (byteCode.Arguments[0].ExpectedType is PointerType) {
								arg2 = DivideBySize(arg2, ((PointerType)byteCode.InferredType).ElementType);
								boe = new Ast.BinaryOperatorExpression(arg1, BinaryOperatorType.Subtract, arg2);
								boe.WithAnnotation(IntroduceUnsafeModifier.PointerArithmeticAnnotation);
							} else {
								boe = new Ast.BinaryOperatorExpression(arg1, BinaryOperatorType.Subtract, arg2);
							}
						} else {
							boe = new Ast.BinaryOperatorExpression(arg1, BinaryOperatorType.Subtract, arg2);
						}
						boe.AddAnnotation(byteCode.Code == ILCode.Sub ? AddCheckedBlocks.UncheckedAnnotation : AddCheckedBlocks.CheckedAnnotation);
						return boe;
					}
					case ILCode.Div:        return new Ast.BinaryOperatorExpression(arg1, BinaryOperatorType.Divide, arg2);
					case ILCode.Div_Un:     return new Ast.BinaryOperatorExpression(arg1, BinaryOperatorType.Divide, arg2);
					case ILCode.Mul:        return new Ast.BinaryOperatorExpression(arg1, BinaryOperatorType.Multiply, arg2).WithAnnotation(AddCheckedBlocks.UncheckedAnnotation);
					case ILCode.Mul_Ovf:    return new Ast.BinaryOperatorExpression(arg1, BinaryOperatorType.Multiply, arg2).WithAnnotation(AddCheckedBlocks.CheckedAnnotation);
					case ILCode.Mul_Ovf_Un: return new Ast.BinaryOperatorExpression(arg1, BinaryOperatorType.Multiply, arg2).WithAnnotation(AddCheckedBlocks.CheckedAnnotation);
					case ILCode.Rem:        return new Ast.BinaryOperatorExpression(arg1, BinaryOperatorType.Modulus, arg2);
					case ILCode.Rem_Un:     return new Ast.BinaryOperatorExpression(arg1, BinaryOperatorType.Modulus, arg2);
					case ILCode.And:        return new Ast.BinaryOperatorExpression(arg1, BinaryOperatorType.BitwiseAnd, arg2);
					case ILCode.Or:         return new Ast.BinaryOperatorExpression(arg1, BinaryOperatorType.BitwiseOr, arg2);
					case ILCode.Xor:        return new Ast.BinaryOperatorExpression(arg1, BinaryOperatorType.ExclusiveOr, arg2);
					case ILCode.Shl:        return new Ast.BinaryOperatorExpression(arg1, BinaryOperatorType.ShiftLeft, arg2);
					case ILCode.Shr:        return new Ast.BinaryOperatorExpression(arg1, BinaryOperatorType.ShiftRight, arg2);
					case ILCode.Shr_Un:     return new Ast.BinaryOperatorExpression(arg1, BinaryOperatorType.ShiftRight, arg2);
					case ILCode.Neg:        return new Ast.UnaryOperatorExpression(UnaryOperatorType.Minus, arg1).WithAnnotation(AddCheckedBlocks.UncheckedAnnotation);
					case ILCode.Not:        return new Ast.UnaryOperatorExpression(UnaryOperatorType.BitNot, arg1);
				case ILCode.PostIncrement:
				case ILCode.PostIncrement_Ovf:
				case ILCode.PostIncrement_Ovf_Un:
					{
						if (arg1 is DirectionExpression)
							arg1 = ((DirectionExpression)arg1).Expression.Detach();
						var uoe = new Ast.UnaryOperatorExpression(
							(int)byteCode.Operand > 0 ? UnaryOperatorType.PostIncrement : UnaryOperatorType.PostDecrement, arg1);
						uoe.AddAnnotation((byteCode.Code == ILCode.PostIncrement) ? AddCheckedBlocks.UncheckedAnnotation : AddCheckedBlocks.CheckedAnnotation);
						return uoe;
					}
					#endregion
					#region Arrays
					case ILCode.Newarr: {
						var ace = new Ast.ArrayCreateExpression();
						ace.Type = operandAsTypeRef;
						ComposedType ct = operandAsTypeRef as ComposedType;
						if (ct != null) {
							// change "new (int[,])[10] to new int[10][,]"
							ct.ArraySpecifiers.MoveTo(ace.AdditionalArraySpecifiers);
						}
						if (byteCode.Code == ILCode.InitArray) {
							ace.Initializer = new ArrayInitializerExpression();
							ace.Initializer.Elements.AddRange(args);
						} else {
							ace.Arguments.Add(arg1);
						}
						return ace;
					}
					case ILCode.InitArray: {
						var ace = new Ast.ArrayCreateExpression();
						ace.Type = operandAsTypeRef;
						ComposedType ct = operandAsTypeRef as ComposedType;
						var arrayType = (ArrayType) operand;
						if (ct != null)
						{
							// change "new (int[,])[10] to new int[10][,]"
							ct.ArraySpecifiers.MoveTo(ace.AdditionalArraySpecifiers);
							ace.Initializer = new ArrayInitializerExpression();
						}
						var newArgs = new List<Expression>();
						foreach (var arrayDimension in arrayType.Dimensions.Skip(1).Reverse())
						{
							int length = (int)arrayDimension.UpperBound - (int)arrayDimension.LowerBound;
							for (int j = 0; j < args.Count; j += length)
							{
								var child = new ArrayInitializerExpression();
								child.Elements.AddRange(args.GetRange(j, length));
								newArgs.Add(child);
							}
							var temp = args;
							args = newArgs;
							newArgs = temp;
							newArgs.Clear();
						}
						ace.Initializer.Elements.AddRange(args);
						return ace;
					}
					case ILCode.Ldlen: return arg1.Member("Length");
				case ILCode.Ldelem_I:
				case ILCode.Ldelem_I1:
				case ILCode.Ldelem_I2:
				case ILCode.Ldelem_I4:
				case ILCode.Ldelem_I8:
				case ILCode.Ldelem_U1:
				case ILCode.Ldelem_U2:
				case ILCode.Ldelem_U4:
				case ILCode.Ldelem_R4:
				case ILCode.Ldelem_R8:
				case ILCode.Ldelem_Ref:
				case ILCode.Ldelem_Any:
					return arg1.Indexer(arg2);
				case ILCode.Ldelema:
					return MakeRef(arg1.Indexer(arg2));
				case ILCode.Stelem_I:
				case ILCode.Stelem_I1:
				case ILCode.Stelem_I2:
				case ILCode.Stelem_I4:
				case ILCode.Stelem_I8:
				case ILCode.Stelem_R4:
				case ILCode.Stelem_R8:
				case ILCode.Stelem_Ref:
				case ILCode.Stelem_Any:
					return new Ast.AssignmentExpression(arg1.Indexer(arg2), arg3);
				case ILCode.CompoundAssignment:
					{
						CastExpression cast = arg1 as CastExpression;
						var boe = cast != null ? (BinaryOperatorExpression)cast.Expression : arg1 as BinaryOperatorExpression;
						// AssignmentExpression doesn't support overloaded operators so they have to be processed to BinaryOperatorExpression
						if (boe == null) {
							var tmp = new ParenthesizedExpression(arg1);
							ReplaceMethodCallsWithOperators.ProcessInvocationExpression((InvocationExpression)arg1);
							boe = (BinaryOperatorExpression)tmp.Expression;
						}
						var assignment = new Ast.AssignmentExpression {
							Left = boe.Left.Detach(),
							Operator = ReplaceMethodCallsWithOperators.GetAssignmentOperatorForBinaryOperator(boe.Operator),
							Right = boe.Right.Detach()
						}.CopyAnnotationsFrom(boe);
						// We do not mark the resulting assignment as RestoreOriginalAssignOperatorAnnotation, because
						// the operator cannot be translated back to the expanded form (as the left-hand expression
						// would be evaluated twice, and might have side-effects)
						if (cast != null) {
							cast.Expression = assignment;
							return cast;
						} else {
							return assignment;
						}
					}
					#endregion
					#region Comparison
					case ILCode.Ceq: return new Ast.BinaryOperatorExpression(arg1, BinaryOperatorType.Equality, arg2);
					case ILCode.Cne: return new Ast.BinaryOperatorExpression(arg1, BinaryOperatorType.InEquality, arg2);
					case ILCode.Cgt: return new Ast.BinaryOperatorExpression(arg1, BinaryOperatorType.GreaterThan, arg2);
					case ILCode.Cgt_Un: {
						// can also mean Inequality, when used with object references
						TypeReference arg1Type = byteCode.Arguments[0].InferredType;
						if (arg1Type != null && !arg1Type.IsValueType) goto case ILCode.Cne;
						goto case ILCode.Cgt;
					}
					case ILCode.Cle_Un: {
						// can also mean Equality, when used with object references
						TypeReference arg1Type = byteCode.Arguments[0].InferredType;
						if (arg1Type != null && !arg1Type.IsValueType) goto case ILCode.Ceq;
						goto case ILCode.Cle;
					}
					case ILCode.Cle: return new Ast.BinaryOperatorExpression(arg1, BinaryOperatorType.LessThanOrEqual, arg2);
				case ILCode.Cge_Un:
					case ILCode.Cge: return new Ast.BinaryOperatorExpression(arg1, BinaryOperatorType.GreaterThanOrEqual, arg2);
				case ILCode.Clt_Un:
					case ILCode.Clt:    return new Ast.BinaryOperatorExpression(arg1, BinaryOperatorType.LessThan, arg2);
					#endregion
					#region Logical
					case ILCode.LogicNot:   return new Ast.UnaryOperatorExpression(UnaryOperatorType.Not, arg1);
					case ILCode.LogicAnd:   return new Ast.BinaryOperatorExpression(arg1, BinaryOperatorType.ConditionalAnd, arg2);
					case ILCode.LogicOr:    return new Ast.BinaryOperatorExpression(arg1, BinaryOperatorType.ConditionalOr, arg2);
					case ILCode.TernaryOp:  return new Ast.ConditionalExpression() { Condition = arg1, TrueExpression = arg2, FalseExpression = arg3 };
					case ILCode.NullCoalescing: 	return new Ast.BinaryOperatorExpression(arg1, BinaryOperatorType.NullCoalescing, arg2);
					#endregion
					#region Branch
					case ILCode.Br:         return new Ast.GotoStatement(((ILLabel)byteCode.Operand).Name);
				case ILCode.Brtrue:
					return new Ast.IfElseStatement() {
						Condition = arg1,
						TrueStatement = new BlockStatement() {
							new Ast.GotoStatement(((ILLabel)byteCode.Operand).Name)
						}
					};
					case ILCode.LoopOrSwitchBreak: return new Ast.BreakStatement();
					case ILCode.LoopContinue:      return new Ast.ContinueStatement();
					#endregion
					#region Conversions
				case ILCode.Conv_I1:
				case ILCode.Conv_I2:
				case ILCode.Conv_I4:
				case ILCode.Conv_I8:
				case ILCode.Conv_U1:
				case ILCode.Conv_U2:
				case ILCode.Conv_U4:
				case ILCode.Conv_U8:
				case ILCode.Conv_I:
				case ILCode.Conv_U:
					{
						// conversion was handled by Convert() function using the info from type analysis
						CastExpression cast = arg1 as CastExpression;
						if (cast != null) {
							cast.AddAnnotation(AddCheckedBlocks.UncheckedAnnotation);
						}
						return arg1;
					}
				case ILCode.Conv_R4:
				case ILCode.Conv_R8:
				case ILCode.Conv_R_Un: // TODO
					return arg1;
				case ILCode.Conv_Ovf_I1:
				case ILCode.Conv_Ovf_I2:
				case ILCode.Conv_Ovf_I4:
				case ILCode.Conv_Ovf_I8:
				case ILCode.Conv_Ovf_U1:
				case ILCode.Conv_Ovf_U2:
				case ILCode.Conv_Ovf_U4:
				case ILCode.Conv_Ovf_U8:
				case ILCode.Conv_Ovf_I1_Un:
				case ILCode.Conv_Ovf_I2_Un:
				case ILCode.Conv_Ovf_I4_Un:
				case ILCode.Conv_Ovf_I8_Un:
				case ILCode.Conv_Ovf_U1_Un:
				case ILCode.Conv_Ovf_U2_Un:
				case ILCode.Conv_Ovf_U4_Un:
				case ILCode.Conv_Ovf_U8_Un:
				case ILCode.Conv_Ovf_I:
				case ILCode.Conv_Ovf_U:
				case ILCode.Conv_Ovf_I_Un:
				case ILCode.Conv_Ovf_U_Un:
					{
						// conversion was handled by Convert() function using the info from type analysis
						CastExpression cast = arg1 as CastExpression;
						if (cast != null) {
							cast.AddAnnotation(AddCheckedBlocks.CheckedAnnotation);
						}
						return arg1;
					}
				case ILCode.Unbox_Any:
					// unboxing does not require a cast if the argument was an isinst instruction
					if (arg1 is AsExpression && byteCode.Arguments[0].Code == ILCode.Isinst && TypeAnalysis.IsSameType(operand as TypeReference, byteCode.Arguments[0].Operand as TypeReference))
						return arg1;
					else
						goto case ILCode.Castclass;
				case ILCode.Castclass:
					if ((byteCode.Arguments[0].InferredType != null && byteCode.Arguments[0].InferredType.IsGenericParameter) || ((Cecil.TypeReference)operand).IsGenericParameter)
						return arg1.CastTo(new PrimitiveType("object")).CastTo(operandAsTypeRef);
					else
						return arg1.CastTo(operandAsTypeRef);
				case ILCode.Isinst:
					return arg1.CastAs(operandAsTypeRef);
				case ILCode.Box:
					return arg1;
				case ILCode.Unbox:
					return MakeRef(arg1.CastTo(operandAsTypeRef));
					#endregion
					#region Indirect
				case ILCode.Ldind_Ref:
				case ILCode.Ldobj:
					if (arg1 is DirectionExpression)
						return ((DirectionExpression)arg1).Expression.Detach();
					else
						return new UnaryOperatorExpression(UnaryOperatorType.Dereference, arg1);
				case ILCode.Stind_Ref:
				case ILCode.Stobj:
					if (arg1 is DirectionExpression)
						return new AssignmentExpression(((DirectionExpression)arg1).Expression.Detach(), arg2);
					else
						return new AssignmentExpression(new UnaryOperatorExpression(UnaryOperatorType.Dereference, arg1), arg2);
					#endregion
				case ILCode.Arglist:
					return new UndocumentedExpression { UndocumentedExpressionType = UndocumentedExpressionType.ArgListAccess };
					case ILCode.Break:    return InlineAssembly(byteCode, args);
				case ILCode.Call:
				case ILCode.CallGetter:
				case ILCode.CallSetter:
					return TransformCall(false, byteCode, args);
				case ILCode.Callvirt:
				case ILCode.CallvirtGetter:
				case ILCode.CallvirtSetter:
					return TransformCall(true, byteCode,  args);
					case ILCode.Ldftn: {
						Cecil.MethodReference cecilMethod = ((MethodReference)operand);
						var expr = new Ast.IdentifierExpression(cecilMethod.Name);
						expr.TypeArguments.AddRange(ConvertTypeArguments(cecilMethod));
						expr.AddAnnotation(cecilMethod);
						return new IdentifierExpression("ldftn").Invoke(expr)
							.WithAnnotation(new Transforms.DelegateConstruction.Annotation(false));
					}
					case ILCode.Ldvirtftn: {
						Cecil.MethodReference cecilMethod = ((MethodReference)operand);
						var expr = new Ast.IdentifierExpression(cecilMethod.Name);
						expr.TypeArguments.AddRange(ConvertTypeArguments(cecilMethod));
						expr.AddAnnotation(cecilMethod);
						return new IdentifierExpression("ldvirtftn").Invoke(expr)
							.WithAnnotation(new Transforms.DelegateConstruction.Annotation(true));
					}
					case ILCode.Calli:       return InlineAssembly(byteCode, args);
					case ILCode.Ckfinite:    return InlineAssembly(byteCode, args);
					case ILCode.Constrained: return InlineAssembly(byteCode, args);
					case ILCode.Cpblk:       return InlineAssembly(byteCode, args);
					case ILCode.Cpobj:       return InlineAssembly(byteCode, args);
					case ILCode.Dup:         return arg1;
					case ILCode.Endfilter:   return InlineAssembly(byteCode, args);
					case ILCode.Endfinally:  return null;
					case ILCode.Initblk:     return InlineAssembly(byteCode, args);
					case ILCode.Initobj:      return InlineAssembly(byteCode, args);
				case ILCode.DefaultValue:
					return MakeDefaultValue((TypeReference)operand);
					case ILCode.Jmp: return InlineAssembly(byteCode, args);
				case ILCode.Ldc_I4:
					return AstBuilder.MakePrimitive((int)operand, byteCode.InferredType);
				case ILCode.Ldc_I8:
					return AstBuilder.MakePrimitive((long)operand, byteCode.InferredType);
				case ILCode.Ldc_R4:
				case ILCode.Ldc_R8:
				case ILCode.Ldc_Decimal:
					return new Ast.PrimitiveExpression(operand);
				case ILCode.Ldfld:
					if (arg1 is DirectionExpression)
						arg1 = ((DirectionExpression)arg1).Expression.Detach();
					return arg1.Member(((FieldReference) operand).Name).WithAnnotation(operand);
				case ILCode.Ldsfld:
					return AstBuilder.ConvertType(((FieldReference)operand).DeclaringType)
						.Member(((FieldReference)operand).Name).WithAnnotation(operand);
				case ILCode.Stfld:
					if (arg1 is DirectionExpression)
						arg1 = ((DirectionExpression)arg1).Expression.Detach();
					return new AssignmentExpression(arg1.Member(((FieldReference) operand).Name).WithAnnotation(operand), arg2);
				case ILCode.Stsfld:
					return new AssignmentExpression(
						AstBuilder.ConvertType(((FieldReference)operand).DeclaringType)
						.Member(((FieldReference)operand).Name).WithAnnotation(operand),
						arg1);
				case ILCode.Ldflda:
					if (arg1 is DirectionExpression)
						arg1 = ((DirectionExpression)arg1).Expression.Detach();
					return MakeRef(arg1.Member(((FieldReference) operand).Name).WithAnnotation(operand));
				case ILCode.Ldsflda:
					return MakeRef(
						AstBuilder.ConvertType(((FieldReference)operand).DeclaringType)
						.Member(((FieldReference)operand).Name).WithAnnotation(operand));
					case ILCode.Ldloc: {
						ILVariable v = (ILVariable)operand;
						if (!v.IsParameter)
							localVariablesToDefine.Add((ILVariable)operand);
						Expression expr;
						if (v.IsParameter && v.OriginalParameter.Index < 0)
							expr = new ThisReferenceExpression();
						else
							expr = new Ast.IdentifierExpression(((ILVariable)operand).Name).WithAnnotation(operand);
						return v.IsParameter && v.Type is ByReferenceType ? MakeRef(expr) : expr;
					}
					case ILCode.Ldloca: {
						ILVariable v = (ILVariable)operand;
						if (v.IsParameter && v.OriginalParameter.Index < 0)
							return MakeRef(new ThisReferenceExpression());
						if (!v.IsParameter)
							localVariablesToDefine.Add((ILVariable)operand);
						return MakeRef(new Ast.IdentifierExpression(((ILVariable)operand).Name).WithAnnotation(operand));
					}
					case ILCode.Ldnull: return new Ast.NullReferenceExpression();
					case ILCode.Ldstr:  return new Ast.PrimitiveExpression(operand);
				case ILCode.Ldtoken:
					if (operand is Cecil.TypeReference) {
						return AstBuilder.CreateTypeOfExpression((TypeReference)operand).Member("TypeHandle");
					} else {
						Expression referencedEntity;
						string loadName;
						string handleName;
						if (operand is Cecil.FieldReference) {
							loadName = "fieldof";
							handleName = "FieldHandle";
							FieldReference fr = (FieldReference)operand;
							referencedEntity = AstBuilder.ConvertType(fr.DeclaringType).Member(fr.Name).WithAnnotation(fr);
						} else if (operand is Cecil.MethodReference) {
							loadName = "methodof";
							handleName = "MethodHandle";
							MethodReference mr = (MethodReference)operand;
							var methodParameters = mr.Parameters.Select(p => new TypeReferenceExpression(AstBuilder.ConvertType(p.ParameterType)));
							referencedEntity = AstBuilder.ConvertType(mr.DeclaringType).Invoke(mr.Name, methodParameters).WithAnnotation(mr);
						} else {
							loadName = "ldtoken";
							handleName = "Handle";
							referencedEntity = new IdentifierExpression(FormatByteCodeOperand(byteCode.Operand));
						}
						return new IdentifierExpression(loadName).Invoke(referencedEntity).WithAnnotation(new LdTokenAnnotation()).Member(handleName);
					}
					case ILCode.Leave:    return new GotoStatement() { Label = ((ILLabel)operand).Name };
				case ILCode.Localloc:
					{
						PointerType ptrType = byteCode.InferredType as PointerType;
						TypeReference type;
						if (ptrType != null) {
							type = ptrType.ElementType;
						} else {
							type = typeSystem.Byte;
						}
						return new StackAllocExpression {
							Type = AstBuilder.ConvertType(type),
							CountExpression = DivideBySize(arg1, type)
						};
					}
				case ILCode.Mkrefany:
					{
						DirectionExpression dir = arg1 as DirectionExpression;
						if (dir != null) {
							return new UndocumentedExpression {
								UndocumentedExpressionType = UndocumentedExpressionType.MakeRef,
								Arguments = { dir.Expression.Detach() }
							};
						} else {
							return InlineAssembly(byteCode, args);
						}
					}
				case ILCode.Refanytype:
					return new UndocumentedExpression {
						UndocumentedExpressionType = UndocumentedExpressionType.RefType,
						Arguments = { arg1 }
					}.Member("TypeHandle");
				case ILCode.Refanyval:
					return MakeRef(
						new UndocumentedExpression {
							UndocumentedExpressionType = UndocumentedExpressionType.RefValue,
							Arguments = { arg1, new TypeReferenceExpression(operandAsTypeRef) }
						});
					case ILCode.Newobj: {
						Cecil.TypeReference declaringType = ((MethodReference)operand).DeclaringType;
						if (declaringType is ArrayType) {
							ComposedType ct = AstBuilder.ConvertType((ArrayType)declaringType) as ComposedType;
							if (ct != null && ct.ArraySpecifiers.Count >= 1) {
								var ace = new Ast.ArrayCreateExpression();
								ct.ArraySpecifiers.First().Remove();
								ct.ArraySpecifiers.MoveTo(ace.AdditionalArraySpecifiers);
								ace.Type = ct;
								ace.Arguments.AddRange(args);
								return ace;
							}
						}
						if (declaringType.IsAnonymousType()) {
							MethodDefinition ctor = ((MethodReference)operand).Resolve();
							if (methodDef != null) {
								AnonymousTypeCreateExpression atce = new AnonymousTypeCreateExpression();
								if (CanInferAnonymousTypePropertyNamesFromArguments(args, ctor.Parameters)) {
									atce.Initializers.AddRange(args);
								} else {
									for (int i = 0; i < args.Count; i++) {
										atce.Initializers.Add(
											new NamedExpression {
												Name = ctor.Parameters[i].Name,
												Expression = args[i]
											});
									}
								}
								return atce;
							}
						}
						var oce = new Ast.ObjectCreateExpression();
						oce.Type = AstBuilder.ConvertType(declaringType);
						oce.Arguments.AddRange(args);
						return oce.WithAnnotation(operand);
					}
					case ILCode.No: return InlineAssembly(byteCode, args);
					case ILCode.Nop: return null;
					case ILCode.Pop: return arg1;
					case ILCode.Readonly: return InlineAssembly(byteCode, args);
				case ILCode.Ret:
					if (methodDef.ReturnType.FullName != "System.Void") {
						return new Ast.ReturnStatement { Expression = arg1 };
					} else {
						return new Ast.ReturnStatement();
					}
					case ILCode.Rethrow: return new Ast.ThrowStatement();
					case ILCode.Sizeof:  return new Ast.SizeOfExpression { Type = operandAsTypeRef };
					case ILCode.Stloc: {
						ILVariable locVar = (ILVariable)operand;
						if (!locVar.IsParameter)
							localVariablesToDefine.Add(locVar);
						return new Ast.AssignmentExpression(new Ast.IdentifierExpression(locVar.Name).WithAnnotation(locVar), arg1);
					}
					case ILCode.Switch: return InlineAssembly(byteCode, args);
					case ILCode.Tail: return InlineAssembly(byteCode, args);
					case ILCode.Throw: return new Ast.ThrowStatement { Expression = arg1 };
					case ILCode.Unaligned: return InlineAssembly(byteCode, args);
					case ILCode.Volatile: return InlineAssembly(byteCode, args);
				case ILCode.YieldBreak:
					return new Ast.YieldBreakStatement();
				case ILCode.YieldReturn:
					return new Ast.YieldReturnStatement { Expression = arg1 };
				case ILCode.InitObject:
				case ILCode.InitCollection:
					{
						ArrayInitializerExpression initializer = new ArrayInitializerExpression();
						for (int i = 1; i < args.Count; i++) {
							Match m = objectInitializerPattern.Match(args[i]);
							if (m.Success) {
								MemberReferenceExpression mre = m.Get<MemberReferenceExpression>("left").Single();
								initializer.Elements.Add(
									new NamedExpression {
										Name = mre.MemberName,
										Expression = m.Get<Expression>("right").Single().Detach()
									}.CopyAnnotationsFrom(mre));
							} else {
								m = collectionInitializerPattern.Match(args[i]);
								if (m.Success) {
									if (m.Get("arg").Count() == 1) {
										initializer.Elements.Add(m.Get<Expression>("arg").Single().Detach());
									} else {
										ArrayInitializerExpression argList = new ArrayInitializerExpression();
										foreach (var expr in m.Get<Expression>("arg")) {
											argList.Elements.Add(expr.Detach());
										}
										initializer.Elements.Add(argList);
									}
								} else {
									initializer.Elements.Add(args[i]);
								}
							}
						}
						ObjectCreateExpression oce = arg1 as ObjectCreateExpression;
						DefaultValueExpression dve = arg1 as DefaultValueExpression;
						if (oce != null) {
							oce.Initializer = initializer;
							return oce;
						} else if (dve != null) {
							oce = new ObjectCreateExpression(dve.Type.Detach());
							oce.CopyAnnotationsFrom(dve);
							oce.Initializer = initializer;
							return oce;
						} else {
							return new AssignmentExpression(arg1, initializer);
						}
					}
				case ILCode.InitializedObject:
					return new InitializedObjectExpression();
				case ILCode.Wrap:
					return arg1.WithAnnotation(PushNegation.LiftedOperatorAnnotation);
				case ILCode.AddressOf:
					return MakeRef(arg1);
				case ILCode.ExpressionTreeParameterDeclarations:
					args[args.Count - 1].AddAnnotation(new ParameterDeclarationAnnotation(byteCode));
					return args[args.Count - 1];
				case ILCode.Await:
					return new UnaryOperatorExpression(UnaryOperatorType.Await, UnpackDirectionExpression(arg1));
				case ILCode.NullableOf:
				case ILCode.ValueOf: 
					return arg1;
				default:
					throw new Exception("Unknown OpCode: " + byteCode.Code);
			}
		}
 public virtual void VisitParenthesizedExpression(ParenthesizedExpression parenthesizedExpression)
 {
     if (this.ThrowException)
     {
         throw (Exception)this.CreateException(parenthesizedExpression);
     }
 }
 /**
  * Call back method that must be called as soon as the given <code>
  * ParenthesizedExpression</code> object has been traversed.
  *
  * @param pParenthesizedExpression  The <code>ParenthesizedExpression</code>
  *                                  object that has just been traversed.
  */
 public void actionPerformed(
      
     ParenthesizedExpression pParenthesizedExpression)
 {
     // Nothing to do.
 }
 public override StringBuilder VisitParenthesizedExpression(ParenthesizedExpression parenthesizedExpression, int data)
 {
     throw new NotImplementedException();
 }
		public override void VisitParenthesizedExpression(ParenthesizedExpression parenthesizedExpression)
		{
			var lp = parenthesizedExpression.LParToken;
			var expr = parenthesizedExpression.Expression;
			int extraSpaces = 0;
			if (lp.StartLocation.Line == expr.StartLocation.Line) {
				ForceSpacesAfter(lp, policy.SpacesWithinParentheses);
			} else {
				extraSpaces += options.IndentSize;
				curIndent.ExtraSpaces += extraSpaces;
				FixIndentation(expr);
			}

			base.VisitParenthesizedExpression(parenthesizedExpression);

			var rp = parenthesizedExpression.RParToken;

			curIndent.ExtraSpaces -= extraSpaces;
			if (rp.StartLocation.Line == expr.EndLocation.Line) {
				ForceSpacesBefore(rp, policy.SpacesWithinParentheses);
			} else {
				FixIndentation(rp);
			}
		}
Example #41
0
 public void VisitParenthesizedExpression(ParenthesizedExpression parensExpr)
 {
     throw new NotImplementedException();
 }
Example #42
0
 public override void VisitParenthesizedExpression(ParenthesizedExpression parenthesizedExpression)
 {
     new ParenthesizedBlock(this, parenthesizedExpression).Emit();
 }
Example #43
0
 public abstract StringBuilder VisitParenthesizedExpression(ParenthesizedExpression parenthesizedExpression, int data);
Example #44
0
 public void VisitParenthesizedExpression(ParenthesizedExpression expression)
 {
     Formatter.StartNode(expression);
     Formatter.WriteToken("(");
     expression.Expression.AcceptVisitor(this);
     Formatter.WriteToken(")");
     Formatter.EndNode();
 }
 /**
  * Call back method that must be called when the given <code>
  * ParenthesizedExpression</code> will become the next <i>traverse
  * candidate</i>.
  *
  * @param pParenthesizedExpression  The <code>ParenthesizedExpression</code>
  *                                  object that will become the next <i>
  *                                  traverse candidate</i>.
  */
 public void performAction(
      
     ParenthesizedExpression pParenthesizedExpression)
 {
     // Nothing to do.
 }
        /// <summary>
        /// Checks the given parenthesized expression to make sure that it is not unnecessary.
        /// </summary>
        /// <param name="element">The element containing the expression.</param>
        /// <param name="parenthesizedExpression">The parenthesized expression to check.</param>
        private void CheckParenthesizedExpression(Element element, ParenthesizedExpression parenthesizedExpression)
        {
            Param.AssertNotNull(element, "element");
            Param.AssertNotNull(parenthesizedExpression, "parenthesizedExpression");

            // Check the type of the inner expression to determine if it is one of types allowed to be wrapped within parenthesis.
            if (parenthesizedExpression.InnerExpression != null)
            {
                // The following types of expressions are allowed to be placed within a set of parenthesis.
                Expression innerExpression = parenthesizedExpression.InnerExpression;
                if (innerExpression.ExpressionType != ExpressionType.Arithmetic &&
                    innerExpression.ExpressionType != ExpressionType.As &&
                    innerExpression.ExpressionType != ExpressionType.Assignment &&
                    innerExpression.ExpressionType != ExpressionType.Cast &&
                    innerExpression.ExpressionType != ExpressionType.Conditional &&
                    innerExpression.ExpressionType != ExpressionType.ConditionalLogical &&
                    innerExpression.ExpressionType != ExpressionType.Decrement &&
                    innerExpression.ExpressionType != ExpressionType.Increment &&
                    innerExpression.ExpressionType != ExpressionType.Is &&
                    innerExpression.ExpressionType != ExpressionType.Lambda &&
                    innerExpression.ExpressionType != ExpressionType.Logical &&
                    innerExpression.ExpressionType != ExpressionType.New &&
                    innerExpression.ExpressionType != ExpressionType.NewArray &&
                    innerExpression.ExpressionType != ExpressionType.NullCoalescing &&
                    innerExpression.ExpressionType != ExpressionType.Query &&
                    innerExpression.ExpressionType != ExpressionType.Relational &&
                    innerExpression.ExpressionType != ExpressionType.Unary &&
                    innerExpression.ExpressionType != ExpressionType.UnsafeAccess)
                {
                    this.AddViolation(element, parenthesizedExpression.LineNumber, Rules.StatementMustNotUseUnnecessaryParenthesis);
                }
                else
                {
                    // These types of expressions are allowed in some cases to be surrounded by parenthesis,
                    // as long as the parenthesized expression is within another expression. They are not allowed
                    // to be within parenthesis within a variable declarator expression. For example:
                    // int x = (2 + 3);
                    if (!(parenthesizedExpression.Parent is Expression) || parenthesizedExpression.Parent is VariableDeclaratorExpression)
                    {
                        this.AddViolation(element, parenthesizedExpression.LineNumber, Rules.StatementMustNotUseUnnecessaryParenthesis);
                    }
                    else
                    {
                        // This is also not allowed when the expression is on the right-hand side of an assignment.
                        AssignmentExpression assignment = parenthesizedExpression.Parent as AssignmentExpression;
                        if (assignment != null && assignment.RightHandSide == parenthesizedExpression)
                        {
                            this.AddViolation(element, parenthesizedExpression.LineNumber, Rules.StatementMustNotUseUnnecessaryParenthesis);
                        }
                    }
                }
            }
        }
			protected override IEnumerable<string> GenerateCode (INRefactoryASTProvider astProvider, string indent, List<IBaseMember> includedMembers)
			{
				// Genereate Equals
				MethodDeclaration methodDeclaration = new MethodDeclaration ();
				methodDeclaration.Name = "Equals";

				methodDeclaration.ReturnType = DomReturnType.Bool.ConvertToTypeReference ();
				methodDeclaration.Modifiers = ICSharpCode.NRefactory.CSharp.Modifiers.Public | ICSharpCode.NRefactory.CSharp.Modifiers.Override;
				methodDeclaration.Body = new BlockStatement ();
				methodDeclaration.Parameters.Add (new ParameterDeclaration (DomReturnType.Object.ConvertToTypeReference (), "obj"));
				IdentifierExpression paramId = new IdentifierExpression ("obj");
				IfElseStatement ifStatement = new IfElseStatement ();
				ifStatement.Condition = new BinaryOperatorExpression (paramId, BinaryOperatorType.Equality, new PrimitiveExpression (null));
				ifStatement.TrueStatement = new ReturnStatement (new PrimitiveExpression (false));
				methodDeclaration.Body.Statements.Add (ifStatement);

				ifStatement = new IfElseStatement ();
				List<Expression> arguments = new List<Expression> ();
				arguments.Add (new ThisReferenceExpression ());
				arguments.Add (paramId.Clone ());
				ifStatement.Condition = new InvocationExpression (new IdentifierExpression ("ReferenceEquals"), arguments);
				ifStatement.TrueStatement = new ReturnStatement (new PrimitiveExpression (true));
				methodDeclaration.Body.Statements.Add (ifStatement);

				ifStatement = new IfElseStatement ();
				ifStatement.Condition = new BinaryOperatorExpression (new InvocationExpression (new MemberReferenceExpression (paramId.Clone (), "GetType")), BinaryOperatorType.InEquality, new TypeOfExpression (new SimpleType (Options.EnclosingType.Name)));
				ifStatement.TrueStatement = new ReturnStatement (new PrimitiveExpression (false));
				methodDeclaration.Body.Statements.Add (ifStatement);

				AstType varType = new DomReturnType (Options.EnclosingType).ConvertToTypeReference ();
				var varDecl = new VariableDeclarationStatement (varType, "other", new CastExpression (varType.Clone (), paramId.Clone ()));
				methodDeclaration.Body.Statements.Add (varDecl);
				
				IdentifierExpression otherId = new IdentifierExpression ("other");
				Expression binOp = null;
				foreach (IMember member in includedMembers) {
					Expression right = new BinaryOperatorExpression (new IdentifierExpression (member.Name), BinaryOperatorType.Equality, new MemberReferenceExpression (otherId, member.Name));
					if (binOp == null) {
						binOp = right;
					} else {
						binOp = new BinaryOperatorExpression (binOp, BinaryOperatorType.ConditionalAnd, right);
					}
				}

				methodDeclaration.Body.Statements.Add (new ReturnStatement (binOp));
				yield return astProvider.OutputNode (this.Options.Dom, methodDeclaration, indent);

				methodDeclaration = new MethodDeclaration ();
				methodDeclaration.Name = "GetHashCode";

				methodDeclaration.ReturnType = DomReturnType.Int32.ConvertToTypeReference ();
				methodDeclaration.Modifiers = ICSharpCode.NRefactory.CSharp.Modifiers.Public | ICSharpCode.NRefactory.CSharp.Modifiers.Override;
				methodDeclaration.Body = new BlockStatement ();

				binOp = null;
				foreach (IMember member in includedMembers) {
					Expression right;
					right = new InvocationExpression (new MemberReferenceExpression (new IdentifierExpression (member.Name), "GetHashCode"));

					IType type = Options.Dom.SearchType (Options.Document.ParsedDocument.CompilationUnit, member is IType ? ((IType)member) : member.DeclaringType, member.Location, member.ReturnType);
					if (type != null && type.ClassType != MonoDevelop.Projects.Dom.ClassType.Struct&& type.ClassType != MonoDevelop.Projects.Dom.ClassType.Enum)
						right = new ParenthesizedExpression (new ConditionalExpression (new BinaryOperatorExpression (new IdentifierExpression (member.Name), BinaryOperatorType.InEquality, new PrimitiveExpression (null)), right, new PrimitiveExpression (0)));

					if (binOp == null) {
						binOp = right;
					} else {
						binOp = new BinaryOperatorExpression (binOp, BinaryOperatorType.ExclusiveOr, right);
					}
				}
				BlockStatement uncheckedBlock = new BlockStatement ();
				uncheckedBlock.Statements.Add (new ReturnStatement (binOp));

				methodDeclaration.Body.Statements.Add (new UncheckedStatement (uncheckedBlock));
				yield return astProvider.OutputNode (this.Options.Dom, methodDeclaration, indent);
			}
Example #48
0
	void SimpleNonInvocationExpression(
#line  1645 "VBNET.ATG" 
out Expression pexpr) {

#line  1647 "VBNET.ATG" 
		Expression expr;
		TypeReference type = null;
		string name = String.Empty;
		pexpr = null;
		
		if (StartOf(32)) {
			switch (la.kind) {
			case 3: {
				lexer.NextToken();

#line  1655 "VBNET.ATG" 
				pexpr = new PrimitiveExpression(t.literalValue, t.val) { LiteralFormat = t.literalFormat };  
				break;
			}
			case 4: {
				lexer.NextToken();

#line  1656 "VBNET.ATG" 
				pexpr = new PrimitiveExpression(t.literalValue, t.val) { LiteralFormat = t.literalFormat };  
				break;
			}
			case 7: {
				lexer.NextToken();

#line  1657 "VBNET.ATG" 
				pexpr = new PrimitiveExpression(t.literalValue, t.val) { LiteralFormat = t.literalFormat };  
				break;
			}
			case 6: {
				lexer.NextToken();

#line  1658 "VBNET.ATG" 
				pexpr = new PrimitiveExpression(t.literalValue, t.val) { LiteralFormat = t.literalFormat };  
				break;
			}
			case 5: {
				lexer.NextToken();

#line  1659 "VBNET.ATG" 
				pexpr = new PrimitiveExpression(t.literalValue, t.val) { LiteralFormat = t.literalFormat };  
				break;
			}
			case 9: {
				lexer.NextToken();

#line  1660 "VBNET.ATG" 
				pexpr = new PrimitiveExpression(t.literalValue, t.val) { LiteralFormat = t.literalFormat };  
				break;
			}
			case 8: {
				lexer.NextToken();

#line  1661 "VBNET.ATG" 
				pexpr = new PrimitiveExpression(t.literalValue, t.val) { LiteralFormat = t.literalFormat };  
				break;
			}
			case 202: {
				lexer.NextToken();

#line  1663 "VBNET.ATG" 
				pexpr = new PrimitiveExpression(true, "true");  
				break;
			}
			case 109: {
				lexer.NextToken();

#line  1664 "VBNET.ATG" 
				pexpr = new PrimitiveExpression(false, "false"); 
				break;
			}
			case 151: {
				lexer.NextToken();

#line  1665 "VBNET.ATG" 
				pexpr = new PrimitiveExpression(null, "null");  
				break;
			}
			case 25: {
				lexer.NextToken();
				Expr(
#line  1666 "VBNET.ATG" 
out expr);
				Expect(26);

#line  1666 "VBNET.ATG" 
				pexpr = new ParenthesizedExpression(expr); 
				break;
			}
			case 2: case 45: case 49: case 51: case 52: case 53: case 54: case 57: case 74: case 85: case 91: case 94: case 103: case 108: case 113: case 120: case 126: case 130: case 133: case 156: case 162: case 169: case 188: case 197: case 198: case 208: case 209: case 215: {
				Identifier();

#line  1668 "VBNET.ATG" 
				pexpr = new IdentifierExpression(t.val);
				pexpr.StartLocation = t.Location; pexpr.EndLocation = t.EndLocation;
				
				if (
#line  1671 "VBNET.ATG" 
la.kind == Tokens.OpenParenthesis && Peek(1).kind == Tokens.Of) {
					lexer.NextToken();
					Expect(155);
					TypeArgumentList(
#line  1672 "VBNET.ATG" 
((IdentifierExpression)pexpr).TypeArguments);
					Expect(26);
				}
				break;
			}
			case 55: case 58: case 69: case 86: case 87: case 96: case 128: case 137: case 154: case 181: case 186: case 187: case 193: case 206: case 207: case 210: {

#line  1674 "VBNET.ATG" 
				string val = String.Empty; 
				if (StartOf(11)) {
					PrimitiveTypeName(
#line  1675 "VBNET.ATG" 
out val);
				} else if (la.kind == 154) {
					lexer.NextToken();

#line  1675 "VBNET.ATG" 
					val = "System.Object"; 
				} else SynErr(257);

#line  1676 "VBNET.ATG" 
				pexpr = new TypeReferenceExpression(new TypeReference(val, true)); 
				break;
			}
			case 139: {
				lexer.NextToken();

#line  1677 "VBNET.ATG" 
				pexpr = new ThisReferenceExpression(); 
				break;
			}
			case 144: case 145: {

#line  1678 "VBNET.ATG" 
				Expression retExpr = null; 
				if (la.kind == 144) {
					lexer.NextToken();

#line  1679 "VBNET.ATG" 
					retExpr = new BaseReferenceExpression(); 
				} else if (la.kind == 145) {
					lexer.NextToken();

#line  1680 "VBNET.ATG" 
					retExpr = new ClassReferenceExpression(); 
				} else SynErr(258);
				Expect(16);
				IdentifierOrKeyword(
#line  1682 "VBNET.ATG" 
out name);

#line  1682 "VBNET.ATG" 
				pexpr = new MemberReferenceExpression(retExpr, name); 
				break;
			}
			case 117: {
				lexer.NextToken();
				Expect(16);
				Identifier();

#line  1684 "VBNET.ATG" 
				type = new TypeReference(t.val ?? ""); 

#line  1686 "VBNET.ATG" 
				type.IsGlobal = true; 

#line  1687 "VBNET.ATG" 
				pexpr = new TypeReferenceExpression(type); 
				break;
			}
			case 148: {
				ObjectCreateExpression(
#line  1688 "VBNET.ATG" 
out expr);

#line  1688 "VBNET.ATG" 
				pexpr = expr; 
				break;
			}
			case 81: case 93: case 204: {

#line  1690 "VBNET.ATG" 
				CastType castType = CastType.Cast; 
				if (la.kind == 93) {
					lexer.NextToken();
				} else if (la.kind == 81) {
					lexer.NextToken();

#line  1692 "VBNET.ATG" 
					castType = CastType.Conversion; 
				} else if (la.kind == 204) {
					lexer.NextToken();

#line  1693 "VBNET.ATG" 
					castType = CastType.TryCast; 
				} else SynErr(259);
				Expect(25);
				Expr(
#line  1695 "VBNET.ATG" 
out expr);
				Expect(12);
				TypeName(
#line  1695 "VBNET.ATG" 
out type);
				Expect(26);

#line  1696 "VBNET.ATG" 
				pexpr = new CastExpression(type, expr, castType); 
				break;
			}
			case 63: case 64: case 65: case 66: case 67: case 68: case 70: case 72: case 73: case 77: case 78: case 79: case 80: case 82: case 83: case 84: {
				CastTarget(
#line  1697 "VBNET.ATG" 
out type);
				Expect(25);
				Expr(
#line  1697 "VBNET.ATG" 
out expr);
				Expect(26);

#line  1697 "VBNET.ATG" 
				pexpr = new CastExpression(type, expr, CastType.PrimitiveConversion); 
				break;
			}
			case 44: {
				lexer.NextToken();
				Expr(
#line  1698 "VBNET.ATG" 
out expr);

#line  1698 "VBNET.ATG" 
				pexpr = new AddressOfExpression(expr); 
				break;
			}
			case 116: {
				lexer.NextToken();
				Expect(25);
				GetTypeTypeName(
#line  1699 "VBNET.ATG" 
out type);
				Expect(26);

#line  1699 "VBNET.ATG" 
				pexpr = new TypeOfExpression(type); 
				break;
			}
			case 205: {
				lexer.NextToken();
				SimpleExpr(
#line  1700 "VBNET.ATG" 
out expr);
				Expect(131);
				TypeName(
#line  1700 "VBNET.ATG" 
out type);

#line  1700 "VBNET.ATG" 
				pexpr = new TypeOfIsExpression(expr, type); 
				break;
			}
			case 122: {
				ConditionalExpression(
#line  1701 "VBNET.ATG" 
out pexpr);
				break;
			}
			}
		} else if (la.kind == 16) {
			lexer.NextToken();
			IdentifierOrKeyword(
#line  1705 "VBNET.ATG" 
out name);

#line  1705 "VBNET.ATG" 
			pexpr = new MemberReferenceExpression(null, name);
		} else SynErr(260);
	}
Example #49
0
 public static dynamic GetValueFromParenthesizedExpression(ParenthesizedExpression expr)
 {
     return GetValueFromExpression(expr.Expression);
 }
			protected override IEnumerable<string> GenerateCode (List<object> includedMembers)
			{
				// Genereate Equals
				var methodDeclaration = new MethodDeclaration ();
				methodDeclaration.Name = "Equals";

				methodDeclaration.ReturnType = new PrimitiveType ("bool");
				methodDeclaration.Modifiers = ICSharpCode.NRefactory.CSharp.Modifiers.Public | ICSharpCode.NRefactory.CSharp.Modifiers.Override;
				methodDeclaration.Body = new BlockStatement ();
				methodDeclaration.Parameters.Add (new ParameterDeclaration (new PrimitiveType ("object"), "obj"));
				var paramId = new IdentifierExpression ("obj");
				IfElseStatement ifStatement = new IfElseStatement ();
				ifStatement.Condition = new BinaryOperatorExpression (paramId, BinaryOperatorType.Equality, new PrimitiveExpression (null));
				ifStatement.TrueStatement = new ReturnStatement (new PrimitiveExpression (false));
				methodDeclaration.Body.Statements.Add (ifStatement);

				ifStatement = new IfElseStatement ();
				var arguments = new List<Expression> ();
				arguments.Add (new ThisReferenceExpression ());
				arguments.Add (paramId.Clone ());
				ifStatement.Condition = new InvocationExpression (new IdentifierExpression ("ReferenceEquals"), arguments);
				ifStatement.TrueStatement = new ReturnStatement (new PrimitiveExpression (true));
				methodDeclaration.Body.Statements.Add (ifStatement);

				ifStatement = new IfElseStatement ();
				ifStatement.Condition = new BinaryOperatorExpression (new InvocationExpression (new MemberReferenceExpression (paramId.Clone (), "GetType")), BinaryOperatorType.InEquality, new TypeOfExpression (new SimpleType (Options.EnclosingType.Name)));
				ifStatement.TrueStatement = new ReturnStatement (new PrimitiveExpression (false));
				methodDeclaration.Body.Statements.Add (ifStatement);

				var varType = new SimpleType (Options.EnclosingType.Name);
				var varDecl = new VariableDeclarationStatement (varType, "other", new CastExpression (varType.Clone (), paramId.Clone ()));
				methodDeclaration.Body.Statements.Add (varDecl);
				
				var otherId = new IdentifierExpression ("other");
				Expression binOp = null;
				foreach (IMember member in includedMembers) {
					Expression right = new BinaryOperatorExpression (new IdentifierExpression (member.Name), BinaryOperatorType.Equality, new MemberReferenceExpression (otherId.Clone (), member.Name));
					if (binOp == null) {
						binOp = right;
					} else {
						binOp = new BinaryOperatorExpression (binOp, BinaryOperatorType.ConditionalAnd, right);
					}
				}

				methodDeclaration.Body.Statements.Add (new ReturnStatement (binOp));
				yield return methodDeclaration.ToString (Options.FormattingOptions);

				methodDeclaration = new MethodDeclaration ();
				methodDeclaration.Name = "GetHashCode";

				methodDeclaration.ReturnType = new PrimitiveType ("int");
				methodDeclaration.Modifiers = ICSharpCode.NRefactory.CSharp.Modifiers.Public | ICSharpCode.NRefactory.CSharp.Modifiers.Override;
				methodDeclaration.Body = new BlockStatement ();

				binOp = null;
				foreach (IMember member in includedMembers) {
					Expression right;
					right = new InvocationExpression (new MemberReferenceExpression (new IdentifierExpression (member.Name), "GetHashCode"));

					IType type = member.ReturnType;
					if (type != null && type.Kind != TypeKind.Struct && type.Kind != TypeKind.Enum)
						right = new ParenthesizedExpression (new ConditionalExpression (new BinaryOperatorExpression (new IdentifierExpression (member.Name), BinaryOperatorType.InEquality, new PrimitiveExpression (null)), right, new PrimitiveExpression (0)));

					if (binOp == null) {
						binOp = right;
					} else {
						binOp = new BinaryOperatorExpression (binOp, BinaryOperatorType.ExclusiveOr, right);
					}
				}
				var uncheckedBlock = new BlockStatement ();
				uncheckedBlock.Statements.Add (new ReturnStatement (binOp));

				methodDeclaration.Body.Statements.Add (new UncheckedStatement (uncheckedBlock));
				yield return methodDeclaration.ToString (Options.FormattingOptions);
			}
 private void Format_Parenthesized_Expression(StringBuilder sb, ParenthesizedExpression exp)
 {
     sb.Append("(").Append(FormatExpression(exp.Expression)).Append(")");
 }
Example #52
0
  /** the generated parser.
      Maintains a state and a value stack, currently with fixed maximum size.
      @param yyLex scanner.
      @return result of the last reduction, if any.
      @throws yyException on irrecoverable parse error.
    */
  internal Object yyparse (yyParser.yyInput yyLex)
  {
    if (yyMax <= 0) yyMax = 256;		// initial size
    int yyState = 0;                   // state stack ptr
    int [] yyStates;               	// state stack 
    yyVal = null;
    yyToken = -1;
    int yyErrorFlag = 0;				// #tks to shift
	if (use_global_stacks && global_yyStates != null) {
		yyVals = global_yyVals;
		yyStates = global_yyStates;
   } else {
		yyVals = new object [yyMax];
		yyStates = new int [yyMax];
		if (use_global_stacks) {
			global_yyVals = yyVals;
			global_yyStates = yyStates;
		}
	}

    /*yyLoop:*/ for (yyTop = 0;; ++ yyTop) {
      if (yyTop >= yyStates.Length) {			// dynamically increase
        global::System.Array.Resize (ref yyStates, yyStates.Length+yyMax);
        global::System.Array.Resize (ref yyVals, yyVals.Length+yyMax);
      }
      yyStates[yyTop] = yyState;
      yyVals[yyTop] = yyVal;
//t      if (debug != null) debug.push(yyState, yyVal);

      /*yyDiscarded:*/ while (true) {	// discarding a token does not change stack
        int yyN;
        if ((yyN = yyDefRed[yyState]) == 0) {	// else [default] reduce (yyN)
          if (yyToken < 0) {
            yyToken = yyLex.advance() ? yyLex.token() : 0;
//t            if (debug != null)
//t              debug.lex(yyState, yyToken, yyname(yyToken), yyLex.value());
          }
          if ((yyN = yySindex[yyState]) != 0 && ((yyN += yyToken) >= 0)
              && (yyN < yyTable.Length) && (yyCheck[yyN] == yyToken)) {
//t            if (debug != null)
//t              debug.shift(yyState, yyTable[yyN], yyErrorFlag-1);
            yyState = yyTable[yyN];		// shift to yyN
            yyVal = yyLex.value();
            yyToken = -1;
            if (yyErrorFlag > 0) -- yyErrorFlag;
            goto continue_yyLoop;
          }
          if ((yyN = yyRindex[yyState]) != 0 && (yyN += yyToken) >= 0
              && yyN < yyTable.Length && yyCheck[yyN] == yyToken)
            yyN = yyTable[yyN];			// reduce (yyN)
          else
            switch (yyErrorFlag) {
  
            case 0:
              yyExpectingState = yyState;
              // yyerror(String.Format ("syntax error, got token `{0}'", yyname (yyToken)), yyExpecting(yyState));
//t              if (debug != null) debug.error("syntax error");
              if (yyToken == 0 /*eof*/ || yyToken == eof_token) throw new yyParser.yyUnexpectedEof ();
              goto case 1;
            case 1: case 2:
              yyErrorFlag = 3;
              do {
                if ((yyN = yySindex[yyStates[yyTop]]) != 0
                    && (yyN += Token.yyErrorCode) >= 0 && yyN < yyTable.Length
                    && yyCheck[yyN] == Token.yyErrorCode) {
//t                  if (debug != null)
//t                    debug.shift(yyStates[yyTop], yyTable[yyN], 3);
                  yyState = yyTable[yyN];
                  yyVal = yyLex.value();
                  goto continue_yyLoop;
                }
//t                if (debug != null) debug.pop(yyStates[yyTop]);
              } while (-- yyTop >= 0);
//t              if (debug != null) debug.reject();
              throw new yyParser.yyException("irrecoverable syntax error");
  
            case 3:
              if (yyToken == 0) {
//t                if (debug != null) debug.reject();
                throw new yyParser.yyException("irrecoverable syntax error at end-of-file");
              }
//t              if (debug != null)
//t                debug.discard(yyState, yyToken, yyname(yyToken),
//t  							yyLex.value());
              yyToken = -1;
              goto continue_yyDiscarded;		// leave stack alone
            }
        }
        int yyV = yyTop + 1-yyLen[yyN];
//t        if (debug != null)
//t          debug.reduce(yyState, yyStates[yyV-1], yyN, YYRules.getRule (yyN), yyLen[yyN]);
        yyVal = yyV > yyTop ? null : yyVals[yyV]; // yyVal = yyDefault(yyV > yyTop ? null : yyVals[yyV]);
        switch (yyN) {
case 1:
#line 392 "cs-parser.jay"
  {
		Lexer.check_incorrect_doc_comment ();
	  }
  break;
case 2:
#line 393 "cs-parser.jay"
  { Lexer.CompleteOnEOF = false; }
  break;
case 6:
  case_6();
  break;
case 7:
#line 412 "cs-parser.jay"
  {
		module.AddAttributes ((Attributes) yyVals[0+yyTop], current_namespace);
	  }
  break;
case 8:
  case_8();
  break;
case 13:
  case_13();
  break;
case 14:
#line 457 "cs-parser.jay"
  {
		Error_SyntaxError (yyToken);
	  }
  break;
case 17:
  case_17();
  break;
case 18:
  case_18();
  break;
case 19:
  case_19();
  break;
case 20:
  case_20();
  break;
case 23:
  case_23();
  break;
case 24:
  case_24();
  break;
case 25:
  case_25();
  break;
case 26:
  case_26();
  break;
case 29:
  case_29();
  break;
case 30:
  case_30();
  break;
case 31:
  case_31();
  break;
case 32:
  case_32();
  break;
case 45:
  case_45();
  break;
case 46:
#line 660 "cs-parser.jay"
  {
		current_namespace.DeclarationFound = true;
	  }
  break;
case 47:
  case_47();
  break;
case 55:
  case_55();
  break;
case 56:
  case_56();
  break;
case 57:
  case_57();
  break;
case 58:
  case_58();
  break;
case 59:
  case_59();
  break;
case 60:
  case_60();
  break;
case 61:
  case_61();
  break;
case 62:
  case_62();
  break;
case 63:
  case_63();
  break;
case 64:
  case_64();
  break;
case 65:
#line 787 "cs-parser.jay"
  { yyVal = "event"; PushLocation (GetLocation (yyVals[0+yyTop])); }
  break;
case 66:
#line 788 "cs-parser.jay"
  { yyVal = "return"; PushLocation (GetLocation (yyVals[0+yyTop])); }
  break;
case 67:
#line 795 "cs-parser.jay"
  {
		yyVal = new List<Attribute> (4) { (Attribute) yyVals[0+yyTop] };
	  }
  break;
case 68:
  case_68();
  break;
case 69:
#line 812 "cs-parser.jay"
  {
		++lexer.parsing_block;
	  }
  break;
case 70:
  case_70();
  break;
case 72:
#line 840 "cs-parser.jay"
  { yyVal = null; HadAttributeParens = false;  }
  break;
case 73:
  case_73();
  break;
case 74:
#line 852 "cs-parser.jay"
  { yyVal = null; }
  break;
case 75:
  case_75();
  break;
case 76:
  case_76();
  break;
case 77:
  case_77();
  break;
case 78:
  case_78();
  break;
case 79:
#line 896 "cs-parser.jay"
  {
	  	yyVal = new Argument ((Expression) yyVals[0+yyTop]);
	  }
  break;
case 81:
  case_81();
  break;
case 82:
#line 909 "cs-parser.jay"
  {
		++lexer.parsing_block;
	  }
  break;
case 83:
  case_83();
  break;
case 84:
  case_84();
  break;
case 86:
#line 940 "cs-parser.jay"
  { yyVal = null; }
  break;
case 87:
#line 944 "cs-parser.jay"
  { 
		yyVal = Argument.AType.Ref;
	  }
  break;
case 88:
#line 948 "cs-parser.jay"
  { 
		yyVal = Argument.AType.Out;
	  }
  break;
case 91:
  case_91();
  break;
case 92:
  case_92();
  break;
case 106:
  case_106();
  break;
case 107:
  case_107();
  break;
case 108:
  case_108();
  break;
case 109:
#line 1025 "cs-parser.jay"
  {
	  }
  break;
case 110:
  case_110();
  break;
case 111:
  case_111();
  break;
case 112:
  case_112();
  break;
case 113:
  case_113();
  break;
case 114:
  case_114();
  break;
case 115:
#line 1075 "cs-parser.jay"
  {
		Error_SyntaxError (yyToken);
	  }
  break;
case 116:
  case_116();
  break;
case 117:
  case_117();
  break;
case 118:
  case_118();
  break;
case 121:
#line 1124 "cs-parser.jay"
  {
		current_field.AddDeclarator ((FieldDeclarator) yyVals[0+yyTop]);
	  }
  break;
case 122:
#line 1128 "cs-parser.jay"
  {
		current_field.AddDeclarator ((FieldDeclarator) yyVals[0+yyTop]);
	  }
  break;
case 123:
  case_123();
  break;
case 124:
#line 1144 "cs-parser.jay"
  {
		++lexer.parsing_block;
	  }
  break;
case 125:
  case_125();
  break;
case 126:
  case_126();
  break;
case 129:
  case_129();
  break;
case 130:
  case_130();
  break;
case 131:
  case_131();
  break;
case 132:
  case_132();
  break;
case 133:
#line 1223 "cs-parser.jay"
  {
		report.Error (1641, GetLocation (yyVals[-1+yyTop]), "A fixed size buffer field must have the array size specifier after the field name");
	  }
  break;
case 135:
  case_135();
  break;
case 136:
  case_136();
  break;
case 139:
#line 1253 "cs-parser.jay"
  {
		current_field.AddDeclarator ((FieldDeclarator) yyVals[0+yyTop]);
	  }
  break;
case 140:
#line 1257 "cs-parser.jay"
  {
		current_field.AddDeclarator ((FieldDeclarator) yyVals[0+yyTop]);
	  }
  break;
case 141:
  case_141();
  break;
case 142:
#line 1270 "cs-parser.jay"
  {
		++lexer.parsing_block;
	  }
  break;
case 143:
  case_143();
  break;
case 146:
#line 1289 "cs-parser.jay"
  {
		current_field.AddDeclarator ((FieldDeclarator) yyVals[0+yyTop]);
	  }
  break;
case 147:
#line 1293 "cs-parser.jay"
  {
		current_field.AddDeclarator ((FieldDeclarator) yyVals[0+yyTop]);
	  }
  break;
case 148:
  case_148();
  break;
case 149:
#line 1309 "cs-parser.jay"
  {
		++lexer.parsing_block;
	  }
  break;
case 150:
  case_150();
  break;
case 151:
  case_151();
  break;
case 154:
  case_154();
  break;
case 155:
  case_155();
  break;
case 156:
  case_156();
  break;
case 157:
#line 1377 "cs-parser.jay"
  {
		valid_param_mod = ParameterModifierType.All;
	  }
  break;
case 158:
  case_158();
  break;
case 159:
  case_159();
  break;
case 160:
#line 1416 "cs-parser.jay"
  {
		lexer.parsing_generic_declaration = true;
	  }
  break;
case 161:
  case_161();
  break;
case 162:
#line 1426 "cs-parser.jay"
  {
		lexer.ConstraintsParsing = true;
	  }
  break;
case 163:
  case_163();
  break;
case 164:
  case_164();
  break;
case 165:
  case_165();
  break;
case 169:
#line 1504 "cs-parser.jay"
  { savedLocation = GetLocation (yyVals[0+yyTop]); yyVal = null; }
  break;
case 170:
  case_170();
  break;
case 171:
  case_171();
  break;
case 172:
#line 1528 "cs-parser.jay"
  { yyVal = ParametersCompiled.EmptyReadOnlyParameters; }
  break;
case 174:
  case_174();
  break;
case 175:
  case_175();
  break;
case 176:
  case_176();
  break;
case 177:
  case_177();
  break;
case 178:
  case_178();
  break;
case 179:
  case_179();
  break;
case 180:
  case_180();
  break;
case 181:
#line 1600 "cs-parser.jay"
  {
		yyVal = new ParametersCompiled (new Parameter[] { (Parameter) yyVals[0+yyTop] } );
	  }
  break;
case 182:
#line 1604 "cs-parser.jay"
  {
		yyVal = new ParametersCompiled (new Parameter [] { new ArglistParameter (GetLocation (yyVals[0+yyTop])) }, true);
	  }
  break;
case 183:
  case_183();
  break;
case 184:
  case_184();
  break;
case 185:
  case_185();
  break;
case 186:
  case_186();
  break;
case 187:
  case_187();
  break;
case 188:
  case_188();
  break;
case 189:
  case_189();
  break;
case 190:
#line 1685 "cs-parser.jay"
  {
	  	++lexer.parsing_block;
	  }
  break;
case 191:
  case_191();
  break;
case 192:
#line 1726 "cs-parser.jay"
  { yyVal = Parameter.Modifier.NONE; }
  break;
case 194:
#line 1734 "cs-parser.jay"
  {
		yyVal = yyVals[0+yyTop];
	  }
  break;
case 195:
  case_195();
  break;
case 196:
  case_196();
  break;
case 197:
  case_197();
  break;
case 198:
  case_198();
  break;
case 199:
  case_199();
  break;
case 200:
  case_200();
  break;
case 201:
  case_201();
  break;
case 202:
  case_202();
  break;
case 203:
  case_203();
  break;
case 204:
#line 1828 "cs-parser.jay"
  {
		Error_DuplicateParameterModifier (GetLocation (yyVals[-1+yyTop]), Parameter.Modifier.PARAMS);
	  }
  break;
case 205:
  case_205();
  break;
case 206:
  case_206();
  break;
case 207:
  case_207();
  break;
case 208:
  case_208();
  break;
case 209:
  case_209();
  break;
case 210:
#line 1878 "cs-parser.jay"
  {
		current_property = null;
	  }
  break;
case 211:
  case_211();
  break;
case 212:
  case_212();
  break;
case 214:
  case_214();
  break;
case 215:
  case_215();
  break;
case 218:
#line 1940 "cs-parser.jay"
  {
	  	valid_param_mod = ParameterModifierType.Params | ParameterModifierType.DefaultValue;
	  }
  break;
case 219:
  case_219();
  break;
case 220:
  case_220();
  break;
case 221:
#line 1986 "cs-parser.jay"
  {
		lbag.AppendToMember (current_property, GetLocation (yyVals[-2+yyTop]), GetLocation (yyVals[0+yyTop]));
	  }
  break;
case 222:
  case_222();
  break;
case 227:
  case_227();
  break;
case 228:
  case_228();
  break;
case 229:
  case_229();
  break;
case 230:
  case_230();
  break;
case 231:
  case_231();
  break;
case 233:
  case_233();
  break;
case 234:
  case_234();
  break;
case 235:
#line 2127 "cs-parser.jay"
  {
	  }
  break;
case 236:
  case_236();
  break;
case 237:
  case_237();
  break;
case 238:
  case_238();
  break;
case 239:
  case_239();
  break;
case 240:
#line 2167 "cs-parser.jay"
  {
		Error_SyntaxError (yyToken);	  
	  }
  break;
case 243:
  case_243();
  break;
case 244:
  case_244();
  break;
case 245:
#line 2192 "cs-parser.jay"
  {
		report.Error (525, GetLocation (yyVals[0+yyTop]), "Interfaces cannot contain fields or constants");
	  }
  break;
case 246:
#line 2196 "cs-parser.jay"
  {
		report.Error (525, GetLocation (yyVals[0+yyTop]), "Interfaces cannot contain fields or constants");
	  }
  break;
case 251:
#line 2204 "cs-parser.jay"
  {
	  	report.Error (567, GetLocation (yyVals[0+yyTop]), "Interfaces cannot contain operators");
	  }
  break;
case 252:
#line 2208 "cs-parser.jay"
  {
	  	report.Error (526, GetLocation (yyVals[0+yyTop]), "Interfaces cannot contain contructors");
	  }
  break;
case 253:
#line 2212 "cs-parser.jay"
  {
	  	report.Error (524, GetLocation (yyVals[0+yyTop]), "Interfaces cannot declare classes, structs, interfaces, delegates, or enumerations");
	  }
  break;
case 254:
#line 2218 "cs-parser.jay"
  {
	  }
  break;
case 255:
  case_255();
  break;
case 257:
  case_257();
  break;
case 258:
  case_258();
  break;
case 259:
  case_259();
  break;
case 261:
#line 2312 "cs-parser.jay"
  { yyVal = Operator.OpType.LogicalNot; savedOperatorLocation = GetLocation (yyVals[0+yyTop]); }
  break;
case 262:
#line 2313 "cs-parser.jay"
  { yyVal = Operator.OpType.OnesComplement; savedOperatorLocation = GetLocation (yyVals[0+yyTop]); }
  break;
case 263:
#line 2314 "cs-parser.jay"
  { yyVal = Operator.OpType.Increment; savedOperatorLocation = GetLocation (yyVals[0+yyTop]); }
  break;
case 264:
#line 2315 "cs-parser.jay"
  { yyVal = Operator.OpType.Decrement; savedOperatorLocation = GetLocation (yyVals[0+yyTop]); }
  break;
case 265:
#line 2316 "cs-parser.jay"
  { yyVal = Operator.OpType.True; savedOperatorLocation = GetLocation (yyVals[0+yyTop]); }
  break;
case 266:
#line 2317 "cs-parser.jay"
  { yyVal = Operator.OpType.False; savedOperatorLocation = GetLocation (yyVals[0+yyTop]); }
  break;
case 267:
#line 2319 "cs-parser.jay"
  { yyVal = Operator.OpType.Addition; savedOperatorLocation = GetLocation (yyVals[0+yyTop]); }
  break;
case 268:
#line 2320 "cs-parser.jay"
  { yyVal = Operator.OpType.Subtraction; savedOperatorLocation = GetLocation (yyVals[0+yyTop]); }
  break;
case 269:
#line 2322 "cs-parser.jay"
  { yyVal = Operator.OpType.Multiply; savedOperatorLocation = GetLocation (yyVals[0+yyTop]); }
  break;
case 270:
#line 2323 "cs-parser.jay"
  {  yyVal = Operator.OpType.Division; savedOperatorLocation = GetLocation (yyVals[0+yyTop]); }
  break;
case 271:
#line 2324 "cs-parser.jay"
  { yyVal = Operator.OpType.Modulus; savedOperatorLocation = GetLocation (yyVals[0+yyTop]); }
  break;
case 272:
#line 2325 "cs-parser.jay"
  { yyVal = Operator.OpType.BitwiseAnd; savedOperatorLocation = GetLocation (yyVals[0+yyTop]); }
  break;
case 273:
#line 2326 "cs-parser.jay"
  { yyVal = Operator.OpType.BitwiseOr; savedOperatorLocation = GetLocation (yyVals[0+yyTop]); }
  break;
case 274:
#line 2327 "cs-parser.jay"
  { yyVal = Operator.OpType.ExclusiveOr; savedOperatorLocation = GetLocation (yyVals[0+yyTop]); }
  break;
case 275:
#line 2328 "cs-parser.jay"
  { yyVal = Operator.OpType.LeftShift; savedOperatorLocation = GetLocation (yyVals[0+yyTop]); }
  break;
case 276:
#line 2329 "cs-parser.jay"
  { yyVal = Operator.OpType.RightShift; savedOperatorLocation = GetLocation (yyVals[0+yyTop]); }
  break;
case 277:
#line 2330 "cs-parser.jay"
  { yyVal = Operator.OpType.Equality; savedOperatorLocation = GetLocation (yyVals[0+yyTop]); }
  break;
case 278:
#line 2331 "cs-parser.jay"
  { yyVal = Operator.OpType.Inequality; savedOperatorLocation = GetLocation (yyVals[0+yyTop]); }
  break;
case 279:
#line 2332 "cs-parser.jay"
  { yyVal = Operator.OpType.GreaterThan; savedOperatorLocation = GetLocation (yyVals[0+yyTop]); }
  break;
case 280:
#line 2333 "cs-parser.jay"
  { yyVal = Operator.OpType.LessThan; savedOperatorLocation = GetLocation (yyVals[0+yyTop]); }
  break;
case 281:
#line 2334 "cs-parser.jay"
  { yyVal = Operator.OpType.GreaterThanOrEqual; savedOperatorLocation = GetLocation (yyVals[0+yyTop]); }
  break;
case 282:
#line 2335 "cs-parser.jay"
  { yyVal = Operator.OpType.LessThanOrEqual; savedOperatorLocation = GetLocation (yyVals[0+yyTop]); }
  break;
case 283:
  case_283();
  break;
case 284:
#line 2349 "cs-parser.jay"
  {
		valid_param_mod = ParameterModifierType.DefaultValue;
	  }
  break;
case 285:
  case_285();
  break;
case 286:
#line 2372 "cs-parser.jay"
  {
		valid_param_mod = ParameterModifierType.DefaultValue;
	  }
  break;
case 287:
  case_287();
  break;
case 288:
  case_288();
  break;
case 289:
  case_289();
  break;
case 290:
  case_290();
  break;
case 291:
  case_291();
  break;
case 292:
  case_292();
  break;
case 293:
  case_293();
  break;
case 295:
#line 2496 "cs-parser.jay"
  { current_block = null; yyVal = null; }
  break;
case 298:
#line 2508 "cs-parser.jay"
  {
		++lexer.parsing_block;
	  }
  break;
case 299:
  case_299();
  break;
case 300:
#line 2518 "cs-parser.jay"
  {
		++lexer.parsing_block;
	  }
  break;
case 301:
  case_301();
  break;
case 302:
  case_302();
  break;
case 303:
  case_303();
  break;
case 304:
  case_304();
  break;
case 305:
  case_305();
  break;
case 306:
  case_306();
  break;
case 307:
  case_307();
  break;
case 308:
  case_308();
  break;
case 309:
  case_309();
  break;
case 310:
  case_310();
  break;
case 311:
  case_311();
  break;
case 313:
#line 2645 "cs-parser.jay"
  {
	  	++lexer.parsing_block;
	  }
  break;
case 314:
  case_314();
  break;
case 317:
#line 2663 "cs-parser.jay"
  {
		current_event_field.AddDeclarator ((FieldDeclarator) yyVals[0+yyTop]);
	  }
  break;
case 318:
#line 2667 "cs-parser.jay"
  {
		current_event_field.AddDeclarator ((FieldDeclarator) yyVals[0+yyTop]);
	  }
  break;
case 319:
  case_319();
  break;
case 320:
#line 2680 "cs-parser.jay"
  {
		++lexer.parsing_block;
	  }
  break;
case 321:
  case_321();
  break;
case 322:
  case_322();
  break;
case 323:
#line 2705 "cs-parser.jay"
  {
		yyVal = yyVals[0+yyTop];
	  }
  break;
case 326:
  case_326();
  break;
case 327:
  case_327();
  break;
case 328:
  case_328();
  break;
case 329:
  case_329();
  break;
case 330:
  case_330();
  break;
case 331:
  case_331();
  break;
case 332:
  case_332();
  break;
case 333:
  case_333();
  break;
case 335:
  case_335();
  break;
case 336:
  case_336();
  break;
case 337:
  case_337();
  break;
case 338:
  case_338();
  break;
case 339:
  case_339();
  break;
case 340:
  case_340();
  break;
case 342:
  case_342();
  break;
case 343:
  case_343();
  break;
case 346:
#line 2893 "cs-parser.jay"
  {
		lbag.AppendToMember (current_container, GetLocation (yyVals[0+yyTop]));
	  }
  break;
case 348:
  case_348();
  break;
case 349:
  case_349();
  break;
case 350:
  case_350();
  break;
case 351:
  case_351();
  break;
case 352:
  case_352();
  break;
case 354:
#line 2967 "cs-parser.jay"
  {
		valid_param_mod = ParameterModifierType.Ref | ParameterModifierType.Out | ParameterModifierType.Params | ParameterModifierType.DefaultValue;
	  }
  break;
case 355:
  case_355();
  break;
case 356:
#line 2986 "cs-parser.jay"
  {
		lexer.ConstraintsParsing = false;
	  }
  break;
case 357:
  case_357();
  break;
case 359:
  case_359();
  break;
case 361:
  case_361();
  break;
case 362:
  case_362();
  break;
case 364:
  case_364();
  break;
case 365:
  case_365();
  break;
case 366:
  case_366();
  break;
case 367:
  case_367();
  break;
case 369:
  case_369();
  break;
case 370:
  case_370();
  break;
case 371:
  case_371();
  break;
case 372:
  case_372();
  break;
case 373:
#line 3111 "cs-parser.jay"
  {
		lexer.parsing_generic_declaration = true;
	  }
  break;
case 374:
  case_374();
  break;
case 375:
  case_375();
  break;
case 377:
  case_377();
  break;
case 378:
  case_378();
  break;
case 379:
  case_379();
  break;
case 380:
  case_380();
  break;
case 381:
  case_381();
  break;
case 382:
  case_382();
  break;
case 384:
  case_384();
  break;
case 385:
  case_385();
  break;
case 386:
  case_386();
  break;
case 387:
  case_387();
  break;
case 388:
  case_388();
  break;
case 390:
#line 3236 "cs-parser.jay"
  {
		yyVal = new TypeExpression (compiler.BuiltinTypes.Void, GetLocation (yyVals[0+yyTop]));
	  }
  break;
case 391:
#line 3243 "cs-parser.jay"
  {
		lexer.parsing_generic_declaration = true;
	  }
  break;
case 397:
  case_397();
  break;
case 399:
#line 3273 "cs-parser.jay"
  {
		yyVal = new ComposedCast ((FullNamedExpression) yyVals[-1+yyTop], (ComposedTypeSpecifier) yyVals[0+yyTop]);
	  }
  break;
case 400:
  case_400();
  break;
case 401:
#line 3292 "cs-parser.jay"
  {
		yyVal = new ComposedCast ((ATypeNameExpression) yyVals[-1+yyTop], (ComposedTypeSpecifier) yyVals[0+yyTop]);
	  }
  break;
case 403:
  case_403();
  break;
case 404:
  case_404();
  break;
case 405:
#line 3313 "cs-parser.jay"
  {
		yyVal = new ComposedCast ((FullNamedExpression) yyVals[-1+yyTop], (ComposedTypeSpecifier) yyVals[0+yyTop]);
	  }
  break;
case 406:
#line 3317 "cs-parser.jay"
  {
		yyVal = new ComposedCast (new TypeExpression (compiler.BuiltinTypes.Void, GetLocation (yyVals[-1+yyTop])), (ComposedTypeSpecifier) yyVals[0+yyTop]);
	  }
  break;
case 407:
  case_407();
  break;
case 408:
  case_408();
  break;
case 409:
  case_409();
  break;
case 410:
#line 3351 "cs-parser.jay"
  { yyVal = new TypeExpression (compiler.BuiltinTypes.Object, GetLocation (yyVals[0+yyTop])); }
  break;
case 411:
#line 3352 "cs-parser.jay"
  { yyVal = new TypeExpression (compiler.BuiltinTypes.String, GetLocation (yyVals[0+yyTop])); }
  break;
case 412:
#line 3353 "cs-parser.jay"
  { yyVal = new TypeExpression (compiler.BuiltinTypes.Bool, GetLocation (yyVals[0+yyTop])); }
  break;
case 413:
#line 3354 "cs-parser.jay"
  { yyVal = new TypeExpression (compiler.BuiltinTypes.Decimal, GetLocation (yyVals[0+yyTop])); }
  break;
case 414:
#line 3355 "cs-parser.jay"
  { yyVal = new TypeExpression (compiler.BuiltinTypes.Float, GetLocation (yyVals[0+yyTop])); }
  break;
case 415:
#line 3356 "cs-parser.jay"
  { yyVal = new TypeExpression (compiler.BuiltinTypes.Double, GetLocation (yyVals[0+yyTop])); }
  break;
case 417:
#line 3361 "cs-parser.jay"
  { yyVal = new TypeExpression (compiler.BuiltinTypes.SByte, GetLocation (yyVals[0+yyTop])); }
  break;
case 418:
#line 3362 "cs-parser.jay"
  { yyVal = new TypeExpression (compiler.BuiltinTypes.Byte, GetLocation (yyVals[0+yyTop])); }
  break;
case 419:
#line 3363 "cs-parser.jay"
  { yyVal = new TypeExpression (compiler.BuiltinTypes.Short, GetLocation (yyVals[0+yyTop])); }
  break;
case 420:
#line 3364 "cs-parser.jay"
  { yyVal = new TypeExpression (compiler.BuiltinTypes.UShort, GetLocation (yyVals[0+yyTop])); }
  break;
case 421:
#line 3365 "cs-parser.jay"
  { yyVal = new TypeExpression (compiler.BuiltinTypes.Int, GetLocation (yyVals[0+yyTop])); }
  break;
case 422:
#line 3366 "cs-parser.jay"
  { yyVal = new TypeExpression (compiler.BuiltinTypes.UInt, GetLocation (yyVals[0+yyTop])); }
  break;
case 423:
#line 3367 "cs-parser.jay"
  { yyVal = new TypeExpression (compiler.BuiltinTypes.Long, GetLocation (yyVals[0+yyTop])); }
  break;
case 424:
#line 3368 "cs-parser.jay"
  { yyVal = new TypeExpression (compiler.BuiltinTypes.ULong, GetLocation (yyVals[0+yyTop])); }
  break;
case 425:
#line 3369 "cs-parser.jay"
  { yyVal = new TypeExpression (compiler.BuiltinTypes.Char, GetLocation (yyVals[0+yyTop])); }
  break;
case 448:
  case_448();
  break;
case 452:
#line 3413 "cs-parser.jay"
  { yyVal = new NullLiteral (GetLocation (yyVals[0+yyTop])); }
  break;
case 453:
#line 3417 "cs-parser.jay"
  { yyVal = new BoolLiteral (compiler.BuiltinTypes, true, GetLocation (yyVals[0+yyTop])); }
  break;
case 454:
#line 3418 "cs-parser.jay"
  { yyVal = new BoolLiteral (compiler.BuiltinTypes, false, GetLocation (yyVals[0+yyTop])); }
  break;
case 455:
#line 3425 "cs-parser.jay"
  {
		yyVal = new InterpolatedString ((StringLiteral) yyVals[-2+yyTop], (List<Expression>) yyVals[-1+yyTop], (StringLiteral) yyVals[0+yyTop]);
	  }
  break;
case 456:
#line 3429 "cs-parser.jay"
  {
		yyVal = new InterpolatedString ((StringLiteral) yyVals[0+yyTop], null, null);
	  }
  break;
case 457:
  case_457();
  break;
case 458:
  case_458();
  break;
case 459:
#line 3452 "cs-parser.jay"
  {
		yyVal = new InterpolatedStringInsert ((Expression) yyVals[0+yyTop]);
	  }
  break;
case 460:
  case_460();
  break;
case 461:
#line 3462 "cs-parser.jay"
  {
		lexer.parsing_interpolation_format = true;
	  }
  break;
case 462:
  case_462();
  break;
case 463:
#line 3474 "cs-parser.jay"
  {
		lexer.parsing_interpolation_format = true;
	  }
  break;
case 464:
  case_464();
  break;
case 469:
  case_469();
  break;
case 470:
#line 3516 "cs-parser.jay"
  {
		yyVal = new ParenthesizedExpression ((Expression) yyVals[-1+yyTop], GetLocation (yyVals[-2+yyTop]));
	  }
  break;
case 471:
  case_471();
  break;
case 472:
  case_472();
  break;
case 473:
  case_473();
  break;
case 474:
  case_474();
  break;
case 475:
  case_475();
  break;
case 476:
  case_476();
  break;
case 477:
  case_477();
  break;
case 478:
  case_478();
  break;
case 479:
#line 3577 "cs-parser.jay"
  {
		yyVal = new CompletionMemberAccess ((Expression) yyVals[-2+yyTop], null,GetLocation (yyVals[0+yyTop]));
	  }
  break;
case 480:
  case_480();
  break;
case 481:
#line 3585 "cs-parser.jay"
  {
		yyVal = new CompletionMemberAccess ((Expression) yyVals[-2+yyTop], null, lexer.Location);
	  }
  break;
case 482:
  case_482();
  break;
case 483:
  case_483();
  break;
case 484:
  case_484();
  break;
case 485:
  case_485();
  break;
case 486:
#line 3615 "cs-parser.jay"
  { yyVal = null; }
  break;
case 488:
  case_488();
  break;
case 489:
  case_489();
  break;
case 490:
#line 3637 "cs-parser.jay"
  { yyVal = null; }
  break;
case 491:
#line 3641 "cs-parser.jay"
  {
		yyVal = yyVals[0+yyTop];
	}
  break;
case 492:
  case_492();
  break;
case 493:
  case_493();
  break;
case 494:
  case_494();
  break;
case 495:
  case_495();
  break;
case 496:
  case_496();
  break;
case 497:
#line 3680 "cs-parser.jay"
  {
		yyVal = new CompletionElementInitializer (null, GetLocation (yyVals[0+yyTop]));
	  }
  break;
case 498:
  case_498();
  break;
case 499:
  case_499();
  break;
case 500:
  case_500();
  break;
case 501:
  case_501();
  break;
case 504:
#line 3720 "cs-parser.jay"
  { yyVal = null; }
  break;
case 506:
  case_506();
  break;
case 507:
  case_507();
  break;
case 508:
  case_508();
  break;
case 509:
  case_509();
  break;
case 510:
  case_510();
  break;
case 511:
#line 3774 "cs-parser.jay"
  {
		yyVal = new Argument ((Expression) yyVals[0+yyTop]);
	  }
  break;
case 515:
  case_515();
  break;
case 516:
#line 3792 "cs-parser.jay"
  {
		yyVal = new Argument ((Expression) yyVals[0+yyTop], Argument.AType.Ref);
	  }
  break;
case 517:
  case_517();
  break;
case 518:
#line 3801 "cs-parser.jay"
  {
		yyVal = new Argument ((Expression) yyVals[0+yyTop], Argument.AType.Out);
	  }
  break;
case 519:
  case_519();
  break;
case 520:
  case_520();
  break;
case 521:
  case_521();
  break;
case 522:
  case_522();
  break;
case 523:
  case_523();
  break;
case 525:
  case_525();
  break;
case 526:
  case_526();
  break;
case 527:
  case_527();
  break;
case 528:
  case_528();
  break;
case 529:
  case_529();
  break;
case 530:
  case_530();
  break;
case 531:
  case_531();
  break;
case 532:
  case_532();
  break;
case 533:
#line 3928 "cs-parser.jay"
  {
	  	yyVal = new Argument ((Expression) yyVals[0+yyTop]);
	  }
  break;
case 535:
#line 3936 "cs-parser.jay"
  {
		yyVal = new This (GetLocation (yyVals[0+yyTop]));
	  }
  break;
case 536:
  case_536();
  break;
case 537:
  case_537();
  break;
case 538:
#line 3956 "cs-parser.jay"
  {
		yyVal = new UnaryMutator (UnaryMutator.Mode.PostIncrement, (Expression) yyVals[-1+yyTop], GetLocation (yyVals[0+yyTop]));
	  }
  break;
case 539:
#line 3963 "cs-parser.jay"
  {
		yyVal = new UnaryMutator (UnaryMutator.Mode.PostDecrement, (Expression) yyVals[-1+yyTop], GetLocation (yyVals[0+yyTop]));
	  }
  break;
case 540:
  case_540();
  break;
case 541:
  case_541();
  break;
case 542:
  case_542();
  break;
case 543:
  case_543();
  break;
case 544:
  case_544();
  break;
case 545:
  case_545();
  break;
case 546:
  case_546();
  break;
case 547:
#line 4030 "cs-parser.jay"
  {
		++lexer.parsing_type;
	  }
  break;
case 548:
  case_548();
  break;
case 549:
  case_549();
  break;
case 550:
#line 4052 "cs-parser.jay"
  {
		yyVal = new EmptyCompletion ();
	  }
  break;
case 553:
#line 4061 "cs-parser.jay"
  { yyVal = null; }
  break;
case 555:
  case_555();
  break;
case 556:
  case_556();
  break;
case 557:
#line 4083 "cs-parser.jay"
  {
		yyVal = new EmptyCompletion ();
	  }
  break;
case 558:
#line 4087 "cs-parser.jay"
  {
	  	yyVal = yyVals[-1+yyTop];
	  }
  break;
case 559:
  case_559();
  break;
case 560:
  case_560();
  break;
case 561:
  case_561();
  break;
case 562:
  case_562();
  break;
case 566:
  case_566();
  break;
case 567:
  case_567();
  break;
case 568:
  case_568();
  break;
case 569:
#line 4147 "cs-parser.jay"
  {
		yyVal = 2;
	  }
  break;
case 570:
#line 4151 "cs-parser.jay"
  {
		yyVal = ((int) yyVals[-1+yyTop]) + 1;
	  }
  break;
case 571:
#line 4158 "cs-parser.jay"
  {
		yyVal = null;
	  }
  break;
case 572:
#line 4162 "cs-parser.jay"
  {
		yyVal = yyVals[0+yyTop];
	  }
  break;
case 573:
  case_573();
  break;
case 574:
  case_574();
  break;
case 575:
  case_575();
  break;
case 576:
  case_576();
  break;
case 577:
  case_577();
  break;
case 579:
  case_579();
  break;
case 580:
  case_580();
  break;
case 581:
  case_581();
  break;
case 582:
  case_582();
  break;
case 583:
  case_583();
  break;
case 584:
  case_584();
  break;
case 585:
  case_585();
  break;
case 586:
  case_586();
  break;
case 587:
  case_587();
  break;
case 588:
  case_588();
  break;
case 589:
#line 4295 "cs-parser.jay"
  {
		start_anonymous (false, (ParametersCompiled) yyVals[0+yyTop], false, GetLocation (yyVals[-1+yyTop]));
	  }
  break;
case 590:
  case_590();
  break;
case 591:
#line 4308 "cs-parser.jay"
  {
		start_anonymous (false, (ParametersCompiled) yyVals[0+yyTop], true, GetLocation (yyVals[-2+yyTop]));
	  }
  break;
case 592:
  case_592();
  break;
case 593:
#line 4325 "cs-parser.jay"
  {
		yyVal = ParametersCompiled.Undefined;
	  }
  break;
case 595:
#line 4333 "cs-parser.jay"
  {
	  	valid_param_mod = ParameterModifierType.Ref | ParameterModifierType.Out;
	  }
  break;
case 596:
  case_596();
  break;
case 597:
  case_597();
  break;
case 599:
#line 4359 "cs-parser.jay"
  {
		yyVal = new Unary (Unary.Operator.LogicalNot, (Expression) yyVals[0+yyTop], GetLocation (yyVals[-1+yyTop]));
	  }
  break;
case 600:
#line 4363 "cs-parser.jay"
  {
		yyVal = new Unary (Unary.Operator.OnesComplement, (Expression) yyVals[0+yyTop], GetLocation (yyVals[-1+yyTop]));
	  }
  break;
case 601:
  case_601();
  break;
case 602:
  case_602();
  break;
case 603:
  case_603();
  break;
case 604:
  case_604();
  break;
case 605:
  case_605();
  break;
case 606:
  case_606();
  break;
case 608:
#line 4427 "cs-parser.jay"
  { 
	  	yyVal = new Unary (Unary.Operator.UnaryPlus, (Expression) yyVals[0+yyTop], GetLocation (yyVals[-1+yyTop]));
	  }
  break;
case 609:
#line 4431 "cs-parser.jay"
  { 
		yyVal = new Unary (Unary.Operator.UnaryNegation, (Expression) yyVals[0+yyTop], GetLocation (yyVals[-1+yyTop]));
	  }
  break;
case 610:
#line 4435 "cs-parser.jay"
  {
		yyVal = new UnaryMutator (UnaryMutator.Mode.PreIncrement, (Expression) yyVals[0+yyTop], GetLocation (yyVals[-1+yyTop]));
	  }
  break;
case 611:
#line 4439 "cs-parser.jay"
  {
		yyVal = new UnaryMutator (UnaryMutator.Mode.PreDecrement, (Expression) yyVals[0+yyTop], GetLocation (yyVals[-1+yyTop]));
	  }
  break;
case 612:
#line 4443 "cs-parser.jay"
  {
		yyVal = new Indirection ((Expression) yyVals[0+yyTop], GetLocation (yyVals[-1+yyTop]));
	  }
  break;
case 613:
#line 4447 "cs-parser.jay"
  {
		yyVal = new Unary (Unary.Operator.AddressOf, (Expression) yyVals[0+yyTop], GetLocation (yyVals[-1+yyTop]));
	  }
  break;
case 614:
  case_614();
  break;
case 615:
  case_615();
  break;
case 616:
  case_616();
  break;
case 617:
  case_617();
  break;
case 618:
  case_618();
  break;
case 619:
  case_619();
  break;
case 621:
  case_621();
  break;
case 622:
  case_622();
  break;
case 623:
  case_623();
  break;
case 624:
  case_624();
  break;
case 625:
  case_625();
  break;
case 626:
  case_626();
  break;
case 628:
  case_628();
  break;
case 629:
  case_629();
  break;
case 630:
  case_630();
  break;
case 631:
  case_631();
  break;
case 632:
#line 4555 "cs-parser.jay"
  {
		yyVal = new As ((Expression) yyVals[-2+yyTop], (Expression) yyVals[0+yyTop], GetLocation (yyVals[-1+yyTop]));
	  }
  break;
case 633:
  case_633();
  break;
case 634:
  case_634();
  break;
case 635:
  case_635();
  break;
case 636:
  case_636();
  break;
case 637:
  case_637();
  break;
case 638:
  case_638();
  break;
case 641:
#line 4611 "cs-parser.jay"
  {
		yyVal = new Unary (Unary.Operator.UnaryPlus, (Expression) yyVals[0+yyTop], GetLocation (yyVals[-1+yyTop]));
	  }
  break;
case 642:
#line 4615 "cs-parser.jay"
  {
		yyVal = new Unary (Unary.Operator.UnaryNegation, (Expression) yyVals[0+yyTop], GetLocation (yyVals[-1+yyTop]));
	  }
  break;
case 645:
  case_645();
  break;
case 646:
#line 4626 "cs-parser.jay"
  {
		yyVal = new WildcardPattern (GetLocation (yyVals[0+yyTop]));
	  }
  break;
case 649:
#line 4635 "cs-parser.jay"
  {
		yyVal = new RecursivePattern ((ATypeNameExpression) yyVals[-3+yyTop], (Arguments) yyVals[-1+yyTop], GetLocation (yyVals[-2+yyTop]));
	  }
  break;
case 650:
#line 4642 "cs-parser.jay"
  {
		yyVal = new PropertyPattern ((ATypeNameExpression) yyVals[-3+yyTop], (List<PropertyPatternMember>) yyVals[-1+yyTop], GetLocation (yyVals[-2+yyTop]));
	  }
  break;
case 651:
  case_651();
  break;
case 652:
  case_652();
  break;
case 653:
  case_653();
  break;
case 655:
  case_655();
  break;
case 656:
#line 4684 "cs-parser.jay"
  {
		yyVal = new Arguments (0);
	  }
  break;
case 658:
  case_658();
  break;
case 659:
  case_659();
  break;
case 660:
#line 4710 "cs-parser.jay"
  {
		yyVal = new Argument ((Expression) yyVals[0+yyTop]);
	  }
  break;
case 661:
  case_661();
  break;
case 663:
  case_663();
  break;
case 664:
  case_664();
  break;
case 665:
  case_665();
  break;
case 666:
  case_666();
  break;
case 668:
  case_668();
  break;
case 669:
  case_669();
  break;
case 670:
  case_670();
  break;
case 671:
  case_671();
  break;
case 672:
  case_672();
  break;
case 673:
  case_673();
  break;
case 674:
  case_674();
  break;
case 675:
  case_675();
  break;
case 677:
  case_677();
  break;
case 678:
  case_678();
  break;
case 679:
  case_679();
  break;
case 680:
  case_680();
  break;
case 682:
  case_682();
  break;
case 683:
  case_683();
  break;
case 685:
  case_685();
  break;
case 686:
  case_686();
  break;
case 688:
  case_688();
  break;
case 689:
  case_689();
  break;
case 691:
  case_691();
  break;
case 692:
  case_692();
  break;
case 694:
  case_694();
  break;
case 695:
  case_695();
  break;
case 697:
  case_697();
  break;
case 699:
  case_699();
  break;
case 700:
  case_700();
  break;
case 701:
  case_701();
  break;
case 702:
  case_702();
  break;
case 703:
  case_703();
  break;
case 704:
  case_704();
  break;
case 705:
  case_705();
  break;
case 706:
  case_706();
  break;
case 707:
  case_707();
  break;
case 708:
  case_708();
  break;
case 709:
  case_709();
  break;
case 710:
  case_710();
  break;
case 711:
  case_711();
  break;
case 712:
  case_712();
  break;
case 713:
  case_713();
  break;
case 714:
  case_714();
  break;
case 715:
  case_715();
  break;
case 716:
  case_716();
  break;
case 717:
  case_717();
  break;
case 718:
  case_718();
  break;
case 719:
  case_719();
  break;
case 720:
#line 5055 "cs-parser.jay"
  { yyVal = ParametersCompiled.EmptyReadOnlyParameters; }
  break;
case 721:
  case_721();
  break;
case 722:
#line 5066 "cs-parser.jay"
  {
		start_block (Location.Null);
	  }
  break;
case 723:
  case_723();
  break;
case 725:
  case_725();
  break;
case 727:
  case_727();
  break;
case 728:
  case_728();
  break;
case 729:
  case_729();
  break;
case 730:
  case_730();
  break;
case 731:
  case_731();
  break;
case 732:
  case_732();
  break;
case 733:
  case_733();
  break;
case 734:
#line 5133 "cs-parser.jay"
  {
	  	valid_param_mod = ParameterModifierType.Ref | ParameterModifierType.Out;
	  }
  break;
case 735:
  case_735();
  break;
case 736:
  case_736();
  break;
case 737:
#line 5147 "cs-parser.jay"
  {
	  	valid_param_mod = ParameterModifierType.Ref | ParameterModifierType.Out;	  
	  }
  break;
case 738:
  case_738();
  break;
case 739:
  case_739();
  break;
case 745:
#line 5172 "cs-parser.jay"
  {
		yyVal = new ArglistAccess (GetLocation (yyVals[0+yyTop]));
	  }
  break;
case 746:
  case_746();
  break;
case 747:
  case_747();
  break;
case 748:
  case_748();
  break;
case 750:
#line 5201 "cs-parser.jay"
  {
		yyVal = new BooleanExpression ((Expression) yyVals[0+yyTop]);
	  }
  break;
case 751:
#line 5208 "cs-parser.jay"
  {
	  	yyVal = null;
	  }
  break;
case 753:
  case_753();
  break;
case 754:
#line 5229 "cs-parser.jay"
  {
	  	yyVal = null;
	  }
  break;
case 755:
#line 5233 "cs-parser.jay"
  {
		yyVal = null;
	  }
  break;
case 756:
#line 5237 "cs-parser.jay"
  {
		yyVal = yyVals[0+yyTop];
	  }
  break;
case 757:
#line 5241 "cs-parser.jay"
  {
		yyVal = yyVals[-1+yyTop];
	  }
  break;
case 758:
  case_758();
  break;
case 759:
  case_759();
  break;
case 760:
#line 5266 "cs-parser.jay"
  {
	  }
  break;
case 761:
  case_761();
  break;
case 762:
  case_762();
  break;
case 763:
  case_763();
  break;
case 764:
  case_764();
  break;
case 765:
#line 5318 "cs-parser.jay"
  { yyVal = null; }
  break;
case 766:
#line 5320 "cs-parser.jay"
  { yyVal = yyVals[0+yyTop]; StoreModifierLocation (Modifiers.PARTIAL, GetLocation (yyVals[0+yyTop])); }
  break;
case 767:
  case_767();
  break;
case 768:
#line 5333 "cs-parser.jay"
  {
		lexer.parsing_modifiers = false;		
	  }
  break;
case 770:
  case_770();
  break;
case 771:
  case_771();
  break;
case 772:
  case_772();
  break;
case 773:
  case_773();
  break;
case 774:
  case_774();
  break;
case 775:
  case_775();
  break;
case 776:
  case_776();
  break;
case 777:
  case_777();
  break;
case 778:
  case_778();
  break;
case 779:
  case_779();
  break;
case 780:
  case_780();
  break;
case 781:
  case_781();
  break;
case 782:
  case_782();
  break;
case 783:
  case_783();
  break;
case 784:
  case_784();
  break;
case 785:
  case_785();
  break;
case 788:
  case_788();
  break;
case 789:
  case_789();
  break;
case 791:
#line 5463 "cs-parser.jay"
  {
		yyVal = yyVals[0+yyTop];
	  }
  break;
case 792:
  case_792();
  break;
case 793:
  case_793();
  break;
case 794:
  case_794();
  break;
case 795:
  case_795();
  break;
case 796:
  case_796();
  break;
case 797:
  case_797();
  break;
case 798:
  case_798();
  break;
case 799:
  case_799();
  break;
case 800:
#line 5556 "cs-parser.jay"
  {
		yyVal = new SpecialContraintExpr (SpecialConstraint.Class, GetLocation (yyVals[0+yyTop]));
	  }
  break;
case 801:
#line 5560 "cs-parser.jay"
  {
		yyVal = new SpecialContraintExpr (SpecialConstraint.Struct, GetLocation (yyVals[0+yyTop]));
	  }
  break;
case 802:
#line 5567 "cs-parser.jay"
  {
		yyVal = null;
	  }
  break;
case 803:
  case_803();
  break;
case 804:
  case_804();
  break;
case 805:
  case_805();
  break;
case 806:
  case_806();
  break;
case 807:
#line 5612 "cs-parser.jay"
  {
		yyVal = yyVals[0+yyTop];
	  }
  break;
case 808:
  case_808();
  break;
case 809:
  case_809();
  break;
case 810:
  case_810();
  break;
case 811:
  case_811();
  break;
case 812:
  case_812();
  break;
case 813:
  case_813();
  break;
case 814:
  case_814();
  break;
case 819:
#line 5674 "cs-parser.jay"
  {
		current_block.AddStatement ((Statement) yyVals[0+yyTop]);
	  }
  break;
case 820:
#line 5678 "cs-parser.jay"
  {
		current_block.AddStatement ((Statement) yyVals[0+yyTop]);
	  }
  break;
case 822:
  case_822();
  break;
case 823:
  case_823();
  break;
case 826:
#line 5712 "cs-parser.jay"
  {
		current_block.AddStatement ((Statement) yyVals[0+yyTop]);
	  }
  break;
case 827:
#line 5716 "cs-parser.jay"
  {
		current_block.AddStatement ((Statement) yyVals[0+yyTop]);
	  }
  break;
case 856:
  case_856();
  break;
case 857:
  case_857();
  break;
case 858:
  case_858();
  break;
case 859:
  case_859();
  break;
case 860:
  case_860();
  break;
case 863:
  case_863();
  break;
case 864:
  case_864();
  break;
case 865:
  case_865();
  break;
case 869:
  case_869();
  break;
case 870:
#line 5857 "cs-parser.jay"
  {
		yyVal = ComposedTypeSpecifier.CreatePointer (GetLocation (yyVals[0+yyTop]));
	  }
  break;
case 872:
#line 5865 "cs-parser.jay"
  {
	  	yyVal = Error_AwaitAsIdentifier (yyVals[0+yyTop]);
	  }
  break;
case 873:
  case_873();
  break;
case 874:
  case_874();
  break;
case 875:
  case_875();
  break;
case 876:
  case_876();
  break;
case 878:
  case_878();
  break;
case 880:
  case_880();
  break;
case 881:
  case_881();
  break;
case 885:
  case_885();
  break;
case 888:
  case_888();
  break;
case 889:
  case_889();
  break;
case 890:
#line 5979 "cs-parser.jay"
  {
		report.Error (145, lexer.Location, "A const field requires a value to be provided");
	  }
  break;
case 891:
  case_891();
  break;
case 896:
  case_896();
  break;
case 898:
  case_898();
  break;
case 899:
  case_899();
  break;
case 900:
  case_900();
  break;
case 901:
#line 6029 "cs-parser.jay"
  { yyVal = yyVals[-1+yyTop]; }
  break;
case 902:
  case_902();
  break;
case 903:
#line 6039 "cs-parser.jay"
  { yyVal = yyVals[-1+yyTop]; }
  break;
case 904:
#line 6040 "cs-parser.jay"
  { yyVal = yyVals[-1+yyTop]; }
  break;
case 905:
  case_905();
  break;
case 906:
  case_906();
  break;
case 907:
  case_907();
  break;
case 910:
  case_910();
  break;
case 911:
  case_911();
  break;
case 912:
  case_912();
  break;
case 913:
#line 6112 "cs-parser.jay"
  {
		start_block (GetLocation (yyVals[0+yyTop]));
	  }
  break;
case 914:
  case_914();
  break;
case 915:
  case_915();
  break;
case 916:
#line 6132 "cs-parser.jay"
  {
		report.Warning (1522, 1, current_block.StartLocation, "Empty switch block"); 
	  }
  break;
case 920:
#line 6142 "cs-parser.jay"
  {
		Error_SyntaxError (yyToken);
	  }
  break;
case 922:
  case_922();
  break;
case 923:
#line 6159 "cs-parser.jay"
  {
		current_block.AddStatement ((Statement) yyVals[0+yyTop]);
	  }
  break;
case 924:
  case_924();
  break;
case 925:
  case_925();
  break;
case 926:
#line 6188 "cs-parser.jay"
  {
		yyVal = new SwitchLabel (null, GetLocation (yyVals[0+yyTop]));
	  }
  break;
case 931:
  case_931();
  break;
case 932:
  case_932();
  break;
case 933:
  case_933();
  break;
case 934:
  case_934();
  break;
case 935:
  case_935();
  break;
case 936:
  case_936();
  break;
case 937:
#line 6249 "cs-parser.jay"
  {
		yyVal = yyVals[0+yyTop];
	  }
  break;
case 938:
  case_938();
  break;
case 939:
#line 6264 "cs-parser.jay"
  {
		yyVal = yyVals[0+yyTop];
	  }
  break;
case 940:
  case_940();
  break;
case 941:
  case_941();
  break;
case 942:
#line 6285 "cs-parser.jay"
  {
		yyVal = yyVals[0+yyTop];
	  }
  break;
case 943:
  case_943();
  break;
case 944:
  case_944();
  break;
case 945:
  case_945();
  break;
case 946:
#line 6319 "cs-parser.jay"
  { yyVal = new EmptyStatement (lexer.Location); }
  break;
case 948:
  case_948();
  break;
case 949:
  case_949();
  break;
case 951:
#line 6343 "cs-parser.jay"
  { yyVal = null; }
  break;
case 953:
#line 6348 "cs-parser.jay"
  { yyVal = new EmptyStatement (lexer.Location); }
  break;
case 957:
  case_957();
  break;
case 958:
  case_958();
  break;
case 959:
  case_959();
  break;
case 960:
  case_960();
  break;
case 961:
  case_961();
  break;
case 962:
  case_962();
  break;
case 963:
  case_963();
  break;
case 970:
  case_970();
  break;
case 971:
  case_971();
  break;
case 972:
  case_972();
  break;
case 973:
  case_973();
  break;
case 974:
  case_974();
  break;
case 975:
  case_975();
  break;
case 976:
  case_976();
  break;
case 977:
  case_977();
  break;
case 978:
  case_978();
  break;
case 979:
  case_979();
  break;
case 980:
  case_980();
  break;
case 981:
  case_981();
  break;
case 982:
  case_982();
  break;
case 983:
  case_983();
  break;
case 984:
  case_984();
  break;
case 987:
#line 6594 "cs-parser.jay"
  {
		yyVal = new TryCatch ((Block) yyVals[-1+yyTop], (List<Catch>) yyVals[0+yyTop], GetLocation (yyVals[-2+yyTop]), false);
	  }
  break;
case 988:
  case_988();
  break;
case 989:
  case_989();
  break;
case 990:
  case_990();
  break;
case 991:
  case_991();
  break;
case 992:
  case_992();
  break;
case 995:
  case_995();
  break;
case 996:
  case_996();
  break;
case 997:
  case_997();
  break;
case 998:
  case_998();
  break;
case 999:
#line 6685 "cs-parser.jay"
  {
		yyVal = yyVals[-1+yyTop];
	  }
  break;
case 1000:
  case_1000();
  break;
case 1001:
#line 6697 "cs-parser.jay"
  {
		lexer.parsing_catch_when = false;
	  }
  break;
case 1002:
#line 6701 "cs-parser.jay"
  {
		lexer.parsing_catch_when = false;
	  }
  break;
case 1003:
  case_1003();
  break;
case 1004:
#line 6716 "cs-parser.jay"
  {
		yyVal = new Checked ((Block) yyVals[0+yyTop], GetLocation (yyVals[-1+yyTop]));
	  }
  break;
case 1005:
#line 6723 "cs-parser.jay"
  {
		yyVal = new Unchecked ((Block) yyVals[0+yyTop], GetLocation (yyVals[-1+yyTop]));
	  }
  break;
case 1006:
  case_1006();
  break;
case 1007:
#line 6733 "cs-parser.jay"
  {
		yyVal = new Unsafe ((Block) yyVals[0+yyTop], GetLocation (yyVals[-2+yyTop]));
	  }
  break;
case 1008:
  case_1008();
  break;
case 1009:
  case_1009();
  break;
case 1010:
  case_1010();
  break;
case 1011:
  case_1011();
  break;
case 1012:
  case_1012();
  break;
case 1013:
  case_1013();
  break;
case 1014:
  case_1014();
  break;
case 1015:
  case_1015();
  break;
case 1016:
  case_1016();
  break;
case 1017:
  case_1017();
  break;
case 1019:
  case_1019();
  break;
case 1020:
#line 6838 "cs-parser.jay"
  {
		Error_MissingInitializer (lexer.Location);
	  }
  break;
case 1021:
  case_1021();
  break;
case 1022:
  case_1022();
  break;
case 1023:
  case_1023();
  break;
case 1024:
  case_1024();
  break;
case 1025:
  case_1025();
  break;
case 1026:
  case_1026();
  break;
case 1027:
  case_1027();
  break;
case 1028:
  case_1028();
  break;
case 1029:
  case_1029();
  break;
case 1030:
#line 6943 "cs-parser.jay"
  {
		current_block = new Linq.QueryBlock (current_block, lexer.Location);
	  }
  break;
case 1031:
  case_1031();
  break;
case 1032:
#line 6958 "cs-parser.jay"
  {
		current_block = new Linq.QueryBlock (current_block, lexer.Location);
	  }
  break;
case 1033:
  case_1033();
  break;
case 1034:
  case_1034();
  break;
case 1035:
  case_1035();
  break;
case 1037:
  case_1037();
  break;
case 1038:
  case_1038();
  break;
case 1039:
#line 7022 "cs-parser.jay"
  {
	  	current_block = new Linq.QueryBlock (current_block, lexer.Location);
	  }
  break;
case 1040:
  case_1040();
  break;
case 1041:
  case_1041();
  break;
case 1042:
  case_1042();
  break;
case 1043:
  case_1043();
  break;
case 1044:
#line 7061 "cs-parser.jay"
  {
	  	yyVal = new object[] { yyVals[0+yyTop], GetLocation (yyVals[-1+yyTop]) };
	  }
  break;
case 1045:
  case_1045();
  break;
case 1047:
  case_1047();
  break;
case 1053:
#line 7090 "cs-parser.jay"
  {
	  	current_block = new Linq.QueryBlock (current_block, lexer.Location);
	  }
  break;
case 1054:
  case_1054();
  break;
case 1055:
#line 7109 "cs-parser.jay"
  {
	  	current_block = new Linq.QueryBlock (current_block, lexer.Location);
	  }
  break;
case 1056:
  case_1056();
  break;
case 1057:
  case_1057();
  break;
case 1058:
  case_1058();
  break;
case 1059:
  case_1059();
  break;
case 1060:
  case_1060();
  break;
case 1061:
  case_1061();
  break;
case 1062:
  case_1062();
  break;
case 1063:
  case_1063();
  break;
case 1064:
  case_1064();
  break;
case 1066:
  case_1066();
  break;
case 1067:
  case_1067();
  break;
case 1068:
  case_1068();
  break;
case 1070:
  case_1070();
  break;
case 1071:
  case_1071();
  break;
case 1073:
  case_1073();
  break;
case 1074:
  case_1074();
  break;
case 1075:
#line 7310 "cs-parser.jay"
  {
		yyVal = new Linq.OrderByAscending ((Linq.QueryBlock) current_block, (Expression)yyVals[0+yyTop]);	
	  }
  break;
case 1076:
  case_1076();
  break;
case 1077:
  case_1077();
  break;
case 1078:
#line 7327 "cs-parser.jay"
  {
		yyVal = new Linq.ThenByAscending ((Linq.QueryBlock) current_block, (Expression)yyVals[0+yyTop]);	
	  }
  break;
case 1079:
  case_1079();
  break;
case 1080:
  case_1080();
  break;
case 1082:
  case_1082();
  break;
case 1083:
  case_1083();
  break;
case 1086:
  case_1086();
  break;
case 1087:
  case_1087();
  break;
case 1095:
#line 7452 "cs-parser.jay"
  {
		module.DocumentationBuilder.ParsedName = (MemberName) yyVals[0+yyTop];
	  }
  break;
case 1096:
#line 7459 "cs-parser.jay"
  {
		module.DocumentationBuilder.ParsedParameters = (List<DocumentationParameter>)yyVals[0+yyTop];
	  }
  break;
case 1097:
  case_1097();
  break;
case 1098:
  case_1098();
  break;
case 1099:
  case_1099();
  break;
case 1100:
#line 7482 "cs-parser.jay"
  {
		yyVal = new MemberName ((MemberName) yyVals[-2+yyTop], MemberCache.IndexerNameAlias, Location.Null);
	  }
  break;
case 1101:
#line 7486 "cs-parser.jay"
  {
		valid_param_mod = ParameterModifierType.Ref | ParameterModifierType.Out;
	  }
  break;
case 1102:
  case_1102();
  break;
case 1103:
  case_1103();
  break;
case 1104:
  case_1104();
  break;
case 1105:
  case_1105();
  break;
case 1107:
#line 7522 "cs-parser.jay"
  {
		yyVal = new MemberName (((MemberName) yyVals[-2+yyTop]), (MemberName) yyVals[0+yyTop]);
	  }
  break;
case 1109:
#line 7530 "cs-parser.jay"
  {
		valid_param_mod = ParameterModifierType.Ref | ParameterModifierType.Out;
	  }
  break;
case 1110:
#line 7534 "cs-parser.jay"
  {
		yyVal = yyVals[-1+yyTop];
	  }
  break;
case 1111:
#line 7541 "cs-parser.jay"
  {
		yyVal = new List<DocumentationParameter> (0);
	  }
  break;
case 1113:
  case_1113();
  break;
case 1114:
  case_1114();
  break;
case 1115:
  case_1115();
  break;
#line default
        }
        yyTop -= yyLen[yyN];
        yyState = yyStates[yyTop];
        int yyM = yyLhs[yyN];
        if (yyState == 0 && yyM == 0) {
//t          if (debug != null) debug.shift(0, yyFinal);
          yyState = yyFinal;
          if (yyToken < 0) {
            yyToken = yyLex.advance() ? yyLex.token() : 0;
//t            if (debug != null)
//t               debug.lex(yyState, yyToken,yyname(yyToken), yyLex.value());
          }
          if (yyToken == 0) {
//t            if (debug != null) debug.accept(yyVal);
            return yyVal;
          }
          goto continue_yyLoop;
        }
        if (((yyN = yyGindex[yyM]) != 0) && ((yyN += yyState) >= 0)
            && (yyN < yyTable.Length) && (yyCheck[yyN] == yyState))
          yyState = yyTable[yyN];
        else
          yyState = yyDgoto[yyM];
//t        if (debug != null) debug.shift(yyStates[yyTop], yyState);
	 goto continue_yyLoop;
      continue_yyDiscarded: ;	// implements the named-loop continue: 'continue yyDiscarded'
      }
    continue_yyLoop: ;		// implements the named-loop continue: 'continue yyLoop'
    }
  }
			public override object Visit (Mono.CSharpPs.ParenthesizedExpression parenthesizedExpression)
			{
				var result = new ParenthesizedExpression ();
				var location = LocationsBag.GetLocations (parenthesizedExpression);
				if (location != null)
					result.AddChild (new CSharpTokenNode (Convert (location [0]), Roles.LPar), Roles.LPar);
				if (parenthesizedExpression.Expr != null)
					result.AddChild ((Expression)parenthesizedExpression.Expr.Accept (this), Roles.Expression);
				if (location != null && location.Count > 1)
					result.AddChild (new CSharpTokenNode (Convert (location [1]), Roles.RPar), Roles.RPar);
				return result;
			}
Example #54
0
void case_521()
#line 3816 "cs-parser.jay"
{
		yyVal = new ParenthesizedExpression ((Expression) yyVals[-1+yyTop], GetLocation (yyVals[-2+yyTop]));
		lbag.AddLocation (yyVal, GetLocation (yyVals[-2+yyTop]), GetLocation (yyVals[0+yyTop]));
	  }
 protected internal virtual void PostWalk(ParenthesizedExpression node) { }
		List<MethodDeclaration> CreateEqualsOverrides(IType currentClass)
		{
			List<MethodDeclaration> methods = new List<MethodDeclaration>();
			
			AstType boolReference = ConvertType(KnownTypeCode.Boolean);
			AstType objectReference = ConvertType(KnownTypeCode.Object);
			
			MethodDeclaration method = new MethodDeclaration {
				Name = "Equals",
				Modifiers = Modifiers.Public | Modifiers.Override,
				ReturnType = boolReference
			};
			method.Parameters.Add(new ParameterDeclaration(objectReference, "obj"));
			method.Body = new BlockStatement();
			
			AstType currentType = ConvertType(currentClass);
			Expression expr = null;
			
			if (currentClass.Kind == TypeKind.Struct) {
				// return obj is CurrentType && Equals((CurrentType)obj);
				expr = new IsExpression() {
					Expression = new IdentifierExpression("obj"),
					Type = currentType.Clone()
				};
				expr = new ParenthesizedExpression(expr);
				expr = new BinaryOperatorExpression(
					expr, BinaryOperatorType.ConditionalAnd,
					new InvocationExpression(
						new IdentifierExpression("Equals"),
						new List<Expression> {
							new CastExpression(currentType.Clone(), new IdentifierExpression("obj"))
						}));
				method.Body.Add(new ReturnStatement(expr));
				
				methods.Add(method);
				
				// IEquatable implementation:
				method = new MethodDeclaration {
					Name = "Equals",
					Modifiers = Modifiers.Public,
					ReturnType = boolReference.Clone()
				};
				method.Parameters.Add(new ParameterDeclaration(currentType, "other"));
				method.Body = new BlockStatement();
			} else {
				method.Body.Add(new VariableDeclarationStatement(
					currentType.Clone(),
					"other",
					new IdentifierExpression("obj").CastAs(currentType.Clone())));
				method.Body.Add(new IfElseStatement(
					new BinaryOperatorExpression(new IdentifierExpression("other"), BinaryOperatorType.Equality, new PrimitiveExpression(null, "null")),
					new ReturnStatement(new PrimitiveExpression(false, "false"))));
			}
			
			expr = null;
			foreach (IField field in currentClass.GetFields()) {
				if (field.IsStatic) continue;
				
				if (expr == null) {
					expr = TestEquality("other", field);
				} else {
					expr = new BinaryOperatorExpression(expr, BinaryOperatorType.ConditionalAnd,
					                                    TestEquality("other", field));
				}
			}
			
			foreach (IProperty property in currentClass.GetProperties()) {
				if (property.IsStatic || !property.IsAutoImplemented()) continue;
				if (expr == null) {
					expr = TestEquality("other", property);
				} else {
					expr = new BinaryOperatorExpression(expr, BinaryOperatorType.ConditionalAnd,
					                                    TestEquality("other", property));
				}
			}
			
			method.Body.Add(new ReturnStatement(expr ?? new PrimitiveExpression(true, "true")));
			
			methods.Add(method);
			
			return methods;
		}
		public virtual void VisitParenthesizedExpression (ParenthesizedExpression parenthesizedExpression)
		{
			VisitChildren (parenthesizedExpression);
		}
Example #58
0
		public override void VisitParenthesizedExpression(ParenthesizedExpression parenthesizedExpression)
		{
			ForceSpacesAfter(parenthesizedExpression.LParToken, policy.SpacesWithinParentheses);
			ForceSpacesBefore(parenthesizedExpression.RParToken, policy.SpacesWithinParentheses);
			base.VisitParenthesizedExpression(parenthesizedExpression);
		}
Example #59
0
		public void VisitParenthesizedExpression(ParenthesizedExpression parenthesizedExpression)
		{
			StartNode(parenthesizedExpression);
			LPar();
			Space(policy.SpacesWithinParentheses);
			parenthesizedExpression.Expression.AcceptVisitor(this);
			Space(policy.SpacesWithinParentheses);
			RPar();
			EndNode(parenthesizedExpression);
		}
Example #60
0
		public virtual object Visit (ParenthesizedExpression parenthesizedExpression)
		{
			return null;
		}