forked from jasder/antlr
Next overhaul
- Added first real unit test set and enable code coverage collection in XCode (for ANTLRInputStream). - Reworked ANTLRFileStream::load, which is now more flexible (supports Unicode BOM + 3 possible encodings), can load from Unicode file names and has almost no platform code. - Enabled strict data size and sign checks in XCode (clang) and fixed a million places... - Started converting int to size_t where it makes more sense. - Started working on const correctness. - Fixed a ton of memory leaks. - The ATN and ATNConfigSet classes now entirely work as value types. Same for Interval(Set). These seem to be the most critical data structures (ATNConfig + ATNState are pending). - The abstract IntSet class is gone now. - Murmur hash code now works with size_t instead of int (need to add unit tests for that). - Fixed a number of TODOs and other smaller things. - The Cpp template now properly handles grammar rule return values.
This commit is contained in:
parent
bc81acba06
commit
3f78367457
|
@ -0,0 +1,165 @@
|
||||||
|
/*
|
||||||
|
* [The "BSD license"]
|
||||||
|
* Copyright (c) 2016 Mike Lischke
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions
|
||||||
|
* are met:
|
||||||
|
*
|
||||||
|
* 1. Redistributions of source code must retain the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer.
|
||||||
|
* 2. Redistributions in binary form must reproduce the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer in the
|
||||||
|
* documentation and/or other materials provided with the distribution.
|
||||||
|
* 3. The name of the author may not be used to endorse or promote products
|
||||||
|
* derived from this software without specific prior written permission.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
||||||
|
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||||
|
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
||||||
|
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||||
|
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||||
|
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||||
|
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||||
|
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||||
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
||||||
|
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#import <XCTest/XCTest.h>
|
||||||
|
|
||||||
|
#include "ANTLRInputStream.h"
|
||||||
|
#include "Exceptions.h"
|
||||||
|
#include "Interval.h"
|
||||||
|
|
||||||
|
using namespace org::antlr::v4::runtime;
|
||||||
|
|
||||||
|
@interface InputHandlingTests : XCTestCase
|
||||||
|
|
||||||
|
@end
|
||||||
|
|
||||||
|
@implementation InputHandlingTests
|
||||||
|
|
||||||
|
- (void)setUp {
|
||||||
|
[super setUp];
|
||||||
|
// Put setup code here. This method is called before the invocation of each test method in the class.
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void)tearDown {
|
||||||
|
// Put teardown code here. This method is called after the invocation of each test method in the class.
|
||||||
|
[super tearDown];
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void)testANTLRInputStreamCreation {
|
||||||
|
ANTLRInputStream stream1;
|
||||||
|
XCTAssert(stream1.toString().empty());
|
||||||
|
XCTAssertEqual(stream1.index(), (size_t)0);
|
||||||
|
|
||||||
|
ANTLRInputStream stream2(L"To be or not to be");
|
||||||
|
XCTAssert(stream2.toString() == L"To be or not to be");
|
||||||
|
XCTAssertEqual(stream2.index(), (size_t)0);
|
||||||
|
XCTAssertEqual(stream2.size(), (size_t)18);
|
||||||
|
|
||||||
|
wchar_t data[] = L"Lorem ipsum dolor sit amet";
|
||||||
|
ANTLRInputStream stream3(data, sizeof(data) / sizeof(data[0]));
|
||||||
|
XCTAssert(stream3.toString() == std::wstring(L"Lorem ipsum dolor sit amet\0", 27));
|
||||||
|
XCTAssertEqual(stream3.index(), (size_t)0);
|
||||||
|
XCTAssertEqual(stream3.size(), (size_t)27);
|
||||||
|
|
||||||
|
std::wstringstream input(data, sizeof(data) / sizeof(data[0]));
|
||||||
|
ANTLRInputStream stream4(input);
|
||||||
|
XCTAssertEqual(stream4.index(), (size_t)0);
|
||||||
|
XCTAssertEqual(stream4.size(), (size_t)26);
|
||||||
|
|
||||||
|
std::wstring longString(33333, L'a');
|
||||||
|
input.str(longString);
|
||||||
|
stream4.load(input, 0);
|
||||||
|
XCTAssertEqual(stream4.index(), (size_t)0);
|
||||||
|
XCTAssertEqual(stream4.size(), (size_t)26); // Nothing changed as the stream is still at eof.
|
||||||
|
|
||||||
|
input.clear();
|
||||||
|
stream4.load(input, 0);
|
||||||
|
XCTAssertEqual(stream4.size(), (size_t)33333);
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void)testANTLRInputStreamUse {
|
||||||
|
std::wstring text(L"🚧Lorem ipsum dolor sit amet🕶");
|
||||||
|
ANTLRInputStream stream(text);
|
||||||
|
XCTAssertEqual(stream.index(), (size_t)0);
|
||||||
|
XCTAssertEqual(stream.size(), text.size());
|
||||||
|
|
||||||
|
for (size_t i = 0; i < stream.size(); ++i) {
|
||||||
|
stream.consume();
|
||||||
|
XCTAssertEqual(stream.index(), i + 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
stream.consume();
|
||||||
|
XCTFail();
|
||||||
|
} catch (const IllegalStateException &e) {
|
||||||
|
// Expected.
|
||||||
|
XCTAssertEqual(e.getMessage(), L"cannot consume EOF");
|
||||||
|
}
|
||||||
|
|
||||||
|
XCTAssertEqual(stream.index(), text.size());
|
||||||
|
stream.reset();
|
||||||
|
XCTAssertEqual(stream.index(), (size_t)0);
|
||||||
|
|
||||||
|
XCTAssertEqual(stream.LA(0), (size_t)0);
|
||||||
|
for (size_t i = 1; i < text.size(); ++i) {
|
||||||
|
XCTAssertEqual(stream.LA((int)i), (size_t)text[i - 1]); // LA(1) means: current char.
|
||||||
|
XCTAssertEqual(stream.LT((int)i), (size_t)text[i - 1]); // LT is mapped to LA.
|
||||||
|
XCTAssertEqual(stream.index(), (size_t)0); // No consumption when looking ahead.
|
||||||
|
}
|
||||||
|
|
||||||
|
stream.seek(text.size() - 1);
|
||||||
|
XCTAssertEqual(stream.index(), text.size() - 1);
|
||||||
|
|
||||||
|
stream.seek(text.size() / 2);
|
||||||
|
XCTAssertEqual(stream.index(), text.size() / 2);
|
||||||
|
|
||||||
|
stream.seek(text.size() - 1);
|
||||||
|
for (size_t i = 1; i < text.size() - 1; ++i) {
|
||||||
|
XCTAssertEqual(stream.LA((ssize_t)-i), (size_t)text[text.size() - i - 1]); // LA(-1) means: previous char.
|
||||||
|
XCTAssertEqual(stream.LT((ssize_t)-i), (size_t)text[text.size() - i - 1]); // LT is mapped to LA.
|
||||||
|
XCTAssertEqual(stream.index(), text.size() - 1); // No consumption when looking ahead.
|
||||||
|
}
|
||||||
|
|
||||||
|
XCTAssertEqual((int)stream.LA(-10000), IntStream::_EOF);
|
||||||
|
|
||||||
|
// Mark and release do nothing.
|
||||||
|
stream.reset();
|
||||||
|
XCTAssertEqual(stream.index(), (size_t)0);
|
||||||
|
ssize_t marker = stream.mark();
|
||||||
|
XCTAssertEqual(marker, -1);
|
||||||
|
stream.seek(10);
|
||||||
|
XCTAssertEqual(stream.index(), (size_t)10);
|
||||||
|
XCTAssertEqual(stream.mark(), -1);
|
||||||
|
|
||||||
|
stream.release(marker);
|
||||||
|
XCTAssertEqual(stream.index(), (size_t)10);
|
||||||
|
|
||||||
|
misc::Interval interval1(2, 10); // From - to, inclusive.
|
||||||
|
std::wstring output = stream.getText(interval1);
|
||||||
|
XCTAssertEqual(output, text.substr(2, 9));
|
||||||
|
|
||||||
|
misc::Interval interval2(200, 10); // Start beyond bounds.
|
||||||
|
output = stream.getText(interval2);
|
||||||
|
XCTAssert(output.empty());
|
||||||
|
|
||||||
|
misc::Interval interval3(0, 200); // End beyond bounds.
|
||||||
|
output = stream.getText(interval3);
|
||||||
|
XCTAssertEqual(output, text);
|
||||||
|
|
||||||
|
stream.name = "unit tests"; // Quite useless test, as "name" is a public field.
|
||||||
|
XCTAssertEqual(stream.getSourceName(), "unit tests");
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void)testPerformanceExample {
|
||||||
|
[self measureBlock: ^{
|
||||||
|
// Put the code you want to measure the time of here.
|
||||||
|
}];
|
||||||
|
}
|
||||||
|
|
||||||
|
@end
|
|
@ -29,11 +29,15 @@
|
||||||
|
|
||||||
#import <Cocoa/Cocoa.h>
|
#import <Cocoa/Cocoa.h>
|
||||||
#import <XCTest/XCTest.h>
|
#import <XCTest/XCTest.h>
|
||||||
|
|
||||||
#include "ParserATNSimulator.h"
|
#include "ParserATNSimulator.h"
|
||||||
#include "DFA.h"
|
#include "DFA.h"
|
||||||
|
#include "ATN.h"
|
||||||
|
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
|
using namespace org::antlr::v4::runtime;
|
||||||
|
|
||||||
@interface antlrcpp_Tests : XCTestCase
|
@interface antlrcpp_Tests : XCTestCase
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
@ -52,9 +56,10 @@
|
||||||
|
|
||||||
- (void)testExample {
|
- (void)testExample {
|
||||||
try {
|
try {
|
||||||
std::vector<org::antlr::v4::runtime::dfa::DFA> decisionToDFA;
|
std::vector<dfa::DFA *> decisionToDFA;
|
||||||
|
atn::ATN atn;
|
||||||
|
|
||||||
org::antlr::v4::runtime::atn::ParserATNSimulator foo(nullptr, decisionToDFA, nullptr);
|
org::antlr::v4::runtime::atn::ParserATNSimulator foo(nullptr, atn, decisionToDFA, nullptr);
|
||||||
}
|
}
|
||||||
catch (std::exception e) {
|
catch (std::exception e) {
|
||||||
|
|
||||||
|
@ -63,11 +68,4 @@
|
||||||
XCTAssert(YES, @"Pass");
|
XCTAssert(YES, @"Pass");
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)testPerformanceExample {
|
|
||||||
// This is an example of a performance test case.
|
|
||||||
[self measureBlock:^{
|
|
||||||
// Put the code you want to measure the time of here.
|
|
||||||
}];
|
|
||||||
}
|
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
|
@ -11,6 +11,7 @@
|
||||||
2747A70B1CA691310030247B /* ConfigLookup.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 2747A7081CA691310030247B /* ConfigLookup.cpp */; };
|
2747A70B1CA691310030247B /* ConfigLookup.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 2747A7081CA691310030247B /* ConfigLookup.cpp */; };
|
||||||
2747A70C1CA691310030247B /* ConfigLookup.h in Headers */ = {isa = PBXBuildFile; fileRef = 2747A7091CA691310030247B /* ConfigLookup.h */; };
|
2747A70C1CA691310030247B /* ConfigLookup.h in Headers */ = {isa = PBXBuildFile; fileRef = 2747A7091CA691310030247B /* ConfigLookup.h */; };
|
||||||
2747A70D1CA691310030247B /* ConfigLookup.h in Headers */ = {isa = PBXBuildFile; fileRef = 2747A7091CA691310030247B /* ConfigLookup.h */; };
|
2747A70D1CA691310030247B /* ConfigLookup.h in Headers */ = {isa = PBXBuildFile; fileRef = 2747A7091CA691310030247B /* ConfigLookup.h */; };
|
||||||
|
2747A7131CA6C46C0030247B /* InputHandlingTests.mm in Sources */ = {isa = PBXBuildFile; fileRef = 2747A7121CA6C46C0030247B /* InputHandlingTests.mm */; };
|
||||||
276927241C9ED49100E4EBF8 /* antlrcpp-Prefix.h in Headers */ = {isa = PBXBuildFile; fileRef = 276927231C9ED49100E4EBF8 /* antlrcpp-Prefix.h */; };
|
276927241C9ED49100E4EBF8 /* antlrcpp-Prefix.h in Headers */ = {isa = PBXBuildFile; fileRef = 276927231C9ED49100E4EBF8 /* antlrcpp-Prefix.h */; };
|
||||||
276927251C9ED49100E4EBF8 /* antlrcpp-Prefix.h in Headers */ = {isa = PBXBuildFile; fileRef = 276927231C9ED49100E4EBF8 /* antlrcpp-Prefix.h */; };
|
276927251C9ED49100E4EBF8 /* antlrcpp-Prefix.h in Headers */ = {isa = PBXBuildFile; fileRef = 276927231C9ED49100E4EBF8 /* antlrcpp-Prefix.h */; };
|
||||||
278A66FB1C95838E002D667E /* ANTLRErrorListener.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 278A66FA1C95838E002D667E /* ANTLRErrorListener.cpp */; };
|
278A66FB1C95838E002D667E /* ANTLRErrorListener.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 278A66FA1C95838E002D667E /* ANTLRErrorListener.cpp */; };
|
||||||
|
@ -385,10 +386,6 @@
|
||||||
27C668B71C9584FA0021E494 /* IntervalSet.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 27C6688A1C9584FA0021E494 /* IntervalSet.cpp */; };
|
27C668B71C9584FA0021E494 /* IntervalSet.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 27C6688A1C9584FA0021E494 /* IntervalSet.cpp */; };
|
||||||
27C668B81C9584FA0021E494 /* IntervalSet.h in Headers */ = {isa = PBXBuildFile; fileRef = 27C6688B1C9584FA0021E494 /* IntervalSet.h */; };
|
27C668B81C9584FA0021E494 /* IntervalSet.h in Headers */ = {isa = PBXBuildFile; fileRef = 27C6688B1C9584FA0021E494 /* IntervalSet.h */; };
|
||||||
27C668B91C9584FA0021E494 /* IntervalSet.h in Headers */ = {isa = PBXBuildFile; fileRef = 27C6688B1C9584FA0021E494 /* IntervalSet.h */; };
|
27C668B91C9584FA0021E494 /* IntervalSet.h in Headers */ = {isa = PBXBuildFile; fileRef = 27C6688B1C9584FA0021E494 /* IntervalSet.h */; };
|
||||||
27C668BA1C9584FA0021E494 /* IntSet.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 27C6688C1C9584FA0021E494 /* IntSet.cpp */; };
|
|
||||||
27C668BB1C9584FA0021E494 /* IntSet.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 27C6688C1C9584FA0021E494 /* IntSet.cpp */; };
|
|
||||||
27C668BC1C9584FA0021E494 /* IntSet.h in Headers */ = {isa = PBXBuildFile; fileRef = 27C6688D1C9584FA0021E494 /* IntSet.h */; };
|
|
||||||
27C668BD1C9584FA0021E494 /* IntSet.h in Headers */ = {isa = PBXBuildFile; fileRef = 27C6688D1C9584FA0021E494 /* IntSet.h */; };
|
|
||||||
27C668C21C9584FA0021E494 /* LogManager.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 27C668901C9584FA0021E494 /* LogManager.cpp */; };
|
27C668C21C9584FA0021E494 /* LogManager.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 27C668901C9584FA0021E494 /* LogManager.cpp */; };
|
||||||
27C668C31C9584FA0021E494 /* LogManager.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 27C668901C9584FA0021E494 /* LogManager.cpp */; };
|
27C668C31C9584FA0021E494 /* LogManager.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 27C668901C9584FA0021E494 /* LogManager.cpp */; };
|
||||||
27C668C41C9584FA0021E494 /* LogManager.h in Headers */ = {isa = PBXBuildFile; fileRef = 27C668911C9584FA0021E494 /* LogManager.h */; };
|
27C668C41C9584FA0021E494 /* LogManager.h in Headers */ = {isa = PBXBuildFile; fileRef = 27C668911C9584FA0021E494 /* LogManager.h */; };
|
||||||
|
@ -611,19 +608,20 @@
|
||||||
/* Begin PBXFileReference section */
|
/* Begin PBXFileReference section */
|
||||||
2747A7081CA691310030247B /* ConfigLookup.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ConfigLookup.cpp; sourceTree = "<group>"; };
|
2747A7081CA691310030247B /* ConfigLookup.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ConfigLookup.cpp; sourceTree = "<group>"; };
|
||||||
2747A7091CA691310030247B /* ConfigLookup.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ConfigLookup.h; sourceTree = "<group>"; };
|
2747A7091CA691310030247B /* ConfigLookup.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ConfigLookup.h; sourceTree = "<group>"; };
|
||||||
|
2747A7121CA6C46C0030247B /* InputHandlingTests.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = InputHandlingTests.mm; sourceTree = "<group>"; wrapsLines = 0; };
|
||||||
276927231C9ED49100E4EBF8 /* antlrcpp-Prefix.h */ = {isa = PBXFileReference; explicitFileType = sourcecode.cpp.h; fileEncoding = 4; name = "antlrcpp-Prefix.h"; path = "../../runtime/antlrcpp-Prefix.h"; sourceTree = "<group>"; };
|
276927231C9ED49100E4EBF8 /* antlrcpp-Prefix.h */ = {isa = PBXFileReference; explicitFileType = sourcecode.cpp.h; fileEncoding = 4; name = "antlrcpp-Prefix.h"; path = "../../runtime/antlrcpp-Prefix.h"; sourceTree = "<group>"; };
|
||||||
278A66FA1C95838E002D667E /* ANTLRErrorListener.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = ANTLRErrorListener.cpp; path = ../../runtime/ANTLRErrorListener.cpp; sourceTree = SOURCE_ROOT; };
|
278A66FA1C95838E002D667E /* ANTLRErrorListener.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = ANTLRErrorListener.cpp; path = ../../runtime/ANTLRErrorListener.cpp; sourceTree = SOURCE_ROOT; };
|
||||||
27C6665D1C9584050021E494 /* ANTLRErrorListener.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = ANTLRErrorListener.h; path = ../../runtime/ANTLRErrorListener.h; sourceTree = SOURCE_ROOT; };
|
27C6665D1C9584050021E494 /* ANTLRErrorListener.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = ANTLRErrorListener.h; path = ../../runtime/ANTLRErrorListener.h; sourceTree = SOURCE_ROOT; wrapsLines = 0; };
|
||||||
27C6665E1C9584050021E494 /* ANTLRErrorStrategy.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = ANTLRErrorStrategy.cpp; path = ../../runtime/ANTLRErrorStrategy.cpp; sourceTree = SOURCE_ROOT; };
|
27C6665E1C9584050021E494 /* ANTLRErrorStrategy.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = ANTLRErrorStrategy.cpp; path = ../../runtime/ANTLRErrorStrategy.cpp; sourceTree = SOURCE_ROOT; };
|
||||||
27C6665F1C9584050021E494 /* ANTLRErrorStrategy.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = ANTLRErrorStrategy.h; path = ../../runtime/ANTLRErrorStrategy.h; sourceTree = SOURCE_ROOT; };
|
27C6665F1C9584050021E494 /* ANTLRErrorStrategy.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = ANTLRErrorStrategy.h; path = ../../runtime/ANTLRErrorStrategy.h; sourceTree = SOURCE_ROOT; };
|
||||||
27C666601C9584050021E494 /* ANTLRFileStream.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = ANTLRFileStream.cpp; path = ../../runtime/ANTLRFileStream.cpp; sourceTree = SOURCE_ROOT; };
|
27C666601C9584050021E494 /* ANTLRFileStream.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = ANTLRFileStream.cpp; path = ../../runtime/ANTLRFileStream.cpp; sourceTree = SOURCE_ROOT; };
|
||||||
27C666611C9584050021E494 /* ANTLRFileStream.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = ANTLRFileStream.h; path = ../../runtime/ANTLRFileStream.h; sourceTree = SOURCE_ROOT; };
|
27C666611C9584050021E494 /* ANTLRFileStream.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = ANTLRFileStream.h; path = ../../runtime/ANTLRFileStream.h; sourceTree = SOURCE_ROOT; };
|
||||||
27C666621C9584050021E494 /* ANTLRInputStream.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = ANTLRInputStream.cpp; path = ../../runtime/ANTLRInputStream.cpp; sourceTree = SOURCE_ROOT; };
|
27C666621C9584050021E494 /* ANTLRInputStream.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = ANTLRInputStream.cpp; path = ../../runtime/ANTLRInputStream.cpp; sourceTree = SOURCE_ROOT; wrapsLines = 0; };
|
||||||
27C666631C9584050021E494 /* ANTLRInputStream.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = ANTLRInputStream.h; path = ../../runtime/ANTLRInputStream.h; sourceTree = SOURCE_ROOT; };
|
27C666631C9584050021E494 /* ANTLRInputStream.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = ANTLRInputStream.h; path = ../../runtime/ANTLRInputStream.h; sourceTree = SOURCE_ROOT; wrapsLines = 0; };
|
||||||
27C666641C9584050021E494 /* BailErrorStrategy.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = BailErrorStrategy.cpp; path = ../../runtime/BailErrorStrategy.cpp; sourceTree = SOURCE_ROOT; };
|
27C666641C9584050021E494 /* BailErrorStrategy.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = BailErrorStrategy.cpp; path = ../../runtime/BailErrorStrategy.cpp; sourceTree = SOURCE_ROOT; };
|
||||||
27C666651C9584050021E494 /* BailErrorStrategy.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = BailErrorStrategy.h; path = ../../runtime/BailErrorStrategy.h; sourceTree = SOURCE_ROOT; };
|
27C666651C9584050021E494 /* BailErrorStrategy.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = BailErrorStrategy.h; path = ../../runtime/BailErrorStrategy.h; sourceTree = SOURCE_ROOT; };
|
||||||
27C666661C9584050021E494 /* BaseErrorListener.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = BaseErrorListener.cpp; path = ../../runtime/BaseErrorListener.cpp; sourceTree = SOURCE_ROOT; };
|
27C666661C9584050021E494 /* BaseErrorListener.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = BaseErrorListener.cpp; path = ../../runtime/BaseErrorListener.cpp; sourceTree = SOURCE_ROOT; wrapsLines = 0; };
|
||||||
27C666671C9584050021E494 /* BaseErrorListener.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = BaseErrorListener.h; path = ../../runtime/BaseErrorListener.h; sourceTree = SOURCE_ROOT; };
|
27C666671C9584050021E494 /* BaseErrorListener.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = BaseErrorListener.h; path = ../../runtime/BaseErrorListener.h; sourceTree = SOURCE_ROOT; wrapsLines = 0; };
|
||||||
27C666681C9584050021E494 /* BufferedTokenStream.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = BufferedTokenStream.cpp; path = ../../runtime/BufferedTokenStream.cpp; sourceTree = SOURCE_ROOT; };
|
27C666681C9584050021E494 /* BufferedTokenStream.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = BufferedTokenStream.cpp; path = ../../runtime/BufferedTokenStream.cpp; sourceTree = SOURCE_ROOT; };
|
||||||
27C666691C9584050021E494 /* BufferedTokenStream.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = BufferedTokenStream.h; path = ../../runtime/BufferedTokenStream.h; sourceTree = SOURCE_ROOT; };
|
27C666691C9584050021E494 /* BufferedTokenStream.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = BufferedTokenStream.h; path = ../../runtime/BufferedTokenStream.h; sourceTree = SOURCE_ROOT; };
|
||||||
27C6666A1C9584050021E494 /* CharStream.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = CharStream.cpp; path = ../../runtime/CharStream.cpp; sourceTree = SOURCE_ROOT; };
|
27C6666A1C9584050021E494 /* CharStream.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = CharStream.cpp; path = ../../runtime/CharStream.cpp; sourceTree = SOURCE_ROOT; };
|
||||||
|
@ -636,10 +634,10 @@
|
||||||
27C666711C9584050021E494 /* CommonTokenStream.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = CommonTokenStream.h; path = ../../runtime/CommonTokenStream.h; sourceTree = SOURCE_ROOT; };
|
27C666711C9584050021E494 /* CommonTokenStream.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = CommonTokenStream.h; path = ../../runtime/CommonTokenStream.h; sourceTree = SOURCE_ROOT; };
|
||||||
27C666721C9584050021E494 /* ConsoleErrorListener.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = ConsoleErrorListener.cpp; path = ../../runtime/ConsoleErrorListener.cpp; sourceTree = SOURCE_ROOT; };
|
27C666721C9584050021E494 /* ConsoleErrorListener.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = ConsoleErrorListener.cpp; path = ../../runtime/ConsoleErrorListener.cpp; sourceTree = SOURCE_ROOT; };
|
||||||
27C666731C9584050021E494 /* ConsoleErrorListener.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = ConsoleErrorListener.h; path = ../../runtime/ConsoleErrorListener.h; sourceTree = SOURCE_ROOT; };
|
27C666731C9584050021E494 /* ConsoleErrorListener.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = ConsoleErrorListener.h; path = ../../runtime/ConsoleErrorListener.h; sourceTree = SOURCE_ROOT; };
|
||||||
27C666741C9584050021E494 /* DefaultErrorStrategy.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = DefaultErrorStrategy.cpp; path = ../../runtime/DefaultErrorStrategy.cpp; sourceTree = SOURCE_ROOT; };
|
27C666741C9584050021E494 /* DefaultErrorStrategy.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = DefaultErrorStrategy.cpp; path = ../../runtime/DefaultErrorStrategy.cpp; sourceTree = SOURCE_ROOT; wrapsLines = 0; };
|
||||||
27C666751C9584050021E494 /* DefaultErrorStrategy.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = DefaultErrorStrategy.h; path = ../../runtime/DefaultErrorStrategy.h; sourceTree = SOURCE_ROOT; };
|
27C666751C9584050021E494 /* DefaultErrorStrategy.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = DefaultErrorStrategy.h; path = ../../runtime/DefaultErrorStrategy.h; sourceTree = SOURCE_ROOT; };
|
||||||
27C666761C9584050021E494 /* DiagnosticErrorListener.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = DiagnosticErrorListener.cpp; path = ../../runtime/DiagnosticErrorListener.cpp; sourceTree = SOURCE_ROOT; };
|
27C666761C9584050021E494 /* DiagnosticErrorListener.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = DiagnosticErrorListener.cpp; path = ../../runtime/DiagnosticErrorListener.cpp; sourceTree = SOURCE_ROOT; wrapsLines = 0; };
|
||||||
27C666771C9584050021E494 /* DiagnosticErrorListener.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = DiagnosticErrorListener.h; path = ../../runtime/DiagnosticErrorListener.h; sourceTree = SOURCE_ROOT; };
|
27C666771C9584050021E494 /* DiagnosticErrorListener.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = DiagnosticErrorListener.h; path = ../../runtime/DiagnosticErrorListener.h; sourceTree = SOURCE_ROOT; wrapsLines = 0; };
|
||||||
27C666781C9584050021E494 /* Exceptions.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = Exceptions.cpp; path = ../../runtime/Exceptions.cpp; sourceTree = SOURCE_ROOT; };
|
27C666781C9584050021E494 /* Exceptions.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = Exceptions.cpp; path = ../../runtime/Exceptions.cpp; sourceTree = SOURCE_ROOT; };
|
||||||
27C666791C9584050021E494 /* Exceptions.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = Exceptions.h; path = ../../runtime/Exceptions.h; sourceTree = SOURCE_ROOT; };
|
27C666791C9584050021E494 /* Exceptions.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = Exceptions.h; path = ../../runtime/Exceptions.h; sourceTree = SOURCE_ROOT; };
|
||||||
27C6667A1C9584050021E494 /* FailedPredicateException.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = FailedPredicateException.cpp; path = ../../runtime/FailedPredicateException.cpp; sourceTree = SOURCE_ROOT; };
|
27C6667A1C9584050021E494 /* FailedPredicateException.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = FailedPredicateException.cpp; path = ../../runtime/FailedPredicateException.cpp; sourceTree = SOURCE_ROOT; };
|
||||||
|
@ -651,13 +649,13 @@
|
||||||
27C666811C9584050021E494 /* IntStream.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = IntStream.cpp; path = ../../runtime/IntStream.cpp; sourceTree = SOURCE_ROOT; };
|
27C666811C9584050021E494 /* IntStream.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = IntStream.cpp; path = ../../runtime/IntStream.cpp; sourceTree = SOURCE_ROOT; };
|
||||||
27C666821C9584050021E494 /* IntStream.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = IntStream.h; path = ../../runtime/IntStream.h; sourceTree = SOURCE_ROOT; };
|
27C666821C9584050021E494 /* IntStream.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = IntStream.h; path = ../../runtime/IntStream.h; sourceTree = SOURCE_ROOT; };
|
||||||
27C666831C9584050021E494 /* IRecognizer.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = IRecognizer.h; path = ../../runtime/IRecognizer.h; sourceTree = SOURCE_ROOT; };
|
27C666831C9584050021E494 /* IRecognizer.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = IRecognizer.h; path = ../../runtime/IRecognizer.h; sourceTree = SOURCE_ROOT; };
|
||||||
27C666841C9584050021E494 /* Lexer.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = Lexer.cpp; path = ../../runtime/Lexer.cpp; sourceTree = SOURCE_ROOT; };
|
27C666841C9584050021E494 /* Lexer.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = Lexer.cpp; path = ../../runtime/Lexer.cpp; sourceTree = SOURCE_ROOT; wrapsLines = 0; };
|
||||||
27C666851C9584050021E494 /* Lexer.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = Lexer.h; path = ../../runtime/Lexer.h; sourceTree = SOURCE_ROOT; };
|
27C666851C9584050021E494 /* Lexer.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = Lexer.h; path = ../../runtime/Lexer.h; sourceTree = SOURCE_ROOT; };
|
||||||
27C666861C9584050021E494 /* LexerInterpreter.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = LexerInterpreter.cpp; path = ../../runtime/LexerInterpreter.cpp; sourceTree = SOURCE_ROOT; };
|
27C666861C9584050021E494 /* LexerInterpreter.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = LexerInterpreter.cpp; path = ../../runtime/LexerInterpreter.cpp; sourceTree = SOURCE_ROOT; };
|
||||||
27C666871C9584050021E494 /* LexerInterpreter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = LexerInterpreter.h; path = ../../runtime/LexerInterpreter.h; sourceTree = SOURCE_ROOT; };
|
27C666871C9584050021E494 /* LexerInterpreter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = LexerInterpreter.h; path = ../../runtime/LexerInterpreter.h; sourceTree = SOURCE_ROOT; };
|
||||||
27C666881C9584050021E494 /* LexerNoViableAltException.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = LexerNoViableAltException.cpp; path = ../../runtime/LexerNoViableAltException.cpp; sourceTree = SOURCE_ROOT; };
|
27C666881C9584050021E494 /* LexerNoViableAltException.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = LexerNoViableAltException.cpp; path = ../../runtime/LexerNoViableAltException.cpp; sourceTree = SOURCE_ROOT; };
|
||||||
27C666891C9584050021E494 /* LexerNoViableAltException.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = LexerNoViableAltException.h; path = ../../runtime/LexerNoViableAltException.h; sourceTree = SOURCE_ROOT; };
|
27C666891C9584050021E494 /* LexerNoViableAltException.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = LexerNoViableAltException.h; path = ../../runtime/LexerNoViableAltException.h; sourceTree = SOURCE_ROOT; };
|
||||||
27C6668A1C9584050021E494 /* ListTokenSource.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = ListTokenSource.cpp; path = ../../runtime/ListTokenSource.cpp; sourceTree = SOURCE_ROOT; };
|
27C6668A1C9584050021E494 /* ListTokenSource.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = ListTokenSource.cpp; path = ../../runtime/ListTokenSource.cpp; sourceTree = SOURCE_ROOT; wrapsLines = 0; };
|
||||||
27C6668B1C9584050021E494 /* ListTokenSource.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = ListTokenSource.h; path = ../../runtime/ListTokenSource.h; sourceTree = SOURCE_ROOT; };
|
27C6668B1C9584050021E494 /* ListTokenSource.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = ListTokenSource.h; path = ../../runtime/ListTokenSource.h; sourceTree = SOURCE_ROOT; };
|
||||||
27C6668C1C9584050021E494 /* NoViableAltException.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = NoViableAltException.cpp; path = ../../runtime/NoViableAltException.cpp; sourceTree = SOURCE_ROOT; wrapsLines = 0; };
|
27C6668C1C9584050021E494 /* NoViableAltException.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = NoViableAltException.cpp; path = ../../runtime/NoViableAltException.cpp; sourceTree = SOURCE_ROOT; wrapsLines = 0; };
|
||||||
27C6668D1C9584050021E494 /* NoViableAltException.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = NoViableAltException.h; path = ../../runtime/NoViableAltException.h; sourceTree = SOURCE_ROOT; wrapsLines = 0; };
|
27C6668D1C9584050021E494 /* NoViableAltException.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = NoViableAltException.h; path = ../../runtime/NoViableAltException.h; sourceTree = SOURCE_ROOT; wrapsLines = 0; };
|
||||||
|
@ -667,13 +665,13 @@
|
||||||
27C666911C9584050021E494 /* ParserInterpreter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = ParserInterpreter.h; path = ../../runtime/ParserInterpreter.h; sourceTree = SOURCE_ROOT; wrapsLines = 0; };
|
27C666911C9584050021E494 /* ParserInterpreter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = ParserInterpreter.h; path = ../../runtime/ParserInterpreter.h; sourceTree = SOURCE_ROOT; wrapsLines = 0; };
|
||||||
27C666921C9584050021E494 /* ParserRuleContext.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = ParserRuleContext.cpp; path = ../../runtime/ParserRuleContext.cpp; sourceTree = SOURCE_ROOT; };
|
27C666921C9584050021E494 /* ParserRuleContext.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = ParserRuleContext.cpp; path = ../../runtime/ParserRuleContext.cpp; sourceTree = SOURCE_ROOT; };
|
||||||
27C666931C9584050021E494 /* ParserRuleContext.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = ParserRuleContext.h; path = ../../runtime/ParserRuleContext.h; sourceTree = SOURCE_ROOT; };
|
27C666931C9584050021E494 /* ParserRuleContext.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = ParserRuleContext.h; path = ../../runtime/ParserRuleContext.h; sourceTree = SOURCE_ROOT; };
|
||||||
27C666941C9584050021E494 /* ProxyErrorListener.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = ProxyErrorListener.cpp; path = ../../runtime/ProxyErrorListener.cpp; sourceTree = SOURCE_ROOT; };
|
27C666941C9584050021E494 /* ProxyErrorListener.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = ProxyErrorListener.cpp; path = ../../runtime/ProxyErrorListener.cpp; sourceTree = SOURCE_ROOT; wrapsLines = 0; };
|
||||||
27C666951C9584050021E494 /* ProxyErrorListener.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = ProxyErrorListener.h; path = ../../runtime/ProxyErrorListener.h; sourceTree = SOURCE_ROOT; };
|
27C666951C9584050021E494 /* ProxyErrorListener.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = ProxyErrorListener.h; path = ../../runtime/ProxyErrorListener.h; sourceTree = SOURCE_ROOT; wrapsLines = 0; };
|
||||||
27C666961C9584050021E494 /* RecognitionException.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = RecognitionException.cpp; path = ../../runtime/RecognitionException.cpp; sourceTree = SOURCE_ROOT; wrapsLines = 0; };
|
27C666961C9584050021E494 /* RecognitionException.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = RecognitionException.cpp; path = ../../runtime/RecognitionException.cpp; sourceTree = SOURCE_ROOT; wrapsLines = 0; };
|
||||||
27C666971C9584050021E494 /* RecognitionException.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = RecognitionException.h; path = ../../runtime/RecognitionException.h; sourceTree = SOURCE_ROOT; };
|
27C666971C9584050021E494 /* RecognitionException.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = RecognitionException.h; path = ../../runtime/RecognitionException.h; sourceTree = SOURCE_ROOT; };
|
||||||
27C666981C9584050021E494 /* Recognizer.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = Recognizer.h; path = ../../runtime/Recognizer.h; sourceTree = SOURCE_ROOT; };
|
27C666981C9584050021E494 /* Recognizer.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = Recognizer.h; path = ../../runtime/Recognizer.h; sourceTree = SOURCE_ROOT; };
|
||||||
27C666991C9584050021E494 /* Recognizer.inl */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; name = Recognizer.inl; path = ../../runtime/Recognizer.inl; sourceTree = SOURCE_ROOT; };
|
27C666991C9584050021E494 /* Recognizer.inl */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; name = Recognizer.inl; path = ../../runtime/Recognizer.inl; sourceTree = SOURCE_ROOT; };
|
||||||
27C6669A1C9584050021E494 /* RuleContext.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = RuleContext.cpp; path = ../../runtime/RuleContext.cpp; sourceTree = SOURCE_ROOT; };
|
27C6669A1C9584050021E494 /* RuleContext.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = RuleContext.cpp; path = ../../runtime/RuleContext.cpp; sourceTree = SOURCE_ROOT; wrapsLines = 0; };
|
||||||
27C6669B1C9584050021E494 /* RuleContext.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = RuleContext.h; path = ../../runtime/RuleContext.h; sourceTree = SOURCE_ROOT; };
|
27C6669B1C9584050021E494 /* RuleContext.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = RuleContext.h; path = ../../runtime/RuleContext.h; sourceTree = SOURCE_ROOT; };
|
||||||
27C6669C1C9584050021E494 /* Token.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = Token.cpp; path = ../../runtime/Token.cpp; sourceTree = SOURCE_ROOT; };
|
27C6669C1C9584050021E494 /* Token.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = Token.cpp; path = ../../runtime/Token.cpp; sourceTree = SOURCE_ROOT; };
|
||||||
27C6669D1C9584050021E494 /* Token.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = Token.h; path = ../../runtime/Token.h; sourceTree = SOURCE_ROOT; };
|
27C6669D1C9584050021E494 /* Token.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = Token.h; path = ../../runtime/Token.h; sourceTree = SOURCE_ROOT; };
|
||||||
|
@ -684,7 +682,7 @@
|
||||||
27C666A21C9584050021E494 /* TokenStream.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = TokenStream.cpp; path = ../../runtime/TokenStream.cpp; sourceTree = SOURCE_ROOT; };
|
27C666A21C9584050021E494 /* TokenStream.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = TokenStream.cpp; path = ../../runtime/TokenStream.cpp; sourceTree = SOURCE_ROOT; };
|
||||||
27C666A31C9584050021E494 /* TokenStream.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = TokenStream.h; path = ../../runtime/TokenStream.h; sourceTree = SOURCE_ROOT; };
|
27C666A31C9584050021E494 /* TokenStream.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = TokenStream.h; path = ../../runtime/TokenStream.h; sourceTree = SOURCE_ROOT; };
|
||||||
27C666A41C9584050021E494 /* TokenStreamRewriter.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = TokenStreamRewriter.cpp; path = ../../runtime/TokenStreamRewriter.cpp; sourceTree = SOURCE_ROOT; wrapsLines = 0; };
|
27C666A41C9584050021E494 /* TokenStreamRewriter.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = TokenStreamRewriter.cpp; path = ../../runtime/TokenStreamRewriter.cpp; sourceTree = SOURCE_ROOT; wrapsLines = 0; };
|
||||||
27C666A51C9584050021E494 /* TokenStreamRewriter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = TokenStreamRewriter.h; path = ../../runtime/TokenStreamRewriter.h; sourceTree = SOURCE_ROOT; };
|
27C666A51C9584050021E494 /* TokenStreamRewriter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = TokenStreamRewriter.h; path = ../../runtime/TokenStreamRewriter.h; sourceTree = SOURCE_ROOT; wrapsLines = 0; };
|
||||||
27C666A61C9584050021E494 /* UnbufferedCharStream.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = UnbufferedCharStream.cpp; path = ../../runtime/UnbufferedCharStream.cpp; sourceTree = SOURCE_ROOT; };
|
27C666A61C9584050021E494 /* UnbufferedCharStream.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = UnbufferedCharStream.cpp; path = ../../runtime/UnbufferedCharStream.cpp; sourceTree = SOURCE_ROOT; };
|
||||||
27C666A71C9584050021E494 /* UnbufferedCharStream.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = UnbufferedCharStream.h; path = ../../runtime/UnbufferedCharStream.h; sourceTree = SOURCE_ROOT; };
|
27C666A71C9584050021E494 /* UnbufferedCharStream.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = UnbufferedCharStream.h; path = ../../runtime/UnbufferedCharStream.h; sourceTree = SOURCE_ROOT; };
|
||||||
27C666A81C9584050021E494 /* UnbufferedTokenStream.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = UnbufferedTokenStream.h; path = ../../runtime/UnbufferedTokenStream.h; sourceTree = SOURCE_ROOT; };
|
27C666A81C9584050021E494 /* UnbufferedTokenStream.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = UnbufferedTokenStream.h; path = ../../runtime/UnbufferedTokenStream.h; sourceTree = SOURCE_ROOT; };
|
||||||
|
@ -710,7 +708,7 @@
|
||||||
27C667571C95846E0021E494 /* ATNSerializer.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ATNSerializer.cpp; sourceTree = "<group>"; };
|
27C667571C95846E0021E494 /* ATNSerializer.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ATNSerializer.cpp; sourceTree = "<group>"; };
|
||||||
27C667581C95846E0021E494 /* ATNSerializer.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ATNSerializer.h; sourceTree = "<group>"; };
|
27C667581C95846E0021E494 /* ATNSerializer.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ATNSerializer.h; sourceTree = "<group>"; };
|
||||||
27C667591C95846E0021E494 /* ATNSimulator.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ATNSimulator.cpp; sourceTree = "<group>"; wrapsLines = 0; };
|
27C667591C95846E0021E494 /* ATNSimulator.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ATNSimulator.cpp; sourceTree = "<group>"; wrapsLines = 0; };
|
||||||
27C6675A1C95846E0021E494 /* ATNSimulator.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ATNSimulator.h; sourceTree = "<group>"; };
|
27C6675A1C95846E0021E494 /* ATNSimulator.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ATNSimulator.h; sourceTree = "<group>"; wrapsLines = 0; };
|
||||||
27C6675B1C95846E0021E494 /* ATNState.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ATNState.cpp; sourceTree = "<group>"; };
|
27C6675B1C95846E0021E494 /* ATNState.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ATNState.cpp; sourceTree = "<group>"; };
|
||||||
27C6675C1C95846E0021E494 /* ATNState.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ATNState.h; sourceTree = "<group>"; };
|
27C6675C1C95846E0021E494 /* ATNState.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ATNState.h; sourceTree = "<group>"; };
|
||||||
27C6675D1C95846E0021E494 /* ATNType.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ATNType.cpp; sourceTree = "<group>"; };
|
27C6675D1C95846E0021E494 /* ATNType.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ATNType.cpp; sourceTree = "<group>"; };
|
||||||
|
@ -736,7 +734,7 @@
|
||||||
27C667711C95846E0021E494 /* LexerATNSimulator.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = LexerATNSimulator.cpp; sourceTree = "<group>"; wrapsLines = 0; };
|
27C667711C95846E0021E494 /* LexerATNSimulator.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = LexerATNSimulator.cpp; sourceTree = "<group>"; wrapsLines = 0; };
|
||||||
27C667721C95846E0021E494 /* LexerATNSimulator.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = LexerATNSimulator.h; sourceTree = "<group>"; wrapsLines = 0; };
|
27C667721C95846E0021E494 /* LexerATNSimulator.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = LexerATNSimulator.h; sourceTree = "<group>"; wrapsLines = 0; };
|
||||||
27C667731C95846E0021E494 /* LL1Analyzer.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = LL1Analyzer.cpp; sourceTree = "<group>"; wrapsLines = 0; };
|
27C667731C95846E0021E494 /* LL1Analyzer.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = LL1Analyzer.cpp; sourceTree = "<group>"; wrapsLines = 0; };
|
||||||
27C667741C95846E0021E494 /* LL1Analyzer.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = LL1Analyzer.h; sourceTree = "<group>"; };
|
27C667741C95846E0021E494 /* LL1Analyzer.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = LL1Analyzer.h; sourceTree = "<group>"; wrapsLines = 0; };
|
||||||
27C667751C95846E0021E494 /* LoopEndState.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = LoopEndState.cpp; sourceTree = "<group>"; };
|
27C667751C95846E0021E494 /* LoopEndState.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = LoopEndState.cpp; sourceTree = "<group>"; };
|
||||||
27C667761C95846E0021E494 /* LoopEndState.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = LoopEndState.h; sourceTree = "<group>"; };
|
27C667761C95846E0021E494 /* LoopEndState.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = LoopEndState.h; sourceTree = "<group>"; };
|
||||||
27C667781C95846E0021E494 /* NotSetTransition.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = NotSetTransition.cpp; sourceTree = "<group>"; };
|
27C667781C95846E0021E494 /* NotSetTransition.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = NotSetTransition.cpp; sourceTree = "<group>"; };
|
||||||
|
@ -744,7 +742,7 @@
|
||||||
27C6677A1C95846E0021E494 /* OrderedATNConfigSet.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = OrderedATNConfigSet.cpp; sourceTree = "<group>"; wrapsLines = 0; };
|
27C6677A1C95846E0021E494 /* OrderedATNConfigSet.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = OrderedATNConfigSet.cpp; sourceTree = "<group>"; wrapsLines = 0; };
|
||||||
27C6677B1C95846E0021E494 /* OrderedATNConfigSet.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = OrderedATNConfigSet.h; sourceTree = "<group>"; };
|
27C6677B1C95846E0021E494 /* OrderedATNConfigSet.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = OrderedATNConfigSet.h; sourceTree = "<group>"; };
|
||||||
27C6677C1C95846E0021E494 /* ParserATNSimulator.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ParserATNSimulator.cpp; sourceTree = "<group>"; wrapsLines = 0; };
|
27C6677C1C95846E0021E494 /* ParserATNSimulator.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ParserATNSimulator.cpp; sourceTree = "<group>"; wrapsLines = 0; };
|
||||||
27C6677D1C95846E0021E494 /* ParserATNSimulator.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ParserATNSimulator.h; sourceTree = "<group>"; };
|
27C6677D1C95846E0021E494 /* ParserATNSimulator.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ParserATNSimulator.h; sourceTree = "<group>"; wrapsLines = 0; };
|
||||||
27C6677E1C95846E0021E494 /* PlusBlockStartState.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = PlusBlockStartState.cpp; sourceTree = "<group>"; };
|
27C6677E1C95846E0021E494 /* PlusBlockStartState.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = PlusBlockStartState.cpp; sourceTree = "<group>"; };
|
||||||
27C6677F1C95846E0021E494 /* PlusBlockStartState.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PlusBlockStartState.h; sourceTree = "<group>"; };
|
27C6677F1C95846E0021E494 /* PlusBlockStartState.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PlusBlockStartState.h; sourceTree = "<group>"; };
|
||||||
27C667801C95846E0021E494 /* PlusLoopbackState.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = PlusLoopbackState.cpp; sourceTree = "<group>"; };
|
27C667801C95846E0021E494 /* PlusLoopbackState.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = PlusLoopbackState.cpp; sourceTree = "<group>"; };
|
||||||
|
@ -753,11 +751,11 @@
|
||||||
27C667831C95846E0021E494 /* PrecedencePredicateTransition.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PrecedencePredicateTransition.h; sourceTree = "<group>"; };
|
27C667831C95846E0021E494 /* PrecedencePredicateTransition.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PrecedencePredicateTransition.h; sourceTree = "<group>"; };
|
||||||
27C667841C95846E0021E494 /* PredicateTransition.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = PredicateTransition.cpp; sourceTree = "<group>"; };
|
27C667841C95846E0021E494 /* PredicateTransition.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = PredicateTransition.cpp; sourceTree = "<group>"; };
|
||||||
27C667851C95846E0021E494 /* PredicateTransition.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PredicateTransition.h; sourceTree = "<group>"; };
|
27C667851C95846E0021E494 /* PredicateTransition.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PredicateTransition.h; sourceTree = "<group>"; };
|
||||||
27C667861C95846E0021E494 /* PredictionContext.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = PredictionContext.cpp; sourceTree = "<group>"; };
|
27C667861C95846E0021E494 /* PredictionContext.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = PredictionContext.cpp; sourceTree = "<group>"; wrapsLines = 0; };
|
||||||
27C667871C95846E0021E494 /* PredictionContext.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PredictionContext.h; sourceTree = "<group>"; };
|
27C667871C95846E0021E494 /* PredictionContext.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PredictionContext.h; sourceTree = "<group>"; };
|
||||||
27C667881C95846E0021E494 /* PredictionContextCache.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = PredictionContextCache.cpp; sourceTree = "<group>"; };
|
27C667881C95846E0021E494 /* PredictionContextCache.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = PredictionContextCache.cpp; sourceTree = "<group>"; };
|
||||||
27C667891C95846E0021E494 /* PredictionContextCache.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PredictionContextCache.h; sourceTree = "<group>"; };
|
27C667891C95846E0021E494 /* PredictionContextCache.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PredictionContextCache.h; sourceTree = "<group>"; };
|
||||||
27C6678A1C95846E0021E494 /* PredictionMode.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = PredictionMode.cpp; sourceTree = "<group>"; };
|
27C6678A1C95846E0021E494 /* PredictionMode.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = PredictionMode.cpp; sourceTree = "<group>"; wrapsLines = 0; };
|
||||||
27C6678B1C95846E0021E494 /* PredictionMode.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PredictionMode.h; sourceTree = "<group>"; };
|
27C6678B1C95846E0021E494 /* PredictionMode.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PredictionMode.h; sourceTree = "<group>"; };
|
||||||
27C6678C1C95846E0021E494 /* RangeTransition.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = RangeTransition.cpp; sourceTree = "<group>"; wrapsLines = 0; };
|
27C6678C1C95846E0021E494 /* RangeTransition.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = RangeTransition.cpp; sourceTree = "<group>"; wrapsLines = 0; };
|
||||||
27C6678D1C95846E0021E494 /* RangeTransition.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RangeTransition.h; sourceTree = "<group>"; };
|
27C6678D1C95846E0021E494 /* RangeTransition.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RangeTransition.h; sourceTree = "<group>"; };
|
||||||
|
@ -800,8 +798,6 @@
|
||||||
27C668891C9584FA0021E494 /* Interval.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Interval.h; sourceTree = "<group>"; };
|
27C668891C9584FA0021E494 /* Interval.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Interval.h; sourceTree = "<group>"; };
|
||||||
27C6688A1C9584FA0021E494 /* IntervalSet.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = IntervalSet.cpp; sourceTree = "<group>"; wrapsLines = 0; };
|
27C6688A1C9584FA0021E494 /* IntervalSet.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = IntervalSet.cpp; sourceTree = "<group>"; wrapsLines = 0; };
|
||||||
27C6688B1C9584FA0021E494 /* IntervalSet.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = IntervalSet.h; sourceTree = "<group>"; };
|
27C6688B1C9584FA0021E494 /* IntervalSet.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = IntervalSet.h; sourceTree = "<group>"; };
|
||||||
27C6688C1C9584FA0021E494 /* IntSet.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = IntSet.cpp; sourceTree = "<group>"; };
|
|
||||||
27C6688D1C9584FA0021E494 /* IntSet.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = IntSet.h; sourceTree = "<group>"; };
|
|
||||||
27C668901C9584FA0021E494 /* LogManager.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = LogManager.cpp; sourceTree = "<group>"; };
|
27C668901C9584FA0021E494 /* LogManager.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = LogManager.cpp; sourceTree = "<group>"; };
|
||||||
27C668911C9584FA0021E494 /* LogManager.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = LogManager.h; sourceTree = "<group>"; };
|
27C668911C9584FA0021E494 /* LogManager.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = LogManager.h; sourceTree = "<group>"; };
|
||||||
27C668921C9584FA0021E494 /* MultiMap.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = MultiMap.cpp; sourceTree = "<group>"; };
|
27C668921C9584FA0021E494 /* MultiMap.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = MultiMap.cpp; sourceTree = "<group>"; };
|
||||||
|
@ -1076,8 +1072,6 @@
|
||||||
27C668891C9584FA0021E494 /* Interval.h */,
|
27C668891C9584FA0021E494 /* Interval.h */,
|
||||||
27C6688A1C9584FA0021E494 /* IntervalSet.cpp */,
|
27C6688A1C9584FA0021E494 /* IntervalSet.cpp */,
|
||||||
27C6688B1C9584FA0021E494 /* IntervalSet.h */,
|
27C6688B1C9584FA0021E494 /* IntervalSet.h */,
|
||||||
27C6688C1C9584FA0021E494 /* IntSet.cpp */,
|
|
||||||
27C6688D1C9584FA0021E494 /* IntSet.h */,
|
|
||||||
27C668901C9584FA0021E494 /* LogManager.cpp */,
|
27C668901C9584FA0021E494 /* LogManager.cpp */,
|
||||||
27C668911C9584FA0021E494 /* LogManager.h */,
|
27C668911C9584FA0021E494 /* LogManager.h */,
|
||||||
27C668921C9584FA0021E494 /* MultiMap.cpp */,
|
27C668921C9584FA0021E494 /* MultiMap.cpp */,
|
||||||
|
@ -1348,8 +1342,9 @@
|
||||||
37F135691B4AC02800E0CACF /* antlrcpp Tests */ = {
|
37F135691B4AC02800E0CACF /* antlrcpp Tests */ = {
|
||||||
isa = PBXGroup;
|
isa = PBXGroup;
|
||||||
children = (
|
children = (
|
||||||
37F1356C1B4AC02800E0CACF /* antlrcpp_Tests.mm */,
|
|
||||||
37F1356A1B4AC02800E0CACF /* Supporting Files */,
|
37F1356A1B4AC02800E0CACF /* Supporting Files */,
|
||||||
|
37F1356C1B4AC02800E0CACF /* antlrcpp_Tests.mm */,
|
||||||
|
2747A7121CA6C46C0030247B /* InputHandlingTests.mm */,
|
||||||
);
|
);
|
||||||
path = "antlrcpp Tests";
|
path = "antlrcpp Tests";
|
||||||
sourceTree = "<group>";
|
sourceTree = "<group>";
|
||||||
|
@ -1436,7 +1431,6 @@
|
||||||
27C669921C9585B80021E494 /* ErrorNode.h in Headers */,
|
27C669921C9585B80021E494 /* ErrorNode.h in Headers */,
|
||||||
27C668B91C9584FA0021E494 /* IntervalSet.h in Headers */,
|
27C668B91C9584FA0021E494 /* IntervalSet.h in Headers */,
|
||||||
27C666C51C9584050021E494 /* BufferedTokenStream.h in Headers */,
|
27C666C51C9584050021E494 /* BufferedTokenStream.h in Headers */,
|
||||||
27C668BD1C9584FA0021E494 /* IntSet.h in Headers */,
|
|
||||||
27C669AA1C9585B80021E494 /* ParseTreeWalker.h in Headers */,
|
27C669AA1C9585B80021E494 /* ParseTreeWalker.h in Headers */,
|
||||||
27C6685F1C95846E0021E494 /* Transition.h in Headers */,
|
27C6685F1C95846E0021E494 /* Transition.h in Headers */,
|
||||||
27C666D51C9584050021E494 /* CommonTokenStream.h in Headers */,
|
27C666D51C9584050021E494 /* CommonTokenStream.h in Headers */,
|
||||||
|
@ -1600,7 +1594,6 @@
|
||||||
27C6699D1C9585B80021E494 /* ParseTreeListener.h in Headers */,
|
27C6699D1C9585B80021E494 /* ParseTreeListener.h in Headers */,
|
||||||
27C666F61C9584050021E494 /* IntStream.h in Headers */,
|
27C666F61C9584050021E494 /* IntStream.h in Headers */,
|
||||||
27C669951C9585B80021E494 /* ErrorNodeImpl.h in Headers */,
|
27C669951C9585B80021E494 /* ErrorNodeImpl.h in Headers */,
|
||||||
27C668BC1C9584FA0021E494 /* IntSet.h in Headers */,
|
|
||||||
27C667A81C95846E0021E494 /* AbstractPredicateTransition.h in Headers */,
|
27C667A81C95846E0021E494 /* AbstractPredicateTransition.h in Headers */,
|
||||||
27C669A91C9585B80021E494 /* ParseTreeWalker.h in Headers */,
|
27C669A91C9585B80021E494 /* ParseTreeWalker.h in Headers */,
|
||||||
27C667181C9584050021E494 /* ParserRuleContext.h in Headers */,
|
27C667181C9584050021E494 /* ParserRuleContext.h in Headers */,
|
||||||
|
@ -1879,7 +1872,6 @@
|
||||||
27C668511C95846E0021E494 /* StarLoopbackState.cpp in Sources */,
|
27C668511C95846E0021E494 /* StarLoopbackState.cpp in Sources */,
|
||||||
27C667FB1C95846E0021E494 /* LexerATNSimulator.cpp in Sources */,
|
27C667FB1C95846E0021E494 /* LexerATNSimulator.cpp in Sources */,
|
||||||
27C667EB1C95846E0021E494 /* DecisionState.cpp in Sources */,
|
27C667EB1C95846E0021E494 /* DecisionState.cpp in Sources */,
|
||||||
27C668BB1C9584FA0021E494 /* IntSet.cpp in Sources */,
|
|
||||||
27C669151C9585230021E494 /* guid.cpp in Sources */,
|
27C669151C9585230021E494 /* guid.cpp in Sources */,
|
||||||
27C669941C9585B80021E494 /* ErrorNodeImpl.cpp in Sources */,
|
27C669941C9585B80021E494 /* ErrorNodeImpl.cpp in Sources */,
|
||||||
27C6687A1C9584B60021E494 /* LexerDFASerializer.cpp in Sources */,
|
27C6687A1C9584B60021E494 /* LexerDFASerializer.cpp in Sources */,
|
||||||
|
@ -2079,7 +2071,6 @@
|
||||||
27C66A3A1C958AC10021E494 /* XPathLexerErrorListener.cpp in Sources */,
|
27C66A3A1C958AC10021E494 /* XPathLexerErrorListener.cpp in Sources */,
|
||||||
27C66A041C958AB30021E494 /* ParseTreePattern.cpp in Sources */,
|
27C66A041C958AB30021E494 /* ParseTreePattern.cpp in Sources */,
|
||||||
27C6685C1C95846E0021E494 /* Transition.cpp in Sources */,
|
27C6685C1C95846E0021E494 /* Transition.cpp in Sources */,
|
||||||
27C668BA1C9584FA0021E494 /* IntSet.cpp in Sources */,
|
|
||||||
27C66A021C958AB30021E494 /* ParseTreeMatch.cpp in Sources */,
|
27C66A021C958AB30021E494 /* ParseTreeMatch.cpp in Sources */,
|
||||||
27C66A361C958AC10021E494 /* XPathElement.cpp in Sources */,
|
27C66A361C958AC10021E494 /* XPathElement.cpp in Sources */,
|
||||||
27C668441C95846E0021E494 /* SetTransition.cpp in Sources */,
|
27C668441C95846E0021E494 /* SetTransition.cpp in Sources */,
|
||||||
|
@ -2115,6 +2106,7 @@
|
||||||
buildActionMask = 2147483647;
|
buildActionMask = 2147483647;
|
||||||
files = (
|
files = (
|
||||||
37F1356D1B4AC02800E0CACF /* antlrcpp_Tests.mm in Sources */,
|
37F1356D1B4AC02800E0CACF /* antlrcpp_Tests.mm in Sources */,
|
||||||
|
2747A7131CA6C46C0030247B /* InputHandlingTests.mm in Sources */,
|
||||||
);
|
);
|
||||||
runOnlyForDeploymentPostprocessing = 0;
|
runOnlyForDeploymentPostprocessing = 0;
|
||||||
};
|
};
|
||||||
|
@ -2224,6 +2216,7 @@
|
||||||
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
|
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
|
||||||
CLANG_WARN_EMPTY_BODY = YES;
|
CLANG_WARN_EMPTY_BODY = YES;
|
||||||
CLANG_WARN_ENUM_CONVERSION = YES;
|
CLANG_WARN_ENUM_CONVERSION = YES;
|
||||||
|
CLANG_WARN_IMPLICIT_SIGN_CONVERSION = YES;
|
||||||
CLANG_WARN_INT_CONVERSION = YES;
|
CLANG_WARN_INT_CONVERSION = YES;
|
||||||
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
|
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
|
||||||
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
|
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
|
||||||
|
@ -2241,6 +2234,7 @@
|
||||||
GCC_SYMBOLS_PRIVATE_EXTERN = NO;
|
GCC_SYMBOLS_PRIVATE_EXTERN = NO;
|
||||||
GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
|
GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
|
||||||
GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR;
|
GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR;
|
||||||
|
GCC_WARN_SIGN_COMPARE = YES;
|
||||||
GCC_WARN_UNDECLARED_SELECTOR = YES;
|
GCC_WARN_UNDECLARED_SELECTOR = YES;
|
||||||
GCC_WARN_UNINITIALIZED_AUTOS = YES;
|
GCC_WARN_UNINITIALIZED_AUTOS = YES;
|
||||||
GCC_WARN_UNUSED_FUNCTION = YES;
|
GCC_WARN_UNUSED_FUNCTION = YES;
|
||||||
|
@ -2263,6 +2257,7 @@
|
||||||
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
|
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
|
||||||
CLANG_WARN_EMPTY_BODY = YES;
|
CLANG_WARN_EMPTY_BODY = YES;
|
||||||
CLANG_WARN_ENUM_CONVERSION = YES;
|
CLANG_WARN_ENUM_CONVERSION = YES;
|
||||||
|
CLANG_WARN_IMPLICIT_SIGN_CONVERSION = YES;
|
||||||
CLANG_WARN_INT_CONVERSION = YES;
|
CLANG_WARN_INT_CONVERSION = YES;
|
||||||
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
|
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
|
||||||
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
|
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
|
||||||
|
@ -2274,6 +2269,7 @@
|
||||||
GCC_PREFIX_HEADER = "../../runtime/antlrcpp-Prefix.h";
|
GCC_PREFIX_HEADER = "../../runtime/antlrcpp-Prefix.h";
|
||||||
GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
|
GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
|
||||||
GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR;
|
GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR;
|
||||||
|
GCC_WARN_SIGN_COMPARE = YES;
|
||||||
GCC_WARN_UNDECLARED_SELECTOR = YES;
|
GCC_WARN_UNDECLARED_SELECTOR = YES;
|
||||||
GCC_WARN_UNINITIALIZED_AUTOS = YES;
|
GCC_WARN_UNINITIALIZED_AUTOS = YES;
|
||||||
GCC_WARN_UNUSED_FUNCTION = YES;
|
GCC_WARN_UNUSED_FUNCTION = YES;
|
||||||
|
|
|
@ -56,7 +56,7 @@ conquer:
|
||||||
|
|
||||||
// Unused rule to demonstrate some of the special features.
|
// Unused rule to demonstrate some of the special features.
|
||||||
// Note: returns and throws are ignored in the C++ target.
|
// Note: returns and throws are ignored in the C++ target.
|
||||||
unused returns [double i] throws stones, flowers @init{ doInit(); } @after { doAfter(); } :
|
unused returns [double calculated] throws stones, flowers @init{ doInit(); } @after { doAfter(); } :
|
||||||
;
|
;
|
||||||
catch [...] {
|
catch [...] {
|
||||||
// Replaces the standard exception handling.
|
// Replaces the standard exception handling.
|
||||||
|
|
|
@ -25,6 +25,8 @@ set -o errexit
|
||||||
# This approach is especially useful if you are working on a target stg file, as it doesn't require to regenerate the
|
# This approach is especially useful if you are working on a target stg file, as it doesn't require to regenerate the
|
||||||
# antlr jar over and over again.
|
# antlr jar over and over again.
|
||||||
CLASSPATH=../../../tool/resources/:ST-4.0.8.jar:../../../tool/target/classes:../../../runtime/Java/target/classes:../../../../antlr3/runtime/Java/target/classes
|
CLASSPATH=../../../tool/resources/:ST-4.0.8.jar:../../../tool/target/classes:../../../runtime/Java/target/classes:../../../../antlr3/runtime/Java/target/classes
|
||||||
java -cp $CLASSPATH org.antlr.v4.Tool -Dlanguage=Cpp -listener -visitor -o generated/ -package antlrcpptest TLexer.g4 TParser.g4
|
#java -cp $CLASSPATH org.antlr.v4.Tool -Dlanguage=Cpp -listener -visitor -o generated/ -package antlrcpptest TLexer.g4 TParser.g4
|
||||||
|
#java -cp $CLASSPATH org.antlr.v4.Tool -Dlanguage=Cpp -listener -visitor -o generated/ -package antlrcpptest MySQL.g4
|
||||||
|
java -cp $CLASSPATH org.antlr.v4.Tool -Dlanguage=Java -listener -visitor -o generated/ -package antlrcpptest MySQL.g4
|
||||||
#java -cp $CLASSPATH org.antlr.v4.Tool -Dlanguage=Java -listener -visitor -o generated/ TLexer.g4 TParser.g4
|
#java -cp $CLASSPATH org.antlr.v4.Tool -Dlanguage=Java -listener -visitor -o generated/ TLexer.g4 TParser.g4
|
||||||
#java -cp $CLASSPATH org.antlr.v4.Tool -Dlanguage=Cpp -listener -visitor -o generated/ -package antlrcpptest -XdbgST TLexer.g4 TParser.g4
|
#java -cp $CLASSPATH org.antlr.v4.Tool -Dlanguage=Cpp -listener -visitor -o generated/ -package antlrcpptest -XdbgST TLexer.g4 TParser.g4
|
||||||
|
|
|
@ -77,9 +77,8 @@ namespace runtime {
|
||||||
/// the parser was able to recover in line without exiting the
|
/// the parser was able to recover in line without exiting the
|
||||||
/// surrounding rule. </param>
|
/// surrounding rule. </param>
|
||||||
public:
|
public:
|
||||||
void syntaxError(IRecognizer *recognizer, void *offendingSymbol,
|
void syntaxError(IRecognizer *recognizer, void *offendingSymbol, size_t line, int charPositionInLine,
|
||||||
int line, int charPositionInLine, const std::wstring &msg,
|
const std::wstring &msg, RecognitionException *e) {}
|
||||||
RecognitionException *e) {}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// This method is called by the parser when a full-context prediction
|
/// This method is called by the parser when a full-context prediction
|
||||||
|
@ -108,7 +107,8 @@ namespace runtime {
|
||||||
/// <param name="ambigAlts"> the potentially ambiguous alternatives </param>
|
/// <param name="ambigAlts"> the potentially ambiguous alternatives </param>
|
||||||
/// <param name="configs"> the ATN configuration set where the ambiguity was
|
/// <param name="configs"> the ATN configuration set where the ambiguity was
|
||||||
/// determined </param>
|
/// determined </param>
|
||||||
virtual void reportAmbiguity(Parser *recognizer, dfa::DFA *dfa, int startIndex, int stopIndex, bool exact, antlrcpp::BitSet *ambigAlts, atn::ATNConfigSet *configs) = 0;
|
virtual void reportAmbiguity(Parser *recognizer, dfa::DFA *dfa, size_t startIndex, size_t stopIndex, bool exact,
|
||||||
|
antlrcpp::BitSet *ambigAlts, atn::ATNConfigSet *configs) = 0;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// This method is called when an SLL conflict occurs and the parser is about
|
/// This method is called when an SLL conflict occurs and the parser is about
|
||||||
|
@ -130,7 +130,8 @@ namespace runtime {
|
||||||
/// represented in {@code configs}. </param>
|
/// represented in {@code configs}. </param>
|
||||||
/// <param name="configs"> the ATN configuration set where the SLL conflict was
|
/// <param name="configs"> the ATN configuration set where the SLL conflict was
|
||||||
/// detected </param>
|
/// detected </param>
|
||||||
virtual void reportAttemptingFullContext(Parser *recognizer, dfa::DFA *dfa, int startIndex, int stopIndex, antlrcpp::BitSet *conflictingAlts, atn::ATNConfigSet *configs) = 0;
|
virtual void reportAttemptingFullContext(Parser *recognizer, dfa::DFA *dfa, size_t startIndex, size_t stopIndex,
|
||||||
|
antlrcpp::BitSet *conflictingAlts, atn::ATNConfigSet *configs) = 0;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// This method is called by the parser when a full-context prediction has a
|
/// This method is called by the parser when a full-context prediction has a
|
||||||
|
@ -159,7 +160,8 @@ namespace runtime {
|
||||||
/// <param name="prediction"> the unambiguous result of the full-context prediction </param>
|
/// <param name="prediction"> the unambiguous result of the full-context prediction </param>
|
||||||
/// <param name="configs"> the ATN configuration set where the unambiguous prediction
|
/// <param name="configs"> the ATN configuration set where the unambiguous prediction
|
||||||
/// was determined </param>
|
/// was determined </param>
|
||||||
virtual void reportContextSensitivity(Parser *recognizer, dfa::DFA *dfa, int startIndex, int stopIndex, int prediction, atn::ATNConfigSet *configs) = 0;
|
virtual void reportContextSensitivity(Parser *recognizer, dfa::DFA *dfa, size_t startIndex, size_t stopIndex,
|
||||||
|
int prediction, atn::ATNConfigSet *configs) = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace runtime
|
} // namespace runtime
|
||||||
|
|
|
@ -30,50 +30,61 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "Exceptions.h"
|
#include "Exceptions.h"
|
||||||
|
#include "Strings.h"
|
||||||
|
|
||||||
#include "ANTLRFileStream.h"
|
#include "ANTLRFileStream.h"
|
||||||
|
|
||||||
using namespace org::antlr::v4::runtime;
|
using namespace org::antlr::v4::runtime;
|
||||||
|
|
||||||
ANTLRFileStream::ANTLRFileStream(const std::string &fileName) {
|
|
||||||
}
|
|
||||||
|
|
||||||
ANTLRFileStream::ANTLRFileStream(const std::string &fileName, const std::string &encoding) {
|
ANTLRFileStream::ANTLRFileStream(const std::string &fileName, const std::string &encoding) {
|
||||||
this->fileName = fileName;
|
_fileName = fileName;
|
||||||
load(fileName, encoding);
|
load(fileName, encoding);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
Issue: is seems that file name in C++ are considered to be not
|
|
||||||
wide for the reason that not all systems support wchar file
|
|
||||||
names. Win32 is good about this but not all others.
|
|
||||||
TODO: this could be a place to have platform specific build
|
|
||||||
flags
|
|
||||||
*/
|
|
||||||
void ANTLRFileStream::load(const std::string &fileName, const std::string &encoding) {
|
void ANTLRFileStream::load(const std::string &fileName, const std::string &encoding) {
|
||||||
if (fileName == "") {
|
if (_fileName.empty()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
enum Encoding { ANSI, UTF8, UTF16LE } encodingType = ANSI;
|
||||||
|
|
||||||
|
#ifdef _WIN32
|
||||||
|
std::ifstream stream(antlrcpp::s2ws(filename).c_str(), std::ios::binary);
|
||||||
|
#else
|
||||||
|
std::ifstream stream(_fileName.c_str(), std::ifstream::binary);
|
||||||
|
#endif
|
||||||
|
|
||||||
std::stringstream ss;
|
std::stringstream ss;
|
||||||
std::wifstream f;
|
|
||||||
|
|
||||||
// Open as a byte stream
|
if (!stream.is_open() || stream.eof())
|
||||||
f.open(fileName, std::ios::binary);
|
return;
|
||||||
ss<<f.rdbuf();
|
|
||||||
|
|
||||||
std::string const &s = ss.str();
|
int ch1 = stream.get();
|
||||||
if (s.size() % sizeof(wchar_t) != 0)
|
int ch2 = stream.get();
|
||||||
|
if (ch1 == 0xff && ch2 == 0xfe)
|
||||||
|
encodingType = UTF16LE;
|
||||||
|
else
|
||||||
|
if (ch1 == 0xfe && ch2 == 0xff)
|
||||||
|
return; // UTF-16BE not supported;
|
||||||
|
else
|
||||||
{
|
{
|
||||||
throw new IOException(L"file not the right size");
|
int ch3 = stream.get();
|
||||||
|
if (ch1 == 0xef && ch2 == 0xbb && ch3 == 0xbf)
|
||||||
|
encodingType = UTF8;
|
||||||
|
else
|
||||||
|
stream.seekg(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::wstring ws;
|
ss << stream.rdbuf() << '\0';
|
||||||
ws.resize(s.size()/sizeof(wchar_t));
|
switch (encodingType)
|
||||||
std::memcpy(&ws[0],s.c_str(),s.size()); // copy data into wstring
|
{
|
||||||
data=ws;
|
case UTF16LE:
|
||||||
|
data = (wchar_t *)ss.str().c_str();
|
||||||
|
default:
|
||||||
|
data = antlrcpp::s2ws(ss.str());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string ANTLRFileStream::getSourceName() {
|
std::string ANTLRFileStream::getSourceName() {
|
||||||
return fileName;
|
return _fileName;
|
||||||
}
|
}
|
||||||
|
|
|
@ -38,18 +38,17 @@ namespace antlr {
|
||||||
namespace v4 {
|
namespace v4 {
|
||||||
namespace runtime {
|
namespace runtime {
|
||||||
|
|
||||||
/// <summary>
|
/// This is an ANTLRInputStream that is loaded from a file all at once
|
||||||
/// This is an <seealso cref="ANTLRInputStream"/> that is loaded from a file all at once
|
|
||||||
/// when you construct the object.
|
/// when you construct the object.
|
||||||
/// </summary>
|
|
||||||
class ANTLRFileStream : public ANTLRInputStream {
|
class ANTLRFileStream : public ANTLRInputStream {
|
||||||
protected:
|
protected:
|
||||||
std::string fileName;
|
std::string _fileName; // UTF-8 encoded file name.
|
||||||
|
|
||||||
public:
|
public:
|
||||||
ANTLRFileStream(const std::string &fileName); //this(fileName, nullptr);
|
// Assumes a file name encoded in UTF-8. The file content encoding is detected automatically
|
||||||
|
// but must be one of ANSI, UTF-8 or UTF-16 (LE). A possible Unicode BOM is used to help auto detection.
|
||||||
ANTLRFileStream(const std::string &fileName, const std::string &encoding);
|
// The encoding paramater is currently being ignored.
|
||||||
|
ANTLRFileStream(const std::string &fileName, const std::string &encoding = "");
|
||||||
|
|
||||||
virtual void load(const std::string &fileName, const std::string &encoding);
|
virtual void load(const std::string &fileName, const std::string &encoding);
|
||||||
|
|
||||||
|
|
|
@ -29,78 +29,54 @@
|
||||||
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include <algorithm>
|
||||||
#include "Exceptions.h"
|
#include "Exceptions.h"
|
||||||
#include "Interval.h"
|
#include "Interval.h"
|
||||||
#include "Arrays.h"
|
#include "Arrays.h"
|
||||||
|
#include "CPPUtils.h"
|
||||||
|
|
||||||
#include "ANTLRInputStream.h"
|
#include "ANTLRInputStream.h"
|
||||||
|
|
||||||
using namespace org::antlr::v4::runtime;
|
using namespace org::antlr::v4::runtime;
|
||||||
|
using namespace antlrcpp;
|
||||||
|
|
||||||
using misc::Interval;
|
using misc::Interval;
|
||||||
|
|
||||||
ANTLRInputStream::ANTLRInputStream() {
|
ANTLRInputStream::ANTLRInputStream(const std::wstring &input) : data(input) {
|
||||||
InitializeInstanceFields();
|
InitializeInstanceFields();
|
||||||
}
|
}
|
||||||
|
|
||||||
ANTLRInputStream::ANTLRInputStream(const std::wstring &input) : ANTLRInputStream() {
|
ANTLRInputStream::ANTLRInputStream(const wchar_t data[], size_t numberOfActualCharsInArray)
|
||||||
this->data = input;
|
: ANTLRInputStream(std::wstring(data, numberOfActualCharsInArray)) {
|
||||||
this->n = (int)input.length();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ANTLRInputStream::ANTLRInputStream(wchar_t data[], int numberOfActualCharsInArray) : ANTLRInputStream() {
|
ANTLRInputStream::ANTLRInputStream(std::wiostream &stream) : ANTLRInputStream(stream, READ_BUFFER_SIZE) {
|
||||||
this->data = data;
|
|
||||||
this->n = numberOfActualCharsInArray;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ANTLRInputStream::ANTLRInputStream(std::wiostream &stream, std::streamsize readChunkSize) : ANTLRInputStream() {
|
||||||
ANTLRInputStream::ANTLRInputStream(std::wifstream *r) : ANTLRInputStream() {
|
load(stream, readChunkSize);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ANTLRInputStream::load(std::wiostream &stream, std::streamsize readChunkSize) {
|
||||||
ANTLRInputStream::ANTLRInputStream(std::wifstream *r, int initialSize) : ANTLRInputStream() {
|
stream.seekg(0, stream.beg);
|
||||||
}
|
if (!stream.good()) // No fail, bad or EOF.
|
||||||
|
|
||||||
ANTLRInputStream::ANTLRInputStream(std::wifstream *r, int initialSize, int readChunkSize) : ANTLRInputStream() {
|
|
||||||
load(r, initialSize, readChunkSize);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void ANTLRInputStream::load(std::wifstream *r, int size, int readChunkSize) {
|
|
||||||
if (r == nullptr) {
|
|
||||||
return;
|
return;
|
||||||
}
|
|
||||||
|
|
||||||
if (size <= 0) {
|
data.clear();
|
||||||
size = INITIAL_BUFFER_SIZE;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (readChunkSize <= 0) {
|
if (readChunkSize == 0) {
|
||||||
readChunkSize = READ_BUFFER_SIZE;
|
readChunkSize = READ_BUFFER_SIZE;
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
wchar_t *buffer = new wchar_t[readChunkSize];
|
||||||
// alloc initial buffer size.
|
auto onExit = finally([buffer] {
|
||||||
data = new wchar_t[size];
|
delete[] buffer;
|
||||||
// read all the data in chunks of readChunkSize
|
});
|
||||||
int numRead = 0;
|
|
||||||
int p = 0;
|
|
||||||
do {
|
|
||||||
if (p + readChunkSize > (int)data.length()) { // overflow?
|
|
||||||
data = antlrcpp::Arrays::copyOf(data, (int)data.length() * 2);
|
|
||||||
}
|
|
||||||
r->read(new wchar_t[100], p);
|
|
||||||
|
|
||||||
p += numRead;
|
while (!stream.eof()) {
|
||||||
} while (numRead != -1); // while not EOF
|
stream.read(buffer, readChunkSize);
|
||||||
// set the actual size of the data available;
|
data.append(buffer, (size_t)std::min(stream.gcount(), readChunkSize));
|
||||||
// EOF subtracted one above in p+=numRead; add one back
|
|
||||||
n = p + 1;
|
|
||||||
}
|
}
|
||||||
catch (void *) {
|
|
||||||
r->close();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void ANTLRInputStream::reset() {
|
void ANTLRInputStream::reset() {
|
||||||
|
@ -108,72 +84,77 @@ void ANTLRInputStream::reset() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void ANTLRInputStream::consume() {
|
void ANTLRInputStream::consume() {
|
||||||
if (p >= n) {
|
if (p >= data.size()) {
|
||||||
assert(LA(1) == IntStream::_EOF);
|
assert(LA(1) == IntStream::_EOF);
|
||||||
throw IllegalStateException(L"cannot consume EOF");
|
throw IllegalStateException(L"cannot consume EOF");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (p < n) {
|
if (p < data.size()) {
|
||||||
p++;
|
p++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int ANTLRInputStream::LA(int i) {
|
size_t ANTLRInputStream::LA(ssize_t i) {
|
||||||
if (i == 0) {
|
if (i == 0) {
|
||||||
return 0; // undefined
|
return 0; // undefined
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ssize_t position = (ssize_t)p;
|
||||||
if (i < 0) {
|
if (i < 0) {
|
||||||
i++; // e.g., translate LA(-1) to use offset i=0; then data[p+0-1]
|
i++; // e.g., translate LA(-1) to use offset i=0; then data[p+0-1]
|
||||||
if ((p + i - 1) < 0) {
|
if ((position + i - 1) < 0) {
|
||||||
return IntStream::_EOF; // invalid; no char before first char
|
return IntStream::_EOF; // invalid; no char before first char
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((p + i - 1) >= n) {
|
if ((position + i - 1) >= (ssize_t)data.size()) {
|
||||||
return IntStream::_EOF;
|
return IntStream::_EOF;
|
||||||
}
|
}
|
||||||
|
|
||||||
return data[p + i - 1];
|
return (size_t)data[(size_t)(position + i - 1)];
|
||||||
}
|
}
|
||||||
|
|
||||||
int ANTLRInputStream::LT(int i) {
|
size_t ANTLRInputStream::LT(ssize_t i) {
|
||||||
return LA(i);
|
return LA(i);
|
||||||
}
|
}
|
||||||
|
|
||||||
int ANTLRInputStream::index() {
|
size_t ANTLRInputStream::index() {
|
||||||
return p;
|
return p;
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t ANTLRInputStream::size() {
|
size_t ANTLRInputStream::size() {
|
||||||
return n;
|
return data.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
int ANTLRInputStream::mark() {
|
// Mark/release do nothing. We have entire buffer.
|
||||||
|
ssize_t ANTLRInputStream::mark() {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ANTLRInputStream::release(int marker) {
|
void ANTLRInputStream::release(ssize_t marker) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void ANTLRInputStream::seek(int index) {
|
void ANTLRInputStream::seek(size_t index) {
|
||||||
if (index <= p) {
|
if (index <= p) {
|
||||||
p = index; // just jump; don't update stream state (line, ...)
|
p = index; // just jump; don't update stream state (line, ...)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// seek forward, consume until p hits index
|
// seek forward, consume until p hits index
|
||||||
while (p < index && index < n) {
|
while (p < index && index < data.size()) {
|
||||||
consume();
|
consume();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
std::wstring ANTLRInputStream::getText(Interval *interval) {
|
std::wstring ANTLRInputStream::getText(const Interval &interval) {
|
||||||
int start = interval->a;
|
size_t start = (size_t)interval.a;
|
||||||
int stop = interval->b;
|
size_t stop = (size_t)interval.b;
|
||||||
if (stop >= n) {
|
|
||||||
stop = n - 1;
|
if (stop >= data.size()) {
|
||||||
|
stop = data.size() - 1;
|
||||||
}
|
}
|
||||||
int count = stop - start + 1;
|
|
||||||
if (start >= n) {
|
size_t count = stop - start + 1;
|
||||||
|
if (start >= data.size()) {
|
||||||
return L"";
|
return L"";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -189,6 +170,5 @@ std::wstring ANTLRInputStream::toString() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void ANTLRInputStream::InitializeInstanceFields() {
|
void ANTLRInputStream::InitializeInstanceFields() {
|
||||||
n = 0;
|
|
||||||
p = 0;
|
p = 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -38,96 +38,58 @@ namespace antlr {
|
||||||
namespace v4 {
|
namespace v4 {
|
||||||
namespace runtime {
|
namespace runtime {
|
||||||
|
|
||||||
/// Vacuum all input from a Reader/InputStream and then treat it
|
/// Vacuum all input from a stream and then treat it
|
||||||
/// like a char[] buffer. Can also pass in a string or char[] to use.
|
/// like a string. Can also pass in a string or char[] to use.
|
||||||
/// <p/>
|
|
||||||
/// If you need encoding, pass in stream/reader with correct encoding.
|
|
||||||
/// </summary>
|
|
||||||
class ANTLRInputStream : public CharStream {
|
class ANTLRInputStream : public CharStream {
|
||||||
public:
|
public:
|
||||||
static const int READ_BUFFER_SIZE = 1024;
|
static const int READ_BUFFER_SIZE = 1024;
|
||||||
static const int INITIAL_BUFFER_SIZE = 1024;
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// The data being scanned </summary>
|
|
||||||
protected:
|
protected:
|
||||||
std::wstring data;
|
/// The data being scanned.
|
||||||
|
std::wstring data; // XXX: move to std::string and UTF-8 to support input beyond the Unicode BMP.
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// How many characters are actually in the buffer </summary>
|
|
||||||
int n;
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 0..n-1 index into string of next char </summary>
|
/// 0..n-1 index into string of next char </summary>
|
||||||
int p;
|
size_t p;
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// What is name or source of this char stream? </summary>
|
|
||||||
public:
|
public:
|
||||||
|
/// What is name or source of this char stream?
|
||||||
std::string name;
|
std::string name;
|
||||||
|
|
||||||
ANTLRInputStream();
|
ANTLRInputStream(const std::wstring &input = L"");
|
||||||
|
ANTLRInputStream(const wchar_t data[], size_t numberOfActualCharsInArray);
|
||||||
|
ANTLRInputStream(std::wiostream &stream) ;
|
||||||
|
ANTLRInputStream(std::wiostream &stream, std::streamsize readChunkSize);
|
||||||
|
|
||||||
/// <summary>
|
virtual void load(std::wiostream &stream, std::streamsize readChunkSize);
|
||||||
/// Copy data in string to a local char array </summary>
|
|
||||||
ANTLRInputStream(const std::wstring &input);
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// This is the preferred constructor for strings as no data is copied </summary>
|
|
||||||
ANTLRInputStream(wchar_t data[], int numberOfActualCharsInArray);
|
|
||||||
|
|
||||||
ANTLRInputStream(std::wifstream *r) ; //this(r, INITIAL_BUFFER_SIZE, READ_BUFFER_SIZE);
|
|
||||||
|
|
||||||
ANTLRInputStream(std::wifstream *r, int initialSize) ; //this(r, initialSize, READ_BUFFER_SIZE);
|
|
||||||
|
|
||||||
ANTLRInputStream(std::wifstream *r, int initialSize, int readChunkSize);
|
|
||||||
|
|
||||||
ANTLRInputStream(std::wiostream *input) ; //this(new InputStreamReader(input), INITIAL_BUFFER_SIZE);
|
|
||||||
|
|
||||||
ANTLRInputStream(std::wiostream *input, int initialSize); //this(new InputStreamReader(input), initialSize);
|
|
||||||
|
|
||||||
ANTLRInputStream(std::wiostream *input, int initialSize, int readChunkSize); //this(new InputStreamReader(input), initialSize, readChunkSize);
|
|
||||||
|
|
||||||
virtual void load(std::wifstream *r, int size, int readChunkSize);
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Reset the stream so that it's in the same state it was
|
/// Reset the stream so that it's in the same state it was
|
||||||
/// when the object was created *except* the data array is not
|
/// when the object was created *except* the data array is not
|
||||||
/// touched.
|
/// touched.
|
||||||
/// </summary>
|
|
||||||
virtual void reset();
|
virtual void reset();
|
||||||
|
|
||||||
virtual void consume() override;
|
virtual void consume() override;
|
||||||
|
virtual size_t LA(ssize_t i) override;
|
||||||
virtual int LA(int i) override;
|
virtual size_t LT(ssize_t i);
|
||||||
|
|
||||||
virtual int LT(int i);
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Return the current input symbol index 0..n where n indicates the
|
/// Return the current input symbol index 0..n where n indicates the
|
||||||
/// last symbol has been read. The index is the index of char to
|
/// last symbol has been read. The index is the index of char to
|
||||||
/// be returned from LA(1).
|
/// be returned from LA(1).
|
||||||
/// </summary>
|
/// </summary>
|
||||||
virtual int index() override;
|
virtual size_t index() override;
|
||||||
|
|
||||||
virtual size_t size() override;
|
virtual size_t size() override;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// mark/release do nothing; we have entire buffer </summary>
|
/// mark/release do nothing; we have entire buffer </summary>
|
||||||
virtual int mark() override;
|
virtual ssize_t mark() override;
|
||||||
|
virtual void release(ssize_t marker) override;
|
||||||
virtual void release(int marker) override;
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// consume() ahead until p==index; can't just set p=index as we must
|
/// consume() ahead until p==index; can't just set p=index as we must
|
||||||
/// update line and charPositionInLine. If we seek backwards, just set p
|
/// update line and charPositionInLine. If we seek backwards, just set p
|
||||||
/// </summary>
|
/// </summary>
|
||||||
virtual void seek(int index) override;
|
virtual void seek(size_t index) override;
|
||||||
|
virtual std::wstring getText(const misc::Interval &interval) override;
|
||||||
virtual std::wstring getText(misc::Interval *interval) override;
|
|
||||||
|
|
||||||
virtual std::string getSourceName() override;
|
virtual std::string getSourceName() override;
|
||||||
|
|
||||||
virtual std::wstring toString();
|
virtual std::wstring toString();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
|
@ -33,11 +33,14 @@
|
||||||
|
|
||||||
using namespace org::antlr::v4::runtime;
|
using namespace org::antlr::v4::runtime;
|
||||||
|
|
||||||
void BaseErrorListener::reportAmbiguity(Parser *recognizer, dfa::DFA *dfa, int startIndex, int stopIndex, bool exact, antlrcpp::BitSet *ambigAlts, atn::ATNConfigSet *configs) {
|
void BaseErrorListener::reportAmbiguity(Parser *recognizer, dfa::DFA *dfa, size_t startIndex, size_t stopIndex,
|
||||||
|
bool exact, antlrcpp::BitSet *ambigAlts, atn::ATNConfigSet *configs) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void BaseErrorListener::reportAttemptingFullContext(Parser *recognizer, dfa::DFA *dfa, int startIndex, int stopIndex, antlrcpp::BitSet *conflictingAlts, atn::ATNConfigSet *configs) {
|
void BaseErrorListener::reportAttemptingFullContext(Parser *recognizer, dfa::DFA *dfa, size_t startIndex,
|
||||||
|
size_t stopIndex, antlrcpp::BitSet *conflictingAlts, atn::ATNConfigSet *configs) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void BaseErrorListener::reportContextSensitivity(Parser *recognizer, dfa::DFA *dfa, int startIndex, int stopIndex, int prediction, atn::ATNConfigSet *configs) {
|
void BaseErrorListener::reportContextSensitivity(Parser *recognizer, dfa::DFA *dfa, size_t startIndex, size_t stopIndex,
|
||||||
|
int prediction, atn::ATNConfigSet *configs) {
|
||||||
}
|
}
|
||||||
|
|
|
@ -44,13 +44,17 @@ namespace runtime {
|
||||||
|
|
||||||
class BaseErrorListener : public ANTLRErrorListener {
|
class BaseErrorListener : public ANTLRErrorListener {
|
||||||
|
|
||||||
void syntaxError(IRecognizer *recognizer, void *offendingSymbol, int line, int charPositionInLine, const std::wstring &msg, RecognitionException *e) { }
|
void syntaxError(IRecognizer *recognizer, void *offendingSymbol, size_t line, int charPositionInLine,
|
||||||
|
const std::wstring &msg, RecognitionException *e) { }
|
||||||
|
|
||||||
virtual void reportAmbiguity(Parser *recognizer, dfa::DFA *dfa, int startIndex, int stopIndex, bool exact, antlrcpp::BitSet *ambigAlts, atn::ATNConfigSet *configs) override;
|
virtual void reportAmbiguity(Parser *recognizer, dfa::DFA *dfa, size_t startIndex, size_t stopIndex, bool exact,
|
||||||
|
antlrcpp::BitSet *ambigAlts, atn::ATNConfigSet *configs) override;
|
||||||
|
|
||||||
virtual void reportAttemptingFullContext(Parser *recognizer, dfa::DFA *dfa, int startIndex, int stopIndex, antlrcpp::BitSet *conflictingAlts, atn::ATNConfigSet *configs) override;
|
virtual void reportAttemptingFullContext(Parser *recognizer, dfa::DFA *dfa, size_t startIndex, size_t stopIndex,
|
||||||
|
antlrcpp::BitSet *conflictingAlts, atn::ATNConfigSet *configs) override;
|
||||||
|
|
||||||
virtual void reportContextSensitivity(Parser *recognizer, dfa::DFA *dfa, int startIndex, int stopIndex, int prediction, atn::ATNConfigSet *configs) override;
|
virtual void reportContextSensitivity(Parser *recognizer, dfa::DFA *dfa, size_t startIndex, size_t stopIndex,
|
||||||
|
int prediction, atn::ATNConfigSet *configs) override;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace runtime
|
} // namespace runtime
|
||||||
|
|
|
@ -51,15 +51,15 @@ TokenSource *BufferedTokenStream::getTokenSource() {
|
||||||
return tokenSource;
|
return tokenSource;
|
||||||
}
|
}
|
||||||
|
|
||||||
int BufferedTokenStream::index() {
|
size_t BufferedTokenStream::index() {
|
||||||
return p;
|
return p;
|
||||||
}
|
}
|
||||||
|
|
||||||
int BufferedTokenStream::mark() {
|
ssize_t BufferedTokenStream::mark() {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void BufferedTokenStream::release(int marker) {
|
void BufferedTokenStream::release(ssize_t marker) {
|
||||||
// no resources to release
|
// no resources to release
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -67,7 +67,7 @@ void BufferedTokenStream::reset() {
|
||||||
seek(0);
|
seek(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
void BufferedTokenStream::seek(int index) {
|
void BufferedTokenStream::seek(size_t index) {
|
||||||
lazyInit();
|
lazyInit();
|
||||||
p = adjustSeekIndex(index);
|
p = adjustSeekIndex(index);
|
||||||
}
|
}
|
||||||
|
@ -86,24 +86,23 @@ void BufferedTokenStream::consume() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool BufferedTokenStream::sync(int i) {
|
bool BufferedTokenStream::sync(size_t i) {
|
||||||
assert(i >= 0);
|
|
||||||
size_t n = i - tokens.size() + 1; // how many more elements we need?
|
size_t n = i - tokens.size() + 1; // how many more elements we need?
|
||||||
|
|
||||||
if (n > 0) {
|
if (n > 0) {
|
||||||
size_t fetched = fetch((int)n);
|
size_t fetched = fetch(n);
|
||||||
return fetched >= n;
|
return fetched >= n;
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
int BufferedTokenStream::fetch(int n) {
|
size_t BufferedTokenStream::fetch(size_t n) {
|
||||||
if (fetchedEOF) {
|
if (fetchedEOF) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int i = 0; i < n; i++) {
|
for (size_t i = 0; i < n; i++) {
|
||||||
Token *t = tokenSource->nextToken();
|
Token *t = tokenSource->nextToken();
|
||||||
if (dynamic_cast<WritableToken*>(t) != nullptr) {
|
if (dynamic_cast<WritableToken*>(t) != nullptr) {
|
||||||
(static_cast<WritableToken*>(t))->setTokenIndex((int)tokens.size());
|
(static_cast<WritableToken*>(t))->setTokenIndex((int)tokens.size());
|
||||||
|
@ -118,8 +117,8 @@ int BufferedTokenStream::fetch(int n) {
|
||||||
return n;
|
return n;
|
||||||
}
|
}
|
||||||
|
|
||||||
Token *BufferedTokenStream::get(int i) {
|
Token *BufferedTokenStream::get(size_t i) {
|
||||||
if (i < 0 || i >= (int)tokens.size()) {
|
if (i >= tokens.size()) {
|
||||||
throw IndexOutOfBoundsException(std::wstring(L"token index ") +
|
throw IndexOutOfBoundsException(std::wstring(L"token index ") +
|
||||||
std::to_wstring(i) +
|
std::to_wstring(i) +
|
||||||
std::wstring(L" out of range 0..") +
|
std::wstring(L" out of range 0..") +
|
||||||
|
@ -128,16 +127,19 @@ Token *BufferedTokenStream::get(int i) {
|
||||||
return tokens[i];
|
return tokens[i];
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<Token*> BufferedTokenStream::get(int start, int stop) {
|
std::vector<Token*> BufferedTokenStream::get(size_t start, size_t stop) {
|
||||||
if (start < 0 || stop < 0) {
|
std::vector<Token*> subset;
|
||||||
return std::vector<Token*>();
|
|
||||||
}
|
|
||||||
lazyInit();
|
lazyInit();
|
||||||
std::vector<Token*> subset = std::vector<Token*>();
|
|
||||||
if (stop >= (int)tokens.size()) {
|
if (tokens.empty()) {
|
||||||
stop = (int)tokens.size() - 1;
|
return subset;
|
||||||
}
|
}
|
||||||
for (int i = start; i <= stop; i++) {
|
|
||||||
|
if (stop >= tokens.size()) {
|
||||||
|
stop = tokens.size() - 1;
|
||||||
|
}
|
||||||
|
for (size_t i = start; i <= stop; i++) {
|
||||||
Token *t = tokens[i];
|
Token *t = tokens[i];
|
||||||
if (t->getType() == Token::_EOF) {
|
if (t->getType() == Token::_EOF) {
|
||||||
break;
|
break;
|
||||||
|
@ -147,47 +149,48 @@ std::vector<Token*> BufferedTokenStream::get(int start, int stop) {
|
||||||
return subset;
|
return subset;
|
||||||
}
|
}
|
||||||
|
|
||||||
int BufferedTokenStream::LA(int i) {
|
size_t BufferedTokenStream::LA(ssize_t i) {
|
||||||
return LT(i)->getType();
|
return (size_t)LT(i)->getType();
|
||||||
}
|
}
|
||||||
|
|
||||||
Token *BufferedTokenStream::LB(int k) {
|
Token *BufferedTokenStream::LB(size_t k) {
|
||||||
if ((p - k) < 0) {
|
if (k > p) {
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
return tokens[p - k];
|
return tokens[(size_t)(p - k)];
|
||||||
}
|
}
|
||||||
|
|
||||||
Token *BufferedTokenStream::LT(int k) {
|
Token *BufferedTokenStream::LT(ssize_t k) {
|
||||||
lazyInit();
|
lazyInit();
|
||||||
if (k == 0) {
|
if (k == 0) {
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
if (k < 0) {
|
if (k < 0) {
|
||||||
return LB(-k);
|
return LB((size_t)-k);
|
||||||
}
|
}
|
||||||
|
|
||||||
int i = p + k - 1;
|
size_t i = (size_t)((ssize_t)p + k - 1);
|
||||||
sync(i);
|
sync(i);
|
||||||
if (i >= (int)tokens.size()) { // return EOF token
|
if (i >= tokens.size()) { // return EOF token
|
||||||
// EOF must be last token
|
// EOF must be last token
|
||||||
return tokens[tokens.size() - 1];
|
return tokens.back();
|
||||||
}
|
}
|
||||||
// if ( i>range ) range = i;
|
|
||||||
return tokens[i];
|
return tokens[i];
|
||||||
}
|
}
|
||||||
|
|
||||||
int BufferedTokenStream::adjustSeekIndex(int i) {
|
size_t BufferedTokenStream::adjustSeekIndex(size_t i) {
|
||||||
return i;
|
return i;
|
||||||
}
|
}
|
||||||
|
|
||||||
void BufferedTokenStream::lazyInit() {
|
void BufferedTokenStream::lazyInit() {
|
||||||
if (p == -1) {
|
if (_needSetup) {
|
||||||
setup();
|
setup();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void BufferedTokenStream::setup() {
|
void BufferedTokenStream::setup() {
|
||||||
|
_needSetup = false;
|
||||||
sync(0);
|
sync(0);
|
||||||
p = adjustSeekIndex(0);
|
p = adjustSeekIndex(0);
|
||||||
}
|
}
|
||||||
|
@ -195,7 +198,7 @@ void BufferedTokenStream::setup() {
|
||||||
void BufferedTokenStream::setTokenSource(TokenSource *tokenSource) {
|
void BufferedTokenStream::setTokenSource(TokenSource *tokenSource) {
|
||||||
this->tokenSource = tokenSource;
|
this->tokenSource = tokenSource;
|
||||||
tokens.clear();
|
tokens.clear();
|
||||||
p = -1;
|
_needSetup = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<Token*> BufferedTokenStream::getTokens() {
|
std::vector<Token*> BufferedTokenStream::getTokens() {
|
||||||
|
@ -222,7 +225,7 @@ std::vector<Token*> BufferedTokenStream::getTokens(int start, int stop, std::vec
|
||||||
|
|
||||||
// list = tokens[start:stop]:{T t, t.getType() in types}
|
// list = tokens[start:stop]:{T t, t.getType() in types}
|
||||||
std::vector<Token*> filteredTokens = std::vector<Token*>();
|
std::vector<Token*> filteredTokens = std::vector<Token*>();
|
||||||
for (int i = start; i <= stop; i++) {
|
for (size_t i = (size_t)start; i <= (size_t)stop; i++) {
|
||||||
Token *tok = tokens[i];
|
Token *tok = tokens[i];
|
||||||
|
|
||||||
if (types == nullptr) {
|
if (types == nullptr) {
|
||||||
|
@ -245,12 +248,13 @@ std::vector<Token*> BufferedTokenStream::getTokens(int start, int stop, int ttyp
|
||||||
return getTokens(start,stop, s);
|
return getTokens(start,stop, s);
|
||||||
}
|
}
|
||||||
|
|
||||||
int BufferedTokenStream::nextTokenOnChannel(int i, int channel) {
|
ssize_t BufferedTokenStream::nextTokenOnChannel(size_t i, int channel) {
|
||||||
sync(i);
|
sync(i);
|
||||||
Token *token = tokens[i];
|
if (i >= size()) {
|
||||||
if (i >= (int)size()) {
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Token *token = tokens[i];
|
||||||
while (token->getChannel() != channel) {
|
while (token->getChannel() != channel) {
|
||||||
if (token->getType() == Token::_EOF) {
|
if (token->getType() == Token::_EOF) {
|
||||||
return -1;
|
return -1;
|
||||||
|
@ -259,67 +263,71 @@ int BufferedTokenStream::nextTokenOnChannel(int i, int channel) {
|
||||||
sync(i);
|
sync(i);
|
||||||
token = tokens[i];
|
token = tokens[i];
|
||||||
}
|
}
|
||||||
return i;
|
return (ssize_t)i;
|
||||||
}
|
}
|
||||||
|
|
||||||
int BufferedTokenStream::previousTokenOnChannel(int i, int channel) {
|
ssize_t BufferedTokenStream::previousTokenOnChannel(size_t i, int channel) const {
|
||||||
while (i >= 0 && tokens[i]->getChannel() != channel) {
|
do {
|
||||||
|
if (tokens[i]->getChannel() == channel)
|
||||||
|
return (ssize_t)i;
|
||||||
|
if (i == 0)
|
||||||
|
return -1;
|
||||||
i--;
|
i--;
|
||||||
}
|
} while (true);
|
||||||
return i;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<Token*> BufferedTokenStream::getHiddenTokensToRight(int tokenIndex, int channel) {
|
std::vector<Token*> BufferedTokenStream::getHiddenTokensToRight(size_t tokenIndex, int channel) {
|
||||||
lazyInit();
|
lazyInit();
|
||||||
if (tokenIndex < 0 || tokenIndex >= (int)tokens.size()) {
|
if (tokenIndex >= tokens.size()) {
|
||||||
throw new IndexOutOfBoundsException(std::to_wstring(tokenIndex) +
|
throw new IndexOutOfBoundsException(std::to_wstring(tokenIndex) +
|
||||||
std::wstring(L" not in 0..") +
|
std::wstring(L" not in 0..") +
|
||||||
std::to_wstring(tokens.size() - 1));
|
std::to_wstring(tokens.size() - 1));
|
||||||
}
|
}
|
||||||
|
|
||||||
int nextOnChannel = nextTokenOnChannel(tokenIndex + 1, Lexer::DEFAULT_TOKEN_CHANNEL);
|
ssize_t nextOnChannel = nextTokenOnChannel(tokenIndex + 1, Lexer::DEFAULT_TOKEN_CHANNEL);
|
||||||
int to;
|
ssize_t to;
|
||||||
int from = tokenIndex + 1;
|
size_t from = tokenIndex + 1;
|
||||||
// if none onchannel to right, nextOnChannel=-1 so set to = last token
|
// if none onchannel to right, nextOnChannel=-1 so set to = last token
|
||||||
if (nextOnChannel == -1) {
|
if (nextOnChannel == -1) {
|
||||||
to = (int)size() - 1;
|
to = (ssize_t)size() - 1;
|
||||||
} else {
|
} else {
|
||||||
to = nextOnChannel;
|
to = nextOnChannel;
|
||||||
}
|
}
|
||||||
|
|
||||||
return filterForChannel(from, to, channel);
|
return filterForChannel(from, (size_t)to, channel);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<Token*> BufferedTokenStream::getHiddenTokensToRight(int tokenIndex) {
|
std::vector<Token*> BufferedTokenStream::getHiddenTokensToRight(size_t tokenIndex) {
|
||||||
return getHiddenTokensToRight(tokenIndex, -1);
|
return getHiddenTokensToRight(tokenIndex, -1);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<Token*> BufferedTokenStream::getHiddenTokensToLeft(int tokenIndex, int channel) {
|
std::vector<Token*> BufferedTokenStream::getHiddenTokensToLeft(size_t tokenIndex, int channel) {
|
||||||
lazyInit();
|
lazyInit();
|
||||||
if (tokenIndex < 0 || tokenIndex >= (int)tokens.size()) {
|
if (tokenIndex >= tokens.size()) {
|
||||||
throw new IndexOutOfBoundsException(std::to_wstring(tokenIndex) +
|
throw new IndexOutOfBoundsException(std::to_wstring(tokenIndex) +
|
||||||
std::wstring(L" not in 0..") +
|
std::wstring(L" not in 0..") +
|
||||||
std::to_wstring(tokens.size() - 1));
|
std::to_wstring(tokens.size() - 1));
|
||||||
}
|
}
|
||||||
|
|
||||||
int prevOnChannel = previousTokenOnChannel(tokenIndex - 1, Lexer::DEFAULT_TOKEN_CHANNEL);
|
ssize_t prevOnChannel = previousTokenOnChannel(tokenIndex - 1, Lexer::DEFAULT_TOKEN_CHANNEL);
|
||||||
if (prevOnChannel == tokenIndex - 1) {
|
if (prevOnChannel == (ssize_t)tokenIndex - 1) {
|
||||||
return std::vector<Token*>();
|
return std::vector<Token*>();
|
||||||
}
|
}
|
||||||
// if none onchannel to left, prevOnChannel=-1 then from=0
|
// if none onchannel to left, prevOnChannel=-1 then from=0
|
||||||
int from = prevOnChannel + 1;
|
size_t from = (size_t)(prevOnChannel + 1);
|
||||||
int to = tokenIndex - 1;
|
size_t to = tokenIndex - 1;
|
||||||
|
|
||||||
return filterForChannel(from, to, channel);
|
return filterForChannel(from, to, channel);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<Token*> BufferedTokenStream::getHiddenTokensToLeft(int tokenIndex) {
|
std::vector<Token*> BufferedTokenStream::getHiddenTokensToLeft(size_t tokenIndex) {
|
||||||
return getHiddenTokensToLeft(tokenIndex, -1);
|
return getHiddenTokensToLeft(tokenIndex, -1);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<Token*> BufferedTokenStream::filterForChannel(int from, int to, int channel) {
|
std::vector<Token*> BufferedTokenStream::filterForChannel(size_t from, size_t to, int channel) {
|
||||||
std::vector<Token*> hidden = std::vector<Token*>();
|
std::vector<Token*> hidden = std::vector<Token*>();
|
||||||
for (int i = from; i <= to; i++) {
|
for (size_t i = from; i <= to; i++) {
|
||||||
Token *t = tokens[i];
|
Token *t = tokens[i];
|
||||||
if (channel == -1) {
|
if (channel == -1) {
|
||||||
if (t->getChannel() != Lexer::DEFAULT_TOKEN_CHANNEL) {
|
if (t->getChannel() != Lexer::DEFAULT_TOKEN_CHANNEL) {
|
||||||
|
@ -351,9 +359,9 @@ std::wstring BufferedTokenStream::getText() {
|
||||||
return getText(misc::Interval::of(0, (int)size() - 1));
|
return getText(misc::Interval::of(0, (int)size() - 1));
|
||||||
}
|
}
|
||||||
|
|
||||||
std::wstring BufferedTokenStream::getText(misc::Interval *interval) {
|
std::wstring BufferedTokenStream::getText(const misc::Interval &interval) {
|
||||||
int start = interval->a;
|
int start = interval.a;
|
||||||
int stop = interval->b;
|
int stop = interval.b;
|
||||||
if (start < 0 || stop < 0) {
|
if (start < 0 || stop < 0) {
|
||||||
return L"";
|
return L"";
|
||||||
}
|
}
|
||||||
|
@ -363,7 +371,7 @@ std::wstring BufferedTokenStream::getText(misc::Interval *interval) {
|
||||||
}
|
}
|
||||||
|
|
||||||
antlrcpp::StringBuilder *buf = new antlrcpp::StringBuilder();
|
antlrcpp::StringBuilder *buf = new antlrcpp::StringBuilder();
|
||||||
for (int i = start; i <= stop; i++) {
|
for (size_t i = (size_t)start; i <= (size_t)stop; i++) {
|
||||||
Token *t = tokens[i];
|
Token *t = tokens[i];
|
||||||
if (t->getType() == Token::_EOF) {
|
if (t->getType() == Token::_EOF) {
|
||||||
break;
|
break;
|
||||||
|
@ -387,9 +395,9 @@ std::wstring BufferedTokenStream::getText(Token *start, Token *stop) {
|
||||||
|
|
||||||
void BufferedTokenStream::fill() {
|
void BufferedTokenStream::fill() {
|
||||||
lazyInit();
|
lazyInit();
|
||||||
const int blockSize = 1000;
|
const size_t blockSize = 1000;
|
||||||
while (true) {
|
while (true) {
|
||||||
int fetched = fetch(blockSize);
|
size_t fetched = fetch(blockSize);
|
||||||
if (fetched < blockSize) {
|
if (fetched < blockSize) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -398,6 +406,6 @@ void BufferedTokenStream::fill() {
|
||||||
|
|
||||||
void BufferedTokenStream::InitializeInstanceFields() {
|
void BufferedTokenStream::InitializeInstanceFields() {
|
||||||
tokens.reserve(100);
|
tokens.reserve(100);
|
||||||
p = -1;
|
_needSetup = true;
|
||||||
fetchedEOF = false;
|
fetchedEOF = false;
|
||||||
}
|
}
|
||||||
|
|
|
@ -70,7 +70,7 @@ namespace runtime {
|
||||||
/// <seealso cref="#LT LT(1)"/> or whatever gets the first token and sets
|
/// <seealso cref="#LT LT(1)"/> or whatever gets the first token and sets
|
||||||
/// <seealso cref="#p"/>{@code =0;}.
|
/// <seealso cref="#p"/>{@code =0;}.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
int p;
|
size_t p;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Set to {@code true} when the EOF token is fetched. Do not continue fetching
|
/// Set to {@code true} when the EOF token is fetched. Do not continue fetching
|
||||||
|
@ -84,14 +84,14 @@ namespace runtime {
|
||||||
BufferedTokenStream(TokenSource *tokenSource);
|
BufferedTokenStream(TokenSource *tokenSource);
|
||||||
|
|
||||||
virtual TokenSource *getTokenSource() override;
|
virtual TokenSource *getTokenSource() override;
|
||||||
virtual int index() override;
|
virtual size_t index() override;
|
||||||
virtual int mark() override;
|
virtual ssize_t mark() override;
|
||||||
|
|
||||||
virtual void release(int marker) override;
|
virtual void release(ssize_t marker) override;
|
||||||
|
|
||||||
virtual void reset();
|
virtual void reset();
|
||||||
|
|
||||||
virtual void seek(int index) override;
|
virtual void seek(size_t index) override;
|
||||||
|
|
||||||
virtual size_t size() override;
|
virtual size_t size() override;
|
||||||
virtual void consume() override;
|
virtual void consume() override;
|
||||||
|
@ -103,30 +103,30 @@ namespace runtime {
|
||||||
/// {@code false}. </returns>
|
/// {@code false}. </returns>
|
||||||
/// <seealso cref= #get(int i) </seealso>
|
/// <seealso cref= #get(int i) </seealso>
|
||||||
protected:
|
protected:
|
||||||
virtual bool sync(int i);
|
virtual bool sync(size_t i);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Add {@code n} elements to buffer.
|
/// Add {@code n} elements to buffer.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <returns> The actual number of elements added to the buffer. </returns>
|
/// <returns> The actual number of elements added to the buffer. </returns>
|
||||||
virtual int fetch(int n);
|
virtual size_t fetch(size_t n);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
virtual Token *get(int i) override;
|
virtual Token *get(size_t i) override;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Get all tokens from start..stop inclusively </summary>
|
/// Get all tokens from start..stop inclusively </summary>
|
||||||
virtual std::vector<Token*> get(int start, int stop);
|
virtual std::vector<Token*> get(size_t start, size_t stop);
|
||||||
|
|
||||||
virtual int LA(int i) override;
|
virtual size_t LA(ssize_t i) override;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual Token *LB(int k);
|
virtual Token *LB(size_t k);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
virtual Token *LT(int k) override;
|
virtual Token *LT(ssize_t k) override;
|
||||||
|
|
||||||
/// <summary>
|
protected:
|
||||||
/// Allowed derived classes to modify the behavior of operations which change
|
/// Allowed derived classes to modify the behavior of operations which change
|
||||||
/// the current stream position by adjusting the target token index of a seek
|
/// the current stream position by adjusting the target token index of a seek
|
||||||
/// operation. The default implementation simply returns {@code i}. If an
|
/// operation. The default implementation simply returns {@code i}. If an
|
||||||
|
@ -135,23 +135,18 @@ namespace runtime {
|
||||||
/// <p/>
|
/// <p/>
|
||||||
/// For example, <seealso cref="CommonTokenStream"/> overrides this method to ensure that
|
/// For example, <seealso cref="CommonTokenStream"/> overrides this method to ensure that
|
||||||
/// the seek target is always an on-channel token.
|
/// the seek target is always an on-channel token.
|
||||||
/// </summary>
|
///
|
||||||
/// <param name="i"> The target token index. </param>
|
/// <param name="i"> The target token index. </param>
|
||||||
/// <returns> The adjusted target token index. </returns>
|
/// <returns> The adjusted target token index. </returns>
|
||||||
protected:
|
virtual size_t adjustSeekIndex(size_t i);
|
||||||
virtual int adjustSeekIndex(int i);
|
|
||||||
|
|
||||||
void lazyInit();
|
void lazyInit();
|
||||||
|
|
||||||
virtual void setup();
|
virtual void setup();
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Reset this token stream by setting its token source. </summary>
|
/// Reset this token stream by setting its token source. </summary>
|
||||||
public:
|
public:
|
||||||
virtual void setTokenSource(TokenSource *tokenSource);
|
virtual void setTokenSource(TokenSource *tokenSource);
|
||||||
|
|
||||||
virtual std::vector<Token*> getTokens();
|
virtual std::vector<Token*> getTokens();
|
||||||
|
|
||||||
virtual std::vector<Token*> getTokens(int start, int stop);
|
virtual std::vector<Token*> getTokens(int start, int stop);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
@ -163,20 +158,16 @@ namespace runtime {
|
||||||
|
|
||||||
virtual std::vector<Token*> getTokens(int start, int stop, int ttype);
|
virtual std::vector<Token*> getTokens(int start, int stop, int ttype);
|
||||||
|
|
||||||
/// <summary>
|
protected:
|
||||||
/// Given a starting index, return the index of the next token on channel.
|
/// Given a starting index, return the index of the next token on channel.
|
||||||
/// Return i if tokens[i] is on channel. Return -1 if there are no tokens
|
/// Return i if tokens[i] is on channel. Return -1 if there are no tokens
|
||||||
/// on channel between i and EOF.
|
/// on channel between i and EOF.
|
||||||
/// </summary>
|
virtual ssize_t nextTokenOnChannel(size_t i, int channel);
|
||||||
protected:
|
|
||||||
virtual int nextTokenOnChannel(int i, int channel);
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Given a starting index, return the index of the previous token on channel.
|
/// Given a starting index, return the index of the previous token on channel.
|
||||||
/// Return i if tokens[i] is on channel. Return -1 if there are no tokens
|
/// Return i if tokens[i] is on channel. Return -1 if there are no tokens
|
||||||
/// on channel between i and 0.
|
/// on channel between i and 0.
|
||||||
/// </summary>
|
virtual ssize_t previousTokenOnChannel(size_t i, int channel) const;
|
||||||
virtual int previousTokenOnChannel(int i, int channel);
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Collect all tokens on specified channel to the right of
|
/// Collect all tokens on specified channel to the right of
|
||||||
|
@ -184,36 +175,36 @@ namespace runtime {
|
||||||
/// EOF. If channel is -1, find any non default channel token.
|
/// EOF. If channel is -1, find any non default channel token.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public:
|
public:
|
||||||
virtual std::vector<Token*> getHiddenTokensToRight(int tokenIndex, int channel);
|
virtual std::vector<Token*> getHiddenTokensToRight(size_t tokenIndex, int channel);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Collect all hidden tokens (any off-default channel) to the right of
|
/// Collect all hidden tokens (any off-default channel) to the right of
|
||||||
/// the current token up until we see a token on DEFAULT_TOKEN_CHANNEL
|
/// the current token up until we see a token on DEFAULT_TOKEN_CHANNEL
|
||||||
/// of EOF.
|
/// of EOF.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
virtual std::vector<Token*> getHiddenTokensToRight(int tokenIndex);
|
virtual std::vector<Token*> getHiddenTokensToRight(size_t tokenIndex);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Collect all tokens on specified channel to the left of
|
/// Collect all tokens on specified channel to the left of
|
||||||
/// the current token up until we see a token on DEFAULT_TOKEN_CHANNEL.
|
/// the current token up until we see a token on DEFAULT_TOKEN_CHANNEL.
|
||||||
/// If channel is -1, find any non default channel token.
|
/// If channel is -1, find any non default channel token.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
virtual std::vector<Token*> getHiddenTokensToLeft(int tokenIndex, int channel);
|
virtual std::vector<Token*> getHiddenTokensToLeft(size_t tokenIndex, int channel);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Collect all hidden tokens (any off-default channel) to the left of
|
/// Collect all hidden tokens (any off-default channel) to the left of
|
||||||
/// the current token up until we see a token on DEFAULT_TOKEN_CHANNEL.
|
/// the current token up until we see a token on DEFAULT_TOKEN_CHANNEL.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
virtual std::vector<Token*> getHiddenTokensToLeft(int tokenIndex);
|
virtual std::vector<Token*> getHiddenTokensToLeft(size_t tokenIndex);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual std::vector<Token*> filterForChannel(int from, int to, int channel);
|
virtual std::vector<Token*> filterForChannel(size_t from, size_t to, int channel);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
virtual std::string getSourceName() override;
|
virtual std::string getSourceName() override;
|
||||||
virtual std::wstring getText() override;
|
virtual std::wstring getText() override;
|
||||||
|
|
||||||
virtual std::wstring getText(misc::Interval *interval) override;
|
virtual std::wstring getText(const misc::Interval &interval) override;
|
||||||
|
|
||||||
virtual std::wstring getText(RuleContext *ctx) override;
|
virtual std::wstring getText(RuleContext *ctx) override;
|
||||||
|
|
||||||
|
@ -224,6 +215,7 @@ namespace runtime {
|
||||||
virtual void fill();
|
virtual void fill();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
bool _needSetup;
|
||||||
void InitializeInstanceFields();
|
void InitializeInstanceFields();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -40,6 +40,8 @@ namespace runtime {
|
||||||
|
|
||||||
/// A source of characters for an ANTLR lexer.
|
/// A source of characters for an ANTLR lexer.
|
||||||
class CharStream : public IntStream {
|
class CharStream : public IntStream {
|
||||||
|
public:
|
||||||
|
virtual ~CharStream() = 0;
|
||||||
|
|
||||||
/// This method returns the text for a range of characters within this input
|
/// This method returns the text for a range of characters within this input
|
||||||
/// stream. This method is guaranteed to not throw an exception if the
|
/// stream. This method is guaranteed to not throw an exception if the
|
||||||
|
@ -55,10 +57,7 @@ namespace runtime {
|
||||||
/// past the end of the stream </exception>
|
/// past the end of the stream </exception>
|
||||||
/// <exception cref="UnsupportedOperationException"> if the stream does not support
|
/// <exception cref="UnsupportedOperationException"> if the stream does not support
|
||||||
/// getting the text of the specified interval </exception>
|
/// getting the text of the specified interval </exception>
|
||||||
public:
|
virtual std::wstring getText(const misc::Interval &interval) = 0;
|
||||||
virtual std::wstring getText(misc::Interval *interval) = 0;
|
|
||||||
|
|
||||||
virtual ~CharStream() = 0;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace runtime
|
} // namespace runtime
|
||||||
|
|
|
@ -53,7 +53,7 @@ CommonToken::CommonToken(std::pair<TokenSource*, CharStream*> *source, int type,
|
||||||
this->start = start;
|
this->start = start;
|
||||||
this->stop = stop;
|
this->stop = stop;
|
||||||
if (source->first != nullptr) {
|
if (source->first != nullptr) {
|
||||||
this->line = source->first->getLine();
|
this->line = (int)source->first->getLine();
|
||||||
this->charPositionInLine = source->first->getCharPositionInLine();
|
this->charPositionInLine = source->first->getCharPositionInLine();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -43,49 +43,48 @@ CommonTokenStream::CommonTokenStream(TokenSource *tokenSource, int channel) : Bu
|
||||||
this->channel = channel;
|
this->channel = channel;
|
||||||
}
|
}
|
||||||
|
|
||||||
int CommonTokenStream::adjustSeekIndex(int i) {
|
size_t CommonTokenStream::adjustSeekIndex(size_t i) {
|
||||||
return nextTokenOnChannel(i, channel);
|
// XXX ml: that code is questionable. If there is no next token on the given channel we get an invalid stream position (-1).
|
||||||
|
return (size_t)nextTokenOnChannel(i, channel);
|
||||||
}
|
}
|
||||||
|
|
||||||
Token *CommonTokenStream::LB(int k) {
|
Token *CommonTokenStream::LB(size_t k) {
|
||||||
if (k == 0 || (p - k) < 0) {
|
if (k == 0 || k > p) {
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
int i = p;
|
size_t i = p;
|
||||||
int n = 1;
|
size_t n = 1;
|
||||||
// find k good tokens looking backwards
|
// find k good tokens looking backwards
|
||||||
while (n <= k) {
|
while (n <= k) {
|
||||||
// skip off-channel tokens
|
// skip off-channel tokens
|
||||||
i = previousTokenOnChannel(i - 1, channel);
|
// XXX ml: also here, no error handling for -1
|
||||||
|
i = (size_t)previousTokenOnChannel(i - 1, channel);
|
||||||
n++;
|
n++;
|
||||||
}
|
}
|
||||||
if (i < 0) {
|
|
||||||
return nullptr;
|
|
||||||
}
|
|
||||||
return tokens[i];
|
return tokens[i];
|
||||||
}
|
}
|
||||||
|
|
||||||
Token *CommonTokenStream::LT(int k) {
|
Token *CommonTokenStream::LT(ssize_t k) {
|
||||||
//System.out.println("enter LT("+k+")");
|
|
||||||
lazyInit();
|
lazyInit();
|
||||||
if (k == 0) {
|
if (k == 0) {
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
if (k < 0) {
|
if (k < 0) {
|
||||||
return LB(-k);
|
return LB((size_t)-k);
|
||||||
}
|
}
|
||||||
int i = p;
|
size_t i = p;
|
||||||
int n = 1; // we know tokens[p] is a good one
|
size_t n = 1; // we know tokens[p] is a good one
|
||||||
// find k good tokens
|
// find k good tokens
|
||||||
while (n < k) {
|
while (n < (size_t)k) {
|
||||||
// skip off-channel tokens, but make sure to not look past EOF
|
// skip off-channel tokens, but make sure to not look past EOF
|
||||||
if (sync(i + 1)) {
|
if (sync(i + 1)) {
|
||||||
i = nextTokenOnChannel(i + 1, channel);
|
// XXX ml: no error handling either
|
||||||
|
i = (size_t)nextTokenOnChannel(i + 1, channel);
|
||||||
}
|
}
|
||||||
n++;
|
n++;
|
||||||
}
|
}
|
||||||
// if ( i>range ) range = i;
|
|
||||||
return tokens[i];
|
return tokens[i];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -67,12 +67,12 @@ namespace runtime {
|
||||||
CommonTokenStream(TokenSource *tokenSource, int channel);
|
CommonTokenStream(TokenSource *tokenSource, int channel);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual int adjustSeekIndex(int i) override;
|
virtual size_t adjustSeekIndex(size_t i) override;
|
||||||
|
|
||||||
virtual Token *LB(int k) override;
|
virtual Token *LB(size_t k) override;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
virtual Token *LT(int k) override;
|
virtual Token *LT(ssize_t k) override;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Count EOF just once. </summary>
|
/// Count EOF just once. </summary>
|
||||||
|
|
|
@ -93,48 +93,42 @@ void DefaultErrorStrategy::reportError(Parser *recognizer, RecognitionException
|
||||||
}
|
}
|
||||||
|
|
||||||
void DefaultErrorStrategy::recover(Parser *recognizer, RecognitionException *e) {
|
void DefaultErrorStrategy::recover(Parser *recognizer, RecognitionException *e) {
|
||||||
// System.out.println("recover in "+recognizer.getRuleInvocationStack()+
|
if (lastErrorIndex == (int)recognizer->getInputStream()->index() && lastErrorStates != nullptr &&
|
||||||
// " index="+recognizer.getInputStream().index()+
|
lastErrorStates->contains(recognizer->getState())) {
|
||||||
// ", lastErrorIndex="+
|
|
||||||
// lastErrorIndex+
|
|
||||||
// ", states="+lastErrorStates);
|
|
||||||
if (lastErrorIndex == recognizer->getInputStream()->index() && lastErrorStates != nullptr && lastErrorStates->contains(recognizer->getState())) {
|
|
||||||
// uh oh, another error at same token index and previously-visited
|
// uh oh, another error at same token index and previously-visited
|
||||||
// state in ATN; must be a case where LT(1) is in the recovery
|
// state in ATN; must be a case where LT(1) is in the recovery
|
||||||
// token set so nothing got consumed. Consume a single token
|
// token set so nothing got consumed. Consume a single token
|
||||||
// at least to prevent an infinite loop; this is a failsafe.
|
// at least to prevent an infinite loop; this is a failsafe.
|
||||||
// System.err.println("seen error condition before index="+
|
|
||||||
// lastErrorIndex+", states="+lastErrorStates);
|
|
||||||
// System.err.println("FAILSAFE consumes "+recognizer.getTokenNames()[recognizer.getInputStream().LA(1)]);
|
|
||||||
recognizer->consume();
|
recognizer->consume();
|
||||||
}
|
}
|
||||||
lastErrorIndex = recognizer->getInputStream()->index();
|
lastErrorIndex = (int)recognizer->getInputStream()->index();
|
||||||
if (lastErrorStates == nullptr) {
|
if (lastErrorStates == nullptr) {
|
||||||
lastErrorStates = new misc::IntervalSet(0);
|
lastErrorStates = new misc::IntervalSet(0);
|
||||||
}
|
}
|
||||||
lastErrorStates->add(recognizer->getState());
|
lastErrorStates->add(recognizer->getState());
|
||||||
misc::IntervalSet *followSet = getErrorRecoverySet(recognizer);
|
misc::IntervalSet followSet = getErrorRecoverySet(recognizer);
|
||||||
consumeUntil(recognizer, followSet);
|
consumeUntil(recognizer, followSet);
|
||||||
}
|
}
|
||||||
|
|
||||||
void DefaultErrorStrategy::sync(Parser *recognizer) {
|
void DefaultErrorStrategy::sync(Parser *recognizer) {
|
||||||
atn::ATNState *s = recognizer->getInterpreter()->atn.states[recognizer->getState()];
|
atn::ATNState *s = recognizer->getInterpreter()->atn.states[(size_t)recognizer->getState()];
|
||||||
// System.err.println("sync @ "+s.stateNumber+"="+s.getClass().getSimpleName());
|
|
||||||
// If already recovering, don't try to sync
|
// If already recovering, don't try to sync
|
||||||
if (inErrorRecoveryMode(recognizer)) {
|
if (inErrorRecoveryMode(recognizer)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
TokenStream *tokens = recognizer->getInputStream();
|
TokenStream *tokens = recognizer->getInputStream();
|
||||||
int la = tokens->LA(1);
|
size_t la = tokens->LA(1);
|
||||||
|
|
||||||
// try cheaper subset first; might get lucky. seems to shave a wee bit off
|
// try cheaper subset first; might get lucky. seems to shave a wee bit off
|
||||||
if (recognizer->getATN().nextTokens(s)->contains(la) || la == Token::_EOF) {
|
if (recognizer->getATN().nextTokens(s).contains((int)la) || la == Token::_EOF) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Return but don't end recovery. only do that upon valid token match
|
// Return but don't end recovery. only do that upon valid token match
|
||||||
if (recognizer->isExpectedToken(la)) {
|
if (recognizer->isExpectedToken((int)la)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -154,8 +148,8 @@ void DefaultErrorStrategy::sync(Parser *recognizer) {
|
||||||
case atn::ATNState::STAR_LOOP_BACK: {
|
case atn::ATNState::STAR_LOOP_BACK: {
|
||||||
// System.err.println("at loop back: "+s.getClass().getSimpleName());
|
// System.err.println("at loop back: "+s.getClass().getSimpleName());
|
||||||
reportUnwantedToken(recognizer);
|
reportUnwantedToken(recognizer);
|
||||||
misc::IntervalSet *expecting = recognizer->getExpectedTokens();
|
misc::IntervalSet expecting = recognizer->getExpectedTokens();
|
||||||
misc::IntervalSet *whatFollowsLoopIterationOrRule = expecting->Or(getErrorRecoverySet(recognizer));
|
misc::IntervalSet whatFollowsLoopIterationOrRule = expecting.Or(getErrorRecoverySet(recognizer));
|
||||||
consumeUntil(recognizer, whatFollowsLoopIterationOrRule);
|
consumeUntil(recognizer, whatFollowsLoopIterationOrRule);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
@ -183,12 +177,12 @@ void DefaultErrorStrategy::reportNoViableAlternative(Parser *recognizer, NoViabl
|
||||||
}
|
}
|
||||||
|
|
||||||
void DefaultErrorStrategy::reportInputMismatch(Parser *recognizer, InputMismatchException *e) {
|
void DefaultErrorStrategy::reportInputMismatch(Parser *recognizer, InputMismatchException *e) {
|
||||||
std::wstring msg = std::wstring(L"mismatched input ") + getTokenErrorDisplay(e->getOffendingToken()) + std::wstring(L" expecting ") + e->getExpectedTokens()->toString(recognizer->getTokenNames());
|
std::wstring msg = std::wstring(L"mismatched input ") + getTokenErrorDisplay(e->getOffendingToken()) + std::wstring(L" expecting ") + e->getExpectedTokens().toString(recognizer->getTokenNames());
|
||||||
recognizer->notifyErrorListeners(e->getOffendingToken(), msg, e);
|
recognizer->notifyErrorListeners(e->getOffendingToken(), msg, e);
|
||||||
}
|
}
|
||||||
|
|
||||||
void DefaultErrorStrategy::reportFailedPredicate(Parser *recognizer, FailedPredicateException *e) {
|
void DefaultErrorStrategy::reportFailedPredicate(Parser *recognizer, FailedPredicateException *e) {
|
||||||
const std::wstring& ruleName = recognizer->getRuleNames()[recognizer->ctx->getRuleIndex()];
|
const std::wstring& ruleName = recognizer->getRuleNames()[(size_t)recognizer->ctx->getRuleIndex()];
|
||||||
std::wstring msg = std::wstring(L"rule ") + ruleName + std::wstring(L" ") + e->getMessage();
|
std::wstring msg = std::wstring(L"rule ") + ruleName + std::wstring(L" ") + e->getMessage();
|
||||||
recognizer->notifyErrorListeners(e->getOffendingToken(), msg, e);
|
recognizer->notifyErrorListeners(e->getOffendingToken(), msg, e);
|
||||||
}
|
}
|
||||||
|
@ -202,9 +196,9 @@ void DefaultErrorStrategy::reportUnwantedToken(Parser *recognizer) {
|
||||||
|
|
||||||
Token *t = recognizer->getCurrentToken();
|
Token *t = recognizer->getCurrentToken();
|
||||||
std::wstring tokenName = getTokenErrorDisplay(t);
|
std::wstring tokenName = getTokenErrorDisplay(t);
|
||||||
misc::IntervalSet *expecting = getExpectedTokens(recognizer);
|
misc::IntervalSet expecting = getExpectedTokens(recognizer);
|
||||||
|
|
||||||
std::wstring msg = std::wstring(L"extraneous input ") + tokenName + std::wstring(L" expecting ") + expecting->toString(recognizer->getTokenNames());
|
std::wstring msg = std::wstring(L"extraneous input ") + tokenName + std::wstring(L" expecting ") + expecting.toString(recognizer->getTokenNames());
|
||||||
recognizer->notifyErrorListeners(t, msg, nullptr);
|
recognizer->notifyErrorListeners(t, msg, nullptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -216,8 +210,8 @@ void DefaultErrorStrategy::reportMissingToken(Parser *recognizer) {
|
||||||
beginErrorCondition(recognizer);
|
beginErrorCondition(recognizer);
|
||||||
|
|
||||||
Token *t = recognizer->getCurrentToken();
|
Token *t = recognizer->getCurrentToken();
|
||||||
misc::IntervalSet *expecting = getExpectedTokens(recognizer);
|
misc::IntervalSet expecting = getExpectedTokens(recognizer);
|
||||||
std::wstring msg = std::wstring(L"missing ") + expecting->toString(recognizer->getTokenNames()) + std::wstring(L" at ") + getTokenErrorDisplay(t);
|
std::wstring msg = std::wstring(L"missing ") + expecting.toString(recognizer->getTokenNames()) + std::wstring(L" at ") + getTokenErrorDisplay(t);
|
||||||
|
|
||||||
recognizer->notifyErrorListeners(t, msg, nullptr);
|
recognizer->notifyErrorListeners(t, msg, nullptr);
|
||||||
}
|
}
|
||||||
|
@ -242,15 +236,16 @@ Token *DefaultErrorStrategy::recoverInline(Parser *recognizer) {
|
||||||
}
|
}
|
||||||
|
|
||||||
bool DefaultErrorStrategy::singleTokenInsertion(Parser *recognizer) {
|
bool DefaultErrorStrategy::singleTokenInsertion(Parser *recognizer) {
|
||||||
int currentSymbolType = recognizer->getInputStream()->LA(1);
|
size_t currentSymbolType = recognizer->getInputStream()->LA(1);
|
||||||
|
|
||||||
// if current token is consistent with what could come after current
|
// if current token is consistent with what could come after current
|
||||||
// ATN state, then we know we're missing a token; error recovery
|
// ATN state, then we know we're missing a token; error recovery
|
||||||
// is free to conjure up and insert the missing token
|
// is free to conjure up and insert the missing token
|
||||||
atn::ATNState *currentState = recognizer->getInterpreter()->atn.states[recognizer->getState()];
|
atn::ATNState *currentState = recognizer->getInterpreter()->atn.states[(size_t)recognizer->getState()];
|
||||||
atn::ATNState *next = currentState->transition(0)->target;
|
atn::ATNState *next = currentState->transition(0)->target;
|
||||||
const atn::ATN &atn = recognizer->getInterpreter()->atn;
|
const atn::ATN &atn = recognizer->getInterpreter()->atn;
|
||||||
misc::IntervalSet *expectingAtLL2 = atn.nextTokens(next, recognizer->ctx);
|
misc::IntervalSet expectingAtLL2 = atn.nextTokens(next, recognizer->ctx);
|
||||||
if (expectingAtLL2->contains(currentSymbolType)) {
|
if (expectingAtLL2.contains((int)currentSymbolType)) {
|
||||||
reportMissingToken(recognizer);
|
reportMissingToken(recognizer);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -258,16 +253,10 @@ bool DefaultErrorStrategy::singleTokenInsertion(Parser *recognizer) {
|
||||||
}
|
}
|
||||||
|
|
||||||
Token *DefaultErrorStrategy::singleTokenDeletion(Parser *recognizer) {
|
Token *DefaultErrorStrategy::singleTokenDeletion(Parser *recognizer) {
|
||||||
int nextTokenType = recognizer->getInputStream()->LA(2);
|
size_t nextTokenType = recognizer->getInputStream()->LA(2);
|
||||||
misc::IntervalSet *expecting = getExpectedTokens(recognizer);
|
misc::IntervalSet expecting = getExpectedTokens(recognizer);
|
||||||
if (expecting->contains(nextTokenType)) {
|
if (expecting.contains((int)nextTokenType)) {
|
||||||
reportUnwantedToken(recognizer);
|
reportUnwantedToken(recognizer);
|
||||||
/*
|
|
||||||
System.err.println("recoverFromMismatchedToken deleting "+
|
|
||||||
((TokenStream)recognizer.getInputStream()).LT(1)+
|
|
||||||
" since "+((TokenStream)recognizer.getInputStream()).LT(2)+
|
|
||||||
" is what we want");
|
|
||||||
*/
|
|
||||||
recognizer->consume(); // simply delete extra token
|
recognizer->consume(); // simply delete extra token
|
||||||
// we want to return the token we're actually matching
|
// we want to return the token we're actually matching
|
||||||
Token *matchedSymbol = recognizer->getCurrentToken();
|
Token *matchedSymbol = recognizer->getCurrentToken();
|
||||||
|
@ -279,23 +268,25 @@ Token *DefaultErrorStrategy::singleTokenDeletion(Parser *recognizer) {
|
||||||
|
|
||||||
Token *DefaultErrorStrategy::getMissingSymbol(Parser *recognizer) {
|
Token *DefaultErrorStrategy::getMissingSymbol(Parser *recognizer) {
|
||||||
Token *currentSymbol = recognizer->getCurrentToken();
|
Token *currentSymbol = recognizer->getCurrentToken();
|
||||||
misc::IntervalSet *expecting = getExpectedTokens(recognizer);
|
misc::IntervalSet expecting = getExpectedTokens(recognizer);
|
||||||
int expectedTokenType = expecting->getMinElement(); // get any element
|
size_t expectedTokenType = (size_t)expecting.getMinElement(); // get any element
|
||||||
std::wstring tokenText;
|
std::wstring tokenText;
|
||||||
if (expectedTokenType == Token::_EOF) {
|
if (expectedTokenType == Token::_EOF) {
|
||||||
tokenText = L"<missing EOF>";
|
tokenText = L"<missing EOF>";
|
||||||
} else {
|
} else {
|
||||||
tokenText = std::wstring(L"<missing ") + recognizer->getTokenNames()[expectedTokenType].at(expectedTokenType) + std::wstring(L">");
|
tokenText = std::wstring(L"<missing ") + recognizer->getTokenNames()[expectedTokenType][expectedTokenType] + std::wstring(L">");
|
||||||
}
|
}
|
||||||
Token *current = currentSymbol;
|
Token *current = currentSymbol;
|
||||||
Token *lookback = recognizer->getInputStream()->LT(-1);
|
Token *lookback = recognizer->getInputStream()->LT(-1);
|
||||||
if (current->getType() == Token::_EOF && lookback != nullptr) {
|
if (current->getType() == Token::_EOF && lookback != nullptr) {
|
||||||
current = lookback;
|
current = lookback;
|
||||||
}
|
}
|
||||||
return (Token*)recognizer->getTokenFactory()->create(new std::pair<TokenSource*, CharStream*>(current->getTokenSource(), current->getTokenSource()->getInputStream()), expectedTokenType, tokenText, Token::DEFAULT_CHANNEL, -1, -1, current->getLine(), current->getCharPositionInLine());
|
return (Token*)recognizer->getTokenFactory()->create(new std::pair<TokenSource*, CharStream*>(current->getTokenSource(),
|
||||||
|
current->getTokenSource()->getInputStream()), (int)expectedTokenType, tokenText, Token::DEFAULT_CHANNEL, -1, -1,
|
||||||
|
current->getLine(), current->getCharPositionInLine());
|
||||||
}
|
}
|
||||||
|
|
||||||
misc::IntervalSet *DefaultErrorStrategy::getExpectedTokens(Parser *recognizer) {
|
misc::IntervalSet DefaultErrorStrategy::getExpectedTokens(Parser *recognizer) {
|
||||||
return recognizer->getExpectedTokens();
|
return recognizer->getExpectedTokens();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -330,26 +321,26 @@ std::wstring DefaultErrorStrategy::escapeWSAndQuote(std::wstring &s) {
|
||||||
return std::wstring(L"'") + s + std::wstring(L"'");
|
return std::wstring(L"'") + s + std::wstring(L"'");
|
||||||
}
|
}
|
||||||
|
|
||||||
misc::IntervalSet *DefaultErrorStrategy::getErrorRecoverySet(Parser *recognizer) {
|
misc::IntervalSet DefaultErrorStrategy::getErrorRecoverySet(Parser *recognizer) {
|
||||||
const atn::ATN &atn = recognizer->getInterpreter()->atn;
|
const atn::ATN &atn = recognizer->getInterpreter()->atn;
|
||||||
RuleContext *ctx = recognizer->ctx;
|
RuleContext *ctx = recognizer->ctx;
|
||||||
misc::IntervalSet *recoverSet = new misc::IntervalSet(0);
|
misc::IntervalSet recoverSet;
|
||||||
while (ctx != nullptr && ctx->invokingState >= 0) {
|
while (ctx != nullptr && ctx->invokingState >= 0) {
|
||||||
// compute what follows who invoked us
|
// compute what follows who invoked us
|
||||||
atn::ATNState *invokingState = atn.states[ctx->invokingState];
|
atn::ATNState *invokingState = atn.states[(size_t)ctx->invokingState];
|
||||||
atn::RuleTransition *rt = dynamic_cast<atn::RuleTransition*>(invokingState->transition(0));
|
atn::RuleTransition *rt = dynamic_cast<atn::RuleTransition*>(invokingState->transition(0));
|
||||||
misc::IntervalSet *follow = atn.nextTokens(rt->followState);
|
misc::IntervalSet follow = atn.nextTokens(rt->followState);
|
||||||
recoverSet->addAll(follow);
|
recoverSet.addAll(follow);
|
||||||
ctx = ctx->parent;
|
ctx = ctx->parent;
|
||||||
}
|
}
|
||||||
recoverSet->remove(Token::EPSILON);
|
recoverSet.remove(Token::EPSILON);
|
||||||
// System.out.println("recover set "+recoverSet.toString(recognizer.getTokenNames()));
|
|
||||||
return recoverSet;
|
return recoverSet;
|
||||||
}
|
}
|
||||||
|
|
||||||
void DefaultErrorStrategy::consumeUntil(Parser *recognizer, misc::IntervalSet *set) {
|
void DefaultErrorStrategy::consumeUntil(Parser *recognizer, const misc::IntervalSet &set) {
|
||||||
int ttype = recognizer->getInputStream()->LA(1);
|
size_t ttype = recognizer->getInputStream()->LA(1);
|
||||||
while (ttype != Token::_EOF && !set->contains(ttype)) {
|
while (ttype != Token::_EOF && !set.contains((int)ttype)) {
|
||||||
recognizer->consume();
|
recognizer->consume();
|
||||||
ttype = recognizer->getInputStream()->LA(1);
|
ttype = recognizer->getInputStream()->LA(1);
|
||||||
}
|
}
|
||||||
|
|
|
@ -32,6 +32,7 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "ANTLRErrorStrategy.h"
|
#include "ANTLRErrorStrategy.h"
|
||||||
|
#include "IntervalSet.h"
|
||||||
|
|
||||||
namespace org {
|
namespace org {
|
||||||
namespace antlr {
|
namespace antlr {
|
||||||
|
@ -367,7 +368,7 @@ namespace runtime {
|
||||||
/// </summary>
|
/// </summary>
|
||||||
virtual Token *getMissingSymbol(Parser *recognizer);
|
virtual Token *getMissingSymbol(Parser *recognizer);
|
||||||
|
|
||||||
virtual misc::IntervalSet *getExpectedTokens(Parser *recognizer);
|
virtual misc::IntervalSet getExpectedTokens(Parser *recognizer);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// How should a token be displayed in an error message? The default
|
/// How should a token be displayed in an error message? The default
|
||||||
|
@ -478,11 +479,11 @@ namespace runtime {
|
||||||
* Like Grosch I implement context-sensitive FOLLOW sets that are combined
|
* Like Grosch I implement context-sensitive FOLLOW sets that are combined
|
||||||
* at run-time upon error to avoid overhead during parsing.
|
* at run-time upon error to avoid overhead during parsing.
|
||||||
*/
|
*/
|
||||||
virtual misc::IntervalSet *getErrorRecoverySet(Parser *recognizer);
|
virtual misc::IntervalSet getErrorRecoverySet(Parser *recognizer);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Consume tokens until one matches the given token set. </summary>
|
/// Consume tokens until one matches the given token set. </summary>
|
||||||
virtual void consumeUntil(Parser *recognizer, misc::IntervalSet *set);
|
virtual void consumeUntil(Parser *recognizer, const misc::IntervalSet &set);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void InitializeInstanceFields();
|
void InitializeInstanceFields();
|
||||||
|
|
|
@ -48,29 +48,32 @@ DiagnosticErrorListener::DiagnosticErrorListener() : exactOnly(true) {
|
||||||
DiagnosticErrorListener::DiagnosticErrorListener(bool exactOnly) : exactOnly(exactOnly) {
|
DiagnosticErrorListener::DiagnosticErrorListener(bool exactOnly) : exactOnly(exactOnly) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void DiagnosticErrorListener::reportAmbiguity(Parser *recognizer, dfa::DFA *dfa, int startIndex, int stopIndex, bool exact, antlrcpp::BitSet *ambigAlts, atn::ATNConfigSet *configs) {
|
void DiagnosticErrorListener::reportAmbiguity(Parser *recognizer, dfa::DFA *dfa, size_t startIndex, size_t stopIndex,
|
||||||
|
bool exact, antlrcpp::BitSet *ambigAlts, atn::ATNConfigSet *configs) {
|
||||||
if (exactOnly && !exact) {
|
if (exactOnly && !exact) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
wchar_t buf[16];
|
wchar_t buf[16];
|
||||||
std::wstring decision = getDecisionDescription(recognizer, dfa);
|
std::wstring decision = getDecisionDescription(recognizer, dfa);
|
||||||
antlrcpp::BitSet *conflictingAlts = getConflictingAlts(ambigAlts, configs);
|
antlrcpp::BitSet *conflictingAlts = getConflictingAlts(ambigAlts, configs);
|
||||||
std::wstring text = recognizer->getTokenStream()->getText(misc::Interval::of(startIndex, stopIndex));
|
std::wstring text = recognizer->getTokenStream()->getText(misc::Interval::of((int)startIndex, (int)stopIndex));
|
||||||
std::wstring message = L"reportAmbiguity d=" + decision + L": ambigAlts=" + conflictingAlts->toString() + L", input='" + text + L"'";
|
std::wstring message = L"reportAmbiguity d=" + decision + L": ambigAlts=" + conflictingAlts->toString() + L", input='" + text + L"'";
|
||||||
swprintf(buf, sizeof(buf) / sizeof(*buf), L"%d", 5);
|
swprintf(buf, sizeof(buf) / sizeof(*buf), L"%d", 5);
|
||||||
recognizer->notifyErrorListeners(message);
|
recognizer->notifyErrorListeners(message);
|
||||||
}
|
}
|
||||||
|
|
||||||
void DiagnosticErrorListener::reportAttemptingFullContext(Parser *recognizer, dfa::DFA *dfa, int startIndex, int stopIndex, antlrcpp::BitSet *conflictingAlts, atn::ATNConfigSet *configs) {
|
void DiagnosticErrorListener::reportAttemptingFullContext(Parser *recognizer, dfa::DFA *dfa, size_t startIndex,
|
||||||
|
size_t stopIndex, antlrcpp::BitSet *conflictingAlts, atn::ATNConfigSet *configs) {
|
||||||
std::wstring decision = getDecisionDescription(recognizer, dfa);
|
std::wstring decision = getDecisionDescription(recognizer, dfa);
|
||||||
std::wstring text = recognizer->getTokenStream()->getText(misc::Interval::of(startIndex, stopIndex));
|
std::wstring text = recognizer->getTokenStream()->getText(misc::Interval::of((int)startIndex, (int)stopIndex));
|
||||||
std::wstring message = L"reportAttemptingFullContext d=" + decision + L", input='" + text + L"'";
|
std::wstring message = L"reportAttemptingFullContext d=" + decision + L", input='" + text + L"'";
|
||||||
recognizer->notifyErrorListeners(message);
|
recognizer->notifyErrorListeners(message);
|
||||||
}
|
}
|
||||||
|
|
||||||
void DiagnosticErrorListener::reportContextSensitivity(Parser *recognizer, dfa::DFA *dfa, int startIndex, int stopIndex, int prediction, atn::ATNConfigSet *configs) {
|
void DiagnosticErrorListener::reportContextSensitivity(Parser *recognizer, dfa::DFA *dfa, size_t startIndex,
|
||||||
|
size_t stopIndex, int prediction, atn::ATNConfigSet *configs) {
|
||||||
std::wstring decision = getDecisionDescription(recognizer, dfa);
|
std::wstring decision = getDecisionDescription(recognizer, dfa);
|
||||||
std::wstring text = recognizer->getTokenStream()->getText(misc::Interval::of(startIndex, stopIndex));
|
std::wstring text = recognizer->getTokenStream()->getText(misc::Interval::of((int)startIndex, (int)stopIndex));
|
||||||
std::wstring message = L"reportContextSensitivity d=" + decision + L", input='" + text + L"'";
|
std::wstring message = L"reportContextSensitivity d=" + decision + L", input='" + text + L"'";
|
||||||
recognizer->notifyErrorListeners(message);
|
recognizer->notifyErrorListeners(message);
|
||||||
}
|
}
|
||||||
|
@ -84,7 +87,7 @@ std::wstring DiagnosticErrorListener::getDecisionDescription(Parser *recognizer,
|
||||||
return antlrcpp::StringConverterHelper::toString(decision);
|
return antlrcpp::StringConverterHelper::toString(decision);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::wstring ruleName = ruleNames[ruleIndex];
|
std::wstring ruleName = ruleNames[(size_t)ruleIndex];
|
||||||
if (ruleName == L"" || ruleName.empty()) {
|
if (ruleName == L"" || ruleName.empty()) {
|
||||||
return antlrcpp::StringConverterHelper::toString(decision);
|
return antlrcpp::StringConverterHelper::toString(decision);
|
||||||
}
|
}
|
||||||
|
@ -99,8 +102,8 @@ antlrcpp::BitSet *DiagnosticErrorListener::getConflictingAlts(antlrcpp::BitSet *
|
||||||
|
|
||||||
antlrcpp::BitSet *result = new antlrcpp::BitSet();
|
antlrcpp::BitSet *result = new antlrcpp::BitSet();
|
||||||
for (size_t i = 0; i < configs->size(); i++) {
|
for (size_t i = 0; i < configs->size(); i++) {
|
||||||
atn::ATNConfig *config = configs->get((int)i);
|
atn::ATNConfig *config = configs->get(i);
|
||||||
result->set(config->alt);
|
result->set((size_t)config->alt);
|
||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
|
|
|
@ -81,11 +81,14 @@ namespace runtime {
|
||||||
/// {@code false} to report all ambiguities. </param>
|
/// {@code false} to report all ambiguities. </param>
|
||||||
DiagnosticErrorListener(bool exactOnly);
|
DiagnosticErrorListener(bool exactOnly);
|
||||||
|
|
||||||
virtual void reportAmbiguity(Parser *recognizer, dfa::DFA *dfa, int startIndex, int stopIndex, bool exact, antlrcpp::BitSet *ambigAlts, atn::ATNConfigSet *configs) override;
|
virtual void reportAmbiguity(Parser *recognizer, dfa::DFA *dfa, size_t startIndex, size_t stopIndex, bool exact,
|
||||||
|
antlrcpp::BitSet *ambigAlts, atn::ATNConfigSet *configs) override;
|
||||||
|
|
||||||
virtual void reportAttemptingFullContext(Parser *recognizer, dfa::DFA *dfa, int startIndex, int stopIndex, antlrcpp::BitSet *conflictingAlts, atn::ATNConfigSet *configs) override;
|
virtual void reportAttemptingFullContext(Parser *recognizer, dfa::DFA *dfa, size_t startIndex, size_t stopIndex,
|
||||||
|
antlrcpp::BitSet *conflictingAlts, atn::ATNConfigSet *configs) override;
|
||||||
|
|
||||||
virtual void reportContextSensitivity(Parser *recognizer, dfa::DFA *dfa, int startIndex, int stopIndex, int prediction, atn::ATNConfigSet *configs) override;
|
virtual void reportContextSensitivity(Parser *recognizer, dfa::DFA *dfa, size_t startIndex, size_t stopIndex,
|
||||||
|
int prediction, atn::ATNConfigSet *configs) override;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual std::wstring getDecisionDescription(Parser *recognizer, dfa::DFA *dfa);
|
virtual std::wstring getDecisionDescription(Parser *recognizer, dfa::DFA *dfa);
|
||||||
|
|
|
@ -44,7 +44,7 @@ namespace runtime {
|
||||||
ANTLRException(const std::wstring msg) {
|
ANTLRException(const std::wstring msg) {
|
||||||
this->errormsg = msg;
|
this->errormsg = msg;
|
||||||
}
|
}
|
||||||
std::wstring getMessage() {
|
std::wstring getMessage() const {
|
||||||
return errormsg;
|
return errormsg;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -52,7 +52,7 @@ FailedPredicateException::FailedPredicateException(Parser *recognizer, const std
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
{
|
{
|
||||||
atn::ATNState *s = recognizer->getInterpreter()->atn.states[recognizer->getState()];
|
atn::ATNState *s = recognizer->getInterpreter()->atn.states[(size_t)recognizer->getState()];
|
||||||
|
|
||||||
atn::AbstractPredicateTransition *trans = static_cast<atn::AbstractPredicateTransition*>(s->transition(0));
|
atn::AbstractPredicateTransition *trans = static_cast<atn::AbstractPredicateTransition*>(s->transition(0));
|
||||||
if (dynamic_cast<atn::PredicateTransition*>(trans) != nullptr) {
|
if (dynamic_cast<atn::PredicateTransition*>(trans) != nullptr) {
|
||||||
|
|
|
@ -59,7 +59,7 @@ namespace runtime {
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public:
|
public:
|
||||||
// EOF Conflict with OS X, change to _EOF
|
// EOF Conflict with OS X, change to _EOF
|
||||||
static const int _EOF = std::ios::eofbit;
|
static const size_t _EOF = std::ios::eofbit;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The value returned by <seealso cref="#getSourceName"/> when the actual name of the
|
/// The value returned by <seealso cref="#getSourceName"/> when the actual name of the
|
||||||
|
@ -123,7 +123,7 @@ namespace runtime {
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <exception cref="UnsupportedOperationException"> if the stream does not support
|
/// <exception cref="UnsupportedOperationException"> if the stream does not support
|
||||||
/// retrieving the value of the specified symbol </exception>
|
/// retrieving the value of the specified symbol </exception>
|
||||||
virtual int LA(int i) = 0;
|
virtual size_t LA(ssize_t i) = 0;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// A mark provides a guarantee that <seealso cref="#seek seek()"/> operations will be
|
/// A mark provides a guarantee that <seealso cref="#seek seek()"/> operations will be
|
||||||
|
@ -170,7 +170,7 @@ namespace runtime {
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <returns> An opaque marker which should be passed to
|
/// <returns> An opaque marker which should be passed to
|
||||||
/// <seealso cref="#release release()"/> when the marked range is no longer required. </returns>
|
/// <seealso cref="#release release()"/> when the marked range is no longer required. </returns>
|
||||||
virtual int mark() = 0;
|
virtual ssize_t mark() = 0;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// This method releases a marked range created by a call to
|
/// This method releases a marked range created by a call to
|
||||||
|
@ -183,7 +183,7 @@ namespace runtime {
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="marker"> A marker returned by a call to {@code mark()}. </param>
|
/// <param name="marker"> A marker returned by a call to {@code mark()}. </param>
|
||||||
/// <seealso cref= #mark </seealso>
|
/// <seealso cref= #mark </seealso>
|
||||||
virtual void release(int marker) = 0;
|
virtual void release(ssize_t marker) = 0;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Return the index into the stream of the input symbol referred to by
|
/// Return the index into the stream of the input symbol referred to by
|
||||||
|
@ -193,7 +193,7 @@ namespace runtime {
|
||||||
/// <seealso cref="IntStream initializing method"/> has occurred after this stream was
|
/// <seealso cref="IntStream initializing method"/> has occurred after this stream was
|
||||||
/// constructed.
|
/// constructed.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
virtual int index() = 0;
|
virtual size_t index() = 0;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Set the input cursor to the position indicated by {@code index}. If the
|
/// Set the input cursor to the position indicated by {@code index}. If the
|
||||||
|
@ -222,7 +222,7 @@ namespace runtime {
|
||||||
/// <exception cref="IllegalArgumentException"> if {@code index} is less than 0 </exception>
|
/// <exception cref="IllegalArgumentException"> if {@code index} is less than 0 </exception>
|
||||||
/// <exception cref="UnsupportedOperationException"> if the stream does not support
|
/// <exception cref="UnsupportedOperationException"> if the stream does not support
|
||||||
/// seeking to the specified index </exception>
|
/// seeking to the specified index </exception>
|
||||||
virtual void seek(int index) = 0;
|
virtual void seek(size_t index) = 0;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Returns the total number of symbols in the stream, including a single EOF
|
/// Returns the total number of symbols in the stream, including a single EOF
|
||||||
|
|
|
@ -33,10 +33,10 @@
|
||||||
|
|
||||||
using namespace org::antlr::v4::runtime;
|
using namespace org::antlr::v4::runtime;
|
||||||
|
|
||||||
InterpreterRuleContext::InterpreterRuleContext(ParserRuleContext *parent, int invokingStateNumber, int ruleIndex)
|
InterpreterRuleContext::InterpreterRuleContext(ParserRuleContext *parent, int invokingStateNumber, ssize_t ruleIndex)
|
||||||
: ParserRuleContext(parent, invokingStateNumber), ruleIndex(ruleIndex) {
|
: ParserRuleContext(parent, invokingStateNumber), ruleIndex(ruleIndex) {
|
||||||
}
|
}
|
||||||
|
|
||||||
int InterpreterRuleContext::getRuleIndex() {
|
ssize_t InterpreterRuleContext::getRuleIndex() const {
|
||||||
return ruleIndex;
|
return ruleIndex;
|
||||||
}
|
}
|
||||||
|
|
|
@ -45,12 +45,12 @@ namespace runtime {
|
||||||
/// </summary>
|
/// </summary>
|
||||||
class InterpreterRuleContext : public ParserRuleContext {
|
class InterpreterRuleContext : public ParserRuleContext {
|
||||||
private:
|
private:
|
||||||
const int ruleIndex;
|
const ssize_t ruleIndex;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
InterpreterRuleContext(ParserRuleContext *parent, int invokingStateNumber, int ruleIndex);
|
InterpreterRuleContext(ParserRuleContext *parent, int invokingStateNumber, ssize_t ruleIndex);
|
||||||
|
|
||||||
virtual int getRuleIndex() override;
|
virtual ssize_t getRuleIndex() const override;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace runtime
|
} // namespace runtime
|
||||||
|
|
|
@ -78,7 +78,7 @@ Token *Lexer::nextToken() {
|
||||||
|
|
||||||
// Mark start location in char stream so unbuffered streams are
|
// Mark start location in char stream so unbuffered streams are
|
||||||
// guaranteed at least have text of current token
|
// guaranteed at least have text of current token
|
||||||
int tokenStartMarker = _input->mark();
|
ssize_t tokenStartMarker = _input->mark();
|
||||||
try {
|
try {
|
||||||
while (true) {
|
while (true) {
|
||||||
outerContinue:
|
outerContinue:
|
||||||
|
@ -89,9 +89,9 @@ Token *Lexer::nextToken() {
|
||||||
|
|
||||||
delete _token;
|
delete _token;
|
||||||
_channel = Token::DEFAULT_CHANNEL;
|
_channel = Token::DEFAULT_CHANNEL;
|
||||||
_tokenStartCharIndex = _input->index();
|
_tokenStartCharIndex = (int)_input->index();
|
||||||
_tokenStartCharPositionInLine = getInterpreter()->getCharPositionInLine();
|
_tokenStartCharPositionInLine = getInterpreter()->getCharPositionInLine();
|
||||||
_tokenStartLine = getInterpreter()->getLine();
|
_tokenStartLine = (int)getInterpreter()->getLine();
|
||||||
_text = L"";
|
_text = L"";
|
||||||
do {
|
do {
|
||||||
_type = Token::INVALID_TYPE;
|
_type = Token::INVALID_TYPE;
|
||||||
|
@ -100,7 +100,7 @@ Token *Lexer::nextToken() {
|
||||||
// " at index "+input.index());
|
// " at index "+input.index());
|
||||||
int ttype;
|
int ttype;
|
||||||
try {
|
try {
|
||||||
ttype = getInterpreter()->match(_input, _mode);
|
ttype = getInterpreter()->match(_input, (size_t)_mode);
|
||||||
} catch (LexerNoViableAltException *e) {
|
} catch (LexerNoViableAltException *e) {
|
||||||
notifyListeners(e); // report error
|
notifyListeners(e); // report error
|
||||||
recover(e);
|
recover(e);
|
||||||
|
@ -207,12 +207,13 @@ Token *Lexer::emitEOF() {
|
||||||
int n = _token->getStopIndex() - _token->getStartIndex() + 1;
|
int n = _token->getStopIndex() - _token->getStartIndex() + 1;
|
||||||
cpos = _token->getCharPositionInLine() + n;
|
cpos = _token->getCharPositionInLine() + n;
|
||||||
}
|
}
|
||||||
Token *eof = (Token*)_factory->create(_tokenFactorySourcePair, Token::_EOF, L"", Token::DEFAULT_CHANNEL, _input->index(), _input->index() - 1, getLine(), cpos);
|
Token *eof = (Token*)_factory->create(_tokenFactorySourcePair, Token::_EOF, L"", Token::DEFAULT_CHANNEL,
|
||||||
|
(int)_input->index(), (int)_input->index() - 1, (int)getLine(), cpos);
|
||||||
emit(eof);
|
emit(eof);
|
||||||
return eof;
|
return eof;
|
||||||
}
|
}
|
||||||
|
|
||||||
int Lexer::getLine() {
|
size_t Lexer::getLine() const {
|
||||||
return getInterpreter()->getLine();
|
return getInterpreter()->getLine();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -220,7 +221,7 @@ int Lexer::getCharPositionInLine() {
|
||||||
return getInterpreter()->getCharPositionInLine();
|
return getInterpreter()->getCharPositionInLine();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Lexer::setLine(int line) {
|
void Lexer::setLine(size_t line) {
|
||||||
getInterpreter()->setLine(line);
|
getInterpreter()->setLine(line);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -229,7 +230,7 @@ void Lexer::setCharPositionInLine(int charPositionInLine) {
|
||||||
}
|
}
|
||||||
|
|
||||||
int Lexer::getCharIndex() {
|
int Lexer::getCharIndex() {
|
||||||
return _input->index();
|
return (int)_input->index();
|
||||||
}
|
}
|
||||||
|
|
||||||
std::wstring Lexer::getText() {
|
std::wstring Lexer::getText() {
|
||||||
|
@ -285,11 +286,11 @@ void Lexer::recover(LexerNoViableAltException *e) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void Lexer::notifyListeners(LexerNoViableAltException *e) {
|
void Lexer::notifyListeners(LexerNoViableAltException *e) {
|
||||||
std::wstring text = _input->getText(misc::Interval::of(_tokenStartCharIndex, _input->index()));
|
std::wstring text = _input->getText(misc::Interval::of(_tokenStartCharIndex, (int)_input->index()));
|
||||||
std::wstring msg = std::wstring(L"token recognition error at: '") + getErrorDisplay(text) + std::wstring(L"'");
|
std::wstring msg = std::wstring(L"token recognition error at: '") + getErrorDisplay(text) + std::wstring(L"'");
|
||||||
|
|
||||||
ANTLRErrorListener *listener = getErrorListenerDispatch();
|
ANTLRErrorListener *listener = getErrorListenerDispatch();
|
||||||
listener->syntaxError(this, nullptr, _tokenStartLine, _tokenStartCharPositionInLine, msg, e);
|
listener->syntaxError(this, nullptr, (size_t)_tokenStartLine, _tokenStartCharPositionInLine, msg, e);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::wstring Lexer::getErrorDisplay(const std::wstring &s) {
|
std::wstring Lexer::getErrorDisplay(const std::wstring &s) {
|
||||||
|
|
|
@ -179,11 +179,11 @@ namespace runtime {
|
||||||
|
|
||||||
virtual Token *emitEOF();
|
virtual Token *emitEOF();
|
||||||
|
|
||||||
virtual int getLine() override;
|
virtual size_t getLine() const override;
|
||||||
|
|
||||||
virtual int getCharPositionInLine() override;
|
virtual int getCharPositionInLine() override;
|
||||||
|
|
||||||
virtual void setLine(int line);
|
virtual void setLine(size_t line);
|
||||||
|
|
||||||
virtual void setCharPositionInLine(int charPositionInLine);
|
virtual void setCharPositionInLine(int charPositionInLine);
|
||||||
|
|
||||||
|
|
|
@ -47,7 +47,7 @@ LexerInterpreter::LexerInterpreter(const std::wstring &grammarFileName, std::vec
|
||||||
|
|
||||||
|
|
||||||
for (int i = 0; i < (int)_decisionToDFA.size(); i++) {
|
for (int i = 0; i < (int)_decisionToDFA.size(); i++) {
|
||||||
_decisionToDFA[i] = new dfa::DFA(_atn.getDecisionState(i), i);
|
_decisionToDFA[(size_t)i] = new dfa::DFA(_atn.getDecisionState(i), i);
|
||||||
}
|
}
|
||||||
_interpreter = new atn::LexerATNSimulator(_atn, _decisionToDFA, _sharedContextCache);
|
_interpreter = new atn::LexerATNSimulator(_atn, _decisionToDFA, _sharedContextCache);
|
||||||
if (tokenNames) {
|
if (tokenNames) {
|
||||||
|
|
|
@ -37,10 +37,10 @@
|
||||||
|
|
||||||
using namespace org::antlr::v4::runtime;
|
using namespace org::antlr::v4::runtime;
|
||||||
|
|
||||||
LexerNoViableAltException::LexerNoViableAltException(Lexer *lexer, CharStream *input, int startIndex, atn::ATNConfigSet *deadEndConfigs) : RecognitionException()/*TODO RecognitionException(lexer, input, nullptr)*/, startIndex(startIndex), deadEndConfigs(deadEndConfigs) {
|
LexerNoViableAltException::LexerNoViableAltException(Lexer *lexer, CharStream *input, size_t startIndex, atn::ATNConfigSet *deadEndConfigs) : RecognitionException()/*TODO RecognitionException(lexer, input, nullptr)*/, startIndex(startIndex), deadEndConfigs(deadEndConfigs) {
|
||||||
}
|
}
|
||||||
|
|
||||||
int LexerNoViableAltException::getStartIndex() {
|
size_t LexerNoViableAltException::getStartIndex() {
|
||||||
return startIndex;
|
return startIndex;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -54,8 +54,8 @@ CharStream *LexerNoViableAltException::getInputStream() {
|
||||||
|
|
||||||
std::wstring LexerNoViableAltException::toString() {
|
std::wstring LexerNoViableAltException::toString() {
|
||||||
std::wstring symbol = L"";
|
std::wstring symbol = L"";
|
||||||
if (startIndex >= 0 && startIndex < (int)getInputStream()->size()) {
|
if (startIndex < getInputStream()->size()) {
|
||||||
symbol = getInputStream()->getText(misc::Interval::of(startIndex,startIndex));
|
symbol = getInputStream()->getText(misc::Interval::of((int)startIndex, (int)startIndex));
|
||||||
symbol = antlrcpp::escapeWhitespace(symbol, false);
|
symbol = antlrcpp::escapeWhitespace(symbol, false);
|
||||||
}
|
}
|
||||||
std::wstring format = L"LexerNoViableAltException('" + symbol + L"')";
|
std::wstring format = L"LexerNoViableAltException('" + symbol + L"')";
|
||||||
|
|
|
@ -43,16 +43,16 @@ namespace runtime {
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Matching attempted at what input index? </summary>
|
/// Matching attempted at what input index? </summary>
|
||||||
private:
|
private:
|
||||||
const int startIndex;
|
const size_t startIndex;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Which configurations did we try at input.index() that couldn't match input.LA(1)? </summary>
|
/// Which configurations did we try at input.index() that couldn't match input.LA(1)? </summary>
|
||||||
atn::ATNConfigSet *const deadEndConfigs;
|
atn::ATNConfigSet *const deadEndConfigs;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
LexerNoViableAltException(Lexer *lexer, CharStream *input, int startIndex, atn::ATNConfigSet *deadEndConfigs);
|
LexerNoViableAltException(Lexer *lexer, CharStream *input, size_t startIndex, atn::ATNConfigSet *deadEndConfigs);
|
||||||
|
|
||||||
virtual int getStartIndex();
|
virtual size_t getStartIndex();
|
||||||
|
|
||||||
virtual atn::ATNConfigSet *getDeadEndConfigs();
|
virtual atn::ATNConfigSet *getDeadEndConfigs();
|
||||||
|
|
||||||
|
|
|
@ -74,7 +74,8 @@ Token *ListTokenSource::nextToken() {
|
||||||
}
|
}
|
||||||
|
|
||||||
int stop = std::max(-1, start - 1);
|
int stop = std::max(-1, start - 1);
|
||||||
eofToken = _factory->create(new std::pair<TokenSource*, CharStream*>(this, getInputStream()), Token::_EOF, L"EOF", Token::DEFAULT_CHANNEL, start, stop, getLine(), getCharPositionInLine());
|
eofToken = _factory->create(new std::pair<TokenSource*, CharStream*>(this, getInputStream()), Token::_EOF,
|
||||||
|
L"EOF", Token::DEFAULT_CHANNEL, start, stop, (int)getLine(), getCharPositionInLine());
|
||||||
}
|
}
|
||||||
|
|
||||||
return eofToken;
|
return eofToken;
|
||||||
|
@ -89,11 +90,11 @@ Token *ListTokenSource::nextToken() {
|
||||||
return t;
|
return t;
|
||||||
}
|
}
|
||||||
|
|
||||||
int ListTokenSource::getLine() {
|
size_t ListTokenSource::getLine() const {
|
||||||
if (i < tokens.size()) {
|
if (i < tokens.size()) {
|
||||||
return tokens[i]->getLine();
|
return (size_t)tokens[i]->getLine();
|
||||||
} else if (eofToken != nullptr) {
|
} else if (eofToken != nullptr) {
|
||||||
return eofToken->getLine();
|
return (size_t)eofToken->getLine();
|
||||||
} else if (tokens.size() > 0) {
|
} else if (tokens.size() > 0) {
|
||||||
// have to calculate the result from the line/column of the previous
|
// have to calculate the result from the line/column of the previous
|
||||||
// token, along with the text of the token.
|
// token, along with the text of the token.
|
||||||
|
@ -110,7 +111,7 @@ int ListTokenSource::getLine() {
|
||||||
}
|
}
|
||||||
|
|
||||||
// if no text is available, assume the token did not contain any newline characters.
|
// if no text is available, assume the token did not contain any newline characters.
|
||||||
return line;
|
return (size_t)line;
|
||||||
}
|
}
|
||||||
|
|
||||||
// only reach this if tokens is empty, meaning EOF occurs at the first
|
// only reach this if tokens is empty, meaning EOF occurs at the first
|
||||||
|
|
|
@ -130,7 +130,7 @@ namespace runtime {
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// @inheritDoc
|
/// @inheritDoc
|
||||||
/// </summary>
|
/// </summary>
|
||||||
virtual int getLine() override;
|
virtual size_t getLine() const override;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// @inheritDoc
|
/// @inheritDoc
|
||||||
|
|
|
@ -54,7 +54,7 @@ Parser::TraceListener::TraceListener(Parser *outerInstance) : outerInstance(oute
|
||||||
|
|
||||||
void Parser::TraceListener::enterEveryRule(ParserRuleContext *ctx) {
|
void Parser::TraceListener::enterEveryRule(ParserRuleContext *ctx) {
|
||||||
std::cout << "enter "
|
std::cout << "enter "
|
||||||
<< antlrcpp::ws2s(outerInstance->getRuleNames()[ctx->getRuleIndex()])
|
<< antlrcpp::ws2s(outerInstance->getRuleNames()[(size_t)ctx->getRuleIndex()])
|
||||||
<< ", LT(1)=" << antlrcpp::ws2s(outerInstance->_input->LT(1)->getText())
|
<< ", LT(1)=" << antlrcpp::ws2s(outerInstance->_input->LT(1)->getText())
|
||||||
<< std::endl;
|
<< std::endl;
|
||||||
}
|
}
|
||||||
|
@ -62,7 +62,7 @@ void Parser::TraceListener::enterEveryRule(ParserRuleContext *ctx) {
|
||||||
void Parser::TraceListener::visitTerminal(tree::TerminalNode *node) {
|
void Parser::TraceListener::visitTerminal(tree::TerminalNode *node) {
|
||||||
std::cout << "consume "
|
std::cout << "consume "
|
||||||
<< node->getSymbol() << " rule "
|
<< node->getSymbol() << " rule "
|
||||||
<< antlrcpp::ws2s(outerInstance->getRuleNames()[outerInstance->ctx->getRuleIndex()])
|
<< antlrcpp::ws2s(outerInstance->getRuleNames()[(size_t)outerInstance->ctx->getRuleIndex()])
|
||||||
<< std::endl;
|
<< std::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -71,7 +71,7 @@ void Parser::TraceListener::visitErrorNode(tree::ErrorNode *node) {
|
||||||
|
|
||||||
void Parser::TraceListener::exitEveryRule(ParserRuleContext *ctx) {
|
void Parser::TraceListener::exitEveryRule(ParserRuleContext *ctx) {
|
||||||
std::cout << "exit "
|
std::cout << "exit "
|
||||||
<< antlrcpp::ws2s(outerInstance->getRuleNames()[ctx->getRuleIndex()])
|
<< antlrcpp::ws2s(outerInstance->getRuleNames()[(size_t)ctx->getRuleIndex()])
|
||||||
<< ", LT(1)=" << antlrcpp::ws2s(outerInstance->_input->LT(1)->getText())
|
<< ", LT(1)=" << antlrcpp::ws2s(outerInstance->_input->LT(1)->getText())
|
||||||
<< std::endl;
|
<< std::endl;
|
||||||
}
|
}
|
||||||
|
@ -314,7 +314,7 @@ void Parser::notifyErrorListeners(Token *offendingToken, const std::wstring &msg
|
||||||
charPositionInLine = offendingToken->getCharPositionInLine();
|
charPositionInLine = offendingToken->getCharPositionInLine();
|
||||||
|
|
||||||
ANTLRErrorListener *listener = getErrorListenerDispatch();
|
ANTLRErrorListener *listener = getErrorListenerDispatch();
|
||||||
listener->syntaxError(this, offendingToken, line, charPositionInLine, msg, e);
|
listener->syntaxError(this, offendingToken, (size_t)line, charPositionInLine, msg, e);
|
||||||
}
|
}
|
||||||
|
|
||||||
Token *Parser::consume() {
|
Token *Parser::consume() {
|
||||||
|
@ -387,7 +387,7 @@ void Parser::enterOuterAlt(ParserRuleContext *localctx, int altNum) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void Parser::enterRecursionRule(ParserRuleContext *localctx, int ruleIndex) {
|
void Parser::enterRecursionRule(ParserRuleContext *localctx, int ruleIndex) {
|
||||||
enterRecursionRule(localctx, getATN().ruleToStartState[ruleIndex]->stateNumber, ruleIndex, 0);
|
enterRecursionRule(localctx, getATN().ruleToStartState[(size_t)ruleIndex]->stateNumber, ruleIndex, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Parser::enterRecursionRule(ParserRuleContext *localctx, int state, int ruleIndex, int precedence) {
|
void Parser::enterRecursionRule(ParserRuleContext *localctx, int state, int ruleIndex, int precedence) {
|
||||||
|
@ -472,42 +472,42 @@ bool Parser::inContext(const std::wstring &context) {
|
||||||
bool Parser::isExpectedToken(int symbol) {
|
bool Parser::isExpectedToken(int symbol) {
|
||||||
const atn::ATN &atn = getInterpreter()->atn;
|
const atn::ATN &atn = getInterpreter()->atn;
|
||||||
ParserRuleContext *ctx = ctx;
|
ParserRuleContext *ctx = ctx;
|
||||||
atn::ATNState *s = atn.states[getState()];
|
atn::ATNState *s = atn.states[(size_t)getState()];
|
||||||
misc::IntervalSet *following = atn.nextTokens(s);
|
misc::IntervalSet following = atn.nextTokens(s);
|
||||||
|
|
||||||
if (following->contains(symbol)) {
|
if (following.contains(symbol)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!following->contains(Token::EPSILON)) {
|
if (!following.contains(Token::EPSILON)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
while (ctx != nullptr && ctx->invokingState >= 0 && following->contains(Token::EPSILON)) {
|
while (ctx != nullptr && ctx->invokingState >= 0 && following.contains(Token::EPSILON)) {
|
||||||
atn::ATNState *invokingState = atn.states[ctx->invokingState];
|
atn::ATNState *invokingState = atn.states[(size_t)ctx->invokingState];
|
||||||
atn::RuleTransition *rt = static_cast<atn::RuleTransition*>(invokingState->transition(0));
|
atn::RuleTransition *rt = static_cast<atn::RuleTransition*>(invokingState->transition(0));
|
||||||
following = atn.nextTokens(rt->followState);
|
following = atn.nextTokens(rt->followState);
|
||||||
if (following->contains(symbol)) {
|
if (following.contains(symbol)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
ctx = static_cast<ParserRuleContext*>(ctx->parent);
|
ctx = static_cast<ParserRuleContext*>(ctx->parent);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (following->contains(Token::EPSILON) && symbol == Token::_EOF) {
|
if (following.contains(Token::EPSILON) && symbol == Token::_EOF) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
misc::IntervalSet *Parser::getExpectedTokens() {
|
misc::IntervalSet Parser::getExpectedTokens() {
|
||||||
return getATN().getExpectedTokens(getState(), getContext());
|
return getATN().getExpectedTokens(getState(), getContext());
|
||||||
}
|
}
|
||||||
|
|
||||||
misc::IntervalSet *Parser::getExpectedTokensWithinCurrentRule() {
|
misc::IntervalSet Parser::getExpectedTokensWithinCurrentRule() {
|
||||||
const atn::ATN &atn = getInterpreter()->atn;
|
const atn::ATN &atn = getInterpreter()->atn;
|
||||||
atn::ATNState *s = atn.states[getState()];
|
atn::ATNState *s = atn.states[(size_t)getState()];
|
||||||
return atn.nextTokens(s);
|
return atn.nextTokens(s);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -532,11 +532,11 @@ std::vector<std::wstring> Parser::getRuleInvocationStack(RuleContext *p) {
|
||||||
std::vector<std::wstring> stack = std::vector<std::wstring>();
|
std::vector<std::wstring> stack = std::vector<std::wstring>();
|
||||||
while (p != nullptr) {
|
while (p != nullptr) {
|
||||||
// compute what follows who invoked us
|
// compute what follows who invoked us
|
||||||
int ruleIndex = p->getRuleIndex();
|
ssize_t ruleIndex = p->getRuleIndex();
|
||||||
if (ruleIndex < 0) {
|
if (ruleIndex < 0) {
|
||||||
stack.push_back(L"n/a");
|
stack.push_back(L"n/a");
|
||||||
} else {
|
} else {
|
||||||
stack.push_back(ruleNames[ruleIndex]);
|
stack.push_back(ruleNames[(size_t)ruleIndex]);
|
||||||
}
|
}
|
||||||
p = p->parent;
|
p = p->parent;
|
||||||
}
|
}
|
||||||
|
|
|
@ -35,6 +35,7 @@
|
||||||
#include "ParseTreeListener.h"
|
#include "ParseTreeListener.h"
|
||||||
#include "TokenStream.h"
|
#include "TokenStream.h"
|
||||||
#include "TokenSource.h"
|
#include "TokenSource.h"
|
||||||
|
#include "Interval.h"
|
||||||
|
|
||||||
namespace org {
|
namespace org {
|
||||||
namespace antlr {
|
namespace antlr {
|
||||||
|
@ -356,9 +357,9 @@ namespace runtime {
|
||||||
/// respectively.
|
/// respectively.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <seealso cref= ATN#getExpectedTokens(int, RuleContext) </seealso>
|
/// <seealso cref= ATN#getExpectedTokens(int, RuleContext) </seealso>
|
||||||
virtual misc::IntervalSet *getExpectedTokens();
|
virtual misc::IntervalSet getExpectedTokens();
|
||||||
|
|
||||||
virtual misc::IntervalSet *getExpectedTokensWithinCurrentRule();
|
virtual misc::IntervalSet getExpectedTokensWithinCurrentRule();
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Get a rule's index (i.e., {@code RULE_ruleName} field) or -1 if not found. </summary>
|
/// Get a rule's index (i.e., {@code RULE_ruleName} field) or -1 if not found. </summary>
|
||||||
|
|
|
@ -65,7 +65,7 @@ ParserInterpreter::ParserInterpreter(const std::wstring &grammarFileName, const
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
atn::RuleStartState *ruleStartState = _atn.ruleToStartState[state->ruleIndex];
|
atn::RuleStartState *ruleStartState = _atn.ruleToStartState[(size_t)state->ruleIndex];
|
||||||
if (!ruleStartState->isPrecedenceRule) {
|
if (!ruleStartState->isPrecedenceRule) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
@ -76,7 +76,7 @@ ParserInterpreter::ParserInterpreter(const std::wstring &grammarFileName, const
|
||||||
}
|
}
|
||||||
|
|
||||||
if (maybeLoopEndState->epsilonOnlyTransitions && dynamic_cast<atn::RuleStopState*>(maybeLoopEndState->transition(0)->target) != nullptr) {
|
if (maybeLoopEndState->epsilonOnlyTransitions && dynamic_cast<atn::RuleStopState*>(maybeLoopEndState->transition(0)->target) != nullptr) {
|
||||||
this->pushRecursionContextStates->set(state->stateNumber);
|
this->pushRecursionContextStates->set((size_t)state->stateNumber);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -105,7 +105,7 @@ std::wstring ParserInterpreter::getGrammarFileName() const {
|
||||||
}
|
}
|
||||||
|
|
||||||
ParserRuleContext *ParserInterpreter::parse(int startRuleIndex) {
|
ParserRuleContext *ParserInterpreter::parse(int startRuleIndex) {
|
||||||
atn::RuleStartState *startRuleStartState = _atn.ruleToStartState[startRuleIndex];
|
atn::RuleStartState *startRuleStartState = _atn.ruleToStartState[(size_t)startRuleIndex];
|
||||||
|
|
||||||
InterpreterRuleContext *rootContext = new InterpreterRuleContext(nullptr, atn::ATNState::INVALID_STATE_NUMBER, startRuleIndex);
|
InterpreterRuleContext *rootContext = new InterpreterRuleContext(nullptr, atn::ATNState::INVALID_STATE_NUMBER, startRuleIndex);
|
||||||
if (startRuleStartState->isPrecedenceRule) {
|
if (startRuleStartState->isPrecedenceRule) {
|
||||||
|
@ -140,7 +140,7 @@ void ParserInterpreter::enterRecursionRule(ParserRuleContext *localctx, int stat
|
||||||
}
|
}
|
||||||
|
|
||||||
atn::ATNState *ParserInterpreter::getATNState() {
|
atn::ATNState *ParserInterpreter::getATNState() {
|
||||||
return _atn.states.at(getState());
|
return _atn.states[(size_t)getState()];
|
||||||
}
|
}
|
||||||
|
|
||||||
void ParserInterpreter::visitState(atn::ATNState *p) {
|
void ParserInterpreter::visitState(atn::ATNState *p) {
|
||||||
|
@ -151,12 +151,12 @@ void ParserInterpreter::visitState(atn::ATNState *p) {
|
||||||
edge = 1;
|
edge = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
atn::Transition *transition = p->transition(edge - 1);
|
atn::Transition *transition = p->transition((size_t)edge - 1);
|
||||||
switch (transition->getSerializationType()) {
|
switch (transition->getSerializationType()) {
|
||||||
case atn::Transition::EPSILON:
|
case atn::Transition::EPSILON:
|
||||||
if (pushRecursionContextStates->data[p->stateNumber] == 1 && !(dynamic_cast<atn::LoopEndState*>(transition->target) != nullptr)) {
|
if (pushRecursionContextStates->data[(size_t)p->stateNumber] == 1 && !(dynamic_cast<atn::LoopEndState*>(transition->target) != nullptr)) {
|
||||||
InterpreterRuleContext *ruleContext = new InterpreterRuleContext(_parentContextStack->front()->first, _parentContextStack->front()->second, ctx->getRuleIndex());
|
InterpreterRuleContext *ruleContext = new InterpreterRuleContext(_parentContextStack->front()->first, _parentContextStack->front()->second, ctx->getRuleIndex());
|
||||||
pushNewRecursionContext(ruleContext, _atn.ruleToStartState[p->ruleIndex]->stateNumber, ruleContext->getRuleIndex());
|
pushNewRecursionContext(ruleContext, _atn.ruleToStartState[(size_t)p->ruleIndex]->stateNumber, (int)ruleContext->getRuleIndex());
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
@ -167,7 +167,7 @@ void ParserInterpreter::visitState(atn::ATNState *p) {
|
||||||
case atn::Transition::RANGE:
|
case atn::Transition::RANGE:
|
||||||
case atn::Transition::SET:
|
case atn::Transition::SET:
|
||||||
case atn::Transition::NOT_SET:
|
case atn::Transition::NOT_SET:
|
||||||
if (!transition->matches(_input->LA(1), Token::MIN_USER_TOKEN_TYPE, 65535)) {
|
if (!transition->matches((int)_input->LA(1), Token::MIN_USER_TOKEN_TYPE, 65535)) {
|
||||||
_errHandler->recoverInline(this);
|
_errHandler->recoverInline(this);
|
||||||
}
|
}
|
||||||
matchWildcard();
|
matchWildcard();
|
||||||
|
@ -222,7 +222,7 @@ void ParserInterpreter::visitState(atn::ATNState *p) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void ParserInterpreter::visitRuleStopState(atn::ATNState *p) {
|
void ParserInterpreter::visitRuleStopState(atn::ATNState *p) {
|
||||||
atn::RuleStartState *ruleStartState = _atn.ruleToStartState[p->ruleIndex];
|
atn::RuleStartState *ruleStartState = _atn.ruleToStartState[(size_t)p->ruleIndex];
|
||||||
if (ruleStartState->isPrecedenceRule) {
|
if (ruleStartState->isPrecedenceRule) {
|
||||||
std::pair<ParserRuleContext*, int> *parentContext = _parentContextStack->back(); // TODO: Dan - make sure this is equivalent
|
std::pair<ParserRuleContext*, int> *parentContext = _parentContextStack->back(); // TODO: Dan - make sure this is equivalent
|
||||||
_parentContextStack->pop_back();
|
_parentContextStack->pop_back();
|
||||||
|
@ -232,6 +232,6 @@ void ParserInterpreter::visitRuleStopState(atn::ATNState *p) {
|
||||||
exitRule();
|
exitRule();
|
||||||
}
|
}
|
||||||
|
|
||||||
atn::RuleTransition *ruleTransition = static_cast<atn::RuleTransition*>(_atn.states.at(getState())->transition(0));
|
atn::RuleTransition *ruleTransition = static_cast<atn::RuleTransition*>(_atn.states[(size_t)getState()]->transition(0));
|
||||||
setState(ruleTransition->followState->stateNumber);
|
setState(ruleTransition->followState->stateNumber);
|
||||||
}
|
}
|
||||||
|
|
|
@ -112,14 +112,13 @@ tree::TerminalNode *ParserRuleContext::getToken(int ttype, std::size_t i) {
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
int j = -1; // what token with ttype have we found?
|
size_t j = 0; // what token with ttype have we found?
|
||||||
for (auto &o : _children) {
|
for (auto &o : _children) {
|
||||||
if (dynamic_cast<tree::TerminalNode*>(o) != nullptr) {
|
if (dynamic_cast<tree::TerminalNode*>(o) != nullptr) {
|
||||||
tree::TerminalNode *tnode = static_cast<tree::TerminalNode*>(o);
|
tree::TerminalNode *tnode = static_cast<tree::TerminalNode*>(o);
|
||||||
Token *symbol = tnode->getSymbol();
|
Token *symbol = tnode->getSymbol();
|
||||||
if (symbol->getType() == ttype) {
|
if (symbol->getType() == ttype) {
|
||||||
j++;
|
if (j++ == i) {
|
||||||
if (j == i) {
|
|
||||||
return tnode;
|
return tnode;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -162,7 +161,7 @@ std::size_t ParserRuleContext::getChildCount() {
|
||||||
return _children.size() > 0 ? _children.size() : 0;
|
return _children.size() > 0 ? _children.size() : 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
misc::Interval *ParserRuleContext::getSourceInterval() {
|
misc::Interval ParserRuleContext::getSourceInterval() {
|
||||||
if (start == nullptr || stop == nullptr) {
|
if (start == nullptr || stop == nullptr) {
|
||||||
return misc::Interval::INVALID;
|
return misc::Interval::INVALID;
|
||||||
}
|
}
|
||||||
|
|
|
@ -139,15 +139,14 @@ namespace runtime {
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
T* getChild(size_t i) {
|
T* getChild(size_t i) {
|
||||||
if (_children.empty() || i >= _children.size()) {
|
if (_children.empty()) {
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
int j = -1; // what element have we found with ctxType?
|
size_t j = 0; // what element have we found with ctxType?
|
||||||
for (auto &child : _children) {
|
for (auto &child : _children) {
|
||||||
if (dynamic_cast<T *>(child) != nullptr) {
|
if (dynamic_cast<T *>(child) != nullptr) {
|
||||||
j++;
|
if (j++ == i) {
|
||||||
if (j == i) {
|
|
||||||
return dynamic_cast<T *>(child);
|
return dynamic_cast<T *>(child);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -160,7 +159,7 @@ namespace runtime {
|
||||||
virtual std::vector<tree::TerminalNode *> getTokens(int ttype);
|
virtual std::vector<tree::TerminalNode *> getTokens(int ttype);
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
T* getRuleContext(int i) {
|
T* getRuleContext(size_t i) {
|
||||||
return getChild<T>(i);
|
return getChild<T>(i);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -189,7 +188,7 @@ namespace runtime {
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual std::size_t getChildCount() override;
|
virtual std::size_t getChildCount() override;
|
||||||
virtual misc::Interval *getSourceInterval() override;
|
virtual misc::Interval getSourceInterval() override;
|
||||||
|
|
||||||
virtual Token *getStart();
|
virtual Token *getStart();
|
||||||
virtual Token *getStop();
|
virtual Token *getStop();
|
||||||
|
|
|
@ -33,19 +33,22 @@
|
||||||
|
|
||||||
using namespace org::antlr::v4::runtime;
|
using namespace org::antlr::v4::runtime;
|
||||||
|
|
||||||
void ProxyErrorListener::reportAmbiguity(Parser *recognizer, dfa::DFA *dfa, int startIndex, int stopIndex, bool exact, antlrcpp::BitSet *ambigAlts, atn::ATNConfigSet *configs) {
|
void ProxyErrorListener::reportAmbiguity(Parser *recognizer, dfa::DFA *dfa, size_t startIndex, size_t stopIndex,
|
||||||
|
bool exact, antlrcpp::BitSet *ambigAlts, atn::ATNConfigSet *configs) {
|
||||||
for (auto listener : *delegates) {
|
for (auto listener : *delegates) {
|
||||||
listener->reportAmbiguity(recognizer, dfa, startIndex, stopIndex, exact, ambigAlts, configs);
|
listener->reportAmbiguity(recognizer, dfa, startIndex, stopIndex, exact, ambigAlts, configs);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void ProxyErrorListener::reportAttemptingFullContext(Parser *recognizer, dfa::DFA *dfa, int startIndex, int stopIndex, antlrcpp::BitSet *conflictingAlts, atn::ATNConfigSet *configs) {
|
void ProxyErrorListener::reportAttemptingFullContext(Parser *recognizer, dfa::DFA *dfa, size_t startIndex,
|
||||||
|
size_t stopIndex, antlrcpp::BitSet *conflictingAlts, atn::ATNConfigSet *configs) {
|
||||||
for (auto listener : *delegates) {
|
for (auto listener : *delegates) {
|
||||||
listener->reportAttemptingFullContext(recognizer, dfa, startIndex, stopIndex, conflictingAlts, configs);
|
listener->reportAttemptingFullContext(recognizer, dfa, startIndex, stopIndex, conflictingAlts, configs);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void ProxyErrorListener::reportContextSensitivity(Parser *recognizer, dfa::DFA *dfa, int startIndex, int stopIndex, int prediction, atn::ATNConfigSet *configs) {
|
void ProxyErrorListener::reportContextSensitivity(Parser *recognizer, dfa::DFA *dfa, size_t startIndex, size_t stopIndex,
|
||||||
|
int prediction, atn::ATNConfigSet *configs) {
|
||||||
for (auto listener : *delegates) {
|
for (auto listener : *delegates) {
|
||||||
listener->reportContextSensitivity(recognizer, dfa, startIndex, stopIndex, prediction, configs);
|
listener->reportContextSensitivity(recognizer, dfa, startIndex, stopIndex, prediction, configs);
|
||||||
}
|
}
|
||||||
|
|
|
@ -58,18 +58,21 @@ namespace runtime {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void syntaxError(IRecognizer *recognizer, void *offendingSymbol, int line, int charPositionInLine, const std::wstring &msg, RecognitionException *e) {
|
void syntaxError(IRecognizer *recognizer, void *offendingSymbol, size_t line, int charPositionInLine,
|
||||||
|
const std::wstring &msg, RecognitionException *e) {
|
||||||
for (auto listener : *delegates) {
|
for (auto listener : *delegates) {
|
||||||
listener->syntaxError(recognizer, offendingSymbol, line, charPositionInLine, msg, e);
|
listener->syntaxError(recognizer, offendingSymbol, line, charPositionInLine, msg, e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual void reportAmbiguity(Parser *recognizer, dfa::DFA *dfa, int startIndex, int stopIndex, bool exact, antlrcpp::BitSet *ambigAlts, atn::ATNConfigSet *configs) override;
|
virtual void reportAmbiguity(Parser *recognizer, dfa::DFA *dfa, size_t startIndex, size_t stopIndex, bool exact,
|
||||||
|
antlrcpp::BitSet *ambigAlts, atn::ATNConfigSet *configs) override;
|
||||||
|
|
||||||
virtual void reportAttemptingFullContext(Parser *recognizer, dfa::DFA *dfa, int startIndex, int stopIndex, antlrcpp::BitSet *conflictingAlts, atn::ATNConfigSet *configs) override;
|
virtual void reportAttemptingFullContext(Parser *recognizer, dfa::DFA *dfa, size_t startIndex, size_t stopIndex,
|
||||||
|
antlrcpp::BitSet *conflictingAlts, atn::ATNConfigSet *configs) override;
|
||||||
|
|
||||||
virtual void reportContextSensitivity(Parser *recognizer, dfa::DFA *dfa, int startIndex, int stopIndex, int prediction, atn::ATNConfigSet *configs) override;
|
virtual void reportContextSensitivity(Parser *recognizer, dfa::DFA *dfa, size_t startIndex, size_t stopIndex,
|
||||||
|
int prediction, atn::ATNConfigSet *configs) override;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace runtime
|
} // namespace runtime
|
||||||
|
|
|
@ -59,11 +59,11 @@ void RecognitionException::setOffendingState(int offendingState) {
|
||||||
_offendingState = offendingState;
|
_offendingState = offendingState;
|
||||||
}
|
}
|
||||||
|
|
||||||
misc::IntervalSet *RecognitionException::getExpectedTokens() {
|
misc::IntervalSet RecognitionException::getExpectedTokens() {
|
||||||
if (_recognizer != nullptr) {
|
if (_recognizer != nullptr) {
|
||||||
return _recognizer->getATN().getExpectedTokens(_offendingState, _ctx);
|
return _recognizer->getATN().getExpectedTokens(_offendingState, _ctx);
|
||||||
}
|
}
|
||||||
return nullptr;
|
return misc::IntervalSet::EMPTY_SET;
|
||||||
}
|
}
|
||||||
|
|
||||||
RuleContext *RecognitionException::getCtx() {
|
RuleContext *RecognitionException::getCtx() {
|
||||||
|
|
|
@ -32,6 +32,7 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "Exceptions.h"
|
#include "Exceptions.h"
|
||||||
|
#include "IntervalSet.h"
|
||||||
|
|
||||||
namespace org {
|
namespace org {
|
||||||
namespace antlr {
|
namespace antlr {
|
||||||
|
@ -100,7 +101,7 @@ namespace runtime {
|
||||||
/// <returns> The set of token types that could potentially follow the current
|
/// <returns> The set of token types that could potentially follow the current
|
||||||
/// state in the ATN, or {@code null} if the information is not available. </returns>
|
/// state in the ATN, or {@code null} if the information is not available. </returns>
|
||||||
public:
|
public:
|
||||||
virtual misc::IntervalSet *getExpectedTokens();
|
virtual misc::IntervalSet getExpectedTokens();
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets the <seealso cref="RuleContext"/> at the time this exception was thrown.
|
/// Gets the <seealso cref="RuleContext"/> at the time this exception was thrown.
|
||||||
|
|
|
@ -64,7 +64,7 @@ bool RuleContext::isEmpty() {
|
||||||
return invokingState == -1;
|
return invokingState == -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
misc::Interval *RuleContext::getSourceInterval() {
|
misc::Interval RuleContext::getSourceInterval() {
|
||||||
return misc::Interval::INVALID;
|
return misc::Interval::INVALID;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -96,14 +96,14 @@ std::wstring RuleContext::getText() {
|
||||||
}
|
}
|
||||||
|
|
||||||
antlrcpp::StringBuilder *builder = new antlrcpp::StringBuilder();
|
antlrcpp::StringBuilder *builder = new antlrcpp::StringBuilder();
|
||||||
for (int i = 0; i < getChildCount(); i++) {
|
for (size_t i = 0; i < getChildCount(); i++) {
|
||||||
builder->append(getChild(i)->getText());
|
builder->append(getChild(i)->getText());
|
||||||
}
|
}
|
||||||
|
|
||||||
return builder->toString();
|
return builder->toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
int RuleContext::getRuleIndex() {
|
ssize_t RuleContext::getRuleIndex() const {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -173,31 +173,31 @@ std::wstring RuleContext::toString(const std::vector<std::wstring> &ruleNames) {
|
||||||
|
|
||||||
|
|
||||||
std::wstring RuleContext::toString(const std::vector<std::wstring> &ruleNames, RuleContext *stop) {
|
std::wstring RuleContext::toString(const std::vector<std::wstring> &ruleNames, RuleContext *stop) {
|
||||||
antlrcpp::StringBuilder *buf = new antlrcpp::StringBuilder();
|
antlrcpp::StringBuilder buffer;
|
||||||
RuleContext *p = this;
|
RuleContext *p = this;
|
||||||
buf->append(L"[");
|
buffer.append(L"[");
|
||||||
while (p != nullptr && p != stop) {
|
while (p != nullptr && p != stop) {
|
||||||
if (ruleNames.empty()) {
|
if (ruleNames.empty()) {
|
||||||
if (!p->isEmpty()) {
|
if (!p->isEmpty()) {
|
||||||
buf->append(p->invokingState);
|
buffer.append(p->invokingState);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
int ruleIndex = p->getRuleIndex();
|
ssize_t ruleIndex = p->getRuleIndex();
|
||||||
|
|
||||||
std::wstring ruleName = ruleIndex >= 0 && ruleIndex < (int)ruleNames.size() ? ruleNames[ruleIndex] : std::to_wstring(ruleIndex);
|
std::wstring ruleName = (ruleIndex >= 0 && ruleIndex < (ssize_t)ruleNames.size()) ? ruleNames[(size_t)ruleIndex] : std::to_wstring(ruleIndex);
|
||||||
buf->append(ruleName);
|
buffer.append(ruleName);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (p->parent != nullptr && (ruleNames.size() > 0 || !p->parent->isEmpty())) {
|
if (p->parent != nullptr && (ruleNames.size() > 0 || !p->parent->isEmpty())) {
|
||||||
buf->append(L" ");
|
buffer.append(L" ");
|
||||||
}
|
}
|
||||||
|
|
||||||
p = p->parent;
|
p = p->parent;
|
||||||
}
|
}
|
||||||
|
|
||||||
buf->append(L"]");
|
buffer.append(L"]");
|
||||||
|
|
||||||
return buf->toString();
|
return buffer.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
std::wstring RuleContext::toString() {
|
std::wstring RuleContext::toString() {
|
||||||
|
|
|
@ -87,14 +87,14 @@ namespace runtime {
|
||||||
|
|
||||||
// satisfy the ParseTree / SyntaxTree interface
|
// satisfy the ParseTree / SyntaxTree interface
|
||||||
|
|
||||||
virtual misc::Interval *getSourceInterval() override;
|
virtual misc::Interval getSourceInterval() override;
|
||||||
|
|
||||||
virtual RuleContext *getRuleContext() override;
|
virtual RuleContext *getRuleContext() override;
|
||||||
virtual RuleContext *getParent() override;
|
virtual RuleContext *getParent() override;
|
||||||
virtual void *getPayload() override;
|
virtual void *getPayload() override;
|
||||||
virtual std::wstring getText() override;
|
virtual std::wstring getText() override;
|
||||||
|
|
||||||
virtual int getRuleIndex();
|
virtual ssize_t getRuleIndex() const;
|
||||||
|
|
||||||
virtual ParseTree *getChild(std::size_t i) override;
|
virtual ParseTree *getChild(std::size_t i) override;
|
||||||
|
|
||||||
|
|
|
@ -33,9 +33,9 @@
|
||||||
|
|
||||||
using namespace org::antlr::v4::runtime;
|
using namespace org::antlr::v4::runtime;
|
||||||
|
|
||||||
const int Token::INVALID_TYPE;
|
const size_t Token::INVALID_TYPE;
|
||||||
const int Token::EPSILON;
|
const ssize_t Token::EPSILON;
|
||||||
const int Token::MIN_USER_TOKEN_TYPE;
|
const size_t Token::MIN_USER_TOKEN_TYPE;
|
||||||
const int Token::_EOF;
|
const size_t Token::_EOF;
|
||||||
const int Token::DEFAULT_CHANNEL;
|
const size_t Token::DEFAULT_CHANNEL;
|
||||||
const int Token::HIDDEN_CHANNEL;
|
const size_t Token::HIDDEN_CHANNEL;
|
||||||
|
|
|
@ -45,17 +45,17 @@ namespace runtime {
|
||||||
/// </summary>
|
/// </summary>
|
||||||
class Token {
|
class Token {
|
||||||
public:
|
public:
|
||||||
static const int INVALID_TYPE = 0;
|
static const size_t INVALID_TYPE = 0;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// During lookahead operations, this "token" signifies we hit rule end ATN state
|
/// During lookahead operations, this "token" signifies we hit rule end ATN state
|
||||||
/// and did not follow it despite needing to.
|
/// and did not follow it despite needing to.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
static const int EPSILON = -2;
|
static const ssize_t EPSILON = -2;
|
||||||
|
|
||||||
static const int MIN_USER_TOKEN_TYPE = 1;
|
static const size_t MIN_USER_TOKEN_TYPE = 1;
|
||||||
|
|
||||||
static const int _EOF = IntStream::_EOF;
|
static const size_t _EOF = IntStream::_EOF;
|
||||||
|
|
||||||
// This isn't necessary
|
// This isn't necessary
|
||||||
virtual ~Token() {};
|
virtual ~Token() {};
|
||||||
|
@ -65,13 +65,13 @@ namespace runtime {
|
||||||
/// on a particular "channel". The parser tunes to a particular channel
|
/// on a particular "channel". The parser tunes to a particular channel
|
||||||
/// so that whitespace etc... can go to the parser on a "hidden" channel.
|
/// so that whitespace etc... can go to the parser on a "hidden" channel.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
static const int DEFAULT_CHANNEL = 0;
|
static const size_t DEFAULT_CHANNEL = 0;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Anything on different channel than DEFAULT_CHANNEL is not parsed
|
/// Anything on different channel than DEFAULT_CHANNEL is not parsed
|
||||||
/// by parser.
|
/// by parser.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
static const int HIDDEN_CHANNEL = 1;
|
static const size_t HIDDEN_CHANNEL = 1;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Get the text of the token.
|
/// Get the text of the token.
|
||||||
|
|
|
@ -69,7 +69,7 @@ namespace runtime {
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <returns> The line number for the current position in the input stream, or
|
/// <returns> The line number for the current position in the input stream, or
|
||||||
/// 0 if the current token source does not track line numbers. </returns>
|
/// 0 if the current token source does not track line numbers. </returns>
|
||||||
virtual int getLine() = 0;
|
virtual size_t getLine() const = 0;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Get the index into the current line for the current position in the input
|
/// Get the index into the current line for the current position in the input
|
||||||
|
|
|
@ -53,7 +53,7 @@ namespace runtime {
|
||||||
public:
|
public:
|
||||||
virtual ~TokenStream();
|
virtual ~TokenStream();
|
||||||
|
|
||||||
virtual Token *LT(int k) = 0;
|
virtual Token *LT(ssize_t k) = 0;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets the <seealso cref="Token"/> at the specified {@code index} in the stream. When
|
/// Gets the <seealso cref="Token"/> at the specified {@code index} in the stream. When
|
||||||
|
@ -72,7 +72,7 @@ namespace runtime {
|
||||||
/// <exception cref="IllegalArgumentException"> if {code index} is less than 0 </exception>
|
/// <exception cref="IllegalArgumentException"> if {code index} is less than 0 </exception>
|
||||||
/// <exception cref="UnsupportedOperationException"> if the stream does not support
|
/// <exception cref="UnsupportedOperationException"> if the stream does not support
|
||||||
/// retrieving the token at the specified index </exception>
|
/// retrieving the token at the specified index </exception>
|
||||||
virtual Token *get(int index) = 0;
|
virtual Token *get(size_t index) = 0;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets the underlying <seealso cref="TokenSource"/> which provides tokens for this
|
/// Gets the underlying <seealso cref="TokenSource"/> which provides tokens for this
|
||||||
|
@ -100,7 +100,7 @@ namespace runtime {
|
||||||
/// stream.
|
/// stream.
|
||||||
/// </returns>
|
/// </returns>
|
||||||
/// <exception cref="NullPointerException"> if {@code interval} is {@code null} </exception>
|
/// <exception cref="NullPointerException"> if {@code interval} is {@code null} </exception>
|
||||||
virtual std::wstring getText(misc::Interval *interval) = 0;
|
virtual std::wstring getText(const misc::Interval &interval) = 0;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Return the text of all tokens in the stream. This method behaves like the
|
/// Return the text of all tokens in the stream. This method behaves like the
|
||||||
|
|
|
@ -40,20 +40,20 @@ using namespace org::antlr::v4::runtime;
|
||||||
|
|
||||||
using org::antlr::v4::runtime::misc::Interval;
|
using org::antlr::v4::runtime::misc::Interval;
|
||||||
|
|
||||||
TokenStreamRewriter::RewriteOperation::RewriteOperation(TokenStreamRewriter *outerInstance, int index) : outerInstance(outerInstance) {
|
TokenStreamRewriter::RewriteOperation::RewriteOperation(TokenStreamRewriter *outerInstance, size_t index) : outerInstance(outerInstance) {
|
||||||
|
|
||||||
InitializeInstanceFields();
|
InitializeInstanceFields();
|
||||||
this->index = index;
|
this->index = index;
|
||||||
}
|
}
|
||||||
|
|
||||||
TokenStreamRewriter::RewriteOperation::RewriteOperation(TokenStreamRewriter *outerInstance, int index, const std::wstring& text) : outerInstance(outerInstance) {
|
TokenStreamRewriter::RewriteOperation::RewriteOperation(TokenStreamRewriter *outerInstance, size_t index, const std::wstring& text) : outerInstance(outerInstance) {
|
||||||
|
|
||||||
InitializeInstanceFields();
|
InitializeInstanceFields();
|
||||||
this->index = index;
|
this->index = index;
|
||||||
this->text = text;
|
this->text = text;
|
||||||
}
|
}
|
||||||
|
|
||||||
int TokenStreamRewriter::RewriteOperation::execute(std::wstring *buf) {
|
size_t TokenStreamRewriter::RewriteOperation::execute(std::wstring *buf) {
|
||||||
return index;
|
return index;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -61,7 +61,7 @@ std::wstring TokenStreamRewriter::RewriteOperation::toString() {
|
||||||
std::wstring opName = L"TokenStreamRewriter";
|
std::wstring opName = L"TokenStreamRewriter";
|
||||||
size_t index = opName.find(L'$');
|
size_t index = opName.find(L'$');
|
||||||
opName = opName.substr(index + 1, opName.length() - (index + 1));
|
opName = opName.substr(index + 1, opName.length() - (index + 1));
|
||||||
return L"<" + opName + L"@" + outerInstance->tokens->get((int)index)->getText() + L":\"" + text + L"\">";
|
return L"<" + opName + L"@" + outerInstance->tokens->get(index)->getText() + L":\"" + text + L"\">";
|
||||||
}
|
}
|
||||||
|
|
||||||
void TokenStreamRewriter::RewriteOperation::InitializeInstanceFields() {
|
void TokenStreamRewriter::RewriteOperation::InitializeInstanceFields() {
|
||||||
|
@ -69,10 +69,11 @@ void TokenStreamRewriter::RewriteOperation::InitializeInstanceFields() {
|
||||||
index = 0;
|
index = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
TokenStreamRewriter::InsertBeforeOp::InsertBeforeOp(TokenStreamRewriter *outerInstance, int index, const std::wstring& text) : RewriteOperation(outerInstance, index, text), outerInstance(outerInstance) {
|
TokenStreamRewriter::InsertBeforeOp::InsertBeforeOp(TokenStreamRewriter *outerInstance, size_t index, const std::wstring& text)
|
||||||
|
: RewriteOperation(outerInstance, index, text), outerInstance(outerInstance) {
|
||||||
}
|
}
|
||||||
|
|
||||||
int TokenStreamRewriter::InsertBeforeOp::execute(std::wstring *buf) {
|
size_t TokenStreamRewriter::InsertBeforeOp::execute(std::wstring *buf) {
|
||||||
buf->append(text);
|
buf->append(text);
|
||||||
if (outerInstance->tokens->get(index)->getType() != Token::_EOF) {
|
if (outerInstance->tokens->get(index)->getType() != Token::_EOF) {
|
||||||
buf->append(outerInstance->tokens->get(index)->getText());
|
buf->append(outerInstance->tokens->get(index)->getText());
|
||||||
|
@ -80,13 +81,13 @@ int TokenStreamRewriter::InsertBeforeOp::execute(std::wstring *buf) {
|
||||||
return index + 1;
|
return index + 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
TokenStreamRewriter::ReplaceOp::ReplaceOp(TokenStreamRewriter *outerInstance, int from, int to, const std::wstring& text) : RewriteOperation(outerInstance, from, text), outerInstance(outerInstance) {
|
TokenStreamRewriter::ReplaceOp::ReplaceOp(TokenStreamRewriter *outerInstance, size_t from, size_t to, const std::wstring& text) : RewriteOperation(outerInstance, from, text), outerInstance(outerInstance) {
|
||||||
|
|
||||||
InitializeInstanceFields();
|
InitializeInstanceFields();
|
||||||
lastIndex = to;
|
lastIndex = to;
|
||||||
}
|
}
|
||||||
|
|
||||||
int TokenStreamRewriter::ReplaceOp::execute(std::wstring *buf) {
|
size_t TokenStreamRewriter::ReplaceOp::execute(std::wstring *buf) {
|
||||||
buf->append(text);
|
buf->append(text);
|
||||||
return lastIndex + 1;
|
return lastIndex + 1;
|
||||||
}
|
}
|
||||||
|
@ -135,15 +136,15 @@ void TokenStreamRewriter::insertAfter(Token *t, const std::wstring& text) {
|
||||||
insertAfter(DEFAULT_PROGRAM_NAME, t, text);
|
insertAfter(DEFAULT_PROGRAM_NAME, t, text);
|
||||||
}
|
}
|
||||||
|
|
||||||
void TokenStreamRewriter::insertAfter(int index, const std::wstring& text) {
|
void TokenStreamRewriter::insertAfter(size_t index, const std::wstring& text) {
|
||||||
insertAfter(DEFAULT_PROGRAM_NAME, index, text);
|
insertAfter(DEFAULT_PROGRAM_NAME, index, text);
|
||||||
}
|
}
|
||||||
|
|
||||||
void TokenStreamRewriter::insertAfter(const std::wstring &programName, Token *t, const std::wstring& text) {
|
void TokenStreamRewriter::insertAfter(const std::wstring &programName, Token *t, const std::wstring& text) {
|
||||||
insertAfter(programName, t->getTokenIndex(), text);
|
insertAfter(programName, (size_t)t->getTokenIndex(), text);
|
||||||
}
|
}
|
||||||
|
|
||||||
void TokenStreamRewriter::insertAfter(const std::wstring &programName, int index, const std::wstring& text) {
|
void TokenStreamRewriter::insertAfter(const std::wstring &programName, size_t index, const std::wstring& text) {
|
||||||
// to insert after, just insert before next index (even if past end)
|
// to insert after, just insert before next index (even if past end)
|
||||||
insertBefore(programName, index + 1, text);
|
insertBefore(programName, index + 1, text);
|
||||||
}
|
}
|
||||||
|
@ -152,26 +153,26 @@ void TokenStreamRewriter::insertBefore(Token *t, const std::wstring& text) {
|
||||||
insertBefore(DEFAULT_PROGRAM_NAME, t, text);
|
insertBefore(DEFAULT_PROGRAM_NAME, t, text);
|
||||||
}
|
}
|
||||||
|
|
||||||
void TokenStreamRewriter::insertBefore(int index, const std::wstring& text) {
|
void TokenStreamRewriter::insertBefore(size_t index, const std::wstring& text) {
|
||||||
insertBefore(DEFAULT_PROGRAM_NAME, index, text);
|
insertBefore(DEFAULT_PROGRAM_NAME, index, text);
|
||||||
}
|
}
|
||||||
|
|
||||||
void TokenStreamRewriter::insertBefore(const std::wstring &programName, Token *t, const std::wstring& text) {
|
void TokenStreamRewriter::insertBefore(const std::wstring &programName, Token *t, const std::wstring& text) {
|
||||||
insertBefore(programName, t->getTokenIndex(), text);
|
insertBefore(programName, (size_t)t->getTokenIndex(), text);
|
||||||
}
|
}
|
||||||
|
|
||||||
void TokenStreamRewriter::insertBefore(const std::wstring &programName, int index, const std::wstring& text) {
|
void TokenStreamRewriter::insertBefore(const std::wstring &programName, size_t index, const std::wstring& text) {
|
||||||
RewriteOperation *op = new InsertBeforeOp(this, index, text);
|
RewriteOperation *op = new InsertBeforeOp(this, index, text);
|
||||||
std::vector<RewriteOperation*> rewrites = getProgram(programName);
|
std::vector<RewriteOperation*> rewrites = getProgram(programName);
|
||||||
op->instructionIndex = (int)rewrites.size();
|
op->instructionIndex = (int)rewrites.size();
|
||||||
rewrites.push_back(op);
|
rewrites.push_back(op);
|
||||||
}
|
}
|
||||||
|
|
||||||
void TokenStreamRewriter::replace(int index, const std::wstring& text) {
|
void TokenStreamRewriter::replace(size_t index, const std::wstring& text) {
|
||||||
replace(DEFAULT_PROGRAM_NAME, index, index, text);
|
replace(DEFAULT_PROGRAM_NAME, index, index, text);
|
||||||
}
|
}
|
||||||
|
|
||||||
void TokenStreamRewriter::replace(int from, int to, const std::wstring& text) {
|
void TokenStreamRewriter::replace(size_t from, size_t to, const std::wstring& text) {
|
||||||
replace(DEFAULT_PROGRAM_NAME, from, to, text);
|
replace(DEFAULT_PROGRAM_NAME, from, to, text);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -183,9 +184,10 @@ void TokenStreamRewriter::replace(Token *from, Token *to, const std::wstring& te
|
||||||
replace(DEFAULT_PROGRAM_NAME, from, to, text);
|
replace(DEFAULT_PROGRAM_NAME, from, to, text);
|
||||||
}
|
}
|
||||||
|
|
||||||
void TokenStreamRewriter::replace(const std::wstring &programName, int from, int to, const std::wstring& text) {
|
void TokenStreamRewriter::replace(const std::wstring &programName, size_t from, size_t to, const std::wstring& text) {
|
||||||
if (from > to || from < 0 || to < 0 || to >= (int)tokens->size()) {
|
if (from > to || to >= tokens->size()) {
|
||||||
throw IllegalArgumentException(L"replace: range invalid: " + std::to_wstring(from) + L".." + std::to_wstring(to) + L"(size=" + std::to_wstring(tokens->size()) + L")");
|
throw IllegalArgumentException(L"replace: range invalid: " + std::to_wstring(from) + L".." + std::to_wstring(to) +
|
||||||
|
L"(size=" + std::to_wstring(tokens->size()) + L")");
|
||||||
}
|
}
|
||||||
RewriteOperation *op = new ReplaceOp(this, from, to, text);
|
RewriteOperation *op = new ReplaceOp(this, from, to, text);
|
||||||
std::vector<RewriteOperation*> rewrites = getProgram(programName);
|
std::vector<RewriteOperation*> rewrites = getProgram(programName);
|
||||||
|
@ -194,30 +196,30 @@ void TokenStreamRewriter::replace(const std::wstring &programName, int from, int
|
||||||
}
|
}
|
||||||
|
|
||||||
void TokenStreamRewriter::replace(const std::wstring &programName, Token *from, Token *to, const std::wstring& text) {
|
void TokenStreamRewriter::replace(const std::wstring &programName, Token *from, Token *to, const std::wstring& text) {
|
||||||
replace(programName, from->getTokenIndex(), to->getTokenIndex(), text);
|
replace(programName, (size_t)from->getTokenIndex(), (size_t)to->getTokenIndex(), text);
|
||||||
}
|
}
|
||||||
|
|
||||||
void TokenStreamRewriter::delete_Renamed(int index) {
|
void TokenStreamRewriter::Delete(size_t index) {
|
||||||
delete_Renamed(DEFAULT_PROGRAM_NAME, index, index);
|
Delete(DEFAULT_PROGRAM_NAME, index, index);
|
||||||
}
|
}
|
||||||
|
|
||||||
void TokenStreamRewriter::delete_Renamed(int from, int to) {
|
void TokenStreamRewriter::Delete(size_t from, size_t to) {
|
||||||
delete_Renamed(DEFAULT_PROGRAM_NAME, from, to);
|
Delete(DEFAULT_PROGRAM_NAME, from, to);
|
||||||
}
|
}
|
||||||
|
|
||||||
void TokenStreamRewriter::delete_Renamed(Token *indexT) {
|
void TokenStreamRewriter::Delete(Token *indexT) {
|
||||||
delete_Renamed(DEFAULT_PROGRAM_NAME, indexT, indexT);
|
Delete(DEFAULT_PROGRAM_NAME, indexT, indexT);
|
||||||
}
|
}
|
||||||
|
|
||||||
void TokenStreamRewriter::delete_Renamed(Token *from, Token *to) {
|
void TokenStreamRewriter::Delete(Token *from, Token *to) {
|
||||||
delete_Renamed(DEFAULT_PROGRAM_NAME, from, to);
|
Delete(DEFAULT_PROGRAM_NAME, from, to);
|
||||||
}
|
}
|
||||||
|
|
||||||
void TokenStreamRewriter::delete_Renamed(const std::wstring &programName, int from, int to) {
|
void TokenStreamRewriter::Delete(const std::wstring &programName, size_t from, size_t to) {
|
||||||
replace(programName, from, to, nullptr);
|
replace(programName, from, to, nullptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
void TokenStreamRewriter::delete_Renamed(const std::wstring &programName, Token *from, Token *to) {
|
void TokenStreamRewriter::Delete(const std::wstring &programName, Token *from, Token *to) {
|
||||||
replace(programName, from, to, nullptr);
|
replace(programName, from, to, nullptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -254,14 +256,14 @@ std::wstring TokenStreamRewriter::getText() {
|
||||||
return getText(DEFAULT_PROGRAM_NAME, Interval::of(0, (int)tokens->size() - 1));
|
return getText(DEFAULT_PROGRAM_NAME, Interval::of(0, (int)tokens->size() - 1));
|
||||||
}
|
}
|
||||||
|
|
||||||
std::wstring TokenStreamRewriter::getText(Interval *interval) {
|
std::wstring TokenStreamRewriter::getText(const Interval &interval) {
|
||||||
return getText(DEFAULT_PROGRAM_NAME, interval);
|
return getText(DEFAULT_PROGRAM_NAME, interval);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::wstring TokenStreamRewriter::getText(const std::wstring &programName, Interval *interval) {
|
std::wstring TokenStreamRewriter::getText(const std::wstring &programName, const Interval &interval) {
|
||||||
std::vector<TokenStreamRewriter::RewriteOperation*> rewrites = programs->at(programName);
|
std::vector<TokenStreamRewriter::RewriteOperation*> rewrites = programs->at(programName);
|
||||||
int start = interval->a;
|
int start = interval.a;
|
||||||
int stop = interval->b;
|
int stop = interval.b;
|
||||||
|
|
||||||
// ensure start/end are in range
|
// ensure start/end are in range
|
||||||
if (stop > (int)tokens->size() - 1) {
|
if (stop > (int)tokens->size() - 1) {
|
||||||
|
@ -284,7 +286,7 @@ std::wstring TokenStreamRewriter::getText(const std::wstring &programName, Inter
|
||||||
while (i <= (size_t)stop && i < tokens->size()) {
|
while (i <= (size_t)stop && i < tokens->size()) {
|
||||||
RewriteOperation *op = indexToOp->at((int)i);
|
RewriteOperation *op = indexToOp->at((int)i);
|
||||||
indexToOp->erase((int)i); // remove so any left have index size-1
|
indexToOp->erase((int)i); // remove so any left have index size-1
|
||||||
Token *t = tokens->get((int)i);
|
Token *t = tokens->get(i);
|
||||||
if (op == nullptr) {
|
if (op == nullptr) {
|
||||||
// no operation at that index, just dump token
|
// no operation at that index, just dump token
|
||||||
if (t->getType() != Token::_EOF) {
|
if (t->getType() != Token::_EOF) {
|
||||||
|
@ -304,7 +306,7 @@ std::wstring TokenStreamRewriter::getText(const std::wstring &programName, Inter
|
||||||
// Scan any remaining operations after last token
|
// Scan any remaining operations after last token
|
||||||
// should be included (they will be inserts).
|
// should be included (they will be inserts).
|
||||||
for (auto op : *indexToOp) {
|
for (auto op : *indexToOp) {
|
||||||
if (op.second->index >= (int)tokens->size() - 1) {
|
if (op.second->index >= tokens->size() - 1) {
|
||||||
buf.append(op.second->text);
|
buf.append(op.second->text);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -327,29 +329,29 @@ std::unordered_map<int, TokenStreamRewriter::RewriteOperation*> *TokenStreamRewr
|
||||||
ReplaceOp *rop = static_cast<ReplaceOp*>(op);
|
ReplaceOp *rop = static_cast<ReplaceOp*>(op);
|
||||||
// Wipe prior inserts within range
|
// Wipe prior inserts within range
|
||||||
InsertBeforeOp* type = nullptr;
|
InsertBeforeOp* type = nullptr;
|
||||||
std::vector<InsertBeforeOp*> inserts = getKindOfOps(rewrites, type, (int)i);
|
std::vector<InsertBeforeOp*> inserts = getKindOfOps(rewrites, type, i);
|
||||||
for (auto iop : inserts) {
|
for (auto iop : inserts) {
|
||||||
if (iop->index == rop->index) {
|
if (iop->index == rop->index) {
|
||||||
// E.g., insert before 2, delete 2..2; update replace
|
// E.g., insert before 2, delete 2..2; update replace
|
||||||
// text to include insert before, kill insert
|
// text to include insert before, kill insert
|
||||||
//JAVA TO C++ CONVERTER WARNING: Java to C++ Converter converted the original 'null' assignment to a call to 'delete', but you should review memory allocation of all pointer variables in the converted code:
|
//JAVA TO C++ CONVERTER WARNING: Java to C++ Converter converted the original 'null' assignment to a call to 'delete', but you should review memory allocation of all pointer variables in the converted code:
|
||||||
delete rewrites[iop->instructionIndex];
|
delete rewrites[(size_t)iop->instructionIndex];
|
||||||
rop->text = iop->text + (!rop->text.empty() ? rop->text : L"");
|
rop->text = iop->text + (!rop->text.empty() ? rop->text : L"");
|
||||||
}
|
}
|
||||||
else if (iop->index > rop->index && iop->index <= rop->lastIndex) {
|
else if (iop->index > rop->index && iop->index <= rop->lastIndex) {
|
||||||
// delete insert as it's a no-op.
|
// delete insert as it's a no-op.
|
||||||
//JAVA TO C++ CONVERTER WARNING: Java to C++ Converter converted the original 'null' assignment to a call to 'delete', but you should review memory allocation of all pointer variables in the converted code:
|
//JAVA TO C++ CONVERTER WARNING: Java to C++ Converter converted the original 'null' assignment to a call to 'delete', but you should review memory allocation of all pointer variables in the converted code:
|
||||||
delete rewrites[iop->instructionIndex];
|
delete rewrites[(size_t)iop->instructionIndex];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Drop any prior replaces contained within
|
// Drop any prior replaces contained within
|
||||||
ReplaceOp* type2 = nullptr;
|
ReplaceOp* type2 = nullptr;
|
||||||
std::vector<ReplaceOp*> prevReplaces = getKindOfOps(rewrites, type2, (int)i);
|
std::vector<ReplaceOp*> prevReplaces = getKindOfOps(rewrites, type2, i);
|
||||||
for (auto prevRop : prevReplaces) {
|
for (auto prevRop : prevReplaces) {
|
||||||
if (prevRop->index >= rop->index && prevRop->lastIndex <= rop->lastIndex) {
|
if (prevRop->index >= rop->index && prevRop->lastIndex <= rop->lastIndex) {
|
||||||
// delete replace as it's a no-op.
|
// delete replace as it's a no-op.
|
||||||
//JAVA TO C++ CONVERTER WARNING: Java to C++ Converter converted the original 'null' assignment to a call to 'delete', but you should review memory allocation of all pointer variables in the converted code:
|
//JAVA TO C++ CONVERTER WARNING: Java to C++ Converter converted the original 'null' assignment to a call to 'delete', but you should review memory allocation of all pointer variables in the converted code:
|
||||||
delete rewrites[prevRop->instructionIndex];
|
delete rewrites[(size_t)prevRop->instructionIndex];
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
// throw exception unless disjoint or identical
|
// throw exception unless disjoint or identical
|
||||||
|
@ -360,7 +362,7 @@ std::unordered_map<int, TokenStreamRewriter::RewriteOperation*> *TokenStreamRewr
|
||||||
if (prevRop->text.empty() && rop->text.empty() && !disjoint) {
|
if (prevRop->text.empty() && rop->text.empty() && !disjoint) {
|
||||||
//System.out.println("overlapping deletes: "+prevRop+", "+rop);
|
//System.out.println("overlapping deletes: "+prevRop+", "+rop);
|
||||||
//JAVA TO C++ CONVERTER WARNING: Java to C++ Converter converted the original 'null' assignment to a call to 'delete', but you should review memory allocation of all pointer variables in the converted code:
|
//JAVA TO C++ CONVERTER WARNING: Java to C++ Converter converted the original 'null' assignment to a call to 'delete', but you should review memory allocation of all pointer variables in the converted code:
|
||||||
delete rewrites[prevRop->instructionIndex]; // kill first delete
|
delete rewrites[(size_t)prevRop->instructionIndex]; // kill first delete
|
||||||
rop->index = std::min(prevRop->index, rop->index);
|
rop->index = std::min(prevRop->index, rop->index);
|
||||||
rop->lastIndex = std::max(prevRop->lastIndex, rop->lastIndex);
|
rop->lastIndex = std::max(prevRop->lastIndex, rop->lastIndex);
|
||||||
std::wcout << L"new rop " << rop << std::endl;
|
std::wcout << L"new rop " << rop << std::endl;
|
||||||
|
@ -383,7 +385,7 @@ std::unordered_map<int, TokenStreamRewriter::RewriteOperation*> *TokenStreamRewr
|
||||||
InsertBeforeOp *iop = static_cast<InsertBeforeOp*>(rewrites[i]);
|
InsertBeforeOp *iop = static_cast<InsertBeforeOp*>(rewrites[i]);
|
||||||
// combine current insert with prior if any at same index
|
// combine current insert with prior if any at same index
|
||||||
|
|
||||||
std::vector<InsertBeforeOp*> prevInserts = getKindOfOps(rewrites, iop, (int)i);
|
std::vector<InsertBeforeOp*> prevInserts = getKindOfOps(rewrites, iop, i);
|
||||||
for (auto prevIop : prevInserts) {
|
for (auto prevIop : prevInserts) {
|
||||||
if (prevIop->index == iop->index) { // combine objects
|
if (prevIop->index == iop->index) { // combine objects
|
||||||
// convert to strings...we're in process of toString'ing
|
// convert to strings...we're in process of toString'ing
|
||||||
|
@ -391,12 +393,12 @@ std::unordered_map<int, TokenStreamRewriter::RewriteOperation*> *TokenStreamRewr
|
||||||
iop->text = catOpText(&iop->text, &prevIop->text);
|
iop->text = catOpText(&iop->text, &prevIop->text);
|
||||||
// delete redundant prior insert
|
// delete redundant prior insert
|
||||||
//JAVA TO C++ CONVERTER WARNING: Java to C++ Converter converted the original 'null' assignment to a call to 'delete', but you should review memory allocation of all pointer variables in the converted code:
|
//JAVA TO C++ CONVERTER WARNING: Java to C++ Converter converted the original 'null' assignment to a call to 'delete', but you should review memory allocation of all pointer variables in the converted code:
|
||||||
delete rewrites[prevIop->instructionIndex];
|
delete rewrites[(size_t)prevIop->instructionIndex];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// look for replaces where iop.index is in range; error
|
// look for replaces where iop.index is in range; error
|
||||||
ReplaceOp *type = nullptr;
|
ReplaceOp *type = nullptr;
|
||||||
std::vector<ReplaceOp*> prevReplaces = getKindOfOps(rewrites, type, (int)i);
|
std::vector<ReplaceOp*> prevReplaces = getKindOfOps(rewrites, type, i);
|
||||||
for (auto rop : prevReplaces) {
|
for (auto rop : prevReplaces) {
|
||||||
if (iop->index == rop->index) {
|
if (iop->index == rop->index) {
|
||||||
rop->text = catOpText(&iop->text, &rop->text);
|
rop->text = catOpText(&iop->text, &rop->text);
|
||||||
|
@ -415,7 +417,7 @@ std::unordered_map<int, TokenStreamRewriter::RewriteOperation*> *TokenStreamRewr
|
||||||
if (op == nullptr) { // ignore deleted ops
|
if (op == nullptr) { // ignore deleted ops
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (m->at(op->index) != nullptr) {
|
if (m->at((int)op->index) != nullptr) {
|
||||||
// TODO: use a specific exception rather than a generic type here?
|
// TODO: use a specific exception rather than a generic type here?
|
||||||
throw new ANTLRException(L"should only be one op per index");
|
throw new ANTLRException(L"should only be one op per index");
|
||||||
}
|
}
|
||||||
|
|
|
@ -104,25 +104,25 @@ namespace runtime {
|
||||||
private:
|
private:
|
||||||
TokenStreamRewriter *const outerInstance;
|
TokenStreamRewriter *const outerInstance;
|
||||||
|
|
||||||
|
public:
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// What index into rewrites List are we? </summary>
|
/// What index into rewrites List are we? </summary>
|
||||||
public:
|
|
||||||
virtual ~RewriteOperation() {};
|
virtual ~RewriteOperation() {};
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Token buffer index. </summary>
|
/// Token buffer index. </summary>
|
||||||
int index;
|
size_t index;
|
||||||
std::wstring text;
|
std::wstring text;
|
||||||
|
|
||||||
RewriteOperation(TokenStreamRewriter *outerInstance, int index);
|
RewriteOperation(TokenStreamRewriter *outerInstance, size_t index);
|
||||||
|
|
||||||
RewriteOperation(TokenStreamRewriter *outerInstance, int index, const std::wstring& text);
|
RewriteOperation(TokenStreamRewriter *outerInstance, size_t index, const std::wstring& text);
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Execute the rewrite operation by possibly adding to the buffer.
|
/// Execute the rewrite operation by possibly adding to the buffer.
|
||||||
/// Return the index of the next token to operate on.
|
/// Return the index of the next token to operate on.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
int instructionIndex;
|
int instructionIndex;
|
||||||
|
|
||||||
virtual int execute(std::wstring *buf);
|
virtual size_t execute(std::wstring *buf);
|
||||||
|
|
||||||
virtual std::wstring toString();
|
virtual std::wstring toString();
|
||||||
|
|
||||||
|
@ -136,9 +136,9 @@ namespace runtime {
|
||||||
TokenStreamRewriter *const outerInstance;
|
TokenStreamRewriter *const outerInstance;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
InsertBeforeOp(TokenStreamRewriter *outerInstance, int index, const std::wstring& text);
|
InsertBeforeOp(TokenStreamRewriter *outerInstance, size_t index, const std::wstring& text);
|
||||||
|
|
||||||
virtual int execute(std::wstring *buf) override;
|
virtual size_t execute(std::wstring *buf) override;
|
||||||
};
|
};
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
@ -147,10 +147,10 @@ namespace runtime {
|
||||||
TokenStreamRewriter *const outerInstance;
|
TokenStreamRewriter *const outerInstance;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
int lastIndex;
|
size_t lastIndex;
|
||||||
|
|
||||||
ReplaceOp(TokenStreamRewriter *outerInstance, int from, int to, const std::wstring& text);
|
ReplaceOp(TokenStreamRewriter *outerInstance, size_t from, size_t to, const std::wstring& text);
|
||||||
virtual int execute(std::wstring *buf) override;
|
virtual size_t execute(std::wstring *buf) override;
|
||||||
virtual std::wstring toString() override;
|
virtual std::wstring toString() override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
@ -204,46 +204,29 @@ namespace runtime {
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Reset the program so that no instructions exist </summary>
|
/// Reset the program so that no instructions exist </summary>
|
||||||
virtual void deleteProgram(const std::wstring &programName);
|
virtual void deleteProgram(const std::wstring &programName);
|
||||||
|
|
||||||
virtual void insertAfter(Token *t, const std::wstring& text);
|
virtual void insertAfter(Token *t, const std::wstring& text);
|
||||||
|
virtual void insertAfter(size_t index, const std::wstring& text);
|
||||||
virtual void insertAfter(int index, const std::wstring& text);
|
|
||||||
|
|
||||||
virtual void insertAfter(const std::wstring &programName, Token *t, const std::wstring& text);
|
virtual void insertAfter(const std::wstring &programName, Token *t, const std::wstring& text);
|
||||||
|
virtual void insertAfter(const std::wstring &programName, size_t index, const std::wstring& text);
|
||||||
virtual void insertAfter(const std::wstring &programName, int index, const std::wstring& text);
|
|
||||||
|
|
||||||
virtual void insertBefore(Token *t, const std::wstring& text);
|
virtual void insertBefore(Token *t, const std::wstring& text);
|
||||||
|
virtual void insertBefore(size_t index, const std::wstring& text);
|
||||||
virtual void insertBefore(int index, const std::wstring& text);
|
|
||||||
|
|
||||||
virtual void insertBefore(const std::wstring &programName, Token *t, const std::wstring& text);
|
virtual void insertBefore(const std::wstring &programName, Token *t, const std::wstring& text);
|
||||||
|
virtual void insertBefore(const std::wstring &programName, size_t index, const std::wstring& text);
|
||||||
|
|
||||||
virtual void insertBefore(const std::wstring &programName, int index, const std::wstring& text);
|
virtual void replace(size_t index, const std::wstring& text);
|
||||||
|
virtual void replace(size_t from, size_t to, const std::wstring& text);
|
||||||
virtual void replace(int index, const std::wstring& text);
|
|
||||||
|
|
||||||
virtual void replace(int from, int to, const std::wstring& text);
|
|
||||||
|
|
||||||
virtual void replace(Token *indexT, const std::wstring& text);
|
virtual void replace(Token *indexT, const std::wstring& text);
|
||||||
|
|
||||||
virtual void replace(Token *from, Token *to, const std::wstring& text);
|
virtual void replace(Token *from, Token *to, const std::wstring& text);
|
||||||
|
virtual void replace(const std::wstring &programName, size_t from, size_t to, const std::wstring& text);
|
||||||
virtual void replace(const std::wstring &programName, int from, int to, const std::wstring& text);
|
|
||||||
|
|
||||||
virtual void replace(const std::wstring &programName, Token *from, Token *to, const std::wstring& text);
|
virtual void replace(const std::wstring &programName, Token *from, Token *to, const std::wstring& text);
|
||||||
|
|
||||||
virtual void delete_Renamed(int index);
|
virtual void Delete(size_t index);
|
||||||
|
virtual void Delete(size_t from, size_t to);
|
||||||
virtual void delete_Renamed(int from, int to);
|
virtual void Delete(Token *indexT);
|
||||||
|
virtual void Delete(Token *from, Token *to);
|
||||||
virtual void delete_Renamed(Token *indexT);
|
virtual void Delete(const std::wstring &programName, size_t from, size_t to);
|
||||||
|
virtual void Delete(const std::wstring &programName, Token *from, Token *to);
|
||||||
virtual void delete_Renamed(Token *from, Token *to);
|
|
||||||
|
|
||||||
virtual void delete_Renamed(const std::wstring &programName, int from, int to);
|
|
||||||
|
|
||||||
virtual void delete_Renamed(const std::wstring &programName, Token *from, Token *to);
|
|
||||||
|
|
||||||
virtual int getLastRewriteTokenIndex();
|
virtual int getLastRewriteTokenIndex();
|
||||||
|
|
||||||
|
@ -274,9 +257,9 @@ namespace runtime {
|
||||||
/// insertBefore on the first token, you would get that insertion.
|
/// insertBefore on the first token, you would get that insertion.
|
||||||
/// The same is true if you do an insertAfter the stop token.
|
/// The same is true if you do an insertAfter the stop token.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
virtual std::wstring getText(misc::Interval *interval);
|
virtual std::wstring getText(const misc::Interval &interval);
|
||||||
|
|
||||||
virtual std::wstring getText(const std::wstring &programName, misc::Interval *interval);
|
virtual std::wstring getText(const std::wstring &programName, const misc::Interval &interval);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// We need to combine operations and report invalid operations (like
|
/// We need to combine operations and report invalid operations (like
|
||||||
|
@ -336,9 +319,9 @@ namespace runtime {
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Get all operations before an index of a particular kind </summary>
|
/// Get all operations before an index of a particular kind </summary>
|
||||||
template <typename T, typename T1>
|
template <typename T, typename T1>
|
||||||
std::vector<T*> getKindOfOps(std::vector<T1*> rewrites, T *kind, int before) {
|
std::vector<T*> getKindOfOps(std::vector<T1*> rewrites, T *kind, size_t before) {
|
||||||
std::vector<T*> ops = std::vector<T*>();
|
std::vector<T*> ops = std::vector<T*>();
|
||||||
for (int i = 0; i < before && i < (int)rewrites.size(); i++) {
|
for (size_t i = 0; i < before && i < rewrites.size(); i++) {
|
||||||
TokenStreamRewriter::RewriteOperation *op = dynamic_cast<RewriteOperation*>(rewrites[i]);
|
TokenStreamRewriter::RewriteOperation *op = dynamic_cast<RewriteOperation*>(rewrites[i]);
|
||||||
if (op == nullptr) { // ignore deleted
|
if (op == nullptr) { // ignore deleted
|
||||||
continue;
|
continue;
|
||||||
|
|
|
@ -39,7 +39,7 @@ using namespace org::antlr::v4::runtime;
|
||||||
UnbufferedCharStream::UnbufferedCharStream() {
|
UnbufferedCharStream::UnbufferedCharStream() {
|
||||||
}
|
}
|
||||||
|
|
||||||
UnbufferedCharStream::UnbufferedCharStream(int bufferSize) {
|
UnbufferedCharStream::UnbufferedCharStream(size_t bufferSize) {
|
||||||
InitializeInstanceFields();
|
InitializeInstanceFields();
|
||||||
n = 0;
|
n = 0;
|
||||||
data = new wchar_t[bufferSize];
|
data = new wchar_t[bufferSize];
|
||||||
|
@ -63,30 +63,31 @@ void UnbufferedCharStream::consume() {
|
||||||
|
|
||||||
if (p == n - 1 && numMarkers == 0) {
|
if (p == n - 1 && numMarkers == 0) {
|
||||||
n = 0;
|
n = 0;
|
||||||
p = -1; // p++ will leave this at 0
|
p = 0;
|
||||||
lastCharBufferStart = lastChar;
|
lastCharBufferStart = lastChar;
|
||||||
|
} else {
|
||||||
|
p++;
|
||||||
}
|
}
|
||||||
|
|
||||||
p++;
|
|
||||||
currentCharIndex++;
|
currentCharIndex++;
|
||||||
sync(1);
|
sync(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
void UnbufferedCharStream::sync(int want) {
|
void UnbufferedCharStream::sync(size_t want) {
|
||||||
int need = (p + want - 1) - n + 1; // how many more elements we need?
|
size_t need = (p + want - 1) - n + 1; // how many more elements we need?
|
||||||
if (need > 0) {
|
if (need > 0) {
|
||||||
fill(need);
|
fill(need);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int UnbufferedCharStream::fill(int n) {
|
size_t UnbufferedCharStream::fill(size_t n) {
|
||||||
for (int i = 0; i < n; i++) {
|
for (size_t i = 0; i < n; i++) {
|
||||||
if (this->n > 0 && data[this->n - 1] == static_cast<wchar_t>(IntStream::_EOF)) {
|
if (this->n > 0 && data[this->n - 1] == static_cast<wchar_t>(IntStream::_EOF)) {
|
||||||
return i;
|
return i;
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
int c = nextChar();
|
size_t c = nextChar();
|
||||||
add(c);
|
add(c);
|
||||||
} catch (IOException ioe) {
|
} catch (IOException ioe) {
|
||||||
throw std::exception(ioe);
|
throw std::exception(ioe);
|
||||||
|
@ -96,48 +97,48 @@ int UnbufferedCharStream::fill(int n) {
|
||||||
return n;
|
return n;
|
||||||
}
|
}
|
||||||
|
|
||||||
int UnbufferedCharStream::nextChar() {
|
size_t UnbufferedCharStream::nextChar() {
|
||||||
return input->get();
|
return (size_t)input->get();
|
||||||
}
|
}
|
||||||
|
|
||||||
void UnbufferedCharStream::add(int c) {
|
void UnbufferedCharStream::add(size_t c) {
|
||||||
if (n >= (int)data.size()) {
|
if (n >= data.size()) {
|
||||||
data.reserve(data.size()*2);
|
data.reserve(data.size()*2);
|
||||||
}
|
}
|
||||||
data[n++] = static_cast<wchar_t>(c);
|
data[n++] = static_cast<wchar_t>(c);
|
||||||
}
|
}
|
||||||
|
|
||||||
int UnbufferedCharStream::LA(int i) {
|
size_t UnbufferedCharStream::LA(ssize_t i) {
|
||||||
if (i == -1) { // special case
|
if (i == -1) { // special case
|
||||||
return lastChar;
|
return (size_t)lastChar;
|
||||||
}
|
}
|
||||||
sync(i);
|
sync((size_t)i);
|
||||||
int index = p + i - 1;
|
ssize_t index = (ssize_t)p + i - 1;
|
||||||
if (index < 0) {
|
if (index < 0) {
|
||||||
throw new IndexOutOfBoundsException();
|
throw new IndexOutOfBoundsException();
|
||||||
}
|
}
|
||||||
if (index >= n) {
|
if ((size_t)index >= n) {
|
||||||
return IntStream::_EOF;
|
return IntStream::_EOF;
|
||||||
}
|
}
|
||||||
wchar_t c = data[index];
|
size_t c = (size_t)data[(size_t)index];
|
||||||
if (c == static_cast<wchar_t>(IntStream::_EOF)) {
|
if (c == IntStream::_EOF) {
|
||||||
return IntStream::_EOF;
|
return IntStream::_EOF;
|
||||||
}
|
}
|
||||||
return c;
|
return c;
|
||||||
}
|
}
|
||||||
|
|
||||||
int UnbufferedCharStream::mark() {
|
ssize_t UnbufferedCharStream::mark() {
|
||||||
if (numMarkers == 0) {
|
if (numMarkers == 0) {
|
||||||
lastCharBufferStart = lastChar;
|
lastCharBufferStart = lastChar;
|
||||||
}
|
}
|
||||||
|
|
||||||
int mark = -numMarkers - 1;
|
ssize_t mark = -(ssize_t)numMarkers - 1;
|
||||||
numMarkers++;
|
numMarkers++;
|
||||||
return mark;
|
return mark;
|
||||||
}
|
}
|
||||||
|
|
||||||
void UnbufferedCharStream::release(int marker) {
|
void UnbufferedCharStream::release(ssize_t marker) {
|
||||||
int expectedMark = -numMarkers;
|
ssize_t expectedMark = -(ssize_t)numMarkers;
|
||||||
if (marker != expectedMark) {
|
if (marker != expectedMark) {
|
||||||
throw IllegalStateException(L"release() called with an invalid marker.");
|
throw IllegalStateException(L"release() called with an invalid marker.");
|
||||||
}
|
}
|
||||||
|
@ -151,11 +152,11 @@ void UnbufferedCharStream::release(int marker) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int UnbufferedCharStream::index() {
|
size_t UnbufferedCharStream::index() {
|
||||||
return currentCharIndex;
|
return currentCharIndex;
|
||||||
}
|
}
|
||||||
|
|
||||||
void UnbufferedCharStream::seek(int index) {
|
void UnbufferedCharStream::seek(size_t index) {
|
||||||
if (index == currentCharIndex) {
|
if (index == currentCharIndex) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -166,14 +167,14 @@ void UnbufferedCharStream::seek(int index) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// index == to bufferStartIndex should set p to 0
|
// index == to bufferStartIndex should set p to 0
|
||||||
int i = index - getBufferStartIndex();
|
ssize_t i = (ssize_t)index - (ssize_t)getBufferStartIndex();
|
||||||
if (i < 0) {
|
if (i < 0) {
|
||||||
throw IllegalArgumentException(std::wstring(L"cannot seek to negative index ") + std::to_wstring(index));
|
throw IllegalArgumentException(std::wstring(L"cannot seek to negative index ") + std::to_wstring(index));
|
||||||
} else if (i >= n) {
|
} else if (i >= (ssize_t)n) {
|
||||||
throw UnsupportedOperationException(std::wstring(L"seek to index outside buffer: ") + std::to_wstring(index) + std::wstring(L" not in ") + std::to_wstring(getBufferStartIndex()) + std::wstring(L"..") + std::to_wstring(getBufferStartIndex() + n));
|
throw UnsupportedOperationException(std::wstring(L"seek to index outside buffer: ") + std::to_wstring(index) + std::wstring(L" not in ") + std::to_wstring(getBufferStartIndex()) + std::wstring(L"..") + std::to_wstring(getBufferStartIndex() + n));
|
||||||
}
|
}
|
||||||
|
|
||||||
p = i;
|
p = (size_t)i;
|
||||||
currentCharIndex = index;
|
currentCharIndex = index;
|
||||||
if (p == 0) {
|
if (p == 0) {
|
||||||
lastChar = lastCharBufferStart;
|
lastChar = lastCharBufferStart;
|
||||||
|
@ -190,27 +191,27 @@ std::string UnbufferedCharStream::getSourceName() {
|
||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::wstring UnbufferedCharStream::getText(misc::Interval *interval) {
|
std::wstring UnbufferedCharStream::getText(const misc::Interval &interval) {
|
||||||
if (interval->a < 0 || interval->b < interval->a - 1) {
|
if (interval.a < 0 || interval.b < interval.a - 1) {
|
||||||
throw IllegalArgumentException(std::wstring(L"invalid interval"));
|
throw IllegalArgumentException(std::wstring(L"invalid interval"));
|
||||||
}
|
}
|
||||||
|
|
||||||
int bufferStartIndex = getBufferStartIndex();
|
size_t bufferStartIndex = getBufferStartIndex();
|
||||||
if (n > 0 && data[n - 1] == WCHAR_MAX) {
|
if (n > 0 && data[n - 1] == WCHAR_MAX) {
|
||||||
if (interval->a + interval->length() > bufferStartIndex + n) {
|
if ((size_t)(interval.a + interval.length()) > bufferStartIndex + n) {
|
||||||
throw IllegalArgumentException(std::wstring(L"the interval extends past the end of the stream"));
|
throw IllegalArgumentException(std::wstring(L"the interval extends past the end of the stream"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (interval->a < bufferStartIndex || interval->b >= bufferStartIndex + n) {
|
if ((size_t)interval.a < bufferStartIndex || (size_t)interval.b >= bufferStartIndex + n) {
|
||||||
throw UnsupportedOperationException(std::wstring(L"interval ") + interval->toString() + std::wstring(L" outside buffer: ") + std::to_wstring(bufferStartIndex) + std::wstring(L"..") + std::to_wstring(bufferStartIndex + n - 1));
|
throw UnsupportedOperationException(std::wstring(L"interval ") + interval.toString() + std::wstring(L" outside buffer: ") + std::to_wstring(bufferStartIndex) + std::wstring(L"..") + std::to_wstring(bufferStartIndex + n - 1));
|
||||||
}
|
}
|
||||||
// convert from absolute to local index
|
// convert from absolute to local index
|
||||||
int i = interval->a - bufferStartIndex;
|
size_t i = (size_t)interval.a - bufferStartIndex;
|
||||||
return std::wstring(data, i, interval->length());
|
return std::wstring(data, i, (size_t)interval.length());
|
||||||
}
|
}
|
||||||
|
|
||||||
int UnbufferedCharStream::getBufferStartIndex() {
|
size_t UnbufferedCharStream::getBufferStartIndex() {
|
||||||
return currentCharIndex - p;
|
return currentCharIndex - p;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -58,7 +58,7 @@ namespace runtime {
|
||||||
/// <p/>
|
/// <p/>
|
||||||
/// This is not the buffer capacity, that's {@code data.length}.
|
/// This is not the buffer capacity, that's {@code data.length}.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
int n;
|
size_t n;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 0..n-1 index into <seealso cref="#data data"/> of next character.
|
/// 0..n-1 index into <seealso cref="#data data"/> of next character.
|
||||||
|
@ -66,7 +66,7 @@ namespace runtime {
|
||||||
/// The {@code LA(1)} character is {@code data[p]}. If {@code p == n}, we are
|
/// The {@code LA(1)} character is {@code data[p]}. If {@code p == n}, we are
|
||||||
/// out of buffered characters.
|
/// out of buffered characters.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
int p;
|
size_t p;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Count up with <seealso cref="#mark mark()"/> and down with
|
/// Count up with <seealso cref="#mark mark()"/> and down with
|
||||||
|
@ -74,18 +74,18 @@ namespace runtime {
|
||||||
/// {@code numMarkers} reaches 0 and we reset the buffer. Copy
|
/// {@code numMarkers} reaches 0 and we reset the buffer. Copy
|
||||||
/// {@code data[p]..data[n-1]} to {@code data[0]..data[(n-1)-p]}.
|
/// {@code data[p]..data[n-1]} to {@code data[0]..data[(n-1)-p]}.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
int numMarkers;
|
size_t numMarkers;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// This is the {@code LA(-1)} character for the current position.
|
/// This is the {@code LA(-1)} character for the current position.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
int lastChar;
|
wchar_t lastChar;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// When {@code numMarkers > 0}, this is the {@code LA(-1)} character for the
|
/// When {@code numMarkers > 0}, this is the {@code LA(-1)} character for the
|
||||||
/// first character in <seealso cref="#data data"/>. Otherwise, this is unspecified.
|
/// first character in <seealso cref="#data data"/>. Otherwise, this is unspecified.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
int lastCharBufferStart;
|
wchar_t lastCharBufferStart;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Absolute character index. It's the index of the character about to be
|
/// Absolute character index. It's the index of the character about to be
|
||||||
|
@ -93,7 +93,7 @@ namespace runtime {
|
||||||
/// entire stream, although the stream size is unknown before the end is
|
/// entire stream, although the stream size is unknown before the end is
|
||||||
/// reached.
|
/// reached.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
int currentCharIndex;
|
size_t currentCharIndex;
|
||||||
|
|
||||||
std::ifstream *input;
|
std::ifstream *input;
|
||||||
|
|
||||||
|
@ -109,7 +109,7 @@ namespace runtime {
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Useful for subclasses that pull char from other than this.input. </summary>
|
/// Useful for subclasses that pull char from other than this.input. </summary>
|
||||||
UnbufferedCharStream(int bufferSize);
|
UnbufferedCharStream(size_t bufferSize);
|
||||||
|
|
||||||
|
|
||||||
UnbufferedCharStream(std::ifstream *input); //this(input, 256);
|
UnbufferedCharStream(std::ifstream *input); //this(input, 256);
|
||||||
|
@ -120,31 +120,31 @@ namespace runtime {
|
||||||
virtual void consume() override;
|
virtual void consume() override;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Make sure we have 'need' elements from current position <seealso cref="#p p"/>.
|
/// Make sure we have 'want' elements from current position <seealso cref="#p p"/>.
|
||||||
/// Last valid {@code p} index is {@code data.length-1}. {@code p+need-1} is
|
/// Last valid {@code p} index is {@code data.length-1}. {@code p+need-1} is
|
||||||
/// the char index 'need' elements ahead. If we need 1 element,
|
/// the char index 'need' elements ahead. If we need 1 element,
|
||||||
/// {@code (p+1-1)==p} must be less than {@code data.length}.
|
/// {@code (p+1-1)==p} must be less than {@code data.length}.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
protected:
|
protected:
|
||||||
virtual void sync(int want);
|
virtual void sync(size_t want);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Add {@code n} characters to the buffer. Returns the number of characters
|
/// Add {@code n} characters to the buffer. Returns the number of characters
|
||||||
/// actually added to the buffer. If the return value is less than {@code n},
|
/// actually added to the buffer. If the return value is less than {@code n},
|
||||||
/// then EOF was reached before {@code n} characters could be added.
|
/// then EOF was reached before {@code n} characters could be added.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
virtual int fill(int n);
|
virtual size_t fill(size_t n);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Override to provide different source of characters than
|
/// Override to provide different source of characters than
|
||||||
/// <seealso cref="#input input"/>.
|
/// <seealso cref="#input input"/>.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
virtual int nextChar();
|
virtual size_t nextChar();
|
||||||
|
|
||||||
virtual void add(int c);
|
virtual void add(size_t c);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
virtual int LA(int i) override;
|
virtual size_t LA(ssize_t i) override;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Return a marker that we can release later.
|
/// Return a marker that we can release later.
|
||||||
|
@ -153,29 +153,29 @@ namespace runtime {
|
||||||
/// protection against misuse where {@code seek()} is called on a mark or
|
/// protection against misuse where {@code seek()} is called on a mark or
|
||||||
/// {@code release()} is called in the wrong order.
|
/// {@code release()} is called in the wrong order.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
virtual int mark() override;
|
virtual ssize_t mark() override;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Decrement number of markers, resetting buffer if we hit 0. </summary>
|
/// Decrement number of markers, resetting buffer if we hit 0. </summary>
|
||||||
/// <param name="marker"> </param>
|
/// <param name="marker"> </param>
|
||||||
virtual void release(int marker) override;
|
virtual void release(ssize_t marker) override;
|
||||||
|
|
||||||
virtual int index() override;
|
virtual size_t index() override;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Seek to absolute character index, which might not be in the current
|
/// Seek to absolute character index, which might not be in the current
|
||||||
/// sliding window. Move {@code p} to {@code index-bufferStartIndex}.
|
/// sliding window. Move {@code p} to {@code index-bufferStartIndex}.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
virtual void seek(int index) override;
|
virtual void seek(size_t index) override;
|
||||||
|
|
||||||
virtual size_t size() override;
|
virtual size_t size() override;
|
||||||
|
|
||||||
virtual std::string getSourceName() override;
|
virtual std::string getSourceName() override;
|
||||||
|
|
||||||
virtual std::wstring getText(misc::Interval *interval) override;
|
virtual std::wstring getText(const misc::Interval &interval) override;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
int getBufferStartIndex();
|
size_t getBufferStartIndex();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void InitializeInstanceFields();
|
void InitializeInstanceFields();
|
||||||
|
|
|
@ -38,7 +38,6 @@ namespace antlr {
|
||||||
namespace v4 {
|
namespace v4 {
|
||||||
namespace runtime {
|
namespace runtime {
|
||||||
|
|
||||||
template<typename T>
|
|
||||||
class UnbufferedTokenStream : public TokenStream {
|
class UnbufferedTokenStream : public TokenStream {
|
||||||
protected:
|
protected:
|
||||||
TokenSource *tokenSource;
|
TokenSource *tokenSource;
|
||||||
|
|
|
@ -45,13 +45,10 @@ namespace antlr {
|
||||||
namespace v4 {
|
namespace v4 {
|
||||||
namespace runtime {
|
namespace runtime {
|
||||||
|
|
||||||
template <typename T>
|
UnbufferedTokenStream::UnbufferedTokenStream(TokenSource* tokenSource) : UnbufferedTokenStream(tokenSource, 256) {
|
||||||
UnbufferedTokenStream<T>::UnbufferedTokenStream(TokenSource* tokenSource)
|
|
||||||
{ //this(tokenSource, 256);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T>
|
UnbufferedTokenStream::UnbufferedTokenStream(TokenSource* tokenSource, int bufferSize)
|
||||||
UnbufferedTokenStream<T>::UnbufferedTokenStream(TokenSource* tokenSource, int bufferSize)
|
|
||||||
{
|
{
|
||||||
InitializeInstanceFields();
|
InitializeInstanceFields();
|
||||||
this->tokenSource = tokenSource;
|
this->tokenSource = tokenSource;
|
||||||
|
@ -60,8 +57,7 @@ namespace runtime {
|
||||||
fill(1); // prime the pump
|
fill(1); // prime the pump
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T>
|
Token* UnbufferedTokenStream::get(int i)
|
||||||
Token* UnbufferedTokenStream<T>::get(int i)
|
|
||||||
{ // get absolute index
|
{ // get absolute index
|
||||||
int bufferStartIndex = getBufferStartIndex();
|
int bufferStartIndex = getBufferStartIndex();
|
||||||
if (i < bufferStartIndex || i >= bufferStartIndex + n) {
|
if (i < bufferStartIndex || i >= bufferStartIndex + n) {
|
||||||
|
@ -70,8 +66,7 @@ namespace runtime {
|
||||||
return tokens[i - bufferStartIndex];
|
return tokens[i - bufferStartIndex];
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T>
|
Token* UnbufferedTokenStream::LT(int i)
|
||||||
Token* UnbufferedTokenStream<T>::LT(int i)
|
|
||||||
{
|
{
|
||||||
if (i == -1) {
|
if (i == -1) {
|
||||||
return lastToken;
|
return lastToken;
|
||||||
|
@ -91,38 +86,32 @@ namespace runtime {
|
||||||
return tokens[index];
|
return tokens[index];
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T>
|
int UnbufferedTokenStream::LA(int i)
|
||||||
int UnbufferedTokenStream<T>::LA(int i)
|
|
||||||
{
|
{
|
||||||
return LT(i)->getType();
|
return LT(i)->getType();
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T>
|
TokenSource* UnbufferedTokenStream::getTokenSource()
|
||||||
TokenSource* UnbufferedTokenStream<T>::getTokenSource()
|
|
||||||
{
|
{
|
||||||
return tokenSource;
|
return tokenSource;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T>
|
std::wstring UnbufferedTokenStream::getText()
|
||||||
std::wstring UnbufferedTokenStream<T>::getText()
|
|
||||||
{
|
{
|
||||||
return L"";
|
return L"";
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T>
|
std::wstring UnbufferedTokenStream::getText(RuleContext* ctx)
|
||||||
std::wstring UnbufferedTokenStream<T>::getText(RuleContext* ctx)
|
|
||||||
{
|
{
|
||||||
return getText(ctx->getSourceInterval());
|
return getText(ctx->getSourceInterval());
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T>
|
std::wstring UnbufferedTokenStream::getText(Token* start, Token* stop)
|
||||||
std::wstring UnbufferedTokenStream<T>::getText(Token* start, Token* stop)
|
|
||||||
{
|
{
|
||||||
return getText(misc::Interval::of(start->getTokenIndex(), stop->getTokenIndex()));
|
return getText(misc::Interval::of(start->getTokenIndex(), stop->getTokenIndex()));
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T>
|
void UnbufferedTokenStream::consume()
|
||||||
void UnbufferedTokenStream<T>::consume()
|
|
||||||
{
|
{
|
||||||
if (LA(1) == Token::_EOF) {
|
if (LA(1) == Token::_EOF) {
|
||||||
throw new IllegalStateException(L"cannot consume EOF");
|
throw new IllegalStateException(L"cannot consume EOF");
|
||||||
|
@ -148,8 +137,7 @@ namespace runtime {
|
||||||
/// {@code p} index is {@code tokens.length-1}. {@code p+need-1} is the tokens index 'need' elements
|
/// {@code p} index is {@code tokens.length-1}. {@code p+need-1} is the tokens index 'need' elements
|
||||||
/// ahead. If we need 1 element, {@code (p+1-1)==p} must be less than {@code tokens.length}.
|
/// ahead. If we need 1 element, {@code (p+1-1)==p} must be less than {@code tokens.length}.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
template <typename T>
|
void UnbufferedTokenStream::sync(int want)
|
||||||
void UnbufferedTokenStream<T>::sync(int want)
|
|
||||||
{
|
{
|
||||||
int need = (p + want - 1) - n + 1; // how many more elements we need?
|
int need = (p + want - 1) - n + 1; // how many more elements we need?
|
||||||
if (need > 0) {
|
if (need > 0) {
|
||||||
|
@ -162,8 +150,7 @@ namespace runtime {
|
||||||
/// actually added to the buffer. If the return value is less than {@code n},
|
/// actually added to the buffer. If the return value is less than {@code n},
|
||||||
/// then EOF was reached before {@code n} tokens could be added.
|
/// then EOF was reached before {@code n} tokens could be added.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
template <typename T>
|
int UnbufferedTokenStream::fill(int n)
|
||||||
int UnbufferedTokenStream<T>::fill(int n)
|
|
||||||
{
|
{
|
||||||
for (int i = 0; i < n; i++) {
|
for (int i = 0; i < n; i++) {
|
||||||
if (this->n > 0 && tokens[this->n - 1]->getType() == Token::_EOF) {
|
if (this->n > 0 && tokens[this->n - 1]->getType() == Token::_EOF) {
|
||||||
|
@ -176,8 +163,8 @@ namespace runtime {
|
||||||
|
|
||||||
return n;
|
return n;
|
||||||
}
|
}
|
||||||
template <typename T>
|
|
||||||
void UnbufferedTokenStream<T>::add(Token* t)
|
void UnbufferedTokenStream::add(Token* t)
|
||||||
{
|
{
|
||||||
if (n >= tokens.size()) {
|
if (n >= tokens.size()) {
|
||||||
tokens = Arrays::copyOf(tokens, tokens.size() * 2);
|
tokens = Arrays::copyOf(tokens, tokens.size() * 2);
|
||||||
|
@ -197,8 +184,7 @@ namespace runtime {
|
||||||
/// protection against misuse where {@code seek()} is called on a mark or
|
/// protection against misuse where {@code seek()} is called on a mark or
|
||||||
/// {@code release()} is called in the wrong order.
|
/// {@code release()} is called in the wrong order.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
template <typename T>
|
int UnbufferedTokenStream::mark()
|
||||||
int UnbufferedTokenStream<T>::mark()
|
|
||||||
{
|
{
|
||||||
if (numMarkers == 0) {
|
if (numMarkers == 0) {
|
||||||
lastTokenBufferStart = lastToken;
|
lastTokenBufferStart = lastToken;
|
||||||
|
@ -210,7 +196,7 @@ namespace runtime {
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
void UnbufferedTokenStream<T>::release(int marker)
|
void UnbufferedTokenStream::release(int marker)
|
||||||
{
|
{
|
||||||
int expectedMark = -numMarkers;
|
int expectedMark = -numMarkers;
|
||||||
if (marker != expectedMark) {
|
if (marker != expectedMark) {
|
||||||
|
@ -230,14 +216,13 @@ namespace runtime {
|
||||||
lastTokenBufferStart = lastToken;
|
lastTokenBufferStart = lastToken;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
template <typename T>
|
|
||||||
int UnbufferedTokenStream<T>::index()
|
int UnbufferedTokenStream::index()
|
||||||
{
|
{
|
||||||
return currentTokenIndex;
|
return currentTokenIndex;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T>
|
void UnbufferedTokenStream::seek(int index)
|
||||||
void UnbufferedTokenStream<T>::seek(int index)
|
|
||||||
{ // seek to absolute index
|
{ // seek to absolute index
|
||||||
if (index == currentTokenIndex) {
|
if (index == currentTokenIndex) {
|
||||||
return;
|
return;
|
||||||
|
@ -267,20 +252,17 @@ namespace runtime {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T>
|
size_t UnbufferedTokenStream::size()
|
||||||
size_t UnbufferedTokenStream<T>::size()
|
|
||||||
{
|
{
|
||||||
throw new UnsupportedOperationException(L"Unbuffered stream cannot know its size");
|
throw new UnsupportedOperationException(L"Unbuffered stream cannot know its size");
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T>
|
std::string UnbufferedTokenStream::getSourceName()
|
||||||
std::string UnbufferedTokenStream<T>::getSourceName()
|
|
||||||
{
|
{
|
||||||
return tokenSource->getSourceName();
|
return tokenSource->getSourceName();
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T>
|
std::wstring UnbufferedTokenStream::getText(misc::Interval* interval)
|
||||||
std::wstring UnbufferedTokenStream<T>::getText(misc::Interval* interval)
|
|
||||||
{
|
{
|
||||||
int bufferStartIndex = getBufferStartIndex();
|
int bufferStartIndex = getBufferStartIndex();
|
||||||
int bufferStopIndex = bufferStartIndex + tokens.size() - 1;
|
int bufferStopIndex = bufferStartIndex + tokens.size() - 1;
|
||||||
|
@ -303,14 +285,12 @@ namespace runtime {
|
||||||
return buf->toString();
|
return buf->toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T>
|
int UnbufferedTokenStream::getBufferStartIndex()
|
||||||
int UnbufferedTokenStream<T>::getBufferStartIndex()
|
|
||||||
{
|
{
|
||||||
return currentTokenIndex - p;
|
return currentTokenIndex - p;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T>
|
void UnbufferedTokenStream::InitializeInstanceFields()
|
||||||
void UnbufferedTokenStream<T>::InitializeInstanceFields()
|
|
||||||
{
|
{
|
||||||
n = 0;
|
n = 0;
|
||||||
p = 0;
|
p = 0;
|
||||||
|
|
|
@ -49,18 +49,17 @@ ATN::ATN() : ATN(ATNType::LEXER, 0) {
|
||||||
ATN::ATN(ATNType grammarType, int maxTokenType) : grammarType(grammarType), maxTokenType(maxTokenType) {
|
ATN::ATN(ATNType grammarType, int maxTokenType) : grammarType(grammarType), maxTokenType(maxTokenType) {
|
||||||
}
|
}
|
||||||
|
|
||||||
org::antlr::v4::runtime::misc::IntervalSet *ATN::nextTokens(ATNState *s, RuleContext *ctx) const {
|
misc::IntervalSet ATN::nextTokens(ATNState *s, RuleContext *ctx) const {
|
||||||
LL1Analyzer *anal = new LL1Analyzer(*this);
|
LL1Analyzer analyzer(*this);
|
||||||
misc::IntervalSet *next = anal->LOOK(s, ctx);
|
return analyzer.LOOK(s, ctx);
|
||||||
return next;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
org::antlr::v4::runtime::misc::IntervalSet *ATN::nextTokens(ATNState *s) const {
|
misc::IntervalSet ATN::nextTokens(ATNState *s) const {
|
||||||
if (s->nextTokenWithinRule != nullptr) {
|
if (s->nextTokenWithinRule.isEmpty()) {
|
||||||
return s->nextTokenWithinRule;
|
|
||||||
}
|
|
||||||
s->nextTokenWithinRule = nextTokens(s, nullptr);
|
s->nextTokenWithinRule = nextTokens(s, nullptr);
|
||||||
s->nextTokenWithinRule->setReadonly(true);
|
s->nextTokenWithinRule.setReadOnly(true);
|
||||||
|
}
|
||||||
return s->nextTokenWithinRule;
|
return s->nextTokenWithinRule;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -71,12 +70,11 @@ void ATN::addState(ATNState *state) {
|
||||||
}
|
}
|
||||||
|
|
||||||
states.push_back(state);
|
states.push_back(state);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void ATN::removeState(ATNState *state) {
|
void ATN::removeState(ATNState *state) {
|
||||||
delete states.at(state->stateNumber);// just free mem, don't shift states in list
|
delete states.at((size_t)state->stateNumber);// just free mem, don't shift states in list
|
||||||
states.at(state->stateNumber) = nullptr;
|
states.at((size_t)state->stateNumber) = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
int ATN::defineDecisionState(DecisionState *s) {
|
int ATN::defineDecisionState(DecisionState *s) {
|
||||||
|
@ -85,9 +83,9 @@ int ATN::defineDecisionState(DecisionState *s) {
|
||||||
return s->decision;
|
return s->decision;
|
||||||
}
|
}
|
||||||
|
|
||||||
org::antlr::v4::runtime::atn::DecisionState *ATN::getDecisionState(int decision) const {
|
DecisionState *ATN::getDecisionState(int decision) const {
|
||||||
if (!decisionToState.empty()) {
|
if (!decisionToState.empty()) {
|
||||||
return decisionToState.at(decision);
|
return decisionToState.at((size_t)decision);
|
||||||
}
|
}
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
@ -96,32 +94,32 @@ int ATN::getNumberOfDecisions() const {
|
||||||
return (int)decisionToState.size();
|
return (int)decisionToState.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
misc::IntervalSet *ATN::getExpectedTokens(int stateNumber, RuleContext *context) const {
|
misc::IntervalSet ATN::getExpectedTokens(int stateNumber, RuleContext *context) const {
|
||||||
if (stateNumber < 0 || stateNumber >= (int)states.size()) {
|
if (stateNumber < 0 || stateNumber >= (int)states.size()) {
|
||||||
throw new IllegalArgumentException(L"Invalid state number.");
|
throw new IllegalArgumentException(L"Invalid state number.");
|
||||||
}
|
}
|
||||||
|
|
||||||
RuleContext *ctx = context;
|
RuleContext *ctx = context;
|
||||||
ATNState *s = states.at(stateNumber);
|
ATNState *s = states.at((size_t)stateNumber);
|
||||||
misc::IntervalSet *following = nextTokens(s);
|
misc::IntervalSet following = nextTokens(s);
|
||||||
if (!following->contains(Token::EPSILON)) {
|
if (!following.contains(Token::EPSILON)) {
|
||||||
return following;
|
return following;
|
||||||
}
|
}
|
||||||
|
|
||||||
misc::IntervalSet *expected = new misc::IntervalSet(0);
|
misc::IntervalSet expected;
|
||||||
expected->addAll(following);
|
expected.addAll(following);
|
||||||
expected->remove(Token::EPSILON);
|
expected.remove(Token::EPSILON);
|
||||||
while (ctx != nullptr && ctx->invokingState >= 0 && following->contains(Token::EPSILON)) {
|
while (ctx != nullptr && ctx->invokingState >= 0 && following.contains(Token::EPSILON)) {
|
||||||
ATNState *invokingState = states.at(ctx->invokingState);
|
ATNState *invokingState = states.at((size_t)ctx->invokingState);
|
||||||
RuleTransition *rt = static_cast<RuleTransition*>(invokingState->transition(0));
|
RuleTransition *rt = static_cast<RuleTransition*>(invokingState->transition(0));
|
||||||
following = nextTokens(rt->followState);
|
following = nextTokens(rt->followState);
|
||||||
expected->addAll(following);
|
expected.addAll(following);
|
||||||
expected->remove(Token::EPSILON);
|
expected.remove(Token::EPSILON);
|
||||||
ctx = ctx->parent;
|
ctx = ctx->parent;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (following->contains(Token::EPSILON)) {
|
if (following.contains(Token::EPSILON)) {
|
||||||
expected->add(Token::_EOF);
|
expected.add(Token::_EOF);
|
||||||
}
|
}
|
||||||
|
|
||||||
return expected;
|
return expected;
|
||||||
|
|
|
@ -102,14 +102,14 @@ namespace atn {
|
||||||
/// the rule surrounding {@code s}. In other words, the set will be
|
/// the rule surrounding {@code s}. In other words, the set will be
|
||||||
/// restricted to tokens reachable staying within {@code s}'s rule.
|
/// restricted to tokens reachable staying within {@code s}'s rule.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
virtual misc::IntervalSet *nextTokens(ATNState *s, RuleContext *ctx) const;
|
virtual misc::IntervalSet nextTokens(ATNState *s, RuleContext *ctx) const;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Compute the set of valid tokens that can occur starting in {@code s} and
|
/// Compute the set of valid tokens that can occur starting in {@code s} and
|
||||||
/// staying in same rule. <seealso cref="Token#EPSILON"/> is in set if we reach end of
|
/// staying in same rule. <seealso cref="Token#EPSILON"/> is in set if we reach end of
|
||||||
/// rule.
|
/// rule.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
virtual misc::IntervalSet *nextTokens(ATNState *s) const;
|
virtual misc::IntervalSet nextTokens(ATNState *s) const;
|
||||||
|
|
||||||
virtual void addState(ATNState *state);
|
virtual void addState(ATNState *state);
|
||||||
|
|
||||||
|
@ -139,7 +139,7 @@ namespace atn {
|
||||||
/// specified state in the specified context. </returns>
|
/// specified state in the specified context. </returns>
|
||||||
/// <exception cref="IllegalArgumentException"> if the ATN does not contain a state with
|
/// <exception cref="IllegalArgumentException"> if the ATN does not contain a state with
|
||||||
/// number {@code stateNumber} </exception>
|
/// number {@code stateNumber} </exception>
|
||||||
virtual misc::IntervalSet *getExpectedTokens(int stateNumber, RuleContext *context) const;
|
virtual misc::IntervalSet getExpectedTokens(int stateNumber, RuleContext *context) const;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace atn
|
} // namespace atn
|
||||||
|
|
|
@ -74,11 +74,11 @@ ATNConfig::ATNConfig(ATNConfig *c, ATNState *state, PredictionContext *context,
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t ATNConfig::hashCode() const {
|
size_t ATNConfig::hashCode() const {
|
||||||
int hashCode = misc::MurmurHash::initialize(7);
|
size_t hashCode = misc::MurmurHash::initialize(7);
|
||||||
hashCode = misc::MurmurHash::update(hashCode, state->stateNumber);
|
hashCode = misc::MurmurHash::update(hashCode, (size_t)state->stateNumber);
|
||||||
hashCode = misc::MurmurHash::update(hashCode, alt);
|
hashCode = misc::MurmurHash::update(hashCode, (size_t)alt);
|
||||||
hashCode = misc::MurmurHash::update(hashCode, context);
|
hashCode = misc::MurmurHash::update(hashCode, (size_t)context);
|
||||||
hashCode = misc::MurmurHash::update(hashCode, semanticContext);
|
hashCode = misc::MurmurHash::update(hashCode, (size_t)semanticContext);
|
||||||
hashCode = misc::MurmurHash::finish(hashCode, 4);
|
hashCode = misc::MurmurHash::finish(hashCode, 4);
|
||||||
return hashCode;
|
return hashCode;
|
||||||
}
|
}
|
||||||
|
@ -86,7 +86,7 @@ size_t ATNConfig::hashCode() const {
|
||||||
bool ATNConfig::operator == (const ATNConfig& other) const
|
bool ATNConfig::operator == (const ATNConfig& other) const
|
||||||
{
|
{
|
||||||
return this->state->stateNumber == other.state->stateNumber && this->alt == other.alt &&
|
return this->state->stateNumber == other.state->stateNumber && this->alt == other.alt &&
|
||||||
(this->context == other.context || (this->context != nullptr && this->context->equals(other.context))) &&
|
(this->context == other.context || (this->context != nullptr && this->context == other.context)) &&
|
||||||
this->semanticContext->equals(other.semanticContext);
|
this->semanticContext->equals(other.semanticContext);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -38,9 +38,9 @@
|
||||||
using namespace org::antlr::v4::runtime::atn;
|
using namespace org::antlr::v4::runtime::atn;
|
||||||
|
|
||||||
size_t SimpleATNConfigHasher::operator()(const ATNConfig &k) const {
|
size_t SimpleATNConfigHasher::operator()(const ATNConfig &k) const {
|
||||||
int hashCode = 7;
|
size_t hashCode = 7;
|
||||||
hashCode = 31 * hashCode + k.state->stateNumber;
|
hashCode = 31 * hashCode + (size_t)k.state->stateNumber;
|
||||||
hashCode = 31 * hashCode + k.alt;
|
hashCode = 31 * hashCode + (size_t)k.alt;
|
||||||
hashCode = 31 * hashCode + k.semanticContext->hashCode();
|
hashCode = 31 * hashCode + k.semanticContext->hashCode();
|
||||||
return hashCode;
|
return hashCode;
|
||||||
}
|
}
|
||||||
|
@ -90,7 +90,7 @@ bool ATNConfigSet::add(ATNConfig *config, misc::DoubleKeyMap<PredictionContext*,
|
||||||
|
|
||||||
ATNConfig *existing = configLookup->getOrAdd(config);
|
ATNConfig *existing = configLookup->getOrAdd(config);
|
||||||
if (existing == config) { // we added this new one
|
if (existing == config) { // we added this new one
|
||||||
_cachedHashCode = -1;
|
_cachedHashCode = 0;
|
||||||
configs.push_back(config); // track order here
|
configs.push_back(config); // track order here
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
@ -135,7 +135,7 @@ std::vector<SemanticContext*> ATNConfigSet::getPredicates() {
|
||||||
return preds;
|
return preds;
|
||||||
}
|
}
|
||||||
|
|
||||||
ATNConfig* ATNConfigSet::get(int i) {
|
ATNConfig* ATNConfigSet::get(size_t i) const {
|
||||||
return configs[i];
|
return configs[i];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -180,16 +180,16 @@ bool ATNConfigSet::equals(ATNConfigSet *other) {
|
||||||
return same;
|
return same;
|
||||||
}
|
}
|
||||||
|
|
||||||
int ATNConfigSet::hashCode() {
|
size_t ATNConfigSet::hashCode() {
|
||||||
if (isReadonly()) {
|
if (isReadonly()) {
|
||||||
if (_cachedHashCode == -1) {
|
if (_cachedHashCode == 0) {
|
||||||
_cachedHashCode = (int)std::hash<std::vector<ATNConfig *>>()(configs);
|
_cachedHashCode = std::hash<std::vector<ATNConfig *>>()(configs);
|
||||||
}
|
}
|
||||||
|
|
||||||
return _cachedHashCode;
|
return _cachedHashCode;
|
||||||
}
|
}
|
||||||
|
|
||||||
return (int)std::hash<std::vector<ATNConfig *>>()(configs);
|
return std::hash<std::vector<ATNConfig *>>()(configs);
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t ATNConfigSet::size() {
|
size_t ATNConfigSet::size() {
|
||||||
|
@ -213,7 +213,7 @@ void ATNConfigSet::clear() {
|
||||||
throw new IllegalStateException(L"This set is readonly");
|
throw new IllegalStateException(L"This set is readonly");
|
||||||
}
|
}
|
||||||
configs.clear();
|
configs.clear();
|
||||||
_cachedHashCode = -1;
|
_cachedHashCode = 0;
|
||||||
configLookup->clear();
|
configLookup->clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -229,7 +229,7 @@ void ATNConfigSet::setReadonly(bool readonly) {
|
||||||
|
|
||||||
std::wstring ATNConfigSet::toString() {
|
std::wstring ATNConfigSet::toString() {
|
||||||
antlrcpp::StringBuilder *buf = new antlrcpp::StringBuilder();
|
antlrcpp::StringBuilder *buf = new antlrcpp::StringBuilder();
|
||||||
for (int i = 0; i < (int)elements().size(); i++) {
|
for (size_t i = 0; i < elements().size(); i++) {
|
||||||
buf->append(elements().at(i)->toString());
|
buf->append(elements().at(i)->toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -259,5 +259,5 @@ void ATNConfigSet::InitializeInstanceFields() {
|
||||||
dipsIntoOuterContext = false;
|
dipsIntoOuterContext = false;
|
||||||
|
|
||||||
_readonly = false;
|
_readonly = false;
|
||||||
_cachedHashCode = -1;
|
_cachedHashCode = 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -110,14 +110,14 @@ namespace atn {
|
||||||
|
|
||||||
virtual std::vector<SemanticContext*> getPredicates();
|
virtual std::vector<SemanticContext*> getPredicates();
|
||||||
|
|
||||||
virtual ATNConfig *get(int i);
|
virtual ATNConfig *get(size_t i) const;
|
||||||
|
|
||||||
virtual void optimizeConfigs(ATNSimulator *interpreter);
|
virtual void optimizeConfigs(ATNSimulator *interpreter);
|
||||||
|
|
||||||
bool addAll(ATNConfigSet *other);
|
bool addAll(ATNConfigSet *other);
|
||||||
|
|
||||||
virtual bool equals(ATNConfigSet *other);
|
virtual bool equals(ATNConfigSet *other);
|
||||||
virtual int hashCode();
|
virtual size_t hashCode();
|
||||||
virtual size_t size();
|
virtual size_t size();
|
||||||
virtual bool isEmpty();
|
virtual bool isEmpty();
|
||||||
virtual bool contains(ATNConfig *o);
|
virtual bool contains(ATNConfig *o);
|
||||||
|
@ -136,7 +136,7 @@ namespace atn {
|
||||||
bool _readonly;
|
bool _readonly;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
int _cachedHashCode;
|
size_t _cachedHashCode;
|
||||||
|
|
||||||
void InitializeInstanceFields();
|
void InitializeInstanceFields();
|
||||||
};
|
};
|
||||||
|
|
|
@ -67,7 +67,7 @@
|
||||||
using namespace antlrcpp;
|
using namespace antlrcpp;
|
||||||
using namespace org::antlr::v4::runtime::atn;
|
using namespace org::antlr::v4::runtime::atn;
|
||||||
|
|
||||||
const int ATNDeserializer::SERIALIZED_VERSION = 3;
|
const size_t ATNDeserializer::SERIALIZED_VERSION = 3;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This value should never change. Updates following this version are
|
* This value should never change. Updates following this version are
|
||||||
|
@ -163,11 +163,11 @@ ATN ATNDeserializer::deserialize(const std::wstring& input) {
|
||||||
|
|
||||||
// delay the assignment of loop back and end states until we know all the state instances have been initialized
|
// delay the assignment of loop back and end states until we know all the state instances have been initialized
|
||||||
for (auto &pair : loopBackStateNumbers) {
|
for (auto &pair : loopBackStateNumbers) {
|
||||||
pair.first->loopBackState = atn.states.at(pair.second);
|
pair.first->loopBackState = atn.states[(size_t)pair.second];
|
||||||
}
|
}
|
||||||
|
|
||||||
for (auto &pair : endStateNumbers) {
|
for (auto &pair : endStateNumbers) {
|
||||||
pair.first->endState = (BlockEndState*)atn.states.at(pair.second);
|
pair.first->endState = (BlockEndState*)atn.states[(size_t)pair.second];
|
||||||
}
|
}
|
||||||
|
|
||||||
int numNonGreedyStates = data[p++];
|
int numNonGreedyStates = data[p++];
|
||||||
|
@ -175,30 +175,30 @@ ATN ATNDeserializer::deserialize(const std::wstring& input) {
|
||||||
int stateNumber = data[p++];
|
int stateNumber = data[p++];
|
||||||
// The serialized ATN must be specifying the right states, so that the
|
// The serialized ATN must be specifying the right states, so that the
|
||||||
// cast below is correct.
|
// cast below is correct.
|
||||||
((DecisionState *)atn.states.at(stateNumber))->nonGreedy = true;
|
((DecisionState *)atn.states[(size_t)stateNumber])->nonGreedy = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (supportsPrecedencePredicates) {
|
if (supportsPrecedencePredicates) {
|
||||||
int numPrecedenceStates = data[p++];
|
int numPrecedenceStates = data[p++];
|
||||||
for (int i = 0; i < numPrecedenceStates; i++) {
|
for (int i = 0; i < numPrecedenceStates; i++) {
|
||||||
int stateNumber = data[p++];
|
int stateNumber = data[p++];
|
||||||
((RuleStartState *)atn.states.at(stateNumber))->isPrecedenceRule = true;
|
((RuleStartState *)atn.states[(size_t)stateNumber])->isPrecedenceRule = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
// RULES
|
// RULES
|
||||||
//
|
//
|
||||||
int nrules = data[p++];
|
size_t nrules = (size_t)data[p++];
|
||||||
if (atn.grammarType == ATNType::LEXER) {
|
if (atn.grammarType == ATNType::LEXER) {
|
||||||
atn.ruleToTokenType.resize(nrules);
|
atn.ruleToTokenType.resize(nrules);
|
||||||
atn.ruleToActionIndex.resize(nrules);
|
atn.ruleToActionIndex.resize(nrules);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int i = 0; i < nrules; i++) {
|
for (size_t i = 0; i < nrules; i++) {
|
||||||
int s = data[p++];
|
size_t s = (size_t)data[p++];
|
||||||
// Also here, the serialized atn must ensure to point to the correct class type.
|
// Also here, the serialized atn must ensure to point to the correct class type.
|
||||||
RuleStartState *startState = (RuleStartState*)atn.states.at(s);
|
RuleStartState *startState = (RuleStartState*)atn.states[s];
|
||||||
atn.ruleToStartState.push_back(startState);
|
atn.ruleToStartState.push_back(startState);
|
||||||
if (atn.grammarType == ATNType::LEXER) {
|
if (atn.grammarType == ATNType::LEXER) {
|
||||||
int tokenType = data[p++];
|
int tokenType = data[p++];
|
||||||
|
@ -224,7 +224,7 @@ ATN ATNDeserializer::deserialize(const std::wstring& input) {
|
||||||
|
|
||||||
RuleStopState *stopState = static_cast<RuleStopState*>(state);
|
RuleStopState *stopState = static_cast<RuleStopState*>(state);
|
||||||
atn.ruleToStopState[state->ruleIndex] = stopState;
|
atn.ruleToStopState[state->ruleIndex] = stopState;
|
||||||
atn.ruleToStartState[state->ruleIndex]->stopState = stopState;
|
atn.ruleToStartState[(size_t)state->ruleIndex]->stopState = stopState;
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
|
@ -232,30 +232,30 @@ ATN ATNDeserializer::deserialize(const std::wstring& input) {
|
||||||
//
|
//
|
||||||
int nmodes = data[p++];
|
int nmodes = data[p++];
|
||||||
for (int i = 0; i < nmodes; i++) {
|
for (int i = 0; i < nmodes; i++) {
|
||||||
int s = data[p++];
|
size_t s = (size_t)data[p++];
|
||||||
atn.modeToStartState.push_back(static_cast<TokensStartState*>(atn.states[s]));
|
atn.modeToStartState.push_back(static_cast<TokensStartState*>(atn.states[s]));
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
// SETS
|
// SETS
|
||||||
//
|
//
|
||||||
std::vector<misc::IntervalSet*> sets;
|
std::vector<misc::IntervalSet> sets;
|
||||||
int nsets = data[p++];
|
int nsets = data[p++];
|
||||||
for (int i = 0; i < nsets; i++) {
|
for (int i = 0; i < nsets; i++) {
|
||||||
int nintervals = data[p];
|
int nintervals = data[p];
|
||||||
p++;
|
p++;
|
||||||
misc::IntervalSet *set = new misc::IntervalSet();
|
misc::IntervalSet set;
|
||||||
sets.push_back(set);
|
|
||||||
|
|
||||||
bool containsEof = data[p++] != 0;
|
bool containsEof = data[p++] != 0;
|
||||||
if (containsEof) {
|
if (containsEof) {
|
||||||
set->add(-1);
|
set.add(-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int j = 0; j < nintervals; j++) {
|
for (int j = 0; j < nintervals; j++) {
|
||||||
set->add(data[p], data[p + 1]);
|
set.add(data[p], data[p + 1]);
|
||||||
p += 2;
|
p += 2;
|
||||||
}
|
}
|
||||||
|
sets.push_back(set);
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
|
@ -270,14 +270,14 @@ ATN ATNDeserializer::deserialize(const std::wstring& input) {
|
||||||
int arg2 = data[p + 4];
|
int arg2 = data[p + 4];
|
||||||
int arg3 = data[p + 5];
|
int arg3 = data[p + 5];
|
||||||
Transition *trans = edgeFactory(atn, ttype, src, trg, arg1, arg2, arg3, sets);
|
Transition *trans = edgeFactory(atn, ttype, src, trg, arg1, arg2, arg3, sets);
|
||||||
ATNState *srcState = atn.states[src];
|
ATNState *srcState = atn.states[(size_t)src];
|
||||||
srcState->addTransition(trans);
|
srcState->addTransition(trans);
|
||||||
p += 6;
|
p += 6;
|
||||||
}
|
}
|
||||||
|
|
||||||
// edges for rule stop states can be derived, so they aren't serialized
|
// edges for rule stop states can be derived, so they aren't serialized
|
||||||
for (ATNState *state : atn.states) {
|
for (ATNState *state : atn.states) {
|
||||||
for (int i = 0; i < state->getNumberOfTransitions(); i++) {
|
for (size_t i = 0; i < state->getNumberOfTransitions(); i++) {
|
||||||
Transition *t = state->transition(i);
|
Transition *t = state->transition(i);
|
||||||
if (!(dynamic_cast<RuleTransition*>(t) != nullptr)) {
|
if (!(dynamic_cast<RuleTransition*>(t) != nullptr)) {
|
||||||
continue;
|
continue;
|
||||||
|
@ -306,7 +306,7 @@ ATN ATNDeserializer::deserialize(const std::wstring& input) {
|
||||||
|
|
||||||
if (dynamic_cast<PlusLoopbackState*>(state) != nullptr) {
|
if (dynamic_cast<PlusLoopbackState*>(state) != nullptr) {
|
||||||
PlusLoopbackState *loopbackState = static_cast<PlusLoopbackState*>(state);
|
PlusLoopbackState *loopbackState = static_cast<PlusLoopbackState*>(state);
|
||||||
for (int i = 0; i < loopbackState->getNumberOfTransitions(); i++) {
|
for (size_t i = 0; i < loopbackState->getNumberOfTransitions(); i++) {
|
||||||
ATNState *target = loopbackState->transition(i)->target;
|
ATNState *target = loopbackState->transition(i)->target;
|
||||||
if (dynamic_cast<PlusBlockStartState*>(target) != nullptr) {
|
if (dynamic_cast<PlusBlockStartState*>(target) != nullptr) {
|
||||||
(static_cast<PlusBlockStartState*>(target))->loopBackState = loopbackState;
|
(static_cast<PlusBlockStartState*>(target))->loopBackState = loopbackState;
|
||||||
|
@ -314,7 +314,7 @@ ATN ATNDeserializer::deserialize(const std::wstring& input) {
|
||||||
}
|
}
|
||||||
} else if (dynamic_cast<StarLoopbackState*>(state) != nullptr) {
|
} else if (dynamic_cast<StarLoopbackState*>(state) != nullptr) {
|
||||||
StarLoopbackState *loopbackState = static_cast<StarLoopbackState*>(state);
|
StarLoopbackState *loopbackState = static_cast<StarLoopbackState*>(state);
|
||||||
for (int i = 0; i < loopbackState->getNumberOfTransitions(); i++) {
|
for (size_t i = 0; i < loopbackState->getNumberOfTransitions(); i++) {
|
||||||
ATNState *target = loopbackState->transition(i)->target;
|
ATNState *target = loopbackState->transition(i)->target;
|
||||||
if (dynamic_cast<StarLoopEntryState*>(target) != nullptr) {
|
if (dynamic_cast<StarLoopEntryState*>(target) != nullptr) {
|
||||||
(static_cast<StarLoopEntryState*>(target))->loopBackState = loopbackState;
|
(static_cast<StarLoopEntryState*>(target))->loopBackState = loopbackState;
|
||||||
|
@ -326,13 +326,13 @@ ATN ATNDeserializer::deserialize(const std::wstring& input) {
|
||||||
//
|
//
|
||||||
// DECISIONS
|
// DECISIONS
|
||||||
//
|
//
|
||||||
int ndecisions = data[p++];
|
size_t ndecisions = (size_t)data[p++];
|
||||||
for (int i = 1; i <= ndecisions; i++) {
|
for (size_t i = 1; i <= ndecisions; i++) {
|
||||||
int s = data[p++];
|
size_t s = (size_t)data[p++];
|
||||||
DecisionState *decState = static_cast<DecisionState*>(atn.states[s]);
|
DecisionState *decState = static_cast<DecisionState*>(atn.states[s]);
|
||||||
// TODO: decisionToState was originally declared as const in ATN
|
// TODO: decisionToState was originally declared as const in ATN
|
||||||
atn.decisionToState.push_back(decState);
|
atn.decisionToState.push_back(decState);
|
||||||
decState->decision = i - 1;
|
decState->decision = (int)i - 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (deserializationOptions.isVerifyATN()) {
|
if (deserializationOptions.isVerifyATN()) {
|
||||||
|
@ -409,7 +409,7 @@ ATN ATNDeserializer::deserialize(const std::wstring& input) {
|
||||||
|
|
||||||
// all transitions leaving the rule start state need to leave blockStart instead
|
// all transitions leaving the rule start state need to leave blockStart instead
|
||||||
while (atn.ruleToStartState[i]->getNumberOfTransitions() > 0) {
|
while (atn.ruleToStartState[i]->getNumberOfTransitions() > 0) {
|
||||||
Transition *transition = atn.ruleToStartState[i]->removeTransition(atn.ruleToStartState[i]->getNumberOfTransitions() - 1);
|
Transition *transition = atn.ruleToStartState[i]->removeTransition((int)atn.ruleToStartState[i]->getNumberOfTransitions() - 1);
|
||||||
bypassStart->addTransition(transition);
|
bypassStart->addTransition(transition);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -507,8 +507,10 @@ Guid ATNDeserializer::toUUID(const wchar_t *data, int offset) {
|
||||||
return Guid((uint32_t *)data + offset, true);
|
return Guid((uint32_t *)data + offset, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
Transition *ATNDeserializer::edgeFactory(const ATN &atn, int type, int src, int trg, int arg1, int arg2, int arg3, std::vector<misc::IntervalSet*> &sets) {
|
Transition *ATNDeserializer::edgeFactory(const ATN &atn, int type, int src, int trg, int arg1, int arg2, int arg3,
|
||||||
ATNState *target = atn.states[trg];
|
const std::vector<misc::IntervalSet> &sets) {
|
||||||
|
|
||||||
|
ATNState *target = atn.states[(size_t)trg];
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case Transition::EPSILON :
|
case Transition::EPSILON :
|
||||||
return new EpsilonTransition(target);
|
return new EpsilonTransition(target);
|
||||||
|
@ -519,7 +521,7 @@ Transition *ATNDeserializer::edgeFactory(const ATN &atn, int type, int src, int
|
||||||
return new RangeTransition(target, arg1, arg2);
|
return new RangeTransition(target, arg1, arg2);
|
||||||
}
|
}
|
||||||
case Transition::RULE :
|
case Transition::RULE :
|
||||||
return new RuleTransition(static_cast<RuleStartState*>(atn.states[arg1]), arg2, arg3, target);
|
return new RuleTransition(static_cast<RuleStartState*>(atn.states[(size_t)arg1]), arg2, arg3, target);
|
||||||
case Transition::PREDICATE :
|
case Transition::PREDICATE :
|
||||||
return new PredicateTransition(target, arg1, arg2, arg3 != 0);
|
return new PredicateTransition(target, arg1, arg2, arg3 != 0);
|
||||||
case Transition::PRECEDENCE:
|
case Transition::PRECEDENCE:
|
||||||
|
@ -533,9 +535,9 @@ Transition *ATNDeserializer::edgeFactory(const ATN &atn, int type, int src, int
|
||||||
case Transition::ACTION :
|
case Transition::ACTION :
|
||||||
return new ActionTransition(target, arg1, arg2, arg3 != 0);
|
return new ActionTransition(target, arg1, arg2, arg3 != 0);
|
||||||
case Transition::SET :
|
case Transition::SET :
|
||||||
return new SetTransition(target, sets[arg1]);
|
return new SetTransition(target, sets[(size_t)arg1]);
|
||||||
case Transition::NOT_SET :
|
case Transition::NOT_SET :
|
||||||
return new NotSetTransition(target, sets[arg1]);
|
return new NotSetTransition(target, sets[(size_t)arg1]);
|
||||||
case Transition::WILDCARD :
|
case Transition::WILDCARD :
|
||||||
return new WildcardTransition(target);
|
return new WildcardTransition(target);
|
||||||
}
|
}
|
||||||
|
|
|
@ -41,7 +41,7 @@ namespace atn {
|
||||||
|
|
||||||
class ATNDeserializer {
|
class ATNDeserializer {
|
||||||
public:
|
public:
|
||||||
static const int SERIALIZED_VERSION;
|
static const size_t SERIALIZED_VERSION;
|
||||||
//static ATNDeserializer();
|
//static ATNDeserializer();
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
@ -108,7 +108,7 @@ namespace atn {
|
||||||
static Guid toUUID(const wchar_t *data, int offset);
|
static Guid toUUID(const wchar_t *data, int offset);
|
||||||
|
|
||||||
virtual Transition *edgeFactory(const ATN &atn, int type, int src, int trg, int arg1, int arg2, int arg3,
|
virtual Transition *edgeFactory(const ATN &atn, int type, int src, int trg, int arg1, int arg2, int arg3,
|
||||||
std::vector<misc::IntervalSet*> &sets);
|
const std::vector<misc::IntervalSet> &sets);
|
||||||
|
|
||||||
virtual ATNState *stateFactory(int type, int ruleIndex);
|
virtual ATNState *stateFactory(int type, int ruleIndex);
|
||||||
|
|
||||||
|
|
|
@ -73,13 +73,12 @@ std::vector<size_t>* ATNSerializer::serialize() {
|
||||||
serializeUUID(data, ATNDeserializer::SERIALIZED_UUID);
|
serializeUUID(data, ATNDeserializer::SERIALIZED_UUID);
|
||||||
|
|
||||||
// convert grammar type to ATN const to avoid dependence on ANTLRParser
|
// convert grammar type to ATN const to avoid dependence on ANTLRParser
|
||||||
data->push_back(static_cast<int>(atn->grammarType));
|
data->push_back((size_t)atn->grammarType);
|
||||||
data->push_back(atn->maxTokenType);
|
data->push_back((size_t)atn->maxTokenType);
|
||||||
int nedges = 0;
|
size_t nedges = 0;
|
||||||
|
|
||||||
std::unordered_map<misc::IntervalSet *, int> *setIndices =
|
std::unordered_map<misc::IntervalSet, int> setIndices;
|
||||||
new std::unordered_map<misc::IntervalSet *, int>();
|
std::vector<misc::IntervalSet> sets;
|
||||||
std::vector<misc::IntervalSet *> sets = std::vector<misc::IntervalSet *>();
|
|
||||||
|
|
||||||
// dump states, count edges and collect sets while doing so
|
// dump states, count edges and collect sets while doing so
|
||||||
std::vector<int> nonGreedyStates;
|
std::vector<int> nonGreedyStates;
|
||||||
|
@ -102,20 +101,20 @@ std::vector<size_t>* ATNSerializer::serialize() {
|
||||||
precedenceStates.push_back(s->stateNumber);
|
precedenceStates.push_back(s->stateNumber);
|
||||||
}
|
}
|
||||||
|
|
||||||
data->push_back(stateType);
|
data->push_back((size_t)stateType);
|
||||||
|
|
||||||
if (s->ruleIndex == -1) {
|
if (s->ruleIndex == -1) {
|
||||||
data->push_back(WCHAR_MAX);
|
data->push_back(WCHAR_MAX);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
data->push_back(s->ruleIndex);
|
data->push_back((size_t)s->ruleIndex);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (s->getStateType() == ATNState::LOOP_END) {
|
if (s->getStateType() == ATNState::LOOP_END) {
|
||||||
data->push_back((static_cast<LoopEndState *>(s))->loopBackState->stateNumber);
|
data->push_back((size_t)(static_cast<LoopEndState *>(s))->loopBackState->stateNumber);
|
||||||
}
|
}
|
||||||
else if (dynamic_cast<BlockStartState *>(s) != nullptr) {
|
else if (dynamic_cast<BlockStartState *>(s) != nullptr) {
|
||||||
data->push_back((static_cast<BlockStartState *>(s))->endState->stateNumber);
|
data->push_back((size_t)(static_cast<BlockStartState *>(s))->endState->stateNumber);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (s->getStateType() != ATNState::RULE_STOP) {
|
if (s->getStateType() != ATNState::RULE_STOP) {
|
||||||
|
@ -124,14 +123,14 @@ std::vector<size_t>* ATNSerializer::serialize() {
|
||||||
nedges += s->getNumberOfTransitions();
|
nedges += s->getNumberOfTransitions();
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int i = 0; i < s->getNumberOfTransitions(); i++) {
|
for (size_t i = 0; i < s->getNumberOfTransitions(); i++) {
|
||||||
Transition *t = s->transition(i);
|
Transition *t = s->transition(i);
|
||||||
int edgeType = t->getSerializationType();
|
int edgeType = t->getSerializationType();
|
||||||
if (edgeType == Transition::SET || edgeType == Transition::NOT_SET) {
|
if (edgeType == Transition::SET || edgeType == Transition::NOT_SET) {
|
||||||
SetTransition *st = static_cast<SetTransition *>(t);
|
SetTransition *st = static_cast<SetTransition *>(t);
|
||||||
if (setIndices->find(st->set) != setIndices->end()) {
|
if (setIndices.find(st->set) != setIndices.end()) {
|
||||||
sets.push_back(st->set);
|
sets.push_back(st->set);
|
||||||
setIndices->insert({ st->set, sets.size() - 1 });
|
setIndices.insert({ st->set, sets.size() - 1 });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -139,34 +138,34 @@ std::vector<size_t>* ATNSerializer::serialize() {
|
||||||
|
|
||||||
// non-greedy states
|
// non-greedy states
|
||||||
data->push_back(nonGreedyStates.size());
|
data->push_back(nonGreedyStates.size());
|
||||||
for (int i = 0; i < (int)nonGreedyStates.size(); i++) {
|
for (size_t i = 0; i < nonGreedyStates.size(); i++) {
|
||||||
data->push_back(nonGreedyStates.at(i));
|
data->push_back((size_t)nonGreedyStates.at(i));
|
||||||
}
|
}
|
||||||
|
|
||||||
// precedence states
|
// precedence states
|
||||||
data->push_back(precedenceStates.size());
|
data->push_back(precedenceStates.size());
|
||||||
for (int i = 0; i < (int)precedenceStates.size(); i++) {
|
for (size_t i = 0; i < precedenceStates.size(); i++) {
|
||||||
data->push_back(precedenceStates.at(i));
|
data->push_back((size_t)precedenceStates.at(i));
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t nrules = atn->ruleToStartState.size();
|
size_t nrules = atn->ruleToStartState.size();
|
||||||
data->push_back(nrules);
|
data->push_back(nrules);
|
||||||
for (int r = 0; r < (int)nrules; r++) {
|
for (size_t r = 0; r < nrules; r++) {
|
||||||
ATNState *ruleStartState = atn->ruleToStartState[r];
|
ATNState *ruleStartState = atn->ruleToStartState[r];
|
||||||
data->push_back(ruleStartState->stateNumber);
|
data->push_back((size_t)ruleStartState->stateNumber);
|
||||||
if (atn->grammarType == ATNType::LEXER) {
|
if (atn->grammarType == ATNType::LEXER) {
|
||||||
if (atn->ruleToTokenType[r] == Token::_EOF) {
|
if (atn->ruleToTokenType[r] == Token::_EOF) {
|
||||||
data->push_back(WCHAR_MAX);
|
data->push_back(WCHAR_MAX);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
data->push_back(atn->ruleToTokenType[r]);
|
data->push_back((size_t)atn->ruleToTokenType[r]);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (atn->ruleToActionIndex[r] == -1) {
|
if (atn->ruleToActionIndex[r] == -1) {
|
||||||
data->push_back(WCHAR_MAX);
|
data->push_back(WCHAR_MAX);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
data->push_back(atn->ruleToActionIndex[r]);
|
data->push_back((size_t)atn->ruleToActionIndex[r]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -175,36 +174,35 @@ std::vector<size_t>* ATNSerializer::serialize() {
|
||||||
data->push_back(nmodes);
|
data->push_back(nmodes);
|
||||||
if (nmodes > 0) {
|
if (nmodes > 0) {
|
||||||
for (const auto &modeStartState : atn->modeToStartState) {
|
for (const auto &modeStartState : atn->modeToStartState) {
|
||||||
data->push_back(modeStartState->stateNumber);
|
data->push_back((size_t)modeStartState->stateNumber);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t nsets = sets.size();
|
size_t nsets = sets.size();
|
||||||
data->push_back(nsets);
|
data->push_back(nsets);
|
||||||
for (auto set : sets) {
|
for (auto set : sets) {
|
||||||
bool containsEof = set->contains(Token::_EOF);
|
bool containsEof = set.contains(Token::_EOF);
|
||||||
if (containsEof && set->getIntervals().at(0)->b == Token::_EOF) {
|
if (containsEof && set.getIntervals().at(0).b == Token::_EOF) {
|
||||||
data->push_back(set->getIntervals().size() - 1);
|
data->push_back(set.getIntervals().size() - 1);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
data->push_back(set->getIntervals().size());
|
data->push_back(set.getIntervals().size());
|
||||||
}
|
}
|
||||||
|
|
||||||
data->push_back(containsEof ? 1 : 0);
|
data->push_back(containsEof ? 1 : 0);
|
||||||
for (misc::Interval *I : set->getIntervals()) {
|
for (auto &interval : set.getIntervals()) {
|
||||||
if (I->a == Token::_EOF) {
|
if (interval.a == Token::_EOF) {
|
||||||
if (I->b == Token::_EOF) {
|
if (interval.b == Token::_EOF) {
|
||||||
continue;
|
continue;
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
data->push_back(0);
|
data->push_back(0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
data->push_back(I->a);
|
data->push_back((size_t)interval.a);
|
||||||
}
|
}
|
||||||
|
|
||||||
data->push_back(I->b);
|
data->push_back((size_t)interval.b);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -219,12 +217,11 @@ std::vector<size_t>* ATNSerializer::serialize() {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int i = 0; i < s->getNumberOfTransitions(); i++) {
|
for (size_t i = 0; i < s->getNumberOfTransitions(); i++) {
|
||||||
Transition *t = s->transition(i);
|
Transition *t = s->transition(i);
|
||||||
|
|
||||||
if (atn->states[t->target->stateNumber] == nullptr) {
|
if (atn->states[(size_t)t->target->stateNumber] == nullptr) {
|
||||||
throw IllegalStateException(
|
throw IllegalStateException(L"Cannot serialize a transition to a removed state.");
|
||||||
L"Cannot serialize a transition to a removed state.");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int src = s->stateNumber;
|
int src = s->stateNumber;
|
||||||
|
@ -285,37 +282,37 @@ std::vector<size_t>* ATNSerializer::serialize() {
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case Transition::SET:
|
case Transition::SET:
|
||||||
arg1 = (*setIndices)[(static_cast<SetTransition *>(t))->set];
|
arg1 = setIndices[(static_cast<SetTransition *>(t))->set];
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case Transition::NOT_SET:
|
case Transition::NOT_SET:
|
||||||
arg1 = (*setIndices)[(static_cast<SetTransition *>(t))->set];
|
arg1 = setIndices[(static_cast<SetTransition *>(t))->set];
|
||||||
break;
|
break;
|
||||||
case Transition::WILDCARD:
|
case Transition::WILDCARD:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
data->push_back(src);
|
data->push_back((size_t)src);
|
||||||
data->push_back(trg);
|
data->push_back((size_t)trg);
|
||||||
data->push_back(edgeType);
|
data->push_back((size_t)edgeType);
|
||||||
data->push_back(arg1);
|
data->push_back((size_t)arg1);
|
||||||
data->push_back(arg2);
|
data->push_back((size_t)arg2);
|
||||||
data->push_back(arg3);
|
data->push_back((size_t)arg3);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
size_t ndecisions = atn->decisionToState.size();
|
size_t ndecisions = atn->decisionToState.size();
|
||||||
data->push_back(ndecisions);
|
data->push_back(ndecisions);
|
||||||
for (DecisionState *decStartState : atn->decisionToState) {
|
for (DecisionState *decStartState : atn->decisionToState) {
|
||||||
data->push_back(decStartState->stateNumber);
|
data->push_back((size_t)decStartState->stateNumber);
|
||||||
}
|
}
|
||||||
|
|
||||||
// don't adjust the first value since that's the version number
|
// don't adjust the first value since that's the version number
|
||||||
for (int i = 1; i < (int)data->size(); i++) {
|
for (size_t i = 1; i < data->size(); i++) {
|
||||||
if (data->at(i) < WCHAR_MIN || data->at(i) > WCHAR_MAX) {
|
if ((wchar_t)data->at(i) < WCHAR_MIN || data->at(i) > WCHAR_MAX) {
|
||||||
throw UnsupportedOperationException(
|
throw UnsupportedOperationException(L"Serialized ATN data element out of range.");
|
||||||
L"Serialized ATN data element out of range.");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int value = (data->at(i) + 2) & 0xFFFF;
|
size_t value = (data->at(i) + 2) & 0xFFFF;
|
||||||
data->assign(i, value);
|
data->assign(i, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -335,7 +332,7 @@ std::wstring ATNSerializer::decode(const std::wstring& inpdata) {
|
||||||
|
|
||||||
std::wstring buf;
|
std::wstring buf;
|
||||||
int p = 0;
|
int p = 0;
|
||||||
int version = data[p++];
|
size_t version = (size_t)data[p++];
|
||||||
if (version != ATNDeserializer::SERIALIZED_VERSION) {
|
if (version != ATNDeserializer::SERIALIZED_VERSION) {
|
||||||
std::wstring reason =
|
std::wstring reason =
|
||||||
L"Could not deserialize ATN with version "
|
L"Could not deserialize ATN with version "
|
||||||
|
@ -474,7 +471,7 @@ std::wstring ATNSerializer::decode(const std::wstring& inpdata) {
|
||||||
.append(L"->")
|
.append(L"->")
|
||||||
.append(std::to_wstring(trg))
|
.append(std::to_wstring(trg))
|
||||||
.append(L" ")
|
.append(L" ")
|
||||||
.append(Transition::serializationNames[ttype])
|
.append(Transition::serializationNames[(size_t)ttype])
|
||||||
.append(L" ")
|
.append(L" ")
|
||||||
.append(std::to_wstring(arg1))
|
.append(std::to_wstring(arg1))
|
||||||
.append(L",")
|
.append(L",")
|
||||||
|
@ -492,7 +489,7 @@ std::wstring ATNSerializer::decode(const std::wstring& inpdata) {
|
||||||
return buf;
|
return buf;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::wstring ATNSerializer::getTokenName(int t) {
|
std::wstring ATNSerializer::getTokenName(ssize_t t) {
|
||||||
if (t == -1) {
|
if (t == -1) {
|
||||||
return L"EOF";
|
return L"EOF";
|
||||||
}
|
}
|
||||||
|
@ -515,21 +512,21 @@ std::wstring ATNSerializer::getTokenName(int t) {
|
||||||
case L'\'':
|
case L'\'':
|
||||||
return L"'\\''";
|
return L"'\\''";
|
||||||
default:
|
default:
|
||||||
std::wstring s_hex = antlrcpp::toHexString(t);
|
std::wstring s_hex = antlrcpp::toHexString((int)t);
|
||||||
if (s_hex >= L"0" && s_hex <= L"7F" &&
|
if (s_hex >= L"0" && s_hex <= L"7F" &&
|
||||||
!iscntrl(t)) {
|
!iscntrl((int)t)) {
|
||||||
return L"'" + std::to_wstring(t) + L"'";
|
return L"'" + std::to_wstring(t) + L"'";
|
||||||
}
|
}
|
||||||
// turn on the bit above max "\uFFFF" value so that we pad with zeros
|
// turn on the bit above max "\uFFFF" value so that we pad with zeros
|
||||||
// then only take last 4 digits
|
// then only take last 4 digits
|
||||||
std::wstring hex = antlrcpp::toHexString(t | 0x10000).substr(1, 4);
|
std::wstring hex = antlrcpp::toHexString((int)t | 0x10000).substr(1, 4);
|
||||||
std::wstring unicodeStr = std::wstring(L"'\\u") + hex + std::wstring(L"'");
|
std::wstring unicodeStr = std::wstring(L"'\\u") + hex + std::wstring(L"'");
|
||||||
return unicodeStr;
|
return unicodeStr;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (tokenNames.size() > 0 && t >= 0 && t < (int)tokenNames.size()) {
|
if (tokenNames.size() > 0 && t >= 0 && t < (ssize_t)tokenNames.size()) {
|
||||||
return tokenNames[t];
|
return tokenNames[(size_t)t];
|
||||||
}
|
}
|
||||||
|
|
||||||
return antlrcpp::StringConverterHelper::toString(t);
|
return antlrcpp::StringConverterHelper::toString(t);
|
||||||
|
|
|
@ -77,7 +77,7 @@ namespace atn {
|
||||||
|
|
||||||
virtual std::wstring decode(const std::wstring& data);
|
virtual std::wstring decode(const std::wstring& data);
|
||||||
|
|
||||||
virtual std::wstring getTokenName(int t);
|
virtual std::wstring getTokenName(ssize_t t);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Used by Java target to encode short/int array as chars in string.
|
/// Used by Java target to encode short/int array as chars in string.
|
||||||
|
|
|
@ -80,7 +80,8 @@ void ATNSimulator::checkCondition(bool condition, const std::wstring &message) {
|
||||||
(new ATNDeserializer())->checkCondition(condition, message);
|
(new ATNDeserializer())->checkCondition(condition, message);
|
||||||
}
|
}
|
||||||
|
|
||||||
Transition *ATNSimulator::edgeFactory(const ATN &atn, int type, int src, int trg, int arg1, int arg2, int arg3, std::vector<misc::IntervalSet*> &sets) {
|
Transition *ATNSimulator::edgeFactory(const ATN &atn, int type, int src, int trg, int arg1, int arg2, int arg3,
|
||||||
|
const std::vector<misc::IntervalSet> &sets) {
|
||||||
return (new ATNDeserializer())->edgeFactory(atn, type, src, trg, arg1, arg2, arg3, sets);
|
return (new ATNDeserializer())->edgeFactory(atn, type, src, trg, arg1, arg2, arg3, sets);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -32,6 +32,7 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "ATN.h"
|
#include "ATN.h"
|
||||||
|
#include "IntervalSet.h"
|
||||||
|
|
||||||
namespace org {
|
namespace org {
|
||||||
namespace antlr {
|
namespace antlr {
|
||||||
|
@ -101,7 +102,8 @@ namespace atn {
|
||||||
static void checkCondition(bool condition, const std::wstring &message);
|
static void checkCondition(bool condition, const std::wstring &message);
|
||||||
|
|
||||||
/// @deprecated Use <seealso cref="ATNDeserializer#edgeFactory"/> instead.
|
/// @deprecated Use <seealso cref="ATNDeserializer#edgeFactory"/> instead.
|
||||||
static Transition *edgeFactory(const ATN &atn, int type, int src, int trg, int arg1, int arg2, int arg3, std::vector<misc::IntervalSet*> &sets);
|
static Transition *edgeFactory(const ATN &atn, int type, int src, int trg, int arg1, int arg2, int arg3,
|
||||||
|
const std::vector<misc::IntervalSet> &sets);
|
||||||
|
|
||||||
/// @deprecated Use <seealso cref="ATNDeserializer#stateFactory"/> instead.
|
/// @deprecated Use <seealso cref="ATNDeserializer#stateFactory"/> instead.
|
||||||
static ATNState *stateFactory(int type, int ruleIndex);
|
static ATNState *stateFactory(int type, int ruleIndex);
|
||||||
|
|
|
@ -47,8 +47,8 @@ const wchar_t * ATNState::serializationNames[] = {L"INVALID", L"BASIC", L"RULE_
|
||||||
L"PLUS_BLOCK_START", L"STAR_BLOCK_START", L"TOKEN_START", L"RULE_STOP",
|
L"PLUS_BLOCK_START", L"STAR_BLOCK_START", L"TOKEN_START", L"RULE_STOP",
|
||||||
L"BLOCK_END", L"STAR_LOOP_BACK", L"STAR_LOOP_ENTRY", L"PLUS_LOOP_BACK", L"LOOP_END"};
|
L"BLOCK_END", L"STAR_LOOP_BACK", L"STAR_LOOP_ENTRY", L"PLUS_LOOP_BACK", L"LOOP_END"};
|
||||||
|
|
||||||
int ATNState::hashCode() {
|
size_t ATNState::hashCode() {
|
||||||
return stateNumber;
|
return (size_t)stateNumber;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ATNState::equals(void *o) {
|
bool ATNState::equals(void *o) {
|
||||||
|
@ -73,8 +73,8 @@ std::vector<Transition*> ATNState::getTransitions() {
|
||||||
return arr;
|
return arr;
|
||||||
}
|
}
|
||||||
|
|
||||||
int ATNState::getNumberOfTransitions() {
|
size_t ATNState::getNumberOfTransitions() {
|
||||||
return (int)transitions.size();
|
return transitions.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
void ATNState::addTransition(Transition *e) {
|
void ATNState::addTransition(Transition *e) {
|
||||||
|
@ -92,11 +92,11 @@ void ATNState::addTransition(int index, Transition *e) {
|
||||||
transitions.insert(transitions.begin() + index, e);
|
transitions.insert(transitions.begin() + index, e);
|
||||||
}
|
}
|
||||||
|
|
||||||
Transition *ATNState::transition(int i) {
|
Transition *ATNState::transition(size_t i) {
|
||||||
return transitions[i];
|
return transitions[i];
|
||||||
}
|
}
|
||||||
|
|
||||||
void ATNState::setTransition(int i, Transition *e) {
|
void ATNState::setTransition(size_t i, Transition *e) {
|
||||||
transitions[i] = e;
|
transitions[i] = e;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -31,6 +31,8 @@
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include "IntervalSet.h"
|
||||||
|
|
||||||
namespace org {
|
namespace org {
|
||||||
namespace antlr {
|
namespace antlr {
|
||||||
namespace v4 {
|
namespace v4 {
|
||||||
|
@ -141,9 +143,9 @@ namespace atn {
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Used to cache lookahead during parsing, not used during construction </summary>
|
/// Used to cache lookahead during parsing, not used during construction </summary>
|
||||||
public:
|
public:
|
||||||
misc::IntervalSet *nextTokenWithinRule;
|
misc::IntervalSet nextTokenWithinRule;
|
||||||
|
|
||||||
virtual int hashCode();
|
virtual size_t hashCode();
|
||||||
virtual bool equals(void *o);
|
virtual bool equals(void *o);
|
||||||
|
|
||||||
virtual bool isNonGreedyExitState();
|
virtual bool isNonGreedyExitState();
|
||||||
|
@ -152,15 +154,15 @@ namespace atn {
|
||||||
|
|
||||||
virtual std::vector<Transition*> getTransitions();
|
virtual std::vector<Transition*> getTransitions();
|
||||||
|
|
||||||
virtual int getNumberOfTransitions();
|
virtual size_t getNumberOfTransitions();
|
||||||
|
|
||||||
virtual void addTransition(Transition *e);
|
virtual void addTransition(Transition *e);
|
||||||
|
|
||||||
virtual void addTransition(int index, Transition *e);
|
virtual void addTransition(int index, Transition *e);
|
||||||
|
|
||||||
virtual Transition *transition(int i);
|
virtual Transition *transition(size_t i);
|
||||||
|
|
||||||
virtual void setTransition(int i, Transition *e);
|
virtual void setTransition(size_t i, Transition *e);
|
||||||
|
|
||||||
virtual Transition *removeTransition(int index);
|
virtual Transition *removeTransition(int index);
|
||||||
|
|
||||||
|
|
|
@ -39,18 +39,18 @@ ActionTransition::ActionTransition(ATNState *target, int ruleIndex) : Transition
|
||||||
ActionTransition::ActionTransition(ATNState *target, int ruleIndex, int actionIndex, bool isCtxDependent) : Transition(target), ruleIndex(ruleIndex), actionIndex(actionIndex), isCtxDependent(isCtxDependent) {
|
ActionTransition::ActionTransition(ATNState *target, int ruleIndex, int actionIndex, bool isCtxDependent) : Transition(target), ruleIndex(ruleIndex), actionIndex(actionIndex), isCtxDependent(isCtxDependent) {
|
||||||
}
|
}
|
||||||
|
|
||||||
int ActionTransition::getSerializationType() {
|
int ActionTransition::getSerializationType() const {
|
||||||
return ACTION;
|
return ACTION;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ActionTransition::isEpsilon() {
|
bool ActionTransition::isEpsilon() const {
|
||||||
return true; // we are to be ignored by analysis 'cept for predicates
|
return true; // we are to be ignored by analysis 'cept for predicates
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ActionTransition::matches(int symbol, int minVocabSymbol, int maxVocabSymbol) {
|
bool ActionTransition::matches(int symbol, int minVocabSymbol, int maxVocabSymbol) const {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::wstring ActionTransition::toString() {
|
std::wstring ActionTransition::toString() const {
|
||||||
return std::wstring(L"action_") + std::to_wstring(ruleIndex) + std::wstring(L":") + std::to_wstring(actionIndex);
|
return std::wstring(L"action_") + std::to_wstring(ruleIndex) + std::wstring(L":") + std::to_wstring(actionIndex);
|
||||||
}
|
}
|
||||||
|
|
|
@ -49,13 +49,13 @@ namespace atn {
|
||||||
|
|
||||||
ActionTransition(ATNState *target, int ruleIndex, int actionIndex, bool isCtxDependent);
|
ActionTransition(ATNState *target, int ruleIndex, int actionIndex, bool isCtxDependent);
|
||||||
|
|
||||||
virtual int getSerializationType() override;
|
virtual int getSerializationType() const override;
|
||||||
|
|
||||||
virtual bool isEpsilon() override;
|
virtual bool isEpsilon() const override;
|
||||||
|
|
||||||
virtual bool matches(int symbol, int minVocabSymbol, int maxVocabSymbol) override;
|
virtual bool matches(int symbol, int minVocabSymbol, int maxVocabSymbol) const override;
|
||||||
|
|
||||||
virtual std::wstring toString();
|
virtual std::wstring toString() const;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace atn
|
} // namespace atn
|
||||||
|
|
|
@ -30,62 +30,50 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "Arrays.h"
|
#include "Arrays.h"
|
||||||
|
#include "SingletonPredictionContext.h"
|
||||||
|
|
||||||
#include "ArrayPredictionContext.h"
|
#include "ArrayPredictionContext.h"
|
||||||
|
|
||||||
using namespace org::antlr::v4::runtime::atn;
|
using namespace org::antlr::v4::runtime::atn;
|
||||||
|
|
||||||
#ifdef TODO
|
ArrayPredictionContext::ArrayPredictionContext(SingletonPredictionContext *a)
|
||||||
//the base class hash code is gettings set to 0 here, what do we want?
|
: ArrayPredictionContext({ a->parent }, { a->returnState }) {
|
||||||
stopffds
|
|
||||||
#endif
|
|
||||||
ArrayPredictionContext::ArrayPredictionContext(SingletonPredictionContext *a) : PredictionContext(0) {
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ArrayPredictionContext::ArrayPredictionContext(std::PredictionContext *parents, int returnStates[]) : PredictionContext(calculateHashCode(parents, *returnStates))/*, parents(parents)*/, returnStates(*returnStates) {
|
ArrayPredictionContext::ArrayPredictionContext(const std::vector<PredictionContext *> &parents, const std::vector<int> &returnStates)
|
||||||
#ifdef TODO
|
: PredictionContext(calculateHashCode(parents, returnStates)), parents(parents), returnStates(returnStates) {
|
||||||
// assert(parents != nullptr && sizeof(parents) / sizeof(parents[0]) > 0);
|
assert(parents.size() > 0);
|
||||||
// assert(returnStates != nullptr && sizeof(returnStates) / sizeof(returnStates[0]) > 0);
|
assert(returnStates.size() > 0);
|
||||||
// Setup the parents variable correctly since we're not setting it in the constructor line above
|
|
||||||
// std::vector<PredictionContext*>
|
|
||||||
#endif
|
|
||||||
// System.err.println("CREATE ARRAY: "+Arrays.toString(parents)+", "+Arrays.toString(returnStates));
|
|
||||||
}
|
}
|
||||||
ArrayPredictionContext::ArrayPredictionContext(std::vector<PredictionContext *>parents,
|
|
||||||
const std::vector<int> returnStates) : PredictionContext(0) {
|
bool ArrayPredictionContext::isEmpty() const {
|
||||||
throw new TODOException(L"ArrayPredictionContext::ArrayPredictionContext");
|
// Since EMPTY_RETURN_STATE can only appear in the last position, we don't need to verify that size == 1.
|
||||||
}
|
|
||||||
bool ArrayPredictionContext::isEmpty() {
|
|
||||||
// since EMPTY_RETURN_STATE can only appear in the last position, we
|
|
||||||
// don't need to verify that size==1
|
|
||||||
return returnStates[0] == EMPTY_RETURN_STATE;
|
return returnStates[0] == EMPTY_RETURN_STATE;
|
||||||
}
|
}
|
||||||
|
|
||||||
int ArrayPredictionContext::size() {
|
size_t ArrayPredictionContext::size() const {
|
||||||
return (int)returnStates.size();
|
return returnStates.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
PredictionContext *ArrayPredictionContext::getParent(int index) {
|
PredictionContext* ArrayPredictionContext::getParent(size_t index) const {
|
||||||
return parents->at(index);
|
return parents[index];
|
||||||
}
|
}
|
||||||
|
|
||||||
int ArrayPredictionContext::getReturnState(int index) {
|
int ArrayPredictionContext::getReturnState(size_t index) const {
|
||||||
return returnStates[index];
|
return returnStates[index];
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ArrayPredictionContext::equals(void *o) {
|
bool ArrayPredictionContext::operator == (PredictionContext *o) const {
|
||||||
if (this == o) {
|
if (this == o) {
|
||||||
return true;
|
return true;
|
||||||
} else if (!((ArrayPredictionContext*)o/*dynamic_cast<ArrayPredictionContext*>(o)*/ != nullptr)) {
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this->hashCode() != ((ArrayPredictionContext*)o)->hashCode()) {
|
ArrayPredictionContext *other = dynamic_cast<ArrayPredictionContext*>(o);
|
||||||
|
if (other == nullptr || hashCode() != other->hashCode()) {
|
||||||
return false; // can't be same if hash is different
|
return false; // can't be same if hash is different
|
||||||
}
|
}
|
||||||
|
|
||||||
ArrayPredictionContext *a = static_cast<ArrayPredictionContext*>(o);
|
return antlrcpp::Arrays::equals(returnStates, other->returnStates) && antlrcpp::Arrays::equals(parents, other->parents);
|
||||||
return antlrcpp::Arrays::equals(returnStates, a->returnStates) && antlrcpp::Arrays::equals(&parents, &a->parents);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
std::wstring ArrayPredictionContext::toString() {
|
std::wstring ArrayPredictionContext::toString() {
|
||||||
|
@ -103,9 +91,9 @@ std::wstring ArrayPredictionContext::toString() {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
buf->append(std::to_wstring(returnStates.at(i)));
|
buf->append(std::to_wstring(returnStates.at(i)));
|
||||||
if (parents->at(i) != nullptr) {
|
if (parents[i] != nullptr) {
|
||||||
buf->append(L" ");
|
buf->append(L" ");
|
||||||
buf->append(parents->at(i)->toString());
|
buf->append(parents[i]->toString());
|
||||||
} else {
|
} else {
|
||||||
buf->append(L"null");
|
buf->append(L"null");
|
||||||
}
|
}
|
||||||
|
|
|
@ -43,40 +43,23 @@ namespace atn {
|
||||||
class SingletonPredictionContext;
|
class SingletonPredictionContext;
|
||||||
|
|
||||||
class ArrayPredictionContext : public PredictionContext {
|
class ArrayPredictionContext : public PredictionContext {
|
||||||
/// <summary>
|
|
||||||
/// Parent can be null only if full ctx mode and we make an array
|
|
||||||
/// from <seealso cref="#EMPTY"/> and non-empty. We merge <seealso cref="#EMPTY"/> by using null parent and
|
|
||||||
/// returnState == <seealso cref="#EMPTY_RETURN_STATE"/>.
|
|
||||||
/// </summary>
|
|
||||||
public:
|
public:
|
||||||
const std::vector<PredictionContext*> *parents;
|
/// Parent can be empty only if full ctx mode and we make an array
|
||||||
|
/// from EMPTY and non-empty. We merge EMPTY by using null parent and
|
||||||
|
/// returnState == EMPTY_RETURN_STATE.
|
||||||
|
const std::vector<PredictionContext*> &parents;
|
||||||
|
|
||||||
/// <summary>
|
/// Sorted for merge, no duplicates; if present, EMPTY_RETURN_STATE is always last.
|
||||||
/// Sorted for merge, no duplicates; if present,
|
const std::vector<int> &returnStates;
|
||||||
/// <seealso cref="#EMPTY_RETURN_STATE"/> is always last.
|
|
||||||
/// </summary>
|
|
||||||
const std::vector<int> returnStates;
|
|
||||||
|
|
||||||
ArrayPredictionContext(SingletonPredictionContext *a); //this(new PredictionContext[] {a.parent}, new int[] {a.returnState});
|
ArrayPredictionContext(SingletonPredictionContext *a); //this(new PredictionContext[] {a.parent}, new int[] {a.returnState});
|
||||||
|
ArrayPredictionContext(const std::vector<PredictionContext *> &parents, const std::vector<int> &returnStates);
|
||||||
|
|
||||||
ArrayPredictionContext(PredictionContext *parents, int returnStates[]);
|
virtual bool isEmpty() const override;
|
||||||
ArrayPredictionContext(std::vector<PredictionContext *>parents,
|
virtual size_t size() const override;
|
||||||
const std::vector<int> returnStates);
|
virtual PredictionContext *getParent(size_t index) const override;
|
||||||
|
virtual int getReturnState(size_t index) const override;
|
||||||
virtual bool isEmpty() override;
|
bool operator == (PredictionContext *o) const override;
|
||||||
|
|
||||||
virtual int size() override;
|
|
||||||
|
|
||||||
virtual PredictionContext *getParent(int index) override;
|
|
||||||
|
|
||||||
virtual int getReturnState(int index) override;
|
|
||||||
|
|
||||||
// @Override
|
|
||||||
// public int findReturnState(int returnState) {
|
|
||||||
// return Arrays.binarySearch(returnStates, returnState);
|
|
||||||
// }
|
|
||||||
|
|
||||||
virtual bool equals(void *o) override;
|
|
||||||
|
|
||||||
virtual std::wstring toString();
|
virtual std::wstring toString();
|
||||||
};
|
};
|
||||||
|
|
|
@ -41,18 +41,18 @@ using namespace org::antlr::v4::runtime::atn;
|
||||||
AtomTransition::AtomTransition(ATNState *target, int label) : Transition(target), _label(label) {
|
AtomTransition::AtomTransition(ATNState *target, int label) : Transition(target), _label(label) {
|
||||||
}
|
}
|
||||||
|
|
||||||
int AtomTransition::getSerializationType() {
|
int AtomTransition::getSerializationType() const {
|
||||||
return ATOM;
|
return ATOM;
|
||||||
}
|
}
|
||||||
|
|
||||||
IntervalSet *AtomTransition::label() {
|
IntervalSet AtomTransition::label() const {
|
||||||
return IntervalSet::of(_label);
|
return IntervalSet::of(_label);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool AtomTransition::matches(int symbol, int minVocabSymbol, int maxVocabSymbol) {
|
bool AtomTransition::matches(int symbol, int minVocabSymbol, int maxVocabSymbol) const {
|
||||||
return _label == symbol;
|
return _label == symbol;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::wstring AtomTransition::toString() {
|
std::wstring AtomTransition::toString() const {
|
||||||
return antlrcpp::StringConverterHelper::toString(_label);
|
return antlrcpp::StringConverterHelper::toString(_label);
|
||||||
}
|
}
|
||||||
|
|
|
@ -49,12 +49,12 @@ namespace atn {
|
||||||
|
|
||||||
AtomTransition(ATNState *target, int label);
|
AtomTransition(ATNState *target, int label);
|
||||||
|
|
||||||
virtual int getSerializationType() override;
|
virtual int getSerializationType() const override;
|
||||||
|
|
||||||
virtual misc::IntervalSet *label() override;
|
virtual misc::IntervalSet label() const override;
|
||||||
virtual bool matches(int symbol, int minVocabSymbol, int maxVocabSymbol) override;
|
virtual bool matches(int symbol, int minVocabSymbol, int maxVocabSymbol) const override;
|
||||||
|
|
||||||
virtual std::wstring toString();
|
virtual std::wstring toString() const;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace atn
|
} // namespace atn
|
||||||
|
|
|
@ -36,26 +36,26 @@ using namespace org::antlr::v4::runtime::atn;
|
||||||
EmptyPredictionContext::EmptyPredictionContext() : SingletonPredictionContext(nullptr, EMPTY_RETURN_STATE) {
|
EmptyPredictionContext::EmptyPredictionContext() : SingletonPredictionContext(nullptr, EMPTY_RETURN_STATE) {
|
||||||
}
|
}
|
||||||
|
|
||||||
bool EmptyPredictionContext::isEmpty() {
|
bool EmptyPredictionContext::isEmpty() const {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
int EmptyPredictionContext::size() {
|
size_t EmptyPredictionContext::size() const {
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
org::antlr::v4::runtime::atn::PredictionContext *EmptyPredictionContext::getParent(int index) {
|
org::antlr::v4::runtime::atn::PredictionContext *EmptyPredictionContext::getParent(size_t index) const {
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
int EmptyPredictionContext::getReturnState(int index) {
|
int EmptyPredictionContext::getReturnState(size_t index) const {
|
||||||
return returnState;
|
return returnState;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool EmptyPredictionContext::equals(void *o) {
|
bool EmptyPredictionContext::operator == (PredictionContext *o) const {
|
||||||
return this == o;
|
return this == o;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::wstring EmptyPredictionContext::toString() {
|
std::wstring EmptyPredictionContext::toString() const {
|
||||||
return L"$";
|
return L"$";
|
||||||
}
|
}
|
||||||
|
|
|
@ -43,16 +43,13 @@ namespace atn {
|
||||||
public:
|
public:
|
||||||
EmptyPredictionContext();
|
EmptyPredictionContext();
|
||||||
|
|
||||||
virtual bool isEmpty() override;
|
virtual bool isEmpty() const override;
|
||||||
virtual int size() override;
|
virtual size_t size() const override;
|
||||||
|
virtual PredictionContext *getParent(size_t index) const override;
|
||||||
|
virtual int getReturnState(size_t index) const override;
|
||||||
|
virtual std::wstring toString() const override;
|
||||||
|
|
||||||
virtual PredictionContext *getParent(int index) override;
|
virtual bool operator == (PredictionContext *o) const override;
|
||||||
|
|
||||||
virtual int getReturnState(int index) override;
|
|
||||||
|
|
||||||
virtual bool equals(void *o) override;
|
|
||||||
|
|
||||||
virtual std::wstring toString() override;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace atn
|
} // namespace atn
|
||||||
|
|
|
@ -36,18 +36,18 @@ using namespace org::antlr::v4::runtime::atn;
|
||||||
EpsilonTransition::EpsilonTransition(ATNState *target) : Transition(target) {
|
EpsilonTransition::EpsilonTransition(ATNState *target) : Transition(target) {
|
||||||
}
|
}
|
||||||
|
|
||||||
int EpsilonTransition::getSerializationType() {
|
int EpsilonTransition::getSerializationType() const {
|
||||||
return EPSILON;
|
return EPSILON;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool EpsilonTransition::isEpsilon() {
|
bool EpsilonTransition::isEpsilon() const {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool EpsilonTransition::matches(int symbol, int minVocabSymbol, int maxVocabSymbol) {
|
bool EpsilonTransition::matches(int symbol, int minVocabSymbol, int maxVocabSymbol) const {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::wstring EpsilonTransition::toString() {
|
std::wstring EpsilonTransition::toString() const {
|
||||||
return L"epsilon";
|
return L"epsilon";
|
||||||
}
|
}
|
||||||
|
|
|
@ -43,12 +43,12 @@ namespace atn {
|
||||||
public:
|
public:
|
||||||
EpsilonTransition(ATNState *target);
|
EpsilonTransition(ATNState *target);
|
||||||
|
|
||||||
virtual int getSerializationType() override;
|
virtual int getSerializationType() const override;
|
||||||
|
|
||||||
virtual bool isEpsilon() override;
|
virtual bool isEpsilon() const override;
|
||||||
virtual bool matches(int symbol, int minVocabSymbol, int maxVocabSymbol) override;
|
virtual bool matches(int symbol, int minVocabSymbol, int maxVocabSymbol) const override;
|
||||||
|
|
||||||
virtual std::wstring toString();
|
virtual std::wstring toString() const;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace atn
|
} // namespace atn
|
||||||
|
|
|
@ -47,85 +47,85 @@ using namespace org::antlr::v4::runtime::atn;
|
||||||
LL1Analyzer::LL1Analyzer(const ATN &atn) : _atn(atn) {
|
LL1Analyzer::LL1Analyzer(const ATN &atn) : _atn(atn) {
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<misc::IntervalSet*> LL1Analyzer::getDecisionLookahead(ATNState *s) {
|
std::vector<misc::IntervalSet> LL1Analyzer::getDecisionLookahead(ATNState *s) const {
|
||||||
// System.out.println("LOOK("+s.stateNumber+")");
|
std::vector<misc::IntervalSet> look;
|
||||||
std::vector<misc::IntervalSet*> look;
|
|
||||||
|
|
||||||
if (s == nullptr) {
|
if (s == nullptr) {
|
||||||
return look;
|
return look;
|
||||||
}
|
}
|
||||||
|
|
||||||
// need s->getNumberOfTransitions()); of them
|
look.resize(s->getNumberOfTransitions()); // Fills all interval sets with defaults.
|
||||||
for (int alt = 0; alt < s->getNumberOfTransitions(); alt++) {
|
for (size_t alt = 0; alt < s->getNumberOfTransitions(); alt++) {
|
||||||
look[alt] = new misc::IntervalSet(0);
|
std::set<ATNConfig*> lookBusy;
|
||||||
std::set<ATNConfig*> *lookBusy = new std::set<ATNConfig*>();
|
|
||||||
bool seeThruPreds = false; // fail to get lookahead upon pred
|
bool seeThruPreds = false; // fail to get lookahead upon pred
|
||||||
_LOOK(s->transition(alt)->target, nullptr, (PredictionContext*)PredictionContext::EMPTY, look[alt], lookBusy, new antlrcpp::BitSet(), seeThruPreds, false);
|
_LOOK(s->transition(alt)->target, nullptr, (PredictionContext*)PredictionContext::EMPTY, look[alt], lookBusy, new antlrcpp::BitSet(), seeThruPreds, false);
|
||||||
|
|
||||||
// Wipe out lookahead for this alternative if we found nothing
|
// Wipe out lookahead for this alternative if we found nothing
|
||||||
// or we had a predicate when we !seeThruPreds
|
// or we had a predicate when we !seeThruPreds
|
||||||
if (look[alt]->size() == 0 || look[alt]->contains(HIT_PRED)) {
|
if (look[alt].size() == 0 || look[alt].contains(HIT_PRED)) {
|
||||||
// TODO: memory managment, delete
|
look[alt].clear();
|
||||||
delete look[alt];
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return look;
|
return look;
|
||||||
}
|
}
|
||||||
|
|
||||||
misc::IntervalSet *LL1Analyzer::LOOK(ATNState *s, RuleContext *ctx) {
|
misc::IntervalSet LL1Analyzer::LOOK(ATNState *s, RuleContext *ctx) const {
|
||||||
return LOOK(s, nullptr, ctx);
|
return LOOK(s, nullptr, ctx);
|
||||||
}
|
}
|
||||||
|
|
||||||
misc::IntervalSet *LL1Analyzer::LOOK(ATNState *s, ATNState *stopState, RuleContext *ctx) {
|
misc::IntervalSet LL1Analyzer::LOOK(ATNState *s, ATNState *stopState, RuleContext *ctx) const {
|
||||||
misc::IntervalSet *r = new misc::IntervalSet(0);
|
misc::IntervalSet r;
|
||||||
bool seeThruPreds = true; // ignore preds; get all lookahead
|
bool seeThruPreds = true; // ignore preds; get all lookahead
|
||||||
PredictionContext *lookContext = ctx != nullptr ? PredictionContext::fromRuleContext(*s->atn, ctx) : nullptr;
|
PredictionContext *lookContext = ctx != nullptr ? PredictionContext::fromRuleContext(*s->atn, ctx) : nullptr;
|
||||||
_LOOK(s, stopState, lookContext, r, new std::set<ATNConfig*>(), new antlrcpp::BitSet(), seeThruPreds, true);
|
std::set<ATNConfig*> lookBusy;
|
||||||
|
_LOOK(s, stopState, lookContext, r, lookBusy, new antlrcpp::BitSet(), seeThruPreds, true);
|
||||||
|
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
void LL1Analyzer::_LOOK(ATNState *s, ATNState *stopState, PredictionContext *ctx, misc::IntervalSet *look, std::set<ATNConfig*> *lookBusy, antlrcpp::BitSet *calledRuleStack, bool seeThruPreds, bool addEOF) {
|
void LL1Analyzer::_LOOK(ATNState *s, ATNState *stopState, PredictionContext *ctx, misc::IntervalSet &look,
|
||||||
// System.out.println("_LOOK("+s.stateNumber+", ctx="+ctx);
|
std::set<ATNConfig*> &lookBusy, antlrcpp::BitSet *calledRuleStack, bool seeThruPreds, bool addEOF) const {
|
||||||
ATNConfig *c = new ATNConfig(s, 0, ctx);
|
ATNConfig *c = new ATNConfig(s, 0, ctx);
|
||||||
|
|
||||||
if (!lookBusy->insert(c).second) {
|
if (!lookBusy.insert(c).second) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (s == stopState) {
|
if (s == stopState) {
|
||||||
if (ctx == nullptr) {
|
if (ctx == nullptr) {
|
||||||
look->add(Token::EPSILON);
|
look.add(Token::EPSILON);
|
||||||
return;
|
return;
|
||||||
} else if (ctx->isEmpty() && addEOF) {
|
} else if (ctx->isEmpty() && addEOF) {
|
||||||
look->add(Token::_EOF);
|
look.add(Token::_EOF);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (dynamic_cast<RuleStopState*>(s) != nullptr) {
|
if (dynamic_cast<RuleStopState*>(s) != nullptr) {
|
||||||
if (ctx == nullptr) {
|
if (ctx == nullptr) {
|
||||||
look->add(Token::EPSILON);
|
look.add(Token::EPSILON);
|
||||||
return;
|
return;
|
||||||
} else if (ctx->isEmpty() && addEOF) {
|
} else if (ctx->isEmpty() && addEOF) {
|
||||||
look->add(Token::_EOF);
|
look.add(Token::_EOF);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ctx != (PredictionContext*)PredictionContext::EMPTY) {
|
if (ctx != (PredictionContext*)PredictionContext::EMPTY) {
|
||||||
// run thru all possible stack tops in ctx
|
// run thru all possible stack tops in ctx
|
||||||
for (int i = 0; i < ctx->size(); i++) {
|
for (size_t i = 0; i < ctx->size(); i++) {
|
||||||
ATNState *returnState = _atn.states[ctx->getReturnState(i)];
|
ATNState *returnState = _atn.states[(size_t)ctx->getReturnState(i)];
|
||||||
// System.out.println("popping back to "+retState);
|
// System.out.println("popping back to "+retState);
|
||||||
|
|
||||||
bool removed = calledRuleStack->data.test(returnState->ruleIndex);
|
bool removed = calledRuleStack->data.test((size_t)returnState->ruleIndex);
|
||||||
try {
|
try {
|
||||||
calledRuleStack->data[returnState->ruleIndex] = false;
|
calledRuleStack->data[(size_t)returnState->ruleIndex] = false;
|
||||||
_LOOK(returnState, stopState, ctx->getParent(i), look, lookBusy, calledRuleStack, seeThruPreds, addEOF);
|
_LOOK(returnState, stopState, ctx->getParent(i), look, lookBusy, calledRuleStack, seeThruPreds, addEOF);
|
||||||
}
|
}
|
||||||
catch(...) {
|
catch(...) {
|
||||||
// Just move to the next steps as a "finally" clause
|
// Just move to the next steps as a "finally" clause
|
||||||
}
|
}
|
||||||
if (removed) {
|
if (removed) {
|
||||||
calledRuleStack->set(returnState->ruleIndex);
|
calledRuleStack->set((size_t)returnState->ruleIndex);
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -133,44 +133,43 @@ void LL1Analyzer::_LOOK(ATNState *s, ATNState *stopState, PredictionContext *ctx
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int n = s->getNumberOfTransitions();
|
size_t n = s->getNumberOfTransitions();
|
||||||
for (int i = 0; i < n; i++) {
|
for (size_t i = 0; i < n; i++) {
|
||||||
Transition *t = s->transition(i);
|
Transition *t = s->transition(i);
|
||||||
|
|
||||||
if (typeid(t) == typeid(RuleTransition)) {
|
if (typeid(t) == typeid(RuleTransition)) {
|
||||||
if ( (*calledRuleStack).data[(static_cast<RuleTransition*>(t))->target->ruleIndex]) {
|
if ( (*calledRuleStack).data[(size_t)(static_cast<RuleTransition*>(t))->target->ruleIndex]) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
PredictionContext *newContext = SingletonPredictionContext::create(ctx, (static_cast<RuleTransition*>(t))->followState->stateNumber);
|
PredictionContext *newContext = SingletonPredictionContext::create(ctx, (static_cast<RuleTransition*>(t))->followState->stateNumber);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
calledRuleStack->set((static_cast<RuleTransition*>(t))->target->ruleIndex);
|
calledRuleStack->set((size_t)(static_cast<RuleTransition*>(t))->target->ruleIndex);
|
||||||
_LOOK(t->target, stopState, newContext, look, lookBusy, calledRuleStack, seeThruPreds, addEOF);
|
_LOOK(t->target, stopState, newContext, look, lookBusy, calledRuleStack, seeThruPreds, addEOF);
|
||||||
}
|
}
|
||||||
catch(...) {
|
catch(...) {
|
||||||
// Just move to the next steps as a "finally" clause
|
// Just move to the next steps as a "finally" clause
|
||||||
}
|
}
|
||||||
calledRuleStack->data[((static_cast<RuleTransition*>(t))->target->ruleIndex)] = false;
|
calledRuleStack->data[(size_t)((static_cast<RuleTransition*>(t))->target->ruleIndex)] = false;
|
||||||
|
|
||||||
} else if (dynamic_cast<AbstractPredicateTransition*>(t) != nullptr) {
|
} else if (dynamic_cast<AbstractPredicateTransition*>(t) != nullptr) {
|
||||||
if (seeThruPreds) {
|
if (seeThruPreds) {
|
||||||
_LOOK(t->target, stopState, ctx, look, lookBusy, calledRuleStack, seeThruPreds, addEOF);
|
_LOOK(t->target, stopState, ctx, look, lookBusy, calledRuleStack, seeThruPreds, addEOF);
|
||||||
} else {
|
} else {
|
||||||
look->add(HIT_PRED);
|
look.add(HIT_PRED);
|
||||||
}
|
}
|
||||||
} else if (t->isEpsilon()) {
|
} else if (t->isEpsilon()) {
|
||||||
_LOOK(t->target, stopState, ctx, look, lookBusy, calledRuleStack, seeThruPreds, addEOF);
|
_LOOK(t->target, stopState, ctx, look, lookBusy, calledRuleStack, seeThruPreds, addEOF);
|
||||||
} else if (typeid(t) == typeid(WildcardTransition)) {
|
} else if (typeid(t) == typeid(WildcardTransition)) {
|
||||||
look->addAll(misc::IntervalSet::of(Token::MIN_USER_TOKEN_TYPE, _atn.maxTokenType));
|
look.addAll(misc::IntervalSet::of(Token::MIN_USER_TOKEN_TYPE, _atn.maxTokenType));
|
||||||
} else {
|
} else {
|
||||||
// System.out.println("adding "+ t);
|
misc::IntervalSet set = t->label();
|
||||||
misc::IntervalSet *set = t->label();
|
if (!set.isEmpty()) {
|
||||||
if (set != nullptr) {
|
|
||||||
if (dynamic_cast<NotSetTransition*>(t) != nullptr) {
|
if (dynamic_cast<NotSetTransition*>(t) != nullptr) {
|
||||||
set = set->complement(misc::IntervalSet::of(Token::MIN_USER_TOKEN_TYPE, _atn.maxTokenType));
|
set = set.complement(misc::IntervalSet::of(Token::MIN_USER_TOKEN_TYPE, _atn.maxTokenType));
|
||||||
}
|
}
|
||||||
look->addAll(set);
|
look.addAll(set);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -61,7 +61,7 @@ namespace atn {
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="s"> the ATN state </param>
|
/// <param name="s"> the ATN state </param>
|
||||||
/// <returns> the expected symbols for each outgoing transition of {@code s}. </returns>
|
/// <returns> the expected symbols for each outgoing transition of {@code s}. </returns>
|
||||||
virtual std::vector<misc::IntervalSet*> getDecisionLookahead(ATNState *s);
|
virtual std::vector<misc::IntervalSet> getDecisionLookahead(ATNState *s) const;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Compute set of tokens that can follow {@code s} in the ATN in the
|
/// Compute set of tokens that can follow {@code s} in the ATN in the
|
||||||
|
@ -78,7 +78,7 @@ namespace atn {
|
||||||
/// </param>
|
/// </param>
|
||||||
/// <returns> The set of tokens that can follow {@code s} in the ATN in the
|
/// <returns> The set of tokens that can follow {@code s} in the ATN in the
|
||||||
/// specified {@code ctx}. </returns>
|
/// specified {@code ctx}. </returns>
|
||||||
virtual misc::IntervalSet *LOOK(ATNState *s, RuleContext *ctx);
|
virtual misc::IntervalSet LOOK(ATNState *s, RuleContext *ctx) const;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Compute set of tokens that can follow {@code s} in the ATN in the
|
/// Compute set of tokens that can follow {@code s} in the ATN in the
|
||||||
|
@ -97,7 +97,7 @@ namespace atn {
|
||||||
/// </param>
|
/// </param>
|
||||||
/// <returns> The set of tokens that can follow {@code s} in the ATN in the
|
/// <returns> The set of tokens that can follow {@code s} in the ATN in the
|
||||||
/// specified {@code ctx}. </returns>
|
/// specified {@code ctx}. </returns>
|
||||||
virtual misc::IntervalSet *LOOK(ATNState *s, ATNState *stopState, RuleContext *ctx);
|
virtual misc::IntervalSet LOOK(ATNState *s, ATNState *stopState, RuleContext *ctx) const;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Compute set of tokens that can follow {@code s} in the ATN in the
|
/// Compute set of tokens that can follow {@code s} in the ATN in the
|
||||||
|
@ -129,7 +129,8 @@ namespace atn {
|
||||||
/// outermost context is reached. This parameter has no effect if {@code ctx}
|
/// outermost context is reached. This parameter has no effect if {@code ctx}
|
||||||
/// is {@code null}. </param>
|
/// is {@code null}. </param>
|
||||||
protected:
|
protected:
|
||||||
virtual void _LOOK(ATNState *s, ATNState *stopState, PredictionContext *ctx, misc::IntervalSet *look, std::set<ATNConfig*> *lookBusy, antlrcpp::BitSet *calledRuleStack, bool seeThruPreds, bool addEOF);
|
virtual void _LOOK(ATNState *s, ATNState *stopState, PredictionContext *ctx, misc::IntervalSet &look,
|
||||||
|
std::set<ATNConfig*> &lookBusy, antlrcpp::BitSet *calledRuleStack, bool seeThruPreds, bool addEOF) const;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace atn
|
} // namespace atn
|
||||||
|
|
|
@ -66,11 +66,11 @@ bool LexerATNConfig::hasPassedThroughNonGreedyDecision() {
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t LexerATNConfig::hashCode() const {
|
size_t LexerATNConfig::hashCode() const {
|
||||||
int hashCode = misc::MurmurHash::initialize(7);
|
size_t hashCode = misc::MurmurHash::initialize(7);
|
||||||
hashCode = misc::MurmurHash::update(hashCode, state->stateNumber);
|
hashCode = misc::MurmurHash::update(hashCode, (size_t)state->stateNumber);
|
||||||
hashCode = misc::MurmurHash::update(hashCode, alt);
|
hashCode = misc::MurmurHash::update(hashCode, (size_t)alt);
|
||||||
hashCode = misc::MurmurHash::update(hashCode, context);
|
hashCode = misc::MurmurHash::update(hashCode, (size_t)context);
|
||||||
hashCode = misc::MurmurHash::update(hashCode, semanticContext);
|
hashCode = misc::MurmurHash::update(hashCode, (size_t)semanticContext);
|
||||||
hashCode = misc::MurmurHash::update(hashCode, passedThroughNonGreedyDecision ? 1 : 0);
|
hashCode = misc::MurmurHash::update(hashCode, passedThroughNonGreedyDecision ? 1 : 0);
|
||||||
hashCode = misc::MurmurHash::finish(hashCode, 5);
|
hashCode = misc::MurmurHash::finish(hashCode, 5);
|
||||||
return hashCode;
|
return hashCode;
|
||||||
|
|
|
@ -56,6 +56,7 @@ void LexerATNSimulator::SimState::reset() {
|
||||||
charPos = -1;
|
charPos = -1;
|
||||||
// TODO: Memory Management - delete
|
// TODO: Memory Management - delete
|
||||||
delete dfaState;
|
delete dfaState;
|
||||||
|
dfaState = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
void LexerATNSimulator::SimState::InitializeInstanceFields() {
|
void LexerATNSimulator::SimState::InitializeInstanceFields() {
|
||||||
|
@ -72,24 +73,24 @@ LexerATNSimulator::LexerATNSimulator(const ATN &atn, const std::vector<dfa::DFA*
|
||||||
}
|
}
|
||||||
|
|
||||||
LexerATNSimulator::LexerATNSimulator(Lexer *recog, const ATN &atn, const std::vector<dfa::DFA*> &decisionToDFA, PredictionContextCache *sharedContextCache)
|
LexerATNSimulator::LexerATNSimulator(Lexer *recog, const ATN &atn, const std::vector<dfa::DFA*> &decisionToDFA, PredictionContextCache *sharedContextCache)
|
||||||
: ATNSimulator(atn, sharedContextCache), recog(recog), _decisionToDFA(decisionToDFA), prevAccept(new SimState()) {
|
: ATNSimulator(atn, sharedContextCache), _recog(recog), _decisionToDFA(decisionToDFA), prevAccept(new SimState()) {
|
||||||
InitializeInstanceFields();
|
InitializeInstanceFields();
|
||||||
}
|
}
|
||||||
|
|
||||||
void LexerATNSimulator::copyState(LexerATNSimulator *simulator) {
|
void LexerATNSimulator::copyState(LexerATNSimulator *simulator) {
|
||||||
this->charPositionInLine = simulator->charPositionInLine;
|
_charPositionInLine = simulator->_charPositionInLine;
|
||||||
this->line = simulator->line;
|
_line = simulator->_line;
|
||||||
this->mode = simulator->mode;
|
_mode = simulator->_mode;
|
||||||
this->startIndex = simulator->startIndex;
|
_startIndex = simulator->_startIndex;
|
||||||
}
|
}
|
||||||
|
|
||||||
int LexerATNSimulator::match(CharStream *input, int mode) {
|
int LexerATNSimulator::match(CharStream *input, size_t mode) {
|
||||||
match_calls++;
|
match_calls++;
|
||||||
this->mode = mode;
|
_mode = mode;
|
||||||
int mark = input->mark();
|
ssize_t mark = input->mark();
|
||||||
try {
|
try {
|
||||||
this->startIndex = input->index();
|
_startIndex = (int)input->index();
|
||||||
this->prevAccept->reset();
|
prevAccept->reset();
|
||||||
dfa::DFA *dfa = _decisionToDFA[mode];
|
dfa::DFA *dfa = _decisionToDFA[mode];
|
||||||
if (dfa->s0 == nullptr) {
|
if (dfa->s0 == nullptr) {
|
||||||
return matchATN(input);
|
return matchATN(input);
|
||||||
|
@ -105,20 +106,21 @@ int LexerATNSimulator::match(CharStream *input, int mode) {
|
||||||
|
|
||||||
void LexerATNSimulator::reset() {
|
void LexerATNSimulator::reset() {
|
||||||
prevAccept->reset();
|
prevAccept->reset();
|
||||||
startIndex = -1;
|
_startIndex = 0; // Originally -1, but that would require a signed type with many casts.
|
||||||
line = 1;
|
// The initial value is never tested, so it doesn't matter which value is set here.
|
||||||
charPositionInLine = 0;
|
_line = 1;
|
||||||
mode = Lexer::DEFAULT_MODE;
|
_charPositionInLine = 0;
|
||||||
|
_mode = Lexer::DEFAULT_MODE;
|
||||||
}
|
}
|
||||||
|
|
||||||
int LexerATNSimulator::matchATN(CharStream *input) {
|
int LexerATNSimulator::matchATN(CharStream *input) {
|
||||||
ATNState *startState = (ATNState *)atn.modeToStartState.at(mode);
|
ATNState *startState = (ATNState *)atn.modeToStartState.at(_mode);
|
||||||
|
|
||||||
if (debug) {
|
if (debug) {
|
||||||
std::wcout << L"matchATN mode" << mode << L" start: " << startState << std::endl;
|
std::wcout << L"matchATN mode" << _mode << L" start: " << startState << std::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
int old_mode = mode;
|
size_t old_mode = _mode;
|
||||||
|
|
||||||
ATNConfigSet *s0_closure = computeStartState(input, startState);
|
ATNConfigSet *s0_closure = computeStartState(input, startState);
|
||||||
bool suppressEdge = s0_closure->hasSemanticContext;
|
bool suppressEdge = s0_closure->hasSemanticContext;
|
||||||
|
@ -126,7 +128,7 @@ int LexerATNSimulator::matchATN(CharStream *input) {
|
||||||
|
|
||||||
dfa::DFAState *next = addDFAState(s0_closure);
|
dfa::DFAState *next = addDFAState(s0_closure);
|
||||||
if (!suppressEdge) {
|
if (!suppressEdge) {
|
||||||
_decisionToDFA[mode]->s0 = next;
|
_decisionToDFA[_mode]->s0 = next;
|
||||||
}
|
}
|
||||||
|
|
||||||
int predict = execATN(input, next);
|
int predict = execATN(input, next);
|
||||||
|
@ -144,7 +146,7 @@ int LexerATNSimulator::execATN(CharStream *input, dfa::DFAState *ds0) {
|
||||||
std::wcout << L"start state closure=" << ds0->configs << std::endl;
|
std::wcout << L"start state closure=" << ds0->configs << std::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
int t = input->LA(1);
|
size_t t = input->LA(1);
|
||||||
dfa::DFAState *s = ds0; // s is current/from DFA state
|
dfa::DFAState *s = ds0; // s is current/from DFA state
|
||||||
|
|
||||||
while (true) { // while more work
|
while (true) { // while more work
|
||||||
|
@ -196,8 +198,8 @@ int LexerATNSimulator::execATN(CharStream *input, dfa::DFAState *ds0) {
|
||||||
return failOrAccept(prevAccept, input, s->configs, t);
|
return failOrAccept(prevAccept, input, s->configs, t);
|
||||||
}
|
}
|
||||||
|
|
||||||
dfa::DFAState *LexerATNSimulator::getExistingTargetState(dfa::DFAState *s, int t) {
|
dfa::DFAState *LexerATNSimulator::getExistingTargetState(dfa::DFAState *s, size_t t) {
|
||||||
if (s->edges.size() == 0 || t < MIN_DFA_EDGE || t > MAX_DFA_EDGE) {
|
if (s->edges.size() == 0 || /*t < MIN_DFA_EDGE ||*/ t > MAX_DFA_EDGE) {
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -209,7 +211,7 @@ dfa::DFAState *LexerATNSimulator::getExistingTargetState(dfa::DFAState *s, int t
|
||||||
return target;
|
return target;
|
||||||
}
|
}
|
||||||
|
|
||||||
dfa::DFAState *LexerATNSimulator::computeTargetState(CharStream *input, dfa::DFAState *s, int t) {
|
dfa::DFAState *LexerATNSimulator::computeTargetState(CharStream *input, dfa::DFAState *s, size_t t) {
|
||||||
OrderedATNConfigSet *reach = new OrderedATNConfigSet();
|
OrderedATNConfigSet *reach = new OrderedATNConfigSet();
|
||||||
|
|
||||||
// if we don't find an existing DFA state
|
// if we don't find an existing DFA state
|
||||||
|
@ -228,23 +230,23 @@ dfa::DFAState *LexerATNSimulator::computeTargetState(CharStream *input, dfa::DFA
|
||||||
return addDFAEdge(s, t, reach);
|
return addDFAEdge(s, t, reach);
|
||||||
}
|
}
|
||||||
|
|
||||||
int LexerATNSimulator::failOrAccept(SimState *prevAccept, CharStream *input, ATNConfigSet *reach, int t) {
|
int LexerATNSimulator::failOrAccept(SimState *prevAccept, CharStream *input, ATNConfigSet *reach, size_t t) {
|
||||||
if (prevAccept->dfaState != nullptr) {
|
if (prevAccept->dfaState != nullptr) {
|
||||||
int ruleIndex = prevAccept->dfaState->lexerRuleIndex;
|
int ruleIndex = prevAccept->dfaState->lexerRuleIndex;
|
||||||
int actionIndex = prevAccept->dfaState->lexerActionIndex;
|
int actionIndex = prevAccept->dfaState->lexerActionIndex;
|
||||||
accept(input, ruleIndex, actionIndex, prevAccept->index, prevAccept->line, prevAccept->charPos);
|
accept(input, ruleIndex, actionIndex, (size_t)prevAccept->index, prevAccept->line, (size_t)prevAccept->charPos);
|
||||||
return prevAccept->dfaState->prediction;
|
return prevAccept->dfaState->prediction;
|
||||||
} else {
|
} else {
|
||||||
// if no accept and EOF is first char, return EOF
|
// if no accept and EOF is first char, return EOF
|
||||||
if (t == IntStream::_EOF && input->index() == startIndex) {
|
if (t == IntStream::_EOF && input->index() == (size_t)_startIndex) {
|
||||||
return Token::_EOF;
|
return Token::_EOF;
|
||||||
}
|
}
|
||||||
|
|
||||||
throw LexerNoViableAltException(recog, input, startIndex, reach);
|
throw LexerNoViableAltException(_recog, input, (size_t)_startIndex, reach);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void LexerATNSimulator::getReachableConfigSet(CharStream *input, ATNConfigSet *closure, ATNConfigSet *reach, int t) {
|
void LexerATNSimulator::getReachableConfigSet(CharStream *input, ATNConfigSet *closure, ATNConfigSet *reach, size_t t) {
|
||||||
// this is used to skip processing for configs which have a lower priority
|
// this is used to skip processing for configs which have a lower priority
|
||||||
// than a config that already reached an accept state for the same rule
|
// than a config that already reached an accept state for the same rule
|
||||||
int skipAlt = ATN::INVALID_ALT_NUMBER;
|
int skipAlt = ATN::INVALID_ALT_NUMBER;
|
||||||
|
@ -255,13 +257,13 @@ void LexerATNSimulator::getReachableConfigSet(CharStream *input, ATNConfigSet *c
|
||||||
}
|
}
|
||||||
|
|
||||||
if (debug) {
|
if (debug) {
|
||||||
std::wcout << L"testing " << getTokenName(t) << " at " <<c->toString(recog, true) << std::endl;
|
std::wcout << L"testing " << getTokenName(t) << " at " <<c->toString(_recog, true) << std::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
int n = c->state->getNumberOfTransitions();
|
size_t n = c->state->getNumberOfTransitions();
|
||||||
for (int ti = 0; ti < n; ti++) { // for each transition
|
for (size_t ti = 0; ti < n; ti++) { // for each transition
|
||||||
Transition *trans = c->state->transition(ti);
|
Transition *trans = c->state->transition(ti);
|
||||||
ATNState *target = getReachableTarget(trans, t);
|
ATNState *target = getReachableTarget(trans, (int)t);
|
||||||
if (target != nullptr) {
|
if (target != nullptr) {
|
||||||
if (this->closure(input, new LexerATNConfig(static_cast<LexerATNConfig*>(c), target), reach, currentAltReachedAcceptState, true)) {
|
if (this->closure(input, new LexerATNConfig(static_cast<LexerATNConfig*>(c), target), reach, currentAltReachedAcceptState, true)) {
|
||||||
// any remaining configs for this alt have a lower priority than
|
// any remaining configs for this alt have a lower priority than
|
||||||
|
@ -274,25 +276,25 @@ void LexerATNSimulator::getReachableConfigSet(CharStream *input, ATNConfigSet *c
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void LexerATNSimulator::accept(CharStream *input, int ruleIndex, int actionIndex, int index, int line, int charPos) {
|
void LexerATNSimulator::accept(CharStream *input, int ruleIndex, int actionIndex, size_t index, size_t line, size_t charPos) {
|
||||||
if (debug) {
|
if (debug) {
|
||||||
std::wcout << L"ACTION ";
|
std::wcout << L"ACTION ";
|
||||||
if (recog != nullptr) {
|
if (_recog != nullptr) {
|
||||||
std::wcout << recog->getRuleNames()[ruleIndex];
|
std::wcout << _recog->getRuleNames()[(size_t)ruleIndex];
|
||||||
} else {
|
} else {
|
||||||
std::wcout << ruleIndex;
|
std::wcout << ruleIndex;
|
||||||
}
|
}
|
||||||
std::wcout << ":" << actionIndex << std::endl;
|
std::wcout << ":" << actionIndex << std::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (actionIndex >= 0 && recog != nullptr) {
|
if (actionIndex >= 0 && _recog != nullptr) {
|
||||||
recog->action(nullptr, ruleIndex, actionIndex);
|
_recog->action(nullptr, ruleIndex, actionIndex);
|
||||||
}
|
}
|
||||||
|
|
||||||
// seek to after last char in token
|
// seek to after last char in token
|
||||||
input->seek(index);
|
input->seek(index);
|
||||||
this->line = line;
|
_line = line;
|
||||||
this->charPositionInLine = charPos;
|
_charPositionInLine = (int)charPos;
|
||||||
if (input->LA(1) != IntStream::_EOF) {
|
if (input->LA(1) != IntStream::_EOF) {
|
||||||
consume(input);
|
consume(input);
|
||||||
}
|
}
|
||||||
|
@ -309,9 +311,9 @@ atn::ATNState *LexerATNSimulator::getReachableTarget(Transition *trans, int t) {
|
||||||
atn::ATNConfigSet *LexerATNSimulator::computeStartState(CharStream *input, ATNState *p) {
|
atn::ATNConfigSet *LexerATNSimulator::computeStartState(CharStream *input, ATNState *p) {
|
||||||
EmptyPredictionContext * initialContext = PredictionContext::EMPTY;
|
EmptyPredictionContext * initialContext = PredictionContext::EMPTY;
|
||||||
ATNConfigSet *configs = new OrderedATNConfigSet();
|
ATNConfigSet *configs = new OrderedATNConfigSet();
|
||||||
for (int i = 0; i < p->getNumberOfTransitions(); i++) {
|
for (size_t i = 0; i < p->getNumberOfTransitions(); i++) {
|
||||||
ATNState *target = p->transition(i)->target;
|
ATNState *target = p->transition(i)->target;
|
||||||
LexerATNConfig *c = new LexerATNConfig(target, i + 1, (PredictionContext*)initialContext);
|
LexerATNConfig *c = new LexerATNConfig(target, (int)(i + 1), (PredictionContext*)initialContext);
|
||||||
closure(input, c, configs, false, false);
|
closure(input, c, configs, false, false);
|
||||||
}
|
}
|
||||||
return configs;
|
return configs;
|
||||||
|
@ -319,13 +321,13 @@ atn::ATNConfigSet *LexerATNSimulator::computeStartState(CharStream *input, ATNSt
|
||||||
|
|
||||||
bool LexerATNSimulator::closure(CharStream *input, LexerATNConfig *config, ATNConfigSet *configs, bool currentAltReachedAcceptState, bool speculative) {
|
bool LexerATNSimulator::closure(CharStream *input, LexerATNConfig *config, ATNConfigSet *configs, bool currentAltReachedAcceptState, bool speculative) {
|
||||||
if (debug) {
|
if (debug) {
|
||||||
std::wcout << L"closure(" << config->toString(recog, true) << L")" << std::endl;
|
std::wcout << L"closure(" << config->toString(_recog, true) << L")" << std::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (dynamic_cast<RuleStopState*>(config->state) != nullptr) {
|
if (dynamic_cast<RuleStopState*>(config->state) != nullptr) {
|
||||||
if (debug) {
|
if (debug) {
|
||||||
if (recog != nullptr) {
|
if (_recog != nullptr) {
|
||||||
std::wcout << L"closure at " << recog->getRuleNames()[config->state->ruleIndex] << L" rule stop " << config << std::endl;
|
std::wcout << L"closure at " << _recog->getRuleNames()[(size_t)config->state->ruleIndex] << L" rule stop " << config << std::endl;
|
||||||
} else {
|
} else {
|
||||||
std::wcout << L"closure at rule stop " << config << std::endl;
|
std::wcout << L"closure at rule stop " << config << std::endl;
|
||||||
}
|
}
|
||||||
|
@ -342,10 +344,10 @@ bool LexerATNSimulator::closure(CharStream *input, LexerATNConfig *config, ATNCo
|
||||||
}
|
}
|
||||||
|
|
||||||
if (config->context != nullptr && !config->context->isEmpty()) {
|
if (config->context != nullptr && !config->context->isEmpty()) {
|
||||||
for (int i = 0; i < config->context->size(); i++) {
|
for (size_t i = 0; i < config->context->size(); i++) {
|
||||||
if (config->context->getReturnState(i) != PredictionContext::EMPTY_RETURN_STATE) {
|
if (config->context->getReturnState(i) != PredictionContext::EMPTY_RETURN_STATE) {
|
||||||
PredictionContext *newContext = config->context->getParent(i); // "pop" return state
|
PredictionContext *newContext = config->context->getParent(i); // "pop" return state
|
||||||
ATNState *returnState = atn.states[config->context->getReturnState(i)];
|
ATNState *returnState = atn.states[(size_t)config->context->getReturnState(i)];
|
||||||
LexerATNConfig *c = new LexerATNConfig(returnState, config->alt, newContext);
|
LexerATNConfig *c = new LexerATNConfig(returnState, config->alt, newContext);
|
||||||
currentAltReachedAcceptState = closure(input, c, configs, currentAltReachedAcceptState, speculative);
|
currentAltReachedAcceptState = closure(input, c, configs, currentAltReachedAcceptState, speculative);
|
||||||
}
|
}
|
||||||
|
@ -363,7 +365,7 @@ bool LexerATNSimulator::closure(CharStream *input, LexerATNConfig *config, ATNCo
|
||||||
}
|
}
|
||||||
|
|
||||||
ATNState *p = config->state;
|
ATNState *p = config->state;
|
||||||
for (int i = 0; i < p->getNumberOfTransitions(); i++) {
|
for (size_t i = 0; i < p->getNumberOfTransitions(); i++) {
|
||||||
Transition *t = p->transition(i);
|
Transition *t = p->transition(i);
|
||||||
LexerATNConfig *c = getEpsilonTarget(input, config, t, configs, speculative);
|
LexerATNConfig *c = getEpsilonTarget(input, config, t, configs, speculative);
|
||||||
if (c != nullptr) {
|
if (c != nullptr) {
|
||||||
|
@ -433,24 +435,24 @@ atn::LexerATNConfig *LexerATNSimulator::getEpsilonTarget(CharStream *input, Lexe
|
||||||
|
|
||||||
bool LexerATNSimulator::evaluatePredicate(CharStream *input, int ruleIndex, int predIndex, bool speculative) {
|
bool LexerATNSimulator::evaluatePredicate(CharStream *input, int ruleIndex, int predIndex, bool speculative) {
|
||||||
// assume true if no recognizer was provided
|
// assume true if no recognizer was provided
|
||||||
if (recog == nullptr) {
|
if (_recog == nullptr) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!speculative) {
|
if (!speculative) {
|
||||||
return recog->sempred(nullptr, ruleIndex, predIndex);
|
return _recog->sempred(nullptr, ruleIndex, predIndex);
|
||||||
}
|
}
|
||||||
|
|
||||||
int savedCharPositionInLine = charPositionInLine;
|
int savedCharPositionInLine = _charPositionInLine;
|
||||||
int savedLine = line;
|
size_t savedLine = _line;
|
||||||
int index = input->index();
|
size_t index = input->index();
|
||||||
int marker = input->mark();
|
ssize_t marker = input->mark();
|
||||||
try {
|
try {
|
||||||
consume(input);
|
consume(input);
|
||||||
return recog->sempred(nullptr, ruleIndex, predIndex);
|
return _recog->sempred(nullptr, ruleIndex, predIndex);
|
||||||
} catch(...) {
|
} catch(...) {
|
||||||
charPositionInLine = savedCharPositionInLine;
|
_charPositionInLine = savedCharPositionInLine;
|
||||||
line = savedLine;
|
_line = savedLine;
|
||||||
input->seek(index);
|
input->seek(index);
|
||||||
input->release(marker);
|
input->release(marker);
|
||||||
}
|
}
|
||||||
|
@ -458,13 +460,13 @@ bool LexerATNSimulator::evaluatePredicate(CharStream *input, int ruleIndex, int
|
||||||
}
|
}
|
||||||
|
|
||||||
void LexerATNSimulator::captureSimState(SimState *settings, CharStream *input, dfa::DFAState *dfaState) {
|
void LexerATNSimulator::captureSimState(SimState *settings, CharStream *input, dfa::DFAState *dfaState) {
|
||||||
settings->index = input->index();
|
settings->index = (int)input->index();
|
||||||
settings->line = line;
|
settings->line = _line;
|
||||||
settings->charPos = charPositionInLine;
|
settings->charPos = _charPositionInLine;
|
||||||
settings->dfaState = dfaState;
|
settings->dfaState = dfaState;
|
||||||
}
|
}
|
||||||
|
|
||||||
dfa::DFAState *LexerATNSimulator::addDFAEdge(dfa::DFAState *from, int t, ATNConfigSet *q) {
|
dfa::DFAState *LexerATNSimulator::addDFAEdge(dfa::DFAState *from, size_t t, ATNConfigSet *q) {
|
||||||
/* leading to this call, ATNConfigSet.hasSemanticContext is used as a
|
/* leading to this call, ATNConfigSet.hasSemanticContext is used as a
|
||||||
* marker indicating dynamic predicate evaluation makes this edge
|
* marker indicating dynamic predicate evaluation makes this edge
|
||||||
* dependent on the specific input sequence, so the static edge in the
|
* dependent on the specific input sequence, so the static edge in the
|
||||||
|
@ -489,8 +491,8 @@ dfa::DFAState *LexerATNSimulator::addDFAEdge(dfa::DFAState *from, int t, ATNConf
|
||||||
return to;
|
return to;
|
||||||
}
|
}
|
||||||
|
|
||||||
void LexerATNSimulator::addDFAEdge(dfa::DFAState *p, int t, dfa::DFAState *q) {
|
void LexerATNSimulator::addDFAEdge(dfa::DFAState *p, size_t t, dfa::DFAState *q) {
|
||||||
if (t < MIN_DFA_EDGE || t > MAX_DFA_EDGE) {
|
if (/*t < MIN_DFA_EDGE ||*/ t > MAX_DFA_EDGE) {
|
||||||
// Only track edges within the DFA bounds
|
// Only track edges within the DFA bounds
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -528,10 +530,10 @@ dfa::DFAState *LexerATNSimulator::addDFAState(ATNConfigSet *configs) {
|
||||||
proposed->isAcceptState = true;
|
proposed->isAcceptState = true;
|
||||||
proposed->lexerRuleIndex = firstConfigWithRuleStopState->state->ruleIndex;
|
proposed->lexerRuleIndex = firstConfigWithRuleStopState->state->ruleIndex;
|
||||||
proposed->lexerActionIndex = (static_cast<LexerATNConfig*>(firstConfigWithRuleStopState))->lexerActionIndex;
|
proposed->lexerActionIndex = (static_cast<LexerATNConfig*>(firstConfigWithRuleStopState))->lexerActionIndex;
|
||||||
proposed->prediction = atn.ruleToTokenType[proposed->lexerRuleIndex];
|
proposed->prediction = atn.ruleToTokenType[(size_t)proposed->lexerRuleIndex];
|
||||||
}
|
}
|
||||||
|
|
||||||
dfa::DFA *dfa = _decisionToDFA[mode];
|
dfa::DFA *dfa = _decisionToDFA[_mode];
|
||||||
|
|
||||||
{
|
{
|
||||||
std::lock_guard<std::mutex> lck(mtx);
|
std::lock_guard<std::mutex> lck(mtx);
|
||||||
|
@ -551,38 +553,38 @@ dfa::DFAState *LexerATNSimulator::addDFAState(ATNConfigSet *configs) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
dfa::DFA *LexerATNSimulator::getDFA(int mode) {
|
dfa::DFA *LexerATNSimulator::getDFA(size_t mode) {
|
||||||
return _decisionToDFA[mode];
|
return _decisionToDFA[mode];
|
||||||
}
|
}
|
||||||
|
|
||||||
std::wstring LexerATNSimulator::getText(CharStream *input) {
|
std::wstring LexerATNSimulator::getText(CharStream *input) {
|
||||||
// index is first lookahead char, don't include.
|
// index is first lookahead char, don't include.
|
||||||
return input->getText(misc::Interval::of(startIndex, input->index() - 1));
|
return input->getText(misc::Interval::of((int)_startIndex, (int)input->index() - 1));
|
||||||
}
|
}
|
||||||
|
|
||||||
int LexerATNSimulator::getLine() {
|
size_t LexerATNSimulator::getLine() const {
|
||||||
return line;
|
return _line;
|
||||||
}
|
}
|
||||||
|
|
||||||
void LexerATNSimulator::setLine(int line) {
|
void LexerATNSimulator::setLine(size_t line) {
|
||||||
this->line = line;
|
_line = line;
|
||||||
}
|
}
|
||||||
|
|
||||||
int LexerATNSimulator::getCharPositionInLine() {
|
int LexerATNSimulator::getCharPositionInLine() {
|
||||||
return charPositionInLine;
|
return _charPositionInLine;
|
||||||
}
|
}
|
||||||
|
|
||||||
void LexerATNSimulator::setCharPositionInLine(int charPositionInLine) {
|
void LexerATNSimulator::setCharPositionInLine(int charPositionInLine) {
|
||||||
this->charPositionInLine = charPositionInLine;
|
_charPositionInLine = charPositionInLine;
|
||||||
}
|
}
|
||||||
|
|
||||||
void LexerATNSimulator::consume(CharStream *input) {
|
void LexerATNSimulator::consume(CharStream *input) {
|
||||||
int curChar = input->LA(1);
|
size_t curChar = input->LA(1);
|
||||||
if (curChar == L'\n') {
|
if (curChar == L'\n') {
|
||||||
line++;
|
_line++;
|
||||||
charPositionInLine = 0;
|
_charPositionInLine = 0;
|
||||||
} else {
|
} else {
|
||||||
charPositionInLine++;
|
_charPositionInLine++;
|
||||||
}
|
}
|
||||||
input->consume();
|
input->consume();
|
||||||
}
|
}
|
||||||
|
@ -596,8 +598,8 @@ std::wstring LexerATNSimulator::getTokenName(int t) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void LexerATNSimulator::InitializeInstanceFields() {
|
void LexerATNSimulator::InitializeInstanceFields() {
|
||||||
startIndex = -1;
|
_startIndex = -1;
|
||||||
line = 1;
|
_line = 1;
|
||||||
charPositionInLine = 0;
|
_charPositionInLine = 0;
|
||||||
mode = org::antlr::v4::runtime::Lexer::DEFAULT_MODE;
|
_mode = org::antlr::v4::runtime::Lexer::DEFAULT_MODE;
|
||||||
}
|
}
|
||||||
|
|
|
@ -46,7 +46,7 @@ namespace atn {
|
||||||
class SimState {
|
class SimState {
|
||||||
protected:
|
protected:
|
||||||
int index;
|
int index;
|
||||||
int line;
|
size_t line;
|
||||||
int charPos;
|
int charPos;
|
||||||
dfa::DFAState *dfaState;
|
dfa::DFAState *dfaState;
|
||||||
virtual void reset();
|
virtual void reset();
|
||||||
|
@ -86,7 +86,7 @@ namespace atn {
|
||||||
/// can simply return the predicted token type.
|
/// can simply return the predicted token type.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
protected:
|
protected:
|
||||||
Lexer *const recog;
|
Lexer *const _recog;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The current token's starting index into the character stream.
|
/// The current token's starting index into the character stream.
|
||||||
|
@ -94,20 +94,20 @@ namespace atn {
|
||||||
/// DFA did not have a previous accept state. In this case, we use the
|
/// DFA did not have a previous accept state. In this case, we use the
|
||||||
/// ATN-generated exception object.
|
/// ATN-generated exception object.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
int startIndex;
|
int _startIndex;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// line number 1..n within the input </summary>
|
/// line number 1..n within the input </summary>
|
||||||
int line;
|
size_t _line;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The index of the character relative to the beginning of the line 0..n-1 </summary>
|
/// The index of the character relative to the beginning of the line 0..n-1 </summary>
|
||||||
int charPositionInLine;
|
int _charPositionInLine;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
const std::vector<dfa::DFA*> _decisionToDFA;
|
const std::vector<dfa::DFA*> _decisionToDFA;
|
||||||
protected:
|
protected:
|
||||||
int mode;
|
size_t _mode;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Used during DFA/ATN exec to record the most recent accept configuration info </summary>
|
/// Used during DFA/ATN exec to record the most recent accept configuration info </summary>
|
||||||
|
@ -121,7 +121,7 @@ namespace atn {
|
||||||
|
|
||||||
virtual void copyState(LexerATNSimulator *simulator);
|
virtual void copyState(LexerATNSimulator *simulator);
|
||||||
|
|
||||||
virtual int match(CharStream *input, int mode);
|
virtual int match(CharStream *input, size_t mode);
|
||||||
|
|
||||||
virtual void reset() override;
|
virtual void reset() override;
|
||||||
|
|
||||||
|
@ -140,7 +140,7 @@ namespace atn {
|
||||||
/// <returns> The existing target DFA state for the given input symbol
|
/// <returns> The existing target DFA state for the given input symbol
|
||||||
/// {@code t}, or {@code null} if the target state for this edge is not
|
/// {@code t}, or {@code null} if the target state for this edge is not
|
||||||
/// already cached </returns>
|
/// already cached </returns>
|
||||||
virtual dfa::DFAState *getExistingTargetState(dfa::DFAState *s, int t);
|
virtual dfa::DFAState *getExistingTargetState(dfa::DFAState *s, size_t t);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Compute a target state for an edge in the DFA, and attempt to add the
|
/// Compute a target state for an edge in the DFA, and attempt to add the
|
||||||
|
@ -153,18 +153,18 @@ namespace atn {
|
||||||
/// <returns> The computed target DFA state for the given input symbol
|
/// <returns> The computed target DFA state for the given input symbol
|
||||||
/// {@code t}. If {@code t} does not lead to a valid DFA state, this method
|
/// {@code t}. If {@code t} does not lead to a valid DFA state, this method
|
||||||
/// returns <seealso cref="#ERROR"/>. </returns>
|
/// returns <seealso cref="#ERROR"/>. </returns>
|
||||||
virtual dfa::DFAState *computeTargetState(CharStream *input, dfa::DFAState *s, int t);
|
virtual dfa::DFAState *computeTargetState(CharStream *input, dfa::DFAState *s, size_t t);
|
||||||
|
|
||||||
virtual int failOrAccept(SimState *prevAccept, CharStream *input, ATNConfigSet *reach, int t);
|
virtual int failOrAccept(SimState *prevAccept, CharStream *input, ATNConfigSet *reach, size_t t);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Given a starting configuration set, figure out all ATN configurations
|
/// Given a starting configuration set, figure out all ATN configurations
|
||||||
/// we can reach upon input {@code t}. Parameter {@code reach} is a return
|
/// we can reach upon input {@code t}. Parameter {@code reach} is a return
|
||||||
/// parameter.
|
/// parameter.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
void getReachableConfigSet(CharStream *input, ATNConfigSet *closure, ATNConfigSet *reach, int t);
|
void getReachableConfigSet(CharStream *input, ATNConfigSet *closure, ATNConfigSet *reach, size_t t);
|
||||||
|
|
||||||
virtual void accept(CharStream *input, int ruleIndex, int actionIndex, int index, int line, int charPos);
|
virtual void accept(CharStream *input, int ruleIndex, int actionIndex, size_t index, size_t line, size_t charPos);
|
||||||
|
|
||||||
virtual ATNState *getReachableTarget(Transition *trans, int t);
|
virtual ATNState *getReachableTarget(Transition *trans, int t);
|
||||||
|
|
||||||
|
@ -208,9 +208,9 @@ namespace atn {
|
||||||
|
|
||||||
virtual void captureSimState(SimState *settings, CharStream *input, dfa::DFAState *dfaState);
|
virtual void captureSimState(SimState *settings, CharStream *input, dfa::DFAState *dfaState);
|
||||||
|
|
||||||
virtual dfa::DFAState *addDFAEdge(dfa::DFAState *from, int t, ATNConfigSet *q);
|
virtual dfa::DFAState *addDFAEdge(dfa::DFAState *from, size_t t, ATNConfigSet *q);
|
||||||
|
|
||||||
virtual void addDFAEdge(dfa::DFAState *p, int t, dfa::DFAState *q);
|
virtual void addDFAEdge(dfa::DFAState *p, size_t t, dfa::DFAState *q);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Add a new DFA state if there isn't one with this set of
|
/// Add a new DFA state if there isn't one with this set of
|
||||||
|
@ -221,16 +221,16 @@ namespace atn {
|
||||||
virtual dfa::DFAState *addDFAState(ATNConfigSet *configs);
|
virtual dfa::DFAState *addDFAState(ATNConfigSet *configs);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
dfa::DFA *getDFA(int mode);
|
dfa::DFA *getDFA(size_t mode);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Get the text matched so far for the current token.
|
/// Get the text matched so far for the current token.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
virtual std::wstring getText(CharStream *input);
|
virtual std::wstring getText(CharStream *input);
|
||||||
|
|
||||||
virtual int getLine();
|
virtual size_t getLine() const;
|
||||||
|
|
||||||
virtual void setLine(int line);
|
virtual void setLine(size_t line);
|
||||||
|
|
||||||
virtual int getCharPositionInLine();
|
virtual int getCharPositionInLine();
|
||||||
|
|
||||||
|
|
|
@ -35,17 +35,17 @@
|
||||||
|
|
||||||
using namespace org::antlr::v4::runtime::atn;
|
using namespace org::antlr::v4::runtime::atn;
|
||||||
|
|
||||||
NotSetTransition::NotSetTransition(ATNState *target, misc::IntervalSet *set) : SetTransition(target, set) {
|
NotSetTransition::NotSetTransition(ATNState *target, const misc::IntervalSet &set) : SetTransition(target, set) {
|
||||||
}
|
}
|
||||||
|
|
||||||
int NotSetTransition::getSerializationType() {
|
int NotSetTransition::getSerializationType() const {
|
||||||
return NOT_SET;
|
return NOT_SET;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool NotSetTransition::matches(int symbol, int minVocabSymbol, int maxVocabSymbol) {
|
bool NotSetTransition::matches(int symbol, int minVocabSymbol, int maxVocabSymbol) const {
|
||||||
return symbol >= minVocabSymbol && symbol <= maxVocabSymbol && !SetTransition::matches(symbol, minVocabSymbol, maxVocabSymbol);
|
return symbol >= minVocabSymbol && symbol <= maxVocabSymbol && !SetTransition::matches(symbol, minVocabSymbol, maxVocabSymbol);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::wstring NotSetTransition::toString() {
|
std::wstring NotSetTransition::toString() const {
|
||||||
return L'~' + SetTransition::toString();
|
return L'~' + SetTransition::toString();
|
||||||
}
|
}
|
||||||
|
|
|
@ -41,13 +41,13 @@ namespace atn {
|
||||||
|
|
||||||
class NotSetTransition final : public SetTransition {
|
class NotSetTransition final : public SetTransition {
|
||||||
public:
|
public:
|
||||||
NotSetTransition(ATNState *target, misc::IntervalSet *set);
|
NotSetTransition(ATNState *target, const misc::IntervalSet &set);
|
||||||
|
|
||||||
virtual int getSerializationType() override;
|
virtual int getSerializationType() const override;
|
||||||
|
|
||||||
virtual bool matches(int symbol, int minVocabSymbol, int maxVocabSymbol) override;
|
virtual bool matches(int symbol, int minVocabSymbol, int maxVocabSymbol) const override;
|
||||||
|
|
||||||
virtual std::wstring toString() override;
|
virtual std::wstring toString() const override;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace atn
|
} // namespace atn
|
||||||
|
|
|
@ -61,6 +61,8 @@
|
||||||
using namespace org::antlr::v4::runtime;
|
using namespace org::antlr::v4::runtime;
|
||||||
using namespace org::antlr::v4::runtime::atn;
|
using namespace org::antlr::v4::runtime::atn;
|
||||||
|
|
||||||
|
using namespace antlrcpp;
|
||||||
|
|
||||||
ParserATNSimulator::ParserATNSimulator(const ATN &atn, const std::vector<dfa::DFA *>& decisionToDFA,
|
ParserATNSimulator::ParserATNSimulator(const ATN &atn, const std::vector<dfa::DFA *>& decisionToDFA,
|
||||||
PredictionContextCache *sharedContextCache)
|
PredictionContextCache *sharedContextCache)
|
||||||
: ParserATNSimulator(nullptr, atn, decisionToDFA, sharedContextCache) {
|
: ParserATNSimulator(nullptr, atn, decisionToDFA, sharedContextCache) {
|
||||||
|
@ -81,12 +83,12 @@ int ParserATNSimulator::adaptivePredict(TokenStream *input, int decision, Parser
|
||||||
}
|
}
|
||||||
|
|
||||||
_input = input;
|
_input = input;
|
||||||
_startIndex = input->index();
|
_startIndex = (int)input->index();
|
||||||
_outerContext = outerContext;
|
_outerContext = outerContext;
|
||||||
dfa::DFA *dfa = _decisionToDFA[decision];
|
dfa::DFA *dfa = _decisionToDFA[(size_t)decision];
|
||||||
|
|
||||||
int m = input->mark();
|
ssize_t m = input->mark();
|
||||||
int index = input->index();
|
size_t index = input->index();
|
||||||
|
|
||||||
// Now we are certain to have a specific decision's DFA
|
// Now we are certain to have a specific decision's DFA
|
||||||
// But, do we still need an initial state?
|
// But, do we still need an initial state?
|
||||||
|
@ -122,7 +124,8 @@ int ParserATNSimulator::adaptivePredict(TokenStream *input, int decision, Parser
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int ParserATNSimulator::execATN(dfa::DFA *dfa, dfa::DFAState *s0, TokenStream *input, int startIndex, ParserRuleContext *outerContext) {
|
int ParserATNSimulator::execATN(dfa::DFA *dfa, dfa::DFAState *s0, TokenStream *input, size_t startIndex,
|
||||||
|
ParserRuleContext *outerContext) {
|
||||||
if (debug || debug_list_atn_decisions) {
|
if (debug || debug_list_atn_decisions) {
|
||||||
std::wcout << L"execATN decision " << dfa->decision << L" exec LA(1)==" << getLookaheadName(input) << L" line " << input->LT(1)->getLine() << L":" << input->LT(1)->getCharPositionInLine() << std::endl;
|
std::wcout << L"execATN decision " << dfa->decision << L" exec LA(1)==" << getLookaheadName(input) << L" line " << input->LT(1)->getLine() << L":" << input->LT(1)->getCharPositionInLine() << std::endl;
|
||||||
}
|
}
|
||||||
|
@ -133,7 +136,7 @@ int ParserATNSimulator::execATN(dfa::DFA *dfa, dfa::DFAState *s0, TokenStream *i
|
||||||
std::wcout << L"s0 = " << s0 << std::endl;
|
std::wcout << L"s0 = " << s0 << std::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
int t = input->LA(1);
|
size_t t = input->LA(1);
|
||||||
|
|
||||||
while (true) { // while more work
|
while (true) { // while more work
|
||||||
dfa::DFAState *D = getExistingTargetState(previousD, t);
|
dfa::DFAState *D = getExistingTargetState(previousD, t);
|
||||||
|
@ -162,14 +165,14 @@ int ParserATNSimulator::execATN(dfa::DFA *dfa, dfa::DFAState *s0, TokenStream *i
|
||||||
|
|
||||||
if (D->requiresFullContext && mode != PredictionMode::SLL) {
|
if (D->requiresFullContext && mode != PredictionMode::SLL) {
|
||||||
// IF PREDS, MIGHT RESOLVE TO SINGLE ALT => SLL (or syntax error)
|
// IF PREDS, MIGHT RESOLVE TO SINGLE ALT => SLL (or syntax error)
|
||||||
antlrcpp::BitSet *conflictingAlts = nullptr;
|
BitSet *conflictingAlts = nullptr;
|
||||||
if (D->predicates.size() != 0) {
|
if (D->predicates.size() != 0) {
|
||||||
if (debug) {
|
if (debug) {
|
||||||
std::wcout << L"DFA state has preds in DFA sim LL failover" << std::endl;
|
std::wcout << L"DFA state has preds in DFA sim LL failover" << std::endl;
|
||||||
}
|
}
|
||||||
int conflictIndex = input->index();
|
size_t conflictIndex = input->index();
|
||||||
if (conflictIndex != startIndex) {
|
if (conflictIndex != (size_t)startIndex) {
|
||||||
input->seek(startIndex);
|
input->seek((size_t)startIndex);
|
||||||
}
|
}
|
||||||
|
|
||||||
conflictingAlts = evalSemanticContext(D->predicates, outerContext, true);
|
conflictingAlts = evalSemanticContext(D->predicates, outerContext, true);
|
||||||
|
@ -202,9 +205,9 @@ int ParserATNSimulator::execATN(dfa::DFA *dfa, dfa::DFAState *s0, TokenStream *i
|
||||||
return D->prediction;
|
return D->prediction;
|
||||||
}
|
}
|
||||||
|
|
||||||
int stopIndex = input->index();
|
size_t stopIndex = input->index();
|
||||||
input->seek(startIndex);
|
input->seek(startIndex);
|
||||||
antlrcpp::BitSet *alts = evalSemanticContext(D->predicates, outerContext, true);
|
BitSet *alts = evalSemanticContext(D->predicates, outerContext, true);
|
||||||
switch (alts->count()) {
|
switch (alts->count()) {
|
||||||
case 0:
|
case 0:
|
||||||
throw noViableAlt(input, outerContext, D->configs, startIndex);
|
throw noViableAlt(input, outerContext, D->configs, startIndex);
|
||||||
|
@ -229,16 +232,16 @@ int ParserATNSimulator::execATN(dfa::DFA *dfa, dfa::DFAState *s0, TokenStream *i
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
dfa::DFAState *ParserATNSimulator::getExistingTargetState(dfa::DFAState *previousD, int t) {
|
dfa::DFAState *ParserATNSimulator::getExistingTargetState(dfa::DFAState *previousD, size_t t) {
|
||||||
std::vector<dfa::DFAState *> edges = previousD->edges;
|
std::vector<dfa::DFAState *> edges = previousD->edges;
|
||||||
if (edges.size() == 0 || t + 1 < 0 || t + 1 >= (int)edges.size()) {
|
if (edges.size() == 0 || /*t + 1 < 0 ||*/ t + 1 >= edges.size()) {
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
return edges[t + 1];
|
return edges[t + 1];
|
||||||
}
|
}
|
||||||
|
|
||||||
dfa::DFAState *ParserATNSimulator::computeTargetState(dfa::DFA *dfa, dfa::DFAState *previousD, int t) {
|
dfa::DFAState *ParserATNSimulator::computeTargetState(dfa::DFA *dfa, dfa::DFAState *previousD, size_t t) {
|
||||||
ATNConfigSet *reach = computeReachSet(previousD->configs, t, false);
|
ATNConfigSet *reach = computeReachSet(previousD->configs, t, false);
|
||||||
if (reach == nullptr) {
|
if (reach == nullptr) {
|
||||||
addDFAEdge(dfa, previousD, t, &ERROR);
|
addDFAEdge(dfa, previousD, t, &ERROR);
|
||||||
|
@ -252,8 +255,8 @@ dfa::DFAState *ParserATNSimulator::computeTargetState(dfa::DFA *dfa, dfa::DFASta
|
||||||
|
|
||||||
if (debug) {
|
if (debug) {
|
||||||
|
|
||||||
std::vector<antlrcpp::BitSet> altSubSets = PredictionModeClass::getConflictingAltSubsets(reach);
|
std::vector<BitSet> altSubSets = PredictionModeClass::getConflictingAltSubsets(reach);
|
||||||
std::wstring altSubSetsStr = antlrcpp::BitSet::subStringRepresentation(altSubSets.begin(), altSubSets.end());
|
std::wstring altSubSetsStr = BitSet::subStringRepresentation(altSubSets.begin(), altSubSets.end());
|
||||||
std::wcout << L"SLL altSubSets=" << altSubSetsStr << L", configs="
|
std::wcout << L"SLL altSubSets=" << altSubSetsStr << L", configs="
|
||||||
<< reach << L", predict=" << predictedAlt << L", allSubsetsConflict="
|
<< reach << L", predict=" << predictedAlt << L", allSubsetsConflict="
|
||||||
<< PredictionModeClass::allSubsetsConflict(altSubSets)
|
<< PredictionModeClass::allSubsetsConflict(altSubSets)
|
||||||
|
@ -290,10 +293,11 @@ dfa::DFAState *ParserATNSimulator::computeTargetState(dfa::DFA *dfa, dfa::DFASta
|
||||||
void ParserATNSimulator::predicateDFAState(dfa::DFAState *dfaState, DecisionState *decisionState) {
|
void ParserATNSimulator::predicateDFAState(dfa::DFAState *dfaState, DecisionState *decisionState) {
|
||||||
// We need to test all predicates, even in DFA states that
|
// We need to test all predicates, even in DFA states that
|
||||||
// uniquely predict alternative.
|
// uniquely predict alternative.
|
||||||
int nalts = decisionState->getNumberOfTransitions();
|
size_t nalts = decisionState->getNumberOfTransitions();
|
||||||
|
|
||||||
// Update DFA so reach becomes accept state with (predicate,alt)
|
// Update DFA so reach becomes accept state with (predicate,alt)
|
||||||
// pairs if preds found for conflicting alts
|
// pairs if preds found for conflicting alts
|
||||||
antlrcpp::BitSet *altsToCollectPredsFrom = nullptr;
|
BitSet *altsToCollectPredsFrom = nullptr;
|
||||||
altsToCollectPredsFrom->data = getConflictingAltsOrUniqueAlt(dfaState->configs).data;
|
altsToCollectPredsFrom->data = getConflictingAltsOrUniqueAlt(dfaState->configs).data;
|
||||||
std::vector<SemanticContext*> altToPred = getPredsForAmbigAlts(altsToCollectPredsFrom, dfaState->configs, nalts);
|
std::vector<SemanticContext*> altToPred = getPredsForAmbigAlts(altsToCollectPredsFrom, dfaState->configs, nalts);
|
||||||
if (!altToPred.empty()) {
|
if (!altToPred.empty()) {
|
||||||
|
@ -307,7 +311,8 @@ void ParserATNSimulator::predicateDFAState(dfa::DFAState *dfaState, DecisionStat
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int ParserATNSimulator::execATNWithFullContext(dfa::DFA *dfa, dfa::DFAState *D, ATNConfigSet *s0, TokenStream *input, int startIndex, ParserRuleContext *outerContext) {
|
int ParserATNSimulator::execATNWithFullContext(dfa::DFA *dfa, dfa::DFAState *D, ATNConfigSet *s0, TokenStream *input,
|
||||||
|
size_t startIndex, ParserRuleContext *outerContext) {
|
||||||
if (debug || debug_list_atn_decisions) {
|
if (debug || debug_list_atn_decisions) {
|
||||||
std::cout << "execATNWithFullContext " << s0 << std::endl;
|
std::cout << "execATNWithFullContext " << s0 << std::endl;
|
||||||
}
|
}
|
||||||
|
@ -316,12 +321,9 @@ int ParserATNSimulator::execATNWithFullContext(dfa::DFA *dfa, dfa::DFAState *D,
|
||||||
ATNConfigSet *reach = nullptr;
|
ATNConfigSet *reach = nullptr;
|
||||||
ATNConfigSet *previous = s0;
|
ATNConfigSet *previous = s0;
|
||||||
input->seek(startIndex);
|
input->seek(startIndex);
|
||||||
int t = input->LA(1);
|
size_t t = input->LA(1);
|
||||||
int predictedAlt;
|
int predictedAlt;
|
||||||
while (true) { // while more work
|
while (true) {
|
||||||
// System.out.println("LL REACH "+getLookaheadName(input)+
|
|
||||||
// " from configs.size="+previous.size()+
|
|
||||||
// " line "+input.LT(1).getLine()+":"+input.LT(1).getCharPositionInLine());
|
|
||||||
reach = computeReachSet(previous, t, fullCtx);
|
reach = computeReachSet(previous, t, fullCtx);
|
||||||
if (reach == nullptr) {
|
if (reach == nullptr) {
|
||||||
// if any configs in previous dipped into outer context, that
|
// if any configs in previous dipped into outer context, that
|
||||||
|
@ -340,9 +342,9 @@ int ParserATNSimulator::execATNWithFullContext(dfa::DFA *dfa, dfa::DFAState *D,
|
||||||
throw noViableAlt(input, outerContext, previous, startIndex);
|
throw noViableAlt(input, outerContext, previous, startIndex);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<antlrcpp::BitSet> altSubSets =PredictionModeClass::getConflictingAltSubsets(reach);
|
std::vector<BitSet> altSubSets =PredictionModeClass::getConflictingAltSubsets(reach);
|
||||||
if (debug) {
|
if (debug) {
|
||||||
std::wstring altSubSetsStr = antlrcpp::BitSet::subStringRepresentation(altSubSets.begin(), altSubSets.end());
|
std::wstring altSubSetsStr = BitSet::subStringRepresentation(altSubSets.begin(), altSubSets.end());
|
||||||
std::wcout << L"LL altSubSets=" << altSubSetsStr << L", predict="
|
std::wcout << L"LL altSubSets=" << altSubSetsStr << L", predict="
|
||||||
<< PredictionModeClass::getUniqueAlt(altSubSets)
|
<< PredictionModeClass::getUniqueAlt(altSubSets)
|
||||||
<< L", resolvesToJustOneViableAlt="
|
<< L", resolvesToJustOneViableAlt="
|
||||||
|
@ -417,12 +419,12 @@ int ParserATNSimulator::execATNWithFullContext(dfa::DFA *dfa, dfa::DFAState *D,
|
||||||
the fact that we should predict alternative 1. We just can't say for
|
the fact that we should predict alternative 1. We just can't say for
|
||||||
sure that there is an ambiguity without looking further.
|
sure that there is an ambiguity without looking further.
|
||||||
*/
|
*/
|
||||||
reportAmbiguity(dfa, D, startIndex, input->index(), foundExactAmbig, nullptr, reach);
|
reportAmbiguity(dfa, D, (size_t)startIndex, input->index(), foundExactAmbig, nullptr, reach);
|
||||||
|
|
||||||
return predictedAlt;
|
return predictedAlt;
|
||||||
}
|
}
|
||||||
|
|
||||||
atn::ATNConfigSet *ParserATNSimulator::computeReachSet(ATNConfigSet *closure, int t, bool fullCtx) {
|
atn::ATNConfigSet *ParserATNSimulator::computeReachSet(ATNConfigSet *closure, size_t t, bool fullCtx) {
|
||||||
if (debug) {
|
if (debug) {
|
||||||
std::wcout << L"in computeReachSet, starting closure: " << closure << std::endl;
|
std::wcout << L"in computeReachSet, starting closure: " << closure << std::endl;
|
||||||
}
|
}
|
||||||
|
@ -468,10 +470,10 @@ atn::ATNConfigSet *ParserATNSimulator::computeReachSet(ATNConfigSet *closure, in
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
int n = c->state->getNumberOfTransitions();
|
size_t n = c->state->getNumberOfTransitions();
|
||||||
for (int ti = 0; ti < n; ti++) { // for each transition
|
for (size_t ti = 0; ti < n; ti++) { // for each transition
|
||||||
Transition *trans = c->state->transition(ti);
|
Transition *trans = c->state->transition(ti);
|
||||||
ATNState *target = getReachableTarget(trans, t);
|
ATNState *target = getReachableTarget(trans, (int)t);
|
||||||
if (target != nullptr) {
|
if (target != nullptr) {
|
||||||
intermediate->add(new ATNConfig(c, target), mergeCache);
|
intermediate->add(new ATNConfig(c, target), mergeCache);
|
||||||
}
|
}
|
||||||
|
@ -577,8 +579,8 @@ atn::ATNConfigSet *ParserATNSimulator::removeAllConfigsNotInRuleStopState(ATNCon
|
||||||
}
|
}
|
||||||
|
|
||||||
if (lookToEndOfRule && config->state->onlyHasEpsilonTransitions()) {
|
if (lookToEndOfRule && config->state->onlyHasEpsilonTransitions()) {
|
||||||
misc::IntervalSet *nextTokens = atn.nextTokens(config->state);
|
misc::IntervalSet nextTokens = atn.nextTokens(config->state);
|
||||||
if (nextTokens->contains(Token::EPSILON)) {
|
if (nextTokens.contains(Token::EPSILON)) {
|
||||||
ATNState *endOfRuleState = atn.ruleToStopState[config->state->ruleIndex];
|
ATNState *endOfRuleState = atn.ruleToStopState[config->state->ruleIndex];
|
||||||
result->add(new ATNConfig(config, endOfRuleState), mergeCache);
|
result->add(new ATNConfig(config, endOfRuleState), mergeCache);
|
||||||
}
|
}
|
||||||
|
@ -593,9 +595,9 @@ atn::ATNConfigSet *ParserATNSimulator::computeStartState(ATNState *p, RuleContex
|
||||||
PredictionContext *initialContext = PredictionContext::fromRuleContext(atn, ctx);
|
PredictionContext *initialContext = PredictionContext::fromRuleContext(atn, ctx);
|
||||||
ATNConfigSet *configs = new ATNConfigSet(fullCtx);
|
ATNConfigSet *configs = new ATNConfigSet(fullCtx);
|
||||||
|
|
||||||
for (int i = 0; i < p->getNumberOfTransitions(); i++) {
|
for (size_t i = 0; i < p->getNumberOfTransitions(); i++) {
|
||||||
ATNState *target = p->transition(i)->target;
|
ATNState *target = p->transition(i)->target;
|
||||||
ATNConfig *c = new ATNConfig(target, i + 1, initialContext);
|
ATNConfig *c = new ATNConfig(target, (int)i + 1, initialContext);
|
||||||
std::set<ATNConfig*> *closureBusy = new std::set<ATNConfig*>();
|
std::set<ATNConfig*> *closureBusy = new std::set<ATNConfig*>();
|
||||||
closure(c, configs, closureBusy, true, fullCtx);
|
closure(c, configs, closureBusy, true, fullCtx);
|
||||||
}
|
}
|
||||||
|
@ -613,7 +615,7 @@ atn::ATNState *ParserATNSimulator::getReachableTarget(Transition *trans, int tty
|
||||||
|
|
||||||
//
|
//
|
||||||
// Note that caller must memory manage the returned value from this function
|
// Note that caller must memory manage the returned value from this function
|
||||||
std::vector<SemanticContext*> ParserATNSimulator::getPredsForAmbigAlts(antlrcpp::BitSet *ambigAlts, ATNConfigSet *configs, int nalts) {
|
std::vector<SemanticContext*> ParserATNSimulator::getPredsForAmbigAlts(BitSet *ambigAlts, ATNConfigSet *configs, size_t nalts) {
|
||||||
// REACH=[1|1|[]|0:0, 1|2|[]|0:1]
|
// REACH=[1|1|[]|0:0, 1|2|[]|0:1]
|
||||||
/* altToPred starts as an array of all null contexts. The entry at index i
|
/* altToPred starts as an array of all null contexts. The entry at index i
|
||||||
* corresponds to alternative i. altToPred[i] may have one of three values:
|
* corresponds to alternative i. altToPred[i] may have one of three values:
|
||||||
|
@ -630,13 +632,13 @@ std::vector<SemanticContext*> ParserATNSimulator::getPredsForAmbigAlts(antlrcpp:
|
||||||
std::vector<SemanticContext*> altToPred;// = new SemanticContext[nalts + 1];
|
std::vector<SemanticContext*> altToPred;// = new SemanticContext[nalts + 1];
|
||||||
|
|
||||||
for (auto c : *configs->configLookup) {
|
for (auto c : *configs->configLookup) {
|
||||||
if (ambigAlts->data.test(c->alt)) {
|
if (ambigAlts->data.test((size_t)c->alt)) {
|
||||||
altToPred[c->alt] = dynamic_cast<SemanticContext*>( (new SemanticContext::OR(altToPred[c->alt], c->semanticContext)));
|
altToPred[(size_t)c->alt] = dynamic_cast<SemanticContext*>( (new SemanticContext::OR(altToPred[(size_t)c->alt], c->semanticContext)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int nPredAlts = 0;
|
size_t nPredAlts = 0;
|
||||||
for (int i = 1; i <= nalts; i++) {
|
for (size_t i = 1; i <= nalts; i++) {
|
||||||
if (altToPred[i] == nullptr) {
|
if (altToPred[i] == nullptr) {
|
||||||
altToPred[i] = SemanticContext::NONE;
|
altToPred[i] = SemanticContext::NONE;
|
||||||
} else if (altToPred[i] != SemanticContext::NONE) {
|
} else if (altToPred[i] != SemanticContext::NONE) {
|
||||||
|
@ -659,10 +661,10 @@ std::vector<SemanticContext*> ParserATNSimulator::getPredsForAmbigAlts(antlrcpp:
|
||||||
return altToPred;
|
return altToPred;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<dfa::DFAState::PredPrediction *> ParserATNSimulator::getPredicatePredictions(antlrcpp::BitSet *ambigAlts, std::vector<SemanticContext*> altToPred) {
|
std::vector<dfa::DFAState::PredPrediction *> ParserATNSimulator::getPredicatePredictions(BitSet *ambigAlts, std::vector<SemanticContext*> altToPred) {
|
||||||
std::vector<dfa::DFAState::PredPrediction*> pairs = std::vector<dfa::DFAState::PredPrediction*>();
|
std::vector<dfa::DFAState::PredPrediction*> pairs = std::vector<dfa::DFAState::PredPrediction*>();
|
||||||
bool containsPredicate = false;
|
bool containsPredicate = false;
|
||||||
for (int i = 1; i < (int)altToPred.size(); i++) {
|
for (size_t i = 1; i < altToPred.size(); i++) {
|
||||||
SemanticContext *pred = altToPred[i];
|
SemanticContext *pred = altToPred[i];
|
||||||
|
|
||||||
// unpredicted is indicated by SemanticContext.NONE
|
// unpredicted is indicated by SemanticContext.NONE
|
||||||
|
@ -673,7 +675,7 @@ std::vector<dfa::DFAState::PredPrediction *> ParserATNSimulator::getPredicatePre
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ambigAlts != nullptr && ambigAlts->data.test(i)) {
|
if (ambigAlts != nullptr && ambigAlts->data.test(i)) {
|
||||||
pairs.push_back(new dfa::DFAState::PredPrediction(pred, i));
|
pairs.push_back(new dfa::DFAState::PredPrediction(pred, (int)i));
|
||||||
}
|
}
|
||||||
if (pred != SemanticContext::NONE) {
|
if (pred != SemanticContext::NONE) {
|
||||||
containsPredicate = true;
|
containsPredicate = true;
|
||||||
|
@ -700,11 +702,11 @@ int ParserATNSimulator::getAltThatFinishedDecisionEntryRule(ATNConfigSet *config
|
||||||
return alts->getMinElement();
|
return alts->getMinElement();
|
||||||
}
|
}
|
||||||
|
|
||||||
antlrcpp::BitSet *ParserATNSimulator::evalSemanticContext(std::vector<dfa::DFAState::PredPrediction*> predPredictions, ParserRuleContext *outerContext, bool complete) {
|
BitSet *ParserATNSimulator::evalSemanticContext(std::vector<dfa::DFAState::PredPrediction*> predPredictions, ParserRuleContext *outerContext, bool complete) {
|
||||||
antlrcpp::BitSet *predictions = new antlrcpp::BitSet();
|
BitSet *predictions = new BitSet();
|
||||||
for (auto pair : predPredictions) {
|
for (auto pair : predPredictions) {
|
||||||
if (pair->pred == SemanticContext::NONE) {
|
if (pair->pred == SemanticContext::NONE) {
|
||||||
predictions->set(pair->alt);
|
predictions->set((size_t)pair->alt);
|
||||||
if (!complete) {
|
if (!complete) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -720,7 +722,7 @@ antlrcpp::BitSet *ParserATNSimulator::evalSemanticContext(std::vector<dfa::DFASt
|
||||||
if (debug || dfa_debug) {
|
if (debug || dfa_debug) {
|
||||||
std::wcout << L"PREDICT " << pair->alt << std::endl;
|
std::wcout << L"PREDICT " << pair->alt << std::endl;
|
||||||
}
|
}
|
||||||
predictions->set(pair->alt);
|
predictions->set((size_t)pair->alt);
|
||||||
if (!complete) {
|
if (!complete) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -749,7 +751,7 @@ void ParserATNSimulator::closureCheckingStopState(ATNConfig *config, ATNConfigSe
|
||||||
// We hit rule end. If we have context info, use it
|
// We hit rule end. If we have context info, use it
|
||||||
// run thru all possible stack tops in ctx
|
// run thru all possible stack tops in ctx
|
||||||
if (!config->context->isEmpty()) {
|
if (!config->context->isEmpty()) {
|
||||||
for (int i = 0; i < config->context->size(); i++) {
|
for (size_t i = 0; i < config->context->size(); i++) {
|
||||||
if (config->context->getReturnState(i) == PredictionContext::EMPTY_RETURN_STATE) {
|
if (config->context->getReturnState(i) == PredictionContext::EMPTY_RETURN_STATE) {
|
||||||
if (fullCtx) {
|
if (fullCtx) {
|
||||||
configs->add(new ATNConfig(config, config->state, dynamic_cast<PredictionContext*>(PredictionContext::EMPTY)), mergeCache);
|
configs->add(new ATNConfig(config, config->state, dynamic_cast<PredictionContext*>(PredictionContext::EMPTY)), mergeCache);
|
||||||
|
@ -757,13 +759,13 @@ void ParserATNSimulator::closureCheckingStopState(ATNConfig *config, ATNConfigSe
|
||||||
} else {
|
} else {
|
||||||
// we have no context info, just chase follow links (if greedy)
|
// we have no context info, just chase follow links (if greedy)
|
||||||
if (debug) {
|
if (debug) {
|
||||||
std::wcout << L"FALLING off rule " << getRuleName(config->state->ruleIndex) << std::endl;
|
std::wcout << L"FALLING off rule " << getRuleName((size_t)config->state->ruleIndex) << std::endl;
|
||||||
}
|
}
|
||||||
closure_(config, configs, closureBusy, collectPredicates, fullCtx, depth);
|
closure_(config, configs, closureBusy, collectPredicates, fullCtx, depth);
|
||||||
}
|
}
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
ATNState *returnState = atn.states[config->context->getReturnState(i)];
|
ATNState *returnState = atn.states[(size_t)config->context->getReturnState(i)];
|
||||||
PredictionContext *newContext = config->context->getParent(i); // "pop" return state
|
PredictionContext *newContext = config->context->getParent(i); // "pop" return state
|
||||||
ATNConfig *c = new ATNConfig(returnState, config->alt, newContext, config->semanticContext);
|
ATNConfig *c = new ATNConfig(returnState, config->alt, newContext, config->semanticContext);
|
||||||
// While we have context to pop back from, we may have
|
// While we have context to pop back from, we may have
|
||||||
|
@ -785,7 +787,7 @@ void ParserATNSimulator::closureCheckingStopState(ATNConfig *config, ATNConfigSe
|
||||||
} else {
|
} else {
|
||||||
// else if we have no context info, just chase follow links (if greedy)
|
// else if we have no context info, just chase follow links (if greedy)
|
||||||
if (debug) {
|
if (debug) {
|
||||||
std::wcout << L"FALLING off rule " << getRuleName(config->state->ruleIndex) << std::endl;
|
std::wcout << L"FALLING off rule " << getRuleName((size_t)config->state->ruleIndex) << std::endl;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -801,7 +803,7 @@ void ParserATNSimulator::closure_(ATNConfig *config, ATNConfigSet *configs, std:
|
||||||
// if ( debug ) System.out.println("added config "+configs);
|
// if ( debug ) System.out.println("added config "+configs);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int i = 0; i < p->getNumberOfTransitions(); i++) {
|
for (size_t i = 0; i < p->getNumberOfTransitions(); i++) {
|
||||||
Transition *t = p->transition(i);
|
Transition *t = p->transition(i);
|
||||||
bool continueCollecting = !(dynamic_cast<ActionTransition*>(t) != nullptr) && collectPredicates;
|
bool continueCollecting = !(dynamic_cast<ActionTransition*>(t) != nullptr) && collectPredicates;
|
||||||
ATNConfig *c = getEpsilonTarget(config, t, continueCollecting, depth == 0, fullCtx);
|
ATNConfig *c = getEpsilonTarget(config, t, continueCollecting, depth == 0, fullCtx);
|
||||||
|
@ -847,8 +849,8 @@ void ParserATNSimulator::closure_(ATNConfig *config, ATNConfigSet *configs, std:
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
std::wstring ParserATNSimulator::getRuleName(int index) {
|
std::wstring ParserATNSimulator::getRuleName(size_t index) {
|
||||||
if (parser != nullptr && index >= 0) {
|
if (parser != nullptr) {
|
||||||
return parser->getRuleNames()[index];
|
return parser->getRuleNames()[index];
|
||||||
}
|
}
|
||||||
return L"<rule " + std::to_wstring(index) + L">";
|
return L"<rule " + std::to_wstring(index) + L">";
|
||||||
|
@ -883,11 +885,12 @@ atn::ATNConfig *ParserATNSimulator::actionTransition(ATNConfig *config, ActionTr
|
||||||
return new ATNConfig(config, t->target);
|
return new ATNConfig(config, t->target);
|
||||||
}
|
}
|
||||||
|
|
||||||
atn::ATNConfig *ParserATNSimulator::precedenceTransition(ATNConfig *config, PrecedencePredicateTransition *pt, bool collectPredicates, bool inContext, bool fullCtx) {
|
atn::ATNConfig *ParserATNSimulator::precedenceTransition(ATNConfig *config, PrecedencePredicateTransition *pt,
|
||||||
|
bool collectPredicates, bool inContext, bool fullCtx) {
|
||||||
if (debug) {
|
if (debug) {
|
||||||
std::wcout << L"PRED (collectPredicates=" << collectPredicates << L") " << pt->precedence << L">=_p" << L", ctx dependent=true" << std::endl;
|
std::wcout << L"PRED (collectPredicates=" << collectPredicates << L") " << pt->precedence << L">=_p" << L", ctx dependent=true" << std::endl;
|
||||||
if (parser != nullptr) {
|
if (parser != nullptr) {
|
||||||
std::wcout << L"context surrounding pred is " << antlrcpp::Arrays::ListToString( parser->getRuleInvocationStack(), L", ") << std::endl;
|
std::wcout << L"context surrounding pred is " << Arrays::listToString( parser->getRuleInvocationStack(), L", ") << std::endl;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -898,8 +901,8 @@ atn::ATNConfig *ParserATNSimulator::precedenceTransition(ATNConfig *config, Prec
|
||||||
// during closure, which dramatically reduces the size of
|
// during closure, which dramatically reduces the size of
|
||||||
// the config sets. It also obviates the need to test predicates
|
// the config sets. It also obviates the need to test predicates
|
||||||
// later during conflict resolution.
|
// later during conflict resolution.
|
||||||
int currentPosition = _input->index();
|
size_t currentPosition = _input->index();
|
||||||
_input->seek(_startIndex);
|
_input->seek((size_t)_startIndex);
|
||||||
bool predSucceeds = pt->getPredicate()->eval(parser, _outerContext);
|
bool predSucceeds = pt->getPredicate()->eval(parser, _outerContext);
|
||||||
_input->seek(currentPosition);
|
_input->seek(currentPosition);
|
||||||
if (predSucceeds) {
|
if (predSucceeds) {
|
||||||
|
@ -923,7 +926,7 @@ atn::ATNConfig *ParserATNSimulator::predTransition(ATNConfig *config, PredicateT
|
||||||
if (debug) {
|
if (debug) {
|
||||||
std::wcout << L"PRED (collectPredicates=" << collectPredicates << L") " << pt->ruleIndex << L":" << pt->predIndex << L", ctx dependent=" << pt->isCtxDependent << std::endl;
|
std::wcout << L"PRED (collectPredicates=" << collectPredicates << L") " << pt->ruleIndex << L":" << pt->predIndex << L", ctx dependent=" << pt->isCtxDependent << std::endl;
|
||||||
if (parser != nullptr) {
|
if (parser != nullptr) {
|
||||||
std::wcout << L"context surrounding pred is " << antlrcpp::Arrays::ListToString(parser->getRuleInvocationStack(), L", ") << std::endl;
|
std::wcout << L"context surrounding pred is " << Arrays::listToString(parser->getRuleInvocationStack(), L", ") << std::endl;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -934,8 +937,8 @@ atn::ATNConfig *ParserATNSimulator::predTransition(ATNConfig *config, PredicateT
|
||||||
// during closure, which dramatically reduces the size of
|
// during closure, which dramatically reduces the size of
|
||||||
// the config sets. It also obviates the need to test predicates
|
// the config sets. It also obviates the need to test predicates
|
||||||
// later during conflict resolution.
|
// later during conflict resolution.
|
||||||
int currentPosition = _input->index();
|
size_t currentPosition = _input->index();
|
||||||
_input->seek(_startIndex);
|
_input->seek((size_t)_startIndex);
|
||||||
bool predSucceeds = pt->getPredicate()->eval(parser, _outerContext);
|
bool predSucceeds = pt->getPredicate()->eval(parser, _outerContext);
|
||||||
_input->seek(currentPosition);
|
_input->seek(currentPosition);
|
||||||
if (predSucceeds) {
|
if (predSucceeds) {
|
||||||
|
@ -957,7 +960,7 @@ atn::ATNConfig *ParserATNSimulator::predTransition(ATNConfig *config, PredicateT
|
||||||
|
|
||||||
atn::ATNConfig *ParserATNSimulator::ruleTransition(ATNConfig *config, RuleTransition *t) {
|
atn::ATNConfig *ParserATNSimulator::ruleTransition(ATNConfig *config, RuleTransition *t) {
|
||||||
if (debug) {
|
if (debug) {
|
||||||
std::wcout << L"CALL rule " << getRuleName(t->target->ruleIndex) << L", ctx=" << config->context << std::endl;
|
std::wcout << L"CALL rule " << getRuleName((size_t)t->target->ruleIndex) << L", ctx=" << config->context << std::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
atn::ATNState *returnState = t->followState;
|
atn::ATNState *returnState = t->followState;
|
||||||
|
@ -965,36 +968,36 @@ atn::ATNConfig *ParserATNSimulator::ruleTransition(ATNConfig *config, RuleTransi
|
||||||
return new atn::ATNConfig(config, t->target, newContext);
|
return new atn::ATNConfig(config, t->target, newContext);
|
||||||
}
|
}
|
||||||
|
|
||||||
antlrcpp::BitSet ParserATNSimulator::getConflictingAlts(ATNConfigSet *configs) {
|
BitSet ParserATNSimulator::getConflictingAlts(ATNConfigSet *configs) {
|
||||||
std::vector<antlrcpp::BitSet> altsets = PredictionModeClass::getConflictingAltSubsets(configs);
|
std::vector<BitSet> altsets = PredictionModeClass::getConflictingAltSubsets(configs);
|
||||||
return PredictionModeClass::getAlts(altsets);
|
return PredictionModeClass::getAlts(altsets);
|
||||||
}
|
}
|
||||||
|
|
||||||
antlrcpp::BitSet ParserATNSimulator::getConflictingAltsOrUniqueAlt(ATNConfigSet *configs) {
|
BitSet ParserATNSimulator::getConflictingAltsOrUniqueAlt(ATNConfigSet *configs) {
|
||||||
antlrcpp::BitSet conflictingAlts;
|
BitSet conflictingAlts;
|
||||||
if (configs->uniqueAlt != ATN::INVALID_ALT_NUMBER) {
|
if (configs->uniqueAlt != ATN::INVALID_ALT_NUMBER) {
|
||||||
conflictingAlts.set(configs->uniqueAlt);
|
conflictingAlts.set((size_t)configs->uniqueAlt);
|
||||||
} else {
|
} else {
|
||||||
conflictingAlts = *configs->conflictingAlts;
|
conflictingAlts = *configs->conflictingAlts;
|
||||||
}
|
}
|
||||||
return conflictingAlts;
|
return conflictingAlts;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::wstring ParserATNSimulator::getTokenName(int t) {
|
std::wstring ParserATNSimulator::getTokenName(size_t t) {
|
||||||
if (t == Token::_EOF) {
|
if (t == Token::_EOF) {
|
||||||
return L"EOF";
|
return L"EOF";
|
||||||
}
|
}
|
||||||
if (parser != nullptr) {
|
if (parser != nullptr) {
|
||||||
std::vector<std::wstring> tokensNames = parser->getTokenNames();
|
std::vector<std::wstring> tokensNames = parser->getTokenNames();
|
||||||
if (t >= (int)tokensNames.size()) {
|
if (t >= tokensNames.size()) {
|
||||||
std::wcerr << t << L" type out of range: " << antlrcpp::Arrays::ListToString(tokensNames, L", ");
|
std::wcerr << t << L" type out of range: " << Arrays::listToString(tokensNames, L", ");
|
||||||
// TODO
|
// TODO
|
||||||
// std::wcerr << ((CommonTokenStream*)parser->getInputStream())->getTokens();
|
// std::wcerr << ((CommonTokenStream*)parser->getInputStream())->getTokens();
|
||||||
} else {
|
} else {
|
||||||
return tokensNames[t] + L"<" + std::to_wstring(t) + L">";
|
return tokensNames[t] + L"<" + std::to_wstring(t) + L">";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return antlrcpp::StringConverterHelper::toString(t);
|
return StringConverterHelper::toString(t);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::wstring ParserATNSimulator::getLookaheadName(TokenStream *input) {
|
std::wstring ParserATNSimulator::getLookaheadName(TokenStream *input) {
|
||||||
|
@ -1009,20 +1012,21 @@ void ParserATNSimulator::dumpDeadEndConfigs(NoViableAltException *nvae) {
|
||||||
Transition *t = c->state->transition(0);
|
Transition *t = c->state->transition(0);
|
||||||
if (dynamic_cast<AtomTransition*>(t) != nullptr) {
|
if (dynamic_cast<AtomTransition*>(t) != nullptr) {
|
||||||
AtomTransition *at = static_cast<AtomTransition*>(t);
|
AtomTransition *at = static_cast<AtomTransition*>(t);
|
||||||
trans = L"Atom " + getTokenName(at->_label);
|
trans = L"Atom " + getTokenName((size_t)at->_label);
|
||||||
} else if (dynamic_cast<SetTransition*>(t) != nullptr) {
|
} else if (dynamic_cast<SetTransition*>(t) != nullptr) {
|
||||||
SetTransition *st = static_cast<SetTransition*>(t);
|
SetTransition *st = static_cast<SetTransition*>(t);
|
||||||
bool is_not = dynamic_cast<NotSetTransition*>(st) != nullptr;
|
bool is_not = dynamic_cast<NotSetTransition*>(st) != nullptr;
|
||||||
trans = (is_not ? L"~" : L"");
|
trans = (is_not ? L"~" : L"");
|
||||||
trans += L"Set ";
|
trans += L"Set ";
|
||||||
trans += st->set->toString();
|
trans += st->set.toString();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
std::wcerr << c->toString(parser, true) + L":" + trans;
|
std::wcerr << c->toString(parser, true) + L":" + trans;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
NoViableAltException *ParserATNSimulator::noViableAlt(TokenStream *input, ParserRuleContext *outerContext, ATNConfigSet *configs, int startIndex) {
|
NoViableAltException *ParserATNSimulator::noViableAlt(TokenStream *input, ParserRuleContext *outerContext,
|
||||||
|
ATNConfigSet *configs, size_t startIndex) {
|
||||||
return new NoViableAltException(parser, input, input->get(startIndex), input->LT(1), configs, outerContext);
|
return new NoViableAltException(parser, input, input->get(startIndex), input->LT(1), configs, outerContext);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1038,7 +1042,7 @@ int ParserATNSimulator::getUniqueAlt(ATNConfigSet *configs) {
|
||||||
return alt;
|
return alt;
|
||||||
}
|
}
|
||||||
|
|
||||||
dfa::DFAState *ParserATNSimulator::addDFAEdge(dfa::DFA *dfa, dfa::DFAState *from, int t, dfa::DFAState *to) {
|
dfa::DFAState *ParserATNSimulator::addDFAEdge(dfa::DFA *dfa, dfa::DFAState *from, size_t t, dfa::DFAState *to) {
|
||||||
if (debug) {
|
if (debug) {
|
||||||
std::wcout << L"EDGE " << from << L" -> " << to << L" upon " << getTokenName(t) << std::endl;
|
std::wcout << L"EDGE " << from << L" -> " << to << L" upon " << getTokenName(t) << std::endl;
|
||||||
}
|
}
|
||||||
|
@ -1048,7 +1052,7 @@ dfa::DFAState *ParserATNSimulator::addDFAEdge(dfa::DFA *dfa, dfa::DFAState *from
|
||||||
}
|
}
|
||||||
|
|
||||||
to = addDFAState(dfa, to); // used existing if possible not incoming
|
to = addDFAState(dfa, to); // used existing if possible not incoming
|
||||||
if (from == nullptr || t < -1 || t > atn.maxTokenType) {
|
if (from == nullptr || t > (size_t)atn.maxTokenType) {
|
||||||
return to;
|
return to;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1098,9 +1102,10 @@ dfa::DFAState *ParserATNSimulator::addDFAState(dfa::DFA *dfa, dfa::DFAState *D)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void ParserATNSimulator::reportAttemptingFullContext(dfa::DFA *dfa, antlrcpp::BitSet *conflictingAlts, ATNConfigSet *configs, int startIndex, int stopIndex) {
|
void ParserATNSimulator::reportAttemptingFullContext(dfa::DFA *dfa, BitSet *conflictingAlts, ATNConfigSet *configs,
|
||||||
|
size_t startIndex, size_t stopIndex) {
|
||||||
if (debug || retry_debug) {
|
if (debug || retry_debug) {
|
||||||
misc::Interval *interval = misc::Interval::of(startIndex, stopIndex);
|
misc::Interval interval = misc::Interval::of((int)startIndex, (int)stopIndex);
|
||||||
std::wcout << L"reportAttemptingFullContext decision=" << dfa->decision << L":" << configs << L", input=" << parser->getTokenStream()->getText(interval) << std::endl;
|
std::wcout << L"reportAttemptingFullContext decision=" << dfa->decision << L":" << configs << L", input=" << parser->getTokenStream()->getText(interval) << std::endl;
|
||||||
}
|
}
|
||||||
if (parser != nullptr) {
|
if (parser != nullptr) {
|
||||||
|
@ -1108,9 +1113,10 @@ void ParserATNSimulator::reportAttemptingFullContext(dfa::DFA *dfa, antlrcpp::Bi
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void ParserATNSimulator::reportContextSensitivity(dfa::DFA *dfa, int prediction, ATNConfigSet *configs, int startIndex, int stopIndex) {
|
void ParserATNSimulator::reportContextSensitivity(dfa::DFA *dfa, int prediction, ATNConfigSet *configs, size_t startIndex,
|
||||||
|
size_t stopIndex) {
|
||||||
if (debug || retry_debug) {
|
if (debug || retry_debug) {
|
||||||
misc::Interval *interval = misc::Interval::of(startIndex, stopIndex);
|
misc::Interval interval = misc::Interval::of((int)startIndex, (int)stopIndex);
|
||||||
std::wcout << L"reportContextSensitivity decision=" << dfa->decision << L":" << configs << L", input=" << parser->getTokenStream()->getText(interval) << std::endl;
|
std::wcout << L"reportContextSensitivity decision=" << dfa->decision << L":" << configs << L", input=" << parser->getTokenStream()->getText(interval) << std::endl;
|
||||||
}
|
}
|
||||||
if (parser != nullptr) {
|
if (parser != nullptr) {
|
||||||
|
@ -1118,7 +1124,8 @@ void ParserATNSimulator::reportContextSensitivity(dfa::DFA *dfa, int prediction,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void ParserATNSimulator::reportAmbiguity(dfa::DFA *dfa, dfa::DFAState *D, int startIndex, int stopIndex, bool exact, antlrcpp::BitSet *ambigAlts, ATNConfigSet *configs) {
|
void ParserATNSimulator::reportAmbiguity(dfa::DFA *dfa, dfa::DFAState *D, size_t startIndex, size_t stopIndex,
|
||||||
|
bool exact, BitSet *ambigAlts, ATNConfigSet *configs) {
|
||||||
if (debug || retry_debug) {
|
if (debug || retry_debug) {
|
||||||
// ParserATNPathFinder finder = new ParserATNPathFinder(parser, atn);
|
// ParserATNPathFinder finder = new ParserATNPathFinder(parser, atn);
|
||||||
// int i = 1;
|
// int i = 1;
|
||||||
|
@ -1136,7 +1143,7 @@ void ParserATNSimulator::reportAmbiguity(dfa::DFA *dfa, dfa::DFAState *D, int st
|
||||||
// }
|
// }
|
||||||
// i++;
|
// i++;
|
||||||
// }
|
// }
|
||||||
misc::Interval *interval = misc::Interval::of(startIndex, stopIndex);
|
misc::Interval interval = misc::Interval::of(startIndex, stopIndex);
|
||||||
std::wcout << L"reportAmbiguity " << ambigAlts << L":" << configs << L", input=" << parser->getTokenStream()->getText(interval) << std::endl;
|
std::wcout << L"reportAmbiguity " << ambigAlts << L":" << configs << L", input=" << parser->getTokenStream()->getText(interval) << std::endl;
|
||||||
}
|
}
|
||||||
if (parser != nullptr) {
|
if (parser != nullptr) {
|
||||||
|
|
|
@ -318,7 +318,7 @@ namespace atn {
|
||||||
/// conflict + preds
|
/// conflict + preds
|
||||||
/// </summary>
|
/// </summary>
|
||||||
protected:
|
protected:
|
||||||
virtual int execATN(dfa::DFA *dfa, dfa::DFAState *s0, TokenStream *input, int startIndex, ParserRuleContext *outerContext);
|
virtual int execATN(dfa::DFA *dfa, dfa::DFAState *s0, TokenStream *input, size_t startIndex, ParserRuleContext *outerContext);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Get an existing target state for an edge in the DFA. If the target state
|
/// Get an existing target state for an edge in the DFA. If the target state
|
||||||
|
@ -330,7 +330,7 @@ namespace atn {
|
||||||
/// <returns> The existing target DFA state for the given input symbol
|
/// <returns> The existing target DFA state for the given input symbol
|
||||||
/// {@code t}, or {@code null} if the target state for this edge is not
|
/// {@code t}, or {@code null} if the target state for this edge is not
|
||||||
/// already cached </returns>
|
/// already cached </returns>
|
||||||
virtual dfa::DFAState *getExistingTargetState(dfa::DFAState *previousD, int t);
|
virtual dfa::DFAState *getExistingTargetState(dfa::DFAState *previousD, size_t t);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Compute a target state for an edge in the DFA, and attempt to add the
|
/// Compute a target state for an edge in the DFA, and attempt to add the
|
||||||
|
@ -343,14 +343,14 @@ namespace atn {
|
||||||
/// <returns> The computed target DFA state for the given input symbol
|
/// <returns> The computed target DFA state for the given input symbol
|
||||||
/// {@code t}. If {@code t} does not lead to a valid DFA state, this method
|
/// {@code t}. If {@code t} does not lead to a valid DFA state, this method
|
||||||
/// returns <seealso cref="#ERROR"/>. </returns>
|
/// returns <seealso cref="#ERROR"/>. </returns>
|
||||||
virtual dfa::DFAState *computeTargetState(dfa::DFA *dfa, dfa::DFAState *previousD, int t);
|
virtual dfa::DFAState *computeTargetState(dfa::DFA *dfa, dfa::DFAState *previousD, size_t t);
|
||||||
|
|
||||||
virtual void predicateDFAState(dfa::DFAState *dfaState, DecisionState *decisionState);
|
virtual void predicateDFAState(dfa::DFAState *dfaState, DecisionState *decisionState);
|
||||||
|
|
||||||
// comes back with reach.uniqueAlt set to a valid alt
|
// comes back with reach.uniqueAlt set to a valid alt
|
||||||
virtual int execATNWithFullContext(dfa::DFA *dfa, dfa::DFAState *D, ATNConfigSet *s0, TokenStream *input, int startIndex, ParserRuleContext *outerContext); // how far we got before failing over
|
virtual int execATNWithFullContext(dfa::DFA *dfa, dfa::DFAState *D, ATNConfigSet *s0, TokenStream *input, size_t startIndex, ParserRuleContext *outerContext); // how far we got before failing over
|
||||||
|
|
||||||
virtual ATNConfigSet *computeReachSet(ATNConfigSet *closure, int t, bool fullCtx);
|
virtual ATNConfigSet *computeReachSet(ATNConfigSet *closure, size_t t, bool fullCtx);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Return a configuration set containing only the configurations from
|
/// Return a configuration set containing only the configurations from
|
||||||
|
@ -377,7 +377,7 @@ namespace atn {
|
||||||
|
|
||||||
virtual ATNState *getReachableTarget(Transition *trans, int ttype);
|
virtual ATNState *getReachableTarget(Transition *trans, int ttype);
|
||||||
|
|
||||||
virtual std::vector<SemanticContext*> getPredsForAmbigAlts(antlrcpp::BitSet *ambigAlts, ATNConfigSet *configs, int nalts);
|
virtual std::vector<SemanticContext*> getPredsForAmbigAlts(antlrcpp::BitSet *ambigAlts, ATNConfigSet *configs, size_t nalts);
|
||||||
|
|
||||||
virtual std::vector<dfa::DFAState::PredPrediction*> getPredicatePredictions(antlrcpp::BitSet *ambigAlts, std::vector<SemanticContext*> altToPred);
|
virtual std::vector<dfa::DFAState::PredPrediction*> getPredicatePredictions(antlrcpp::BitSet *ambigAlts, std::vector<SemanticContext*> altToPred);
|
||||||
|
|
||||||
|
@ -409,7 +409,7 @@ namespace atn {
|
||||||
virtual void closure_(ATNConfig *config, ATNConfigSet *configs, std::set<ATNConfig*> *closureBusy, bool collectPredicates, bool fullCtx, int depth);
|
virtual void closure_(ATNConfig *config, ATNConfigSet *configs, std::set<ATNConfig*> *closureBusy, bool collectPredicates, bool fullCtx, int depth);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
virtual std::wstring getRuleName(int index);
|
virtual std::wstring getRuleName(size_t index);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual ATNConfig *getEpsilonTarget(ATNConfig *config, Transition *t, bool collectPredicates, bool inContext, bool fullCtx);
|
virtual ATNConfig *getEpsilonTarget(ATNConfig *config, Transition *t, bool collectPredicates, bool inContext, bool fullCtx);
|
||||||
|
@ -466,7 +466,7 @@ namespace atn {
|
||||||
virtual antlrcpp::BitSet getConflictingAltsOrUniqueAlt(ATNConfigSet *configs);
|
virtual antlrcpp::BitSet getConflictingAltsOrUniqueAlt(ATNConfigSet *configs);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
virtual std::wstring getTokenName(int t);
|
virtual std::wstring getTokenName(size_t t);
|
||||||
|
|
||||||
virtual std::wstring getLookaheadName(TokenStream *input);
|
virtual std::wstring getLookaheadName(TokenStream *input);
|
||||||
|
|
||||||
|
@ -478,7 +478,7 @@ namespace atn {
|
||||||
virtual void dumpDeadEndConfigs(NoViableAltException *nvae);
|
virtual void dumpDeadEndConfigs(NoViableAltException *nvae);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual NoViableAltException *noViableAlt(TokenStream *input, ParserRuleContext *outerContext, ATNConfigSet *configs, int startIndex);
|
virtual NoViableAltException *noViableAlt(TokenStream *input, ParserRuleContext *outerContext, ATNConfigSet *configs, size_t startIndex);
|
||||||
|
|
||||||
static int getUniqueAlt(ATNConfigSet *configs);
|
static int getUniqueAlt(ATNConfigSet *configs);
|
||||||
|
|
||||||
|
@ -501,7 +501,7 @@ namespace atn {
|
||||||
/// <returns> If {@code to} is {@code null}, this method returns {@code null};
|
/// <returns> If {@code to} is {@code null}, this method returns {@code null};
|
||||||
/// otherwise this method returns the result of calling <seealso cref="#addDFAState"/>
|
/// otherwise this method returns the result of calling <seealso cref="#addDFAState"/>
|
||||||
/// on {@code to} </returns>
|
/// on {@code to} </returns>
|
||||||
virtual dfa::DFAState *addDFAEdge(dfa::DFA *dfa, dfa::DFAState *from, int t, dfa::DFAState *to);
|
virtual dfa::DFAState *addDFAEdge(dfa::DFA *dfa, dfa::DFAState *from, size_t t, dfa::DFAState *to);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Add state {@code D} to the DFA if it is not already present, and return
|
/// Add state {@code D} to the DFA if it is not already present, and return
|
||||||
|
@ -519,13 +519,14 @@ namespace atn {
|
||||||
/// state was not already present. </returns>
|
/// state was not already present. </returns>
|
||||||
virtual dfa::DFAState *addDFAState(dfa::DFA *dfa, dfa::DFAState *D);
|
virtual dfa::DFAState *addDFAState(dfa::DFA *dfa, dfa::DFAState *D);
|
||||||
|
|
||||||
virtual void reportAttemptingFullContext(dfa::DFA *dfa, antlrcpp::BitSet *conflictingAlts, ATNConfigSet *configs, int startIndex, int stopIndex);
|
virtual void reportAttemptingFullContext(dfa::DFA *dfa, antlrcpp::BitSet *conflictingAlts, ATNConfigSet *configs,
|
||||||
|
size_t startIndex, size_t stopIndex);
|
||||||
|
|
||||||
virtual void reportContextSensitivity(dfa::DFA *dfa, int prediction, ATNConfigSet *configs, int startIndex, int stopIndex);
|
virtual void reportContextSensitivity(dfa::DFA *dfa, int prediction, ATNConfigSet *configs, size_t startIndex, size_t stopIndex);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// If context sensitive parsing, we know it's ambiguity not conflict </summary>
|
/// If context sensitive parsing, we know it's ambiguity not conflict </summary>
|
||||||
virtual void reportAmbiguity(dfa::DFA *dfa, dfa::DFAState *D, int startIndex, int stopIndex, bool exact, antlrcpp::BitSet *ambigAlts, ATNConfigSet *configs);
|
virtual void reportAmbiguity(dfa::DFA *dfa, dfa::DFAState *D, size_t startIndex, size_t stopIndex, bool exact, antlrcpp::BitSet *ambigAlts, ATNConfigSet *configs);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
void setPredictionMode(PredictionMode mode);
|
void setPredictionMode(PredictionMode mode);
|
||||||
|
|
|
@ -36,22 +36,22 @@ using namespace org::antlr::v4::runtime::atn;
|
||||||
PrecedencePredicateTransition::PrecedencePredicateTransition(ATNState *target, int precedence) : AbstractPredicateTransition(target), precedence(precedence) {
|
PrecedencePredicateTransition::PrecedencePredicateTransition(ATNState *target, int precedence) : AbstractPredicateTransition(target), precedence(precedence) {
|
||||||
}
|
}
|
||||||
|
|
||||||
int PrecedencePredicateTransition::getSerializationType() {
|
int PrecedencePredicateTransition::getSerializationType() const {
|
||||||
return PRECEDENCE;
|
return PRECEDENCE;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool PrecedencePredicateTransition::isEpsilon() {
|
bool PrecedencePredicateTransition::isEpsilon() const {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool PrecedencePredicateTransition::matches(int symbol, int minVocabSymbol, int maxVocabSymbol) {
|
bool PrecedencePredicateTransition::matches(int symbol, int minVocabSymbol, int maxVocabSymbol) const {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
org::antlr::v4::runtime::atn::SemanticContext::PrecedencePredicate *PrecedencePredicateTransition::getPredicate() {
|
org::antlr::v4::runtime::atn::SemanticContext::PrecedencePredicate *PrecedencePredicateTransition::getPredicate() const {
|
||||||
return new SemanticContext::PrecedencePredicate(precedence);
|
return new SemanticContext::PrecedencePredicate(precedence);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::wstring PrecedencePredicateTransition::toString() {
|
std::wstring PrecedencePredicateTransition::toString() const {
|
||||||
return std::to_wstring(precedence) + std::wstring(L" >= _p");
|
return std::to_wstring(precedence) + std::wstring(L" >= _p");
|
||||||
}
|
}
|
||||||
|
|
|
@ -50,15 +50,15 @@ namespace atn {
|
||||||
|
|
||||||
PrecedencePredicateTransition(ATNState *target, int precedence);
|
PrecedencePredicateTransition(ATNState *target, int precedence);
|
||||||
|
|
||||||
virtual int getSerializationType() override;
|
virtual int getSerializationType() const override;
|
||||||
|
|
||||||
virtual bool isEpsilon() override;
|
virtual bool isEpsilon() const override;
|
||||||
|
|
||||||
virtual bool matches(int symbol, int minVocabSymbol, int maxVocabSymbol) override;
|
virtual bool matches(int symbol, int minVocabSymbol, int maxVocabSymbol) const override;
|
||||||
|
|
||||||
SemanticContext::PrecedencePredicate *getPredicate();
|
SemanticContext::PrecedencePredicate *getPredicate() const;
|
||||||
|
|
||||||
virtual std::wstring toString();
|
virtual std::wstring toString() const;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -37,23 +37,23 @@ using namespace org::antlr::v4::runtime::atn;
|
||||||
PredicateTransition::PredicateTransition(ATNState *target, int ruleIndex, int predIndex, bool isCtxDependent) : AbstractPredicateTransition(target), ruleIndex(ruleIndex), predIndex(predIndex), isCtxDependent(isCtxDependent) {
|
PredicateTransition::PredicateTransition(ATNState *target, int ruleIndex, int predIndex, bool isCtxDependent) : AbstractPredicateTransition(target), ruleIndex(ruleIndex), predIndex(predIndex), isCtxDependent(isCtxDependent) {
|
||||||
}
|
}
|
||||||
|
|
||||||
int PredicateTransition::getSerializationType() {
|
int PredicateTransition::getSerializationType() const {
|
||||||
return PREDICATE;
|
return PREDICATE;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool PredicateTransition::isEpsilon() {
|
bool PredicateTransition::isEpsilon() const {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool PredicateTransition::matches(int symbol, int minVocabSymbol, int maxVocabSymbol) {
|
bool PredicateTransition::matches(int symbol, int minVocabSymbol, int maxVocabSymbol) const {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
SemanticContext::Predicate *PredicateTransition::getPredicate() {
|
SemanticContext::Predicate *PredicateTransition::getPredicate() const {
|
||||||
// TODO: who is responsible for managing this memory?
|
// TODO: who is responsible for managing this memory?
|
||||||
return new SemanticContext::Predicate(ruleIndex, predIndex, isCtxDependent);
|
return new SemanticContext::Predicate(ruleIndex, predIndex, isCtxDependent);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::wstring PredicateTransition::toString() {
|
std::wstring PredicateTransition::toString() const {
|
||||||
return std::wstring(L"pred_") + antlrcpp::StringConverterHelper::toString(ruleIndex) + std::wstring(L":") + antlrcpp::StringConverterHelper::toString(predIndex);
|
return std::wstring(L"pred_") + antlrcpp::StringConverterHelper::toString(ruleIndex) + std::wstring(L":") + antlrcpp::StringConverterHelper::toString(predIndex);
|
||||||
}
|
}
|
||||||
|
|
|
@ -55,14 +55,14 @@ namespace atn {
|
||||||
|
|
||||||
PredicateTransition(ATNState *target, int ruleIndex, int predIndex, bool isCtxDependent);
|
PredicateTransition(ATNState *target, int ruleIndex, int predIndex, bool isCtxDependent);
|
||||||
|
|
||||||
virtual int getSerializationType() override;
|
virtual int getSerializationType() const override;
|
||||||
|
|
||||||
virtual bool isEpsilon() override;
|
virtual bool isEpsilon() const override;
|
||||||
virtual bool matches(int symbol, int minVocabSymbol, int maxVocabSymbol) override;
|
virtual bool matches(int symbol, int minVocabSymbol, int maxVocabSymbol) const override;
|
||||||
|
|
||||||
SemanticContext::Predicate *getPredicate();
|
SemanticContext::Predicate *getPredicate() const;
|
||||||
|
|
||||||
virtual std::wstring toString();
|
virtual std::wstring toString() const;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -48,7 +48,7 @@ EmptyPredictionContext * PredictionContext::EMPTY;
|
||||||
const int PredictionContext::EMPTY_RETURN_STATE;
|
const int PredictionContext::EMPTY_RETURN_STATE;
|
||||||
const int PredictionContext::INITIAL_HASH;
|
const int PredictionContext::INITIAL_HASH;
|
||||||
|
|
||||||
PredictionContext::PredictionContext(int cachedHashCode) : id(globalNodeCount++), cachedHashCode(cachedHashCode) {
|
PredictionContext::PredictionContext(size_t cachedHashCode) : id(globalNodeCount++), cachedHashCode(cachedHashCode) {
|
||||||
}
|
}
|
||||||
|
|
||||||
PredictionContext *PredictionContext::fromRuleContext(const ATN &atn, RuleContext *outerContext) {
|
PredictionContext *PredictionContext::fromRuleContext(const ATN &atn, RuleContext *outerContext) {
|
||||||
|
@ -66,50 +66,50 @@ PredictionContext *PredictionContext::fromRuleContext(const ATN &atn, RuleContex
|
||||||
PredictionContext *parent = EMPTY;
|
PredictionContext *parent = EMPTY;
|
||||||
parent = PredictionContext::fromRuleContext(atn, outerContext->parent);
|
parent = PredictionContext::fromRuleContext(atn, outerContext->parent);
|
||||||
|
|
||||||
ATNState *state = atn.states[outerContext->invokingState];
|
ATNState *state = atn.states[(size_t)outerContext->invokingState];
|
||||||
RuleTransition *transition = (RuleTransition *)state->transition(0);//static_cast<RuleTransition*>(state->transition(0));
|
RuleTransition *transition = (RuleTransition *)state->transition(0);//static_cast<RuleTransition*>(state->transition(0));
|
||||||
return SingletonPredictionContext::create(parent, transition->followState->stateNumber);
|
return SingletonPredictionContext::create(parent, transition->followState->stateNumber);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool PredictionContext::isEmpty() {
|
bool PredictionContext::isEmpty() const {
|
||||||
return this == EMPTY;
|
return this == EMPTY;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool PredictionContext::hasEmptyPath() {
|
bool PredictionContext::hasEmptyPath() const {
|
||||||
return getReturnState(size() - 1) == EMPTY_RETURN_STATE;
|
return getReturnState(size() - 1) == EMPTY_RETURN_STATE;
|
||||||
}
|
}
|
||||||
|
|
||||||
int PredictionContext::hashCode() {
|
size_t PredictionContext::hashCode() const {
|
||||||
return cachedHashCode;
|
return cachedHashCode;
|
||||||
}
|
}
|
||||||
|
|
||||||
int PredictionContext::calculateEmptyHashCode() {
|
size_t PredictionContext::calculateEmptyHashCode() {
|
||||||
int hash = MurmurHash::initialize(INITIAL_HASH);
|
size_t hash = MurmurHash::initialize(INITIAL_HASH);
|
||||||
hash = MurmurHash::finish(hash, 0);
|
hash = MurmurHash::finish(hash, 0);
|
||||||
return hash;
|
return hash;
|
||||||
}
|
}
|
||||||
|
|
||||||
int PredictionContext::calculateHashCode(PredictionContext *parent, int returnState) {
|
size_t PredictionContext::calculateHashCode(PredictionContext *parent, int returnState) {
|
||||||
int hash = MurmurHash::initialize(INITIAL_HASH);
|
size_t hash = MurmurHash::initialize(INITIAL_HASH);
|
||||||
hash = MurmurHash::update(hash, parent);
|
hash = MurmurHash::update(hash, (size_t)parent);
|
||||||
hash = MurmurHash::update(hash, returnState);
|
hash = MurmurHash::update(hash, (size_t)returnState);
|
||||||
hash = MurmurHash::finish(hash, 2);
|
hash = MurmurHash::finish(hash, 2);
|
||||||
return hash;
|
return hash;
|
||||||
}
|
}
|
||||||
|
|
||||||
int PredictionContext::calculateHashCode(std::vector<PredictionContext*> parents, std::vector<int> returnStates) {
|
size_t PredictionContext::calculateHashCode(const std::vector<PredictionContext*> &parents, const std::vector<int> &returnStates) {
|
||||||
int hash = MurmurHash::initialize(INITIAL_HASH);
|
size_t hash = MurmurHash::initialize(INITIAL_HASH);
|
||||||
|
|
||||||
for (auto parent : parents) {
|
for (auto parent : parents) {
|
||||||
hash = MurmurHash::update(hash, parent);
|
hash = MurmurHash::update(hash, (size_t)parent);
|
||||||
}
|
}
|
||||||
for (std::vector<PredictionContext*>::size_type i = 0; i < parents.size() ; i++) {
|
for (std::vector<PredictionContext*>::size_type i = 0; i < parents.size() ; i++) {
|
||||||
PredictionContext * parent = parents[i];
|
PredictionContext * parent = parents[i];
|
||||||
hash = MurmurHash::update(hash, parent);
|
hash = MurmurHash::update(hash, (size_t)parent);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (auto returnState : returnStates) {
|
for (auto returnState : returnStates) {
|
||||||
hash = MurmurHash::update(hash, returnState);
|
hash = MurmurHash::update(hash, (size_t)returnState);
|
||||||
}
|
}
|
||||||
|
|
||||||
hash = MurmurHash::finish(hash, 2 * sizeof(parents) / sizeof(parents[0]));
|
hash = MurmurHash::finish(hash, 2 * sizeof(parents) / sizeof(parents[0]));
|
||||||
|
@ -124,7 +124,7 @@ PredictionContext *PredictionContext::merge(PredictionContext *a, PredictionCont
|
||||||
};
|
};
|
||||||
|
|
||||||
// share same graph if both same
|
// share same graph if both same
|
||||||
if (a == b || a->equals(b)) {
|
if (a == b) {
|
||||||
return a;
|
return a;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -195,17 +195,17 @@ PredictionContext *PredictionContext::mergeSingletons(SingletonPredictionContext
|
||||||
else { // a != b payloads differ
|
else { // a != b payloads differ
|
||||||
// see if we can collapse parents due to $+x parents if local ctx
|
// see if we can collapse parents due to $+x parents if local ctx
|
||||||
PredictionContext *singleParent = nullptr;
|
PredictionContext *singleParent = nullptr;
|
||||||
if (a == b || (a->parent != nullptr && a->parent->equals(b->parent))) { // ax + bx = [a,b]x
|
if (a == b || (a->parent != nullptr && a->parent == b->parent)) { // ax + bx = [a,b]x
|
||||||
singleParent = a->parent;
|
singleParent = a->parent;
|
||||||
}
|
}
|
||||||
if (singleParent != nullptr) { // parents are same
|
if (singleParent != nullptr) { // parents are same
|
||||||
// sort payloads and use same parent
|
// sort payloads and use same parent
|
||||||
int payloads[2] = {a->returnState, b->returnState};
|
std::vector<int> payloads = { a->returnState, b->returnState };
|
||||||
if (a->returnState > b->returnState) {
|
if (a->returnState > b->returnState) {
|
||||||
payloads[0] = b->returnState;
|
payloads[0] = b->returnState;
|
||||||
payloads[1] = a->returnState;
|
payloads[1] = a->returnState;
|
||||||
}
|
}
|
||||||
PredictionContext parents[2] = {*singleParent, *singleParent};
|
std::vector<PredictionContext *> parents = { singleParent, singleParent };
|
||||||
PredictionContext *a_ = new ArrayPredictionContext(parents, payloads);
|
PredictionContext *a_ = new ArrayPredictionContext(parents, payloads);
|
||||||
if (mergeCache != nullptr) {
|
if (mergeCache != nullptr) {
|
||||||
mergeCache->put(a, b, a_);
|
mergeCache->put(a, b, a_);
|
||||||
|
@ -217,12 +217,12 @@ PredictionContext *PredictionContext::mergeSingletons(SingletonPredictionContext
|
||||||
// ax + by = [ax,by]
|
// ax + by = [ax,by]
|
||||||
PredictionContext *a_;
|
PredictionContext *a_;
|
||||||
if (a->returnState > b->returnState) { // sort by payload
|
if (a->returnState > b->returnState) { // sort by payload
|
||||||
int payloads[2] = {b->returnState, a->returnState};
|
std::vector<int> payloads = { b->returnState, a->returnState };
|
||||||
PredictionContext parents[2] = {*b->parent, *a->parent};
|
std::vector<PredictionContext *> parents = { b->parent, a->parent };
|
||||||
a_ = new ArrayPredictionContext(parents, payloads);
|
a_ = new ArrayPredictionContext(parents, payloads);
|
||||||
} else {
|
} else {
|
||||||
int payloads[2] = {a->returnState, b->returnState};
|
std::vector<int> payloads = {a->returnState, b->returnState};
|
||||||
PredictionContext parents[2] = {*a->parent, *b->parent};
|
std::vector<PredictionContext *> parents = { a->parent, b->parent };
|
||||||
a_ = new ArrayPredictionContext(parents, payloads);
|
a_ = new ArrayPredictionContext(parents, payloads);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -246,14 +246,14 @@ PredictionContext *PredictionContext::mergeRoot(SingletonPredictionContext *a, S
|
||||||
return (PredictionContext *)EMPTY;
|
return (PredictionContext *)EMPTY;
|
||||||
}
|
}
|
||||||
if (a == EMPTY) { // $ + x = [$,x]
|
if (a == EMPTY) { // $ + x = [$,x]
|
||||||
int payloads[2] = {b->returnState, EMPTY_RETURN_STATE};
|
std::vector<int> payloads = { b->returnState, EMPTY_RETURN_STATE };
|
||||||
PredictionContext parents[2] = {*b->parent, *EMPTY};
|
std::vector<PredictionContext *> parents = { b->parent, EMPTY };
|
||||||
PredictionContext *joined = new ArrayPredictionContext(parents, payloads);
|
PredictionContext *joined = new ArrayPredictionContext(parents, payloads);
|
||||||
return joined;
|
return joined;
|
||||||
}
|
}
|
||||||
if (b == EMPTY) { // x + $ = [$,x] ($ is always first if present)
|
if (b == EMPTY) { // x + $ = [$,x] ($ is always first if present)
|
||||||
int payloads[2] = {a->returnState, EMPTY_RETURN_STATE};
|
std::vector<int> payloads = { a->returnState, EMPTY_RETURN_STATE };
|
||||||
PredictionContext parents[2] = {*a->parent, *EMPTY};
|
std::vector<PredictionContext *> parents = { a->parent, EMPTY };
|
||||||
PredictionContext *joined = new ArrayPredictionContext(parents, payloads);
|
PredictionContext *joined = new ArrayPredictionContext(parents, payloads);
|
||||||
return joined;
|
return joined;
|
||||||
}
|
}
|
||||||
|
@ -283,14 +283,14 @@ PredictionContext *PredictionContext::mergeArrays(ArrayPredictionContext *a, Arr
|
||||||
|
|
||||||
// walk and merge to yield mergedParents, mergedReturnStates
|
// walk and merge to yield mergedParents, mergedReturnStates
|
||||||
while (i < a->returnStates.size() && j < b->returnStates.size()) {
|
while (i < a->returnStates.size() && j < b->returnStates.size()) {
|
||||||
PredictionContext *a_parent = a->parents->at(i);// [i];
|
PredictionContext *a_parent = a->parents[i];
|
||||||
PredictionContext *b_parent = b->parents->at(i);//&b->parents[j];
|
PredictionContext *b_parent = b->parents[j];
|
||||||
if (a->returnStates[i] == b->returnStates[j]) {
|
if (a->returnStates[i] == b->returnStates[j]) {
|
||||||
// same payload (stack tops are equal), must yield merged singleton
|
// same payload (stack tops are equal), must yield merged singleton
|
||||||
int payload = a->returnStates[i];
|
int payload = a->returnStates[i];
|
||||||
// $+$ = $
|
// $+$ = $
|
||||||
bool both$ = payload == EMPTY_RETURN_STATE && a_parent == nullptr && b_parent == nullptr;
|
bool both$ = payload == EMPTY_RETURN_STATE && a_parent == nullptr && b_parent == nullptr;
|
||||||
bool ax_ax = (a_parent != nullptr && b_parent != nullptr) && a_parent == b_parent;//->equals(b_parent); // ax+ax -> ax
|
bool ax_ax = (a_parent != nullptr && b_parent != nullptr) && a_parent == b_parent; // ax+ax -> ax
|
||||||
if (both$ || ax_ax) {
|
if (both$ || ax_ax) {
|
||||||
mergedParents[k] = a_parent; // choose left
|
mergedParents[k] = a_parent; // choose left
|
||||||
mergedReturnStates[k] = payload;
|
mergedReturnStates[k] = payload;
|
||||||
|
@ -318,13 +318,13 @@ PredictionContext *PredictionContext::mergeArrays(ArrayPredictionContext *a, Arr
|
||||||
// copy over any payloads remaining in either array
|
// copy over any payloads remaining in either array
|
||||||
if (i < a->returnStates.size()) {
|
if (i < a->returnStates.size()) {
|
||||||
for (std::vector<int>::size_type p = i; p < a->returnStates.size(); p++) {
|
for (std::vector<int>::size_type p = i; p < a->returnStates.size(); p++) {
|
||||||
mergedParents[k] = a->parents->at(p);//[p];
|
mergedParents[k] = a->parents[p];
|
||||||
mergedReturnStates[k] = a->returnStates[p];
|
mergedReturnStates[k] = a->returnStates[p];
|
||||||
k++;
|
k++;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
for (std::vector<int>::size_type p = j; p < b->returnStates.size(); p++) {
|
for (std::vector<int>::size_type p = j; p < b->returnStates.size(); p++) {
|
||||||
mergedParents[k] = b->parents->at(p);// [p];
|
mergedParents[k] = b->parents[p];
|
||||||
mergedReturnStates[k] = b->returnStates[p];
|
mergedReturnStates[k] = b->returnStates[p];
|
||||||
k++;
|
k++;
|
||||||
}
|
}
|
||||||
|
@ -348,13 +348,13 @@ PredictionContext *PredictionContext::mergeArrays(ArrayPredictionContext *a, Arr
|
||||||
|
|
||||||
// if we created same array as a or b, return that instead
|
// if we created same array as a or b, return that instead
|
||||||
// TODO: track whether this is possible above during merge sort for speed
|
// TODO: track whether this is possible above during merge sort for speed
|
||||||
if (M->equals(a)) {
|
if (M == a) {
|
||||||
if (mergeCache != nullptr) {
|
if (mergeCache != nullptr) {
|
||||||
mergeCache->put(a,b,a);
|
mergeCache->put(a,b,a);
|
||||||
}
|
}
|
||||||
return a;
|
return a;
|
||||||
}
|
}
|
||||||
if (M->equals(b)) {
|
if (M == b) {
|
||||||
if (mergeCache != nullptr) {
|
if (mergeCache != nullptr) {
|
||||||
mergeCache->put(a,b,b);
|
mergeCache->put(a,b,b);
|
||||||
}
|
}
|
||||||
|
@ -433,7 +433,7 @@ std::wstring PredictionContext::toDOTString(PredictionContext *context) {
|
||||||
if (current == EMPTY) {
|
if (current == EMPTY) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
for (int i = 0; i < current->size(); i++) {
|
for (size_t i = 0; i < current->size(); i++) {
|
||||||
if (current->getParent(i) == nullptr) {
|
if (current->getParent(i) == nullptr) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
@ -477,12 +477,12 @@ PredictionContext *PredictionContext::getCachedContext(PredictionContext *contex
|
||||||
|
|
||||||
std::vector<PredictionContext*> parents;
|
std::vector<PredictionContext*> parents;
|
||||||
|
|
||||||
for (int i = 0; i < sizeof(parents) / sizeof(parents[0]); i++) {
|
for (size_t i = 0; i < sizeof(parents) / sizeof(parents[0]); i++) {
|
||||||
PredictionContext *parent = getCachedContext(context->getParent(i), contextCache, visited);
|
PredictionContext *parent = getCachedContext(context->getParent(i), contextCache, visited);
|
||||||
if (changed || parent != context->getParent(i)) {
|
if (changed || parent != context->getParent(i)) {
|
||||||
if (!changed) {
|
if (!changed) {
|
||||||
parents = std::vector<PredictionContext*>();
|
parents = std::vector<PredictionContext*>();
|
||||||
for (int j = 0; j < context->size(); j++) {
|
for (size_t j = 0; j < context->size(); j++) {
|
||||||
parents[j] = context->getParent(j);
|
parents[j] = context->getParent(j);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -542,7 +542,7 @@ void PredictionContext::getAllContextNodes_(PredictionContext *context, std::vec
|
||||||
|
|
||||||
nodes.push_back(context);
|
nodes.push_back(context);
|
||||||
|
|
||||||
for (int i = 0; i < context->size(); i++) {
|
for (size_t i = 0; i < context->size(); i++) {
|
||||||
getAllContextNodes_(context->getParent(i), nodes, visited);
|
getAllContextNodes_(context->getParent(i), nodes, visited);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -552,15 +552,3 @@ std::wstring PredictionContext::toString() {
|
||||||
// for now.)
|
// for now.)
|
||||||
return L"TODO PredictionContext::toString()";
|
return L"TODO PredictionContext::toString()";
|
||||||
}
|
}
|
||||||
|
|
||||||
int PredictionContext::size() {
|
|
||||||
throw "PredictionContext::size() should not be called";
|
|
||||||
}
|
|
||||||
|
|
||||||
PredictionContext *PredictionContext::getParent(int index) {
|
|
||||||
throw "PredictionContext::getParent should not be called";
|
|
||||||
}
|
|
||||||
|
|
||||||
int PredictionContext::getReturnState(int index) {
|
|
||||||
throw "PredictionContext::getReturnState should not be called";
|
|
||||||
}
|
|
||||||
|
|
|
@ -86,48 +86,33 @@ namespace atn {
|
||||||
/// }
|
/// }
|
||||||
/// </pre>
|
/// </pre>
|
||||||
/// </summary>
|
/// </summary>
|
||||||
const int cachedHashCode;
|
const size_t cachedHashCode;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
PredictionContext(int cachedHashCode);
|
PredictionContext(size_t cachedHashCode);
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Convert a <seealso cref="RuleContext"/> tree to a <seealso cref="PredictionContext"/> graph.
|
|
||||||
/// Return <seealso cref="#EMPTY"/> if {@code outerContext} is empty or null.
|
|
||||||
/// </summary>
|
|
||||||
public:
|
public:
|
||||||
|
/// Convert a RuleContext tree to a PredictionContext graph.
|
||||||
|
/// Return EMPTY if outerContext is empty.
|
||||||
static PredictionContext *fromRuleContext(const ATN &atn, RuleContext *outerContext);
|
static PredictionContext *fromRuleContext(const ATN &atn, RuleContext *outerContext);
|
||||||
|
|
||||||
virtual int size();//= 0;
|
virtual size_t size() const = 0;
|
||||||
|
virtual PredictionContext *getParent(size_t index) const = 0;
|
||||||
|
virtual int getReturnState(size_t index) const = 0;
|
||||||
|
virtual bool operator == (PredictionContext *o) const = 0;
|
||||||
|
|
||||||
virtual PredictionContext *getParent(int index);//= 0;
|
/// This means only the EMPTY context is in set.
|
||||||
|
virtual bool isEmpty() const;
|
||||||
virtual int getReturnState(int index); // = 0;
|
virtual bool hasEmptyPath() const;
|
||||||
|
virtual size_t hashCode() const;
|
||||||
/// <summary>
|
|
||||||
/// This means only the <seealso cref="#EMPTY"/> context is in set. </summary>
|
|
||||||
virtual bool isEmpty();
|
|
||||||
|
|
||||||
virtual bool hasEmptyPath();
|
|
||||||
|
|
||||||
virtual int hashCode() final;
|
|
||||||
|
|
||||||
virtual bool equals(void *obj){ // = 0;
|
|
||||||
// This should be abstract but we need to create arrays of it, which will point to
|
|
||||||
// daughters in reality
|
|
||||||
throw new ASSERTException(L"PredictionContext", L"equal should never be called, abstract class");
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
static int calculateEmptyHashCode();
|
static size_t calculateEmptyHashCode();
|
||||||
|
static size_t calculateHashCode(PredictionContext *parent, int returnState);
|
||||||
|
static size_t calculateHashCode(const std::vector<PredictionContext*> &parents, const std::vector<int> &returnStates);
|
||||||
|
|
||||||
static int calculateHashCode(PredictionContext *parent, int returnState);
|
|
||||||
|
|
||||||
static int calculateHashCode(std::vector<PredictionContext*> parents, std::vector<int>returnStates);
|
|
||||||
|
|
||||||
// dispatch
|
|
||||||
public:
|
public:
|
||||||
|
// dispatch
|
||||||
static PredictionContext *merge(PredictionContext *a, PredictionContext *b, bool rootIsWildcard, misc::DoubleKeyMap<PredictionContext*, PredictionContext*, PredictionContext*> *mergeCache);
|
static PredictionContext *merge(PredictionContext *a, PredictionContext *b, bool rootIsWildcard, misc::DoubleKeyMap<PredictionContext*, PredictionContext*, PredictionContext*> *mergeCache);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
@ -305,22 +290,22 @@ namespace atn {
|
||||||
std::wstring *toStrings(Recognizer<T1, T2> *recognizer, PredictionContext *stop, int currentState) {
|
std::wstring *toStrings(Recognizer<T1, T2> *recognizer, PredictionContext *stop, int currentState) {
|
||||||
std::vector<std::wstring> result = std::vector<std::wstring>();
|
std::vector<std::wstring> result = std::vector<std::wstring>();
|
||||||
|
|
||||||
for (int perm = 0; ; perm++) {
|
for (size_t perm = 0; ; perm++) {
|
||||||
int offset = 0;
|
size_t offset = 0;
|
||||||
bool last = true;
|
bool last = true;
|
||||||
PredictionContext *p = this;
|
PredictionContext *p = this;
|
||||||
int stateNumber = currentState;
|
int stateNumber = currentState;
|
||||||
antlrcpp::StringBuilder *localBuffer = new antlrcpp::StringBuilder();
|
antlrcpp::StringBuilder *localBuffer = new antlrcpp::StringBuilder();
|
||||||
localBuffer->append(L"[");
|
localBuffer->append(L"[");
|
||||||
while (!p->isEmpty() && p != stop) {
|
while (!p->isEmpty() && p != stop) {
|
||||||
int index = 0;
|
size_t index = 0;
|
||||||
if (p->size() > 0) {
|
if (p->size() > 0) {
|
||||||
int bits = 1;
|
size_t bits = 1;
|
||||||
while ((1 << bits) < p->size()) {
|
while ((1 << bits) < p->size()) {
|
||||||
bits++;
|
bits++;
|
||||||
}
|
}
|
||||||
|
|
||||||
int mask = (1 << bits) - 1;
|
size_t mask = (1 << bits) - 1;
|
||||||
index = (perm >> offset) & mask;
|
index = (perm >> offset) & mask;
|
||||||
last &= index >= p->size() - 1;
|
last &= index >= p->size() - 1;
|
||||||
if (index >= p->size()) {
|
if (index >= p->size()) {
|
||||||
|
@ -336,7 +321,7 @@ namespace atn {
|
||||||
}
|
}
|
||||||
|
|
||||||
ATN *atn = recognizer->getATN();
|
ATN *atn = recognizer->getATN();
|
||||||
ATNState *s = atn->states[stateNumber];
|
ATNState *s = atn->states[(size_t)stateNumber];
|
||||||
std::wstring ruleName = recognizer->getRuleNames()[s->ruleIndex];
|
std::wstring ruleName = recognizer->getRuleNames()[s->ruleIndex];
|
||||||
localBuffer->append(ruleName);
|
localBuffer->append(ruleName);
|
||||||
} else if (p->getReturnState(index) != EMPTY_RETURN_STATE) {
|
} else if (p->getReturnState(index) != EMPTY_RETURN_STATE) {
|
||||||
|
|
|
@ -39,45 +39,28 @@
|
||||||
using namespace org::antlr::v4::runtime;
|
using namespace org::antlr::v4::runtime;
|
||||||
using namespace org::antlr::v4::runtime::atn;
|
using namespace org::antlr::v4::runtime::atn;
|
||||||
|
|
||||||
class AltAndContextConfigEqualityComparator : misc::EqualityComparator<ATNConfig> {
|
struct AltAndContextConfigHasher
|
||||||
public:
|
{
|
||||||
int hashCode(ATNConfig* o);
|
size_t operator () (const ATNConfig &o) const {
|
||||||
bool equals(ATNConfig* a, ATNConfig* b);
|
size_t hashCode = misc::MurmurHash::initialize(7);
|
||||||
|
hashCode = misc::MurmurHash::update(hashCode, (size_t)o.state->stateNumber);
|
||||||
private:
|
hashCode = misc::MurmurHash::update(hashCode, (size_t)o.context);
|
||||||
AltAndContextConfigEqualityComparator() {}
|
|
||||||
};
|
|
||||||
|
|
||||||
// TODO -- Determine if we need this hash function.
|
|
||||||
int AltAndContextConfigEqualityComparator::hashCode(ATNConfig* o) {
|
|
||||||
int hashCode = misc::MurmurHash::initialize(7);
|
|
||||||
hashCode = misc::MurmurHash::update(hashCode, o->state->stateNumber);
|
|
||||||
hashCode = misc::MurmurHash::update(hashCode, o->context);
|
|
||||||
return misc::MurmurHash::finish(hashCode, 2);
|
return misc::MurmurHash::finish(hashCode, 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO -- Determine if we need this comparator.
|
|
||||||
bool AltAndContextConfigEqualityComparator::equals(ATNConfig* a, ATNConfig* b) {
|
|
||||||
if (a == b) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
if (a == nullptr || b == nullptr) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return a->state->stateNumber == b->state->stateNumber &&
|
|
||||||
a->context->equals(b->context);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// A Map that uses just the state and the stack context as the key. </summary>
|
|
||||||
class AltAndContextMap : public std::unordered_map < ATNConfig, antlrcpp::BitSet, ATNConfig::ATNConfigHasher> {
|
|
||||||
public:
|
|
||||||
AltAndContextMap() {}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct AltAndContextConfigComparer {
|
||||||
|
bool operator()(const ATNConfig &a, const ATNConfig &b) const
|
||||||
|
{
|
||||||
|
if (&a == &b) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return a.state->stateNumber == b.state->stateNumber &&
|
||||||
|
a.context == b.context;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
bool PredictionModeClass::hasSLLConflictTerminatingPrediction(PredictionMode* mode,
|
bool PredictionModeClass::hasSLLConflictTerminatingPrediction(PredictionMode* mode, ATNConfigSet* configs) {
|
||||||
ATNConfigSet* configs) {
|
|
||||||
/* Configs in rule stop states indicate reaching the end of the decision
|
/* Configs in rule stop states indicate reaching the end of the decision
|
||||||
* rule (local context) or end of start rule (full context). If all
|
* rule (local context) or end of start rule (full context). If all
|
||||||
* configs meet this condition, then none of the configurations is able
|
* configs meet this condition, then none of the configurations is able
|
||||||
|
@ -190,7 +173,8 @@ antlrcpp::BitSet PredictionModeClass::getAlts(const std::vector<antlrcpp::BitSet
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<antlrcpp::BitSet> PredictionModeClass::getConflictingAltSubsets(ATNConfigSet* configs) {
|
std::vector<antlrcpp::BitSet> PredictionModeClass::getConflictingAltSubsets(ATNConfigSet* configs) {
|
||||||
AltAndContextMap configToAlts;
|
/*
|
||||||
|
std::unordered_map<const ATNConfig&, antlrcpp::BitSet, AltAndContextConfigHasher, AltAndContextConfigComparer> configToAlts;
|
||||||
for (const ATNConfig& c : *configs->configLookup) {
|
for (const ATNConfig& c : *configs->configLookup) {
|
||||||
configToAlts[c].set(c.alt);
|
configToAlts[c].set(c.alt);
|
||||||
}
|
}
|
||||||
|
@ -199,12 +183,14 @@ std::vector<antlrcpp::BitSet> PredictionModeClass::getConflictingAltSubsets(ATNC
|
||||||
values.push_back(it.second);
|
values.push_back(it.second);
|
||||||
}
|
}
|
||||||
return values;
|
return values;
|
||||||
|
*/
|
||||||
|
return std::vector<antlrcpp::BitSet>();
|
||||||
}
|
}
|
||||||
|
|
||||||
std::map<ATNState*, antlrcpp::BitSet> PredictionModeClass::getStateToAltMap(ATNConfigSet* configs) {
|
std::map<ATNState*, antlrcpp::BitSet> PredictionModeClass::getStateToAltMap(ATNConfigSet* configs) {
|
||||||
std::map<ATNState*, antlrcpp::BitSet> m;
|
std::map<ATNState*, antlrcpp::BitSet> m;
|
||||||
for (ATNConfig c : *configs->configLookup) {
|
for (ATNConfig c : *configs->configLookup) {
|
||||||
m[c.state].set(c.alt);
|
m[c.state].set((size_t)c.alt);
|
||||||
}
|
}
|
||||||
return m;
|
return m;
|
||||||
}
|
}
|
||||||
|
@ -223,7 +209,7 @@ int PredictionModeClass::getSingleViableAlt(const std::vector<antlrcpp::BitSet>&
|
||||||
int minAlt = alts.nextSetBit(0);
|
int minAlt = alts.nextSetBit(0);
|
||||||
|
|
||||||
assert(minAlt != -1); // TODO -- Remove this after verification.
|
assert(minAlt != -1); // TODO -- Remove this after verification.
|
||||||
viableAlts.set(minAlt);
|
viableAlts.set((size_t)minAlt);
|
||||||
if (viableAlts.count() > 1) // more than 1 viable alt
|
if (viableAlts.count() > 1) // more than 1 viable alt
|
||||||
{
|
{
|
||||||
return ATN::INVALID_ALT_NUMBER;
|
return ATN::INVALID_ALT_NUMBER;
|
||||||
|
|
|
@ -39,18 +39,18 @@ using namespace org::antlr::v4::runtime::atn;
|
||||||
RangeTransition::RangeTransition(ATNState *target, int from, int to) : Transition(target), from(from), to(to) {
|
RangeTransition::RangeTransition(ATNState *target, int from, int to) : Transition(target), from(from), to(to) {
|
||||||
}
|
}
|
||||||
|
|
||||||
int RangeTransition::getSerializationType() {
|
int RangeTransition::getSerializationType() const {
|
||||||
return RANGE;
|
return RANGE;
|
||||||
}
|
}
|
||||||
|
|
||||||
misc::IntervalSet *RangeTransition::label() {
|
misc::IntervalSet RangeTransition::label() const {
|
||||||
return misc::IntervalSet::of(from, to);
|
return misc::IntervalSet::of(from, to);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool RangeTransition::matches(int symbol, int minVocabSymbol, int maxVocabSymbol) {
|
bool RangeTransition::matches(int symbol, int minVocabSymbol, int maxVocabSymbol) const {
|
||||||
return symbol >= from && symbol <= to;
|
return symbol >= from && symbol <= to;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::wstring RangeTransition::toString() {
|
std::wstring RangeTransition::toString() const {
|
||||||
return std::wstring(L"'") + static_cast<wchar_t>(from) + std::wstring(L"'..'") + static_cast<wchar_t>(to) + std::wstring(L"'");
|
return std::wstring(L"'") + static_cast<wchar_t>(from) + std::wstring(L"'..'") + static_cast<wchar_t>(to) + std::wstring(L"'");
|
||||||
}
|
}
|
||||||
|
|
|
@ -46,12 +46,12 @@ namespace atn {
|
||||||
|
|
||||||
RangeTransition(ATNState *target, int from, int to);
|
RangeTransition(ATNState *target, int from, int to);
|
||||||
|
|
||||||
virtual int getSerializationType() override;
|
virtual int getSerializationType() const override;
|
||||||
|
|
||||||
virtual misc::IntervalSet *label() override;
|
virtual misc::IntervalSet label() const override;
|
||||||
virtual bool matches(int symbol, int minVocabSymbol, int maxVocabSymbol) override;
|
virtual bool matches(int symbol, int minVocabSymbol, int maxVocabSymbol) const override;
|
||||||
|
|
||||||
virtual std::wstring toString();
|
virtual std::wstring toString() const;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace atn
|
} // namespace atn
|
||||||
|
|
|
@ -41,14 +41,14 @@ RuleTransition::RuleTransition(RuleStartState *ruleStart, int ruleIndex, int pre
|
||||||
this->followState = followState;
|
this->followState = followState;
|
||||||
}
|
}
|
||||||
|
|
||||||
int RuleTransition::getSerializationType() {
|
int RuleTransition::getSerializationType() const {
|
||||||
return RULE;
|
return RULE;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool RuleTransition::isEpsilon() {
|
bool RuleTransition::isEpsilon() const {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool RuleTransition::matches(int symbol, int minVocabSymbol, int maxVocabSymbol) {
|
bool RuleTransition::matches(int symbol, int minVocabSymbol, int maxVocabSymbol) const {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
|
@ -57,10 +57,10 @@ namespace atn {
|
||||||
|
|
||||||
RuleTransition(RuleStartState *ruleStart, int ruleIndex, int precedence, ATNState *followState);
|
RuleTransition(RuleStartState *ruleStart, int ruleIndex, int precedence, ATNState *followState);
|
||||||
|
|
||||||
virtual int getSerializationType() override;
|
virtual int getSerializationType() const override;
|
||||||
|
|
||||||
virtual bool isEpsilon() override;
|
virtual bool isEpsilon() const override;
|
||||||
virtual bool matches(int symbol, int minVocabSymbol, int maxVocabSymbol) override;
|
virtual bool matches(int symbol, int minVocabSymbol, int maxVocabSymbol) const override;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace atn
|
} // namespace atn
|
||||||
|
|
|
@ -46,7 +46,7 @@ std::wstring SemanticContext::toString() const {
|
||||||
throw new ASSERTException(L"SemanticContext::toString", L"Should never be called, abstract class");
|
throw new ASSERTException(L"SemanticContext::toString", L"Should never be called, abstract class");
|
||||||
}
|
}
|
||||||
|
|
||||||
int SemanticContext::hashCode() {
|
size_t SemanticContext::hashCode() {
|
||||||
// This is a pure virtual function, why does it need an impl?
|
// This is a pure virtual function, why does it need an impl?
|
||||||
throw new ASSERTException(L"SemanticContext::hashCode", L"Should never be called, abstract class");
|
throw new ASSERTException(L"SemanticContext::hashCode", L"Should never be called, abstract class");
|
||||||
}
|
}
|
||||||
|
@ -57,10 +57,10 @@ bool SemanticContext::equals(void *obj) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int SemanticContext::Predicate::hashCode() {
|
size_t SemanticContext::Predicate::hashCode() {
|
||||||
int hashCode = misc::MurmurHash::initialize();
|
size_t hashCode = misc::MurmurHash::initialize();
|
||||||
hashCode = misc::MurmurHash::update(hashCode, ruleIndex);
|
hashCode = misc::MurmurHash::update(hashCode, (size_t)ruleIndex);
|
||||||
hashCode = misc::MurmurHash::update(hashCode, predIndex);
|
hashCode = misc::MurmurHash::update(hashCode, (size_t)predIndex);
|
||||||
hashCode = misc::MurmurHash::update(hashCode, isCtxDependent ? 1 : 0);
|
hashCode = misc::MurmurHash::update(hashCode, isCtxDependent ? 1 : 0);
|
||||||
hashCode = misc::MurmurHash::finish(hashCode, 3);
|
hashCode = misc::MurmurHash::finish(hashCode, 3);
|
||||||
return hashCode;
|
return hashCode;
|
||||||
|
@ -91,9 +91,9 @@ int SemanticContext::PrecedencePredicate::compareTo(PrecedencePredicate *o) {
|
||||||
return precedence - o->precedence;
|
return precedence - o->precedence;
|
||||||
}
|
}
|
||||||
|
|
||||||
int SemanticContext::PrecedencePredicate::hashCode() {
|
size_t SemanticContext::PrecedencePredicate::hashCode() {
|
||||||
int hashCode = 1;
|
size_t hashCode = 1;
|
||||||
hashCode = 31 * hashCode + precedence;
|
hashCode = 31 * hashCode + (size_t)precedence;
|
||||||
return hashCode;
|
return hashCode;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -165,9 +165,8 @@ bool SemanticContext::AND::equals(void *obj) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int SemanticContext::AND::hashCode() {
|
size_t SemanticContext::AND::hashCode() {
|
||||||
return misc::MurmurHash::hashCode(opnds.data(),
|
return misc::MurmurHash::hashCode(opnds.data(), opnds.size(), typeid(AND).hash_code());
|
||||||
opnds.size(), (int)typeid(AND).hash_code());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -229,8 +228,8 @@ bool SemanticContext::OR::equals(SemanticContext *obj) {
|
||||||
return this->opnds == other->opnds;
|
return this->opnds == other->opnds;
|
||||||
}
|
}
|
||||||
|
|
||||||
int SemanticContext::OR::hashCode() {
|
size_t SemanticContext::OR::hashCode() {
|
||||||
return misc::MurmurHash::hashCode(opnds.data(), opnds.size(), (int)typeid(OR).hash_code());
|
return misc::MurmurHash::hashCode(opnds.data(), opnds.size(), typeid(OR).hash_code());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -52,7 +52,7 @@ namespace atn {
|
||||||
public:
|
public:
|
||||||
static SemanticContext *const NONE;
|
static SemanticContext *const NONE;
|
||||||
|
|
||||||
virtual int hashCode() = 0;
|
virtual size_t hashCode() = 0;
|
||||||
|
|
||||||
class Predicate;
|
class Predicate;
|
||||||
class PrecedencePredicate;
|
class PrecedencePredicate;
|
||||||
|
@ -131,7 +131,7 @@ namespace atn {
|
||||||
return parser->sempred(localctx, ruleIndex, predIndex);
|
return parser->sempred(localctx, ruleIndex, predIndex);
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual int hashCode() override;
|
virtual size_t hashCode() override;
|
||||||
|
|
||||||
virtual bool equals(void *obj) override;
|
virtual bool equals(void *obj) override;
|
||||||
|
|
||||||
|
@ -155,7 +155,7 @@ namespace atn {
|
||||||
|
|
||||||
virtual int compareTo(PrecedencePredicate *o);
|
virtual int compareTo(PrecedencePredicate *o);
|
||||||
|
|
||||||
virtual int hashCode() override;
|
virtual size_t hashCode() override;
|
||||||
|
|
||||||
virtual bool equals(void *obj) override;
|
virtual bool equals(void *obj) override;
|
||||||
|
|
||||||
|
@ -179,7 +179,7 @@ namespace atn {
|
||||||
|
|
||||||
virtual bool equals(void *obj) override;
|
virtual bool equals(void *obj) override;
|
||||||
|
|
||||||
virtual int hashCode() override;
|
virtual size_t hashCode() override;
|
||||||
|
|
||||||
template<typename T1, typename T2>
|
template<typename T1, typename T2>
|
||||||
bool eval(Recognizer<T1, T2> *parser, RuleContext *outerContext) {
|
bool eval(Recognizer<T1, T2> *parser, RuleContext *outerContext) {
|
||||||
|
@ -203,7 +203,7 @@ namespace atn {
|
||||||
|
|
||||||
virtual bool equals(SemanticContext *obj);
|
virtual bool equals(SemanticContext *obj);
|
||||||
|
|
||||||
virtual int hashCode() override;
|
virtual size_t hashCode() override;
|
||||||
|
|
||||||
template<typename T1, typename T2>
|
template<typename T1, typename T2>
|
||||||
bool eval(Recognizer<T1, T2> *parser, RuleContext *outerContext) {
|
bool eval(Recognizer<T1, T2> *parser, RuleContext *outerContext) {
|
||||||
|
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue