use of com.cburch.logisim.circuit.ExpressionComputer in project logisim-evolution by reds-heig.
the class AbstractGate method getInstanceFeature.
@Override
protected Object getInstanceFeature(final Instance instance, Object key) {
if (key == WireRepair.class) {
return new WireRepair() {
public boolean shouldRepairWire(WireRepairData data) {
return AbstractGate.this.shouldRepairWire(instance, data);
}
};
}
if (key == ExpressionComputer.class) {
return new ExpressionComputer() {
public void computeExpression(Map<Location, Expression> expressionMap) {
GateAttributes attrs = (GateAttributes) instance.getAttributeSet();
int inputCount = attrs.inputs;
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);
}
}
};
}
return super.getInstanceFeature(instance, key);
}
Aggregations