View Javadoc

1   package net.obsearch.example.ted;
2   
3   import java.util.BitSet;
4   
5   import net.obsearch.index.utils.IntegerHolder;
6   
7   import antlr.collections.AST;
8   
9   
10  
11  /*
12   * a bigger slice node  that contains extra information
13   */
14  public class SliceASTIds extends SliceAST {
15  	
16  	private int id = -1; // id used to uniquely identify this node
17      private BitSet contains;
18      
19      
20      public BitSet containedNodes(){
21      	assert contains != null;
22      	return contains;
23      }
24      
25      public void updateContains(){
26      	if (contains == null){
27      		this.updateIdInfo();    	
28      		updateContainsAux(null);
29      	}
30      }
31      
32      public boolean containsNode(int i){
33      	assert contains != null;
34      	return this.contains.get(i);
35      }
36      
37      protected void updateContainsAux(BitSet parent){
38      	SliceASTIds n = (SliceASTIds)this.getLeftmostChild();
39      	BitSet me = new BitSet();
40  		while(n != null){
41  			me.set(n.getId());
42  			n.updateContainsAux(me);
43  			n = (SliceASTIds)n.getNextSibling();
44      	}
45  		this.contains = me;
46  		if(parent != null){
47  			parent.or(me);// update the parent
48  		}
49      }
50      
51      
52      
53      public int getId(){
54      	assert id != -1;
55      	return id;
56      }
57      
58      public void updateIdInfo(){
59      	updateIdInfoAux(new IntegerHolder(0));
60      }
61      
62      public void updateIdInfoAux(IntegerHolder i){
63      	this.id = i.getValue();
64      	SliceASTIds n = (SliceASTIds)this.getLeftmostChild();
65  		while(n != null){
66  			i.inc();
67  			n.updateIdInfoAux(i);
68  			n = (SliceASTIds)n.getNextSibling();
69      	}
70      }
71      
72      /*
73       * little speed up to the normal equalsTree method
74       * this is wrong!!! TODO review
75       * @see antlr.BaseAST#equalsTree(antlr.collections.AST)
76       */
77     /** public boolean equalsTree(AST t) {
78      	SliceASTIds j = (SliceASTIds)t;
79      	if(j.getSize() != this.getSize() || ! j.contains.equals(this.contains)){ // little speed up! ;)
80      		return false;
81      	}else{
82      		return super.equalsTree(t);
83      	}
84      }**/
85      
86      
87      
88  }