Blame view

circus/src/jcircus/complementaryenvs/ChanDotFieldEnv.java 1.72 KB
8d0dc533f   Madiel de Souza Conserva Filho   first
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
  package jcircus.complementaryenvs;
  
  import java.util.HashMap;
  import java.util.LinkedHashMap;
  
  import net.sourceforge.czt.circus.ast.CircusFieldList;
  import net.sourceforge.czt.circus.ast.Communication;
  import net.sourceforge.czt.circus.ast.DotField;
  import net.sourceforge.czt.circus.ast.Field;
  import net.sourceforge.czt.circus.ast.OutputFieldAnn;
  
  //@author: Samuel Lincoln M. Barrocas
  	//Checks if a channel is used at least one time as a communication with its last field being a dot field
  public class ChanDotFieldEnv {
  	private HashMap map;
  	public ChanDotFieldEnv () {
  		this.map = new LinkedHashMap <String, Boolean> ();
  	}
  	private void put (String channel, Boolean b) {
  		if (!this.map.containsKey (channel))
  			this.map.put(channel, b);
  		if (!((Boolean)this.map.get(channel))) {
  			this.map.put(channel, b);
  		}
  	}
      public static boolean hasOutputFieldAnn (Field field) {
      	if (!(field instanceof DotField)) {
      		return false;
      	}
      	for (int i = 0; i < field.getAnns().size(); i++) {
      		if (field.getAnns().get(0) instanceof OutputFieldAnn) {
      			return true;
      		}
      	}
      	return false;
      }
  
  	public void put (Communication c) {
  		CircusFieldList cfl = c.getCircusFieldList();
  		if (cfl.size() == 0) {
  			this.put(c.getChannelExpr().getZName().toString(), false);			
  		}
  		else if (cfl.get(cfl.size() - 1) instanceof DotField && !hasOutputFieldAnn (cfl.get(cfl.size() - 1))) {
  			this.put(c.getChannelExpr().getZName().toString(), true);
  		}
  		else {
  			this.put(c.getChannelExpr().getZName().toString(), false);
  		}
  	}
  	public Boolean get (String channel) {
  		if (this.map.get(channel) == null) {
  			return false;
  		}
  		return (Boolean) this.map.get(channel);
  	}
  }