mirror of
https://github.com/hneemann/Digital.git
synced 2025-09-17 08:55:05 -04:00
some refactoring, mostly working
This commit is contained in:
parent
da350b285a
commit
00d8a2f845
@ -150,7 +150,7 @@ public class SubstituteLibrary implements LibraryInterface {
|
|||||||
c.getAttributes().set(Keys.IS_GENERIC, false);
|
c.getAttributes().set(Keys.IS_GENERIC, false);
|
||||||
generify(attr, c);
|
generify(attr, c);
|
||||||
|
|
||||||
return ElementLibrary.createCustomDescription(new File(filename), c).isSubstitutedBuiltIn();
|
return ElementLibrary.createCustomDescription(new File(filename), c, library).isSubstitutedBuiltIn();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void generify(ElementAttributes attr, Circuit circuit) throws IOException {
|
private void generify(ElementAttributes attr, Circuit circuit) throws IOException {
|
||||||
|
@ -19,6 +19,7 @@ import java.util.Map;
|
|||||||
public class ElementAttributes implements HGSMap {
|
public class ElementAttributes implements HGSMap {
|
||||||
private HashMap<String, Object> attributes;
|
private HashMap<String, Object> attributes;
|
||||||
private transient ArrayList<AttributeListener> listeners;
|
private transient ArrayList<AttributeListener> listeners;
|
||||||
|
private transient HashMap<String, Object> cache;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a new instance
|
* Creates a new instance
|
||||||
@ -293,4 +294,16 @@ public class ElementAttributes implements HGSMap {
|
|||||||
} else
|
} else
|
||||||
return get(k);
|
return get(k);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void putToCache(String key, Object value) {
|
||||||
|
if (cache == null)
|
||||||
|
cache = new HashMap<>();
|
||||||
|
cache.put(key, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Object getFromCache(String key) {
|
||||||
|
if (cache == null)
|
||||||
|
return null;
|
||||||
|
return cache.get(key);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -253,13 +253,6 @@ public class ElementTypeDescription {
|
|||||||
return inputPins.get(i);
|
return inputPins.get(i);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @return true if this is a custom component
|
|
||||||
*/
|
|
||||||
public boolean isCustom() {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return the class loader, the component is loaded from. Maybe null.
|
* @return the class loader, the component is loaded from. Maybe null.
|
||||||
*/
|
*/
|
||||||
|
@ -39,7 +39,6 @@ public class VisualElement implements Drawable, Movable, AttributeListener {
|
|||||||
// shapes are recreated if attributes are changed, therefore a factory is necessary and not only a simple shape!
|
// shapes are recreated if attributes are changed, therefore a factory is necessary and not only a simple shape!
|
||||||
private transient ShapeFactory shapeFactory;
|
private transient ShapeFactory shapeFactory;
|
||||||
private transient Transform transform;
|
private transient Transform transform;
|
||||||
private transient Context genericArgs;
|
|
||||||
|
|
||||||
// these fields are stored to disk
|
// these fields are stored to disk
|
||||||
private String elementName;
|
private String elementName;
|
||||||
@ -461,22 +460,6 @@ public class VisualElement implements Drawable, Movable, AttributeListener {
|
|||||||
return interactor != null;
|
return interactor != null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Sets the generic arguments for this element
|
|
||||||
*
|
|
||||||
* @param genericArgs the arguments
|
|
||||||
*/
|
|
||||||
public void setGenericArgs(Context genericArgs) {
|
|
||||||
this.genericArgs = genericArgs;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return the generic arguments for this element
|
|
||||||
*/
|
|
||||||
public Context getGenericArgs() {
|
|
||||||
return genericArgs;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the name of this element
|
* Sets the name of this element
|
||||||
*
|
*
|
||||||
|
@ -39,14 +39,13 @@ public class CustomElement implements Element {
|
|||||||
* @param depth recursion depth, used to detect a circuit which contains itself
|
* @param depth recursion depth, used to detect a circuit which contains itself
|
||||||
* @param errorVisualElement visual element used for error indicating
|
* @param errorVisualElement visual element used for error indicating
|
||||||
* @param containingVisualElement the containing visual element
|
* @param containingVisualElement the containing visual element
|
||||||
* @param library the library to use
|
|
||||||
* @return the {@link ModelCreator}
|
* @return the {@link ModelCreator}
|
||||||
* @throws PinException PinException
|
* @throws PinException PinException
|
||||||
* @throws NodeException NodeException
|
* @throws NodeException NodeException
|
||||||
* @throws ElementNotFoundException ElementNotFoundException
|
* @throws ElementNotFoundException ElementNotFoundException
|
||||||
*/
|
*/
|
||||||
public ModelCreator getModelCreator(String subName, int depth, VisualElement errorVisualElement, VisualElement containingVisualElement, LibraryInterface library) throws PinException, NodeException, ElementNotFoundException {
|
public ModelCreator getModelCreator(String subName, int depth, VisualElement errorVisualElement, VisualElement containingVisualElement) throws PinException, NodeException, ElementNotFoundException {
|
||||||
return descriptionCustom.getModelCreator(subName, depth, errorVisualElement, containingVisualElement, library);
|
return descriptionCustom.getModelCreator(subName, depth, errorVisualElement, containingVisualElement);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -587,7 +587,7 @@ public class ElementLibrary implements Iterable<ElementLibrary.ElementContainer>
|
|||||||
throw new IOException(Lang.get("err_couldNotFindIncludedFile_N0", file));
|
throw new IOException(Lang.get("err_couldNotFindIncludedFile_N0", file));
|
||||||
}
|
}
|
||||||
|
|
||||||
ElementTypeDescriptionCustom description = createCustomDescription(file, circuit);
|
ElementTypeDescriptionCustom description = createCustomDescription(file, circuit, this);
|
||||||
description.setShortName(createShortName(file.getName(), circuit.getAttributes().getLabel()));
|
description.setShortName(createShortName(file.getName(), circuit.getAttributes().getLabel()));
|
||||||
|
|
||||||
String descriptionText = Lang.evalMultilingualContent(circuit.getAttributes().get(Keys.DESCRIPTION));
|
String descriptionText = Lang.evalMultilingualContent(circuit.getAttributes().get(Keys.DESCRIPTION));
|
||||||
@ -622,8 +622,8 @@ public class ElementLibrary implements Iterable<ElementLibrary.ElementContainer>
|
|||||||
* @return the type description
|
* @return the type description
|
||||||
* @throws PinException PinException
|
* @throws PinException PinException
|
||||||
*/
|
*/
|
||||||
public static ElementTypeDescriptionCustom createCustomDescription(File file, Circuit circuit) throws PinException {
|
public static ElementTypeDescriptionCustom createCustomDescription(File file, Circuit circuit, ElementLibrary library) throws PinException {
|
||||||
ElementTypeDescriptionCustom d = new ElementTypeDescriptionCustom(file, circuit);
|
ElementTypeDescriptionCustom d = new ElementTypeDescriptionCustom(file, circuit, library);
|
||||||
d.setElementFactory(attributes -> new CustomElement(d));
|
d.setElementFactory(attributes -> new CustomElement(d));
|
||||||
return d;
|
return d;
|
||||||
}
|
}
|
||||||
|
@ -32,6 +32,7 @@ public final class ElementTypeDescriptionCustom extends ElementTypeDescription {
|
|||||||
private final File file;
|
private final File file;
|
||||||
private final Circuit circuit;
|
private final Circuit circuit;
|
||||||
private final ResolveGenerics resolveGenerics;
|
private final ResolveGenerics resolveGenerics;
|
||||||
|
private final LibraryInterface library;
|
||||||
private String description;
|
private String description;
|
||||||
private NetList netList;
|
private NetList netList;
|
||||||
private boolean isCustom = true;
|
private boolean isCustom = true;
|
||||||
@ -44,11 +45,12 @@ public final class ElementTypeDescriptionCustom extends ElementTypeDescription {
|
|||||||
* @param circuit the circuit
|
* @param circuit the circuit
|
||||||
* @throws PinException PinException
|
* @throws PinException PinException
|
||||||
*/
|
*/
|
||||||
ElementTypeDescriptionCustom(File file, Circuit circuit) throws PinException {
|
ElementTypeDescriptionCustom(File file, Circuit circuit, ElementLibrary library) throws PinException {
|
||||||
super(file.getName(), (ElementFactory) null, circuit.getInputNames());
|
super(file.getName(), (ElementFactory) null, circuit.getInputNames());
|
||||||
this.file = file;
|
this.file = file;
|
||||||
this.circuit = circuit;
|
this.circuit = circuit;
|
||||||
resolveGenerics = new ResolveGenerics();
|
this.library = library;
|
||||||
|
resolveGenerics = new ResolveGenerics(circuit, library);
|
||||||
setShortName(file.getName());
|
setShortName(file.getName());
|
||||||
addAttribute(Keys.ROTATE);
|
addAttribute(Keys.ROTATE);
|
||||||
addAttribute(Keys.LABEL);
|
addAttribute(Keys.LABEL);
|
||||||
@ -105,13 +107,12 @@ public final class ElementTypeDescriptionCustom extends ElementTypeDescription {
|
|||||||
* @param subName name of the circuit, used to name unique elements
|
* @param subName name of the circuit, used to name unique elements
|
||||||
* @param depth recursion depth, used to detect a circuit which contains itself
|
* @param depth recursion depth, used to detect a circuit which contains itself
|
||||||
* @param containingVisualElement the containing visual element
|
* @param containingVisualElement the containing visual element
|
||||||
* @param library the library used
|
|
||||||
* @return the {@link ModelCreator}
|
* @return the {@link ModelCreator}
|
||||||
* @throws PinException PinException
|
* @throws PinException PinException
|
||||||
* @throws NodeException NodeException
|
* @throws NodeException NodeException
|
||||||
* @throws ElementNotFoundException ElementNotFoundException
|
* @throws ElementNotFoundException ElementNotFoundException
|
||||||
*/
|
*/
|
||||||
ModelCreator getModelCreator(String subName, int depth, VisualElement errorVisualElement, VisualElement containingVisualElement, LibraryInterface library) throws PinException, NodeException, ElementNotFoundException {
|
ModelCreator getModelCreator(String subName, int depth, VisualElement errorVisualElement, VisualElement containingVisualElement) throws PinException, NodeException, ElementNotFoundException {
|
||||||
if (netList == null)
|
if (netList == null)
|
||||||
netList = new NetList(circuit);
|
netList = new NetList(circuit);
|
||||||
|
|
||||||
@ -119,14 +120,13 @@ public final class ElementTypeDescriptionCustom extends ElementTypeDescription {
|
|||||||
throw new NodeException(Lang.get("err_recursiveNestingAt_N0", circuit.getOrigin()));
|
throw new NodeException(Lang.get("err_recursiveNestingAt_N0", circuit.getOrigin()));
|
||||||
|
|
||||||
if (isGeneric()) {
|
if (isGeneric()) {
|
||||||
Circuit c = resolveGenerics.resolveCircuit(containingVisualElement, circuit, library).getCircuit();
|
Circuit c = resolveGenerics.resolveCircuit(containingVisualElement.getElementAttributes()).getCircuit();
|
||||||
|
|
||||||
return new ModelCreator(c, library, true, new NetList(new NetList(c), errorVisualElement), subName, depth, errorVisualElement);
|
return new ModelCreator(c, library, true, new NetList(new NetList(c), errorVisualElement), subName, depth, errorVisualElement);
|
||||||
} else
|
} else
|
||||||
return new ModelCreator(circuit, library, true, new NetList(netList, errorVisualElement), subName, depth, errorVisualElement);
|
return new ModelCreator(circuit, library, true, new NetList(netList, errorVisualElement), subName, depth, errorVisualElement);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isCustom() {
|
public boolean isCustom() {
|
||||||
return isCustom;
|
return isCustom;
|
||||||
}
|
}
|
||||||
@ -198,4 +198,30 @@ public final class ElementTypeDescriptionCustom extends ElementTypeDescription {
|
|||||||
public boolean isGeneric() {
|
public boolean isGeneric() {
|
||||||
return circuit.getAttributes().get(Keys.IS_GENERIC);
|
return circuit.getAttributes().get(Keys.IS_GENERIC);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public PinDescriptions getInputDescription(ElementAttributes elementAttributes) throws NodeException {
|
||||||
|
if (isGeneric()) {
|
||||||
|
try {
|
||||||
|
Circuit c = resolveGenerics.resolveCircuit(elementAttributes).getCircuit();
|
||||||
|
return new PinDescriptions(c.getInputNames());
|
||||||
|
} catch (ElementNotFoundException | PinException e) {
|
||||||
|
return super.getInputDescription(elementAttributes);
|
||||||
|
}
|
||||||
|
} else
|
||||||
|
return super.getInputDescription(elementAttributes);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public PinDescriptions getOutputDescriptions(ElementAttributes elementAttributes) throws PinException {
|
||||||
|
if (isGeneric()) {
|
||||||
|
try {
|
||||||
|
Circuit c = resolveGenerics.resolveCircuit(elementAttributes).getCircuit();
|
||||||
|
return new PinDescriptions(c.getOutputNames());
|
||||||
|
} catch (ElementNotFoundException | PinException | NodeException e) {
|
||||||
|
return super.getOutputDescriptions(elementAttributes);
|
||||||
|
}
|
||||||
|
} else
|
||||||
|
return super.getOutputDescriptions(elementAttributes);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -7,6 +7,8 @@ package de.neemann.digital.draw.library;
|
|||||||
|
|
||||||
import de.neemann.digital.analyse.SubstituteLibrary;
|
import de.neemann.digital.analyse.SubstituteLibrary;
|
||||||
import de.neemann.digital.core.NodeException;
|
import de.neemann.digital.core.NodeException;
|
||||||
|
import de.neemann.digital.core.element.ElementAttributes;
|
||||||
|
import de.neemann.digital.core.element.ElementTypeDescription;
|
||||||
import de.neemann.digital.core.element.Keys;
|
import de.neemann.digital.core.element.Keys;
|
||||||
import de.neemann.digital.draw.elements.Circuit;
|
import de.neemann.digital.draw.elements.Circuit;
|
||||||
import de.neemann.digital.draw.elements.VisualElement;
|
import de.neemann.digital.draw.elements.VisualElement;
|
||||||
@ -16,6 +18,8 @@ import de.neemann.digital.hdl.hgs.*;
|
|||||||
import de.neemann.digital.hdl.hgs.function.Function;
|
import de.neemann.digital.hdl.hgs.function.Function;
|
||||||
import de.neemann.digital.hdl.hgs.function.InnerFunction;
|
import de.neemann.digital.hdl.hgs.function.InnerFunction;
|
||||||
import de.neemann.digital.lang.Lang;
|
import de.neemann.digital.lang.Lang;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
@ -26,39 +30,63 @@ import static de.neemann.digital.draw.shapes.GenericShape.SIZE;
|
|||||||
* Resolves a generic circuit and makes it non generic
|
* Resolves a generic circuit and makes it non generic
|
||||||
*/
|
*/
|
||||||
public class ResolveGenerics {
|
public class ResolveGenerics {
|
||||||
|
private static final Logger LOGGER = LoggerFactory.getLogger(ResolveGenerics.class);
|
||||||
|
private static final Context EMPTY_CONTEXT = new Context();
|
||||||
|
|
||||||
|
public static final String GEN_ARGS_KEY = "genArgs";
|
||||||
private final HashMap<String, Statement> map;
|
private final HashMap<String, Statement> map;
|
||||||
private LibraryInterface library;
|
private final HashMap<Context, CircuitHolder> circuitMap;
|
||||||
|
private final Circuit circuit;
|
||||||
|
private final LibraryInterface library;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a new instance
|
* Creates a new instance
|
||||||
|
*
|
||||||
|
* @param circuit the circuit to resolve
|
||||||
|
* @param library the library to ude
|
||||||
*/
|
*/
|
||||||
public ResolveGenerics() {
|
public ResolveGenerics(Circuit circuit, LibraryInterface library) {
|
||||||
|
this.circuit = circuit;
|
||||||
|
this.library = library;
|
||||||
map = new HashMap<>();
|
map = new HashMap<>();
|
||||||
|
circuitMap = new HashMap<>();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Resolves the generics
|
* Resolves the generics
|
||||||
*
|
*
|
||||||
* @param visualElement the visual element
|
* @param attributes the visual elements attributes
|
||||||
* @param circuit the circuit to resolve
|
|
||||||
* @param library the library to ude
|
|
||||||
* @return the resolved circuit
|
* @return the resolved circuit
|
||||||
* @throws NodeException NodeException
|
* @throws NodeException NodeException
|
||||||
* @throws ElementNotFoundException ElementNotFoundException
|
* @throws ElementNotFoundException ElementNotFoundException
|
||||||
*/
|
*/
|
||||||
public CircuitHolder resolveCircuit(VisualElement visualElement, Circuit circuit, LibraryInterface library) throws NodeException, ElementNotFoundException {
|
public CircuitHolder resolveCircuit(ElementAttributes attributes) throws NodeException, ElementNotFoundException {
|
||||||
this.library = library;
|
Context context = EMPTY_CONTEXT;
|
||||||
|
if (attributes != null)
|
||||||
|
context = (Context) attributes.getFromCache(GEN_ARGS_KEY);
|
||||||
|
|
||||||
|
CircuitHolder ch = circuitMap.get(context);
|
||||||
|
if (ch == null) {
|
||||||
|
ch = innerResolveCircuit(attributes);
|
||||||
|
circuitMap.put(context, ch);
|
||||||
|
}
|
||||||
|
return ch;
|
||||||
|
}
|
||||||
|
|
||||||
|
public CircuitHolder innerResolveCircuit(ElementAttributes parentAttributes) throws NodeException, ElementNotFoundException {
|
||||||
|
LOGGER.info("create concrete circuit based on " + circuit.getOrigin());
|
||||||
final Circuit c = circuit.createDeepCopy();
|
final Circuit c = circuit.createDeepCopy();
|
||||||
ArrayList<VisualElement> newComponents = new ArrayList<>();
|
ArrayList<VisualElement> newComponents = new ArrayList<>();
|
||||||
|
final Args args = createArgs(parentAttributes, c, newComponents);
|
||||||
final Args args = createArgs(visualElement, c, newComponents);
|
|
||||||
|
|
||||||
for (VisualElement ve : c.getElements()) {
|
for (VisualElement ve : c.getElements()) {
|
||||||
String gen = ve.getElementAttributes().get(Keys.GENERIC).trim();
|
ElementAttributes elementAttributes = ve.getElementAttributes();
|
||||||
|
String gen = elementAttributes.get(Keys.GENERIC).trim();
|
||||||
try {
|
try {
|
||||||
if (!gen.isEmpty()) {
|
if (!gen.isEmpty()) {
|
||||||
boolean isCustom = library.getElementType(ve.getElementName(), ve.getElementAttributes()).isCustom();
|
ElementTypeDescription elementTypeDescription = library.getElementType(ve.getElementName(), elementAttributes);
|
||||||
|
|
||||||
|
boolean isCustom = elementTypeDescription instanceof ElementTypeDescriptionCustom;
|
||||||
Statement genS = getStatement(gen);
|
Statement genS = getStatement(gen);
|
||||||
Context mod = createContext(c, newComponents);
|
Context mod = createContext(c, newComponents);
|
||||||
if (isCustom) {
|
if (isCustom) {
|
||||||
@ -67,10 +95,10 @@ public class ResolveGenerics {
|
|||||||
genS.execute(mod);
|
genS.execute(mod);
|
||||||
} else {
|
} else {
|
||||||
mod.declareVar("args", args)
|
mod.declareVar("args", args)
|
||||||
.declareVar("this", new SubstituteLibrary.AllowSetAttributes(ve.getElementAttributes()));
|
.declareVar("this", new SubstituteLibrary.AllowSetAttributes(elementAttributes));
|
||||||
genS.execute(mod);
|
genS.execute(mod);
|
||||||
}
|
}
|
||||||
ve.setGenericArgs(mod);
|
elementAttributes.putToCache(GEN_ARGS_KEY, mod);
|
||||||
}
|
}
|
||||||
} catch (HGSEvalException | ParserException | IOException e) {
|
} catch (HGSEvalException | ParserException | IOException e) {
|
||||||
final NodeException ex = new NodeException(Lang.get("err_evaluatingGenericsCode_N_N", ve, gen), e);
|
final NodeException ex = new NodeException(Lang.get("err_evaluatingGenericsCode_N_N", ve, gen), e);
|
||||||
@ -97,18 +125,18 @@ public class ResolveGenerics {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private Args createArgs(VisualElement visualElement, Circuit circuit, ArrayList<VisualElement> newComponents) throws NodeException {
|
private Args createArgs(ElementAttributes attributes, Circuit circuit, ArrayList<VisualElement> newComponents) throws NodeException {
|
||||||
Context context;
|
Context context;
|
||||||
if (visualElement != null) {
|
if (attributes != null) {
|
||||||
context = visualElement.getGenericArgs();
|
context = (Context) attributes.getFromCache(GEN_ARGS_KEY);
|
||||||
if (context == null) {
|
if (context == null) {
|
||||||
String argsCode = visualElement.getElementAttributes().get(Keys.GENERIC);
|
String argsCode = attributes.get(Keys.GENERIC);
|
||||||
try {
|
try {
|
||||||
Statement s = getStatement(argsCode);
|
Statement s = getStatement(argsCode);
|
||||||
context = createContext(circuit, newComponents);
|
context = createContext(circuit, newComponents);
|
||||||
s.execute(context);
|
s.execute(context);
|
||||||
} catch (HGSEvalException | ParserException | IOException e) {
|
} catch (HGSEvalException | ParserException | IOException e) {
|
||||||
final NodeException ex = new NodeException(Lang.get("err_evaluatingGenericsCode_N_N", visualElement, argsCode), e);
|
final NodeException ex = new NodeException(Lang.get("err_evaluatingGenericsCode_N_N", null, argsCode), e);
|
||||||
ex.setOrigin(circuit.getOrigin());
|
ex.setOrigin(circuit.getOrigin());
|
||||||
throw ex;
|
throw ex;
|
||||||
}
|
}
|
||||||
@ -214,16 +242,16 @@ public class ResolveGenerics {
|
|||||||
circuit.delete(gic);
|
circuit.delete(gic);
|
||||||
for (VisualElement v : circuit.getElements()) {
|
for (VisualElement v : circuit.getElements()) {
|
||||||
try {
|
try {
|
||||||
boolean isCustom = library.getElementType(v.getElementName(), v.getElementAttributes()).isCustom();
|
boolean isCustom = library.getElementType(v.getElementName(), v.getElementAttributes()) instanceof ElementTypeDescriptionCustom;
|
||||||
if (isCustom)
|
if (isCustom)
|
||||||
v.getElementAttributes().set(Keys.GENERIC, createGenericCode(v.getGenericArgs()));
|
v.getElementAttributes().set(Keys.GENERIC, createGenericCode((Context) v.getElementAttributes().getFromCache(GEN_ARGS_KEY)));
|
||||||
else
|
else
|
||||||
v.getElementAttributes().set(Keys.GENERIC, "");
|
v.getElementAttributes().set(Keys.GENERIC, "");
|
||||||
} catch (ElementNotFoundException e) {
|
} catch (ElementNotFoundException e) {
|
||||||
// can not happen
|
// can not happen
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
v.setGenericArgs(null);
|
v.getElementAttributes().putToCache(GEN_ARGS_KEY, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
circuit.getAttributes().set(Keys.IS_GENERIC, false);
|
circuit.getAttributes().set(Keys.IS_GENERIC, false);
|
||||||
|
@ -65,7 +65,7 @@ public class ModelCreator implements Iterable<ModelEntry> {
|
|||||||
*/
|
*/
|
||||||
public static Circuit fixGenerics(Circuit circuit, LibraryInterface library) throws NodeException, ElementNotFoundException {
|
public static Circuit fixGenerics(Circuit circuit, LibraryInterface library) throws NodeException, ElementNotFoundException {
|
||||||
if (circuit.getAttributes().get(Keys.IS_GENERIC))
|
if (circuit.getAttributes().get(Keys.IS_GENERIC))
|
||||||
return new ResolveGenerics().resolveCircuit(null, circuit, library).getCircuit();
|
return new ResolveGenerics(circuit, library).resolveCircuit(null).getCircuit();
|
||||||
else
|
else
|
||||||
return circuit;
|
return circuit;
|
||||||
}
|
}
|
||||||
@ -170,7 +170,7 @@ public class ModelCreator implements Iterable<ModelEntry> {
|
|||||||
combineNames(subName, me.getVisualElement().getElementAttributes().getLabel()),
|
combineNames(subName, me.getVisualElement().getElementAttributes().getLabel()),
|
||||||
depth + 1,
|
depth + 1,
|
||||||
containingVisualElement != null ? containingVisualElement : me.getVisualElement(),
|
containingVisualElement != null ? containingVisualElement : me.getVisualElement(),
|
||||||
me.getVisualElement(), library);
|
me.getVisualElement());
|
||||||
modelCreators.add(child);
|
modelCreators.add(child);
|
||||||
|
|
||||||
HashMap<Net, Net> netMatch = new HashMap<>();
|
HashMap<Net, Net> netMatch = new HashMap<>();
|
||||||
|
@ -33,8 +33,13 @@ public class TextShape implements Shape {
|
|||||||
*/
|
*/
|
||||||
public TextShape(ElementAttributes attr, PinDescriptions inputs, PinDescriptions outputs) {
|
public TextShape(ElementAttributes attr, PinDescriptions inputs, PinDescriptions outputs) {
|
||||||
String text = attr.get(Keys.DESCRIPTION);
|
String text = attr.get(Keys.DESCRIPTION);
|
||||||
if (text.length() == 0)
|
if (text.length() == 0) {
|
||||||
|
String gen = attr.get(Keys.GENERIC);
|
||||||
|
if (gen.isEmpty())
|
||||||
text = Lang.get("elem_Text");
|
text = Lang.get("elem_Text");
|
||||||
|
else
|
||||||
|
text = gen.replace(" ", "\u00A0");
|
||||||
|
}
|
||||||
this.text = Lang.evalMultilingualContent(text);
|
this.text = Lang.evalMultilingualContent(text);
|
||||||
|
|
||||||
fontSize = attr.get(Keys.FONT_SIZE);
|
fontSize = attr.get(Keys.FONT_SIZE);
|
||||||
|
@ -375,7 +375,7 @@ public final class Main extends JFrame implements ClosingWindowListener.ConfirmS
|
|||||||
file = new File(name);
|
file = new File(name);
|
||||||
try {
|
try {
|
||||||
ElementTypeDescriptionCustom description =
|
ElementTypeDescriptionCustom description =
|
||||||
ElementLibrary.createCustomDescription(file, circuit);
|
ElementLibrary.createCustomDescription(file, circuit, library);
|
||||||
description.setShortName(name);
|
description.setShortName(name);
|
||||||
description.setDescription(Lang.evalMultilingualContent(circuit.getAttributes().get(Keys.DESCRIPTION)));
|
description.setDescription(Lang.evalMultilingualContent(circuit.getAttributes().get(Keys.DESCRIPTION)));
|
||||||
new ElementHelpDialog(Main.this, description, circuit.getAttributes()).setVisible(true);
|
new ElementHelpDialog(Main.this, description, circuit.getAttributes()).setVisible(true);
|
||||||
|
@ -1176,8 +1176,8 @@ public class CircuitComponent extends JComponent implements ChangedListener, Lib
|
|||||||
modify(checkNetRename(element, modified, mod));
|
modify(checkNetRename(element, modified, mod));
|
||||||
}
|
}
|
||||||
|
|
||||||
Circuit concreteCircuit = new ResolveGenerics()
|
Circuit concreteCircuit = new ResolveGenerics(getCircuit(), library)
|
||||||
.resolveCircuit(element, getCircuit(), library)
|
.resolveCircuit(element.getElementAttributes())
|
||||||
.cleanupConcreteCircuit()
|
.cleanupConcreteCircuit()
|
||||||
.getCircuit();
|
.getCircuit();
|
||||||
|
|
||||||
|
@ -36,7 +36,6 @@ import static de.neemann.digital.draw.model.ModelCreator.fixGenerics;
|
|||||||
public class HDLModel implements Iterable<HDLCircuit> {
|
public class HDLModel implements Iterable<HDLCircuit> {
|
||||||
private final ElementLibrary elementLibrary;
|
private final ElementLibrary elementLibrary;
|
||||||
private final HashMap<Circuit, HDLCircuit> circuitMap;
|
private final HashMap<Circuit, HDLCircuit> circuitMap;
|
||||||
private final ResolveGenerics resolveGenerics = new ResolveGenerics();
|
|
||||||
private final HashMap<String, GenericsCache> genericInstanceNumbers;
|
private final HashMap<String, GenericsCache> genericInstanceNumbers;
|
||||||
private HDLCircuit main;
|
private HDLCircuit main;
|
||||||
private Renaming renaming;
|
private Renaming renaming;
|
||||||
@ -68,7 +67,7 @@ public class HDLModel implements Iterable<HDLCircuit> {
|
|||||||
|
|
||||||
final Circuit circuit = tdc.getCircuit();
|
final Circuit circuit = tdc.getCircuit();
|
||||||
if (circuit.getAttributes().get(Keys.IS_GENERIC)) {
|
if (circuit.getAttributes().get(Keys.IS_GENERIC)) {
|
||||||
ResolveGenerics.CircuitHolder holder = resolveGenerics.resolveCircuit(v, circuit, elementLibrary);
|
ResolveGenerics.CircuitHolder holder = new ResolveGenerics(circuit, elementLibrary).resolveCircuit(v.getElementAttributes());
|
||||||
|
|
||||||
GenericsCache cache = genericInstanceNumbers.computeIfAbsent(v.getElementName(), t -> new GenericsCache());
|
GenericsCache cache = genericInstanceNumbers.computeIfAbsent(v.getElementName(), t -> new GenericsCache());
|
||||||
|
|
||||||
|
@ -53,7 +53,7 @@ public class TestExecutor {
|
|||||||
static private Model createModel(Circuit.TestCase testCase, Circuit circuit, ElementLibrary library) throws NodeException, ElementNotFoundException, PinException {
|
static private Model createModel(Circuit.TestCase testCase, Circuit circuit, ElementLibrary library) throws NodeException, ElementNotFoundException, PinException {
|
||||||
final Model model;
|
final Model model;
|
||||||
if (circuit != null && circuit.getAttributes().get(Keys.IS_GENERIC) && testCase.hasGenericCode()) {
|
if (circuit != null && circuit.getAttributes().get(Keys.IS_GENERIC) && testCase.hasGenericCode()) {
|
||||||
Circuit c = new ResolveGenerics().resolveCircuit(testCase.getVisualElement(), circuit, library).getCircuit();
|
Circuit c = new ResolveGenerics(circuit, library).resolveCircuit(testCase.getVisualElement().getElementAttributes()).getCircuit();
|
||||||
model = new ModelCreator(c, library, false).createModel(false);
|
model = new ModelCreator(c, library, false).createModel(false);
|
||||||
} else
|
} else
|
||||||
model = new ModelCreator(circuit, library).createModel(false);
|
model = new ModelCreator(circuit, library).createModel(false);
|
||||||
|
@ -23,6 +23,8 @@ import junit.framework.TestCase;
|
|||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
import static de.neemann.digital.draw.library.ResolveGenerics.GEN_ARGS_KEY;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Reads all examples and tries to create the model.
|
* Reads all examples and tries to create the model.
|
||||||
* Makes sure that all examples are creatable (one can build the model)
|
* Makes sure that all examples are creatable (one can build the model)
|
||||||
@ -32,6 +34,12 @@ public class TestExamples extends TestCase {
|
|||||||
|
|
||||||
private int testCasesInFiles;
|
private int testCasesInFiles;
|
||||||
|
|
||||||
|
|
||||||
|
public void testDebug() throws Exception {
|
||||||
|
File f = new File("/home/hneemann/Dokumente/Java/digital/src/main/dig/generic/barrelShifter/TestBarrelShifter.dig");
|
||||||
|
check(f);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests the examples which are distributed
|
* Tests the examples which are distributed
|
||||||
*
|
*
|
||||||
@ -123,13 +131,13 @@ public class TestExamples extends TestCase {
|
|||||||
|
|
||||||
VisualElement element = initCodeList.get(0);
|
VisualElement element = initCodeList.get(0);
|
||||||
|
|
||||||
Circuit concreteCircuit = new ResolveGenerics()
|
Circuit concreteCircuit = new ResolveGenerics(circuit, library)
|
||||||
.resolveCircuit(element, circuit, library)
|
.resolveCircuit(element.getElementAttributes())
|
||||||
.cleanupConcreteCircuit()
|
.cleanupConcreteCircuit()
|
||||||
.getCircuit();
|
.getCircuit();
|
||||||
|
|
||||||
for (VisualElement ve : concreteCircuit.getElements()) {
|
for (VisualElement ve : concreteCircuit.getElements()) {
|
||||||
assertNull(ve.getGenericArgs());
|
assertNull(ve.getElementAttributes().getFromCache(GEN_ARGS_KEY));
|
||||||
assertFalse(ve.equalsDescription(GenericInitCode.DESCRIPTION));
|
assertFalse(ve.equalsDescription(GenericInitCode.DESCRIPTION));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user