Commit Graph

180 Commits

Author SHA1 Message Date
parrt 38a95da397 manual edits of 4.7.1 -> 4.7.2 2018-12-17 14:32:39 -08:00
Terence Parr 0308999f06
Merge pull request #2413 from nxtstep/fix/mutex-free
[Swift-runtime] Make sure mutexes are being freed accordingly
2018-11-18 09:13:57 -08:00
Terence Parr 6080a0639c
Merge pull request #2411 from ewanmellor/swift-fix-2369
[Swift] Syntax error in antlr4/runtime/Swift/boot.py
2018-11-16 08:48:09 -08:00
nxtstep 4e744043a3 Make sure mutexes are being freed accordingly 2018-11-16 17:26:52 +01:00
Ewan Mellor 9d29f116cb
[Swift] Syntax error in antlr4/runtime/Swift/boot.py
Make boot.py work under both Python 2 and 3.  This fixes #2369.

Add an extra exception handler, for neater error messages.
2018-11-15 21:49:58 -08:00
Ewan Mellor 0f1614dd99
[Swift] Tidy-ups around addDFAEdge.
Do some tidy-ups around addDFAEdge, improving the handling of nils so that
we're not forcing or nil-checking so much.
2018-11-15 21:25:47 -08:00
Ewan Mellor 8f42439943
[Swift] Remove unused constructors.
Remove unused constructors from ATNConfig and DFAState, and merge two
by using a default parameter instead.
2018-11-15 21:25:47 -08:00
Ewan Mellor 176d92d373
[Swift] Tighten up the permissions on lots of fields
Tighten up the permissions on lots of fields, for debuggability.
2018-11-15 21:25:47 -08:00
Ewan Mellor 623fe00fb7
[Swift] Change a whole bunch of "final var" to "let".
I think that there was some confusion when the original port from Java
was done, because "final" in Java is not the same as "final" in Swift.
2018-11-15 21:25:47 -08:00
Ewan Mellor e01d0be92c
[Swift] Remove implicitly unwrapped optional from ATN.grammarType.
This is set in the constructor and is never nil, so this wasn't doing
anything.
2018-11-15 21:25:47 -08:00
Ewan Mellor 9ca1a9e158
[Swift] Remove ATNState.INITIAL_NUM_TRANSITIONS.
This was brought over from the Java runtime in the initial port, but there
it was used as an array capacity hint.  We're not using it in Swift so
this is useless.
2018-11-15 21:25:47 -08:00
Ewan Mellor 8a34dcdcf9
[Swift] Move doc-comment.
This was attached to the incorrect method in the initial port from Java.
2018-11-15 21:25:47 -08:00
Ewan Mellor 3deb4d91e6
[Swift] Remove OrderedATNConfigSet.
This is a subclass that only exists to have a different constructor.  There
is no need for this construction in Swift, since we have named parameters,
so we can remove the entire subclass and make ATNConfigSet final instead.
2018-11-15 21:25:47 -08:00
Ewan Mellor 657ab4b3b4
[Swift] Remove OrderedATNConfig.
This is unused.
2018-11-15 21:25:47 -08:00
Ewan Mellor 768a0a66e6
[Swift] Build and test error checking.
Change all the subprocess calls in boot.py to check whether they succeeded,
and set the script status appropriately.

