~ubuntu-branches/ubuntu/maverick/electric/maverick

« back to all changes in this revision

Viewing changes to com/sun/electric/database/CellRevision.java

  • Committer: Bazaar Package Importer
  • Author(s): Onkar Shinde
  • Date: 2010-01-09 16:26:04 UTC
  • mfrom: (1.1.4 upstream) (3.1.6 sid)
  • Revision ID: james.westby@ubuntu.com-20100109162604-1ypvmy8ijmlc6oq7
Tags: 8.10-1
* New upstream version.
* debian/control
  - Add libjava3d-java and quilt build dependencies.
  - Update standards version to 3.8.3.
  - Add libjava3d-java as recommends to binary package.
* debian/rules
  - Use quilt patch system instead of simple patchsys.
  - Add java3d related jar files to DEB_JARS.
* debian/patches/*
  - Update as per current upstream source. Convert to quilt.
* debian/ant.properties
  - Do not disable 3D plugin anymore.
  - Use new property to disable compilation of OS X related classes.
* debian/wrappers/electric
  - Add java3d related jar files to runtime classpath.
* debian/README.source
  - Change text to the appropriate one for quilt.

Show diffs side-by-side

added added

removed removed

Lines of Context:
54
54
 * This representation should be technology-independent
55
55
 */
56
56
public class CellRevision {
 
57
 
57
58
    public static final CellRevision[] NULL_ARRAY = {};
58
59
    public static final ImmutableArrayList<CellRevision> EMPTY_LIST = new ImmutableArrayList<CellRevision>(NULL_ARRAY);
59
 
 
60
60
    private static final int[] NULL_INT_ARRAY = {};
61
61
    static final CellUsageInfo[] NULL_CELL_USAGE_INFO_ARRAY = {};
62
62
    static int cellRevisionsCreated = 0;
63
 
    /** Cell persistent data. */                                    public final ImmutableCell d;
64
 
    /** An array of Exports on the Cell by chronological index. */  public final ImmutableArrayList<ImmutableExport> exports;
65
 
        /** A list of NodeInsts in this Cell. */                                                public final ImmutableArrayList<ImmutableNodeInst> nodes;
66
 
    /** A list of ArcInsts in this Cell. */                                                     public final ImmutableArrayList<ImmutableArcInst> arcs;
67
 
    /** TechId usage counts. */                                     final BitSet techUsages;
68
 
    /** CellUsageInfos indexed by CellUsage.indefInParent */        final CellUsageInfo[] cellUsages;
 
63
    /** Cell persistent data. */
 
64
    public final ImmutableCell d;
 
65
    /** An array of Exports on the Cell by chronological index. */
 
66
    public final ImmutableArrayList<ImmutableExport> exports;
 
67
    /** A list of NodeInsts in this Cell. */
 
68
    public final ImmutableArrayList<ImmutableNodeInst> nodes;
 
69
    /** A list of ArcInsts in this Cell. */
 
70
    public final ImmutableArrayList<ImmutableArcInst> arcs;
 
71
    /** TechId usage counts. */
 
72
    final BitSet techUsages;
 
73
    /** CellUsageInfos indexed by CellUsage.indefInParent */
 
74
    final CellUsageInfo[] cellUsages;
69
75
    /** definedExport == [0..definedExportLength) - deletedExports . */
70
 
    /** Map from chronIndex of Exports to sortIndex. */             final int exportIndex[];
71
 
    /** Bitmap of defined exports. */                               final BitSet definedExports;
72
 
    /** Length of defined exports. */                               final int definedExportsLength;
73
 
