Package com.strobel.decompiler.semantics

Examples of com.strobel.decompiler.semantics.ResolveResult


                if (castType != null &&
                    castType.isPrimitive() &&
                    castedValue instanceof BinaryOperatorExpression) {

                    final ResolveResult leftResult = _resolver.apply(left);

                    if (leftResult != null &&
                        MetadataResolver.areEquivalent(castType, leftResult.getType()) &&
                        tryRewriteBinaryAsAssignment(node, left, castedValue)) {

                        final Expression newValue = castExpression.getExpression();

                        newValue.remove();
View Full Code Here


        return Comparer.equals(c1.getConstantValue(), c2.getConstantValue());
    }

    protected Boolean evaluateCondition(final Expression e) {
        final ResolveResult result = evaluateConstant(e);

        if (result != null && result.isCompileTimeConstant()) {
            final Object constantValue = result.getConstantValue();

            if (constantValue instanceof Boolean) {
                return (Boolean) constantValue;
            }
View Full Code Here

                binary.getRight() instanceof NullReferenceExpression) {

                return false;
            }

            final ResolveResult leftResult = _resolver.apply(binary.getLeft());
            final ResolveResult rightResult = _resolver.apply(binary.getRight());

            return leftResult != null &&
                   rightResult != null &&
                   leftResult.getType() != null &&
                   rightResult.getType() != null &&
                   (node == binary.getLeft() ? rightResult.getType().isPrimitive()
                                             : leftResult.getType().isPrimitive());
        }

        //
        // TODO: Remove the `if` below once overload resolution is written and integrated.
View Full Code Here

        // it must be simplified to `g((short)i.intValue())`.  A boxed type `S` can only
        // be cast to a primitive type `t` if there exists an implicit conversion from
        // the underlying primitive type `s` to `t`.
        //

        final ResolveResult boxedValueResult = _resolver.apply(boxedValue);

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

        final TypeReference targetType = ((MethodReference) outerBoxMethod).getReturnType();
        final TypeReference sourceType = boxedValueResult.getType();

        switch (MetadataHelper.getNumericConversionType(targetType, sourceType)) {
            case IDENTITY:
            case IMPLICIT: {
                boxedValue.remove();
View Full Code Here

            return createConnectedEndNode(node, data);
        }

        @Override
        public ControlFlowNode visitSwitchStatement(final SwitchStatement node, final ControlFlowNode data) {
            final ResolveResult constant = evaluateConstant(node.getExpression());

            SwitchSection defaultSection = null;
            SwitchSection sectionMatchedByConstant = null;

            for (final SwitchSection section : node.getSwitchSections()) {
                for (final CaseLabel label : section.getCaseLabels()) {
                    if (label.getExpression().isNull()) {
                        defaultSection = section;
                    }
                    else if (constant != null && constant.isCompileTimeConstant()) {
                        final ResolveResult labelConstant = evaluateConstant(label.getExpression());

                        if (areEqualConstants(constant, labelConstant)) {
                            sectionMatchedByConstant = section;
                        }
                    }
View Full Code Here

        if (targetType == null || !targetType.isPrimitive()) {
            return;
        }

        final Expression boxedValue = target.getTarget();
        final ResolveResult boxedValueResult = _resolver.apply(boxedValue);

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

        final TypeReference sourceType = boxedValueResult.getType();
        final ConversionType conversionType = MetadataHelper.getNumericConversionType(targetType, sourceType);

        switch (conversionType) {
            case IMPLICIT: {
                boxedValue.remove();
View Full Code Here

            return;
        }

        final AstNodeCollection<Expression> arguments = node.getArguments();
        final Expression underlyingValue = arguments.firstOrNullObject();
        final ResolveResult valueResult = _resolver.apply(underlyingValue);

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

        final TypeReference sourceType = valueResult.getType();
        final TypeReference targetType = ((MethodReference) reference).getReturnType();
        final ConversionType conversionType = MetadataHelper.getNumericConversionType(targetType, sourceType);

        switch (conversionType) {
            case IMPLICIT: {
View Full Code Here

    }

    private void tryRemoveCast(final CastExpression node) {
        final AstNode parent = node.getParent();
        final Expression value = node.getExpression();
        final ResolveResult valueResult = _resolver.apply(value);

        if (parent == null ||
            parent.isNull() ||
            value == null ||
            value.isNull() ||
            valueResult == null ||
            valueResult.getType() == null) {

            return;
        }

        final TypeReference sourceType = node.getType().toTypeReference();

        if (sourceType == null) {
            return;
        }

        final Role role = node.getRole();

        if (role == Roles.ARGUMENT) {
            tryRemoveCastForArgument(node, value, parent, sourceType, valueResult.getType());
            return;
        }

        if (parent instanceof CastExpression) {
            trySimplifyDoubleCast(node, value, (CastExpression) parent, sourceType, valueResult.getType());
            return;
        }

        if (parent instanceof AssignmentExpression) {
            trySimplifyCastForAssignment(node, value, (AssignmentExpression) parent, sourceType, valueResult.getType());
            return;
        }

        if (parent instanceof MemberReferenceExpression &&
            MetadataResolver.areEquivalent(sourceType, valueResult.getType())) {

            value.remove();
            node.replaceWith(value);
            return;
        }
View Full Code Here

            // Huh?  Shouldn't be possible, but lord knows who built this AST.
            //
            return;
        }

        final ResolveResult targetResult = _resolver.apply(parent.getLeft());

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

        if (parent.getOperator() == AssignmentOperatorType.ASSIGN) {
            final TypeReference targetType = targetResult.getType();

            final ConversionType valueToCast = MetadataHelper.getConversionType(castType, valueType);

            if (valueToCast == ConversionType.IDENTITY) {
                //
View Full Code Here

        if (target instanceof MemberReferenceExpression) {
            target = ((MemberReferenceExpression) target).getTarget();
        }

        final ResolveResult targetResult = _resolver.apply(target);

        if (targetResult != null && targetResult.getType() != null) {
            method = MetadataHelper.asMemberOf(method, targetResult.getType());
        }

        final List<ParameterDefinition> parameters = method.getParameters();
        final AstNodeCollection<Expression> arguments = parent.getChildrenByRole(Roles.ARGUMENT);

        final int argumentPosition = firstIndexWhere(
            arguments,
            new Predicate<Expression>() {
                @Override
                public boolean test(final Expression e) {
                    return e == node;
                }
            }
        );

        if (argumentPosition < 0) {
            return;
        }

        int parameterPosition = 0;

        while (parameterPosition < parameters.size() && parameters.get(parameterPosition).isSynthetic()) {
            ++parameterPosition;
        }

        parameterPosition += argumentPosition;

        if (parameterPosition < 0 || parameterPosition >= parameters.size()) {
            return;
        }

        final ConversionType valueToCast = MetadataHelper.getConversionType(castType, valueType);

        if (valueToCast == ConversionType.IDENTITY) {
            //
            // T t; f((T)t) => f(t)
            //
            value.remove();
            node.replaceWith(value);
            return;
        }

        final ParameterDefinition parameter = parameters.get(parameterPosition);
        final TypeReference targetType = parameter.getParameterType();
        final ConversionType castToTarget = MetadataHelper.getConversionType(targetType, castType);

        if (castToTarget != ConversionType.IDENTITY && castToTarget != ConversionType.IMPLICIT) {
            return;
        }

        final ConversionType valueToTarget = MetadataHelper.getConversionType(targetType, valueType);

        if (valueToTarget != ConversionType.IMPLICIT) {
            return;
        }

        final List<TypeReference> argumentTypes = new ArrayList<>();
        final int syntheticParameters = parameterPosition - argumentPosition;

        for (int j = 0; j < syntheticParameters; j++) {
            argumentTypes.add(parameters.get(j).getParameterType());
        }

        for (final Expression argument : arguments) {
            final ResolveResult argumentResult = _resolver.apply(argument);

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

            argumentTypes.add(argumentResult.getType());
        }

        final TypeReference declaringType = method.getDeclaringType();

        final List<MethodReference> candidates = MetadataHelper.findMethods(
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.