[Swift] Make ATNSimulator.sharedContextCache non-optional.

Make ATNSimulator.sharedContextCache declared as non-optional.  It
was used this way anyway, so it was just being pointlessly forced
at the use-sites.
This commit is contained in:
Ewan Mellor 2017-11-09 15:12:21 -08:00
parent b4c34da1f0
commit 4baedb5e7b
No known key found for this signature in database
GPG Key ID: 7CE1C6BC9EC8645D
3 changed files with 8 additions and 13 deletions

View File

@ -1022,11 +1022,10 @@ open class Parser: Recognizer<ParserATNSimulator> {
if !(interp is ProfilingATNSimulator) {
setInterpreter(ProfilingATNSimulator(self))
}
} else {
if interp is ProfilingATNSimulator {
let sim = ParserATNSimulator(self, getATN(), interp.decisionToDFA, interp.getSharedContextCache()!)
setInterpreter(sim)
}
}
else if interp is ProfilingATNSimulator {
let sim = ParserATNSimulator(self, getATN(), interp.decisionToDFA, interp.getSharedContextCache())
setInterpreter(sim)
}
getInterpreter().setPredictionMode(saveMode)
}

View File

@ -40,7 +40,7 @@ open class ATNSimulator {
/// more time I think and doesn't save on the overall footprint
/// so it's not worth the complexity.
///
internal final var sharedContextCache: PredictionContextCache?
internal let sharedContextCache: PredictionContextCache
public init(_ atn: ATN,
_ sharedContextCache: PredictionContextCache) {
@ -68,21 +68,17 @@ open class ATNSimulator {
throw ANTLRError.unsupportedOperation(msg: "This ATN simulator does not support clearing the DFA. ")
}
open func getSharedContextCache() -> PredictionContextCache? {
open func getSharedContextCache() -> PredictionContextCache {
return sharedContextCache
}
open func getCachedContext(_ context: PredictionContext) -> PredictionContext {
if sharedContextCache == nil {
return context
}
//TODO: synced (sharedContextCache!)
//synced (sharedContextCache!) {
let visited = HashMap<PredictionContext, PredictionContext>()
return PredictionContext.getCachedContext(context,
sharedContextCache!,
sharedContextCache,
visited)
}

View File

@ -41,7 +41,7 @@ public class ProfilingATNSimulator: ParserATNSimulator {
super.init(parser,
parser.getInterpreter().atn,
parser.getInterpreter().decisionToDFA,
parser.getInterpreter().sharedContextCache!)
parser.getInterpreter().sharedContextCache)
numDecisions = atn.decisionToState.count
for i in 0..<numDecisions {