コード例 #1
0
        public override IExpression VisitPrefixUnaryExpression(PrefixUnaryExpressionSyntax node)
        {
            var            o       = this.semanticModel.GetTypeInfo(node);
            var            t       = this.mapper.Map(o.Type);
            var            operand = this.Visit(node.Operand);
            UnaryOperation op      = null;

            switch (node.Kind)
            {
            case SyntaxKind.BitwiseNotExpression:
                op = new OnesComplement();
                break;

            case SyntaxKind.UnaryMinusExpression:
                op      = new UnaryNegation();
                op.Type = operand.Type;
                break;

            case SyntaxKind.PreDecrementExpression:
            case SyntaxKind.PreIncrementExpression:
                BinaryOperation bo;
                if (node.OperatorToken.Kind == SyntaxKind.MinusMinusToken)
                {
                    bo = new Subtraction();
                }
                else
                {
                    bo = new Addition();
                }
                object one = GetConstantOneOfMatchingTypeForIncrementDecrement(operand.Type.ResolvedType); // REVIEW: Do we really need to resolve?
                bo.LeftOperand  = operand;
                bo.RightOperand = new CompileTimeConstant()
                {
                    Type = operand.Type, Value = one,
                };
                bo.Type = operand.Type;
                var assign = new Assignment()
                {
                    Source = bo,
                    Target = Helper.MakeTargetExpression(operand),
                    Type   = operand.Type,
                };
                return(assign);

            case SyntaxKind.LogicalNotExpression:
                op = new LogicalNot();
                break;

            default:
                var typeName = node.GetType().ToString();
                var msg      = String.Format("Was unable to convert a {0} node to CCI because the kind '{1}' wasn't handled",
                                             typeName, node.Kind.ToString());
                throw new ConverterException(msg);
            }
            op.Operand = operand;
            return(op);
        }