📄 immutablenodeinst.java
字号:
public ImmutableNodeInst withOrient(Orientation orient) { if (this.orient == orient) return this; if (orient == null) throw new NullPointerException("orient"); if (isCellCenter(protoId)) return this; return newInstance(this.nodeId, this.protoId, this.name, this.nameDescriptor, orient, this.anchor, this.size, this.flags, this.techBits, this.protoDescriptor, getVars(), this.ports, getDefinedParams()); } /** * Returns ImmutableNodeInst which differs from this ImmutableNodeInst by anchor point. * @param anchor node anchor point. * @return ImmutableNodeInst which differs from this ImmutableNodeInst by anchor point. * @throws NullPointerException if anchor is null. */ public ImmutableNodeInst withAnchor(EPoint anchor) { if (this.anchor.equals(anchor)) return this; if (anchor == null) throw new NullPointerException("anchor"); if (isCellCenter(protoId)) return this; return newInstance(this.nodeId, this.protoId, this.name, this.nameDescriptor, this.orient, anchor, this.size, this.flags, this.techBits, this.protoDescriptor, getVars(), this.ports, getDefinedParams()); } /** * Returns ImmutableNodeInst which differs from this ImmutableNodeInst by size. * @param size a point with x as size and y as height. * @return ImmutableNodeInst which differs from this ImmutableNodeInst by size. * @throws IllegalArgumentException if width or height is negative. */ public ImmutableNodeInst withSize(EPoint size) { if (this.size.equals(size)) return this; if (size == null) throw new NullPointerException("size");// if (size.getGridX() < 0 || size.getGridY() < 0) throw new IllegalArgumentException("size is " + size); if (isCellCenter(protoId)) return this; if (protoId instanceof CellId) return this; return newInstance(this.nodeId, this.protoId, this.name, this.nameDescriptor, this.orient, this.anchor, size, this.flags, this.techBits, this.protoDescriptor, getVars(), this.ports, getDefinedParams()); } /** * Returns ImmutableNodeInst which differs from this ImmutableNodeInst by flag bits. * @param flags flag bits defined by ImmutableNodeInst.Flag. * @return ImmutableNodeInst which differs from this ImmutableNodeInst by flag bit. */ private ImmutableNodeInst withFlags(int flags) { flags &= FLAG_BITS; if (this.flags == flags) return this; return newInstance(this.nodeId, this.protoId, this.name, this.nameDescriptor, this.orient, this.anchor, this.size, flags, this.techBits, this.protoDescriptor, getVars(), this.ports, getDefinedParams()); } /** * Returns ImmutableNodeInst which differs from this ImmutableNodeInst by state bits. * State bits are flags and tech-specifiic bits. * @param d another ImmutableNodeInst where to take state bits. * @return ImmutableNodeInst which differs from this ImmutableNodeInst by state bit. */ public ImmutableNodeInst withStateBits(ImmutableNodeInst d) { return withFlags(d.flags).withTechSpecific(d.techBits); } /** * Returns ImmutableNodeInst which differs from this ImmutableNodeInst by flag bit. * @param flag Flag selector. * @param value new value of flag. * @return ImmutableNodeInst which differs from this ImmutableNodeInst by flag bit. */ public ImmutableNodeInst withFlag(Flag flag, boolean value) { return withFlags(flag.set(this.flags, value)); } /** * Returns ImmutableNodeInst which differs from this ImmutableNodeInst by tech specific bits. * This is mostly used by the Schematics technology which allows variations * on a NodeInst to be stored. * For example, the Transistor primitive uses these bits to distinguish nMOS, pMOS, etc. * @param techBits the Technology-specific value to store on this NodeInst. * @return ImmutableNodeInst which differs from this ImmutableNodeInst by tech bits. */ public ImmutableNodeInst withTechSpecific(int techBits) { techBits &= NTECHBITS >> NTECHBITSSH; if (this.techBits == techBits) return this; return newInstance(this.nodeId, this.protoId, this.name, this.nameDescriptor, this.orient, this.anchor, this.size, this.flags, (byte)techBits, this.protoDescriptor, getVars(), this.ports, getDefinedParams()); } /** * Returns ImmutableNodeInst which differs from this ImmutableNodeInst by proto descriptor. * @param protoDescriptor TextDescriptor of proto * @return ImmutableNodeInst which differs from this ImmutableNodeInst by proto descriptor. */ public ImmutableNodeInst withProtoDescriptor(TextDescriptor protoDescriptor) { if (protoDescriptor != null) protoDescriptor = protoDescriptor.withDisplayWithoutParam(); if (this.protoDescriptor == protoDescriptor) return this; return newInstance(this.nodeId, this.protoId, this.name, this.nameDescriptor, this.orient, this.anchor, this.size, this.flags, this.techBits, protoDescriptor, getVars(), this.ports, getDefinedParams()); } /** * Returns ImmutableNodeInst which differs from this ImmutableNodeInst by additional Variable. * If this ImmutableNideInst has Variable with the same key as new, the old variable will not be in new * ImmutableNodeInst. * @param var additional Variable. * @return ImmutableNodeInst with additional Variable. * @throws NullPointerException if var is null */ public ImmutableNodeInst withVariable(Variable var) { Variable[] vars = arrayWithVariable(var.withParam(false).withInherit(false)); if (this.getVars() == vars) return this; return newInstance(this.nodeId, this.protoId, this.name, this.nameDescriptor, this.orient, this.anchor, this.size, this.flags, this.techBits, this.protoDescriptor, vars, this.ports, getDefinedParams()); } /** * Returns ImmutableNodeInst which differs from this ImmutableNodeInst by removing Variable * with the specified key. Returns this ImmutableNodeInst if it doesn't contain variable with the specified key. * @param key Variable Key to remove. * @return ImmutableNodeInst without Variable with the specified key. * @throws NullPointerException if key is null */ public ImmutableNodeInst withoutVariable(Variable.Key key) { Variable[] vars = arrayWithoutVariable(key); if (this.getVars() == vars) return this; return newInstance(this.nodeId, this.protoId, this.name, this.nameDescriptor, this.orient, this.anchor, this.size, this.flags, this.techBits, this.protoDescriptor, vars, this.ports, getDefinedParams()); } /** * Returns ImmutableNodeInst which differs from this ImmutableNodeInst by renamed Ids. * @param idMapper a map from old Ids to new Ids. * @return ImmutableNodeInst with renamed Ids. */ ImmutableNodeInst withRenamedIds(IdMapper idMapper) { Variable[] vars = arrayWithRenamedIds(idMapper); NodeProtoId protoId = this.protoId; ImmutablePortInst[] ports = portsWithRenamedIds(idMapper); if (protoId instanceof CellId) protoId = idMapper.get((CellId)protoId); if (getVars() == vars && this.protoId == protoId && this.ports == ports) return this; return newInstance(this.nodeId, protoId, this.name, this.nameDescriptor, this.orient, this.anchor, this.size, this.flags, this.techBits, this.protoDescriptor, vars, ports, arrayWithRenamedIds(getDefinedParams(), idMapper)); } /** * Returns array of ImmutablePortInst which differs from array of this ImmutableNodeInst by renamed Ids. * Returns array of this ImmutableNodeInst if it doesn't contain renamed Ids. * @param idMapper a map from old Ids to new Ids. * @return array of ImmutablePortInst with renamed Ids. */ private ImmutablePortInst[] portsWithRenamedIds(IdMapper idMapper) { if (ports.length == 0) { assert ports == ImmutablePortInst.NULL_ARRAY; return ports; } if (protoId instanceof CellId) { boolean chronIndexChanged = false; int maxChronIndex = -1; CellId subCellId = (CellId)protoId; for (int chronIndex = 0; chronIndex < ports.length; chronIndex++) { ImmutablePortInst oldPort = ports[chronIndex]; if (oldPort == ImmutablePortInst.EMPTY) continue; ExportId oldExportId = subCellId.getPortId(chronIndex); assert oldExportId.chronIndex == chronIndex; ExportId newExportId = idMapper.get(oldExportId); maxChronIndex = Math.max(maxChronIndex, newExportId.chronIndex); if (newExportId.chronIndex != chronIndex) chronIndexChanged = true; } if (chronIndexChanged) { ImmutablePortInst[] newPorts = new ImmutablePortInst[maxChronIndex + 1]; assert newPorts.length > 0; Arrays.fill(newPorts, ImmutablePortInst.EMPTY); for (int chronIndex = 0; chronIndex < ports.length; chronIndex++) { ImmutablePortInst oldPort = ports[chronIndex]; if (oldPort == ImmutablePortInst.EMPTY) continue; newPorts[idMapper.get(subCellId.getPortId(chronIndex)).chronIndex] = oldPort.withRenamedIds(idMapper); } return newPorts; } } ImmutablePortInst[] newPorts = null; for (int i = 0; i < ports.length; i++) { ImmutablePortInst oldPort = ports[i]; ImmutablePortInst newPort = oldPort.withRenamedIds(idMapper); if (newPort != oldPort && newPorts == null) { newPorts = new ImmutablePortInst[ports.length]; System.arraycopy(ports, 0, newPorts, 0, i); } if (newPorts != null) newPorts[i] = newPort; } return newPorts != null ? newPorts : ports; } /** * Returns ImmutableNodeInst which differs from this ImmutableNodeInst by additional Variable on PortInst. * If this ImmutableNideInst has Variable on PortInst with the same key as new, the old variable will not be in new * ImmutableNodeInst. * @param portProtoId PortProtoId of port instance. * @return ImmutableNodeInst with additional Variable. * @throws NullPointerException if var is null */ public ImmutableNodeInst withPortInst(PortProtoId portProtoId, ImmutablePortInst portInst) { if (portProtoId.getParentId() != protoId) throw new IllegalArgumentException("portProtoId"); int portChronIndex = portProtoId.getChronIndex(); ImmutablePortInst[] newPorts; if (portChronIndex < ports.length) { if (ports[portChronIndex] == portInst) return this; if (portInst == ImmutablePortInst.EMPTY && portChronIndex == ports.length - 1) { int newLength = ports.length -1; while (newLength > 0 && ports[newLength - 1] == ImmutablePortInst.EMPTY) newLength--; if (newLength > 0) { newPorts = new ImmutablePortInst[newLength]; System.arraycopy(ports, 0, newPorts, 0, newLength); } else { newPorts = ImmutablePortInst.NULL_ARRAY; } } else { newPorts = ports.clone(); newPorts[portChronIndex] = portInst; } } else { if (portInst == ImmutablePortInst.EMPTY) return this; newPorts = new ImmutablePortInst[portChronIndex + 1]; System.arraycopy(ports, 0, newPorts, 0, ports.length); Arrays.fill(newPorts, ports.length, portChronIndex, ImmutablePortInst.EMPTY); newPorts[portChronIndex] = portInst; } return newInstance(this.nodeId, this.protoId, this.name, this.nameDescriptor, this.orient, this.anchor, this.size, this.flags, this.techBits, this.protoDescriptor, getVars(), newPorts, getDefinedParams()); } /** * Retruns true if this ImmutableNodeInst was named by user. * @return true if this ImmutableNodeInst was named by user. */ public boolean isUsernamed() { return !name.isTempname(); } /** * Returns ImmutablePortInst of this ImmutableNodeInst with the specified PortProtoId. * @param portProtoId PortProtoId of port instance. * @return ImmutablePortInst of this ImmutableNodeInst with the specified PortProtoId. * @throws NullPointerException if portProtoId is null. * @throws IlleagalArgumentException if parent of portProtoId is not protoId of this ImmutableNodeInst. */ public ImmutablePortInst getPortInst(PortProtoId portProtoId) { if (portProtoId.getParentId() != protoId) throw new IllegalArgumentException("portProtoId"); int portChronIndex = portProtoId.getChronIndex(); return portChronIndex < ports.length ? ports[portChronIndex] : ImmutablePortInst.EMPTY; } /** * Returns an Iterator over all PortProtoIds such that the correspondent PortInst on this * ImmutablePortInst has variables. * @return an Iterator over all PortProtoIds with variables. * @throws NullPointerException if portProtoId is null. * @throws IlleagalArgumentException if parent of portProtoId is not protoId of this ImmutableNodeInst. */ public Iterator<PortProtoId> getPortsWithVariables() { if (ports.length == 0) { Iterator<PortProtoId> emptyIterator = ArrayIterator.emptyIterator(); return emptyIterator; } return new PortInstIterator(); } private class PortInstIterator implements Iterator<PortProtoId> { int chronIndex; PortProtoId next; PortInstIterator() { getNext(); } public boolean hasNext() { return next != null; } public PortProtoId next() { PortProtoId result = next; if (result == null) throw new NoSuchElementException(); getNext(); return result; } public void remove() { throw new UnsupportedOperationException(); } private void getNext() { PortProtoId next = null; for (; chronIndex < ports.length; chronIndex++) { if (ports[chronIndex] != ImmutablePortInst.EMPTY) { next = protoId.getPortId(chronIndex++); break; } } this.next = next; } } /** * Returns true if this ImmutableNodeInst has variables on port instances. * @return true if this ImmutableNodeInst has variables on port instances. */ public boolean hasPortInstVariables() { return ports.length > 0; }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -