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 SequentialDefineSubConstruct 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;
11 public final HashMap<String, String> options;
13 public GlobalConstruct(SequentialDefineSubConstruct code, HashMap<String, String> options) {
15 this.interfaceCluster = new HashMap<String, HashSet<ConditionalInterface>>();
16 this.originalHBRelations = new HashMap<ConditionalInterface, HashSet<ConditionalInterface>>();
17 this.hbRelations = new HashMap<ConditionalInterface, HashSet<ConditionalInterface>>();
18 this.options = options;
21 public void addInterface2Cluster(String clusterName, ConditionalInterface condInterface) {
22 if (!interfaceCluster.containsKey(clusterName)) {
23 interfaceCluster.put(clusterName, new HashSet<ConditionalInterface>());
25 HashSet<ConditionalInterface> set = interfaceCluster.get(clusterName);
26 set.add(condInterface);
29 public void addHBCondition(ConditionalInterface left, ConditionalInterface right) {
30 if (!originalHBRelations.containsKey(left)) {
31 originalHBRelations.put(left, new HashSet<ConditionalInterface>());
33 HashSet<ConditionalInterface> set = originalHBRelations.get(left);
37 private void addUnfoldedHBCondition(ConditionalInterface left, ConditionalInterface right) {
38 if (!hbRelations.containsKey(left)) {
39 hbRelations.put(left, new HashSet<ConditionalInterface>());
41 HashSet<ConditionalInterface> set = hbRelations.get(left);
45 private HashSet<ConditionalInterface> getByName(ConditionalInterface condInterface) {
46 if (interfaceCluster.containsKey(condInterface.interfaceName))
47 return interfaceCluster.get(condInterface.interfaceName);
48 HashSet<ConditionalInterface> res = new HashSet<ConditionalInterface>();
49 res.add(condInterface);
53 public void unfoldInterfaceCluster() {
54 for (ConditionalInterface left : originalHBRelations.keySet()) {
55 HashSet<ConditionalInterface> rights = originalHBRelations.get(left);
56 for (ConditionalInterface right : rights) {
57 HashSet<ConditionalInterface> leftCondInterfaces = getByName(left),
58 rightCondInterfaces = getByName(right);
59 for (ConditionalInterface l : leftCondInterfaces) {
60 for (ConditionalInterface r : rightCondInterfaces) {
61 addUnfoldedHBCondition(l, r);
68 public String toString() {
69 StringBuilder sb = new StringBuilder("GlobalConstruct:\n");
70 sb.append("@Code:\n");
73 sb.append("@Happens_before:\n");
74 for (ConditionalInterface left : hbRelations.keySet()) {
75 HashSet<ConditionalInterface> rights = hbRelations.get(left);
76 sb.append(left + " -> ");
77 for (ConditionalInterface right : rights) {
78 sb.append(right + " | ");