Class: PredictionContext
Direct Known Subclasses
Constant Summary collapse
- EMPTY_RETURN_STATE =
Represents $ in an array in full context mode, when $ doesn’t mean wildcard: $ + x = [$,x]. Here, $ = #EMPTY_RETURN_STATE.
0x7FFFFFFF
- @@EMPTY =
Represents $ in local context prediction, which means wildcard. =#.
nil
- @@globalNodeCount =
1
- @@id =
@@globalNodeCount
Instance Attribute Summary collapse
-
#cachedHashCode ⇒ Object
readonly
Stores the computed hash code of this PredictionContext.
Class Method Summary collapse
- .calculateEmptyHashCode ⇒ Object
- .calculateHashCode(parent, returnState) ⇒ Object
- .EMPTY ⇒ Object
- .EMPTY_RETURN_STATE ⇒ Object
Instance Method Summary collapse
- #hasEmptyPath ⇒ Object
- #hash ⇒ Object
-
#initialize(_cachedHashCode) ⇒ PredictionContext
constructor
A new instance of PredictionContext.
-
#isEmpty ⇒ Object
This means only the #EMPTY context is in set.
Constructor Details
#initialize(_cachedHashCode) ⇒ PredictionContext
Returns a new instance of PredictionContext.
43 44 45 |
# File 'lib/antlr4/PredictionContext.rb', line 43 def initialize(_cachedHashCode) @cachedHashCode = _cachedHashCode end |
Instance Attribute Details
#cachedHashCode ⇒ Object (readonly)
Stores the computed hash code of this PredictionContext. The hash code is computed in parts to match the following reference algorithm.
<pre>
private int referenceHashCode() {
int hash = {@link MurmurHash#initialize MurmurHash.initialize}({@link #INITIAL_HASH});
for (int i = 0; i < {@link #size()}; i++) {
hash = {@link MurmurHash#update MurmurHash.update}(hash, {@link #getParent getParent}(i));
}
for (int i = 0; i < {@link #size()}; i++) {
hash = {@link MurmurHash#update MurmurHash.update}(hash, {@link #getReturnState getReturnState}(i));
}
hash = {@link MurmurHash#finish MurmurHash.finish}(hash, 2# {@link #size()});
return hash;
}
</pre> /
42 43 44 |
# File 'lib/antlr4/PredictionContext.rb', line 42 def cachedHashCode @cachedHashCode end |
Class Method Details
.calculateEmptyHashCode ⇒ Object
57 58 59 |
# File 'lib/antlr4/PredictionContext.rb', line 57 def self.calculateEmptyHashCode "".hash end |
.calculateHashCode(parent, returnState) ⇒ Object
60 61 62 |
# File 'lib/antlr4/PredictionContext.rb', line 60 def self.calculateHashCode(parent, returnState) "#{parent}#{returnState}".hash end |
.EMPTY ⇒ Object
7 8 9 10 |
# File 'lib/antlr4/PredictionContext.rb', line 7 def self.EMPTY @@EMPTY = EmptyPredictionContext.new if @@EMPTY.nil? @@EMPTY end |
.EMPTY_RETURN_STATE ⇒ Object
15 16 17 |
# File 'lib/antlr4/PredictionContext.rb', line 15 def self.EMPTY_RETURN_STATE PredictionContext::EMPTY_RETURN_STATE end |
Instance Method Details
#hasEmptyPath ⇒ Object
51 52 53 |
# File 'lib/antlr4/PredictionContext.rb', line 51 def hasEmptyPath return self.getReturnState(self.length - 1) == PredictionContext::EMPTY_RETURN_STATE end |
#hash ⇒ Object
54 55 56 |
# File 'lib/antlr4/PredictionContext.rb', line 54 def hash return self.cachedHashCode end |
#isEmpty ⇒ Object
This means only the #EMPTY context is in set.
48 49 50 |
# File 'lib/antlr4/PredictionContext.rb', line 48 def isEmpty self.equal? PredictionContext.EMPTY end |