fixes a consistency issue

This commit is contained in:
hneemann 2021-01-07 10:24:48 +01:00
parent a6daa600be
commit fed6329dce
2 changed files with 21 additions and 20 deletions

View File

@ -189,7 +189,7 @@ public final class ElementTypeDescriptionCustom extends ElementTypeDescription {
try { try {
Circuit c = resolveGenerics.resolveCircuit(elementAttributes).getCircuit(); Circuit c = resolveGenerics.resolveCircuit(elementAttributes).getCircuit();
return new PinDescriptions(c.getInputNames()); return new PinDescriptions(c.getInputNames());
} catch (ElementNotFoundException | PinException e) { } catch (Exception e) {
return super.getInputDescription(elementAttributes); return super.getInputDescription(elementAttributes);
} }
} else } else
@ -202,7 +202,7 @@ public final class ElementTypeDescriptionCustom extends ElementTypeDescription {
try { try {
Circuit c = resolveGenerics.resolveCircuit(elementAttributes).getCircuit(); Circuit c = resolveGenerics.resolveCircuit(elementAttributes).getCircuit();
return new PinDescriptions(c.getOutputNames()); return new PinDescriptions(c.getOutputNames());
} catch (ElementNotFoundException | PinException | NodeException e) { } catch (Exception e) {
return super.getOutputDescriptions(elementAttributes); return super.getOutputDescriptions(elementAttributes);
} }
} else } else

View File

@ -63,18 +63,23 @@ public class ResolveGenerics {
* @throws ElementNotFoundException ElementNotFoundException * @throws ElementNotFoundException ElementNotFoundException
*/ */
public CircuitHolder resolveCircuit(ElementAttributes attributes) throws NodeException, ElementNotFoundException { public CircuitHolder resolveCircuit(ElementAttributes attributes) throws NodeException, ElementNotFoundException {
try {
Args args; Args args;
if (attributes == null || attributes.get(Keys.GENERIC).isEmpty()) if (attributes == null)
args = createArgsFromGenericBlock(); args = createArgsFromGenericInitBlock();
else else
args = createArgsFromParentCircuitEmbedding(attributes); args = createArgsFromParentCircuitEmbedding(attributes);
CircuitHolder ch = circuitMap.get(args); CircuitHolder ch = circuitMap.get(args);
if (ch == null) { if (ch == null) {
ch = innerResolveCircuit(args); ch = createResolvedCircuit(args);
circuitMap.put(args, ch); circuitMap.put(args, ch);
} }
return ch; return ch;
} catch (NodeException e) {
e.setOrigin(circuit.getOrigin());
throw e;
}
} }
private Args createArgsFromParentCircuitEmbedding(ElementAttributes attributes) throws NodeException { private Args createArgsFromParentCircuitEmbedding(ElementAttributes attributes) throws NodeException {
@ -86,15 +91,13 @@ public class ResolveGenerics {
context = new Context(); context = new Context();
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", null, argsCode), e); throw new NodeException(Lang.get("err_evaluatingGenericsCode_N_N", null, argsCode), e);
ex.setOrigin(circuit.getOrigin());
throw ex;
} }
} }
return new Args(context); return new Args(context);
} }
private Args createArgsFromGenericBlock() throws NodeException { private Args createArgsFromGenericInitBlock() throws NodeException {
Context context = new Context(); Context context = new Context();
List<VisualElement> g = circuit.getElements(v -> v.equalsDescription(GenericInitCode.DESCRIPTION) && v.getElementAttributes().get(Keys.ENABLED)); List<VisualElement> g = circuit.getElements(v -> v.equalsDescription(GenericInitCode.DESCRIPTION) && v.getElementAttributes().get(Keys.ENABLED));
if (g.size() == 0) if (g.size() == 0)
@ -118,7 +121,7 @@ public class ResolveGenerics {
return new Args(context); return new Args(context);
} }
private CircuitHolder innerResolveCircuit(Args args) throws NodeException, ElementNotFoundException { private CircuitHolder createResolvedCircuit(Args args) throws NodeException, ElementNotFoundException {
LOGGER.info("create concrete circuit based on " + circuit.getOrigin() + " width: " + args); LOGGER.info("create concrete circuit based on " + circuit.getOrigin() + " width: " + args);
final Circuit c = circuit.createDeepCopy(); final Circuit c = circuit.createDeepCopy();
ArrayList<VisualElement> newComponents = new ArrayList<>(); ArrayList<VisualElement> newComponents = new ArrayList<>();
@ -144,9 +147,7 @@ public class ResolveGenerics {
elementAttributes.putToCache(GEN_ARGS_KEY, 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); throw new NodeException(Lang.get("err_evaluatingGenericsCode_N_N", ve, gen), e);
ex.setOrigin(circuit.getOrigin());
throw ex;
} }
} }
for (VisualElement ve : newComponents) for (VisualElement ve : newComponents)