コード例 #1
0
        private static ITranslationUnit BuildUnaryExpressionTranslationUnit(PostfixUnaryExpressionSyntax expression, SemanticModel semanticModel)
        {
            OperatorToken token = OperatorToken.Undefined;

            switch (expression.Kind())
            {
            case SyntaxKind.PostIncrementExpression:
                token = OperatorToken.Increment;
                break;

            case SyntaxKind.PostDecrementExpression:
                token = OperatorToken.Decrement;
                break;
            }

            if (token == OperatorToken.Undefined)
            {
                throw new InvalidOperationException("Unary operator could not be detected!");
            }

            UnaryExpression  unaryExpressionHelper = new UnaryExpression(expression, semanticModel);
            ITranslationUnit operand = new ExpressionTranslationUnitBuilder(unaryExpressionHelper.Operand, semanticModel).Build();

            return(UnaryExpressionTranslationUnit.Create(operand, token, UnaryExpressionTranslationUnit.UnaryPosition.Postfix));
        }
コード例 #2
0
        private static ITranslationUnit BuildObjectCreationExpressionTranslationUnit(ObjectCreationExpressionSyntax expression, SemanticModel semanticModel)
        {
            var helper = new ObjectCreationExpression(expression, semanticModel);

            var translationUnit = ObjectCreateExpressionTranslationUnit.Create(
                new ExpressionTranslationUnitBuilder(helper.Expression, semanticModel).Build());

            foreach (var argument in helper.Arguments)
            {
                var argumentTranslationUnit = new ExpressionTranslationUnitBuilder(argument.Expression, semanticModel).Build();
                translationUnit.AddArgument(argumentTranslationUnit);
            }

            return(translationUnit);
        }
コード例 #3
0
        private static ITranslationUnit BuildObjectCreationExpressionTranslationUnit(ObjectCreationExpressionSyntax expression, SemanticModel semanticModel)
        {
            ObjectCreationExpression helper = new ObjectCreationExpression(expression, semanticModel);

            var translationUnit = ObjectCreationExpressionTranslationUnit.Create(
                TypeIdentifierTranslationUnit.Create(helper.Type.FullName.MapType().MappedType.Translate())); // TODO: Create factory for TypeReference

            foreach (var argument in helper.Arguments)
            {
                var argumentTranslationUnit = new ExpressionTranslationUnitBuilder(argument.Expression, semanticModel).Build();

                translationUnit.AddArgument(argumentTranslationUnit);
            }

            return(translationUnit);
        }
コード例 #4
0
        private static ITranslationUnit BuildArrayCreationExpressionTranslationUnit(ArrayCreationExpressionSyntax expression, SemanticModel semanticModel)
        {
            var helper = new ArrayCreationExpression(expression, semanticModel);

            var translationUnit = ArrayCreateExpressionTranslationUnit.Create(
                new ExpressionTranslationUnitBuilder(helper.Expression, semanticModel).Build());

            if (helper.Initializer != null)
            {
                foreach (var argument in helper.Initializer.Expressions)
                {
                    var argumentTranslationUnit = new ExpressionTranslationUnitBuilder(argument, semanticModel).Build();

                    translationUnit.AddArgument(argumentTranslationUnit);
                }
            }

            return(translationUnit);
        }
コード例 #5
0
        private static ITranslationUnit BuildBinaryExpressionTranslationUnit(BinaryExpressionSyntax expression, SemanticModel semanticModel)
        {
            OperatorToken token = OperatorToken.Undefined;

            switch (expression.Kind())
            {
            case SyntaxKind.AddExpression:
                token = OperatorToken.Addition;
                break;

            case SyntaxKind.MultiplyExpression:
                token = OperatorToken.Multiplication;
                break;

            case SyntaxKind.DivideExpression:
                token = OperatorToken.Divide;
                break;

            case SyntaxKind.SubtractExpression:
                token = OperatorToken.Subtraction;
                break;

            case SyntaxKind.EqualsExpression:
                token = OperatorToken.LogicalEquals;
                break;

            case SyntaxKind.NotEqualsExpression:
                token = OperatorToken.NotEquals;
                break;
            }

            if (token == OperatorToken.Undefined)
            {
                throw new InvalidOperationException("Binary operator could not be detected!");
            }

            BinaryExpression binaryExpressionHelper = new BinaryExpression(expression, semanticModel);
            ITranslationUnit leftHandOperand        = new ExpressionTranslationUnitBuilder(binaryExpressionHelper.LeftHandOperand, semanticModel).Build();
            ITranslationUnit rightHandOperand       = new ExpressionTranslationUnitBuilder(binaryExpressionHelper.RightHandOperand, semanticModel).Build();

            return(BinaryExpressionTranslationUnit.Create(leftHandOperand, rightHandOperand, token));
        }