Class: PredictionContextCache
Overview
Used to cache PredictionContext objects. Its used for the shared
context cash associated with contexts in DFA states. This cache
can be used for both lexers and parsers.
Instance Attribute Summary collapse
-
#cache ⇒ Object
readonly
Returns the value of attribute cache.
Instance Method Summary collapse
-
#add(ctx) ⇒ Object
Add a context to the cache and return it.
- #get(ctx) ⇒ Object
-
#initialize ⇒ PredictionContextCache
constructor
A new instance of PredictionContextCache.
- #length ⇒ Object
Constructor Details
#initialize ⇒ PredictionContextCache
Returns a new instance of PredictionContextCache.
71 72 73 |
# File 'lib/antlr4/PredictionContext.rb', line 71 def initialize @cache = Hash.new end |
Instance Attribute Details
#cache ⇒ Object (readonly)
Returns the value of attribute cache.
70 71 72 |
# File 'lib/antlr4/PredictionContext.rb', line 70 def cache @cache end |
Instance Method Details
#add(ctx) ⇒ Object
Add a context to the cache and return it. If the context already exists,
return that one instead and do not add a new context to the cache.
Protect shared cache from unsafe thread access.
79 80 81 82 83 84 85 86 87 |
# File 'lib/antlr4/PredictionContext.rb', line 79 def add(ctx) if ctx.equal? PredictionContext.EMPTY then return PredictionContext.EMPTY end existing = self.cache[ctx] return existing if existing self.cache[ctx] = ctx return ctx end |
#get(ctx) ⇒ Object
88 89 90 |
# File 'lib/antlr4/PredictionContext.rb', line 88 def get(ctx) return self.cache[ctx] end |
#length ⇒ Object
91 92 93 |
# File 'lib/antlr4/PredictionContext.rb', line 91 def length return self.cache.length end |