1 package edu.uci.eecs.specCompiler.specExtraction;
4 import java.util.ArrayList;
5 import java.util.HashMap;
6 import java.util.HashSet;
8 public class GlobalConstruct extends Construct {
9 public final SequentialDefineSubConstruct code;
10 private final HashMap<String, HashSet<ConditionalInterface>> interfaceCluster;
11 private final HashMap<ConditionalInterface, HashSet<ConditionalInterface>> originalHBRelations;
12 public final HashMap<ConditionalInterface, HashSet<ConditionalInterface>> hbRelations;
13 public final ArrayList<CommutativityRule> commutativityRules;
14 public final HashMap<String, String> options;
16 public GlobalConstruct(File file, int beginLineNum,
17 SequentialDefineSubConstruct code, HashMap<String, String> options) {
18 super(file, beginLineNum);
20 this.interfaceCluster = new HashMap<String, HashSet<ConditionalInterface>>();
21 this.originalHBRelations = new HashMap<ConditionalInterface, HashSet<ConditionalInterface>>();
22 this.hbRelations = new HashMap<ConditionalInterface, HashSet<ConditionalInterface>>();
23 this.options = options;
24 this.commutativityRules = new ArrayList<CommutativityRule>();
27 public void addInterface2Cluster(String clusterName,
28 ConditionalInterface condInterface) {
29 if (!interfaceCluster.containsKey(clusterName)) {
30 interfaceCluster.put(clusterName,
31 new HashSet<ConditionalInterface>());
33 HashSet<ConditionalInterface> set = interfaceCluster.get(clusterName);
34 set.add(condInterface);
37 public void addHBCondition(ConditionalInterface left,
38 ConditionalInterface right) {
39 if (!originalHBRelations.containsKey(left)) {
40 originalHBRelations.put(left, new HashSet<ConditionalInterface>());
42 HashSet<ConditionalInterface> set = originalHBRelations.get(left);
46 public void addCommutativityRule(String method1, String method2, String condition) {
47 CommutativityRule rule = new CommutativityRule(method1, method2, condition);
48 if (!commutativityRules.contains(rule)) {
49 commutativityRules.add(rule);
53 private void addUnfoldedHBCondition(ConditionalInterface left,
54 ConditionalInterface right) {
55 if (!hbRelations.containsKey(left)) {
56 hbRelations.put(left, new HashSet<ConditionalInterface>());
58 HashSet<ConditionalInterface> set = hbRelations.get(left);
62 private HashSet<ConditionalInterface> getByName(
63 ConditionalInterface condInterface) {
64 if (interfaceCluster.containsKey(condInterface.interfaceName))
65 return interfaceCluster.get(condInterface.interfaceName);
66 HashSet<ConditionalInterface> res = new HashSet<ConditionalInterface>();
67 res.add(condInterface);
71 public void unfoldInterfaceCluster() {
72 for (ConditionalInterface left : originalHBRelations.keySet()) {
73 HashSet<ConditionalInterface> rights = originalHBRelations
75 for (ConditionalInterface right : rights) {
76 HashSet<ConditionalInterface> leftCondInterfaces = getByName(left), rightCondInterfaces = getByName(right);
77 for (ConditionalInterface l : leftCondInterfaces) {
78 for (ConditionalInterface r : rightCondInterfaces) {
79 addUnfoldedHBCondition(l, r);
86 public String toString() {
87 StringBuilder sb = new StringBuilder("GlobalConstruct:\n");
88 sb.append("@Code:\n");
91 sb.append("@Happens_before:\n");
92 for (ConditionalInterface left : hbRelations.keySet()) {
93 HashSet<ConditionalInterface> rights = hbRelations.get(left);
94 sb.append(left + " -> ");
95 for (ConditionalInterface right : rights) {
96 sb.append(right + " | ");
101 return sb.toString();