Package com.strobel.decompiler.semantics

Examples of com.strobel.decompiler.semantics.ResolveResult


    private boolean anyIsString(final List<Expression> expressions) {
        final JavaResolver resolver = new JavaResolver(context);

        for (int i = 0; i < expressions.size(); i++) {
            final ResolveResult result = resolver.apply(expressions.get(i));

            if (result != null &&
                result.getType() != null &&
                CommonTypeReferences.String.isEquivalentTo(result.getType())) {

                return true;
            }
        }
View Full Code Here


    @Override
    public Void visitCastExpression(final CastExpression node, final Void data) {
        super.visitCastExpression(node, data);

        final Expression operand = node.getExpression();
        final ResolveResult targetResult = _resolver.apply(node.getType());

        if (targetResult == null || targetResult.getType() == null) {
            return null;
        }

        final ResolveResult valueResult = _resolver.apply(operand);

        if (valueResult == null || valueResult.getType() == null) {
            return null;
        }

        final ConversionType conversionType = MetadataHelper.getConversionType(targetResult.getType(), valueResult.getType());

        if (conversionType == ConversionType.NONE) {
            addCastForAssignment(node.getType(), node.getExpression());
        }
View Full Code Here

        if (astBuilder == null) {
            return null;
        }

        final ResolveResult valueResult = _resolver.apply(node.getTarget());

        TypeReference declaringType = member.getDeclaringType();

        if (valueResult != null &&
            valueResult.getType() != null) {

            if (MetadataHelper.isAssignableFrom(declaringType, valueResult.getType())) {
                return null;
            }

            if (valueResult.getType().isGenericType() &&
                (declaringType.isGenericType() ||
                 MetadataHelper.isRawType(declaringType))) {

                final TypeReference asSuper = MetadataHelper.asSuper(declaringType, valueResult.getType());

                if (asSuper != null) {
                    declaringType = asSuper;
                }
            }
View Full Code Here

        return null;
    }

    private boolean addCastForAssignment(final AstNode left, final Expression right) {
        final ResolveResult targetResult = _resolver.apply(left);

        if (targetResult == null || targetResult.getType() == null) {
            return false;
        }

        final ResolveResult valueResult = _resolver.apply(right);

        if (valueResult == null || valueResult.getType() == null) {
            return false;
        }

        final TypeReference unboxedTargetType = MetadataHelper.getUnderlyingPrimitiveTypeOrSelf(targetResult.getType());
        final TypeReference unboxedValueType = MetadataHelper.getUnderlyingPrimitiveTypeOrSelf(valueResult.getType());

        if (right instanceof PrimitiveExpression &&
            unboxedTargetType.getSimpleType().isIntegral() &&
            unboxedTargetType.getSimpleType().isSubWordOrInt32() &&
            MetadataHelper.isAssignableFrom(BuiltinTypes.Integer, unboxedValueType, false)) {

            return false;
        }

        final ConversionType conversionType = MetadataHelper.getConversionType(targetResult.getType(), valueResult.getType());

        AstNode replacement = null;

        if (conversionType == ConversionType.EXPLICIT || conversionType == ConversionType.EXPLICIT_TO_UNBOXED) {
            final AstBuilder astBuilder = context.getUserData(Keys.AST_BUILDER);

            if (astBuilder == null) {
                return false;
            }

            final ConvertTypeOptions convertTypeOptions = new ConvertTypeOptions();

            convertTypeOptions.setAllowWildcards(false);

            final AstType castToType = astBuilder.convertType(targetResult.getType(), convertTypeOptions);

            replacement = right.replaceWith(
                new Function<AstNode, Expression>() {
                    @Override
                    public Expression apply(final AstNode e) {
                        return new CastExpression(castToType, right);
                    }
                }
            );
        }
        else if (conversionType == ConversionType.NONE) {
            if (valueResult.getType().getSimpleType() == JvmType.Boolean &&
                targetResult.getType().getSimpleType() != JvmType.Boolean &&
                targetResult.getType().getSimpleType().isNumeric()) {

                replacement = convertBooleanToNumeric(right);

                if (targetResult.getType().getSimpleType().bitWidth() < 32) {
                    final AstBuilder astBuilder = context.getUserData(Keys.AST_BUILDER);

                    if (astBuilder != null) {
                        replacement = replacement.replaceWith(
                            new Function<AstNode, AstNode>() {
                                @Override
                                public AstNode apply(final AstNode input) {
                                    return new CastExpression(astBuilder.convertType(targetResult.getType()), (Expression) input);
                                }
                            }
                        );
                    }
                }
            }
            else if (targetResult.getType().getSimpleType() == JvmType.Boolean &&
                     valueResult.getType().getSimpleType() != JvmType.Boolean &&
                     valueResult.getType().getSimpleType().isNumeric()) {

                replacement = convertNumericToBoolean(right, valueResult.getType());
            }
            else {
                final AstBuilder astBuilder = context.getUserData(Keys.AST_BUILDER);

                if (astBuilder != null) {
View Full Code Here

        super.visitUnaryOperatorExpression(node, data);

        switch (node.getOperator()) {
            case NOT: {
                final Expression operand = node.getExpression();
                final ResolveResult result = _resolver.apply(operand);

                if (result != null &&
                    result.getType() != null &&
                    !TypeUtilities.isBoolean(result.getType()) &&
                    MetadataHelper.getUnderlyingPrimitiveTypeOrSelf(result.getType()).getSimpleType().isNumeric()) {

                    final TypeReference comparandType = MetadataHelper.getUnderlyingPrimitiveTypeOrSelf(result.getType());

                    operand.replaceWith(
                        new Function<AstNode, AstNode>() {
                            @Override
                            public AstNode apply(final AstNode input) {
View Full Code Here

            case SHIFT_RIGHT:
            case UNSIGNED_SHIFT_RIGHT: {
                final Expression left = node.getLeft();
                final Expression right = node.getRight();

                final ResolveResult leftResult = _resolver.apply(left);
                final ResolveResult rightResult = _resolver.apply(right);

                if (leftResult != null && TypeUtilities.isBoolean(leftResult.getType())) {
                    convertBooleanToNumeric(left);
                }

                if (rightResult != null && TypeUtilities.isBoolean(rightResult.getType())) {
                    convertBooleanToNumeric(right);
                }

                break;
            }

            case BITWISE_AND:
            case BITWISE_OR:
            case EXCLUSIVE_OR:
                final Expression left = node.getLeft();
                final Expression right = node.getRight();

                final ResolveResult leftResult = _resolver.apply(left);
                final ResolveResult rightResult = _resolver.apply(right);

                if (leftResult != null &&
                    leftResult.getType() != null &&
                    rightResult != null &&
                    rightResult.getType() != null &&
                    TypeUtilities.isBoolean(leftResult.getType()) ^ TypeUtilities.isBoolean(rightResult.getType())) {

                    if (TypeUtilities.isBoolean(leftResult.getType()) &&
                        TypeUtilities.isArithmetic(rightResult.getType())) {

                        final TypeReference comparandType = MetadataHelper.getUnderlyingPrimitiveTypeOrSelf(rightResult.getType());

                        if (TRUE_NODE.matches(left)) {
                            ((PrimitiveExpression) left).setValue(JavaPrimitiveCast.cast(comparandType.getSimpleType(), 1));
                        }
                        else if (FALSE_NODE.matches(left)) {
                            ((PrimitiveExpression) left).setValue(JavaPrimitiveCast.cast(comparandType.getSimpleType(), 0));
                        }
                        else {
                            convertBooleanToNumeric(left);
                        }
                    }
                    else if (TypeUtilities.isArithmetic(leftResult.getType())) {
                        final TypeReference comparandType = MetadataHelper.getUnderlyingPrimitiveTypeOrSelf(leftResult.getType());

                        if (TRUE_NODE.matches(right)) {
                            ((PrimitiveExpression) right).setValue(JavaPrimitiveCast.cast(comparandType.getSimpleType(), 1));
                        }
                        else if (FALSE_NODE.matches(right)) {
                            ((PrimitiveExpression) right).setValue(JavaPrimitiveCast.cast(comparandType.getSimpleType(), 0));
                        }
                        else {
                            convertBooleanToNumeric(right);
                        }
                    }
                }
                else {
                    final TypeReference expectedType = TypeUtilities.getExpectedTypeByParent(_resolver, node);

                    if (expectedType != null && TypeUtilities.isBoolean(expectedType)) {
                        final ResolveResult result = _resolver.apply(node);

                        if (result != null &&
                            result.getType() != null &&
                            TypeUtilities.isArithmetic(result.getType())) {

                            convertNumericToBoolean(node, result.getType());
                        }
                    }
                }

                break;
View Full Code Here

    @Override
    public Void visitIfElseStatement(final IfElseStatement node, final Void data) {
        super.visitIfElseStatement(node, data);

        final Expression condition = node.getCondition();
        final ResolveResult conditionResult = _resolver.apply(condition);

        if (conditionResult != null &&
            TypeUtilities.isArithmetic(conditionResult.getType())) {

            convertNumericToBoolean(condition, conditionResult.getType());
        }

        return null;
    }
View Full Code Here

    @Override
    public Void visitConditionalExpression(final ConditionalExpression node, final Void data) {
        super.visitConditionalExpression(node, data);

        final Expression condition = node.getCondition();
        final ResolveResult conditionResult = _resolver.apply(condition);

        if (conditionResult != null &&
            TypeUtilities.isArithmetic(conditionResult.getType())) {

            convertNumericToBoolean(condition, conditionResult.getType());
        }

        return null;
    }
View Full Code Here

        final AstNodeCollection<Expression> arguments = node.getArguments();

        if (!arguments.isEmpty()) {
            final Expression firstArgument = arguments.firstOrNullObject();
            final ResolveResult resolvedArgument = _resolver.apply(firstArgument);

            if (resolvedArgument != null) {
                final TypeReference createdType = node.getType().getUserData(Keys.TYPE_REFERENCE);
                final TypeReference argumentType = resolvedArgument.getType();

                if (createdType != null && argumentType != null) {
                    final TypeDefinition resolvedCreatedType = createdType.resolve();

                    if (resolvedCreatedType != null &&
View Full Code Here

        if (node.getParent() instanceof InvocationExpression) {
            final InvocationExpression parent = (InvocationExpression) node.getParent();

            if (!parent.getArguments().isEmpty()) {
                final Expression firstArgument = parent.getArguments().firstOrNullObject();
                final ResolveResult resolvedArgument = _resolver.apply(firstArgument);

                if (resolvedArgument != null) {
                    final TypeReference superType = node.getUserData(Keys.TYPE_REFERENCE);
                    final TypeReference argumentType = resolvedArgument.getType();

                    if (superType != null && argumentType != null) {
                        final TypeDefinition resolvedSuperType = superType.resolve();

                        if (resolvedSuperType != null &&
View Full Code Here

TOP

Related Classes of com.strobel.decompiler.semantics.ResolveResult

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.