Package com.cburch.logisim.analyze.model

Examples of com.cburch.logisim.analyze.model.Expression


        return GateFunctions.computeOddParity(inputs, numInputs).not();
    }

    @Override
    protected Expression computeExpression(Expression[] inputs, int numInputs) {
        Expression ret = inputs[0];
        for (int i = 1; i < numInputs; i++) {
            ret = Expressions.xor(ret, inputs[i]);
        }
        return Expressions.not(ret);
    }
View Full Code Here


                field.setText(getCurrentString());
                field.grabFocus();
            } else if ((src == field || src == enter) && enter.isEnabled()) {
                try {
                    String exprString = field.getText();
                    Expression expr = Parser.parse(field.getText(), model);
                    setError(null);
                    model.getOutputExpressions().setExpression(getCurrentVariable(), expr, exprString);
                    insertUpdate(null);
                } catch (ParserException ex) {
                    setError(ex.getMessageGetter());
View Full Code Here

                    int negated = attrs.negated;

                    Expression[] inputs = new Expression[inputCount];
                    int numInputs = 0;
                    for (int i = 1; i <= inputCount; i++) {
                        Expression e = expressionMap.get(instance.getPortLocation(i));
                        if (e != null) {
                            int negatedBit = (negated >> (i - 1)) & 1;
                            if (negatedBit == 1) {
                                e = Expressions.not(e);
                            }
                            inputs[numInputs] = e;
                            ++numInputs;
                        }
                    }
                    if (numInputs > 0) {
                        Expression out = AbstractGate.this.computeExpression(inputs, numInputs);
                        expressionMap.put(instance.getPortLocation(0), out);
                    }
                }
            };
        }
View Full Code Here

        for (Map.Entry<Instance, String> entry : pinNames.entrySet()) {
            Instance pin = entry.getKey();
            String label = entry.getValue();
            if (Pin.FACTORY.isInputPin(pin)) {
                expressionMap.currentCause = Instance.getComponentFor(pin);
                Expression e = Expressions.variable(label);
                expressionMap.put(pin.getLocation(), e);
                inputNames.add(label);
            } else {
                outputPins.add(pin);
                outputNames.add(label);
            }
        }

        propagateComponents(expressionMap, circuit.getNonWires());

        for (int iterations = 0; !expressionMap.dirtyPoints.isEmpty(); iterations++) {
            if (iterations > MAX_ITERATIONS) {
                throw new AnalyzeException.Circular();
            }

            propagateWires(expressionMap, new HashSet<Location>(expressionMap.dirtyPoints));

            HashSet<Component> dirtyComponents = getDirtyComponents(circuit, expressionMap.dirtyPoints);
            expressionMap.dirtyPoints.clear();
            propagateComponents(expressionMap, dirtyComponents);

            Expression expr = checkForCircularExpressions(expressionMap);
            if (expr != null) {
                throw new AnalyzeException.Circular();
            }

        }
View Full Code Here

    // propagates expressions down wires
    private static void propagateWires(ExpressionMap expressionMap,
            HashSet<Location> pointsToProcess) throws AnalyzeException {
        expressionMap.currentCause = null;
        for (Location p : pointsToProcess) {
            Expression e = expressionMap.get(p);
            expressionMap.currentCause = expressionMap.causes.get(p);
            WireBundle bundle = expressionMap.circuit.wires.getWireBundle(p);
            if (e != null && bundle != null && bundle.points != null) {
                for (Location p2 : bundle.points) {
                    if (p2.equals(p)) {
                        continue;
                    }

                    Expression old = expressionMap.get(p2);
                    if (old != null) {
                        Component eCause = expressionMap.currentCause;
                        Component oldCause = expressionMap.causes.get(p2);
                        if (eCause != oldCause && !old.equals(e)) {
                            throw new AnalyzeException.Conflict();
                        }
                    }
                    expressionMap.put(p2, e);
                }
View Full Code Here

    /** Checks whether any of the recently placed expressions in the
     * expression map are self-referential; if so, return it. */
    private static Expression checkForCircularExpressions(ExpressionMap expressionMap)
            throws AnalyzeException {
        for (Location point : expressionMap.dirtyPoints) {
            Expression expr = expressionMap.get(point);
            if (expr.isCircular()) {
                return expr;
            }

        }
        return null;
View Full Code Here

            this.circuit = circuit;
        }

        @Override
        public Expression put(Location point, Expression expression) {
            Expression ret = super.put(point, expression);
            if (currentCause != null) {
                causes.put(point, currentCause);
            }

            if (ret == null ? expression != null : !ret.equals(expression)) {
                dirtyPoints.add(point);
            }
            return ret;
        }
View Full Code Here

    protected Object getInstanceFeature(final Instance instance, Object key) {
        if (key == ExpressionComputer.class) {
            return new ExpressionComputer() {
                @Override
                public void computeExpression(Map<Location,Expression> expressionMap) {
                    Expression e = expressionMap.get(instance.getPortLocation(1));
                    if (e != null) {
                        expressionMap.put(instance.getPortLocation(0), Expressions.not(e));
                    }
                }
            };
View Full Code Here

    public Object getInstanceFeature(final Instance instance, Object key) {
        if (key == ExpressionComputer.class) {
            return new ExpressionComputer() {
                @Override
                public void computeExpression(Map<Location,Expression> expressionMap) {
                    Expression e = expressionMap.get(instance.getPortLocation(1));
                    if (e != null) {
                        expressionMap.put(instance.getPortLocation(0), e);
                    }
                }
            };
View Full Code Here

    protected static Expression xorExpression(Expression[] inputs, int numInputs) {
        if (numInputs > 2) {
            throw new UnsupportedOperationException("XorGate");
        }
        Expression ret = inputs[0];
        for (int i = 1; i < numInputs; i++) {
            ret = Expressions.xor(ret, inputs[i]);
        }
        return ret;
    }
View Full Code Here

TOP

Related Classes of com.cburch.logisim.analyze.model.Expression

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.