Package com.strobel.core

Examples of com.strobel.core.MutableInteger


        return _values.toArray();
    }

    void addReference(final Object value, final Type<?> type) {
        if (!_indexes.containsKey(value)) {
            _indexes.put(value, new MutableInteger(_values.size()));
            _values.add(value);
        }
        incrementCount(new TypedConstant(value, type), _references);
    }
View Full Code Here


        lc.emitClosureArgument();
        lc.generator.getField(Type.of(Closure.class).getField("constants"));
    }

    private void emitConstantFromArray(final LambdaCompiler lc, final Object value, final Type type) {
        MutableInteger index = _indexes.get(value);
       
        if (index == null) {
            _indexes.put(value, (index = new MutableInteger(_values.size())));
            _values.add(value);
        }

        lc.generator.emitInteger(index.getValue());
        lc.generator.emitLoadElement(Types.Object);
        lc.generator.emitConversion(Types.Object, type);
    }
View Full Code Here

        for (final TypedConstant reference : _references.keySet()) {
            if (!lc.canEmitBoundConstants()) {
                throw Error.cannotCompileConstant(reference.value);
            }

            final MutableInteger referenceCount = _references.get(reference);

            if (shouldCache(referenceCount.getValue())) {
                count++;
            }
        }

        if (count == 0) {
            return;
        }

        emitConstantsArray(lc);

        // The same lambda can be in multiple places in the tree, so we
        // need to clear any locals from last time.
        _cache.clear();

        for (final TypedConstant reference : _references.keySet()) {
            final MutableInteger referenceCount = _references.get(reference);

            if (shouldCache(referenceCount.getValue())) {
                if (--count > 0) {
                    // Dup array to keep it on the stack
                    lc.generator.dup();
                }
View Full Code Here

        // Also, it is too conservative for variables used inside of loops.
        return refCount > 2;
    }

    private void incrementCount(final TypedConstant typedConstant, final HashMap<TypedConstant, MutableInteger> references) {
        final MutableInteger count = references.get(typedConstant);
        if (count != null) {
            count.increment();
        }
        else {
            references.put(typedConstant, new MutableInteger(1));
        }
    }
View Full Code Here

    private boolean shouldCache(final ParameterExpression v) {
        if (referenceCount == null) {
            return false;
        }

        final MutableInteger refCount = referenceCount.get(v);

        return refCount != null &&
               shouldCache(v, refCount.getValue());
    }
View Full Code Here

        return null;
    }

    static <T> void incrementCount(final T key, final Map<T, MutableInteger> dict) {
        MutableInteger count = dict.get(key);

        if (count == null) {
            dict.put(key, count = new MutableInteger());
        }

        count.increment();
    }
View Full Code Here

                return false;
        }
    }

    static int count(final Map<Variable, MutableInteger> map, final Variable variable) {
        final MutableInteger count = map.get(variable);
        return count != null ? count.getValue() : 0;
    }
View Full Code Here

        final MutableInteger count = map.get(variable);
        return count != null ? count.getValue() : 0;
    }

    private static void increment(final Map<Variable, MutableInteger> map, final Variable variable) {
        final MutableInteger count = map.get(variable);

        if (count == null) {
            map.put(variable, new MutableInteger(1));
        }
        else {
            count.increment();
        }
    }
View Full Code Here

    public AstType convertType(final TypeReference type) {
        return convertType(type, new ConvertTypeOptions());
    }

    public AstType convertType(final TypeReference type, final ConvertTypeOptions options) {
        return convertType(type, new MutableInteger(0), options);
    }
View Full Code Here

            return false;
        }

        final StrongBox<Variable> v = new StrongBox<>();
        final StrongBox<Expression> parent = new StrongBox<>();
        final MutableInteger position = new MutableInteger();

        if (matchStore(inlinedExpression, v, parent) &&
            match(parent.value, AstCode.InitArray) &&
            (match(n, AstCode.LoadElement) || match(n, AstCode.StoreElement))) {

            //
            // Don't allow creation of `(n = new X[] ( ... )[n]`.  It's ugly, and I hate it.
            //
            return false;
        }

        if (findLoadInNext((Expression) n, variable, inlinedExpression, parent, position) == Boolean.TRUE) {
            if (!aggressive &&
                !(variable.isGenerated() ||
                  notFromMetadata(variable) && matchReturnOrThrow(n) /* allow inline to return or throw */) &&
                !nonAggressiveInlineInto((Expression) n, parent.get(), inlinedExpression)) {

                return false;
            }

            final List<Expression> parentArguments = parent.get().getArguments();
            final Map<Expression, Expression> parentLookup = new IdentityHashMap<>();

            for (final Expression node : next.getSelfAndChildrenRecursive(Expression.class)) {
                for (final Expression child : node.getArguments()) {
                    parentLookup.put(child, node);
                }
            }

            final List<Expression> nestedAssignments = inlinedExpression.getSelfAndChildrenRecursive(
                Expression.class,
                new Predicate<Expression>() {
                    @Override
                    public boolean test(final Expression node) {
                        return node.getCode() == AstCode.Store;
                    }
                }
            );

            //
            // Make sure we do not inline an initialization expression into the left-hand side of an assignment
            // whose value references the initialized variable.  For example, do not allow inlining in this case:
            //
            //     v = (x = y); v.f = x.f - 1 => (x = y).f = x.f - 1
            //
            for (final Expression assignment : nestedAssignments) {
                Expression lastParent = parentArguments.get(position.getValue());

                for (final Expression e : getParents((Expression) n, parentLookup, parentArguments.get(position.getValue()))) {
                    if (e.getCode().isWriteOperation()) {
                        boolean lastParentFound = false;

                        for (final Expression a : e.getArguments()) {
                            if (lastParentFound) {
                                if (AstOptimizer.references(a, (Variable) assignment.getOperand())) {
                                    return false;
                                }
                            }
                            else if (a == lastParent) {
                                lastParentFound = true;
                            }
                        }
                    }
                    lastParent = e;
                }
            }

            //
            // Assign the ranges of the Load instruction.
            //
            inlinedExpression.getRanges().addAll(
                parentArguments.get(position.getValue()).getRanges()
            );

            parentArguments.set(position.getValue(), inlinedExpression);

            return true;
        }

        return false;
View Full Code Here

TOP

Related Classes of com.strobel.core.MutableInteger

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.