[Swift] Replace IntervalSet.setReadonly with makeReadonly.

Replace IntervalSet.setReadonly(Bool) with makeReadonly().  This
operation only ever works in one direction, and would throw an exception
if a caller attempted to make a read-only IntervalSet read-write again.
By changing the interface we remove the need to check this, and so we
don't need to declare the exception.  Unlike in the Java runtime, we
need to declare the possibility of the exception at the callsite, so this
was pointlessly cluttering.
This commit is contained in:
Ewan Mellor 2017-11-09 14:49:45 -08:00
parent b4c34da1f0
commit afdfb56b59
No known key found for this signature in database
GPG Key ID: 7CE1C6BC9EC8645D
2 changed files with 6 additions and 11 deletions

View File

@ -85,13 +85,12 @@ public class ATN {
/// rule.
///
public func nextTokens(_ s: ATNState) -> IntervalSet {
if let nextTokenWithinRule = s.nextTokenWithinRule
{
if let nextTokenWithinRule = s.nextTokenWithinRule {
return nextTokenWithinRule
}
let intervalSet = nextTokens(s, nil)
s.nextTokenWithinRule = intervalSet
try! intervalSet.setReadonly(true)
intervalSet.makeReadonly()
return intervalSet
}

View File

@ -22,13 +22,13 @@ public class IntervalSet: IntSet, Hashable, CustomStringConvertible {
public static let COMPLETE_CHAR_SET: IntervalSet =
{
let set = IntervalSet.of(Lexer.MIN_CHAR_VALUE, Lexer.MAX_CHAR_VALUE)
try! set.setReadonly(true)
set.makeReadonly()
return set
}()
public static let EMPTY_SET: IntervalSet = {
let set = IntervalSet()
try! set.setReadonly(true)
set.makeReadonly()
return set
}()
@ -702,12 +702,8 @@ public class IntervalSet: IntSet, Hashable, CustomStringConvertible {
return readonly
}
public func setReadonly(_ readonly: Bool) throws {
if self.readonly && !readonly {
throw ANTLRError.illegalState(msg: "can't alter readonly IntervalSet")
}
self.readonly = readonly
public func makeReadonly() {
readonly = true
}
}