📄 jelibparser.java
字号:
for (revision = 0; revision < revisions.length; revision++) { if (version.compareTo(Version.parseVersion(revisions[revision])) < 0) break; } escapeChar = revision < 1 ? '^' : '\\'; pieces = parseLine(line); curLibName = unQuote(pieces.get(0)); if (version.compareTo(Version.getVersion()) > 0) { logWarning("Library " + curLibName + " comes from a NEWER version of Electric (" + version + ")"); } libVars = readVariables(pieces, 2); continue; } if (first == 'O') { // parse Tool information List<String> pieces = parseLine(line); String toolName = unQuote(pieces.get(0)); // get additional meaning preferences starting at position 1 Variable[] vars = readVariables(pieces, 1); if (!tools.containsKey(toolName)) tools.put(toolName, vars); continue; } if (first == 'V') { // parse View information List<String> pieces = parseLine(line); String viewName = unQuote(pieces.get(0)); View view = View.findView(viewName); if (view == null) { String viewAbbr = unQuote(pieces.get(1)); view = View.newInstance(viewName, viewAbbr); if (view == null) { logError("Cannot create view " + viewName); continue; } } // get additional variables starting at position 2 Variable[] vars = readVariables(pieces, 2); continue; } if (first == 'T') { // parse Technology information List<String> pieces = parseLine(line); String techName = unQuote(pieces.get(0)); curTechId = idManager.newTechId(techName); curPrimId = null; // get additional meaning preferences starting at position 1 Variable[] vars = readVariables(pieces, 1); if (!techIds.containsKey(curTechId)) techIds.put(curTechId, vars); continue; } if (first == 'D') { // parse PrimitiveNode information List<String> pieces = parseLine(line); String primName = unQuote(pieces.get(0)); if (curTechId == null) { logError("Primitive node " + primName + " has no technology before it"); continue; } curPrimId = curTechId.newPrimitiveNodeId(primName); // get additional variables starting at position 1 Variable[] vars = readVariables(pieces, 1); if (!primitiveNodeIds.containsKey(curPrimId)) primitiveNodeIds.put(curPrimId, vars); continue; } if (first == 'P') { // parse PrimitivePort information List<String> pieces = parseLine(line); String primPortName = unQuote(pieces.get(0)); if (curPrimId == null) { logError("Primitive port " + primPortName + " has no primitive node before it"); continue; } PrimitivePortId primitivePortId = curPrimId.newPortId(primPortName); // get additional variables starting at position 1 Variable[] vars = readVariables(pieces, 1); if (!primitivePortIds.containsKey(primitivePortId)) primitivePortIds.put(primitivePortId, vars); continue; } if (first == 'W') { // parse ArcProto information List<String> pieces = parseLine(line); String arcName = unQuote(pieces.get(0)); if (curTechId == null) { logError("Primitive arc " + arcName + " has no technology before it"); continue; } ArcProtoId arcProtoId = curTechId.newArcProtoId(arcName); // get additional variables starting at position 1 Variable[] vars = readVariables(pieces, 1); if (!arcProtoIds.containsKey(arcProtoId)) arcProtoIds.put(arcProtoId, vars); continue; } if (first == 'G') { // group information List<String> pieces = parseLine(line); String firstProtoName = null; for(int i=0; i<pieces.size(); i++) { String cellNameString = unQuote(pieces.get(i)); if (cellNameString.length() == 0) continue; int colonPos = cellNameString.indexOf(':'); if (colonPos >= 0) cellNameString = cellNameString.substring(colonPos+1); CellName cellName = CellName.parseName(cellNameString); if (cellName == null) { logError("Bad cell name " + cellNameString); continue; } if (cellsWithProtoName.get(cellName.getName()) == null) { logError("Unknown cell " + cellName); continue; } String protoName = cellName.getName(); if (firstProtoName == null) firstProtoName = protoName; else transitiveProtoNames.theseAreRelated(firstProtoName, protoName); } continue; } logError("Unrecognized line: " + line); } } private void readDelibCell(String line) throws IOException { // get the file location; remove 'C' at start String cellFile = line.substring(1, line.length()); // New header file as of version 8.04n, no cell refs, searches delib dir for cell files if (version.compareTo(newDelibHeaderVersion) >= 0) { if (cellFile.equals(com.sun.electric.tool.io.output.DELIB.SEARCH_FOR_CELL_FILES)) { File delibDir = new File(filePath); if (delibDir.exists() && delibDir.isDirectory()) { for (File file : delibDir.listFiles()) { if (file.isDirectory()) continue; String name = file.getName(); int dot = name.lastIndexOf('.'); if (dot < 0) continue; View view = View.findView(name.substring(dot+1)); if (view == null) continue; try { readDelibFile(file); } catch (Exception e) { if (e instanceof IOException) throw (IOException)e; // some other exception, probably invalid cell file Input.errorLogger.logError("Exception reading file "+file, -1); } } } } return; } cellFile = cellFile.replace(com.sun.electric.tool.io.output.DELIB.PLATFORM_INDEPENDENT_FILE_SEPARATOR, File.separatorChar); File cellFD = new File(filePath, cellFile); readDelibFile(cellFD); } private void readDelibFile(File cellFD) throws IOException { LineNumberReader cellReader; try { FileInputStream fin = new FileInputStream(cellFD); InputStreamReader is = new InputStreamReader(fin); cellReader = new LineNumberReader(is); } catch (IOException e) { System.out.println("Error opening file "+cellFD+": "+e.getMessage()); return; } Version savedVersion = version; int savedRevision = revision; char savedEscapeChar = escapeChar; String savedCurLibName = curLibName; lineReader = cellReader; curReadFile = cellFD.getAbsolutePath(); try { readFromFile(false); delibCellFiles.add(curReadFile); } finally { version = savedVersion; revision = savedRevision; escapeChar = savedEscapeChar; curLibName = savedCurLibName; lineReader.close(); lineReader = delibHeaderReader; curReadFile = filePath; } } private void readCell(String line) throws IOException { // grab a cell description List<String> pieces = parseLine(line); int numPieces = revision >= 2 ? 6 : revision == 1 ? 5 : 7; if (pieces.size() < numPieces) { logError("Cell declaration needs " + numPieces + " fields: " + line); return; } int fieldIndex = 0; String name; String groupName = null; if (revision >= 1) { name = unQuote(pieces.get(fieldIndex++)); if (revision >= 2) { String s = pieces.get(fieldIndex++); if (s.length() > 0) groupName = unQuote(s); } } else { name = unQuote(pieces.get(fieldIndex++)); String viewAbbrev = pieces.get(fieldIndex++); String versionString = pieces.get(fieldIndex++); name = name + ";" + versionString + "{" + viewAbbrev + "}"; } CellName cellName = CellName.parseName(name); CellContents cc = new CellContents(version); cc.fileName = curReadFile; cc.lineNumber = lineReader.getLineNumber() + 1; cc.cellId = libId.newCellId(cellName); String techName = unQuote(pieces.get(fieldIndex++)); cc.techId = idManager.newTechId(techName); cc.creationDate = Long.parseLong(pieces.get(fieldIndex++)); cc.revisionDate = Long.parseLong(pieces.get(fieldIndex++)); // parse state information String stateInfo = pieces.get(fieldIndex++); for(int i=0; i<stateInfo.length(); i++) { switch (stateInfo.charAt(i)) { case 'E': cc.expanded = true; break; case 'L': cc.allLocked = true; break; case 'I': cc.instLocked = true; break; case 'C': cc.cellLib = true; break; case 'T': cc.techLib = true; break; } } // add variables assert fieldIndex == numPieces; cc.vars = readVariables(pieces, numPieces); // gather the contents of the cell for(;;) { String nextLine = lineReader.readLine(); if (nextLine == null) break; if (nextLine.length() == 0) continue; char nextFirst = nextLine.charAt(0); if (nextFirst == 'X') break; switch (nextFirst) { case '#': break; case 'N': case 'I': parseNode(nextLine, cc); break; case 'E': parseExport(nextLine, cc); break; case 'A': parseArc(nextLine, cc); break; default: } } // check if the version is not null if (cc.version == null) { logError("Version for Cell '" + cc.cellId.cellName + "' is null"); return; } // remember the contents of the cell for later if (allCells.containsKey(cc.cellId)) { logError("Duplicate cell " + cc.cellId); return; } String protoName = cellName.getName(); if (groupName == null) groupName = protoName; transitiveProtoNames.theseAreRelated(protoName, groupName); allCells.put(cc.cellId, cc); ArrayList<CellContents> list = cellsWithProtoName.get(protoName); if (list == null) { list = new ArrayList<CellContents>(); cellsWithProtoName.put(protoName, list); } list.add(cc); return; } private void parseNode(String cellString, CellContents cc) { NodeContents n = new NodeContents(); n.line = lineReader.getLineNumber(); // parse the node line List<String> pieces = parseLine(cellString); char firstChar = cellString.charAt(0); int numPieces = revision < 1 ? 10 : firstChar == 'N' ? 9 : 8; if (pieces.size() < numPieces) { logError("Node instance needs " + numPieces + " fields: " + cellString, cc.cellId); return; } String protoName = unQuote(pieces.get(0)); // figure out the name for this node. Handle the form: "Sig"12 String diskNodeName = revision >= 1 ? pieces.get(1) : unQuote(pieces.get(1)); String nodeName = diskNodeName; if (nodeName.charAt(0) == '"') { int lastQuote = nodeName.lastIndexOf('"'); if (lastQuote > 1) { nodeName = nodeName.substring(1, lastQuote); if (revision >= 1) nodeName = unQuote(nodeName); } } n.nodeName = nodeName; String nameTextDescriptorInfo = pieces.get(2); double x = readDouble(pieces.get(3)); double y = readDouble(pieces.get(4)); LibId libId = cc.cellId.libId; String prefixName = libId.libName; int colonPos = protoName.indexOf(':'); if (colonPos < 0) { if (firstChar == 'I' || revision < 1) n.protoId = libId.newCellId(CellName.parseName(protoName)); else n.protoId = cc.techId.newPrimitiveNodeId(protoName); } else { prefixName = protoName.substring(0, colonPos); protoName = protoName.substring(colonPos+1); if (firstChar == 'I' || revision < 1 && protoName.indexOf('{') >= 0) { if (!prefixName.equals(curLibName)) libId = idManager.newLibId(prefixName); n.protoId = libId.newCellId(CellName.parseName(protoName)); } else { n.protoId = idManager.newTechId(prefixName).newPrimitiveNodeId(protoName); } } n.size = EPoint.ORIGIN; boolean flipX = false, flipY = false; String orientString; String stateInfo; String textDescriptorInfo = ""; if (firstChar == 'N' || revision < 1) { double wid = readDouble(pieces.get(5)); if (revision < 1 && (wid < 0 || wid == 0 && 1/wid < 0)) { flipX = true; wid = -wid; } double hei = readDouble(pieces.get(6)); if (revision < 1 && (hei < 0 || hei == 0 && 1/hei < 0)) { flipY = true; hei = -hei; } if (n.protoId instanceof PrimitiveNodeId) n.size = EPoint.fromLambda(wid, hei); orientString = pieces.get(7); stateInfo = pieces.get(8); if (revision < 1) textDescriptorInfo = pieces.get(9); } else { orientString = pieces.get(5); stateInfo = pieces.get(6); textDescriptorInfo = pieces.get(7); } int angle = 0; for (int i = 0; i < orientString.length(); i++) { char ch = orientString.charAt(i); if (ch == 'X') flipX = !flipX; else if (ch == 'Y') flipY = !flipY; else if (ch == 'R') angle += 900; else { angle += Integer.valueOf(orientString.substring(i)); break; } } // parse state information in stateInfo field TextDescriptorAndCode nameTdC = loadTextDescriptor(nameTextDescriptorInfo, false); n.nameTextDescriptor = nameTdC.td; int flags = 0, techBits = 0; // parse state information in jelibUserBits parseStateInfo: for(int i=0; i<stateInfo.length(); i++) { char chr = stateInfo.charAt(i); switch (chr) { case 'E': /*flags = ImmutableNodeInst.EXPAND.set(flags, true);*/ break; case 'L': flags = ImmutableNodeInst.LOCKED.set(flags, true); break;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -