[Swift] Make DFA.precedenceDfa be a "let" rather than a "var".

Make DFA.precedenceDfa be a "let" rather than a "var", and remove
setPrecedenceDfa.  This field never varies after construction.  The
code in setPrecedenceDfa was carried over from the Java runtime, but
it only threw an exception, and was deprecated.  There's no need for
that in the Swift runtime.
This commit is contained in:
Ewan Mellor 2017-11-09 14:56:39 -08:00
parent b4c34da1f0
commit b548999b16
No known key found for this signature in database
GPG Key ID: 7CE1C6BC9EC8645D
1 changed files with 14 additions and 32 deletions

View File

@ -27,7 +27,7 @@ public class DFA: CustomStringConvertible {
/// `true` if this DFA is for a precedence decision; otherwise,
/// `false`. This is the backing field for _#isPrecedenceDfa_.
///
private final var precedenceDfa: Bool
private let precedenceDfa: Bool
///
/// mutex for DFAState changes.
@ -42,19 +42,19 @@ public class DFA: CustomStringConvertible {
self.atnStartState = atnStartState
self.decision = decision
var precedenceDfa: Bool = false
if atnStartState is StarLoopEntryState {
if (atnStartState as! StarLoopEntryState).precedenceRuleDecision {
precedenceDfa = true
let precedenceState: DFAState = DFAState(ATNConfigSet())
precedenceState.edges = [DFAState]() //new DFAState[0];
if let starLoopState = atnStartState as? StarLoopEntryState, starLoopState.precedenceRuleDecision {
let precedenceState = DFAState(ATNConfigSet())
precedenceState.edges = [DFAState]()
precedenceState.isAcceptState = false
precedenceState.requiresFullContext = false
self.s0 = precedenceState
}
}
self.precedenceDfa = precedenceDfa
precedenceDfa = true
s0 = precedenceState
}
else {
precedenceDfa = false
s0 = nil
}
}
///
@ -130,24 +130,6 @@ public class DFA: CustomStringConvertible {
}
}
///
/// Sets whether this is a precedence DFA.
///
/// - parameter precedenceDfa: `true` if this is a precedence DFA; otherwise,
/// `false`
///
/// - throws: ANTLRError.unsupportedOperation if `precedenceDfa` does not
/// match the value of _#isPrecedenceDfa_ for the current DFA.
///
/// - note: This method no longer performs any action.
///
public final func setPrecedenceDfa(_ precedenceDfa: Bool) throws {
if precedenceDfa != isPrecedenceDfa() {
throw ANTLRError.unsupportedOperation(msg: "The precedenceDfa field cannot change after a DFA is constructed.")
}
}
///
/// Return a list of all states in this DFA, ordered by state number.
///