    /** Bitmap of deleted exports. */                               final BitSet deletedExports;
 
76
    /** Map from chronIndex of Exports to sortIndex. */
 
77
    final int exportIndex[];
 
78
    /** Bitmap of defined exports. */
 
79
    final BitSet definedExports;
 
80
    /** Length of defined exports. */
 
81
    final int definedExportsLength;
 
82
    /** Bitmap of deleted exports. */
 
83
    final BitSet deletedExports;
74
84
 
75
85
    /** Creates a new instance of CellRevision */
76
86
    private CellRevision(ImmutableCell d,
96
106
    public CellRevision(ImmutableCell d) {
97
107
        this(d, ImmutableNodeInst.EMPTY_LIST, ImmutableArcInst.EMPTY_LIST, ImmutableExport.EMPTY_LIST,
98
108
                makeTechUsages(d.techId), NULL_CELL_USAGE_INFO_ARRAY, NULL_INT_ARRAY, EMPTY_BITSET, 0, EMPTY_BITSET);
99
 
        if (d.techId == null)
 
109
        if (d.techId == null) {
100
110
            throw new NullPointerException("techId");
 
111
        }
101
112
    }
102
113
 
103
114
    private static BitSet makeTechUsages(TechId techId) {
112
123
     * @return new CellRevision which differs from this CellRevision by revision date.
113
124
     */
114
125
    public CellRevision withRevisionDate(long revisionDate) {
115
 
        if (d.revisionDate == revisionDate) return this;
 
126
        if (d.revisionDate == revisionDate) {
 
127
            return this;
 
128
        }
116
129
        return new CellRevision(this.d.withRevisionDate(revisionDate), this.nodes, this.arcs, this.exports,
117
130
                this.techUsages, this.cellUsages, this.exportIndex,
118
131
                this.definedExports, this.definedExportsLength, this.deletedExports);
141
154
        CellId cellId = d.cellId;
142
155
        boolean busNamesAllowed = d.busNamesAllowed();
143
156
        if (this.d != d) {
144
 
            if (d.techId == null)
 
157
            if (d.techId == null) {
145
158
                throw new NullPointerException("tech");
 
159
            }
146
160
//            if (cellId != this.d.cellId)
147
161
//                throw new IllegalArgumentException("cellId");
148
162
        }
154
168
            techUsages = uc.getTechUsages(this.techUsages);
155
169
            cellUsages = uc.getCellUsages(this.cellUsages);
156
170
        }
157
 
        if (cellId.isIcon() && cellUsages.length != 0)
 
171
        if (cellId.isIcon() && cellUsages.length != 0) {
158
172
            throw new IllegalArgumentException("Icon contains subcells");
 
173
        }
159
174
 
160
175
        if (nodes != this.nodes && !nodes.isEmpty()) {
161
176
            boolean hasCellCenter = false;
163
178
            for (int i = 0; i < nodes.size(); i++) {
164
179
                ImmutableNodeInst n = nodes.get(i);
165
180
                if (ImmutableNodeInst.isCellCenter(n.protoId)) {
166
 
                    if (hasCellCenter)
 
181
                    if (hasCellCenter) {
167
182
                        throw new IllegalArgumentException("Duplicate cell center");
 
183
                    }
168
184
                    hasCellCenter = true;
169
185
                }
170
 
                if (prevN != null && TextUtils.STRING_NUMBER_ORDER.compare(prevN.name.toString(), n.name.toString()) >= 0)
 
186
                if (!busNamesAllowed && n.name.isBus()) {
 
187
                    throw new IllegalArgumentException("arrayedName " + n.name);
 
188
                }
 
189
                if (prevN != null && TextUtils.STRING_NUMBER_ORDER.compare(prevN.name.toString(), n.name.toString()) >= 0) {
171
190
                    throw new IllegalArgumentException("nodes order");
 
191
                }
172
192
                prevN = n;
173
193
            }
174
194
        }
175
195
 
 
196
        if (arcs != this.arcs && !arcs.isEmpty()) {
 
197
            ImmutableArcInst prevA = null;
 
198
            for (int i = 0; i < arcs.size(); i++) {
 
199
                ImmutableArcInst a = arcs.get(i);
 
200
                if (!busNamesAllowed && a.name.isBus()) {
 
201
                    throw new IllegalArgumentException("arrayedName " + a.name);
 
202
                }
 
203
                if (prevA != null) {
 
204
                    int cmp = TextUtils.STRING_NUMBER_ORDER.compare(prevA.name.toString(), a.name.toString());
 
205
                    if (cmp > 0 || cmp == 0 && (a.name.isTempname() || prevA.arcId >= a.arcId))
 
206
                        throw new IllegalArgumentException("arcs order");
 
207
                }
 
208
                prevA = a;
 
209
            }
 
210
        }
 
211
 
176
212
        int[] exportIndex = this.exportIndex;
177
213
        BitSet definedExports = this.definedExports;
178
214
        int definedExportsLength = this.definedExportsLength;
180
216
        if (exports != this.exports) {
181
217
            int exportIndexLength = 0;
182
218
            String prevExportName = null;
183
 
            for (ImmutableExport e: exports) {
184
 
                if (e.exportId.parentId != cellId)
 
219
            for (ImmutableExport e : exports) {
 
220
                if (e.exportId.parentId != cellId) {
185
221
                    throw new IllegalArgumentException("exportId");
 
222
                }
186
223
                String exportName = e.name.toString();
187
 
                if (!busNamesAllowed && e.name.busWidth() != 1)
 
224
                if (!busNamesAllowed && e.name.isBus()) {
188
225
                    throw new IllegalArgumentException("arrayedName " + e.name);
189
 
                if (prevExportName != null && TextUtils.STRING_NUMBER_ORDER.compare(prevExportName, exportName) >= 0)
 
226
                }
 
227
                if (prevExportName != null && TextUtils.STRING_NUMBER_ORDER.compare(prevExportName, exportName) >= 0) {
190
228
                    throw new IllegalArgumentException("exportName");
 
229
                }
191
230
                prevExportName = exportName;
192
231
                int chronIndex = e.exportId.chronIndex;
193
232
                exportIndexLength = Math.max(exportIndexLength, chronIndex + 1);
197
236
            for (int portIndex = 0; portIndex < exports.size(); portIndex++) {
198
237
                ImmutableExport e = exports.get(portIndex);
199
238
                int chronIndex = e.exportId.chronIndex;
200
 
                if (exportIndex[chronIndex] >= 0)
 
239
                if (exportIndex[chronIndex] >= 0) {
201
240
                    throw new IllegalArgumentException("exportChronIndex");
 
241
                }
202
242
                exportIndex[chronIndex] = portIndex;
203
243
                //checkPortInst(nodesById.get(e.originalNodeId), e.originalPortId);
204
244
            }
207
247
            } else {
208
248
                definedExports = new BitSet();
209
249
                for (int chronIndex = 0; chronIndex < exportIndex.length; chronIndex++) {
210
 
                    if (exportIndex[chronIndex] < 0) continue;
 
250
                    if (exportIndex[chronIndex] < 0) {
 
251
                        continue;
 
252
                    }
211
253
                    definedExports.set(chronIndex);
212
254
                }
213
255
                definedExports = UsageCollector.bitSetWith(this.definedExports, definedExports);
230
272
        return newArray != null ? new ImmutableArrayList<T>(newArray) : oldList;
231
273
    }
232
274
 
233
 
        /**
234
 
         * Returns CellRevision which differs from this CellRevision by renamed Ids.
235
 
         * @param idMapper a map from old Ids to new Ids.
 
275
    /**
 
276
     * Returns CellRevision which differs from this CellRevision by renamed Ids.
 
277
     * @param idMapper a map from old Ids to new Ids.
236
278
     * @return CellRevision with renamed Ids.
237
 
         */
 
279
     */
238
280
    CellRevision withRenamedIds(IdMapper idMapper, CellName newGroupName) {
239
281
        ImmutableCell d = this.d.withRenamedIds(idMapper).withGroupName(newGroupName);
240
282
 
244
286
            ImmutableNodeInst newNode = oldNode.withRenamedIds(idMapper);
245
287
            if (newNode != oldNode && nodesArray == null) {
246
288
                nodesArray = new ImmutableNodeInst[nodes.size()];
247
 
                for (int j = 0; j < i; j++)
 
289
                for (int j = 0; j < i; j++) {
248
290
                    nodesArray[j] = nodes.get(j);
 
291
                }
249
292
            }
250
 
            if (nodesArray != null)
 
293
            if (nodesArray != null) {
251
294
                nodesArray[i] = newNode;
 
295
            }
252
296
        }
253
297
 
254
298
        ImmutableArcInst[] arcsArray = null;
257
301
            ImmutableArcInst newArc = oldArc.withRenamedIds(idMapper);
258
302
            if (newArc != oldArc && arcsArray == null) {
259
303
                arcsArray = new ImmutableArcInst[arcs.size()];
260
 
                for (int j = 0; j < i; j++)
 
304
                for (int j = 0; j < i; j++) {
261
305
                    arcsArray[j] = arcs.get(j);
 
306
                }
262
307
            }
263
 
            if (arcsArray != null)
 
308
            if (arcsArray != null) {
264
309
                arcsArray[i] = newArc;
 
310
            }
265
311
        }
266
312
 
267
313
        ImmutableExport[] exportsArray = null;
270
316
            ImmutableExport newExport = oldExport.withRenamedIds(idMapper);
271
317
            if (newExport != oldExport && exportsArray == null) {
272
318
                exportsArray = new ImmutableExport[exports.size()];
273
 
                for (int j = 0; j < i; j++)
 
319
                for (int j = 0; j < i; j++) {
274
320
                    exportsArray[j] = exports.get(j);
 
321
                }
275
322
            }
276
 
            if (exportsArray != null)
 
323
            if (exportsArray != null) {
277
324
                exportsArray[i] = newExport;
 
325
            }
278
326
        }
279
327
 
280
 
        if (this.d == d && nodesArray == null && arcsArray == null && exportsArray == null) return this;
 
328
        if (this.d == d && nodesArray == null && arcsArray == null && exportsArray == null) {
 
329
            return this;
 
330
        }
281
331
        CellRevision newRevision = with(d, nodesArray, arcsArray, exportsArray);
282
332
        newRevision.check();
283
333
        return newRevision;
284
334
    }
285
335
 
286
336
    /**
287
 
     * Returns ImmutableNodeInst by its node id.
288
 
     * @param nodeId id of node.
289
 
     * @return ImmutableNodeInst with this id or null if node doesn't exist.
290
 
     */
291
 
    // FIX ME !!!
292
 
    public ImmutableNodeInst getNode(int nodeId) { return nodeId < nodes.size() ? nodes.get(nodeId) : null; }
293
 
 
294
 
    /**
295
 
     * Returns ImmutableArcInst by its arc id.
296
 
     * @param arcId id of node.
297
 
     * @return ImmutableArcInst with this id or null if node doesn't exist.
298
 
     */
299
 
    // FIX ME !!!
300
 
    public ImmutableArcInst getArc(int arcId) { return arcId < arcs.size() ? arcs.get(arcId) : null; }
301
 
 
302
 
    /**
303
337
     * Returns ImmutableExport by its export id.
304
338
     * @param exportId id of export.
305
339
     * @return ImmutableExport with this id or null if node doesn't exist.
306
340
     */
307
341
    public ImmutableExport getExport(ExportId exportId) {
308
 
        if (exportId.parentId != d.cellId)
 
342
        if (exportId.parentId != d.cellId) {
309
343
            throw new IllegalArgumentException();
 
344
        }
310
345
        int chronIndex = exportId.chronIndex;
311
346
        int portIndex = chronIndex < exportIndex.length ? exportIndex[chronIndex] : -1;
312
347
        return portIndex >= 0 ? exports.get(portIndex) : null;
313
348
    }
314
349
 
 
350
    public int getExportIndexByExportId(ExportId exportId) {
 
351
        if (exportId.parentId != d.cellId) {
 
352
            throw new IllegalArgumentException();
 
353
        }
 
354
        int chronIndex = exportId.chronIndex;
 
355
        return chronIndex < exportIndex.length ? exportIndex[chronIndex] : -1;
 
356
    }
 
357
 
315
358
    /**
316
359
     * Returns subcell instance counts, indexed by CellUsage.indexInParent.
317
360
     * @return subcell instance counts, indexed by CellUsage.indexInParent.
318
361
     */
319
362
    public int[] getInstCounts() {
320
363
        int l = cellUsages.length;
321
 
        while (l > 0 && (cellUsages[l - 1] == null || cellUsages[l - 1].instCount == 0)) l--;
322
 
        if (l == 0) return NULL_INT_ARRAY;
 
364
        while (l > 0 && (cellUsages[l - 1] == null || cellUsages[l - 1].instCount == 0)) {
 
365
            l--;
 
366
        }
 
367
        if (l == 0) {
 
368
            return NULL_INT_ARRAY;
 
369
        }
323
370
        int[] instCounts = new int[l];
324
371
        for (int indexInParent = 0; indexInParent < l; indexInParent++) {
325
 
            if (cellUsages[indexInParent] != null)
 
372
            if (cellUsages[indexInParent] != null) {
326
373
                instCounts[indexInParent] = cellUsages[indexInParent].instCount;
 
374
            }
327
375
        }
328
376
        return instCounts;
329
377
    }
335
383
     * @throws IllegalArgumentException if CellUsage's parent is not this cell.
336
384
     */
337
385
    public int getInstCount(CellUsage u) {
338
 
        if (u.parentId != d.cellId)
 
386
        if (u.parentId != d.cellId) {
339
387
            throw new IllegalArgumentException();
340
 
        if (u.indexInParent >= cellUsages.length) return 0;
 
388
        }
 
389
        if (u.indexInParent >= cellUsages.length) {
 
390
            return 0;
 
391
        }
341
392
        CellUsageInfo cui = cellUsages[u.indexInParent];
342
 
        if (cui == null) return 0;
 
393
        if (cui == null) {
 
394
            return 0;
 
395
        }
343
396
        return cui.instCount;
344
397
    }
345
398
 
349
402
    public Set<TechId> getTechUsages() {
350
403
        LinkedHashSet<TechId> techUsagesSet = new LinkedHashSet<TechId>();
351
404
        for (int techIndex = 0; techIndex < techUsages.length(); techIndex++) {
352
 
            if (techUsages.get(techIndex))
 
405
            if (techUsages.get(techIndex)) {
353
406
                techUsagesSet.add(d.cellId.idManager.getTechId(techIndex));
 
407
            }
354
408
        }
355
409
        return techUsagesSet;
356
410
    }
362
416
    void write(IdWriter writer) throws IOException {
363
417
        d.write(writer);
364
418
        writer.writeInt(nodes.size());
365
 
        for (ImmutableNodeInst n: nodes)
 
419
        for (ImmutableNodeInst n : nodes) {
366
420
            n.write(writer);
 
421
        }
367
422
        writer.writeInt(arcs.size());
368
 
        for (ImmutableArcInst a: arcs)
 
423
        for (ImmutableArcInst a : arcs) {
369
424
            a.write(writer);
 
425
        }
370
426
        writer.writeInt(exports.size());
371
 
        for (ImmutableExport e: exports)
 
427
        for (ImmutableExport e : exports) {
372
428
            e.write(writer);
 
429
        }
373
430
    }
374
431
 
375
432
    /**
382
439
 
383
440
        int nodesLength = reader.readInt();
384
441
        ImmutableNodeInst[] nodes = new ImmutableNodeInst[nodesLength];
385
 
        for (int i = 0; i < nodesLength; i++)
 
442
        for (int i = 0; i < nodesLength; i++) {
386
443
            nodes[i] = ImmutableNodeInst.read(reader);
 
444
        }
387
445
 
388
446
        int arcsLength = reader.readInt();
389
447
        ImmutableArcInst[] arcs = new ImmutableArcInst[arcsLength];
390
 
        for (int i = 0; i < arcsLength; i++)
 
448
        for (int i = 0; i < arcsLength; i++) {
391
449
            arcs[i] = ImmutableArcInst.read(reader);
 
450
        }
392
451
 
393
452
        int exportsLength = reader.readInt();
394
453
        ImmutableExport[] exports = new ImmutableExport[exportsLength];
395
 
        for (int i = 0; i < exportsLength; i++)
 
454
        for (int i = 0; i < exportsLength; i++) {
396
455
            exports[i] = ImmutableExport.read(reader);
 
456
        }
397
457
 
398
458
        revision = revision.with(d, nodes, arcs, exports);
399
459
        return revision;
400
460
    }
401
461
 
402
462
    /**
403
 
         * Checks invariant of this CellRevision.
404
 
         * @throws AssertionError if invariant is broken.
405
 
         */
 
463
     * Checks invariant of this CellRevision.
 
464
     * @throws AssertionError if invariant is broken.
 
465
     */
406
466
    public void check() {
407
467
        d.check();
408
468
        CellId cellId = d.cellId;
413
473
        boolean hasCellCenter = false;
414
474
        ArrayList<ImmutableNodeInst> nodesById = new ArrayList<ImmutableNodeInst>();
415
475
        ImmutableNodeInst prevN = null;
416
 
        for (ImmutableNodeInst n: nodes) {
 
476
        for (ImmutableNodeInst n : nodes) {
417
477
            n.check();
418
478
            if (ImmutableNodeInst.isCellCenter(n.protoId)) {
419
479
                assert !hasCellCenter;
420
480
                hasCellCenter = true;
421
481
            }
422
 
            while (n.nodeId >= nodesById.size()) nodesById.add(null);
 
482
            while (n.nodeId >= nodesById.size()) {
 
483
                nodesById.add(null);
 
484
            }
423
485
            ImmutableNodeInst oldNode = nodesById.set(n.nodeId, n);
424
486
            assert oldNode == null;
425
 
                        if (prevN != null)
426
 
                                assert TextUtils.STRING_NUMBER_ORDER.compare(prevN.name.toString(), n.name.toString()) < 0;
 
487
            assert busNamesAllowed || !n.name.isBus();
 
488
            if (prevN != null) {
 
489
                assert TextUtils.STRING_NUMBER_ORDER.compare(prevN.name.toString(), n.name.toString()) < 0;
 
490
            }
427
491
            prevN = n;
428
492
            if (n.protoId instanceof CellId) {
429
 
                CellId subCellId = (CellId)n.protoId;
 
493
                CellId subCellId = (CellId) n.protoId;
430
494
                CellUsage u = cellId.getUsageIn(subCellId);
431
495
                checkCellUsages[u.indexInParent]--;
432
496
                CellUsageInfo cui = cellUsages[u.indexInParent];
433
497
                assert cui != null;
434
498
                for (int j = 0; j < n.ports.length; j++) {
435
499
                    ImmutablePortInst pid = n.ports[j];
436
 
                    if (pid == ImmutablePortInst.EMPTY) continue;
 
500
                    if (pid == ImmutablePortInst.EMPTY) {
 
501
                        continue;
 
502
                    }
437
503
                    checkPortInst(n, subCellId.getPortId(j));
438
504
                }
439
505
                if (subCellId.isIcon()) {
440
 
                    for (Variable param: n.getDefinedParams())
441
 
                        assert cui.usedAttributes.get((Variable.AttrKey)param.getKey()) == param.getUnit();
442
 
                    for (Iterator<Variable> it = n.getVariables(); it.hasNext(); ) {
 
506
                    for (Variable param : n.getDefinedParams()) {
 
507
                        assert cui.usedAttributes.get((Variable.AttrKey) param.getKey()) == param.getUnit();
 
508
                    }
 
509
                    for (Iterator<Variable> it = n.getVariables(); it.hasNext();) {
443
510
                        Variable.Key varKey = it.next().getKey();
444
 
                        if (varKey.isAttribute())
 
511
                        if (varKey.isAttribute()) {
445
512
                            assert cui.usedAttributes.get(varKey) == null;
 
513
                        }
446
514
                    }
447
515
                }
448
516
            } else {
449
 
                TechId techId = ((PrimitiveNodeId)n.protoId).techId;
 
517
                TechId techId = ((PrimitiveNodeId) n.protoId).techId;
450
518
                checkTechUsages.set(techId.techIndex);
451
519
            }
452
520
        }
453
 
        for (int i = 0; i < checkCellUsages.length; i++)
 
521
        for (int i = 0; i < checkCellUsages.length; i++) {
454
522
            assert checkCellUsages[i] == 0;
 
523
        }
455
524
        BitSet arcIds = new BitSet();
456
525
        ImmutableArcInst prevA = null;
457
 
        for (ImmutableArcInst a: arcs) {
 
526
        for (ImmutableArcInst a : arcs) {
458
527
            assert !arcIds.get(a.arcId);
459
528
            arcIds.set(a.arcId);
460
 
                        if (prevA != null) {
461
 
                                int cmp = TextUtils.STRING_NUMBER_ORDER.compare(prevA.name.toString(), a.name.toString());
462
 
                                assert cmp <= 0;
463
 
                                if (cmp == 0) {
 
529
            assert busNamesAllowed || !a.name.isBus();
 
530
            if (prevA != null) {
 
531
                int cmp = TextUtils.STRING_NUMBER_ORDER.compare(prevA.name.toString(), a.name.toString());
 
532
                assert cmp <= 0;
 
533
                if (cmp == 0) {
464
534
                    assert !a.name.isTempname();
465
 
                                        assert prevA.arcId < a.arcId;
 
535
                    assert prevA.arcId < a.arcId;
466
536
                }
467
 
                        }
 
537
            }
468
538
            prevA = a;
469
539
 
470
540
            a.check();
474
544
            checkTechUsages.set(a.protoId.techId.techIndex);
475
545
        }
476
546
 
477
 
        if (exportIndex.length > 0)
 
547
        if (exportIndex.length > 0) {
478
548
            assert exportIndex[exportIndex.length - 1] >= 0;
 
549
        }
479
550
        assert exportIndex.length == definedExportsLength;
480
551
        assert definedExports.length() == definedExportsLength;
481
552
        for (int i = 0; i < exports.size(); i++) {
483
554
            e.check();
484
555
            assert e.exportId.parentId == cellId;
485
556
            assert exportIndex[e.exportId.chronIndex] == i;
486
 
            if (!busNamesAllowed)
487
 
                assert e.name.busWidth() == 1;
488
 
            if (i > 0)
489
 
                assert(TextUtils.STRING_NUMBER_ORDER.compare(exports.get(i - 1).name.toString(), e.name.toString()) < 0) : i;
 
557
            assert busNamesAllowed || !e.name.isBus();
 
558
            if (i > 0) {
 
559
                assert (TextUtils.STRING_NUMBER_ORDER.compare(exports.get(i - 1).name.toString(), e.name.toString()) < 0) : i;
 
560
            }
490
561
            checkPortInst(nodesById.get(e.originalNodeId), e.originalPortId);
491
562
        }
492
563
        int exportCount = 0;
505
576
        checkDeleted.set(0, definedExportsLength);
506
577
        checkDeleted.andNot(definedExports);
507
578
        assert deletedExports.equals(checkDeleted);
508
 
        if (definedExports.isEmpty())
 
579
        if (definedExports.isEmpty()) {
509
580
            assert definedExports == EMPTY_BITSET;
510
 
        if (deletedExports.isEmpty())
 
581
        }
 
582
        if (deletedExports.isEmpty()) {
511
583
            assert deletedExports == EMPTY_BITSET;
 
584
        }
512
585
        assert techUsages.equals(checkTechUsages);
513
586
 
514
 
        if (d.cellId.isIcon())
 
587
        if (d.cellId.isIcon()) {
515
588
            assert cellUsages.length == 0;
 
589
        }
516
590
        for (int i = 0; i < cellUsages.length; i++) {
517
591
            CellUsageInfo cui = cellUsages[i];
518
 
            if (cui == null) continue;
 
592
            if (cui == null) {
 
593
                continue;
 
594
            }
519
595
            cui.check(d.cellId.getUsageIn(i));
520
596
        }
521
597
    }
523
599
    private void checkPortInst(ImmutableNodeInst node, PortProtoId portId) {
524
600
        assert node != null;
525
601
        assert portId.getParentId() == node.protoId;
526
 
        if (portId instanceof ExportId)
527
 
            checkExportId((ExportId)portId);
 
602
        if (portId instanceof ExportId) {
 
603
            checkExportId((ExportId) portId);
 
604
        }
528
605
    }
529
606
 
530
607
    private void checkExportId(ExportId exportId) {
533
610
    }
534
611
 
535
612
    public boolean sameExports(CellRevision thatRevision) {
536
 
        if (thatRevision == this) return true;
537
 
        if (exports.size() != thatRevision.exports.size())
 
613
        if (thatRevision == this) {
 
614
            return true;
 
615
        }
 
616
        if (exports.size() != thatRevision.exports.size()) {
538
617
            return false;
 
618
        }
539
619
        for (int i = 0; i < exports.size(); i++) {
540
 
            if (exports.get(i).exportId != thatRevision.exports.get(i).exportId)
 
620
            if (exports.get(i).exportId != thatRevision.exports.get(i).exportId) {
541
621
                return false;
 
622
            }
542
623
        }
543
624
        return true;
544
625
    }
545
626
 
546
627
    static class CellUsageInfo {
 
628
 
547
629
        final int instCount;
548
630
        final BitSet usedExports;
549
631
        final int usedExportsLength;
550
 
        final TreeMap<Variable.AttrKey,TextDescriptor.Unit> usedAttributes;
 
632
        final TreeMap<Variable.AttrKey, TextDescriptor.Unit> usedAttributes;
551
633
 
552
 
        CellUsageInfo(int instCount, BitSet usedExports, TreeMap<Variable.AttrKey,TextDescriptor.Unit> usedAttributes) {
 
634
        CellUsageInfo(int instCount, BitSet usedExports, TreeMap<Variable.AttrKey, TextDescriptor.Unit> usedAttributes) {
553
635
            this.instCount = instCount;
554
636
            usedExportsLength = usedExports.length();
555
637
            this.usedExports = usedExportsLength > 0 ? usedExports : EMPTY_BITSET;
556
638
            this.usedAttributes = usedAttributes;
557
639
        }
558
640
 
559
 
        CellUsageInfo with(int instCount, BitSet usedExports, TreeMap<Variable.AttrKey,TextDescriptor.Unit> usedAttributes) {
 
641
        CellUsageInfo with(int instCount, BitSet usedExports, TreeMap<Variable.AttrKey, TextDescriptor.Unit> usedAttributes) {
560
642
            usedExports = UsageCollector.bitSetWith(this.usedExports, usedExports);
561
643
            usedAttributes = UsageCollector.usedAttributesWith(this.usedAttributes, usedAttributes);
562
 
            if (this.instCount == instCount && this.usedExports == usedExports &&
563
 
                    this.usedAttributes == usedAttributes) return this;
 
644
            if (this.instCount == instCount && this.usedExports == usedExports
 
645
                    && this.usedAttributes == usedAttributes) {
 
646
                return this;
 
647
            }
564
648
            return new CellUsageInfo(instCount, usedExports, usedAttributes);
565
649
        }
566
650
 
567
651
        void checkUsage(CellRevision subCellRevision) {
568
 
            if (subCellRevision == null)
 
652
            if (subCellRevision == null) {
569
653
                throw new IllegalArgumentException("subCell deleted");
570
 
            if (subCellRevision.definedExportsLength < usedExportsLength || subCellRevision.deletedExports.intersects(usedExports))
 
654
            }
 
655
            if (subCellRevision.definedExportsLength < usedExportsLength || subCellRevision.deletedExports.intersects(usedExports)) {
571
656
                throw new IllegalArgumentException("exportUsages");
 
657
            }
572
658
            if (isIcon()) {
573
 
                for (Map.Entry<Variable.AttrKey,TextDescriptor.Unit> e: usedAttributes.entrySet()) {
 
659
                for (Map.Entry<Variable.AttrKey, TextDescriptor.Unit> e : usedAttributes.entrySet()) {
574
660
                    Variable.AttrKey paramKey = e.getKey();
575
661
                    Variable param = subCellRevision.d.getParameter(paramKey);
576
662
                    TextDescriptor.Unit unit = e.getValue();
577
663
                    if (unit != null) {
578
 
                        if (param == null || param.getUnit() != unit)
 
664
                        if (param == null || param.getUnit() != unit) {
579
665
                            throw new IllegalArgumentException("param " + paramKey);
 
666
                        }
580
667
                    } else {
581
 
                        if (param != null)
 
668
                        if (param != null) {
582
669
                            throw new IllegalArgumentException("param " + paramKey);
 
670
                        }
583
671
                    }
584
672
                }
585
673
            }
586
674
        }
587
675
 
588
 
        private boolean isIcon() { return usedAttributes != null; }
 
676
        private boolean isIcon() {
 
677
            return usedAttributes != null;
 
678
        }
589
679
 
590
680
        private void check(CellUsage u) {
591
 
            assert instCount >= 0;
 
681
            assert instCount > 0;
592
682
            assert usedExportsLength == usedExports.length();
593
 
            if (usedExportsLength == 0)
 
683
            if (usedExportsLength == 0) {
594
684
                assert usedExports == EMPTY_BITSET;
 
685
            }
595
686
            assert isIcon() == u.protoId.isIcon();
596
687
            assert !u.parentId.isIcon();
597
688
        }
598
689
    }
599
690
 
600
691
    @Override
601
 
    public String toString() { return d.toString(); }
 
692
    public String toString() {
 
693
        return d.toString();
 
694
    }
602
695
}