1 package edu.uci.eecs.specCompiler.specExtraction;
3 import java.util.HashMap;
4 import java.util.HashSet;
6 public class GlobalConstruct extends Construct {
7 public final String code;
8 private final HashMap<String, HashSet<ConditionalInterface>> interfaceCluster;
9 private final HashMap<ConditionalInterface, HashSet<ConditionalInterface>> originalHBRelations;
10 public final HashMap<ConditionalInterface, HashSet<ConditionalInterface>> hbRelations;
12 public GlobalConstruct(String code) {
14 this.interfaceCluster = new HashMap<String, HashSet<ConditionalInterface>>();
15 this.originalHBRelations = new HashMap<ConditionalInterface, HashSet<ConditionalInterface>>();
16 this.hbRelations = new HashMap<ConditionalInterface, HashSet<ConditionalInterface>>();
19 public void addInterface2Cluster(String clusterName, ConditionalInterface condInterface) {
20 if (!interfaceCluster.containsKey(clusterName)) {
21 interfaceCluster.put(clusterName, new HashSet<ConditionalInterface>());
23 HashSet<ConditionalInterface> set = interfaceCluster.get(clusterName);
24 set.add(condInterface);
27 public void addHBCondition(ConditionalInterface left, ConditionalInterface right) {
28 if (!originalHBRelations.containsKey(left)) {
29 originalHBRelations.put(left, new HashSet<ConditionalInterface>());
31 HashSet<ConditionalInterface> set = originalHBRelations.get(left);
35 private void addUnfoldedHBCondition(ConditionalInterface left, ConditionalInterface right) {
36 if (!hbRelations.containsKey(left)) {
37 hbRelations.put(left, new HashSet<ConditionalInterface>());
39 HashSet<ConditionalInterface> set = hbRelations.get(left);
43 private HashSet<ConditionalInterface> getByName(ConditionalInterface condInterface) {
44 if (interfaceCluster.containsKey(condInterface.interfaceName))
45 return interfaceCluster.get(condInterface.interfaceName);
46 HashSet<ConditionalInterface> res = new HashSet<ConditionalInterface>();
47 res.add(condInterface);
51 public void unfoldInterfaceCluster() {
52 for (ConditionalInterface left : originalHBRelations.keySet()) {
53 HashSet<ConditionalInterface> rights = originalHBRelations.get(left);
54 for (ConditionalInterface right : rights) {
55 HashSet<ConditionalInterface> leftCondInterfaces = getByName(left),
56 rightCondInterfaces = getByName(right);
57 for (ConditionalInterface l : leftCondInterfaces) {
58 for (ConditionalInterface r : rightCondInterfaces) {
59 addUnfoldedHBCondition(l, r);
66 public String toString() {
67 StringBuilder sb = new StringBuilder("GlobalConstruct:\n");
68 sb.append("@Code:\n");
71 sb.append("@Happens_before:\n");
72 for (ConditionalInterface left : hbRelations.keySet()) {
73 HashSet<ConditionalInterface> rights = hbRelations.get(left);
74 sb.append(left + " -> ");
75 for (ConditionalInterface right : rights) {
76 sb.append(right + " | ");