In particular, when our unit tests fail, we need the script to exit
with a failure code so that we actually notice on Travis.
2018-11-15 15:33:10 -08:00
Ewan Mellor d275a8c97f
[Swift] Make ParserATNSimulator.precedenceTransition return a nullable value.
This was always clearly a possibility, looking at the body of the method.
The newly-enabled performance tests expose this bug (and I don't know how
we've gotten away with it otherwise for so long).

The Java runtime also returns null at this point.
2018-11-15 15:28:47 -08:00
Ewan Mellor 8cd798431d
[Swift] Change getStateToAltMap to use Int as the dictionary key, not ATNState.
The ATNState hashValue and == override are just using the stateNumber field, so
using the Int directly is equivalent, and saves bouncing through those methods.

This also seems to be a correctness issue with the new Hashable protocol changes in
Swift 4.2 (though I admit that I don't know why).

Remove PredictionMode.getStateToAltMap, which was just a stub onto
ATNConfigSet.getStateToAltMap and didn't seem to be doing anything useful.
2018-11-15 11:26:09 -08:00
Ewan Mellor 1184c67f72
[Swift] Swift-Runtime error after XCode 10 / iOS 12 update
Avoid adding to closureBusy before all ATNConfig properties are set.

This fixes #2372.

This is a port of c8805ab from the Java runtime.  That was PR #1955.
2018-11-15 11:26:09 -08:00
Ewan Mellor 75d4d867ef
[Swift] Suppress "Optional" in the output when printing a value.
Suppress "Optional" in the output when printing a value in the tests and
some debugging messages.

This is a change in behavior in Swift 4.2 (SE-0054) that implicitly
unwrapped optionals are now seen as plain Optional at runtime, and so
print doesn't implicitly unwrap them any more.
2018-11-15 11:26:09 -08:00
Ewan Mellor 938883d516
[Swift] Fix MurmurHash calculations under Swift 4.2.
This was working before because calling hashValue on a boxed UInt32 gave
back the value itself.  This is apparently no longer true.

It's not something we should have been doing anyway.  We were needlessly
boxing the intermediate hash values, and passing them into a generic
method, just to unbox them again.

Fix this by creating a helper method, and calling that directly when
updating intermediate hash values.
2018-11-15 11:26:09 -08:00
Ewan Mellor e327e4a13e
Change uses of functions deprecated in Swift 4.2.
This is three instances of flatMap changing to compactMap, and
one instance of UnsafeMutablePointer.deallocate(capacity:) changing
to UnsafeMutablePointer.deallocate().
2018-11-15 11:26:09 -08:00
Terence Parr dc15fe9133
Merge pull request #2404 from ewanmellor/swift-repeated-epsilon-transitions
[Swift] Remove repeated epsilon transitions in ATN.
2018-11-15 09:28:26 -08:00
Ewan Mellor c88fe83578
[Swift] Remove repeated epsilon transitions in ATN.
Port the cset 125a509e from the Java runtime.  This adds checks to ATNState
to remove any repeated edges.  This was PR #1369 for the Java runtime.
2018-11-14 21:11:27 -08:00
Ewan Mellor 842d3d7597
[Swift] Report InputMismatchException with original context information
Port 0803c74 from the Java runtime to Swift.  This was issue #1922.
Enable the corresponding tests for Swift.
2018-11-14 20:28:24 -08:00
Terence Parr 39a1aa5c0f
Merge pull request #2156 from ewanmellor/swift-stream-tidyups
[Swift] Minor tidyups in the stream code.
2018-11-08 13:45:30 -08:00
Terence Parr 54131a074e
Merge pull request #2155 from ewanmellor/swift-ATNDeserializationOptions-struct
[Swift] Make ATNDeserializationOptions a simple struct.
2018-11-08 13:45:16 -08:00
Terence Parr 0c63b68e18
Merge pull request #2154 from ewanmellor/swift-remove-hashmap
[Swift] Remove HashMap and fix Parser caches.
2018-11-08 13:44:59 -08:00
Ewan Mellor 35b9bbfe17
[Swift] Minor tidyups in the stream code.
No semantic change.
2017-12-08 16:36:00 -08:00
Ewan Mellor b4f3a619fd
[Swift] Make ATNDeserializationOptions a simple struct.
The previous code was ported from Java, which resulted in 70 lines of code
to hold two bools.  Use a struct instead.
2017-12-08 16:35:21 -08:00
Ewan Mellor f8e63d53c5
[Swift] Remove HashMap and fix Parser caches.
Remove HashMap, and replace all uses of it with dictionaries.  There's
no need for us to have a custom HashMap implementation (mirroring the Java
standard library) when Swift's standard dictionaries work just fine.

Fix Parser.bypassAltsAtnCache.  This was declared as a Parser instance
variable, when in the Java runtime it is static (and therefore the cache
outlives the Parser instances).  It was also being handled in a
thread-unsafe manner, because the cache was being read outside of the
mutex that was supposed to be protecting it.  Fix both issues by moving
the cache and the mutex so that they are static to the Parser module and
rewriting getATNWithBypassAlts.

Remove Parser.decisionToDFAMutex.  The Java code uses a synchronized block
on ParserATNSimulator.decisionToDFA, but the translation to Swift had put
a mutex in Parser.  The decisionToDFA value is shared between Parser,
ParserATNSimulator, and the generated parser, so a mutex in
ParserATNSimulator isn't blocking all possible accesses, so it's useless.
Since this is only code for debugging anyway, just remove the useless mutex
and simplify getDFAStrings and dumpDFA.
2017-12-08 16:32:51 -08:00
parrt 763a1242b7 update version number and tweak doc 2017-12-08 12:47:11 -08:00
Terence Parr b5e6147cd5
Merge pull request #2123 from ewanmellor/swift-fix-parse-cancellation
[Swift] Fix parse-cancellation in BailErrorStrategy.
2017-11-29 09:56:09 -08:00
Terence Parr bd4f1a9365
Merge pull request #2122 from ewanmellor/swift-remove-recognizer-caches
[Swift] Remove Recognizer.tokenTypeMapCache and .ruleIndexMapCache.
2017-11-29 09:55:53 -08:00
Terence Parr 756fcdd5ec
Merge pull request #2121 from ewanmellor/swift-fix-interpreter-dfas
[Swift] Fix initialization of {Lexer,Parser}Interpreter.decisionToDFA.
2017-11-29 09:55:38 -08:00
Terence Parr c586a592ce
Merge pull request #2120 from ewanmellor/swift-remove-arraylist
[Swift] Remove ArrayList.
2017-11-29 09:55:23 -08:00
Terence Parr 406b1816c8
Merge pull request #2119 from ewanmellor/swift-remove-triple
[Swift] Remove Triple.swift.
2017-11-29 09:55:11 -08:00
Terence Parr 633de4aeab
Merge pull request #2118 from ewanmellor/swift-let-sharedcontextcache
[Swift] Make ATNSimulator.sharedContextCache non-optional.
2017-11-29 09:54:52 -08:00
Terence Parr aec23acb24
Merge pull request #2117 from ewanmellor/swift-remove-modeNameToStartState
[Swift] Remove unused ATN.modeNameToStartState.
2017-11-29 09:54:26 -08:00
Terence Parr ed37fa23e6
Merge pull request #2115 from ewanmellor/swift-minor-tidups
[Swift] Some minor tidyups.
2017-11-29 09:54:13 -08:00
Terence Parr 3536a84b52
Merge pull request #2114 from ewanmellor/swift-let-precedencedfa
[Swift] Make DFA.precedenceDfa be a "let" rather than a "var".
2017-11-29 09:53:57 -08:00
Terence Parr aaca1b9f3c
Merge pull request #2113 from ewanmellor/swift-makereadonly
[Swift] Replace IntervalSet.setReadonly with makeReadonly.
2017-11-29 09:53:40 -08:00
Terence Parr 8c1a46d87a
Merge pull request #2112 from ewanmellor/swift-mutexes-let
[Swift] Make all the mutexes "let" rather than "var".
2017-11-29 09:53:11 -08:00
Terence Parr d691f4d086
Merge pull request #2108 from ewanmellor/swift-tidyups-parser
Tidy-ups inside the Swift runtime around ParseTree, ParserRuleContext
2017-11-29 09:52:54 -08:00
Terence Parr 84e9a46932
Merge pull request #2107 from ewanmellor/swift-fix-deprecated-string-methods
Remove use of deprecated String functions
2017-11-29 09:52:27 -08:00
Terence Parr 6bcde64abf
Merge pull request #2106 from ewanmellor/swift-open-error-strategy
Open the error strategies to subclasses.
2017-11-29 09:50:03 -08:00
Terence Parr 9a701ef57f
Merge pull request #2103 from ewanmellor/swift-tidy-atndeserializer
Tidy ATNDeserializer.
2017-11-29 09:47:19 -08:00
Terence Parr 8b86af6654
Merge pull request #2102 from ewanmellor/swift-antlrfilestream-report-errors
Report errors in ANTLRFileStream.
2017-11-29 09:47:04 -08:00
Terence Parr a7af99b17f
Merge pull request #2101 from ewanmellor/swift-fix-uuid-extension
Implement UUID.init(mostSigBits, leastSigBits) in the Swift runtime.
2017-11-29 09:46:29 -08:00
Ewan Mellor eb9124fff8
[Swift] Fix parse-cancellation in BailErrorStrategy.
BailErrorStrategy is supposed to throw an error that's different from
the ordinary recognition error, specifically so that it can be handled
differently by client code.  This was not ported over from Java correctly.

Fix this by moving parseCancellation from ANTLRError to ANTLRException,
adding its RecognitionException argument, and throwing it from the
two handlers in BailErrorStrategy.

Also remove ANTLRException.cannotInvokeStartRule, which is unused.
(The Java runtime uses it when ParseTreePatternMatcher throws a generic
exception, but we don't have that.)
2017-11-11 10:45:38 -08:00
Ewan Mellor 7cf8ef7bc5
[Swift] Remove ArrayList.
This was only used in some commented-out debugging code.  Swift has
perfectly good array types, we don't need to implement our own.
2017-11-10 18:46:06 -08:00