aboutsummaryrefslogtreecommitdiffhomepage
path: root/third_party/checker_framework_dataflow/java/org/checkerframework/dataflow/cfg/block/BlockImpl.java
blob: c3df418ecc852e46a8ce177ec819c16fd022c619 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
package org.checkerframework.dataflow.cfg.block;

import java.util.Collections;
import java.util.HashSet;
import java.util.Set;

/**
 * Base class of the {@link Block} implementation hierarchy.
 * 
 * @author Stefan Heule
 * 
 */
public abstract class BlockImpl implements Block {

    /** A unique ID for this node. */
    protected long id = BlockImpl.uniqueID();

    /** The last ID that has already been used. */
    protected static long lastId = 0;

    /** The type of this basic block. */
    protected BlockType type;

    /** The set of predecessors. */
    protected Set<BlockImpl> predecessors;

    /**
     * @return A fresh identifier.
     */
    private static long uniqueID() {
        return lastId++;
    }

    public BlockImpl() {
        predecessors = new HashSet<>();
    }

    @Override
    public long getId() {
        return id;
    }

    @Override
    public BlockType getType() {
        return type;
    }

    /**
     * @return The list of predecessors of this basic block.
     */
    public Set<BlockImpl> getPredecessors() {
        return Collections.unmodifiableSet(predecessors);
    }

    public void addPredecessor(BlockImpl pred) {
        predecessors.add(pred);
    }

    public void removePredecessor(BlockImpl pred) {
        predecessors.remove(pred);
    }

}