forked from jasder/antlr
Migrate the Swift runtime to Swift 4.
Remove a number of generic type constraints, since these can now be inferred by the compiler. Match the syntax change when passing a tuple into a function (adding an extra set of parens). Change filterPrecedencePredicates to avoid a now-illegal cast. Match the renames truncatingBitPattern -> truncatingIfNeeded, multiplyWithOverflow -> multipliedReportingOverflow, etc. In some cases the multiplyWithOverflow calls are replaced by overflowing operators (e.g. &*) instead.
This commit is contained in:
parent
365d4f40bb
commit
8a292c0f4f
|
@ -39,12 +39,12 @@ public protocol ANTLRErrorListener: class {
|
||||||
/// the parser was able to recover in line without exiting the
|
/// the parser was able to recover in line without exiting the
|
||||||
/// surrounding rule.
|
/// surrounding rule.
|
||||||
///
|
///
|
||||||
func syntaxError<T:ATNSimulator>(_ recognizer: Recognizer<T>,
|
func syntaxError<T>(_ recognizer: Recognizer<T>,
|
||||||
_ offendingSymbol: AnyObject?,
|
_ offendingSymbol: AnyObject?,
|
||||||
_ line: Int,
|
_ line: Int,
|
||||||
_ charPositionInLine: Int,
|
_ charPositionInLine: Int,
|
||||||
_ msg: String,
|
_ msg: String,
|
||||||
_ e: AnyObject?
|
_ e: AnyObject?
|
||||||
)
|
)
|
||||||
|
|
||||||
///
|
///
|
||||||
|
|
|
@ -17,12 +17,12 @@ open class BaseErrorListener: ANTLRErrorListener {
|
||||||
public init() {
|
public init() {
|
||||||
}
|
}
|
||||||
|
|
||||||
open func syntaxError<T:ATNSimulator>(_ recognizer: Recognizer<T>,
|
open func syntaxError<T>(_ recognizer: Recognizer<T>,
|
||||||
_ offendingSymbol: AnyObject?,
|
_ offendingSymbol: AnyObject?,
|
||||||
_ line: Int,
|
_ line: Int,
|
||||||
_ charPositionInLine: Int,
|
_ charPositionInLine: Int,
|
||||||
_ msg: String,
|
_ msg: String,
|
||||||
_ e: AnyObject?
|
_ e: AnyObject?
|
||||||
) {
|
) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -25,12 +25,12 @@ public class ConsoleErrorListener: BaseErrorListener {
|
||||||
/// line __line__:__charPositionInLine__ __msg__
|
/// line __line__:__charPositionInLine__ __msg__
|
||||||
///
|
///
|
||||||
///
|
///
|
||||||
override public func syntaxError<T:ATNSimulator>(_ recognizer: Recognizer<T>,
|
override public func syntaxError<T>(_ recognizer: Recognizer<T>,
|
||||||
_ offendingSymbol: AnyObject?,
|
_ offendingSymbol: AnyObject?,
|
||||||
_ line: Int,
|
_ line: Int,
|
||||||
_ charPositionInLine: Int,
|
_ charPositionInLine: Int,
|
||||||
_ msg: String,
|
_ msg: String,
|
||||||
_ e: AnyObject?
|
_ e: AnyObject?
|
||||||
) {
|
) {
|
||||||
if Parser.ConsoleError {
|
if Parser.ConsoleError {
|
||||||
errPrint("line \(line):\(charPositionInLine) \(msg)")
|
errPrint("line \(line):\(charPositionInLine) \(msg)")
|
||||||
|
|
|
@ -405,7 +405,7 @@ open class Lexer: Recognizer<LexerATNSimulator>
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
open func notifyListeners<T:ATNSimulator>(_ e: LexerNoViableAltException, recognizer: Recognizer<T>) {
|
open func notifyListeners<T>(_ e: LexerNoViableAltException, recognizer: Recognizer<T>) {
|
||||||
|
|
||||||
let text: String = _input!.getText(Interval.of(_tokenStartCharIndex, _input!.index()))
|
let text: String = _input!.getText(Interval.of(_tokenStartCharIndex, _input!.index()))
|
||||||
let msg: String = "token recognition error at: '\(getErrorDisplay(text))'"
|
let msg: String = "token recognition error at: '\(getErrorDisplay(text))'"
|
||||||
|
|
|
@ -20,13 +20,13 @@ public class ProxyErrorListener: ANTLRErrorListener {
|
||||||
self.delegates = delegates
|
self.delegates = delegates
|
||||||
}
|
}
|
||||||
|
|
||||||
public func syntaxError<T:ATNSimulator>(_ recognizer: Recognizer<T>,
|
public func syntaxError<T>(_ recognizer: Recognizer<T>,
|
||||||
_ offendingSymbol: AnyObject?,
|
_ offendingSymbol: AnyObject?,
|
||||||
_ line: Int,
|
_ line: Int,
|
||||||
_ charPositionInLine: Int,
|
_ charPositionInLine: Int,
|
||||||
_ msg: String,
|
_ msg: String,
|
||||||
_ e: AnyObject?)
|
_ e: AnyObject?)
|
||||||
{
|
{
|
||||||
for listener: ANTLRErrorListener in delegates {
|
for listener: ANTLRErrorListener in delegates {
|
||||||
listener.syntaxError(recognizer, offendingSymbol, line, charPositionInLine, msg, e)
|
listener.syntaxError(recognizer, offendingSymbol, line, charPositionInLine, msg, e)
|
||||||
}
|
}
|
||||||
|
|
|
@ -233,7 +233,7 @@ open class RuleContext: RuleNode {
|
||||||
return description
|
return description
|
||||||
}
|
}
|
||||||
|
|
||||||
public final func toString<T:ATNSimulator>(_ recog: Recognizer<T>) -> String {
|
public final func toString<T>(_ recog: Recognizer<T>) -> String {
|
||||||
return toString(recog, ParserRuleContext.EMPTY)
|
return toString(recog, ParserRuleContext.EMPTY)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -242,7 +242,7 @@ open class RuleContext: RuleNode {
|
||||||
}
|
}
|
||||||
|
|
||||||
// recog null unless ParserRuleContext, in which case we use subclass toString(...)
|
// recog null unless ParserRuleContext, in which case we use subclass toString(...)
|
||||||
open func toString<T:ATNSimulator>(_ recog: Recognizer<T>?, _ stop: RuleContext) -> String {
|
open func toString<T>(_ recog: Recognizer<T>?, _ stop: RuleContext) -> String {
|
||||||
let ruleNames: [String]? = recog != nil ? recog!.getRuleNames() : nil
|
let ruleNames: [String]? = recog != nil ? recog!.getRuleNames() : nil
|
||||||
let ruleNamesList: Array<String>? = ruleNames ?? nil
|
let ruleNamesList: Array<String>? = ruleNames ?? nil
|
||||||
return toString(ruleNamesList, stop)
|
return toString(ruleNamesList, stop)
|
||||||
|
|
|
@ -167,7 +167,7 @@ public class ATNConfig: Hashable, CustomStringConvertible {
|
||||||
//return "MyClass \(string)"
|
//return "MyClass \(string)"
|
||||||
return toString(nil, true)
|
return toString(nil, true)
|
||||||
}
|
}
|
||||||
public func toString<T:ATNSimulator>(_ recog: Recognizer<T>?, _ showAlt: Bool) -> String {
|
public func toString<T>(_ recog: Recognizer<T>?, _ showAlt: Bool) -> String {
|
||||||
let buf: StringBuilder = StringBuilder()
|
let buf: StringBuilder = StringBuilder()
|
||||||
buf.append("(")
|
buf.append("(")
|
||||||
buf.append(state)
|
buf.append(state)
|
||||||
|
|
|
@ -238,12 +238,9 @@ public class ATNConfigSet: Hashable, CustomStringConvertible {
|
||||||
private var configsHashValue: Int {
|
private var configsHashValue: Int {
|
||||||
var hashCode = 1
|
var hashCode = 1
|
||||||
for item in configs {
|
for item in configs {
|
||||||
hashCode = Int.multiplyWithOverflow(3, hashCode).0
|
hashCode = hashCode &* 3 &+ item.hashValue
|
||||||
hashCode = Int.addWithOverflow(hashCode, item.hashValue).0
|
|
||||||
|
|
||||||
}
|
}
|
||||||
return hashCode
|
return hashCode
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public final var count: Int {
|
public final var count: Int {
|
||||||
|
|
|
@ -175,7 +175,7 @@ public class ATNDeserializer {
|
||||||
if let s = s as? BlockStartState {
|
if let s = s as? BlockStartState {
|
||||||
let endStateNumber: Int = toInt(data[p])
|
let endStateNumber: Int = toInt(data[p])
|
||||||
p += 1
|
p += 1
|
||||||
endStateNumbers.append(s, endStateNumber)
|
endStateNumbers.append((s, endStateNumber))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
atn.addState(s)
|
atn.addState(s)
|
||||||
|
|
|
@ -712,17 +712,17 @@ public class PredictionContext: Hashable, CustomStringConvertible {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public func toString<T:ATNSimulator>(_ recog: Recognizer<T>) -> String {
|
public func toString<T>(_ recog: Recognizer<T>) -> String {
|
||||||
return NSStringFromClass(PredictionContext.self)
|
return NSStringFromClass(PredictionContext.self)
|
||||||
// return toString(recog, ParserRuleContext.EMPTY);
|
// return toString(recog, ParserRuleContext.EMPTY);
|
||||||
}
|
}
|
||||||
|
|
||||||
public func toStrings<T:ATNSimulator>(_ recognizer: Recognizer<T>, _ currentState: Int) -> [String] {
|
public func toStrings<T>(_ recognizer: Recognizer<T>, _ currentState: Int) -> [String] {
|
||||||
return toStrings(recognizer, PredictionContext.EMPTY, currentState)
|
return toStrings(recognizer, PredictionContext.EMPTY, currentState)
|
||||||
}
|
}
|
||||||
|
|
||||||
// FROM SAM
|
// FROM SAM
|
||||||
public func toStrings<T:ATNSimulator>(_ recognizer: Recognizer<T>?, _ stop: PredictionContext, _ currentState: Int) -> [String] {
|
public func toStrings<T>(_ recognizer: Recognizer<T>?, _ stop: PredictionContext, _ currentState: Int) -> [String] {
|
||||||
var result: Array<String> = Array<String>()
|
var result: Array<String> = Array<String>()
|
||||||
var perm: Int = 0
|
var perm: Int = 0
|
||||||
outer: while true {
|
outer: while true {
|
||||||
|
|
|
@ -37,7 +37,7 @@ public class SemanticContext: Hashable, CustomStringConvertible {
|
||||||
/// prediction, so we passed in the outer context here in case of context
|
/// prediction, so we passed in the outer context here in case of context
|
||||||
/// dependent predicate evaluation.
|
/// dependent predicate evaluation.
|
||||||
///
|
///
|
||||||
public func eval<T:ATNSimulator>(_ parser: Recognizer<T>, _ parserCallStack: RuleContext) throws -> Bool {
|
public func eval<T>(_ parser: Recognizer<T>, _ parserCallStack: RuleContext) throws -> Bool {
|
||||||
RuntimeException(#function + " must be overridden")
|
RuntimeException(#function + " must be overridden")
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
@ -58,7 +58,7 @@ public class SemanticContext: Hashable, CustomStringConvertible {
|
||||||
/// * A non-`null` _org.antlr.v4.runtime.atn.SemanticContext_: the new simplified
|
/// * A non-`null` _org.antlr.v4.runtime.atn.SemanticContext_: the new simplified
|
||||||
/// semantic context after precedence predicates are evaluated.
|
/// semantic context after precedence predicates are evaluated.
|
||||||
///
|
///
|
||||||
public func evalPrecedence<T:ATNSimulator>(_ parser: Recognizer<T>, _ parserCallStack: RuleContext) throws -> SemanticContext? {
|
public func evalPrecedence<T>(_ parser: Recognizer<T>, _ parserCallStack: RuleContext) throws -> SemanticContext? {
|
||||||
return self
|
return self
|
||||||
}
|
}
|
||||||
public var hashValue: Int {
|
public var hashValue: Int {
|
||||||
|
@ -90,7 +90,7 @@ public class SemanticContext: Hashable, CustomStringConvertible {
|
||||||
}
|
}
|
||||||
|
|
||||||
override
|
override
|
||||||
public func eval<T:ATNSimulator>(_ parser: Recognizer<T>, _ parserCallStack: RuleContext) throws -> Bool {
|
public func eval<T>(_ parser: Recognizer<T>, _ parserCallStack: RuleContext) throws -> Bool {
|
||||||
let localctx: RuleContext? = isCtxDependent ? parserCallStack : nil
|
let localctx: RuleContext? = isCtxDependent ? parserCallStack : nil
|
||||||
return try parser.sempred(localctx, ruleIndex, predIndex)
|
return try parser.sempred(localctx, ruleIndex, predIndex)
|
||||||
}
|
}
|
||||||
|
@ -126,12 +126,12 @@ public class SemanticContext: Hashable, CustomStringConvertible {
|
||||||
}
|
}
|
||||||
|
|
||||||
override
|
override
|
||||||
public func eval<T:ATNSimulator>(_ parser: Recognizer<T>, _ parserCallStack: RuleContext) throws -> Bool {
|
public func eval<T>(_ parser: Recognizer<T>, _ parserCallStack: RuleContext) throws -> Bool {
|
||||||
return try parser.precpred(parserCallStack, precedence)
|
return try parser.precpred(parserCallStack, precedence)
|
||||||
}
|
}
|
||||||
|
|
||||||
override
|
override
|
||||||
public func evalPrecedence<T:ATNSimulator>(_ parser: Recognizer<T>, _ parserCallStack: RuleContext) throws -> SemanticContext? {
|
public func evalPrecedence<T>(_ parser: Recognizer<T>, _ parserCallStack: RuleContext) throws -> SemanticContext? {
|
||||||
if try parser.precpred(parserCallStack, precedence) {
|
if try parser.precpred(parserCallStack, precedence) {
|
||||||
return SemanticContext.NONE
|
return SemanticContext.NONE
|
||||||
} else {
|
} else {
|
||||||
|
@ -198,18 +198,17 @@ public class SemanticContext: Hashable, CustomStringConvertible {
|
||||||
operands.insert(b)
|
operands.insert(b)
|
||||||
}
|
}
|
||||||
|
|
||||||
let precedencePredicates: Array<PrecedencePredicate> =
|
let precedencePredicates = SemanticContext.filterPrecedencePredicates(&operands)
|
||||||
SemanticContext.filterPrecedencePredicates(&operands)
|
|
||||||
if !precedencePredicates.isEmpty {
|
if !precedencePredicates.isEmpty {
|
||||||
// interested in the transition with the lowest precedence
|
// interested in the transition with the lowest precedence
|
||||||
|
|
||||||
let reduced: PrecedencePredicate = precedencePredicates.sorted {
|
let reduced = precedencePredicates.sorted {
|
||||||
$0.precedence < $1.precedence
|
$0.precedence < $1.precedence
|
||||||
}.first! //Collections.min(precedencePredicates);
|
}
|
||||||
operands.insert(reduced)
|
operands.insert(reduced[0])
|
||||||
}
|
}
|
||||||
|
|
||||||
opnds = Array(operands) //.toArray(new, SemanticContext[operands.size()]);
|
opnds = Array(operands)
|
||||||
}
|
}
|
||||||
|
|
||||||
override
|
override
|
||||||
|
@ -234,7 +233,7 @@ public class SemanticContext: Hashable, CustomStringConvertible {
|
||||||
/// unordered.
|
/// unordered.
|
||||||
///
|
///
|
||||||
override
|
override
|
||||||
public func eval<T:ATNSimulator>(_ parser: Recognizer<T>, _ parserCallStack: RuleContext) throws -> Bool {
|
public func eval<T>(_ parser: Recognizer<T>, _ parserCallStack: RuleContext) throws -> Bool {
|
||||||
for opnd: SemanticContext in opnds {
|
for opnd: SemanticContext in opnds {
|
||||||
if try !opnd.eval(parser, parserCallStack) {
|
if try !opnd.eval(parser, parserCallStack) {
|
||||||
return false
|
return false
|
||||||
|
@ -244,7 +243,7 @@ public class SemanticContext: Hashable, CustomStringConvertible {
|
||||||
}
|
}
|
||||||
|
|
||||||
override
|
override
|
||||||
public func evalPrecedence<T:ATNSimulator>(_ parser: Recognizer<T>, _ parserCallStack: RuleContext) throws -> SemanticContext? {
|
public func evalPrecedence<T>(_ parser: Recognizer<T>, _ parserCallStack: RuleContext) throws -> SemanticContext? {
|
||||||
var differs: Bool = false
|
var differs: Bool = false
|
||||||
var operands: Array<SemanticContext> = Array<SemanticContext>()
|
var operands: Array<SemanticContext> = Array<SemanticContext>()
|
||||||
for context: SemanticContext in opnds {
|
for context: SemanticContext in opnds {
|
||||||
|
@ -314,17 +313,17 @@ public class SemanticContext: Hashable, CustomStringConvertible {
|
||||||
operands.insert(b)
|
operands.insert(b)
|
||||||
}
|
}
|
||||||
|
|
||||||
let precedencePredicates: Array<PrecedencePredicate> = SemanticContext.filterPrecedencePredicates(&operands)
|
let precedencePredicates = SemanticContext.filterPrecedencePredicates(&operands)
|
||||||
if !precedencePredicates.isEmpty {
|
if !precedencePredicates.isEmpty {
|
||||||
// interested in the transition with the highest precedence
|
// interested in the transition with the highest precedence
|
||||||
let reduced: PrecedencePredicate = precedencePredicates.sorted {
|
|
||||||
|
let reduced = precedencePredicates.sorted {
|
||||||
$0.precedence > $1.precedence
|
$0.precedence > $1.precedence
|
||||||
}.first!
|
}
|
||||||
//var reduced : PrecedencePredicate = Collections.max(precedencePredicates);
|
operands.insert(reduced[0])
|
||||||
operands.insert(reduced)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
self.opnds = Array(operands) //operands.toArray(new, SemanticContext[operands.size()]);
|
self.opnds = Array(operands)
|
||||||
}
|
}
|
||||||
|
|
||||||
override
|
override
|
||||||
|
@ -347,7 +346,7 @@ public class SemanticContext: Hashable, CustomStringConvertible {
|
||||||
/// unordered.
|
/// unordered.
|
||||||
///
|
///
|
||||||
override
|
override
|
||||||
public func eval<T:ATNSimulator>(_ parser: Recognizer<T>, _ parserCallStack: RuleContext) throws -> Bool {
|
public func eval<T>(_ parser: Recognizer<T>, _ parserCallStack: RuleContext) throws -> Bool {
|
||||||
for opnd: SemanticContext in opnds {
|
for opnd: SemanticContext in opnds {
|
||||||
if try opnd.eval(parser, parserCallStack) {
|
if try opnd.eval(parser, parserCallStack) {
|
||||||
return true
|
return true
|
||||||
|
@ -357,7 +356,7 @@ public class SemanticContext: Hashable, CustomStringConvertible {
|
||||||
}
|
}
|
||||||
|
|
||||||
override
|
override
|
||||||
public func evalPrecedence<T:ATNSimulator>(_ parser: Recognizer<T>, _ parserCallStack: RuleContext) throws -> SemanticContext? {
|
public func evalPrecedence<T>(_ parser: Recognizer<T>, _ parserCallStack: RuleContext) throws -> SemanticContext? {
|
||||||
var differs: Bool = false
|
var differs: Bool = false
|
||||||
var operands: Array<SemanticContext> = Array<SemanticContext>()
|
var operands: Array<SemanticContext> = Array<SemanticContext>()
|
||||||
for context: SemanticContext in opnds {
|
for context: SemanticContext in opnds {
|
||||||
|
@ -443,21 +442,14 @@ public class SemanticContext: Hashable, CustomStringConvertible {
|
||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
private static func filterPrecedencePredicates(
|
private static func filterPrecedencePredicates(_ collection: inout Set<SemanticContext>) -> [PrecedencePredicate] {
|
||||||
_ collection: inout Set<SemanticContext>) ->
|
let result = collection.flatMap {
|
||||||
Array<PrecedencePredicate> {
|
$0 as? PrecedencePredicate
|
||||||
|
|
||||||
let result = collection.filter {
|
|
||||||
$0 is PrecedencePredicate
|
|
||||||
}
|
}
|
||||||
collection = Set<SemanticContext>(collection.filter {
|
collection = Set<SemanticContext>(collection.filter {
|
||||||
!($0 is PrecedencePredicate)
|
!($0 is PrecedencePredicate)
|
||||||
})
|
})
|
||||||
//if (result == nil) {
|
return result
|
||||||
//return Array<PrecedencePredicate>();
|
|
||||||
//}
|
|
||||||
|
|
||||||
return (result as! Array<PrecedencePredicate>)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -69,7 +69,7 @@ public final class ArrayWrapper<T: Hashable>: ExpressibleByArrayLiteral, Hashabl
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public func == <Element: Equatable>(lhs: ArrayWrapper<Element>, rhs: ArrayWrapper<Element>) -> Bool {
|
public func == <Element>(lhs: ArrayWrapper<Element>, rhs: ArrayWrapper<Element>) -> Bool {
|
||||||
if lhs === rhs {
|
if lhs === rhs {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
|
@ -648,12 +648,12 @@ public class BitSet: Hashable, CustomStringConvertible {
|
||||||
return 64
|
return 64
|
||||||
}
|
}
|
||||||
var n: Int32 = 63
|
var n: Int32 = 63
|
||||||
y = Int32(truncatingBitPattern: i)
|
y = Int32(truncatingIfNeeded: i)
|
||||||
if y != 0 {
|
if y != 0 {
|
||||||
n = n - 32
|
n = n - 32
|
||||||
x = y
|
x = y
|
||||||
} else {
|
} else {
|
||||||
x = Int32(truncatingBitPattern: i >>> 32)
|
x = Int32(truncatingIfNeeded: i >>> 32)
|
||||||
}
|
}
|
||||||
|
|
||||||
y = x << 16
|
y = x << 16
|
||||||
|
|
|
@ -41,7 +41,7 @@ final class Entry<K: Hashable,V>: CustomStringConvertible {
|
||||||
var description: String { return "\(getKey())=\(getValue())" }
|
var description: String { return "\(getKey())=\(getValue())" }
|
||||||
|
|
||||||
}
|
}
|
||||||
func == <K: Hashable, V: Equatable>(lhs: Entry<K,V>, rhs: Entry<K,V>) -> Bool {
|
func == <K, V: Equatable>(lhs: Entry<K,V>, rhs: Entry<K,V>) -> Bool {
|
||||||
if lhs === rhs {
|
if lhs === rhs {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
@ -52,7 +52,7 @@ func == <K: Hashable, V: Equatable>(lhs: Entry<K,V>, rhs: Entry<K,V>) -> Bool {
|
||||||
}
|
}
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
func == <K: Hashable, V: Equatable>(lhs: Entry<K,V?>, rhs: Entry<K,V?>) -> Bool {
|
func == <K, V: Equatable>(lhs: Entry<K,V?>, rhs: Entry<K,V?>) -> Bool {
|
||||||
if lhs === rhs {
|
if lhs === rhs {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
|
@ -49,19 +49,19 @@ public final class MurmurHash {
|
||||||
let m: Int32 = 5
|
let m: Int32 = 5
|
||||||
let n: Int32 = -430675100//0xE6546B64;
|
let n: Int32 = -430675100//0xE6546B64;
|
||||||
|
|
||||||
var k: Int32 = Int32(truncatingBitPattern: value)
|
var k: Int32 = Int32(truncatingIfNeeded: value)
|
||||||
k = Int32.multiplyWithOverflow(k, c1).0
|
k = k.multipliedReportingOverflow(by: c1).partialValue
|
||||||
// (k,_) = UInt32.multiplyWithOverflow(k, c1) ;//( k * c1);
|
// (k,_) = UInt32.multiplyWithOverflow(k, c1) ;//( k * c1);
|
||||||
//TODO: CHECKE >>>
|
//TODO: CHECKE >>>
|
||||||
k = (k << r1) | (k >>> (Int32(32) - r1)) //k = (k << r1) | (k >>> (32 - r1));
|
k = (k << r1) | (k >>> (Int32(32) - r1)) //k = (k << r1) | (k >>> (32 - r1));
|
||||||
//k = UInt32 (truncatingBitPattern:Int64(Int64(k) * Int64(c2)));//( k * c2);
|
//k = UInt32 (truncatingBitPattern:Int64(Int64(k) * Int64(c2)));//( k * c2);
|
||||||
//(k,_) = UInt32.multiplyWithOverflow(k, c2)
|
//(k,_) = UInt32.multiplyWithOverflow(k, c2)
|
||||||
k = Int32.multiplyWithOverflow(k, c2).0
|
k = k.multipliedReportingOverflow(by: c2).partialValue
|
||||||
var hash = Int32(hashIn)
|
var hash = Int32(hashIn)
|
||||||
hash = hash ^ k
|
hash = hash ^ k
|
||||||
hash = (hash << r2) | (hash >>> (Int32(32) - r2))//hash = (hash << r2) | (hash >>> (32 - r2));
|
hash = (hash << r2) | (hash >>> (Int32(32) - r2))//hash = (hash << r2) | (hash >>> (32 - r2));
|
||||||
(hash, _) = Int32.multiplyWithOverflow(hash, m)
|
hash = hash.multipliedReportingOverflow(by: m).partialValue
|
||||||
(hash, _) = Int32.addWithOverflow(hash, n)
|
hash = hash.addingReportingOverflow(n).partialValue
|
||||||
//hash = hash * m + n;
|
//hash = hash * m + n;
|
||||||
// print("murmur update2 : \(hash)")
|
// print("murmur update2 : \(hash)")
|
||||||
return Int(hash)
|
return Int(hash)
|
||||||
|
@ -90,12 +90,12 @@ public final class MurmurHash {
|
||||||
public static func finish(_ hashin: Int, _ numberOfWordsIn: Int) -> Int {
|
public static func finish(_ hashin: Int, _ numberOfWordsIn: Int) -> Int {
|
||||||
var hash = Int32(hashin)
|
var hash = Int32(hashin)
|
||||||
let numberOfWords = Int32(numberOfWordsIn)
|
let numberOfWords = Int32(numberOfWordsIn)
|
||||||
hash = hash ^ Int32.multiplyWithOverflow(numberOfWords, Int32(4)).0 //(numberOfWords * UInt32(4));
|
hash = hash ^ numberOfWords.multipliedReportingOverflow(by: 4).partialValue //(numberOfWords * UInt32(4));
|
||||||
hash = hash ^ (hash >>> Int32(16)) //hash = hash ^ (hash >>> 16);
|
hash = hash ^ (hash >>> Int32(16)) //hash = hash ^ (hash >>> 16);
|
||||||
(hash, _) = Int32.multiplyWithOverflow(hash, Int32(-2048144789))//hash * UInt32(0x85EBCA6B);
|
hash = hash.multipliedReportingOverflow(by: -2048144789).partialValue //hash * UInt32(0x85EBCA6B);
|
||||||
hash = hash ^ (hash >>> Int32(13))//hash = hash ^ (hash >>> 13);
|
hash = hash ^ (hash >>> Int32(13))//hash = hash ^ (hash >>> 13);
|
||||||
//hash = UInt32(truncatingBitPattern: UInt64(hash) * UInt64(0xC2B2AE35)) ;
|
//hash = UInt32(truncatingBitPattern: UInt64(hash) * UInt64(0xC2B2AE35)) ;
|
||||||
(hash, _) = Int32.multiplyWithOverflow(hash, Int32(-1028477387))
|
hash = hash.multipliedReportingOverflow(by: -1028477387).partialValue
|
||||||
hash = hash ^ (hash >>> Int32(16))// hash = hash ^ (hash >>> 16);
|
hash = hash ^ (hash >>> Int32(16))// hash = hash ^ (hash >>> 16);
|
||||||
//print("murmur finish : \(hash)")
|
//print("murmur finish : \(hash)")
|
||||||
return Int(hash)
|
return Int(hash)
|
||||||
|
|
|
@ -61,7 +61,7 @@ extension String {
|
||||||
let start = characters.index(startIndex, offsetBy: integerRange.lowerBound)
|
let start = characters.index(startIndex, offsetBy: integerRange.lowerBound)
|
||||||
let end = characters.index(startIndex, offsetBy: integerRange.upperBound)
|
let end = characters.index(startIndex, offsetBy: integerRange.upperBound)
|
||||||
let range = start ..< end
|
let range = start ..< end
|
||||||
return self[range]
|
return String(self[range])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -62,10 +62,10 @@ class VisitorTests: XCTestCase {
|
||||||
|
|
||||||
var errors = [String]()
|
var errors = [String]()
|
||||||
|
|
||||||
override func syntaxError<T : ATNSimulator>(_ recognizer: Recognizer<T>,
|
override func syntaxError<T>(_ recognizer: Recognizer<T>,
|
||||||
_ offendingSymbol: AnyObject?,
|
_ offendingSymbol: AnyObject?,
|
||||||
_ line: Int, _ charPositionInLine: Int,
|
_ line: Int, _ charPositionInLine: Int,
|
||||||
_ msg: String, _ e: AnyObject?) {
|
_ msg: String, _ e: AnyObject?) {
|
||||||
errors.append("line \(line):\(charPositionInLine) \(msg)")
|
errors.append("line \(line):\(charPositionInLine) \(msg)")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue