mirror of
https://github.com/hneemann/Digital.git
synced 2025-09-17 17:04:42 -04:00
better error handling
This commit is contained in:
parent
cbf97388c9
commit
36cf778825
@ -12,6 +12,7 @@ import de.neemann.digital.draw.elements.VisualElement;
|
|||||||
import de.neemann.digital.draw.elements.Wire;
|
import de.neemann.digital.draw.elements.Wire;
|
||||||
import de.neemann.digital.draw.graphics.Vector;
|
import de.neemann.digital.draw.graphics.Vector;
|
||||||
import de.neemann.digital.draw.shapes.ShapeFactory;
|
import de.neemann.digital.draw.shapes.ShapeFactory;
|
||||||
|
import de.neemann.digital.lang.Lang;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
@ -49,8 +50,9 @@ public class Builder {
|
|||||||
* @param name the output name
|
* @param name the output name
|
||||||
* @param expression the expression
|
* @param expression the expression
|
||||||
* @return this for chained calls
|
* @return this for chained calls
|
||||||
|
* @throws BuilderException BuilderException
|
||||||
*/
|
*/
|
||||||
public Builder addExpression(String name, Expression expression) {
|
public Builder addExpression(String name, Expression expression) throws BuilderException {
|
||||||
Fragment fr = createFragment(expression);
|
Fragment fr = createFragment(expression);
|
||||||
|
|
||||||
fr = new FragmentExpression(fr, new FragmentVisualElement(Out.DESCRIPTION, shapeFactory).setAttr(Keys.LABEL, name));
|
fr = new FragmentExpression(fr, new FragmentVisualElement(Out.DESCRIPTION, shapeFactory).setAttr(Keys.LABEL, name));
|
||||||
@ -59,14 +61,14 @@ public class Builder {
|
|||||||
Box b = fr.doLayout();
|
Box b = fr.doLayout();
|
||||||
|
|
||||||
fr.addToCircuit(new Vector(0, pos), circuit);
|
fr.addToCircuit(new Vector(0, pos), circuit);
|
||||||
pos += b.getHeight() + SIZE;
|
pos += b.getHeight() + SIZE * 2;
|
||||||
|
|
||||||
expression.traverse(variableVisitor);
|
expression.traverse(variableVisitor);
|
||||||
|
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
private Fragment createFragment(Expression expression) {
|
private Fragment createFragment(Expression expression) throws BuilderException {
|
||||||
if (expression instanceof Operation) {
|
if (expression instanceof Operation) {
|
||||||
Operation op = (Operation) expression;
|
Operation op = (Operation) expression;
|
||||||
ArrayList<Fragment> frags = new ArrayList<>();
|
ArrayList<Fragment> frags = new ArrayList<>();
|
||||||
@ -78,7 +80,7 @@ public class Builder {
|
|||||||
else if (op instanceof Operation.Or)
|
else if (op instanceof Operation.Or)
|
||||||
return new FragmentExpression(frags, new FragmentVisualElement(Or.DESCRIPTION, frags.size(), shapeFactory));
|
return new FragmentExpression(frags, new FragmentVisualElement(Or.DESCRIPTION, frags.size(), shapeFactory));
|
||||||
else
|
else
|
||||||
throw new RuntimeException("nyi");
|
throw new BuilderException(Lang.get("err_builder_operationNotSupported", op.getClass().getSimpleName()));
|
||||||
} else if (expression instanceof Not) {
|
} else if (expression instanceof Not) {
|
||||||
Not n = (Not) expression;
|
Not n = (Not) expression;
|
||||||
if (n.getExpression() instanceof Variable) {
|
if (n.getExpression() instanceof Variable) {
|
||||||
@ -92,7 +94,7 @@ public class Builder {
|
|||||||
fragmentVariables.add(fragmentVariable);
|
fragmentVariables.add(fragmentVariable);
|
||||||
return fragmentVariable;
|
return fragmentVariable;
|
||||||
} else
|
} else
|
||||||
throw new RuntimeException("nyi");
|
throw new BuilderException(Lang.get("err_builder_exprNotSupported", expression.getClass().getSimpleName()));
|
||||||
}
|
}
|
||||||
|
|
||||||
private void createInputBus() {
|
private void createInputBus() {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user