Class: PredictionContext

Inherits:
Object show all
Defined in:
lib/antlr4/PredictionContext.rb

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

Class Method Summary collapse

Instance Method Summary collapse

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

#cachedHashCodeObject (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 &lt; {@link #size()}; i++) {
        hash = {@link MurmurHash#update MurmurHash.update}(hash, {@link #getParent getParent}(i));
    }

    for (int i = 0; i &lt; {@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

.calculateEmptyHashCodeObject



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

.EMPTYObject



7
8
9
10
# File 'lib/antlr4/PredictionContext.rb', line 7

def self.EMPTY 
  @@EMPTY = EmptyPredictionContext.new if @@EMPTY.nil?
  @@EMPTY
end

.EMPTY_RETURN_STATEObject



15
16
17
# File 'lib/antlr4/PredictionContext.rb', line 15

def self.EMPTY_RETURN_STATE 
  PredictionContext::EMPTY_RETURN_STATE 
end

Instance Method Details

#hasEmptyPathObject



51
52
53
# File 'lib/antlr4/PredictionContext.rb', line 51

def hasEmptyPath
    return self.getReturnState(self.length - 1) == PredictionContext::EMPTY_RETURN_STATE 
end

#hashObject



54
55
56
# File 'lib/antlr4/PredictionContext.rb', line 54

def hash
    return self.cachedHashCode
end

#isEmptyObject

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