1 package edu.uci.eecs.specCompiler.specExtraction;
4 import java.util.HashMap;
5 import java.util.HashSet;
7 public class GlobalConstruct extends Construct {
8 public final SequentialDefineSubConstruct code;
9 private final HashMap<String, HashSet<ConditionalInterface>> interfaceCluster;
10 private final HashMap<ConditionalInterface, HashSet<ConditionalInterface>> originalHBRelations;
11 public final HashMap<ConditionalInterface, HashSet<ConditionalInterface>> hbRelations;
12 public final HashMap<String, String> options;
14 public GlobalConstruct(File file, int beginLineNum,
15 SequentialDefineSubConstruct code, HashMap<String, String> options) {
16 super(file, beginLineNum);
18 this.interfaceCluster = new HashMap<String, HashSet<ConditionalInterface>>();
19 this.originalHBRelations = new HashMap<ConditionalInterface, HashSet<ConditionalInterface>>();
20 this.hbRelations = new HashMap<ConditionalInterface, HashSet<ConditionalInterface>>();
21 this.options = options;
24 public void addInterface2Cluster(String clusterName,
25 ConditionalInterface condInterface) {
26 if (!interfaceCluster.containsKey(clusterName)) {
27 interfaceCluster.put(clusterName,
28 new HashSet<ConditionalInterface>());
30 HashSet<ConditionalInterface> set = interfaceCluster.get(clusterName);
31 set.add(condInterface);
34 public void addHBCondition(ConditionalInterface left,
35 ConditionalInterface right) {
36 if (!originalHBRelations.containsKey(left)) {
37 originalHBRelations.put(left, new HashSet<ConditionalInterface>());
39 HashSet<ConditionalInterface> set = originalHBRelations.get(left);
43 private void addUnfoldedHBCondition(ConditionalInterface left,
44 ConditionalInterface right) {
45 if (!hbRelations.containsKey(left)) {
46 hbRelations.put(left, new HashSet<ConditionalInterface>());
48 HashSet<ConditionalInterface> set = hbRelations.get(left);
52 private HashSet<ConditionalInterface> getByName(
53 ConditionalInterface condInterface) {
54 if (interfaceCluster.containsKey(condInterface.interfaceName))
55 return interfaceCluster.get(condInterface.interfaceName);
56 HashSet<ConditionalInterface> res = new HashSet<ConditionalInterface>();
57 res.add(condInterface);
61 public void unfoldInterfaceCluster() {
62 for (ConditionalInterface left : originalHBRelations.keySet()) {
63 HashSet<ConditionalInterface> rights = originalHBRelations
65 for (ConditionalInterface right : rights) {
66 HashSet<ConditionalInterface> leftCondInterfaces = getByName(left), rightCondInterfaces = getByName(right);
67 for (ConditionalInterface l : leftCondInterfaces) {
68 for (ConditionalInterface r : rightCondInterfaces) {
69 addUnfoldedHBCondition(l, r);
76 public String toString() {
77 StringBuilder sb = new StringBuilder("GlobalConstruct:\n");
78 sb.append("@Code:\n");
81 sb.append("@Happens_before:\n");
82 for (ConditionalInterface left : hbRelations.keySet()) {
83 HashSet<ConditionalInterface> rights = hbRelations.get(left);
84 sb.append(left + " -> ");
85 for (ConditionalInterface right : rights) {
86 sb.append(right + " | ");