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 <XCTest/XCTest.h>
|
||||
|
||||
#include "ParserATNSimulator.h"
|
||||
#include "DFA.h"
|
||||
#include "ATN.h"
|
||||
|
||||
#include <vector>
|
||||
|
||||
using namespace org::antlr::v4::runtime;
|
||||
|
||||
@interface antlrcpp_Tests : XCTestCase
|
||||
|
||||
@end
|
||||
|
@ -52,9 +56,10 @@
|
|||
|
||||
- (void)testExample {
|
||||
try {
|
||||
std::vector<org::antlr::v4::runtime::dfa::DFA> decisionToDFA;
|
||||
|
||||
org::antlr::v4::runtime::atn::ParserATNSimulator foo(nullptr, decisionToDFA, nullptr);
|
||||
std::vector<dfa::DFA *> decisionToDFA;
|
||||
atn::ATN atn;
|
||||
|
||||
org::antlr::v4::runtime::atn::ParserATNSimulator foo(nullptr, atn, decisionToDFA, nullptr);
|
||||
}
|
||||
catch (std::exception e) {
|
||||
|
||||
|
@ -63,11 +68,4 @@
|
|||
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
|
||||
|
|
|
@ -11,6 +11,7 @@
|
|||
2747A70B1CA691310030247B /* ConfigLookup.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 2747A7081CA691310030247B /* ConfigLookup.cpp */; };
|
||||
2747A70C1CA691310030247B /* 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 */; };
|
||||
276927251C9ED49100E4EBF8 /* antlrcpp-Prefix.h in Headers */ = {isa = PBXBuildFile; fileRef = 276927231C9ED49100E4EBF8 /* antlrcpp-Prefix.h */; };
|
||||
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 */; };
|
||||
27C668B81C9584FA0021E494 /* 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 */; };
|
||||
27C668C31C9584FA0021E494 /* LogManager.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 27C668901C9584FA0021E494 /* LogManager.cpp */; };
|
||||
27C668C41C9584FA0021E494 /* LogManager.h in Headers */ = {isa = PBXBuildFile; fileRef = 27C668911C9584FA0021E494 /* LogManager.h */; };
|
||||
|
@ -611,19 +608,20 @@
|
|||
/* Begin PBXFileReference section */
|
||||
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>"; };
|
||||
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>"; };
|
||||
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; };
|
||||
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; };
|
||||
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; };
|
||||
27C666631C9584050021E494 /* ANTLRInputStream.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = ANTLRInputStream.h; path = ../../runtime/ANTLRInputStream.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; wrapsLines = 0; };
|
||||
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; };
|
||||
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; };
|
||||
27C666671C9584050021E494 /* BaseErrorListener.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = BaseErrorListener.h; path = ../../runtime/BaseErrorListener.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; wrapsLines = 0; };
|
||||
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; };
|
||||
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; };
|
||||
|
@ -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; };
|
||||
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; };
|
||||
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; };
|
||||
27C666761C9584050021E494 /* DiagnosticErrorListener.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = DiagnosticErrorListener.cpp; path = ../../runtime/DiagnosticErrorListener.cpp; sourceTree = SOURCE_ROOT; };
|
||||
27C666771C9584050021E494 /* DiagnosticErrorListener.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = DiagnosticErrorListener.h; path = ../../runtime/DiagnosticErrorListener.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; wrapsLines = 0; };
|
||||
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; };
|
||||
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; };
|
||||
|
@ -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; };
|
||||
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; };
|
||||
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; };
|
||||
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; };
|
||||
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; };
|
||||
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; };
|
||||
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; };
|
||||
|
@ -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; };
|
||||
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; };
|
||||
27C666941C9584050021E494 /* ProxyErrorListener.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = ProxyErrorListener.cpp; path = ../../runtime/ProxyErrorListener.cpp; sourceTree = SOURCE_ROOT; };
|
||||
27C666951C9584050021E494 /* ProxyErrorListener.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = ProxyErrorListener.h; path = ../../runtime/ProxyErrorListener.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; wrapsLines = 0; };
|
||||
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; };
|
||||
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; };
|
||||
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; };
|
||||
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; };
|
||||
|
@ -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; };
|
||||
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; };
|
||||
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; };
|
||||
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; };
|
||||
|
@ -710,7 +708,7 @@
|
|||
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>"; };
|
||||
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>"; };
|
||||
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>"; };
|
||||
|
@ -736,7 +734,7 @@
|
|||
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; };
|
||||
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>"; };
|
||||
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>"; };
|
||||
|
@ -744,7 +742,7 @@
|
|||
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>"; };
|
||||
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>"; };
|
||||
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>"; };
|
||||
|
@ -753,11 +751,11 @@
|
|||
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>"; };
|
||||
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>"; };
|
||||
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>"; };
|
||||
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>"; };
|
||||
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>"; };
|
||||
|
@ -800,8 +798,6 @@
|
|||
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; };
|
||||
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>"; };
|
||||
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>"; };
|
||||
|
@ -1076,8 +1072,6 @@
|
|||
27C668891C9584FA0021E494 /* Interval.h */,
|
||||
27C6688A1C9584FA0021E494 /* IntervalSet.cpp */,
|
||||
27C6688B1C9584FA0021E494 /* IntervalSet.h */,
|
||||
27C6688C1C9584FA0021E494 /* IntSet.cpp */,
|
||||
27C6688D1C9584FA0021E494 /* IntSet.h */,
|
||||
27C668901C9584FA0021E494 /* LogManager.cpp */,
|
||||
27C668911C9584FA0021E494 /* LogManager.h */,
|
||||
27C668921C9584FA0021E494 /* MultiMap.cpp */,
|
||||
|
@ -1348,8 +1342,9 @@
|
|||
37F135691B4AC02800E0CACF /* antlrcpp Tests */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
37F1356C1B4AC02800E0CACF /* antlrcpp_Tests.mm */,
|
||||
37F1356A1B4AC02800E0CACF /* Supporting Files */,
|
||||
37F1356C1B4AC02800E0CACF /* antlrcpp_Tests.mm */,
|
||||
2747A7121CA6C46C0030247B /* InputHandlingTests.mm */,
|
||||
);
|
||||
path = "antlrcpp Tests";
|
||||
sourceTree = "<group>";
|
||||
|
@ -1436,7 +1431,6 @@
|
|||
27C669921C9585B80021E494 /* ErrorNode.h in Headers */,
|
||||
27C668B91C9584FA0021E494 /* IntervalSet.h in Headers */,
|
||||
27C666C51C9584050021E494 /* BufferedTokenStream.h in Headers */,
|
||||
27C668BD1C9584FA0021E494 /* IntSet.h in Headers */,
|
||||
27C669AA1C9585B80021E494 /* ParseTreeWalker.h in Headers */,
|
||||
27C6685F1C95846E0021E494 /* Transition.h in Headers */,
|
||||
27C666D51C9584050021E494 /* CommonTokenStream.h in Headers */,
|
||||
|
@ -1600,7 +1594,6 @@
|
|||
27C6699D1C9585B80021E494 /* ParseTreeListener.h in Headers */,
|
||||
27C666F61C9584050021E494 /* IntStream.h in Headers */,
|
||||
27C669951C9585B80021E494 /* ErrorNodeImpl.h in Headers */,
|
||||
27C668BC1C9584FA0021E494 /* IntSet.h in Headers */,
|
||||
27C667A81C95846E0021E494 /* AbstractPredicateTransition.h in Headers */,
|
||||
27C669A91C9585B80021E494 /* ParseTreeWalker.h in Headers */,
|
||||
27C667181C9584050021E494 /* ParserRuleContext.h in Headers */,
|
||||
|
@ -1879,7 +1872,6 @@
|
|||
27C668511C95846E0021E494 /* StarLoopbackState.cpp in Sources */,
|
||||
27C667FB1C95846E0021E494 /* LexerATNSimulator.cpp in Sources */,
|
||||
27C667EB1C95846E0021E494 /* DecisionState.cpp in Sources */,
|
||||
27C668BB1C9584FA0021E494 /* IntSet.cpp in Sources */,
|
||||
27C669151C9585230021E494 /* guid.cpp in Sources */,
|
||||
27C669941C9585B80021E494 /* ErrorNodeImpl.cpp in Sources */,
|
||||
27C6687A1C9584B60021E494 /* LexerDFASerializer.cpp in Sources */,
|
||||
|
@ -2079,7 +2071,6 @@
|
|||
27C66A3A1C958AC10021E494 /* XPathLexerErrorListener.cpp in Sources */,
|
||||
27C66A041C958AB30021E494 /* ParseTreePattern.cpp in Sources */,
|
||||
27C6685C1C95846E0021E494 /* Transition.cpp in Sources */,
|
||||
27C668BA1C9584FA0021E494 /* IntSet.cpp in Sources */,
|
||||
27C66A021C958AB30021E494 /* ParseTreeMatch.cpp in Sources */,
|
||||
27C66A361C958AC10021E494 /* XPathElement.cpp in Sources */,
|
||||
27C668441C95846E0021E494 /* SetTransition.cpp in Sources */,
|
||||
|
@ -2115,6 +2106,7 @@
|
|||
buildActionMask = 2147483647;
|
||||
files = (
|
||||
37F1356D1B4AC02800E0CACF /* antlrcpp_Tests.mm in Sources */,
|
||||
2747A7131CA6C46C0030247B /* InputHandlingTests.mm in Sources */,
|
||||
);
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
};
|
||||
|
@ -2224,6 +2216,7 @@
|
|||
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
|
||||
CLANG_WARN_EMPTY_BODY = YES;
|
||||
CLANG_WARN_ENUM_CONVERSION = YES;
|
||||
CLANG_WARN_IMPLICIT_SIGN_CONVERSION = YES;
|
||||
CLANG_WARN_INT_CONVERSION = YES;
|
||||
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
|
||||
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
|
||||
|
@ -2241,6 +2234,7 @@
|
|||
GCC_SYMBOLS_PRIVATE_EXTERN = NO;
|
||||
GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
|
||||
GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR;
|
||||
GCC_WARN_SIGN_COMPARE = YES;
|
||||
GCC_WARN_UNDECLARED_SELECTOR = YES;
|
||||
GCC_WARN_UNINITIALIZED_AUTOS = YES;
|
||||
GCC_WARN_UNUSED_FUNCTION = YES;
|
||||
|
@ -2263,6 +2257,7 @@
|
|||
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
|
||||
CLANG_WARN_EMPTY_BODY = YES;
|
||||
CLANG_WARN_ENUM_CONVERSION = YES;
|
||||
CLANG_WARN_IMPLICIT_SIGN_CONVERSION = YES;
|
||||
CLANG_WARN_INT_CONVERSION = YES;
|
||||
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
|
||||
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
|
||||
|
@ -2274,6 +2269,7 @@
|
|||
GCC_PREFIX_HEADER = "../../runtime/antlrcpp-Prefix.h";
|
||||
GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
|
||||
GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR;
|
||||
GCC_WARN_SIGN_COMPARE = YES;
|
||||
GCC_WARN_UNDECLARED_SELECTOR = YES;
|
||||
GCC_WARN_UNINITIALIZED_AUTOS = YES;
|
||||
GCC_WARN_UNUSED_FUNCTION = YES;
|
||||
|
|
|
@ -56,7 +56,7 @@ conquer:
|
|||
|
||||
// Unused rule to demonstrate some of the special features.
|
||||
// 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 [...] {
|
||||
// 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
|
||||
# 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
|
||||
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=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
|
||||
/// surrounding rule. </param>
|
||||
public:
|
||||
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) {}
|
||||
|
||||
/// <summary>
|
||||
/// 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="configs"> the ATN configuration set where the ambiguity was
|
||||
/// 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>
|
||||
/// 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>
|
||||
/// <param name="configs"> the ATN configuration set where the SLL conflict was
|
||||
/// 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>
|
||||
/// 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="configs"> the ATN configuration set where the unambiguous prediction
|
||||
/// 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
|
||||
|
|
|
@ -30,50 +30,61 @@
|
|||
*/
|
||||
|
||||
#include "Exceptions.h"
|
||||
#include "Strings.h"
|
||||
|
||||
#include "ANTLRFileStream.h"
|
||||
|
||||
using namespace org::antlr::v4::runtime;
|
||||
|
||||
ANTLRFileStream::ANTLRFileStream(const std::string &fileName) {
|
||||
}
|
||||
|
||||
ANTLRFileStream::ANTLRFileStream(const std::string &fileName, const std::string &encoding) {
|
||||
this->fileName = fileName;
|
||||
_fileName = fileName;
|
||||
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) {
|
||||
if (fileName == "") {
|
||||
if (_fileName.empty()) {
|
||||
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::wifstream f;
|
||||
|
||||
// Open as a byte stream
|
||||
f.open(fileName, std::ios::binary);
|
||||
ss<<f.rdbuf();
|
||||
if (!stream.is_open() || stream.eof())
|
||||
return;
|
||||
|
||||
std::string const &s = ss.str();
|
||||
if (s.size() % sizeof(wchar_t) != 0)
|
||||
int ch1 = stream.get();
|
||||
int ch2 = stream.get();
|
||||
if (ch1 == 0xff && ch2 == 0xfe)
|
||||
encodingType = UTF16LE;
|
||||
else
|
||||
if (ch1 == 0xfe && ch2 == 0xff)
|
||||
return; // UTF-16BE not supported;
|
||||
else
|
||||
{
|
||||
int ch3 = stream.get();
|
||||
if (ch1 == 0xef && ch2 == 0xbb && ch3 == 0xbf)
|
||||
encodingType = UTF8;
|
||||
else
|
||||
stream.seekg(0);
|
||||
}
|
||||
|
||||
ss << stream.rdbuf() << '\0';
|
||||
switch (encodingType)
|
||||
{
|
||||
throw new IOException(L"file not the right size");
|
||||
case UTF16LE:
|
||||
data = (wchar_t *)ss.str().c_str();
|
||||
default:
|
||||
data = antlrcpp::s2ws(ss.str());
|
||||
}
|
||||
|
||||
std::wstring ws;
|
||||
ws.resize(s.size()/sizeof(wchar_t));
|
||||
std::memcpy(&ws[0],s.c_str(),s.size()); // copy data into wstring
|
||||
data=ws;
|
||||
}
|
||||
|
||||
std::string ANTLRFileStream::getSourceName() {
|
||||
return fileName;
|
||||
return _fileName;
|
||||
}
|
||||
|
|
|
@ -38,18 +38,17 @@ namespace antlr {
|
|||
namespace v4 {
|
||||
namespace runtime {
|
||||
|
||||
/// <summary>
|
||||
/// This is an <seealso cref="ANTLRInputStream"/> that is loaded from a file all at once
|
||||
/// This is an ANTLRInputStream that is loaded from a file all at once
|
||||
/// when you construct the object.
|
||||
/// </summary>
|
||||
class ANTLRFileStream : public ANTLRInputStream {
|
||||
protected:
|
||||
std::string fileName;
|
||||
std::string _fileName; // UTF-8 encoded file name.
|
||||
|
||||
public:
|
||||
ANTLRFileStream(const std::string &fileName); //this(fileName, nullptr);
|
||||
|
||||
ANTLRFileStream(const std::string &fileName, const std::string &encoding);
|
||||
// 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.
|
||||
// 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);
|
||||
|
||||
|
|
|
@ -29,78 +29,54 @@
|
|||
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include <algorithm>
|
||||
#include "Exceptions.h"
|
||||
#include "Interval.h"
|
||||
#include "Arrays.h"
|
||||
#include "CPPUtils.h"
|
||||
|
||||
#include "ANTLRInputStream.h"
|
||||
|
||||
using namespace org::antlr::v4::runtime;
|
||||
using namespace antlrcpp;
|
||||
|
||||
using misc::Interval;
|
||||
|
||||
ANTLRInputStream::ANTLRInputStream() {
|
||||
ANTLRInputStream::ANTLRInputStream(const std::wstring &input) : data(input) {
|
||||
InitializeInstanceFields();
|
||||
}
|
||||
|
||||
ANTLRInputStream::ANTLRInputStream(const std::wstring &input) : ANTLRInputStream() {
|
||||
this->data = input;
|
||||
this->n = (int)input.length();
|
||||
ANTLRInputStream::ANTLRInputStream(const wchar_t data[], size_t numberOfActualCharsInArray)
|
||||
: ANTLRInputStream(std::wstring(data, numberOfActualCharsInArray)) {
|
||||
}
|
||||
|
||||
ANTLRInputStream::ANTLRInputStream(wchar_t data[], int numberOfActualCharsInArray) : ANTLRInputStream() {
|
||||
this->data = data;
|
||||
this->n = numberOfActualCharsInArray;
|
||||
ANTLRInputStream::ANTLRInputStream(std::wiostream &stream) : ANTLRInputStream(stream, READ_BUFFER_SIZE) {
|
||||
}
|
||||
|
||||
|
||||
ANTLRInputStream::ANTLRInputStream(std::wifstream *r) : ANTLRInputStream() {
|
||||
ANTLRInputStream::ANTLRInputStream(std::wiostream &stream, std::streamsize readChunkSize) : ANTLRInputStream() {
|
||||
load(stream, readChunkSize);
|
||||
}
|
||||
|
||||
|
||||
ANTLRInputStream::ANTLRInputStream(std::wifstream *r, int initialSize) : ANTLRInputStream() {
|
||||
}
|
||||
|
||||
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) {
|
||||
void ANTLRInputStream::load(std::wiostream &stream, std::streamsize readChunkSize) {
|
||||
stream.seekg(0, stream.beg);
|
||||
if (!stream.good()) // No fail, bad or EOF.
|
||||
return;
|
||||
}
|
||||
|
||||
if (size <= 0) {
|
||||
size = INITIAL_BUFFER_SIZE;
|
||||
}
|
||||
|
||||
if (readChunkSize <= 0) {
|
||||
data.clear();
|
||||
|
||||
if (readChunkSize == 0) {
|
||||
readChunkSize = READ_BUFFER_SIZE;
|
||||
}
|
||||
|
||||
try {
|
||||
// alloc initial buffer size.
|
||||
data = new wchar_t[size];
|
||||
// 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);
|
||||
wchar_t *buffer = new wchar_t[readChunkSize];
|
||||
auto onExit = finally([buffer] {
|
||||
delete[] buffer;
|
||||
});
|
||||
|
||||
p += numRead;
|
||||
} while (numRead != -1); // while not EOF
|
||||
// set the actual size of the data available;
|
||||
// EOF subtracted one above in p+=numRead; add one back
|
||||
n = p + 1;
|
||||
while (!stream.eof()) {
|
||||
stream.read(buffer, readChunkSize);
|
||||
data.append(buffer, (size_t)std::min(stream.gcount(), readChunkSize));
|
||||
}
|
||||
catch (void *) {
|
||||
r->close();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void ANTLRInputStream::reset() {
|
||||
|
@ -108,72 +84,77 @@ void ANTLRInputStream::reset() {
|
|||
}
|
||||
|
||||
void ANTLRInputStream::consume() {
|
||||
if (p >= n) {
|
||||
if (p >= data.size()) {
|
||||
assert(LA(1) == IntStream::_EOF);
|
||||
throw IllegalStateException(L"cannot consume EOF");
|
||||
}
|
||||
|
||||
if (p < n) {
|
||||
if (p < data.size()) {
|
||||
p++;
|
||||
}
|
||||
}
|
||||
|
||||
int ANTLRInputStream::LA(int i) {
|
||||
size_t ANTLRInputStream::LA(ssize_t i) {
|
||||
if (i == 0) {
|
||||
return 0; // undefined
|
||||
}
|
||||
|
||||
ssize_t position = (ssize_t)p;
|
||||
if (i < 0) {
|
||||
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
|
||||
}
|
||||
}
|
||||
|
||||
if ((p + i - 1) >= n) {
|
||||
if ((position + i - 1) >= (ssize_t)data.size()) {
|
||||
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);
|
||||
}
|
||||
|
||||
int ANTLRInputStream::index() {
|
||||
size_t ANTLRInputStream::index() {
|
||||
return p;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
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) {
|
||||
p = index; // just jump; don't update stream state (line, ...)
|
||||
return;
|
||||
}
|
||||
// seek forward, consume until p hits index
|
||||
while (p < index && index < n) {
|
||||
while (p < index && index < data.size()) {
|
||||
consume();
|
||||
}
|
||||
}
|
||||
|
||||
std::wstring ANTLRInputStream::getText(Interval *interval) {
|
||||
int start = interval->a;
|
||||
int stop = interval->b;
|
||||
if (stop >= n) {
|
||||
stop = n - 1;
|
||||
std::wstring ANTLRInputStream::getText(const Interval &interval) {
|
||||
size_t start = (size_t)interval.a;
|
||||
size_t stop = (size_t)interval.b;
|
||||
|
||||
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"";
|
||||
}
|
||||
|
||||
|
@ -189,6 +170,5 @@ std::wstring ANTLRInputStream::toString() {
|
|||
}
|
||||
|
||||
void ANTLRInputStream::InitializeInstanceFields() {
|
||||
n = 0;
|
||||
p = 0;
|
||||
}
|
||||
|
|
|
@ -38,96 +38,58 @@ namespace antlr {
|
|||
namespace v4 {
|
||||
namespace runtime {
|
||||
|
||||
/// Vacuum all input from a Reader/InputStream and then treat it
|
||||
/// like a char[] buffer. Can also pass in a string or char[] to use.
|
||||
/// <p/>
|
||||
/// If you need encoding, pass in stream/reader with correct encoding.
|
||||
/// </summary>
|
||||
/// Vacuum all input from a stream and then treat it
|
||||
/// like a string. Can also pass in a string or char[] to use.
|
||||
class ANTLRInputStream : public CharStream {
|
||||
public:
|
||||
static const int READ_BUFFER_SIZE = 1024;
|
||||
static const int INITIAL_BUFFER_SIZE = 1024;
|
||||
|
||||
/// <summary>
|
||||
/// The data being scanned </summary>
|
||||
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>
|
||||
int p;
|
||||
size_t p;
|
||||
|
||||
/// <summary>
|
||||
/// What is name or source of this char stream? </summary>
|
||||
public:
|
||||
/// What is name or source of this char stream?
|
||||
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>
|
||||
/// Copy data in string to a local char array </summary>
|
||||
ANTLRInputStream(const std::wstring &input);
|
||||
virtual void load(std::wiostream &stream, std::streamsize readChunkSize);
|
||||
|
||||
/// <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
|
||||
/// when the object was created *except* the data array is not
|
||||
/// touched.
|
||||
/// </summary>
|
||||
/// when the object was created *except* the data array is not
|
||||
/// touched.
|
||||
virtual void reset();
|
||||
|
||||
virtual void consume() override;
|
||||
|
||||
virtual int LA(int i) override;
|
||||
|
||||
virtual int LT(int i);
|
||||
virtual size_t LA(ssize_t i) override;
|
||||
virtual size_t LT(ssize_t i);
|
||||
|
||||
/// <summary>
|
||||
/// 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
|
||||
/// be returned from LA(1).
|
||||
/// </summary>
|
||||
virtual int index() override;
|
||||
|
||||
virtual size_t index() override;
|
||||
virtual size_t size() override;
|
||||
|
||||
/// <summary>
|
||||
/// mark/release do nothing; we have entire buffer </summary>
|
||||
virtual int mark() override;
|
||||
|
||||
virtual void release(int marker) override;
|
||||
virtual ssize_t mark() override;
|
||||
virtual void release(ssize_t marker) override;
|
||||
|
||||
/// <summary>
|
||||
/// 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
|
||||
/// </summary>
|
||||
virtual void seek(int index) override;
|
||||
|
||||
virtual std::wstring getText(misc::Interval *interval) override;
|
||||
|
||||
virtual void seek(size_t index) override;
|
||||
virtual std::wstring getText(const misc::Interval &interval) override;
|
||||
virtual std::string getSourceName() override;
|
||||
|
||||
virtual std::wstring toString();
|
||||
|
||||
private:
|
||||
|
|
|
@ -33,11 +33,14 @@
|
|||
|
||||
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 {
|
||||
|
||||
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
|
||||
|
|
|
@ -51,15 +51,15 @@ TokenSource *BufferedTokenStream::getTokenSource() {
|
|||
return tokenSource;
|
||||
}
|
||||
|
||||
int BufferedTokenStream::index() {
|
||||
size_t BufferedTokenStream::index() {
|
||||
return p;
|
||||
}
|
||||
|
||||
int BufferedTokenStream::mark() {
|
||||
ssize_t BufferedTokenStream::mark() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
void BufferedTokenStream::release(int marker) {
|
||||
void BufferedTokenStream::release(ssize_t marker) {
|
||||
// no resources to release
|
||||
}
|
||||
|
||||
|
@ -67,7 +67,7 @@ void BufferedTokenStream::reset() {
|
|||
seek(0);
|
||||
}
|
||||
|
||||
void BufferedTokenStream::seek(int index) {
|
||||
void BufferedTokenStream::seek(size_t index) {
|
||||
lazyInit();
|
||||
p = adjustSeekIndex(index);
|
||||
}
|
||||
|
@ -86,24 +86,23 @@ void BufferedTokenStream::consume() {
|
|||
}
|
||||
}
|
||||
|
||||
bool BufferedTokenStream::sync(int i) {
|
||||
assert(i >= 0);
|
||||
bool BufferedTokenStream::sync(size_t i) {
|
||||
size_t n = i - tokens.size() + 1; // how many more elements we need?
|
||||
|
||||
if (n > 0) {
|
||||
size_t fetched = fetch((int)n);
|
||||
size_t fetched = fetch(n);
|
||||
return fetched >= n;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
int BufferedTokenStream::fetch(int n) {
|
||||
size_t BufferedTokenStream::fetch(size_t n) {
|
||||
if (fetchedEOF) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
for (int i = 0; i < n; i++) {
|
||||
for (size_t i = 0; i < n; i++) {
|
||||
Token *t = tokenSource->nextToken();
|
||||
if (dynamic_cast<WritableToken*>(t) != nullptr) {
|
||||
(static_cast<WritableToken*>(t))->setTokenIndex((int)tokens.size());
|
||||
|
@ -118,8 +117,8 @@ int BufferedTokenStream::fetch(int n) {
|
|||
return n;
|
||||
}
|
||||
|
||||
Token *BufferedTokenStream::get(int i) {
|
||||
if (i < 0 || i >= (int)tokens.size()) {
|
||||
Token *BufferedTokenStream::get(size_t i) {
|
||||
if (i >= tokens.size()) {
|
||||
throw IndexOutOfBoundsException(std::wstring(L"token index ") +
|
||||
std::to_wstring(i) +
|
||||
std::wstring(L" out of range 0..") +
|
||||
|
@ -128,16 +127,19 @@ Token *BufferedTokenStream::get(int i) {
|
|||
return tokens[i];
|
||||
}
|
||||
|
||||
std::vector<Token*> BufferedTokenStream::get(int start, int stop) {
|
||||
if (start < 0 || stop < 0) {
|
||||
return std::vector<Token*>();
|
||||
}
|
||||
std::vector<Token*> BufferedTokenStream::get(size_t start, size_t stop) {
|
||||
std::vector<Token*> subset;
|
||||
|
||||
lazyInit();
|
||||
std::vector<Token*> subset = std::vector<Token*>();
|
||||
if (stop >= (int)tokens.size()) {
|
||||
stop = (int)tokens.size() - 1;
|
||||
|
||||
if (tokens.empty()) {
|
||||
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];
|
||||
if (t->getType() == Token::_EOF) {
|
||||
break;
|
||||
|
@ -147,47 +149,48 @@ std::vector<Token*> BufferedTokenStream::get(int start, int stop) {
|
|||
return subset;
|
||||
}
|
||||
|
||||
int BufferedTokenStream::LA(int i) {
|
||||
return LT(i)->getType();
|
||||
size_t BufferedTokenStream::LA(ssize_t i) {
|
||||
return (size_t)LT(i)->getType();
|
||||
}
|
||||
|
||||
Token *BufferedTokenStream::LB(int k) {
|
||||
if ((p - k) < 0) {
|
||||
Token *BufferedTokenStream::LB(size_t k) {
|
||||
if (k > p) {
|
||||
return nullptr;
|
||||
}
|
||||
return tokens[p - k];
|
||||
return tokens[(size_t)(p - k)];
|
||||
}
|
||||
|
||||
Token *BufferedTokenStream::LT(int k) {
|
||||
Token *BufferedTokenStream::LT(ssize_t k) {
|
||||
lazyInit();
|
||||
if (k == 0) {
|
||||
return nullptr;
|
||||
}
|
||||
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);
|
||||
if (i >= (int)tokens.size()) { // return EOF token
|
||||
if (i >= tokens.size()) { // return EOF token
|
||||
// EOF must be last token
|
||||
return tokens[tokens.size() - 1];
|
||||
return tokens.back();
|
||||
}
|
||||
// if ( i>range ) range = i;
|
||||
|
||||
return tokens[i];
|
||||
}
|
||||
|
||||
int BufferedTokenStream::adjustSeekIndex(int i) {
|
||||
size_t BufferedTokenStream::adjustSeekIndex(size_t i) {
|
||||
return i;
|
||||
}
|
||||
|
||||
void BufferedTokenStream::lazyInit() {
|
||||
if (p == -1) {
|
||||
if (_needSetup) {
|
||||
setup();
|
||||
}
|
||||
}
|
||||
|
||||
void BufferedTokenStream::setup() {
|
||||
_needSetup = false;
|
||||
sync(0);
|
||||
p = adjustSeekIndex(0);
|
||||
}
|
||||
|
@ -195,7 +198,7 @@ void BufferedTokenStream::setup() {
|
|||
void BufferedTokenStream::setTokenSource(TokenSource *tokenSource) {
|
||||
this->tokenSource = tokenSource;
|
||||
tokens.clear();
|
||||
p = -1;
|
||||
_needSetup = true;
|
||||
}
|
||||
|
||||
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}
|
||||
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];
|
||||
|
||||
if (types == nullptr) {
|
||||
|
@ -245,12 +248,13 @@ std::vector<Token*> BufferedTokenStream::getTokens(int start, int stop, int ttyp
|
|||
return getTokens(start,stop, s);
|
||||
}
|
||||
|
||||
int BufferedTokenStream::nextTokenOnChannel(int i, int channel) {
|
||||
ssize_t BufferedTokenStream::nextTokenOnChannel(size_t i, int channel) {
|
||||
sync(i);
|
||||
Token *token = tokens[i];
|
||||
if (i >= (int)size()) {
|
||||
if (i >= size()) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
Token *token = tokens[i];
|
||||
while (token->getChannel() != channel) {
|
||||
if (token->getType() == Token::_EOF) {
|
||||
return -1;
|
||||
|
@ -259,67 +263,71 @@ int BufferedTokenStream::nextTokenOnChannel(int i, int channel) {
|
|||
sync(i);
|
||||
token = tokens[i];
|
||||
}
|
||||
return i;
|
||||
return (ssize_t)i;
|
||||
}
|
||||
|
||||
int BufferedTokenStream::previousTokenOnChannel(int i, int channel) {
|
||||
while (i >= 0 && tokens[i]->getChannel() != channel) {
|
||||
ssize_t BufferedTokenStream::previousTokenOnChannel(size_t i, int channel) const {
|
||||
do {
|
||||
if (tokens[i]->getChannel() == channel)
|
||||
return (ssize_t)i;
|
||||
if (i == 0)
|
||||
return -1;
|
||||
i--;
|
||||
}
|
||||
return i;
|
||||
} while (true);
|
||||
return -1;
|
||||
}
|
||||
|
||||
std::vector<Token*> BufferedTokenStream::getHiddenTokensToRight(int tokenIndex, int channel) {
|
||||
std::vector<Token*> BufferedTokenStream::getHiddenTokensToRight(size_t tokenIndex, int channel) {
|
||||
lazyInit();
|
||||
if (tokenIndex < 0 || tokenIndex >= (int)tokens.size()) {
|
||||
if (tokenIndex >= tokens.size()) {
|
||||
throw new IndexOutOfBoundsException(std::to_wstring(tokenIndex) +
|
||||
std::wstring(L" not in 0..") +
|
||||
std::to_wstring(tokens.size() - 1));
|
||||
}
|
||||
|
||||
int nextOnChannel = nextTokenOnChannel(tokenIndex + 1, Lexer::DEFAULT_TOKEN_CHANNEL);
|
||||
int to;
|
||||
int from = tokenIndex + 1;
|
||||
ssize_t nextOnChannel = nextTokenOnChannel(tokenIndex + 1, Lexer::DEFAULT_TOKEN_CHANNEL);
|
||||
ssize_t to;
|
||||
size_t from = tokenIndex + 1;
|
||||
// if none onchannel to right, nextOnChannel=-1 so set to = last token
|
||||
if (nextOnChannel == -1) {
|
||||
to = (int)size() - 1;
|
||||
to = (ssize_t)size() - 1;
|
||||
} else {
|
||||
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);
|
||||
}
|
||||
|
||||
std::vector<Token*> BufferedTokenStream::getHiddenTokensToLeft(int tokenIndex, int channel) {
|
||||
std::vector<Token*> BufferedTokenStream::getHiddenTokensToLeft(size_t tokenIndex, int channel) {
|
||||
lazyInit();
|
||||
if (tokenIndex < 0 || tokenIndex >= (int)tokens.size()) {
|
||||
if (tokenIndex >= tokens.size()) {
|
||||
throw new IndexOutOfBoundsException(std::to_wstring(tokenIndex) +
|
||||
std::wstring(L" not in 0..") +
|
||||
std::to_wstring(tokens.size() - 1));
|
||||
}
|
||||
|
||||
int prevOnChannel = previousTokenOnChannel(tokenIndex - 1, Lexer::DEFAULT_TOKEN_CHANNEL);
|
||||
if (prevOnChannel == tokenIndex - 1) {
|
||||
ssize_t prevOnChannel = previousTokenOnChannel(tokenIndex - 1, Lexer::DEFAULT_TOKEN_CHANNEL);
|
||||
if (prevOnChannel == (ssize_t)tokenIndex - 1) {
|
||||
return std::vector<Token*>();
|
||||
}
|
||||
// if none onchannel to left, prevOnChannel=-1 then from=0
|
||||
int from = prevOnChannel + 1;
|
||||
int to = tokenIndex - 1;
|
||||
size_t from = (size_t)(prevOnChannel + 1);
|
||||
size_t to = tokenIndex - 1;
|
||||
|
||||
return filterForChannel(from, to, channel);
|
||||
}
|
||||
|
||||
std::vector<Token*> BufferedTokenStream::getHiddenTokensToLeft(int tokenIndex) {
|
||||
std::vector<Token*> BufferedTokenStream::getHiddenTokensToLeft(size_t tokenIndex) {
|
||||
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*>();
|
||||
for (int i = from; i <= to; i++) {
|
||||
for (size_t i = from; i <= to; i++) {
|
||||
Token *t = tokens[i];
|
||||
if (channel == -1) {
|
||||
if (t->getChannel() != Lexer::DEFAULT_TOKEN_CHANNEL) {
|
||||
|
@ -351,9 +359,9 @@ std::wstring BufferedTokenStream::getText() {
|
|||
return getText(misc::Interval::of(0, (int)size() - 1));
|
||||
}
|
||||
|
||||
std::wstring BufferedTokenStream::getText(misc::Interval *interval) {
|
||||
int start = interval->a;
|
||||
int stop = interval->b;
|
||||
std::wstring BufferedTokenStream::getText(const misc::Interval &interval) {
|
||||
int start = interval.a;
|
||||
int stop = interval.b;
|
||||
if (start < 0 || stop < 0) {
|
||||
return L"";
|
||||
}
|
||||
|
@ -363,7 +371,7 @@ std::wstring BufferedTokenStream::getText(misc::Interval *interval) {
|
|||
}
|
||||
|
||||
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];
|
||||
if (t->getType() == Token::_EOF) {
|
||||
break;
|
||||
|
@ -387,9 +395,9 @@ std::wstring BufferedTokenStream::getText(Token *start, Token *stop) {
|
|||
|
||||
void BufferedTokenStream::fill() {
|
||||
lazyInit();
|
||||
const int blockSize = 1000;
|
||||
const size_t blockSize = 1000;
|
||||
while (true) {
|
||||
int fetched = fetch(blockSize);
|
||||
size_t fetched = fetch(blockSize);
|
||||
if (fetched < blockSize) {
|
||||
return;
|
||||
}
|
||||
|
@ -398,6 +406,6 @@ void BufferedTokenStream::fill() {
|
|||
|
||||
void BufferedTokenStream::InitializeInstanceFields() {
|
||||
tokens.reserve(100);
|
||||
p = -1;
|
||||
_needSetup = true;
|
||||
fetchedEOF = false;
|
||||
}
|
||||
|
|
|
@ -70,7 +70,7 @@ namespace runtime {
|
|||
/// <seealso cref="#LT LT(1)"/> or whatever gets the first token and sets
|
||||
/// <seealso cref="#p"/>{@code =0;}.
|
||||
/// </summary>
|
||||
int p;
|
||||
size_t p;
|
||||
|
||||
/// <summary>
|
||||
/// Set to {@code true} when the EOF token is fetched. Do not continue fetching
|
||||
|
@ -84,14 +84,14 @@ namespace runtime {
|
|||
BufferedTokenStream(TokenSource *tokenSource);
|
||||
|
||||
virtual TokenSource *getTokenSource() override;
|
||||
virtual int index() override;
|
||||
virtual int mark() override;
|
||||
virtual size_t index() override;
|
||||
virtual ssize_t mark() override;
|
||||
|
||||
virtual void release(int marker) override;
|
||||
virtual void release(ssize_t marker) override;
|
||||
|
||||
virtual void reset();
|
||||
|
||||
virtual void seek(int index) override;
|
||||
virtual void seek(size_t index) override;
|
||||
|
||||
virtual size_t size() override;
|
||||
virtual void consume() override;
|
||||
|
@ -103,30 +103,30 @@ namespace runtime {
|
|||
/// {@code false}. </returns>
|
||||
/// <seealso cref= #get(int i) </seealso>
|
||||
protected:
|
||||
virtual bool sync(int i);
|
||||
virtual bool sync(size_t i);
|
||||
|
||||
/// <summary>
|
||||
/// Add {@code n} elements to buffer.
|
||||
/// </summary>
|
||||
/// <returns> The actual number of elements added to the buffer. </returns>
|
||||
virtual int fetch(int n);
|
||||
virtual size_t fetch(size_t n);
|
||||
|
||||
public:
|
||||
virtual Token *get(int i) override;
|
||||
virtual Token *get(size_t i) override;
|
||||
|
||||
/// <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:
|
||||
virtual Token *LB(int k);
|
||||
virtual Token *LB(size_t k);
|
||||
|
||||
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
|
||||
/// the current stream position by adjusting the target token index of a seek
|
||||
/// operation. The default implementation simply returns {@code i}. If an
|
||||
|
@ -135,23 +135,18 @@ namespace runtime {
|
|||
/// <p/>
|
||||
/// For example, <seealso cref="CommonTokenStream"/> overrides this method to ensure that
|
||||
/// the seek target is always an on-channel token.
|
||||
/// </summary>
|
||||
///
|
||||
/// <param name="i"> The target token index. </param>
|
||||
/// <returns> The adjusted target token index. </returns>
|
||||
protected:
|
||||
virtual int adjustSeekIndex(int i);
|
||||
|
||||
virtual size_t adjustSeekIndex(size_t i);
|
||||
void lazyInit();
|
||||
|
||||
virtual void setup();
|
||||
|
||||
/// <summary>
|
||||
/// Reset this token stream by setting its token source. </summary>
|
||||
public:
|
||||
virtual void setTokenSource(TokenSource *tokenSource);
|
||||
|
||||
virtual std::vector<Token*> getTokens();
|
||||
|
||||
virtual std::vector<Token*> getTokens(int start, int stop);
|
||||
|
||||
/// <summary>
|
||||
|
@ -163,20 +158,16 @@ namespace runtime {
|
|||
|
||||
virtual std::vector<Token*> getTokens(int start, int stop, int ttype);
|
||||
|
||||
/// <summary>
|
||||
/// 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
|
||||
/// on channel between i and EOF.
|
||||
/// </summary>
|
||||
protected:
|
||||
virtual int nextTokenOnChannel(int i, int 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
|
||||
/// on channel between i and EOF.
|
||||
virtual ssize_t nextTokenOnChannel(size_t i, int channel);
|
||||
|
||||
/// <summary>
|
||||
/// 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
|
||||
/// on channel between i and 0.
|
||||
/// </summary>
|
||||
virtual int previousTokenOnChannel(int i, int channel);
|
||||
/// Return i if tokens[i] is on channel. Return -1 if there are no tokens
|
||||
/// on channel between i and 0.
|
||||
virtual ssize_t previousTokenOnChannel(size_t i, int channel) const;
|
||||
|
||||
/// <summary>
|
||||
/// 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.
|
||||
/// </summary>
|
||||
public:
|
||||
virtual std::vector<Token*> getHiddenTokensToRight(int tokenIndex, int channel);
|
||||
virtual std::vector<Token*> getHiddenTokensToRight(size_t tokenIndex, int channel);
|
||||
|
||||
/// <summary>
|
||||
/// 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
|
||||
/// of EOF.
|
||||
/// </summary>
|
||||
virtual std::vector<Token*> getHiddenTokensToRight(int tokenIndex);
|
||||
virtual std::vector<Token*> getHiddenTokensToRight(size_t tokenIndex);
|
||||
|
||||
/// <summary>
|
||||
/// Collect all tokens on specified channel to the left of
|
||||
/// the current token up until we see a token on DEFAULT_TOKEN_CHANNEL.
|
||||
/// If channel is -1, find any non default channel token.
|
||||
/// </summary>
|
||||
virtual std::vector<Token*> getHiddenTokensToLeft(int tokenIndex, int channel);
|
||||
virtual std::vector<Token*> getHiddenTokensToLeft(size_t tokenIndex, int channel);
|
||||
|
||||
/// <summary>
|
||||
/// 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.
|
||||
/// </summary>
|
||||
virtual std::vector<Token*> getHiddenTokensToLeft(int tokenIndex);
|
||||
virtual std::vector<Token*> getHiddenTokensToLeft(size_t tokenIndex);
|
||||
|
||||
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:
|
||||
virtual std::string getSourceName() 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;
|
||||
|
||||
|
@ -224,6 +215,7 @@ namespace runtime {
|
|||
virtual void fill();
|
||||
|
||||
private:
|
||||
bool _needSetup;
|
||||
void InitializeInstanceFields();
|
||||
};
|
||||
|
||||
|
|
|
@ -40,6 +40,8 @@ namespace runtime {
|
|||
|
||||
/// A source of characters for an ANTLR lexer.
|
||||
class CharStream : public IntStream {
|
||||
public:
|
||||
virtual ~CharStream() = 0;
|
||||
|
||||
/// 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
|
||||
|
@ -55,10 +57,7 @@ namespace runtime {
|
|||
/// past the end of the stream </exception>
|
||||
/// <exception cref="UnsupportedOperationException"> if the stream does not support
|
||||
/// getting the text of the specified interval </exception>
|
||||
public:
|
||||
virtual std::wstring getText(misc::Interval *interval) = 0;
|
||||
|
||||
virtual ~CharStream() = 0;
|
||||
virtual std::wstring getText(const misc::Interval &interval) = 0;
|
||||
};
|
||||
|
||||
} // namespace runtime
|
||||
|
|
|
@ -53,7 +53,7 @@ CommonToken::CommonToken(std::pair<TokenSource*, CharStream*> *source, int type,
|
|||
this->start = start;
|
||||
this->stop = stop;
|
||||
if (source->first != nullptr) {
|
||||
this->line = source->first->getLine();
|
||||
this->line = (int)source->first->getLine();
|
||||
this->charPositionInLine = source->first->getCharPositionInLine();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -43,49 +43,48 @@ CommonTokenStream::CommonTokenStream(TokenSource *tokenSource, int channel) : Bu
|
|||
this->channel = channel;
|
||||
}
|
||||
|
||||
int CommonTokenStream::adjustSeekIndex(int i) {
|
||||
return nextTokenOnChannel(i, channel);
|
||||
size_t CommonTokenStream::adjustSeekIndex(size_t i) {
|
||||
// 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) {
|
||||
if (k == 0 || (p - k) < 0) {
|
||||
Token *CommonTokenStream::LB(size_t k) {
|
||||
if (k == 0 || k > p) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
int i = p;
|
||||
int n = 1;
|
||||
size_t i = p;
|
||||
size_t n = 1;
|
||||
// find k good tokens looking backwards
|
||||
while (n <= k) {
|
||||
// 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++;
|
||||
}
|
||||
if (i < 0) {
|
||||
return nullptr;
|
||||
}
|
||||
return tokens[i];
|
||||
}
|
||||
|
||||
Token *CommonTokenStream::LT(int k) {
|
||||
//System.out.println("enter LT("+k+")");
|
||||
Token *CommonTokenStream::LT(ssize_t k) {
|
||||
lazyInit();
|
||||
if (k == 0) {
|
||||
return nullptr;
|
||||
}
|
||||
if (k < 0) {
|
||||
return LB(-k);
|
||||
return LB((size_t)-k);
|
||||
}
|
||||
int i = p;
|
||||
int n = 1; // we know tokens[p] is a good one
|
||||
size_t i = p;
|
||||
size_t n = 1; // we know tokens[p] is a good one
|
||||
// find k good tokens
|
||||
while (n < k) {
|
||||
while (n < (size_t)k) {
|
||||
// skip off-channel tokens, but make sure to not look past EOF
|
||||
if (sync(i + 1)) {
|
||||
i = nextTokenOnChannel(i + 1, channel);
|
||||
// XXX ml: no error handling either
|
||||
i = (size_t)nextTokenOnChannel(i + 1, channel);
|
||||
}
|
||||
n++;
|
||||
}
|
||||
// if ( i>range ) range = i;
|
||||
|
||||
return tokens[i];
|
||||
}
|
||||
|
||||
|
|
|
@ -67,12 +67,12 @@ namespace runtime {
|
|||
CommonTokenStream(TokenSource *tokenSource, int channel);
|
||||
|
||||
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:
|
||||
virtual Token *LT(int k) override;
|
||||
virtual Token *LT(ssize_t k) override;
|
||||
|
||||
/// <summary>
|
||||
/// Count EOF just once. </summary>
|
||||
|
|
|
@ -93,48 +93,42 @@ void DefaultErrorStrategy::reportError(Parser *recognizer, RecognitionException
|
|||
}
|
||||
|
||||
void DefaultErrorStrategy::recover(Parser *recognizer, RecognitionException *e) {
|
||||
// System.out.println("recover in "+recognizer.getRuleInvocationStack()+
|
||||
// " index="+recognizer.getInputStream().index()+
|
||||
// ", lastErrorIndex="+
|
||||
// lastErrorIndex+
|
||||
// ", states="+lastErrorStates);
|
||||
if (lastErrorIndex == recognizer->getInputStream()->index() && lastErrorStates != nullptr && lastErrorStates->contains(recognizer->getState())) {
|
||||
if (lastErrorIndex == (int)recognizer->getInputStream()->index() && lastErrorStates != nullptr &&
|
||||
lastErrorStates->contains(recognizer->getState())) {
|
||||
|
||||
// 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
|
||||
// token set so nothing got consumed. Consume a single token
|
||||
// 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();
|
||||
}
|
||||
lastErrorIndex = recognizer->getInputStream()->index();
|
||||
lastErrorIndex = (int)recognizer->getInputStream()->index();
|
||||
if (lastErrorStates == nullptr) {
|
||||
lastErrorStates = new misc::IntervalSet(0);
|
||||
}
|
||||
lastErrorStates->add(recognizer->getState());
|
||||
misc::IntervalSet *followSet = getErrorRecoverySet(recognizer);
|
||||
misc::IntervalSet followSet = getErrorRecoverySet(recognizer);
|
||||
consumeUntil(recognizer, followSet);
|
||||
}
|
||||
|
||||
void DefaultErrorStrategy::sync(Parser *recognizer) {
|
||||
atn::ATNState *s = recognizer->getInterpreter()->atn.states[recognizer->getState()];
|
||||
// System.err.println("sync @ "+s.stateNumber+"="+s.getClass().getSimpleName());
|
||||
atn::ATNState *s = recognizer->getInterpreter()->atn.states[(size_t)recognizer->getState()];
|
||||
|
||||
// If already recovering, don't try to sync
|
||||
if (inErrorRecoveryMode(recognizer)) {
|
||||
return;
|
||||
}
|
||||
|
||||
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
|
||||
if (recognizer->getATN().nextTokens(s)->contains(la) || la == Token::_EOF) {
|
||||
if (recognizer->getATN().nextTokens(s).contains((int)la) || la == Token::_EOF) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Return but don't end recovery. only do that upon valid token match
|
||||
if (recognizer->isExpectedToken(la)) {
|
||||
if (recognizer->isExpectedToken((int)la)) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -154,8 +148,8 @@ void DefaultErrorStrategy::sync(Parser *recognizer) {
|
|||
case atn::ATNState::STAR_LOOP_BACK: {
|
||||
// System.err.println("at loop back: "+s.getClass().getSimpleName());
|
||||
reportUnwantedToken(recognizer);
|
||||
misc::IntervalSet *expecting = recognizer->getExpectedTokens();
|
||||
misc::IntervalSet *whatFollowsLoopIterationOrRule = expecting->Or(getErrorRecoverySet(recognizer));
|
||||
misc::IntervalSet expecting = recognizer->getExpectedTokens();
|
||||
misc::IntervalSet whatFollowsLoopIterationOrRule = expecting.Or(getErrorRecoverySet(recognizer));
|
||||
consumeUntil(recognizer, whatFollowsLoopIterationOrRule);
|
||||
}
|
||||
break;
|
||||
|
@ -183,12 +177,12 @@ void DefaultErrorStrategy::reportNoViableAlternative(Parser *recognizer, NoViabl
|
|||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
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();
|
||||
recognizer->notifyErrorListeners(e->getOffendingToken(), msg, e);
|
||||
}
|
||||
|
@ -202,9 +196,9 @@ void DefaultErrorStrategy::reportUnwantedToken(Parser *recognizer) {
|
|||
|
||||
Token *t = recognizer->getCurrentToken();
|
||||
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);
|
||||
}
|
||||
|
||||
|
@ -216,8 +210,8 @@ void DefaultErrorStrategy::reportMissingToken(Parser *recognizer) {
|
|||
beginErrorCondition(recognizer);
|
||||
|
||||
Token *t = recognizer->getCurrentToken();
|
||||
misc::IntervalSet *expecting = getExpectedTokens(recognizer);
|
||||
std::wstring msg = std::wstring(L"missing ") + expecting->toString(recognizer->getTokenNames()) + std::wstring(L" at ") + getTokenErrorDisplay(t);
|
||||
misc::IntervalSet expecting = getExpectedTokens(recognizer);
|
||||
std::wstring msg = std::wstring(L"missing ") + expecting.toString(recognizer->getTokenNames()) + std::wstring(L" at ") + getTokenErrorDisplay(t);
|
||||
|
||||
recognizer->notifyErrorListeners(t, msg, nullptr);
|
||||
}
|
||||
|
@ -242,15 +236,16 @@ Token *DefaultErrorStrategy::recoverInline(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
|
||||
// ATN state, then we know we're missing a token; error recovery
|
||||
// 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;
|
||||
const atn::ATN &atn = recognizer->getInterpreter()->atn;
|
||||
misc::IntervalSet *expectingAtLL2 = atn.nextTokens(next, recognizer->ctx);
|
||||
if (expectingAtLL2->contains(currentSymbolType)) {
|
||||
misc::IntervalSet expectingAtLL2 = atn.nextTokens(next, recognizer->ctx);
|
||||
if (expectingAtLL2.contains((int)currentSymbolType)) {
|
||||
reportMissingToken(recognizer);
|
||||
return true;
|
||||
}
|
||||
|
@ -258,16 +253,10 @@ bool DefaultErrorStrategy::singleTokenInsertion(Parser *recognizer) {
|
|||
}
|
||||
|
||||
Token *DefaultErrorStrategy::singleTokenDeletion(Parser *recognizer) {
|
||||
int nextTokenType = recognizer->getInputStream()->LA(2);
|
||||
misc::IntervalSet *expecting = getExpectedTokens(recognizer);
|
||||
if (expecting->contains(nextTokenType)) {
|
||||
size_t nextTokenType = recognizer->getInputStream()->LA(2);
|
||||
misc::IntervalSet expecting = getExpectedTokens(recognizer);
|
||||
if (expecting.contains((int)nextTokenType)) {
|
||||
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
|
||||
// we want to return the token we're actually matching
|
||||
Token *matchedSymbol = recognizer->getCurrentToken();
|
||||
|
@ -279,23 +268,25 @@ Token *DefaultErrorStrategy::singleTokenDeletion(Parser *recognizer) {
|
|||
|
||||
Token *DefaultErrorStrategy::getMissingSymbol(Parser *recognizer) {
|
||||
Token *currentSymbol = recognizer->getCurrentToken();
|
||||
misc::IntervalSet *expecting = getExpectedTokens(recognizer);
|
||||
int expectedTokenType = expecting->getMinElement(); // get any element
|
||||
misc::IntervalSet expecting = getExpectedTokens(recognizer);
|
||||
size_t expectedTokenType = (size_t)expecting.getMinElement(); // get any element
|
||||
std::wstring tokenText;
|
||||
if (expectedTokenType == Token::_EOF) {
|
||||
tokenText = L"<missing EOF>";
|
||||
} 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 *lookback = recognizer->getInputStream()->LT(-1);
|
||||
if (current->getType() == Token::_EOF && lookback != nullptr) {
|
||||
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();
|
||||
}
|
||||
|
||||
|
@ -330,26 +321,26 @@ std::wstring DefaultErrorStrategy::escapeWSAndQuote(std::wstring &s) {
|
|||
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;
|
||||
RuleContext *ctx = recognizer->ctx;
|
||||
misc::IntervalSet *recoverSet = new misc::IntervalSet(0);
|
||||
misc::IntervalSet recoverSet;
|
||||
while (ctx != nullptr && ctx->invokingState >= 0) {
|
||||
// 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));
|
||||
misc::IntervalSet *follow = atn.nextTokens(rt->followState);
|
||||
recoverSet->addAll(follow);
|
||||
misc::IntervalSet follow = atn.nextTokens(rt->followState);
|
||||
recoverSet.addAll(follow);
|
||||
ctx = ctx->parent;
|
||||
}
|
||||
recoverSet->remove(Token::EPSILON);
|
||||
// System.out.println("recover set "+recoverSet.toString(recognizer.getTokenNames()));
|
||||
recoverSet.remove(Token::EPSILON);
|
||||
|
||||
return recoverSet;
|
||||
}
|
||||
|
||||
void DefaultErrorStrategy::consumeUntil(Parser *recognizer, misc::IntervalSet *set) {
|
||||
int ttype = recognizer->getInputStream()->LA(1);
|
||||
while (ttype != Token::_EOF && !set->contains(ttype)) {
|
||||
void DefaultErrorStrategy::consumeUntil(Parser *recognizer, const misc::IntervalSet &set) {
|
||||
size_t ttype = recognizer->getInputStream()->LA(1);
|
||||
while (ttype != Token::_EOF && !set.contains((int)ttype)) {
|
||||
recognizer->consume();
|
||||
ttype = recognizer->getInputStream()->LA(1);
|
||||
}
|
||||
|
|
|
@ -32,6 +32,7 @@
|
|||
#pragma once
|
||||
|
||||
#include "ANTLRErrorStrategy.h"
|
||||
#include "IntervalSet.h"
|
||||
|
||||
namespace org {
|
||||
namespace antlr {
|
||||
|
@ -367,7 +368,7 @@ namespace runtime {
|
|||
/// </summary>
|
||||
virtual Token *getMissingSymbol(Parser *recognizer);
|
||||
|
||||
virtual misc::IntervalSet *getExpectedTokens(Parser *recognizer);
|
||||
virtual misc::IntervalSet getExpectedTokens(Parser *recognizer);
|
||||
|
||||
/// <summary>
|
||||
/// 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
|
||||
* at run-time upon error to avoid overhead during parsing.
|
||||
*/
|
||||
virtual misc::IntervalSet *getErrorRecoverySet(Parser *recognizer);
|
||||
virtual misc::IntervalSet getErrorRecoverySet(Parser *recognizer);
|
||||
|
||||
/// <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:
|
||||
void InitializeInstanceFields();
|
||||
|
|
|
@ -48,29 +48,32 @@ DiagnosticErrorListener::DiagnosticErrorListener() : exactOnly(true) {
|
|||
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) {
|
||||
return;
|
||||
}
|
||||
wchar_t buf[16];
|
||||
std::wstring decision = getDecisionDescription(recognizer, dfa);
|
||||
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"'";
|
||||
swprintf(buf, sizeof(buf) / sizeof(*buf), L"%d", 5);
|
||||
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 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"'";
|
||||
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 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"'";
|
||||
recognizer->notifyErrorListeners(message);
|
||||
}
|
||||
|
@ -84,7 +87,7 @@ std::wstring DiagnosticErrorListener::getDecisionDescription(Parser *recognizer,
|
|||
return antlrcpp::StringConverterHelper::toString(decision);
|
||||
}
|
||||
|
||||
std::wstring ruleName = ruleNames[ruleIndex];
|
||||
std::wstring ruleName = ruleNames[(size_t)ruleIndex];
|
||||
if (ruleName == L"" || ruleName.empty()) {
|
||||
return antlrcpp::StringConverterHelper::toString(decision);
|
||||
}
|
||||
|
@ -99,8 +102,8 @@ antlrcpp::BitSet *DiagnosticErrorListener::getConflictingAlts(antlrcpp::BitSet *
|
|||
|
||||
antlrcpp::BitSet *result = new antlrcpp::BitSet();
|
||||
for (size_t i = 0; i < configs->size(); i++) {
|
||||
atn::ATNConfig *config = configs->get((int)i);
|
||||
result->set(config->alt);
|
||||
atn::ATNConfig *config = configs->get(i);
|
||||
result->set((size_t)config->alt);
|
||||
}
|
||||
|
||||
return result;
|
||||
|
|
|
@ -81,11 +81,14 @@ namespace runtime {
|
|||
/// {@code false} to report all ambiguities. </param>
|
||||
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:
|
||||
virtual std::wstring getDecisionDescription(Parser *recognizer, dfa::DFA *dfa);
|
||||
|
|
|
@ -44,7 +44,7 @@ namespace runtime {
|
|||
ANTLRException(const std::wstring msg) {
|
||||
this->errormsg = msg;
|
||||
}
|
||||
std::wstring getMessage() {
|
||||
std::wstring getMessage() const {
|
||||
return errormsg;
|
||||
}
|
||||
|
||||
|
|
|
@ -52,7 +52,7 @@ FailedPredicateException::FailedPredicateException(Parser *recognizer, const std
|
|||
#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));
|
||||
if (dynamic_cast<atn::PredicateTransition*>(trans) != nullptr) {
|
||||
|
|
|
@ -59,7 +59,7 @@ namespace runtime {
|
|||
/// </summary>
|
||||
public:
|
||||
// EOF Conflict with OS X, change to _EOF
|
||||
static const int _EOF = std::ios::eofbit;
|
||||
static const size_t _EOF = std::ios::eofbit;
|
||||
|
||||
/// <summary>
|
||||
/// The value returned by <seealso cref="#getSourceName"/> when the actual name of the
|
||||
|
@ -123,7 +123,7 @@ namespace runtime {
|
|||
/// </summary>
|
||||
/// <exception cref="UnsupportedOperationException"> if the stream does not support
|
||||
/// retrieving the value of the specified symbol </exception>
|
||||
virtual int LA(int i) = 0;
|
||||
virtual size_t LA(ssize_t i) = 0;
|
||||
|
||||
/// <summary>
|
||||
/// A mark provides a guarantee that <seealso cref="#seek seek()"/> operations will be
|
||||
|
@ -170,7 +170,7 @@ namespace runtime {
|
|||
/// </summary>
|
||||
/// <returns> An opaque marker which should be passed to
|
||||
/// <seealso cref="#release release()"/> when the marked range is no longer required. </returns>
|
||||
virtual int mark() = 0;
|
||||
virtual ssize_t mark() = 0;
|
||||
|
||||
/// <summary>
|
||||
/// This method releases a marked range created by a call to
|
||||
|
@ -183,7 +183,7 @@ namespace runtime {
|
|||
/// </summary>
|
||||
/// <param name="marker"> A marker returned by a call to {@code mark()}. </param>
|
||||
/// <seealso cref= #mark </seealso>
|
||||
virtual void release(int marker) = 0;
|
||||
virtual void release(ssize_t marker) = 0;
|
||||
|
||||
/// <summary>
|
||||
/// 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
|
||||
/// constructed.
|
||||
/// </summary>
|
||||
virtual int index() = 0;
|
||||
virtual size_t index() = 0;
|
||||
|
||||
/// <summary>
|
||||
/// 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="UnsupportedOperationException"> if the stream does not support
|
||||
/// seeking to the specified index </exception>
|
||||
virtual void seek(int index) = 0;
|
||||
virtual void seek(size_t index) = 0;
|
||||
|
||||
/// <summary>
|
||||
/// Returns the total number of symbols in the stream, including a single EOF
|
||||
|
|
|
@ -33,10 +33,10 @@
|
|||
|
||||
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) {
|
||||
}
|
||||
|
||||
int InterpreterRuleContext::getRuleIndex() {
|
||||
ssize_t InterpreterRuleContext::getRuleIndex() const {
|
||||
return ruleIndex;
|
||||
}
|
||||
|
|
|
@ -45,12 +45,12 @@ namespace runtime {
|
|||
/// </summary>
|
||||
class InterpreterRuleContext : public ParserRuleContext {
|
||||
private:
|
||||
const int ruleIndex;
|
||||
const ssize_t ruleIndex;
|
||||
|
||||
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
|
||||
|
|
|
@ -78,7 +78,7 @@ Token *Lexer::nextToken() {
|
|||
|
||||
// Mark start location in char stream so unbuffered streams are
|
||||
// guaranteed at least have text of current token
|
||||
int tokenStartMarker = _input->mark();
|
||||
ssize_t tokenStartMarker = _input->mark();
|
||||
try {
|
||||
while (true) {
|
||||
outerContinue:
|
||||
|
@ -89,9 +89,9 @@ Token *Lexer::nextToken() {
|
|||
|
||||
delete _token;
|
||||
_channel = Token::DEFAULT_CHANNEL;
|
||||
_tokenStartCharIndex = _input->index();
|
||||
_tokenStartCharIndex = (int)_input->index();
|
||||
_tokenStartCharPositionInLine = getInterpreter()->getCharPositionInLine();
|
||||
_tokenStartLine = getInterpreter()->getLine();
|
||||
_tokenStartLine = (int)getInterpreter()->getLine();
|
||||
_text = L"";
|
||||
do {
|
||||
_type = Token::INVALID_TYPE;
|
||||
|
@ -100,7 +100,7 @@ Token *Lexer::nextToken() {
|
|||
// " at index "+input.index());
|
||||
int ttype;
|
||||
try {
|
||||
ttype = getInterpreter()->match(_input, _mode);
|
||||
ttype = getInterpreter()->match(_input, (size_t)_mode);
|
||||
} catch (LexerNoViableAltException *e) {
|
||||
notifyListeners(e); // report error
|
||||
recover(e);
|
||||
|
@ -207,12 +207,13 @@ Token *Lexer::emitEOF() {
|
|||
int n = _token->getStopIndex() - _token->getStartIndex() + 1;
|
||||
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);
|
||||
return eof;
|
||||
}
|
||||
|
||||
int Lexer::getLine() {
|
||||
size_t Lexer::getLine() const {
|
||||
return getInterpreter()->getLine();
|
||||
}
|
||||
|
||||
|
@ -220,7 +221,7 @@ int Lexer::getCharPositionInLine() {
|
|||
return getInterpreter()->getCharPositionInLine();
|
||||
}
|
||||
|
||||
void Lexer::setLine(int line) {
|
||||
void Lexer::setLine(size_t line) {
|
||||
getInterpreter()->setLine(line);
|
||||
}
|
||||
|
||||
|
@ -229,7 +230,7 @@ void Lexer::setCharPositionInLine(int charPositionInLine) {
|
|||
}
|
||||
|
||||
int Lexer::getCharIndex() {
|
||||
return _input->index();
|
||||
return (int)_input->index();
|
||||
}
|
||||
|
||||
std::wstring Lexer::getText() {
|
||||
|
@ -285,11 +286,11 @@ void Lexer::recover(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"'");
|
||||
|
||||
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) {
|
||||
|
|
|
@ -179,11 +179,11 @@ namespace runtime {
|
|||
|
||||
virtual Token *emitEOF();
|
||||
|
||||
virtual int getLine() override;
|
||||
virtual size_t getLine() const override;
|
||||
|
||||
virtual int getCharPositionInLine() override;
|
||||
|
||||
virtual void setLine(int line);
|
||||
virtual void setLine(size_t line);
|
||||
|
||||
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++) {
|
||||
_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);
|
||||
if (tokenNames) {
|
||||
|
|
|
@ -37,10 +37,10 @@
|
|||
|
||||
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;
|
||||
}
|
||||
|
||||
|
@ -54,8 +54,8 @@ CharStream *LexerNoViableAltException::getInputStream() {
|
|||
|
||||
std::wstring LexerNoViableAltException::toString() {
|
||||
std::wstring symbol = L"";
|
||||
if (startIndex >= 0 && startIndex < (int)getInputStream()->size()) {
|
||||
symbol = getInputStream()->getText(misc::Interval::of(startIndex,startIndex));
|
||||
if (startIndex < getInputStream()->size()) {
|
||||
symbol = getInputStream()->getText(misc::Interval::of((int)startIndex, (int)startIndex));
|
||||
symbol = antlrcpp::escapeWhitespace(symbol, false);
|
||||
}
|
||||
std::wstring format = L"LexerNoViableAltException('" + symbol + L"')";
|
||||
|
|
|
@ -43,16 +43,16 @@ namespace runtime {
|
|||
/// <summary>
|
||||
/// Matching attempted at what input index? </summary>
|
||||
private:
|
||||
const int startIndex;
|
||||
const size_t startIndex;
|
||||
|
||||
/// <summary>
|
||||
/// Which configurations did we try at input.index() that couldn't match input.LA(1)? </summary>
|
||||
atn::ATNConfigSet *const deadEndConfigs;
|
||||
|
||||
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();
|
||||
|
||||
|
|
|
@ -74,7 +74,8 @@ Token *ListTokenSource::nextToken() {
|
|||
}
|
||||
|
||||
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;
|
||||
|
@ -89,11 +90,11 @@ Token *ListTokenSource::nextToken() {
|
|||
return t;
|
||||
}
|
||||
|
||||
int ListTokenSource::getLine() {
|
||||
size_t ListTokenSource::getLine() const {
|
||||
if (i < tokens.size()) {
|
||||
return tokens[i]->getLine();
|
||||
return (size_t)tokens[i]->getLine();
|
||||
} else if (eofToken != nullptr) {
|
||||
return eofToken->getLine();
|
||||
return (size_t)eofToken->getLine();
|
||||
} else if (tokens.size() > 0) {
|
||||
// have to calculate the result from the line/column of the previous
|
||||
// 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.
|
||||
return line;
|
||||
return (size_t)line;
|
||||
}
|
||||
|
||||
// only reach this if tokens is empty, meaning EOF occurs at the first
|
||||
|
|
|
@ -130,7 +130,7 @@ namespace runtime {
|
|||
/// <summary>
|
||||
/// @inheritDoc
|
||||
/// </summary>
|
||||
virtual int getLine() override;
|
||||
virtual size_t getLine() const override;
|
||||
|
||||
/// <summary>
|
||||
/// @inheritDoc
|
||||
|
|
|
@ -54,7 +54,7 @@ Parser::TraceListener::TraceListener(Parser *outerInstance) : outerInstance(oute
|
|||
|
||||
void Parser::TraceListener::enterEveryRule(ParserRuleContext *ctx) {
|
||||
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())
|
||||
<< std::endl;
|
||||
}
|
||||
|
@ -62,7 +62,7 @@ void Parser::TraceListener::enterEveryRule(ParserRuleContext *ctx) {
|
|||
void Parser::TraceListener::visitTerminal(tree::TerminalNode *node) {
|
||||
std::cout << "consume "
|
||||
<< node->getSymbol() << " rule "
|
||||
<< antlrcpp::ws2s(outerInstance->getRuleNames()[outerInstance->ctx->getRuleIndex()])
|
||||
<< antlrcpp::ws2s(outerInstance->getRuleNames()[(size_t)outerInstance->ctx->getRuleIndex()])
|
||||
<< std::endl;
|
||||
}
|
||||
|
||||
|
@ -71,7 +71,7 @@ void Parser::TraceListener::visitErrorNode(tree::ErrorNode *node) {
|
|||
|
||||
void Parser::TraceListener::exitEveryRule(ParserRuleContext *ctx) {
|
||||
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())
|
||||
<< std::endl;
|
||||
}
|
||||
|
@ -314,7 +314,7 @@ void Parser::notifyErrorListeners(Token *offendingToken, const std::wstring &msg
|
|||
charPositionInLine = offendingToken->getCharPositionInLine();
|
||||
|
||||
ANTLRErrorListener *listener = getErrorListenerDispatch();
|
||||
listener->syntaxError(this, offendingToken, line, charPositionInLine, msg, e);
|
||||
listener->syntaxError(this, offendingToken, (size_t)line, charPositionInLine, msg, e);
|
||||
}
|
||||
|
||||
Token *Parser::consume() {
|
||||
|
@ -387,7 +387,7 @@ void Parser::enterOuterAlt(ParserRuleContext *localctx, int altNum) {
|
|||
}
|
||||
|
||||
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) {
|
||||
|
@ -472,42 +472,42 @@ bool Parser::inContext(const std::wstring &context) {
|
|||
bool Parser::isExpectedToken(int symbol) {
|
||||
const atn::ATN &atn = getInterpreter()->atn;
|
||||
ParserRuleContext *ctx = ctx;
|
||||
atn::ATNState *s = atn.states[getState()];
|
||||
misc::IntervalSet *following = atn.nextTokens(s);
|
||||
atn::ATNState *s = atn.states[(size_t)getState()];
|
||||
misc::IntervalSet following = atn.nextTokens(s);
|
||||
|
||||
if (following->contains(symbol)) {
|
||||
if (following.contains(symbol)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!following->contains(Token::EPSILON)) {
|
||||
if (!following.contains(Token::EPSILON)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
while (ctx != nullptr && ctx->invokingState >= 0 && following->contains(Token::EPSILON)) {
|
||||
atn::ATNState *invokingState = atn.states[ctx->invokingState];
|
||||
while (ctx != nullptr && ctx->invokingState >= 0 && following.contains(Token::EPSILON)) {
|
||||
atn::ATNState *invokingState = atn.states[(size_t)ctx->invokingState];
|
||||
atn::RuleTransition *rt = static_cast<atn::RuleTransition*>(invokingState->transition(0));
|
||||
following = atn.nextTokens(rt->followState);
|
||||
if (following->contains(symbol)) {
|
||||
if (following.contains(symbol)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
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 false;
|
||||
}
|
||||
|
||||
misc::IntervalSet *Parser::getExpectedTokens() {
|
||||
misc::IntervalSet Parser::getExpectedTokens() {
|
||||
return getATN().getExpectedTokens(getState(), getContext());
|
||||
}
|
||||
|
||||
misc::IntervalSet *Parser::getExpectedTokensWithinCurrentRule() {
|
||||
misc::IntervalSet Parser::getExpectedTokensWithinCurrentRule() {
|
||||
const atn::ATN &atn = getInterpreter()->atn;
|
||||
atn::ATNState *s = atn.states[getState()];
|
||||
atn::ATNState *s = atn.states[(size_t)getState()];
|
||||
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>();
|
||||
while (p != nullptr) {
|
||||
// compute what follows who invoked us
|
||||
int ruleIndex = p->getRuleIndex();
|
||||
ssize_t ruleIndex = p->getRuleIndex();
|
||||
if (ruleIndex < 0) {
|
||||
stack.push_back(L"n/a");
|
||||
} else {
|
||||
stack.push_back(ruleNames[ruleIndex]);
|
||||
stack.push_back(ruleNames[(size_t)ruleIndex]);
|
||||
}
|
||||
p = p->parent;
|
||||
}
|
||||
|
|
|
@ -35,6 +35,7 @@
|
|||
#include "ParseTreeListener.h"
|
||||
#include "TokenStream.h"
|
||||
#include "TokenSource.h"
|
||||
#include "Interval.h"
|
||||
|
||||
namespace org {
|
||||
namespace antlr {
|
||||
|
@ -356,9 +357,9 @@ namespace runtime {
|
|||
/// respectively.
|
||||
/// </summary>
|
||||
/// <seealso cref= ATN#getExpectedTokens(int, RuleContext) </seealso>
|
||||
virtual misc::IntervalSet *getExpectedTokens();
|
||||
virtual misc::IntervalSet getExpectedTokens();
|
||||
|
||||
virtual misc::IntervalSet *getExpectedTokensWithinCurrentRule();
|
||||
virtual misc::IntervalSet getExpectedTokensWithinCurrentRule();
|
||||
|
||||
/// <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;
|
||||
}
|
||||
|
||||
atn::RuleStartState *ruleStartState = _atn.ruleToStartState[state->ruleIndex];
|
||||
atn::RuleStartState *ruleStartState = _atn.ruleToStartState[(size_t)state->ruleIndex];
|
||||
if (!ruleStartState->isPrecedenceRule) {
|
||||
continue;
|
||||
}
|
||||
|
@ -76,7 +76,7 @@ ParserInterpreter::ParserInterpreter(const std::wstring &grammarFileName, const
|
|||
}
|
||||
|
||||
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) {
|
||||
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);
|
||||
if (startRuleStartState->isPrecedenceRule) {
|
||||
|
@ -140,7 +140,7 @@ void ParserInterpreter::enterRecursionRule(ParserRuleContext *localctx, int stat
|
|||
}
|
||||
|
||||
atn::ATNState *ParserInterpreter::getATNState() {
|
||||
return _atn.states.at(getState());
|
||||
return _atn.states[(size_t)getState()];
|
||||
}
|
||||
|
||||
void ParserInterpreter::visitState(atn::ATNState *p) {
|
||||
|
@ -151,12 +151,12 @@ void ParserInterpreter::visitState(atn::ATNState *p) {
|
|||
edge = 1;
|
||||
}
|
||||
|
||||
atn::Transition *transition = p->transition(edge - 1);
|
||||
atn::Transition *transition = p->transition((size_t)edge - 1);
|
||||
switch (transition->getSerializationType()) {
|
||||
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());
|
||||
pushNewRecursionContext(ruleContext, _atn.ruleToStartState[p->ruleIndex]->stateNumber, ruleContext->getRuleIndex());
|
||||
pushNewRecursionContext(ruleContext, _atn.ruleToStartState[(size_t)p->ruleIndex]->stateNumber, (int)ruleContext->getRuleIndex());
|
||||
}
|
||||
break;
|
||||
|
||||
|
@ -167,7 +167,7 @@ void ParserInterpreter::visitState(atn::ATNState *p) {
|
|||
case atn::Transition::RANGE:
|
||||
case atn::Transition::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);
|
||||
}
|
||||
matchWildcard();
|
||||
|
@ -222,7 +222,7 @@ void ParserInterpreter::visitState(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) {
|
||||
std::pair<ParserRuleContext*, int> *parentContext = _parentContextStack->back(); // TODO: Dan - make sure this is equivalent
|
||||
_parentContextStack->pop_back();
|
||||
|
@ -232,6 +232,6 @@ void ParserInterpreter::visitRuleStopState(atn::ATNState *p) {
|
|||
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);
|
||||
}
|
||||
|
|
|
@ -112,14 +112,13 @@ tree::TerminalNode *ParserRuleContext::getToken(int ttype, std::size_t i) {
|
|||
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) {
|
||||
if (dynamic_cast<tree::TerminalNode*>(o) != nullptr) {
|
||||
tree::TerminalNode *tnode = static_cast<tree::TerminalNode*>(o);
|
||||
Token *symbol = tnode->getSymbol();
|
||||
if (symbol->getType() == ttype) {
|
||||
j++;
|
||||
if (j == i) {
|
||||
if (j++ == i) {
|
||||
return tnode;
|
||||
}
|
||||
}
|
||||
|
@ -162,7 +161,7 @@ std::size_t ParserRuleContext::getChildCount() {
|
|||
return _children.size() > 0 ? _children.size() : 0;
|
||||
}
|
||||
|
||||
misc::Interval *ParserRuleContext::getSourceInterval() {
|
||||
misc::Interval ParserRuleContext::getSourceInterval() {
|
||||
if (start == nullptr || stop == nullptr) {
|
||||
return misc::Interval::INVALID;
|
||||
}
|
||||
|
|
|
@ -139,15 +139,14 @@ namespace runtime {
|
|||
|
||||
template<typename T>
|
||||
T* getChild(size_t i) {
|
||||
if (_children.empty() || i >= _children.size()) {
|
||||
if (_children.empty()) {
|
||||
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) {
|
||||
if (dynamic_cast<T *>(child) != nullptr) {
|
||||
j++;
|
||||
if (j == i) {
|
||||
if (j++ == i) {
|
||||
return dynamic_cast<T *>(child);
|
||||
}
|
||||
}
|
||||
|
@ -160,7 +159,7 @@ namespace runtime {
|
|||
virtual std::vector<tree::TerminalNode *> getTokens(int ttype);
|
||||
|
||||
template<typename T>
|
||||
T* getRuleContext(int i) {
|
||||
T* getRuleContext(size_t i) {
|
||||
return getChild<T>(i);
|
||||
}
|
||||
|
||||
|
@ -189,7 +188,7 @@ namespace runtime {
|
|||
}
|
||||
|
||||
virtual std::size_t getChildCount() override;
|
||||
virtual misc::Interval *getSourceInterval() override;
|
||||
virtual misc::Interval getSourceInterval() override;
|
||||
|
||||
virtual Token *getStart();
|
||||
virtual Token *getStop();
|
||||
|
|
|
@ -33,19 +33,22 @@
|
|||
|
||||
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) {
|
||||
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) {
|
||||
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) {
|
||||
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) {
|
||||
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
|
||||
|
|
|
@ -59,11 +59,11 @@ void RecognitionException::setOffendingState(int offendingState) {
|
|||
_offendingState = offendingState;
|
||||
}
|
||||
|
||||
misc::IntervalSet *RecognitionException::getExpectedTokens() {
|
||||
misc::IntervalSet RecognitionException::getExpectedTokens() {
|
||||
if (_recognizer != nullptr) {
|
||||
return _recognizer->getATN().getExpectedTokens(_offendingState, _ctx);
|
||||
}
|
||||
return nullptr;
|
||||
return misc::IntervalSet::EMPTY_SET;
|
||||
}
|
||||
|
||||
RuleContext *RecognitionException::getCtx() {
|
||||
|
|
|
@ -32,6 +32,7 @@
|
|||
#pragma once
|
||||
|
||||
#include "Exceptions.h"
|
||||
#include "IntervalSet.h"
|
||||
|
||||
namespace org {
|
||||
namespace antlr {
|
||||
|
@ -100,7 +101,7 @@ namespace runtime {
|
|||
/// <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>
|
||||
public:
|
||||
virtual misc::IntervalSet *getExpectedTokens();
|
||||
virtual misc::IntervalSet getExpectedTokens();
|
||||
|
||||
/// <summary>
|
||||
/// Gets the <seealso cref="RuleContext"/> at the time this exception was thrown.
|
||||
|
|
|
@ -64,7 +64,7 @@ bool RuleContext::isEmpty() {
|
|||
return invokingState == -1;
|
||||
}
|
||||
|
||||
misc::Interval *RuleContext::getSourceInterval() {
|
||||
misc::Interval RuleContext::getSourceInterval() {
|
||||
return misc::Interval::INVALID;
|
||||
}
|
||||
|
||||
|
@ -96,14 +96,14 @@ std::wstring RuleContext::getText() {
|
|||
}
|
||||
|
||||
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());
|
||||
}
|
||||
|
||||
return builder->toString();
|
||||
}
|
||||
|
||||
int RuleContext::getRuleIndex() {
|
||||
ssize_t RuleContext::getRuleIndex() const {
|
||||
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) {
|
||||
antlrcpp::StringBuilder *buf = new antlrcpp::StringBuilder();
|
||||
antlrcpp::StringBuilder buffer;
|
||||
RuleContext *p = this;
|
||||
buf->append(L"[");
|
||||
buffer.append(L"[");
|
||||
while (p != nullptr && p != stop) {
|
||||
if (ruleNames.empty()) {
|
||||
if (!p->isEmpty()) {
|
||||
buf->append(p->invokingState);
|
||||
buffer.append(p->invokingState);
|
||||
}
|
||||
} 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);
|
||||
buf->append(ruleName);
|
||||
std::wstring ruleName = (ruleIndex >= 0 && ruleIndex < (ssize_t)ruleNames.size()) ? ruleNames[(size_t)ruleIndex] : std::to_wstring(ruleIndex);
|
||||
buffer.append(ruleName);
|
||||
}
|
||||
|
||||
if (p->parent != nullptr && (ruleNames.size() > 0 || !p->parent->isEmpty())) {
|
||||
buf->append(L" ");
|
||||
buffer.append(L" ");
|
||||
}
|
||||
|
||||
p = p->parent;
|
||||
}
|
||||
|
||||
buf->append(L"]");
|
||||
buffer.append(L"]");
|
||||
|
||||
return buf->toString();
|
||||
return buffer.toString();
|
||||
}
|
||||
|
||||
std::wstring RuleContext::toString() {
|
||||
|
|
|
@ -87,14 +87,14 @@ namespace runtime {
|
|||
|
||||
// satisfy the ParseTree / SyntaxTree interface
|
||||
|
||||
virtual misc::Interval *getSourceInterval() override;
|
||||
virtual misc::Interval getSourceInterval() override;
|
||||
|
||||
virtual RuleContext *getRuleContext() override;
|
||||
virtual RuleContext *getParent() override;
|
||||
virtual void *getPayload() override;
|
||||
virtual std::wstring getText() override;
|
||||
|
||||
virtual int getRuleIndex();
|
||||
virtual ssize_t getRuleIndex() const;
|
||||
|
||||
virtual ParseTree *getChild(std::size_t i) override;
|
||||
|
||||
|
|
|
@ -33,9 +33,9 @@
|
|||
|
||||
using namespace org::antlr::v4::runtime;
|
||||
|
||||
const int Token::INVALID_TYPE;
|
||||
const int Token::EPSILON;
|
||||
const int Token::MIN_USER_TOKEN_TYPE;
|
||||
const int Token::_EOF;
|
||||
const int Token::DEFAULT_CHANNEL;
|
||||
const int Token::HIDDEN_CHANNEL;
|
||||
const size_t Token::INVALID_TYPE;
|
||||
const ssize_t Token::EPSILON;
|
||||
const size_t Token::MIN_USER_TOKEN_TYPE;
|
||||
const size_t Token::_EOF;
|
||||
const size_t Token::DEFAULT_CHANNEL;
|
||||
const size_t Token::HIDDEN_CHANNEL;
|
||||
|
|
|
@ -45,17 +45,17 @@ namespace runtime {
|
|||
/// </summary>
|
||||
class Token {
|
||||
public:
|
||||
static const int INVALID_TYPE = 0;
|
||||
static const size_t INVALID_TYPE = 0;
|
||||
|
||||
/// <summary>
|
||||
/// During lookahead operations, this "token" signifies we hit rule end ATN state
|
||||
/// and did not follow it despite needing to.
|
||||
/// </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
|
||||
virtual ~Token() {};
|
||||
|
@ -65,13 +65,13 @@ namespace runtime {
|
|||
/// on a particular "channel". The parser tunes to a particular channel
|
||||
/// so that whitespace etc... can go to the parser on a "hidden" channel.
|
||||
/// </summary>
|
||||
static const int DEFAULT_CHANNEL = 0;
|
||||
static const size_t DEFAULT_CHANNEL = 0;
|
||||
|
||||
/// <summary>
|
||||
/// Anything on different channel than DEFAULT_CHANNEL is not parsed
|
||||
/// by parser.
|
||||
/// </summary>
|
||||
static const int HIDDEN_CHANNEL = 1;
|
||||
static const size_t HIDDEN_CHANNEL = 1;
|
||||
|
||||
/// <summary>
|
||||
/// Get the text of the token.
|
||||
|
|
|
@ -69,7 +69,7 @@ namespace runtime {
|
|||
/// </summary>
|
||||
/// <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>
|
||||
virtual int getLine() = 0;
|
||||
virtual size_t getLine() const = 0;
|
||||
|
||||
/// <summary>
|
||||
/// Get the index into the current line for the current position in the input
|
||||
|
|
|
@ -53,7 +53,7 @@ namespace runtime {
|
|||
public:
|
||||
virtual ~TokenStream();
|
||||
|
||||
virtual Token *LT(int k) = 0;
|
||||
virtual Token *LT(ssize_t k) = 0;
|
||||
|
||||
/// <summary>
|
||||
/// 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="UnsupportedOperationException"> if the stream does not support
|
||||
/// retrieving the token at the specified index </exception>
|
||||
virtual Token *get(int index) = 0;
|
||||
virtual Token *get(size_t index) = 0;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the underlying <seealso cref="TokenSource"/> which provides tokens for this
|
||||
|
@ -100,7 +100,7 @@ namespace runtime {
|
|||
/// stream.
|
||||
/// </returns>
|
||||
/// <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>
|
||||
/// 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;
|
||||
|
||||
TokenStreamRewriter::RewriteOperation::RewriteOperation(TokenStreamRewriter *outerInstance, int index) : outerInstance(outerInstance) {
|
||||
TokenStreamRewriter::RewriteOperation::RewriteOperation(TokenStreamRewriter *outerInstance, size_t index) : outerInstance(outerInstance) {
|
||||
|
||||
InitializeInstanceFields();
|
||||
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();
|
||||
this->index = index;
|
||||
this->text = text;
|
||||
}
|
||||
|
||||
int TokenStreamRewriter::RewriteOperation::execute(std::wstring *buf) {
|
||||
size_t TokenStreamRewriter::RewriteOperation::execute(std::wstring *buf) {
|
||||
return index;
|
||||
}
|
||||
|
||||
|
@ -61,7 +61,7 @@ std::wstring TokenStreamRewriter::RewriteOperation::toString() {
|
|||
std::wstring opName = L"TokenStreamRewriter";
|
||||
size_t index = opName.find(L'$');
|
||||
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() {
|
||||
|
@ -69,10 +69,11 @@ void TokenStreamRewriter::RewriteOperation::InitializeInstanceFields() {
|
|||
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);
|
||||
if (outerInstance->tokens->get(index)->getType() != Token::_EOF) {
|
||||
buf->append(outerInstance->tokens->get(index)->getText());
|
||||
|
@ -80,13 +81,13 @@ int TokenStreamRewriter::InsertBeforeOp::execute(std::wstring *buf) {
|
|||
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();
|
||||
lastIndex = to;
|
||||
}
|
||||
|
||||
int TokenStreamRewriter::ReplaceOp::execute(std::wstring *buf) {
|
||||
size_t TokenStreamRewriter::ReplaceOp::execute(std::wstring *buf) {
|
||||
buf->append(text);
|
||||
return lastIndex + 1;
|
||||
}
|
||||
|
@ -135,15 +136,15 @@ void TokenStreamRewriter::insertAfter(Token *t, const std::wstring& 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);
|
||||
}
|
||||
|
||||
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)
|
||||
insertBefore(programName, index + 1, text);
|
||||
}
|
||||
|
@ -152,26 +153,26 @@ void TokenStreamRewriter::insertBefore(Token *t, const std::wstring& 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);
|
||||
}
|
||||
|
||||
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);
|
||||
std::vector<RewriteOperation*> rewrites = getProgram(programName);
|
||||
op->instructionIndex = (int)rewrites.size();
|
||||
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);
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
|
@ -183,9 +184,10 @@ void TokenStreamRewriter::replace(Token *from, Token *to, const std::wstring& te
|
|||
replace(DEFAULT_PROGRAM_NAME, from, to, text);
|
||||
}
|
||||
|
||||
void TokenStreamRewriter::replace(const std::wstring &programName, int from, int to, const std::wstring& text) {
|
||||
if (from > to || from < 0 || to < 0 || to >= (int)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")");
|
||||
void TokenStreamRewriter::replace(const std::wstring &programName, size_t from, size_t to, const std::wstring& text) {
|
||||
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")");
|
||||
}
|
||||
RewriteOperation *op = new ReplaceOp(this, from, to, text);
|
||||
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) {
|
||||
replace(programName, from->getTokenIndex(), to->getTokenIndex(), text);
|
||||
replace(programName, (size_t)from->getTokenIndex(), (size_t)to->getTokenIndex(), text);
|
||||
}
|
||||
|
||||
void TokenStreamRewriter::delete_Renamed(int index) {
|
||||
delete_Renamed(DEFAULT_PROGRAM_NAME, index, index);
|
||||
void TokenStreamRewriter::Delete(size_t index) {
|
||||
Delete(DEFAULT_PROGRAM_NAME, index, index);
|
||||
}
|
||||
|
||||
void TokenStreamRewriter::delete_Renamed(int from, int to) {
|
||||
delete_Renamed(DEFAULT_PROGRAM_NAME, from, to);
|
||||
void TokenStreamRewriter::Delete(size_t from, size_t to) {
|
||||
Delete(DEFAULT_PROGRAM_NAME, from, to);
|
||||
}
|
||||
|
||||
void TokenStreamRewriter::delete_Renamed(Token *indexT) {
|
||||
delete_Renamed(DEFAULT_PROGRAM_NAME, indexT, indexT);
|
||||
void TokenStreamRewriter::Delete(Token *indexT) {
|
||||
Delete(DEFAULT_PROGRAM_NAME, indexT, indexT);
|
||||
}
|
||||
|
||||
void TokenStreamRewriter::delete_Renamed(Token *from, Token *to) {
|
||||
delete_Renamed(DEFAULT_PROGRAM_NAME, from, to);
|
||||
void TokenStreamRewriter::Delete(Token *from, Token *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);
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
|
@ -254,14 +256,14 @@ std::wstring TokenStreamRewriter::getText() {
|
|||
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);
|
||||
}
|
||||
|
||||
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);
|
||||
int start = interval->a;
|
||||
int stop = interval->b;
|
||||
int start = interval.a;
|
||||
int stop = interval.b;
|
||||
|
||||
// ensure start/end are in range
|
||||
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()) {
|
||||
RewriteOperation *op = indexToOp->at((int)i);
|
||||
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) {
|
||||
// no operation at that index, just dump token
|
||||
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
|
||||
// should be included (they will be inserts).
|
||||
for (auto op : *indexToOp) {
|
||||
if (op.second->index >= (int)tokens->size() - 1) {
|
||||
if (op.second->index >= tokens->size() - 1) {
|
||||
buf.append(op.second->text);
|
||||
}
|
||||
}
|
||||
|
@ -327,29 +329,29 @@ std::unordered_map<int, TokenStreamRewriter::RewriteOperation*> *TokenStreamRewr
|
|||
ReplaceOp *rop = static_cast<ReplaceOp*>(op);
|
||||
// Wipe prior inserts within range
|
||||
InsertBeforeOp* type = nullptr;
|
||||
std::vector<InsertBeforeOp*> inserts = getKindOfOps(rewrites, type, (int)i);
|
||||
std::vector<InsertBeforeOp*> inserts = getKindOfOps(rewrites, type, i);
|
||||
for (auto iop : inserts) {
|
||||
if (iop->index == rop->index) {
|
||||
// E.g., insert before 2, delete 2..2; update replace
|
||||
// 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:
|
||||
delete rewrites[iop->instructionIndex];
|
||||
delete rewrites[(size_t)iop->instructionIndex];
|
||||
rop->text = iop->text + (!rop->text.empty() ? rop->text : L"");
|
||||
}
|
||||
else if (iop->index > rop->index && iop->index <= rop->lastIndex) {
|
||||
// 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:
|
||||
delete rewrites[iop->instructionIndex];
|
||||
delete rewrites[(size_t)iop->instructionIndex];
|
||||
}
|
||||
}
|
||||
// Drop any prior replaces contained within
|
||||
ReplaceOp* type2 = nullptr;
|
||||
std::vector<ReplaceOp*> prevReplaces = getKindOfOps(rewrites, type2, (int)i);
|
||||
std::vector<ReplaceOp*> prevReplaces = getKindOfOps(rewrites, type2, i);
|
||||
for (auto prevRop : prevReplaces) {
|
||||
if (prevRop->index >= rop->index && prevRop->lastIndex <= rop->lastIndex) {
|
||||
// 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:
|
||||
delete rewrites[prevRop->instructionIndex];
|
||||
delete rewrites[(size_t)prevRop->instructionIndex];
|
||||
continue;
|
||||
}
|
||||
// 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) {
|
||||
//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:
|
||||
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->lastIndex = std::max(prevRop->lastIndex, rop->lastIndex);
|
||||
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]);
|
||||
// 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) {
|
||||
if (prevIop->index == iop->index) { // combine objects
|
||||
// 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);
|
||||
// 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:
|
||||
delete rewrites[prevIop->instructionIndex];
|
||||
delete rewrites[(size_t)prevIop->instructionIndex];
|
||||
}
|
||||
}
|
||||
// look for replaces where iop.index is in range; error
|
||||
ReplaceOp *type = nullptr;
|
||||
std::vector<ReplaceOp*> prevReplaces = getKindOfOps(rewrites, type, (int)i);
|
||||
std::vector<ReplaceOp*> prevReplaces = getKindOfOps(rewrites, type, i);
|
||||
for (auto rop : prevReplaces) {
|
||||
if (iop->index == rop->index) {
|
||||
rop->text = catOpText(&iop->text, &rop->text);
|
||||
|
@ -415,7 +417,7 @@ std::unordered_map<int, TokenStreamRewriter::RewriteOperation*> *TokenStreamRewr
|
|||
if (op == nullptr) { // ignore deleted ops
|
||||
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?
|
||||
throw new ANTLRException(L"should only be one op per index");
|
||||
}
|
||||
|
|
|
@ -1,33 +1,33 @@
|
|||
/*
|
||||
* [The "BSD license"]
|
||||
* Copyright (c) 2016 Mike Lischke
|
||||
* Copyright (c) 2013 Terence Parr
|
||||
* Copyright (c) 2013 Dan McLaughlin
|
||||
* 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.
|
||||
*/
|
||||
* Copyright (c) 2013 Terence Parr
|
||||
* Copyright (c) 2013 Dan McLaughlin
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
|
@ -77,12 +77,12 @@ namespace runtime {
|
|||
/// TokenStreamRewriter rewriter = new TokenStreamRewriter(tokens);
|
||||
/// parser.startRule();
|
||||
///
|
||||
/// Then in the rules, you can execute (assuming rewriter is visible):
|
||||
/// Then in the rules, you can execute (assuming rewriter is visible):
|
||||
/// Token t,u;
|
||||
/// ...
|
||||
/// rewriter.insertAfter(t, "text to put after t");}
|
||||
/// rewriter.insertAfter(u, "text after u");}
|
||||
/// System.out.println(tokens.toString());
|
||||
/// rewriter.insertAfter(u, "text after u");}
|
||||
/// System.out.println(tokens.toString());
|
||||
///
|
||||
/// You can also have multiple "instruction streams" and get multiple
|
||||
/// rewrites from a single pass over the input. Just name the instruction
|
||||
|
@ -91,9 +91,9 @@ namespace runtime {
|
|||
/// same buffer:
|
||||
///
|
||||
/// tokens.insertAfter("pass1", t, "text to put after t");}
|
||||
/// tokens.insertAfter("pass2", u, "text after u");}
|
||||
/// System.out.println(tokens.toString("pass1"));
|
||||
/// System.out.println(tokens.toString("pass2"));
|
||||
/// tokens.insertAfter("pass2", u, "text after u");}
|
||||
/// System.out.println(tokens.toString("pass1"));
|
||||
/// System.out.println(tokens.toString("pass2"));
|
||||
///
|
||||
/// If you don't use named rewrite streams, a "default" stream is used as
|
||||
/// the first example shows.
|
||||
|
@ -102,59 +102,59 @@ namespace runtime {
|
|||
public:
|
||||
class RewriteOperation {
|
||||
private:
|
||||
TokenStreamRewriter *const outerInstance;
|
||||
TokenStreamRewriter *const outerInstance;
|
||||
|
||||
/// <summary>
|
||||
/// What index into rewrites List are we? </summary>
|
||||
public:
|
||||
virtual ~RewriteOperation() {};
|
||||
/// <summary>
|
||||
/// Token buffer index. </summary>
|
||||
int index;
|
||||
std::wstring text;
|
||||
/// <summary>
|
||||
/// What index into rewrites List are we? </summary>
|
||||
virtual ~RewriteOperation() {};
|
||||
/// <summary>
|
||||
/// Token buffer index. </summary>
|
||||
size_t index;
|
||||
std::wstring text;
|
||||
|
||||
RewriteOperation(TokenStreamRewriter *outerInstance, int index);
|
||||
RewriteOperation(TokenStreamRewriter *outerInstance, size_t index);
|
||||
|
||||
RewriteOperation(TokenStreamRewriter *outerInstance, int index, const std::wstring& text);
|
||||
/// <summary>
|
||||
/// Execute the rewrite operation by possibly adding to the buffer.
|
||||
/// Return the index of the next token to operate on.
|
||||
/// </summary>
|
||||
int instructionIndex;
|
||||
RewriteOperation(TokenStreamRewriter *outerInstance, size_t index, const std::wstring& text);
|
||||
/// <summary>
|
||||
/// Execute the rewrite operation by possibly adding to the buffer.
|
||||
/// Return the index of the next token to operate on.
|
||||
/// </summary>
|
||||
int instructionIndex;
|
||||
|
||||
virtual int execute(std::wstring *buf);
|
||||
virtual size_t execute(std::wstring *buf);
|
||||
|
||||
virtual std::wstring toString();
|
||||
virtual std::wstring toString();
|
||||
|
||||
private:
|
||||
void InitializeInstanceFields();
|
||||
void InitializeInstanceFields();
|
||||
};
|
||||
|
||||
public:
|
||||
class InsertBeforeOp : public RewriteOperation {
|
||||
private:
|
||||
TokenStreamRewriter *const outerInstance;
|
||||
TokenStreamRewriter *const outerInstance;
|
||||
|
||||
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:
|
||||
class ReplaceOp : public RewriteOperation {
|
||||
private:
|
||||
TokenStreamRewriter *const outerInstance;
|
||||
TokenStreamRewriter *const outerInstance;
|
||||
|
||||
public:
|
||||
int lastIndex;
|
||||
size_t lastIndex;
|
||||
|
||||
ReplaceOp(TokenStreamRewriter *outerInstance, int from, int to, const std::wstring& text);
|
||||
virtual int execute(std::wstring *buf) override;
|
||||
virtual std::wstring toString() override;
|
||||
ReplaceOp(TokenStreamRewriter *outerInstance, size_t from, size_t to, const std::wstring& text);
|
||||
virtual size_t execute(std::wstring *buf) override;
|
||||
virtual std::wstring toString() override;
|
||||
|
||||
private:
|
||||
void InitializeInstanceFields();
|
||||
void InitializeInstanceFields();
|
||||
};
|
||||
|
||||
public:
|
||||
|
@ -204,46 +204,29 @@ namespace runtime {
|
|||
/// <summary>
|
||||
/// Reset the program so that no instructions exist </summary>
|
||||
virtual void deleteProgram(const std::wstring &programName);
|
||||
|
||||
virtual void insertAfter(Token *t, const std::wstring& text);
|
||||
|
||||
virtual void insertAfter(int index, const std::wstring& text);
|
||||
|
||||
virtual void insertAfter(size_t 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, int index, const std::wstring& text);
|
||||
virtual void insertAfter(const std::wstring &programName, size_t index, const std::wstring& text);
|
||||
|
||||
virtual void insertBefore(Token *t, const std::wstring& text);
|
||||
|
||||
virtual void insertBefore(int index, const std::wstring& text);
|
||||
|
||||
virtual void insertBefore(size_t 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, size_t index, const std::wstring& text);
|
||||
|
||||
virtual void insertBefore(const std::wstring &programName, int index, 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(size_t index, const std::wstring& text);
|
||||
virtual void replace(size_t from, size_t to, 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(const std::wstring &programName, int from, int 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, Token *from, Token *to, const std::wstring& text);
|
||||
|
||||
virtual void delete_Renamed(int index);
|
||||
|
||||
virtual void delete_Renamed(int from, int to);
|
||||
|
||||
virtual void delete_Renamed(Token *indexT);
|
||||
|
||||
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 void Delete(size_t index);
|
||||
virtual void Delete(size_t from, size_t to);
|
||||
virtual void Delete(Token *indexT);
|
||||
virtual void Delete(Token *from, Token *to);
|
||||
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 int getLastRewriteTokenIndex();
|
||||
|
||||
|
@ -274,49 +257,49 @@ namespace runtime {
|
|||
/// insertBefore on the first token, you would get that insertion.
|
||||
/// The same is true if you do an insertAfter the stop token.
|
||||
/// </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>
|
||||
/// We need to combine operations and report invalid operations (like
|
||||
/// overlapping replaces that are not completed nested). Inserts to
|
||||
/// same index need to be combined etc... Here are the cases:
|
||||
///
|
||||
/// I.i.u I.j.v leave alone, nonoverlapping
|
||||
/// I.i.u I.i.v combine: Iivu
|
||||
/// I.i.u I.j.v leave alone, nonoverlapping
|
||||
/// I.i.u I.i.v combine: Iivu
|
||||
///
|
||||
/// R.i-j.u R.x-y.v | i-j in x-y delete first R
|
||||
/// R.i-j.u R.i-j.v delete first R
|
||||
/// R.i-j.u R.x-y.v | x-y in i-j ERROR
|
||||
/// R.i-j.u R.x-y.v | boundaries overlap ERROR
|
||||
/// R.i-j.u R.x-y.v | i-j in x-y delete first R
|
||||
/// R.i-j.u R.i-j.v delete first R
|
||||
/// R.i-j.u R.x-y.v | x-y in i-j ERROR
|
||||
/// R.i-j.u R.x-y.v | boundaries overlap ERROR
|
||||
///
|
||||
/// Delete special case of replace (text==null):
|
||||
/// D.i-j.u D.x-y.v | boundaries overlap combine to max(min)..max(right)
|
||||
/// D.i-j.u D.x-y.v | boundaries overlap combine to max(min)..max(right)
|
||||
///
|
||||
/// I.i.u R.x-y.v | i in (x+1)-y delete I (since insert before
|
||||
/// we're not deleting i)
|
||||
/// I.i.u R.x-y.v | i not in (x+1)-y leave alone, nonoverlapping
|
||||
/// R.x-y.v I.i.u | i in x-y ERROR
|
||||
/// R.x-y.v I.x.u R.x-y.uv (combine, delete I)
|
||||
/// R.x-y.v I.i.u | i not in x-y leave alone, nonoverlapping
|
||||
/// I.i.u R.x-y.v | i in (x+1)-y delete I (since insert before
|
||||
/// we're not deleting i)
|
||||
/// I.i.u R.x-y.v | i not in (x+1)-y leave alone, nonoverlapping
|
||||
/// R.x-y.v I.i.u | i in x-y ERROR
|
||||
/// R.x-y.v I.x.u R.x-y.uv (combine, delete I)
|
||||
/// R.x-y.v I.i.u | i not in x-y leave alone, nonoverlapping
|
||||
///
|
||||
/// I.i.u = insert u before op @ index i
|
||||
/// R.x-y.u = replace x-y indexed tokens with u
|
||||
///
|
||||
/// First we need to examine replaces. For any replace op:
|
||||
///
|
||||
/// 1. wipe out any insertions before op within that range.
|
||||
/// 2. Drop any replace op before that is contained completely within
|
||||
/// 1. wipe out any insertions before op within that range.
|
||||
/// 2. Drop any replace op before that is contained completely within
|
||||
/// that range.
|
||||
/// 3. Throw exception upon boundary overlap with any previous replace.
|
||||
/// 3. Throw exception upon boundary overlap with any previous replace.
|
||||
///
|
||||
/// Then we can deal with inserts:
|
||||
///
|
||||
/// 1. for any inserts to same index, combine even if not adjacent.
|
||||
/// 2. for any prior replace with same left boundary, combine this
|
||||
/// 1. for any inserts to same index, combine even if not adjacent.
|
||||
/// 2. for any prior replace with same left boundary, combine this
|
||||
/// insert with replace and delete this replace.
|
||||
/// 3. throw exception if index in same range as previous replace
|
||||
/// 3. throw exception if index in same range as previous replace
|
||||
///
|
||||
/// Don't actually delete; make op null in list. Easier to walk list.
|
||||
/// Later we can throw as we add to index -> op map.
|
||||
|
@ -336,9 +319,9 @@ namespace runtime {
|
|||
/// <summary>
|
||||
/// Get all operations before an index of a particular kind </summary>
|
||||
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*>();
|
||||
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]);
|
||||
if (op == nullptr) { // ignore deleted
|
||||
continue;
|
||||
|
|
|
@ -39,7 +39,7 @@ using namespace org::antlr::v4::runtime;
|
|||
UnbufferedCharStream::UnbufferedCharStream() {
|
||||
}
|
||||
|
||||
UnbufferedCharStream::UnbufferedCharStream(int bufferSize) {
|
||||
UnbufferedCharStream::UnbufferedCharStream(size_t bufferSize) {
|
||||
InitializeInstanceFields();
|
||||
n = 0;
|
||||
data = new wchar_t[bufferSize];
|
||||
|
@ -63,30 +63,31 @@ void UnbufferedCharStream::consume() {
|
|||
|
||||
if (p == n - 1 && numMarkers == 0) {
|
||||
n = 0;
|
||||
p = -1; // p++ will leave this at 0
|
||||
p = 0;
|
||||
lastCharBufferStart = lastChar;
|
||||
} else {
|
||||
p++;
|
||||
}
|
||||
|
||||
p++;
|
||||
currentCharIndex++;
|
||||
sync(1);
|
||||
}
|
||||
|
||||
void UnbufferedCharStream::sync(int want) {
|
||||
int need = (p + want - 1) - n + 1; // how many more elements we need?
|
||||
void UnbufferedCharStream::sync(size_t want) {
|
||||
size_t need = (p + want - 1) - n + 1; // how many more elements we need?
|
||||
if (need > 0) {
|
||||
fill(need);
|
||||
}
|
||||
}
|
||||
|
||||
int UnbufferedCharStream::fill(int n) {
|
||||
for (int i = 0; i < n; i++) {
|
||||
size_t UnbufferedCharStream::fill(size_t n) {
|
||||
for (size_t i = 0; i < n; i++) {
|
||||
if (this->n > 0 && data[this->n - 1] == static_cast<wchar_t>(IntStream::_EOF)) {
|
||||
return i;
|
||||
}
|
||||
|
||||
try {
|
||||
int c = nextChar();
|
||||
size_t c = nextChar();
|
||||
add(c);
|
||||
} catch (IOException ioe) {
|
||||
throw std::exception(ioe);
|
||||
|
@ -96,48 +97,48 @@ int UnbufferedCharStream::fill(int n) {
|
|||
return n;
|
||||
}
|
||||
|
||||
int UnbufferedCharStream::nextChar() {
|
||||
return input->get();
|
||||
size_t UnbufferedCharStream::nextChar() {
|
||||
return (size_t)input->get();
|
||||
}
|
||||
|
||||
void UnbufferedCharStream::add(int c) {
|
||||
if (n >= (int)data.size()) {
|
||||
void UnbufferedCharStream::add(size_t c) {
|
||||
if (n >= data.size()) {
|
||||
data.reserve(data.size()*2);
|
||||
}
|
||||
data[n++] = static_cast<wchar_t>(c);
|
||||
}
|
||||
|
||||
int UnbufferedCharStream::LA(int i) {
|
||||
size_t UnbufferedCharStream::LA(ssize_t i) {
|
||||
if (i == -1) { // special case
|
||||
return lastChar;
|
||||
return (size_t)lastChar;
|
||||
}
|
||||
sync(i);
|
||||
int index = p + i - 1;
|
||||
sync((size_t)i);
|
||||
ssize_t index = (ssize_t)p + i - 1;
|
||||
if (index < 0) {
|
||||
throw new IndexOutOfBoundsException();
|
||||
}
|
||||
if (index >= n) {
|
||||
if ((size_t)index >= n) {
|
||||
return IntStream::_EOF;
|
||||
}
|
||||
wchar_t c = data[index];
|
||||
if (c == static_cast<wchar_t>(IntStream::_EOF)) {
|
||||
size_t c = (size_t)data[(size_t)index];
|
||||
if (c == IntStream::_EOF) {
|
||||
return IntStream::_EOF;
|
||||
}
|
||||
return c;
|
||||
}
|
||||
|
||||
int UnbufferedCharStream::mark() {
|
||||
ssize_t UnbufferedCharStream::mark() {
|
||||
if (numMarkers == 0) {
|
||||
lastCharBufferStart = lastChar;
|
||||
}
|
||||
|
||||
int mark = -numMarkers - 1;
|
||||
ssize_t mark = -(ssize_t)numMarkers - 1;
|
||||
numMarkers++;
|
||||
return mark;
|
||||
}
|
||||
|
||||
void UnbufferedCharStream::release(int marker) {
|
||||
int expectedMark = -numMarkers;
|
||||
void UnbufferedCharStream::release(ssize_t marker) {
|
||||
ssize_t expectedMark = -(ssize_t)numMarkers;
|
||||
if (marker != expectedMark) {
|
||||
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;
|
||||
}
|
||||
|
||||
void UnbufferedCharStream::seek(int index) {
|
||||
void UnbufferedCharStream::seek(size_t index) {
|
||||
if (index == currentCharIndex) {
|
||||
return;
|
||||
}
|
||||
|
@ -166,14 +167,14 @@ void UnbufferedCharStream::seek(int index) {
|
|||
}
|
||||
|
||||
// index == to bufferStartIndex should set p to 0
|
||||
int i = index - getBufferStartIndex();
|
||||
ssize_t i = (ssize_t)index - (ssize_t)getBufferStartIndex();
|
||||
if (i < 0) {
|
||||
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));
|
||||
}
|
||||
|
||||
p = i;
|
||||
p = (size_t)i;
|
||||
currentCharIndex = index;
|
||||
if (p == 0) {
|
||||
lastChar = lastCharBufferStart;
|
||||
|
@ -190,27 +191,27 @@ std::string UnbufferedCharStream::getSourceName() {
|
|||
return name;
|
||||
}
|
||||
|
||||
std::wstring UnbufferedCharStream::getText(misc::Interval *interval) {
|
||||
if (interval->a < 0 || interval->b < interval->a - 1) {
|
||||
std::wstring UnbufferedCharStream::getText(const misc::Interval &interval) {
|
||||
if (interval.a < 0 || interval.b < interval.a - 1) {
|
||||
throw IllegalArgumentException(std::wstring(L"invalid interval"));
|
||||
}
|
||||
|
||||
int bufferStartIndex = getBufferStartIndex();
|
||||
size_t bufferStartIndex = getBufferStartIndex();
|
||||
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"));
|
||||
}
|
||||
}
|
||||
|
||||
if (interval->a < bufferStartIndex || 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));
|
||||
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));
|
||||
}
|
||||
// convert from absolute to local index
|
||||
int i = interval->a - bufferStartIndex;
|
||||
return std::wstring(data, i, interval->length());
|
||||
size_t i = (size_t)interval.a - bufferStartIndex;
|
||||
return std::wstring(data, i, (size_t)interval.length());
|
||||
}
|
||||
|
||||
int UnbufferedCharStream::getBufferStartIndex() {
|
||||
size_t UnbufferedCharStream::getBufferStartIndex() {
|
||||
return currentCharIndex - p;
|
||||
}
|
||||
|
||||
|
|
|
@ -58,7 +58,7 @@ namespace runtime {
|
|||
/// <p/>
|
||||
/// This is not the buffer capacity, that's {@code data.length}.
|
||||
/// </summary>
|
||||
int n;
|
||||
size_t n;
|
||||
|
||||
/// <summary>
|
||||
/// 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
|
||||
/// out of buffered characters.
|
||||
/// </summary>
|
||||
int p;
|
||||
size_t p;
|
||||
|
||||
/// <summary>
|
||||
/// 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 data[p]..data[n-1]} to {@code data[0]..data[(n-1)-p]}.
|
||||
/// </summary>
|
||||
int numMarkers;
|
||||
size_t numMarkers;
|
||||
|
||||
/// <summary>
|
||||
/// This is the {@code LA(-1)} character for the current position.
|
||||
/// </summary>
|
||||
int lastChar;
|
||||
wchar_t lastChar;
|
||||
|
||||
/// <summary>
|
||||
/// When {@code numMarkers > 0}, this is the {@code LA(-1)} character for the
|
||||
/// first character in <seealso cref="#data data"/>. Otherwise, this is unspecified.
|
||||
/// </summary>
|
||||
int lastCharBufferStart;
|
||||
wchar_t lastCharBufferStart;
|
||||
|
||||
/// <summary>
|
||||
/// 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
|
||||
/// reached.
|
||||
/// </summary>
|
||||
int currentCharIndex;
|
||||
size_t currentCharIndex;
|
||||
|
||||
std::ifstream *input;
|
||||
|
||||
|
@ -109,7 +109,7 @@ namespace runtime {
|
|||
|
||||
/// <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);
|
||||
|
@ -120,31 +120,31 @@ namespace runtime {
|
|||
virtual void consume() override;
|
||||
|
||||
/// <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
|
||||
/// the char index 'need' elements ahead. If we need 1 element,
|
||||
/// {@code (p+1-1)==p} must be less than {@code data.length}.
|
||||
/// </summary>
|
||||
protected:
|
||||
virtual void sync(int want);
|
||||
virtual void sync(size_t want);
|
||||
|
||||
/// <summary>
|
||||
/// 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},
|
||||
/// then EOF was reached before {@code n} characters could be added.
|
||||
/// </summary>
|
||||
virtual int fill(int n);
|
||||
virtual size_t fill(size_t n);
|
||||
|
||||
/// <summary>
|
||||
/// Override to provide different source of characters than
|
||||
/// <seealso cref="#input input"/>.
|
||||
/// </summary>
|
||||
virtual int nextChar();
|
||||
virtual size_t nextChar();
|
||||
|
||||
virtual void add(int c);
|
||||
virtual void add(size_t c);
|
||||
|
||||
public:
|
||||
virtual int LA(int i) override;
|
||||
virtual size_t LA(ssize_t i) override;
|
||||
|
||||
/// <summary>
|
||||
/// 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
|
||||
/// {@code release()} is called in the wrong order.
|
||||
/// </summary>
|
||||
virtual int mark() override;
|
||||
virtual ssize_t mark() override;
|
||||
|
||||
/// <summary>
|
||||
/// Decrement number of markers, resetting buffer if we hit 0. </summary>
|
||||
/// <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>
|
||||
/// Seek to absolute character index, which might not be in the current
|
||||
/// sliding window. Move {@code p} to {@code index-bufferStartIndex}.
|
||||
/// </summary>
|
||||
virtual void seek(int index) override;
|
||||
virtual void seek(size_t index) override;
|
||||
|
||||
virtual size_t size() override;
|
||||
|
||||
virtual std::string getSourceName() override;
|
||||
|
||||
virtual std::wstring getText(misc::Interval *interval) override;
|
||||
virtual std::wstring getText(const misc::Interval &interval) override;
|
||||
|
||||
protected:
|
||||
int getBufferStartIndex();
|
||||
size_t getBufferStartIndex();
|
||||
|
||||
private:
|
||||
void InitializeInstanceFields();
|
||||
|
|
|
@ -38,7 +38,6 @@ namespace antlr {
|
|||
namespace v4 {
|
||||
namespace runtime {
|
||||
|
||||
template<typename T>
|
||||
class UnbufferedTokenStream : public TokenStream {
|
||||
protected:
|
||||
TokenSource *tokenSource;
|
||||
|
|
|
@ -45,13 +45,10 @@ namespace antlr {
|
|||
namespace v4 {
|
||||
namespace runtime {
|
||||
|
||||
template <typename T>
|
||||
UnbufferedTokenStream<T>::UnbufferedTokenStream(TokenSource* tokenSource)
|
||||
{ //this(tokenSource, 256);
|
||||
UnbufferedTokenStream::UnbufferedTokenStream(TokenSource* tokenSource) : UnbufferedTokenStream(tokenSource, 256) {
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
UnbufferedTokenStream<T>::UnbufferedTokenStream(TokenSource* tokenSource, int bufferSize)
|
||||
UnbufferedTokenStream::UnbufferedTokenStream(TokenSource* tokenSource, int bufferSize)
|
||||
{
|
||||
InitializeInstanceFields();
|
||||
this->tokenSource = tokenSource;
|
||||
|
@ -60,8 +57,7 @@ namespace runtime {
|
|||
fill(1); // prime the pump
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
Token* UnbufferedTokenStream<T>::get(int i)
|
||||
Token* UnbufferedTokenStream::get(int i)
|
||||
{ // get absolute index
|
||||
int bufferStartIndex = getBufferStartIndex();
|
||||
if (i < bufferStartIndex || i >= bufferStartIndex + n) {
|
||||
|
@ -70,8 +66,7 @@ namespace runtime {
|
|||
return tokens[i - bufferStartIndex];
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
Token* UnbufferedTokenStream<T>::LT(int i)
|
||||
Token* UnbufferedTokenStream::LT(int i)
|
||||
{
|
||||
if (i == -1) {
|
||||
return lastToken;
|
||||
|
@ -91,38 +86,32 @@ namespace runtime {
|
|||
return tokens[index];
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
int UnbufferedTokenStream<T>::LA(int i)
|
||||
int UnbufferedTokenStream::LA(int i)
|
||||
{
|
||||
return LT(i)->getType();
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
TokenSource* UnbufferedTokenStream<T>::getTokenSource()
|
||||
TokenSource* UnbufferedTokenStream::getTokenSource()
|
||||
{
|
||||
return tokenSource;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
std::wstring UnbufferedTokenStream<T>::getText()
|
||||
std::wstring UnbufferedTokenStream::getText()
|
||||
{
|
||||
return L"";
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
std::wstring UnbufferedTokenStream<T>::getText(RuleContext* ctx)
|
||||
std::wstring UnbufferedTokenStream::getText(RuleContext* ctx)
|
||||
{
|
||||
return getText(ctx->getSourceInterval());
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
std::wstring UnbufferedTokenStream<T>::getText(Token* start, Token* stop)
|
||||
std::wstring UnbufferedTokenStream::getText(Token* start, Token* stop)
|
||||
{
|
||||
return getText(misc::Interval::of(start->getTokenIndex(), stop->getTokenIndex()));
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
void UnbufferedTokenStream<T>::consume()
|
||||
void UnbufferedTokenStream::consume()
|
||||
{
|
||||
if (LA(1) == Token::_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
|
||||
/// ahead. If we need 1 element, {@code (p+1-1)==p} must be less than {@code tokens.length}.
|
||||
/// </summary>
|
||||
template <typename T>
|
||||
void UnbufferedTokenStream<T>::sync(int want)
|
||||
void UnbufferedTokenStream::sync(int want)
|
||||
{
|
||||
int need = (p + want - 1) - n + 1; // how many more elements we need?
|
||||
if (need > 0) {
|
||||
|
@ -162,8 +150,7 @@ namespace runtime {
|
|||
/// 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.
|
||||
/// </summary>
|
||||
template <typename T>
|
||||
int UnbufferedTokenStream<T>::fill(int n)
|
||||
int UnbufferedTokenStream::fill(int n)
|
||||
{
|
||||
for (int i = 0; i < n; i++) {
|
||||
if (this->n > 0 && tokens[this->n - 1]->getType() == Token::_EOF) {
|
||||
|
@ -176,8 +163,8 @@ namespace runtime {
|
|||
|
||||
return n;
|
||||
}
|
||||
template <typename T>
|
||||
void UnbufferedTokenStream<T>::add(Token* t)
|
||||
|
||||
void UnbufferedTokenStream::add(Token* t)
|
||||
{
|
||||
if (n >= tokens.size()) {
|
||||
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
|
||||
/// {@code release()} is called in the wrong order.
|
||||
/// </summary>
|
||||
template <typename T>
|
||||
int UnbufferedTokenStream<T>::mark()
|
||||
int UnbufferedTokenStream::mark()
|
||||
{
|
||||
if (numMarkers == 0) {
|
||||
lastTokenBufferStart = lastToken;
|
||||
|
@ -210,7 +196,7 @@ namespace runtime {
|
|||
}
|
||||
|
||||
template <typename T>
|
||||
void UnbufferedTokenStream<T>::release(int marker)
|
||||
void UnbufferedTokenStream::release(int marker)
|
||||
{
|
||||
int expectedMark = -numMarkers;
|
||||
if (marker != expectedMark) {
|
||||
|
@ -230,14 +216,13 @@ namespace runtime {
|
|||
lastTokenBufferStart = lastToken;
|
||||
}
|
||||
}
|
||||
template <typename T>
|
||||
int UnbufferedTokenStream<T>::index()
|
||||
|
||||
int UnbufferedTokenStream::index()
|
||||
{
|
||||
return currentTokenIndex;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
void UnbufferedTokenStream<T>::seek(int index)
|
||||
void UnbufferedTokenStream::seek(int index)
|
||||
{ // seek to absolute index
|
||||
if (index == currentTokenIndex) {
|
||||
return;
|
||||
|
@ -267,20 +252,17 @@ namespace runtime {
|
|||
}
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
size_t UnbufferedTokenStream<T>::size()
|
||||
size_t UnbufferedTokenStream::size()
|
||||
{
|
||||
throw new UnsupportedOperationException(L"Unbuffered stream cannot know its size");
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
std::string UnbufferedTokenStream<T>::getSourceName()
|
||||
std::string UnbufferedTokenStream::getSourceName()
|
||||
{
|
||||
return tokenSource->getSourceName();
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
std::wstring UnbufferedTokenStream<T>::getText(misc::Interval* interval)
|
||||
std::wstring UnbufferedTokenStream::getText(misc::Interval* interval)
|
||||
{
|
||||
int bufferStartIndex = getBufferStartIndex();
|
||||
int bufferStopIndex = bufferStartIndex + tokens.size() - 1;
|
||||
|
@ -303,14 +285,12 @@ namespace runtime {
|
|||
return buf->toString();
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
int UnbufferedTokenStream<T>::getBufferStartIndex()
|
||||
int UnbufferedTokenStream::getBufferStartIndex()
|
||||
{
|
||||
return currentTokenIndex - p;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
void UnbufferedTokenStream<T>::InitializeInstanceFields()
|
||||
void UnbufferedTokenStream::InitializeInstanceFields()
|
||||
{
|
||||
n = 0;
|
||||
p = 0;
|
||||
|
|
|
@ -49,18 +49,17 @@ ATN::ATN() : ATN(ATNType::LEXER, 0) {
|
|||
ATN::ATN(ATNType grammarType, int maxTokenType) : grammarType(grammarType), maxTokenType(maxTokenType) {
|
||||
}
|
||||
|
||||
org::antlr::v4::runtime::misc::IntervalSet *ATN::nextTokens(ATNState *s, RuleContext *ctx) const {
|
||||
LL1Analyzer *anal = new LL1Analyzer(*this);
|
||||
misc::IntervalSet *next = anal->LOOK(s, ctx);
|
||||
return next;
|
||||
misc::IntervalSet ATN::nextTokens(ATNState *s, RuleContext *ctx) const {
|
||||
LL1Analyzer analyzer(*this);
|
||||
return analyzer.LOOK(s, ctx);
|
||||
|
||||
}
|
||||
|
||||
org::antlr::v4::runtime::misc::IntervalSet *ATN::nextTokens(ATNState *s) const {
|
||||
if (s->nextTokenWithinRule != nullptr) {
|
||||
return s->nextTokenWithinRule;
|
||||
misc::IntervalSet ATN::nextTokens(ATNState *s) const {
|
||||
if (s->nextTokenWithinRule.isEmpty()) {
|
||||
s->nextTokenWithinRule = nextTokens(s, nullptr);
|
||||
s->nextTokenWithinRule.setReadOnly(true);
|
||||
}
|
||||
s->nextTokenWithinRule = nextTokens(s, nullptr);
|
||||
s->nextTokenWithinRule->setReadonly(true);
|
||||
return s->nextTokenWithinRule;
|
||||
}
|
||||
|
||||
|
@ -71,12 +70,11 @@ void ATN::addState(ATNState *state) {
|
|||
}
|
||||
|
||||
states.push_back(state);
|
||||
|
||||
}
|
||||
|
||||
void ATN::removeState(ATNState *state) {
|
||||
delete states.at(state->stateNumber);// just free mem, don't shift states in list
|
||||
states.at(state->stateNumber) = nullptr;
|
||||
delete states.at((size_t)state->stateNumber);// just free mem, don't shift states in list
|
||||
states.at((size_t)state->stateNumber) = nullptr;
|
||||
}
|
||||
|
||||
int ATN::defineDecisionState(DecisionState *s) {
|
||||
|
@ -85,9 +83,9 @@ int ATN::defineDecisionState(DecisionState *s) {
|
|||
return s->decision;
|
||||
}
|
||||
|
||||
org::antlr::v4::runtime::atn::DecisionState *ATN::getDecisionState(int decision) const {
|
||||
DecisionState *ATN::getDecisionState(int decision) const {
|
||||
if (!decisionToState.empty()) {
|
||||
return decisionToState.at(decision);
|
||||
return decisionToState.at((size_t)decision);
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
@ -96,32 +94,32 @@ int ATN::getNumberOfDecisions() const {
|
|||
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()) {
|
||||
throw new IllegalArgumentException(L"Invalid state number.");
|
||||
}
|
||||
|
||||
RuleContext *ctx = context;
|
||||
ATNState *s = states.at(stateNumber);
|
||||
misc::IntervalSet *following = nextTokens(s);
|
||||
if (!following->contains(Token::EPSILON)) {
|
||||
ATNState *s = states.at((size_t)stateNumber);
|
||||
misc::IntervalSet following = nextTokens(s);
|
||||
if (!following.contains(Token::EPSILON)) {
|
||||
return following;
|
||||
}
|
||||
|
||||
misc::IntervalSet *expected = new misc::IntervalSet(0);
|
||||
expected->addAll(following);
|
||||
expected->remove(Token::EPSILON);
|
||||
while (ctx != nullptr && ctx->invokingState >= 0 && following->contains(Token::EPSILON)) {
|
||||
ATNState *invokingState = states.at(ctx->invokingState);
|
||||
misc::IntervalSet expected;
|
||||
expected.addAll(following);
|
||||
expected.remove(Token::EPSILON);
|
||||
while (ctx != nullptr && ctx->invokingState >= 0 && following.contains(Token::EPSILON)) {
|
||||
ATNState *invokingState = states.at((size_t)ctx->invokingState);
|
||||
RuleTransition *rt = static_cast<RuleTransition*>(invokingState->transition(0));
|
||||
following = nextTokens(rt->followState);
|
||||
expected->addAll(following);
|
||||
expected->remove(Token::EPSILON);
|
||||
expected.addAll(following);
|
||||
expected.remove(Token::EPSILON);
|
||||
ctx = ctx->parent;
|
||||
}
|
||||
|
||||
if (following->contains(Token::EPSILON)) {
|
||||
expected->add(Token::_EOF);
|
||||
if (following.contains(Token::EPSILON)) {
|
||||
expected.add(Token::_EOF);
|
||||
}
|
||||
|
||||
return expected;
|
||||
|
|
|
@ -102,14 +102,14 @@ namespace atn {
|
|||
/// the rule surrounding {@code s}. In other words, the set will be
|
||||
/// restricted to tokens reachable staying within {@code s}'s rule.
|
||||
/// </summary>
|
||||
virtual misc::IntervalSet *nextTokens(ATNState *s, RuleContext *ctx) const;
|
||||
virtual misc::IntervalSet nextTokens(ATNState *s, RuleContext *ctx) const;
|
||||
|
||||
/// <summary>
|
||||
/// 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
|
||||
/// rule.
|
||||
/// </summary>
|
||||
virtual misc::IntervalSet *nextTokens(ATNState *s) const;
|
||||
virtual misc::IntervalSet nextTokens(ATNState *s) const;
|
||||
|
||||
virtual void addState(ATNState *state);
|
||||
|
||||
|
@ -139,7 +139,7 @@ namespace atn {
|
|||
/// specified state in the specified context. </returns>
|
||||
/// <exception cref="IllegalArgumentException"> if the ATN does not contain a state with
|
||||
/// number {@code stateNumber} </exception>
|
||||
virtual misc::IntervalSet *getExpectedTokens(int stateNumber, RuleContext *context) const;
|
||||
virtual misc::IntervalSet getExpectedTokens(int stateNumber, RuleContext *context) const;
|
||||
};
|
||||
|
||||
} // namespace atn
|
||||
|
|
|
@ -74,11 +74,11 @@ ATNConfig::ATNConfig(ATNConfig *c, ATNState *state, PredictionContext *context,
|
|||
}
|
||||
|
||||
size_t ATNConfig::hashCode() const {
|
||||
int hashCode = misc::MurmurHash::initialize(7);
|
||||
hashCode = misc::MurmurHash::update(hashCode, state->stateNumber);
|
||||
hashCode = misc::MurmurHash::update(hashCode, alt);
|
||||
hashCode = misc::MurmurHash::update(hashCode, context);
|
||||
hashCode = misc::MurmurHash::update(hashCode, semanticContext);
|
||||
size_t hashCode = misc::MurmurHash::initialize(7);
|
||||
hashCode = misc::MurmurHash::update(hashCode, (size_t)state->stateNumber);
|
||||
hashCode = misc::MurmurHash::update(hashCode, (size_t)alt);
|
||||
hashCode = misc::MurmurHash::update(hashCode, (size_t)context);
|
||||
hashCode = misc::MurmurHash::update(hashCode, (size_t)semanticContext);
|
||||
hashCode = misc::MurmurHash::finish(hashCode, 4);
|
||||
return hashCode;
|
||||
}
|
||||
|
@ -86,7 +86,7 @@ size_t ATNConfig::hashCode() const {
|
|||
bool ATNConfig::operator == (const ATNConfig& other) const
|
||||
{
|
||||
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);
|
||||
}
|
||||
|
||||
|
|
|
@ -113,8 +113,8 @@ namespace atn {
|
|||
};
|
||||
|
||||
/// An ATN configuration is equal to another if both have
|
||||
/// the same state, they predict the same alternative, and
|
||||
/// syntactic/semantic contexts are the same.
|
||||
/// the same state, they predict the same alternative, and
|
||||
/// syntactic/semantic contexts are the same.
|
||||
bool operator == (const ATNConfig &other) const;
|
||||
|
||||
virtual std::wstring toString();
|
||||
|
|
|
@ -38,9 +38,9 @@
|
|||
using namespace org::antlr::v4::runtime::atn;
|
||||
|
||||
size_t SimpleATNConfigHasher::operator()(const ATNConfig &k) const {
|
||||
int hashCode = 7;
|
||||
hashCode = 31 * hashCode + k.state->stateNumber;
|
||||
hashCode = 31 * hashCode + k.alt;
|
||||
size_t hashCode = 7;
|
||||
hashCode = 31 * hashCode + (size_t)k.state->stateNumber;
|
||||
hashCode = 31 * hashCode + (size_t)k.alt;
|
||||
hashCode = 31 * hashCode + k.semanticContext->hashCode();
|
||||
return hashCode;
|
||||
}
|
||||
|
@ -90,7 +90,7 @@ bool ATNConfigSet::add(ATNConfig *config, misc::DoubleKeyMap<PredictionContext*,
|
|||
|
||||
ATNConfig *existing = configLookup->getOrAdd(config);
|
||||
if (existing == config) { // we added this new one
|
||||
_cachedHashCode = -1;
|
||||
_cachedHashCode = 0;
|
||||
configs.push_back(config); // track order here
|
||||
|
||||
return true;
|
||||
|
@ -135,7 +135,7 @@ std::vector<SemanticContext*> ATNConfigSet::getPredicates() {
|
|||
return preds;
|
||||
}
|
||||
|
||||
ATNConfig* ATNConfigSet::get(int i) {
|
||||
ATNConfig* ATNConfigSet::get(size_t i) const {
|
||||
return configs[i];
|
||||
}
|
||||
|
||||
|
@ -180,16 +180,16 @@ bool ATNConfigSet::equals(ATNConfigSet *other) {
|
|||
return same;
|
||||
}
|
||||
|
||||
int ATNConfigSet::hashCode() {
|
||||
size_t ATNConfigSet::hashCode() {
|
||||
if (isReadonly()) {
|
||||
if (_cachedHashCode == -1) {
|
||||
_cachedHashCode = (int)std::hash<std::vector<ATNConfig *>>()(configs);
|
||||
if (_cachedHashCode == 0) {
|
||||
_cachedHashCode = std::hash<std::vector<ATNConfig *>>()(configs);
|
||||
}
|
||||
|
||||
return _cachedHashCode;
|
||||
}
|
||||
|
||||
return (int)std::hash<std::vector<ATNConfig *>>()(configs);
|
||||
return std::hash<std::vector<ATNConfig *>>()(configs);
|
||||
}
|
||||
|
||||
size_t ATNConfigSet::size() {
|
||||
|
@ -213,7 +213,7 @@ void ATNConfigSet::clear() {
|
|||
throw new IllegalStateException(L"This set is readonly");
|
||||
}
|
||||
configs.clear();
|
||||
_cachedHashCode = -1;
|
||||
_cachedHashCode = 0;
|
||||
configLookup->clear();
|
||||
}
|
||||
|
||||
|
@ -229,7 +229,7 @@ void ATNConfigSet::setReadonly(bool readonly) {
|
|||
|
||||
std::wstring ATNConfigSet::toString() {
|
||||
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());
|
||||
}
|
||||
|
||||
|
@ -259,5 +259,5 @@ void ATNConfigSet::InitializeInstanceFields() {
|
|||
dipsIntoOuterContext = false;
|
||||
|
||||
_readonly = false;
|
||||
_cachedHashCode = -1;
|
||||
_cachedHashCode = 0;
|
||||
}
|
||||
|
|
|
@ -110,14 +110,14 @@ namespace atn {
|
|||
|
||||
virtual std::vector<SemanticContext*> getPredicates();
|
||||
|
||||
virtual ATNConfig *get(int i);
|
||||
virtual ATNConfig *get(size_t i) const;
|
||||
|
||||
virtual void optimizeConfigs(ATNSimulator *interpreter);
|
||||
|
||||
bool addAll(ATNConfigSet *other);
|
||||
|
||||
virtual bool equals(ATNConfigSet *other);
|
||||
virtual int hashCode();
|
||||
virtual size_t hashCode();
|
||||
virtual size_t size();
|
||||
virtual bool isEmpty();
|
||||
virtual bool contains(ATNConfig *o);
|
||||
|
@ -136,7 +136,7 @@ namespace atn {
|
|||
bool _readonly;
|
||||
|
||||
private:
|
||||
int _cachedHashCode;
|
||||
size_t _cachedHashCode;
|
||||
|
||||
void InitializeInstanceFields();
|
||||
};
|
||||
|
|
|
@ -67,7 +67,7 @@
|
|||
using namespace antlrcpp;
|
||||
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
|
||||
|
@ -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
|
||||
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) {
|
||||
pair.first->endState = (BlockEndState*)atn.states.at(pair.second);
|
||||
pair.first->endState = (BlockEndState*)atn.states[(size_t)pair.second];
|
||||
}
|
||||
|
||||
int numNonGreedyStates = data[p++];
|
||||
|
@ -175,30 +175,30 @@ ATN ATNDeserializer::deserialize(const std::wstring& input) {
|
|||
int stateNumber = data[p++];
|
||||
// The serialized ATN must be specifying the right states, so that the
|
||||
// cast below is correct.
|
||||
((DecisionState *)atn.states.at(stateNumber))->nonGreedy = true;
|
||||
((DecisionState *)atn.states[(size_t)stateNumber])->nonGreedy = true;
|
||||
}
|
||||
|
||||
if (supportsPrecedencePredicates) {
|
||||
int numPrecedenceStates = data[p++];
|
||||
for (int i = 0; i < numPrecedenceStates; i++) {
|
||||
int stateNumber = data[p++];
|
||||
((RuleStartState *)atn.states.at(stateNumber))->isPrecedenceRule = true;
|
||||
((RuleStartState *)atn.states[(size_t)stateNumber])->isPrecedenceRule = true;
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// RULES
|
||||
//
|
||||
int nrules = data[p++];
|
||||
size_t nrules = (size_t)data[p++];
|
||||
if (atn.grammarType == ATNType::LEXER) {
|
||||
atn.ruleToTokenType.resize(nrules);
|
||||
atn.ruleToActionIndex.resize(nrules);
|
||||
}
|
||||
|
||||
for (int i = 0; i < nrules; i++) {
|
||||
int s = data[p++];
|
||||
for (size_t i = 0; i < nrules; i++) {
|
||||
size_t s = (size_t)data[p++];
|
||||
// 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);
|
||||
if (atn.grammarType == ATNType::LEXER) {
|
||||
int tokenType = data[p++];
|
||||
|
@ -224,7 +224,7 @@ ATN ATNDeserializer::deserialize(const std::wstring& input) {
|
|||
|
||||
RuleStopState *stopState = static_cast<RuleStopState*>(state);
|
||||
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++];
|
||||
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]));
|
||||
}
|
||||
|
||||
//
|
||||
// SETS
|
||||
//
|
||||
std::vector<misc::IntervalSet*> sets;
|
||||
std::vector<misc::IntervalSet> sets;
|
||||
int nsets = data[p++];
|
||||
for (int i = 0; i < nsets; i++) {
|
||||
int nintervals = data[p];
|
||||
p++;
|
||||
misc::IntervalSet *set = new misc::IntervalSet();
|
||||
sets.push_back(set);
|
||||
misc::IntervalSet set;
|
||||
|
||||
bool containsEof = data[p++] != 0;
|
||||
if (containsEof) {
|
||||
set->add(-1);
|
||||
set.add(-1);
|
||||
}
|
||||
|
||||
for (int j = 0; j < nintervals; j++) {
|
||||
set->add(data[p], data[p + 1]);
|
||||
set.add(data[p], data[p + 1]);
|
||||
p += 2;
|
||||
}
|
||||
sets.push_back(set);
|
||||
}
|
||||
|
||||
//
|
||||
|
@ -270,14 +270,14 @@ ATN ATNDeserializer::deserialize(const std::wstring& input) {
|
|||
int arg2 = data[p + 4];
|
||||
int arg3 = data[p + 5];
|
||||
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);
|
||||
p += 6;
|
||||
}
|
||||
|
||||
// edges for rule stop states can be derived, so they aren't serialized
|
||||
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);
|
||||
if (!(dynamic_cast<RuleTransition*>(t) != nullptr)) {
|
||||
continue;
|
||||
|
@ -306,7 +306,7 @@ ATN ATNDeserializer::deserialize(const std::wstring& input) {
|
|||
|
||||
if (dynamic_cast<PlusLoopbackState*>(state) != nullptr) {
|
||||
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;
|
||||
if (dynamic_cast<PlusBlockStartState*>(target) != nullptr) {
|
||||
(static_cast<PlusBlockStartState*>(target))->loopBackState = loopbackState;
|
||||
|
@ -314,7 +314,7 @@ ATN ATNDeserializer::deserialize(const std::wstring& input) {
|
|||
}
|
||||
} else if (dynamic_cast<StarLoopbackState*>(state) != nullptr) {
|
||||
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;
|
||||
if (dynamic_cast<StarLoopEntryState*>(target) != nullptr) {
|
||||
(static_cast<StarLoopEntryState*>(target))->loopBackState = loopbackState;
|
||||
|
@ -326,13 +326,13 @@ ATN ATNDeserializer::deserialize(const std::wstring& input) {
|
|||
//
|
||||
// DECISIONS
|
||||
//
|
||||
int ndecisions = data[p++];
|
||||
for (int i = 1; i <= ndecisions; i++) {
|
||||
int s = data[p++];
|
||||
size_t ndecisions = (size_t)data[p++];
|
||||
for (size_t i = 1; i <= ndecisions; i++) {
|
||||
size_t s = (size_t)data[p++];
|
||||
DecisionState *decState = static_cast<DecisionState*>(atn.states[s]);
|
||||
// TODO: decisionToState was originally declared as const in ATN
|
||||
atn.decisionToState.push_back(decState);
|
||||
decState->decision = i - 1;
|
||||
decState->decision = (int)i - 1;
|
||||
}
|
||||
|
||||
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
|
||||
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);
|
||||
}
|
||||
|
||||
|
@ -507,8 +507,10 @@ Guid ATNDeserializer::toUUID(const wchar_t *data, int offset) {
|
|||
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) {
|
||||
ATNState *target = atn.states[trg];
|
||||
Transition *ATNDeserializer::edgeFactory(const ATN &atn, int type, int src, int trg, int arg1, int arg2, int arg3,
|
||||
const std::vector<misc::IntervalSet> &sets) {
|
||||
|
||||
ATNState *target = atn.states[(size_t)trg];
|
||||
switch (type) {
|
||||
case Transition::EPSILON :
|
||||
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);
|
||||
}
|
||||
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 :
|
||||
return new PredicateTransition(target, arg1, arg2, arg3 != 0);
|
||||
case Transition::PRECEDENCE:
|
||||
|
@ -533,9 +535,9 @@ Transition *ATNDeserializer::edgeFactory(const ATN &atn, int type, int src, int
|
|||
case Transition::ACTION :
|
||||
return new ActionTransition(target, arg1, arg2, arg3 != 0);
|
||||
case Transition::SET :
|
||||
return new SetTransition(target, sets[arg1]);
|
||||
return new SetTransition(target, sets[(size_t)arg1]);
|
||||
case Transition::NOT_SET :
|
||||
return new NotSetTransition(target, sets[arg1]);
|
||||
return new NotSetTransition(target, sets[(size_t)arg1]);
|
||||
case Transition::WILDCARD :
|
||||
return new WildcardTransition(target);
|
||||
}
|
||||
|
|
|
@ -41,7 +41,7 @@ namespace atn {
|
|||
|
||||
class ATNDeserializer {
|
||||
public:
|
||||
static const int SERIALIZED_VERSION;
|
||||
static const size_t SERIALIZED_VERSION;
|
||||
//static ATNDeserializer();
|
||||
|
||||
/// <summary>
|
||||
|
@ -108,7 +108,7 @@ namespace atn {
|
|||
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,
|
||||
std::vector<misc::IntervalSet*> &sets);
|
||||
const std::vector<misc::IntervalSet> &sets);
|
||||
|
||||
virtual ATNState *stateFactory(int type, int ruleIndex);
|
||||
|
||||
|
|
|
@ -73,13 +73,12 @@ std::vector<size_t>* ATNSerializer::serialize() {
|
|||
serializeUUID(data, ATNDeserializer::SERIALIZED_UUID);
|
||||
|
||||
// convert grammar type to ATN const to avoid dependence on ANTLRParser
|
||||
data->push_back(static_cast<int>(atn->grammarType));
|
||||
data->push_back(atn->maxTokenType);
|
||||
int nedges = 0;
|
||||
data->push_back((size_t)atn->grammarType);
|
||||
data->push_back((size_t)atn->maxTokenType);
|
||||
size_t nedges = 0;
|
||||
|
||||
std::unordered_map<misc::IntervalSet *, int> *setIndices =
|
||||
new std::unordered_map<misc::IntervalSet *, int>();
|
||||
std::vector<misc::IntervalSet *> sets = std::vector<misc::IntervalSet *>();
|
||||
std::unordered_map<misc::IntervalSet, int> setIndices;
|
||||
std::vector<misc::IntervalSet> sets;
|
||||
|
||||
// dump states, count edges and collect sets while doing so
|
||||
std::vector<int> nonGreedyStates;
|
||||
|
@ -102,20 +101,20 @@ std::vector<size_t>* ATNSerializer::serialize() {
|
|||
precedenceStates.push_back(s->stateNumber);
|
||||
}
|
||||
|
||||
data->push_back(stateType);
|
||||
data->push_back((size_t)stateType);
|
||||
|
||||
if (s->ruleIndex == -1) {
|
||||
data->push_back(WCHAR_MAX);
|
||||
}
|
||||
else {
|
||||
data->push_back(s->ruleIndex);
|
||||
data->push_back((size_t)s->ruleIndex);
|
||||
}
|
||||
|
||||
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) {
|
||||
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) {
|
||||
|
@ -124,14 +123,14 @@ std::vector<size_t>* ATNSerializer::serialize() {
|
|||
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);
|
||||
int edgeType = t->getSerializationType();
|
||||
if (edgeType == Transition::SET || edgeType == Transition::NOT_SET) {
|
||||
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);
|
||||
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
|
||||
data->push_back(nonGreedyStates.size());
|
||||
for (int i = 0; i < (int)nonGreedyStates.size(); i++) {
|
||||
data->push_back(nonGreedyStates.at(i));
|
||||
for (size_t i = 0; i < nonGreedyStates.size(); i++) {
|
||||
data->push_back((size_t)nonGreedyStates.at(i));
|
||||
}
|
||||
|
||||
// precedence states
|
||||
data->push_back(precedenceStates.size());
|
||||
for (int i = 0; i < (int)precedenceStates.size(); i++) {
|
||||
data->push_back(precedenceStates.at(i));
|
||||
for (size_t i = 0; i < precedenceStates.size(); i++) {
|
||||
data->push_back((size_t)precedenceStates.at(i));
|
||||
}
|
||||
|
||||
size_t nrules = atn->ruleToStartState.size();
|
||||
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];
|
||||
data->push_back(ruleStartState->stateNumber);
|
||||
data->push_back((size_t)ruleStartState->stateNumber);
|
||||
if (atn->grammarType == ATNType::LEXER) {
|
||||
if (atn->ruleToTokenType[r] == Token::_EOF) {
|
||||
data->push_back(WCHAR_MAX);
|
||||
}
|
||||
else {
|
||||
data->push_back(atn->ruleToTokenType[r]);
|
||||
data->push_back((size_t)atn->ruleToTokenType[r]);
|
||||
}
|
||||
|
||||
if (atn->ruleToActionIndex[r] == -1) {
|
||||
data->push_back(WCHAR_MAX);
|
||||
}
|
||||
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);
|
||||
if (nmodes > 0) {
|
||||
for (const auto &modeStartState : atn->modeToStartState) {
|
||||
data->push_back(modeStartState->stateNumber);
|
||||
data->push_back((size_t)modeStartState->stateNumber);
|
||||
}
|
||||
}
|
||||
|
||||
size_t nsets = sets.size();
|
||||
data->push_back(nsets);
|
||||
for (auto set : sets) {
|
||||
bool containsEof = set->contains(Token::_EOF);
|
||||
if (containsEof && set->getIntervals().at(0)->b == Token::_EOF) {
|
||||
data->push_back(set->getIntervals().size() - 1);
|
||||
bool containsEof = set.contains(Token::_EOF);
|
||||
if (containsEof && set.getIntervals().at(0).b == Token::_EOF) {
|
||||
data->push_back(set.getIntervals().size() - 1);
|
||||
}
|
||||
else {
|
||||
data->push_back(set->getIntervals().size());
|
||||
data->push_back(set.getIntervals().size());
|
||||
}
|
||||
|
||||
data->push_back(containsEof ? 1 : 0);
|
||||
for (misc::Interval *I : set->getIntervals()) {
|
||||
if (I->a == Token::_EOF) {
|
||||
if (I->b == Token::_EOF) {
|
||||
continue;
|
||||
}
|
||||
else {
|
||||
data->push_back(0);
|
||||
for (auto &interval : set.getIntervals()) {
|
||||
if (interval.a == Token::_EOF) {
|
||||
if (interval.b == Token::_EOF) {
|
||||
continue;
|
||||
} else {
|
||||
data->push_back(0);
|
||||
}
|
||||
}
|
||||
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;
|
||||
}
|
||||
|
||||
for (int i = 0; i < s->getNumberOfTransitions(); i++) {
|
||||
for (size_t i = 0; i < s->getNumberOfTransitions(); i++) {
|
||||
Transition *t = s->transition(i);
|
||||
|
||||
if (atn->states[t->target->stateNumber] == nullptr) {
|
||||
throw IllegalStateException(
|
||||
L"Cannot serialize a transition to a removed state.");
|
||||
if (atn->states[(size_t)t->target->stateNumber] == nullptr) {
|
||||
throw IllegalStateException(L"Cannot serialize a transition to a removed state.");
|
||||
}
|
||||
|
||||
int src = s->stateNumber;
|
||||
|
@ -285,37 +282,37 @@ std::vector<size_t>* ATNSerializer::serialize() {
|
|||
}
|
||||
break;
|
||||
case Transition::SET:
|
||||
arg1 = (*setIndices)[(static_cast<SetTransition *>(t))->set];
|
||||
arg1 = setIndices[(static_cast<SetTransition *>(t))->set];
|
||||
break;
|
||||
case Transition::NOT_SET:
|
||||
arg1 = (*setIndices)[(static_cast<SetTransition *>(t))->set];
|
||||
|
||||
case Transition::NOT_SET:
|
||||
arg1 = setIndices[(static_cast<SetTransition *>(t))->set];
|
||||
break;
|
||||
case Transition::WILDCARD:
|
||||
break;
|
||||
}
|
||||
|
||||
data->push_back(src);
|
||||
data->push_back(trg);
|
||||
data->push_back(edgeType);
|
||||
data->push_back(arg1);
|
||||
data->push_back(arg2);
|
||||
data->push_back(arg3);
|
||||
data->push_back((size_t)src);
|
||||
data->push_back((size_t)trg);
|
||||
data->push_back((size_t)edgeType);
|
||||
data->push_back((size_t)arg1);
|
||||
data->push_back((size_t)arg2);
|
||||
data->push_back((size_t)arg3);
|
||||
}
|
||||
}
|
||||
size_t ndecisions = atn->decisionToState.size();
|
||||
data->push_back(ndecisions);
|
||||
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
|
||||
for (int i = 1; i < (int)data->size(); i++) {
|
||||
if (data->at(i) < WCHAR_MIN || data->at(i) > WCHAR_MAX) {
|
||||
throw UnsupportedOperationException(
|
||||
L"Serialized ATN data element out of range.");
|
||||
for (size_t i = 1; i < data->size(); i++) {
|
||||
if ((wchar_t)data->at(i) < WCHAR_MIN || data->at(i) > WCHAR_MAX) {
|
||||
throw UnsupportedOperationException(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);
|
||||
}
|
||||
|
||||
|
@ -335,7 +332,7 @@ std::wstring ATNSerializer::decode(const std::wstring& inpdata) {
|
|||
|
||||
std::wstring buf;
|
||||
int p = 0;
|
||||
int version = data[p++];
|
||||
size_t version = (size_t)data[p++];
|
||||
if (version != ATNDeserializer::SERIALIZED_VERSION) {
|
||||
std::wstring reason =
|
||||
L"Could not deserialize ATN with version "
|
||||
|
@ -474,7 +471,7 @@ std::wstring ATNSerializer::decode(const std::wstring& inpdata) {
|
|||
.append(L"->")
|
||||
.append(std::to_wstring(trg))
|
||||
.append(L" ")
|
||||
.append(Transition::serializationNames[ttype])
|
||||
.append(Transition::serializationNames[(size_t)ttype])
|
||||
.append(L" ")
|
||||
.append(std::to_wstring(arg1))
|
||||
.append(L",")
|
||||
|
@ -492,7 +489,7 @@ std::wstring ATNSerializer::decode(const std::wstring& inpdata) {
|
|||
return buf;
|
||||
}
|
||||
|
||||
std::wstring ATNSerializer::getTokenName(int t) {
|
||||
std::wstring ATNSerializer::getTokenName(ssize_t t) {
|
||||
if (t == -1) {
|
||||
return L"EOF";
|
||||
}
|
||||
|
@ -515,21 +512,21 @@ std::wstring ATNSerializer::getTokenName(int t) {
|
|||
case L'\'':
|
||||
return L"'\\''";
|
||||
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" &&
|
||||
!iscntrl(t)) {
|
||||
!iscntrl((int)t)) {
|
||||
return L"'" + std::to_wstring(t) + L"'";
|
||||
}
|
||||
// turn on the bit above max "\uFFFF" value so that we pad with zeros
|
||||
// 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"'");
|
||||
return unicodeStr;
|
||||
}
|
||||
}
|
||||
|
||||
if (tokenNames.size() > 0 && t >= 0 && t < (int)tokenNames.size()) {
|
||||
return tokenNames[t];
|
||||
if (tokenNames.size() > 0 && t >= 0 && t < (ssize_t)tokenNames.size()) {
|
||||
return tokenNames[(size_t)t];
|
||||
}
|
||||
|
||||
return antlrcpp::StringConverterHelper::toString(t);
|
||||
|
|
|
@ -77,7 +77,7 @@ namespace atn {
|
|||
|
||||
virtual std::wstring decode(const std::wstring& data);
|
||||
|
||||
virtual std::wstring getTokenName(int t);
|
||||
virtual std::wstring getTokenName(ssize_t t);
|
||||
|
||||
/// <summary>
|
||||
/// 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);
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
|
|
|
@ -32,6 +32,7 @@
|
|||
#pragma once
|
||||
|
||||
#include "ATN.h"
|
||||
#include "IntervalSet.h"
|
||||
|
||||
namespace org {
|
||||
namespace antlr {
|
||||
|
@ -101,7 +102,8 @@ namespace atn {
|
|||
static void checkCondition(bool condition, const std::wstring &message);
|
||||
|
||||
/// @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.
|
||||
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"BLOCK_END", L"STAR_LOOP_BACK", L"STAR_LOOP_ENTRY", L"PLUS_LOOP_BACK", L"LOOP_END"};
|
||||
|
||||
int ATNState::hashCode() {
|
||||
return stateNumber;
|
||||
size_t ATNState::hashCode() {
|
||||
return (size_t)stateNumber;
|
||||
}
|
||||
|
||||
bool ATNState::equals(void *o) {
|
||||
|
@ -73,8 +73,8 @@ std::vector<Transition*> ATNState::getTransitions() {
|
|||
return arr;
|
||||
}
|
||||
|
||||
int ATNState::getNumberOfTransitions() {
|
||||
return (int)transitions.size();
|
||||
size_t ATNState::getNumberOfTransitions() {
|
||||
return transitions.size();
|
||||
}
|
||||
|
||||
void ATNState::addTransition(Transition *e) {
|
||||
|
@ -92,11 +92,11 @@ void ATNState::addTransition(int index, Transition *e) {
|
|||
transitions.insert(transitions.begin() + index, e);
|
||||
}
|
||||
|
||||
Transition *ATNState::transition(int i) {
|
||||
Transition *ATNState::transition(size_t i) {
|
||||
return transitions[i];
|
||||
}
|
||||
|
||||
void ATNState::setTransition(int i, Transition *e) {
|
||||
void ATNState::setTransition(size_t i, Transition *e) {
|
||||
transitions[i] = e;
|
||||
}
|
||||
|
||||
|
|
|
@ -31,6 +31,8 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include "IntervalSet.h"
|
||||
|
||||
namespace org {
|
||||
namespace antlr {
|
||||
namespace v4 {
|
||||
|
@ -141,9 +143,9 @@ namespace atn {
|
|||
/// <summary>
|
||||
/// Used to cache lookahead during parsing, not used during construction </summary>
|
||||
public:
|
||||
misc::IntervalSet *nextTokenWithinRule;
|
||||
misc::IntervalSet nextTokenWithinRule;
|
||||
|
||||
virtual int hashCode();
|
||||
virtual size_t hashCode();
|
||||
virtual bool equals(void *o);
|
||||
|
||||
virtual bool isNonGreedyExitState();
|
||||
|
@ -152,15 +154,15 @@ namespace atn {
|
|||
|
||||
virtual std::vector<Transition*> getTransitions();
|
||||
|
||||
virtual int getNumberOfTransitions();
|
||||
virtual size_t getNumberOfTransitions();
|
||||
|
||||
virtual void addTransition(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);
|
||||
|
||||
|
|
|
@ -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) {
|
||||
}
|
||||
|
||||
int ActionTransition::getSerializationType() {
|
||||
int ActionTransition::getSerializationType() const {
|
||||
return ACTION;
|
||||
}
|
||||
|
||||
bool ActionTransition::isEpsilon() {
|
||||
bool ActionTransition::isEpsilon() const {
|
||||
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;
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
|
|
@ -49,13 +49,13 @@ namespace atn {
|
|||
|
||||
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
|
||||
|
|
|
@ -30,62 +30,50 @@
|
|||
*/
|
||||
|
||||
#include "Arrays.h"
|
||||
#include "SingletonPredictionContext.h"
|
||||
|
||||
#include "ArrayPredictionContext.h"
|
||||
|
||||
using namespace org::antlr::v4::runtime::atn;
|
||||
|
||||
#ifdef TODO
|
||||
//the base class hash code is gettings set to 0 here, what do we want?
|
||||
stopffds
|
||||
#endif
|
||||
ArrayPredictionContext::ArrayPredictionContext(SingletonPredictionContext *a) : PredictionContext(0) {
|
||||
ArrayPredictionContext::ArrayPredictionContext(SingletonPredictionContext *a)
|
||||
: ArrayPredictionContext({ a->parent }, { a->returnState }) {
|
||||
}
|
||||
|
||||
ArrayPredictionContext::ArrayPredictionContext(std::PredictionContext *parents, int returnStates[]) : PredictionContext(calculateHashCode(parents, *returnStates))/*, parents(parents)*/, returnStates(*returnStates) {
|
||||
#ifdef TODO
|
||||
// assert(parents != nullptr && sizeof(parents) / sizeof(parents[0]) > 0);
|
||||
// assert(returnStates != nullptr && sizeof(returnStates) / sizeof(returnStates[0]) > 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(const std::vector<PredictionContext *> &parents, const std::vector<int> &returnStates)
|
||||
: PredictionContext(calculateHashCode(parents, returnStates)), parents(parents), returnStates(returnStates) {
|
||||
assert(parents.size() > 0);
|
||||
assert(returnStates.size() > 0);
|
||||
}
|
||||
ArrayPredictionContext::ArrayPredictionContext(std::vector<PredictionContext *>parents,
|
||||
const std::vector<int> returnStates) : PredictionContext(0) {
|
||||
throw new TODOException(L"ArrayPredictionContext::ArrayPredictionContext");
|
||||
}
|
||||
bool ArrayPredictionContext::isEmpty() {
|
||||
// since EMPTY_RETURN_STATE can only appear in the last position, we
|
||||
// don't need to verify that size==1
|
||||
|
||||
bool ArrayPredictionContext::isEmpty() const {
|
||||
// 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;
|
||||
}
|
||||
|
||||
int ArrayPredictionContext::size() {
|
||||
return (int)returnStates.size();
|
||||
size_t ArrayPredictionContext::size() const {
|
||||
return returnStates.size();
|
||||
}
|
||||
|
||||
PredictionContext *ArrayPredictionContext::getParent(int index) {
|
||||
return parents->at(index);
|
||||
PredictionContext* ArrayPredictionContext::getParent(size_t index) const {
|
||||
return parents[index];
|
||||
}
|
||||
|
||||
int ArrayPredictionContext::getReturnState(int index) {
|
||||
int ArrayPredictionContext::getReturnState(size_t index) const {
|
||||
return returnStates[index];
|
||||
}
|
||||
|
||||
bool ArrayPredictionContext::equals(void *o) {
|
||||
bool ArrayPredictionContext::operator == (PredictionContext *o) const {
|
||||
if (this == o) {
|
||||
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
|
||||
}
|
||||
|
||||
ArrayPredictionContext *a = static_cast<ArrayPredictionContext*>(o);
|
||||
return antlrcpp::Arrays::equals(returnStates, a->returnStates) && antlrcpp::Arrays::equals(&parents, &a->parents);
|
||||
return antlrcpp::Arrays::equals(returnStates, other->returnStates) && antlrcpp::Arrays::equals(parents, other->parents);
|
||||
}
|
||||
|
||||
std::wstring ArrayPredictionContext::toString() {
|
||||
|
@ -103,9 +91,9 @@ std::wstring ArrayPredictionContext::toString() {
|
|||
continue;
|
||||
}
|
||||
buf->append(std::to_wstring(returnStates.at(i)));
|
||||
if (parents->at(i) != nullptr) {
|
||||
if (parents[i] != nullptr) {
|
||||
buf->append(L" ");
|
||||
buf->append(parents->at(i)->toString());
|
||||
buf->append(parents[i]->toString());
|
||||
} else {
|
||||
buf->append(L"null");
|
||||
}
|
||||
|
|
|
@ -43,40 +43,23 @@ namespace atn {
|
|||
class SingletonPredictionContext;
|
||||
|
||||
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:
|
||||
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,
|
||||
/// <seealso cref="#EMPTY_RETURN_STATE"/> is always last.
|
||||
/// </summary>
|
||||
const std::vector<int> returnStates;
|
||||
/// Sorted for merge, no duplicates; if present, EMPTY_RETURN_STATE is always last.
|
||||
const std::vector<int> &returnStates;
|
||||
|
||||
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[]);
|
||||
ArrayPredictionContext(std::vector<PredictionContext *>parents,
|
||||
const std::vector<int> returnStates);
|
||||
|
||||
virtual bool isEmpty() 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 bool isEmpty() const override;
|
||||
virtual size_t size() const override;
|
||||
virtual PredictionContext *getParent(size_t index) const override;
|
||||
virtual int getReturnState(size_t index) const override;
|
||||
bool operator == (PredictionContext *o) const override;
|
||||
|
||||
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) {
|
||||
}
|
||||
|
||||
int AtomTransition::getSerializationType() {
|
||||
int AtomTransition::getSerializationType() const {
|
||||
return ATOM;
|
||||
}
|
||||
|
||||
IntervalSet *AtomTransition::label() {
|
||||
IntervalSet AtomTransition::label() const {
|
||||
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;
|
||||
}
|
||||
|
||||
std::wstring AtomTransition::toString() {
|
||||
std::wstring AtomTransition::toString() const {
|
||||
return antlrcpp::StringConverterHelper::toString(_label);
|
||||
}
|
||||
|
|
|
@ -49,12 +49,12 @@ namespace atn {
|
|||
|
||||
AtomTransition(ATNState *target, int label);
|
||||
|
||||
virtual int getSerializationType() override;
|
||||
virtual int getSerializationType() const override;
|
||||
|
||||
virtual misc::IntervalSet *label() override;
|
||||
virtual bool matches(int symbol, int minVocabSymbol, int maxVocabSymbol) override;
|
||||
virtual misc::IntervalSet label() const override;
|
||||
virtual bool matches(int symbol, int minVocabSymbol, int maxVocabSymbol) const override;
|
||||
|
||||
virtual std::wstring toString();
|
||||
virtual std::wstring toString() const;
|
||||
};
|
||||
|
||||
} // namespace atn
|
||||
|
|
|
@ -36,26 +36,26 @@ using namespace org::antlr::v4::runtime::atn;
|
|||
EmptyPredictionContext::EmptyPredictionContext() : SingletonPredictionContext(nullptr, EMPTY_RETURN_STATE) {
|
||||
}
|
||||
|
||||
bool EmptyPredictionContext::isEmpty() {
|
||||
bool EmptyPredictionContext::isEmpty() const {
|
||||
return true;
|
||||
}
|
||||
|
||||
int EmptyPredictionContext::size() {
|
||||
size_t EmptyPredictionContext::size() const {
|
||||
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;
|
||||
}
|
||||
|
||||
int EmptyPredictionContext::getReturnState(int index) {
|
||||
int EmptyPredictionContext::getReturnState(size_t index) const {
|
||||
return returnState;
|
||||
}
|
||||
|
||||
bool EmptyPredictionContext::equals(void *o) {
|
||||
bool EmptyPredictionContext::operator == (PredictionContext *o) const {
|
||||
return this == o;
|
||||
}
|
||||
|
||||
std::wstring EmptyPredictionContext::toString() {
|
||||
std::wstring EmptyPredictionContext::toString() const {
|
||||
return L"$";
|
||||
}
|
||||
|
|
|
@ -43,16 +43,13 @@ namespace atn {
|
|||
public:
|
||||
EmptyPredictionContext();
|
||||
|
||||
virtual bool isEmpty() override;
|
||||
virtual int size() override;
|
||||
virtual bool isEmpty() const 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 int getReturnState(int index) override;
|
||||
|
||||
virtual bool equals(void *o) override;
|
||||
|
||||
virtual std::wstring toString() override;
|
||||
virtual bool operator == (PredictionContext *o) const override;
|
||||
};
|
||||
|
||||
} // namespace atn
|
||||
|
|
|
@ -36,18 +36,18 @@ using namespace org::antlr::v4::runtime::atn;
|
|||
EpsilonTransition::EpsilonTransition(ATNState *target) : Transition(target) {
|
||||
}
|
||||
|
||||
int EpsilonTransition::getSerializationType() {
|
||||
int EpsilonTransition::getSerializationType() const {
|
||||
return EPSILON;
|
||||
}
|
||||
|
||||
bool EpsilonTransition::isEpsilon() {
|
||||
bool EpsilonTransition::isEpsilon() const {
|
||||
return true;
|
||||
}
|
||||
|
||||
bool EpsilonTransition::matches(int symbol, int minVocabSymbol, int maxVocabSymbol) {
|
||||
bool EpsilonTransition::matches(int symbol, int minVocabSymbol, int maxVocabSymbol) const {
|
||||
return false;
|
||||
}
|
||||
|
||||
std::wstring EpsilonTransition::toString() {
|
||||
std::wstring EpsilonTransition::toString() const {
|
||||
return L"epsilon";
|
||||
}
|
||||
|
|
|
@ -43,12 +43,12 @@ namespace atn {
|
|||
public:
|
||||
EpsilonTransition(ATNState *target);
|
||||
|
||||
virtual int getSerializationType() override;
|
||||
virtual int getSerializationType() const override;
|
||||
|
||||
virtual bool isEpsilon() override;
|
||||
virtual bool matches(int symbol, int minVocabSymbol, int maxVocabSymbol) override;
|
||||
virtual bool isEpsilon() const override;
|
||||
virtual bool matches(int symbol, int minVocabSymbol, int maxVocabSymbol) const override;
|
||||
|
||||
virtual std::wstring toString();
|
||||
virtual std::wstring toString() const;
|
||||
};
|
||||
|
||||
} // namespace atn
|
||||
|
|
|
@ -47,85 +47,85 @@ using namespace org::antlr::v4::runtime::atn;
|
|||
LL1Analyzer::LL1Analyzer(const ATN &atn) : _atn(atn) {
|
||||
}
|
||||
|
||||
std::vector<misc::IntervalSet*> LL1Analyzer::getDecisionLookahead(ATNState *s) {
|
||||
// System.out.println("LOOK("+s.stateNumber+")");
|
||||
std::vector<misc::IntervalSet*> look;
|
||||
std::vector<misc::IntervalSet> LL1Analyzer::getDecisionLookahead(ATNState *s) const {
|
||||
std::vector<misc::IntervalSet> look;
|
||||
|
||||
if (s == nullptr) {
|
||||
return look;
|
||||
}
|
||||
|
||||
// need s->getNumberOfTransitions()); of them
|
||||
for (int alt = 0; alt < s->getNumberOfTransitions(); alt++) {
|
||||
look[alt] = new misc::IntervalSet(0);
|
||||
std::set<ATNConfig*> *lookBusy = new std::set<ATNConfig*>();
|
||||
look.resize(s->getNumberOfTransitions()); // Fills all interval sets with defaults.
|
||||
for (size_t alt = 0; alt < s->getNumberOfTransitions(); alt++) {
|
||||
std::set<ATNConfig*> lookBusy;
|
||||
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);
|
||||
|
||||
// Wipe out lookahead for this alternative if we found nothing
|
||||
// or we had a predicate when we !seeThruPreds
|
||||
if (look[alt]->size() == 0 || look[alt]->contains(HIT_PRED)) {
|
||||
// TODO: memory managment, delete
|
||||
delete look[alt];
|
||||
if (look[alt].size() == 0 || look[alt].contains(HIT_PRED)) {
|
||||
look[alt].clear();
|
||||
}
|
||||
}
|
||||
return look;
|
||||
}
|
||||
|
||||
misc::IntervalSet *LL1Analyzer::LOOK(ATNState *s, RuleContext *ctx) {
|
||||
misc::IntervalSet LL1Analyzer::LOOK(ATNState *s, RuleContext *ctx) const {
|
||||
return LOOK(s, nullptr, ctx);
|
||||
}
|
||||
|
||||
misc::IntervalSet *LL1Analyzer::LOOK(ATNState *s, ATNState *stopState, RuleContext *ctx) {
|
||||
misc::IntervalSet *r = new misc::IntervalSet(0);
|
||||
misc::IntervalSet LL1Analyzer::LOOK(ATNState *s, ATNState *stopState, RuleContext *ctx) const {
|
||||
misc::IntervalSet r;
|
||||
bool seeThruPreds = true; // ignore preds; get all lookahead
|
||||
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;
|
||||
}
|
||||
|
||||
void LL1Analyzer::_LOOK(ATNState *s, ATNState *stopState, PredictionContext *ctx, misc::IntervalSet *look, std::set<ATNConfig*> *lookBusy, antlrcpp::BitSet *calledRuleStack, bool seeThruPreds, bool addEOF) {
|
||||
// System.out.println("_LOOK("+s.stateNumber+", ctx="+ctx);
|
||||
void LL1Analyzer::_LOOK(ATNState *s, ATNState *stopState, PredictionContext *ctx, misc::IntervalSet &look,
|
||||
std::set<ATNConfig*> &lookBusy, antlrcpp::BitSet *calledRuleStack, bool seeThruPreds, bool addEOF) const {
|
||||
ATNConfig *c = new ATNConfig(s, 0, ctx);
|
||||
|
||||
if (!lookBusy->insert(c).second) {
|
||||
if (!lookBusy.insert(c).second) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (s == stopState) {
|
||||
if (ctx == nullptr) {
|
||||
look->add(Token::EPSILON);
|
||||
look.add(Token::EPSILON);
|
||||
return;
|
||||
} else if (ctx->isEmpty() && addEOF) {
|
||||
look->add(Token::_EOF);
|
||||
look.add(Token::_EOF);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (dynamic_cast<RuleStopState*>(s) != nullptr) {
|
||||
if (ctx == nullptr) {
|
||||
look->add(Token::EPSILON);
|
||||
look.add(Token::EPSILON);
|
||||
return;
|
||||
} else if (ctx->isEmpty() && addEOF) {
|
||||
look->add(Token::_EOF);
|
||||
look.add(Token::_EOF);
|
||||
return;
|
||||
}
|
||||
|
||||
if (ctx != (PredictionContext*)PredictionContext::EMPTY) {
|
||||
// run thru all possible stack tops in ctx
|
||||
for (int i = 0; i < ctx->size(); i++) {
|
||||
ATNState *returnState = _atn.states[ctx->getReturnState(i)];
|
||||
for (size_t i = 0; i < ctx->size(); i++) {
|
||||
ATNState *returnState = _atn.states[(size_t)ctx->getReturnState(i)];
|
||||
// System.out.println("popping back to "+retState);
|
||||
|
||||
bool removed = calledRuleStack->data.test(returnState->ruleIndex);
|
||||
bool removed = calledRuleStack->data.test((size_t)returnState->ruleIndex);
|
||||
try {
|
||||
calledRuleStack->data[returnState->ruleIndex] = false;
|
||||
calledRuleStack->data[(size_t)returnState->ruleIndex] = false;
|
||||
_LOOK(returnState, stopState, ctx->getParent(i), look, lookBusy, calledRuleStack, seeThruPreds, addEOF);
|
||||
}
|
||||
catch(...) {
|
||||
// Just move to the next steps as a "finally" clause
|
||||
}
|
||||
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();
|
||||
for (int i = 0; i < n; i++) {
|
||||
size_t n = s->getNumberOfTransitions();
|
||||
for (size_t i = 0; i < n; i++) {
|
||||
Transition *t = s->transition(i);
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
PredictionContext *newContext = SingletonPredictionContext::create(ctx, (static_cast<RuleTransition*>(t))->followState->stateNumber);
|
||||
|
||||
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);
|
||||
}
|
||||
catch(...) {
|
||||
// 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) {
|
||||
if (seeThruPreds) {
|
||||
_LOOK(t->target, stopState, ctx, look, lookBusy, calledRuleStack, seeThruPreds, addEOF);
|
||||
} else {
|
||||
look->add(HIT_PRED);
|
||||
look.add(HIT_PRED);
|
||||
}
|
||||
} else if (t->isEpsilon()) {
|
||||
_LOOK(t->target, stopState, ctx, look, lookBusy, calledRuleStack, seeThruPreds, addEOF);
|
||||
} 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 {
|
||||
// System.out.println("adding "+ t);
|
||||
misc::IntervalSet *set = t->label();
|
||||
if (set != nullptr) {
|
||||
misc::IntervalSet set = t->label();
|
||||
if (!set.isEmpty()) {
|
||||
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>
|
||||
/// <param name="s"> the ATN state </param>
|
||||
/// <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>
|
||||
/// Compute set of tokens that can follow {@code s} in the ATN in the
|
||||
|
@ -78,7 +78,7 @@ namespace atn {
|
|||
/// </param>
|
||||
/// <returns> The set of tokens that can follow {@code s} in the ATN in the
|
||||
/// specified {@code ctx}. </returns>
|
||||
virtual misc::IntervalSet *LOOK(ATNState *s, RuleContext *ctx);
|
||||
virtual misc::IntervalSet LOOK(ATNState *s, RuleContext *ctx) const;
|
||||
|
||||
/// <summary>
|
||||
/// Compute set of tokens that can follow {@code s} in the ATN in the
|
||||
|
@ -97,7 +97,7 @@ namespace atn {
|
|||
/// </param>
|
||||
/// <returns> The set of tokens that can follow {@code s} in the ATN in the
|
||||
/// 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>
|
||||
/// 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}
|
||||
/// is {@code null}. </param>
|
||||
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
|
||||
|
|
|
@ -66,11 +66,11 @@ bool LexerATNConfig::hasPassedThroughNonGreedyDecision() {
|
|||
}
|
||||
|
||||
size_t LexerATNConfig::hashCode() const {
|
||||
int hashCode = misc::MurmurHash::initialize(7);
|
||||
hashCode = misc::MurmurHash::update(hashCode, state->stateNumber);
|
||||
hashCode = misc::MurmurHash::update(hashCode, alt);
|
||||
hashCode = misc::MurmurHash::update(hashCode, context);
|
||||
hashCode = misc::MurmurHash::update(hashCode, semanticContext);
|
||||
size_t hashCode = misc::MurmurHash::initialize(7);
|
||||
hashCode = misc::MurmurHash::update(hashCode, (size_t)state->stateNumber);
|
||||
hashCode = misc::MurmurHash::update(hashCode, (size_t)alt);
|
||||
hashCode = misc::MurmurHash::update(hashCode, (size_t)context);
|
||||
hashCode = misc::MurmurHash::update(hashCode, (size_t)semanticContext);
|
||||
hashCode = misc::MurmurHash::update(hashCode, passedThroughNonGreedyDecision ? 1 : 0);
|
||||
hashCode = misc::MurmurHash::finish(hashCode, 5);
|
||||
return hashCode;
|
||||
|
|
|
@ -56,6 +56,7 @@ void LexerATNSimulator::SimState::reset() {
|
|||
charPos = -1;
|
||||
// TODO: Memory Management - delete
|
||||
delete dfaState;
|
||||
dfaState = nullptr;
|
||||
}
|
||||
|
||||
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)
|
||||
: ATNSimulator(atn, sharedContextCache), recog(recog), _decisionToDFA(decisionToDFA), prevAccept(new SimState()) {
|
||||
: ATNSimulator(atn, sharedContextCache), _recog(recog), _decisionToDFA(decisionToDFA), prevAccept(new SimState()) {
|
||||
InitializeInstanceFields();
|
||||
}
|
||||
|
||||
void LexerATNSimulator::copyState(LexerATNSimulator *simulator) {
|
||||
this->charPositionInLine = simulator->charPositionInLine;
|
||||
this->line = simulator->line;
|
||||
this->mode = simulator->mode;
|
||||
this->startIndex = simulator->startIndex;
|
||||
_charPositionInLine = simulator->_charPositionInLine;
|
||||
_line = simulator->_line;
|
||||
_mode = simulator->_mode;
|
||||
_startIndex = simulator->_startIndex;
|
||||
}
|
||||
|
||||
int LexerATNSimulator::match(CharStream *input, int mode) {
|
||||
int LexerATNSimulator::match(CharStream *input, size_t mode) {
|
||||
match_calls++;
|
||||
this->mode = mode;
|
||||
int mark = input->mark();
|
||||
_mode = mode;
|
||||
ssize_t mark = input->mark();
|
||||
try {
|
||||
this->startIndex = input->index();
|
||||
this->prevAccept->reset();
|
||||
_startIndex = (int)input->index();
|
||||
prevAccept->reset();
|
||||
dfa::DFA *dfa = _decisionToDFA[mode];
|
||||
if (dfa->s0 == nullptr) {
|
||||
return matchATN(input);
|
||||
|
@ -105,20 +106,21 @@ int LexerATNSimulator::match(CharStream *input, int mode) {
|
|||
|
||||
void LexerATNSimulator::reset() {
|
||||
prevAccept->reset();
|
||||
startIndex = -1;
|
||||
line = 1;
|
||||
charPositionInLine = 0;
|
||||
mode = Lexer::DEFAULT_MODE;
|
||||
_startIndex = 0; // Originally -1, but that would require a signed type with many casts.
|
||||
// The initial value is never tested, so it doesn't matter which value is set here.
|
||||
_line = 1;
|
||||
_charPositionInLine = 0;
|
||||
_mode = Lexer::DEFAULT_MODE;
|
||||
}
|
||||
|
||||
int LexerATNSimulator::matchATN(CharStream *input) {
|
||||
ATNState *startState = (ATNState *)atn.modeToStartState.at(mode);
|
||||
ATNState *startState = (ATNState *)atn.modeToStartState.at(_mode);
|
||||
|
||||
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);
|
||||
bool suppressEdge = s0_closure->hasSemanticContext;
|
||||
|
@ -126,7 +128,7 @@ int LexerATNSimulator::matchATN(CharStream *input) {
|
|||
|
||||
dfa::DFAState *next = addDFAState(s0_closure);
|
||||
if (!suppressEdge) {
|
||||
_decisionToDFA[mode]->s0 = next;
|
||||
_decisionToDFA[_mode]->s0 = 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;
|
||||
}
|
||||
|
||||
int t = input->LA(1);
|
||||
size_t t = input->LA(1);
|
||||
dfa::DFAState *s = ds0; // s is current/from DFA state
|
||||
|
||||
while (true) { // while more work
|
||||
|
@ -196,8 +198,8 @@ int LexerATNSimulator::execATN(CharStream *input, dfa::DFAState *ds0) {
|
|||
return failOrAccept(prevAccept, input, s->configs, t);
|
||||
}
|
||||
|
||||
dfa::DFAState *LexerATNSimulator::getExistingTargetState(dfa::DFAState *s, int t) {
|
||||
if (s->edges.size() == 0 || t < MIN_DFA_EDGE || t > MAX_DFA_EDGE) {
|
||||
dfa::DFAState *LexerATNSimulator::getExistingTargetState(dfa::DFAState *s, size_t t) {
|
||||
if (s->edges.size() == 0 || /*t < MIN_DFA_EDGE ||*/ t > MAX_DFA_EDGE) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
|
@ -209,7 +211,7 @@ dfa::DFAState *LexerATNSimulator::getExistingTargetState(dfa::DFAState *s, int t
|
|||
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();
|
||||
|
||||
// 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);
|
||||
}
|
||||
|
||||
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) {
|
||||
int ruleIndex = prevAccept->dfaState->lexerRuleIndex;
|
||||
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;
|
||||
} else {
|
||||
// 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;
|
||||
}
|
||||
|
||||
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
|
||||
// than a config that already reached an accept state for the same rule
|
||||
int skipAlt = ATN::INVALID_ALT_NUMBER;
|
||||
|
@ -255,13 +257,13 @@ void LexerATNSimulator::getReachableConfigSet(CharStream *input, ATNConfigSet *c
|
|||
}
|
||||
|
||||
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();
|
||||
for (int ti = 0; ti < n; ti++) { // for each transition
|
||||
size_t n = c->state->getNumberOfTransitions();
|
||||
for (size_t ti = 0; ti < n; ti++) { // for each transition
|
||||
Transition *trans = c->state->transition(ti);
|
||||
ATNState *target = getReachableTarget(trans, t);
|
||||
ATNState *target = getReachableTarget(trans, (int)t);
|
||||
if (target != nullptr) {
|
||||
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
|
||||
|
@ -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) {
|
||||
std::wcout << L"ACTION ";
|
||||
if (recog != nullptr) {
|
||||
std::wcout << recog->getRuleNames()[ruleIndex];
|
||||
if (_recog != nullptr) {
|
||||
std::wcout << _recog->getRuleNames()[(size_t)ruleIndex];
|
||||
} else {
|
||||
std::wcout << ruleIndex;
|
||||
}
|
||||
std::wcout << ":" << actionIndex << std::endl;
|
||||
}
|
||||
|
||||
if (actionIndex >= 0 && recog != nullptr) {
|
||||
recog->action(nullptr, ruleIndex, actionIndex);
|
||||
if (actionIndex >= 0 && _recog != nullptr) {
|
||||
_recog->action(nullptr, ruleIndex, actionIndex);
|
||||
}
|
||||
|
||||
// seek to after last char in token
|
||||
input->seek(index);
|
||||
this->line = line;
|
||||
this->charPositionInLine = charPos;
|
||||
_line = line;
|
||||
_charPositionInLine = (int)charPos;
|
||||
if (input->LA(1) != IntStream::_EOF) {
|
||||
consume(input);
|
||||
}
|
||||
|
@ -309,9 +311,9 @@ atn::ATNState *LexerATNSimulator::getReachableTarget(Transition *trans, int t) {
|
|||
atn::ATNConfigSet *LexerATNSimulator::computeStartState(CharStream *input, ATNState *p) {
|
||||
EmptyPredictionContext * initialContext = PredictionContext::EMPTY;
|
||||
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;
|
||||
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);
|
||||
}
|
||||
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) {
|
||||
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 (debug) {
|
||||
if (recog != nullptr) {
|
||||
std::wcout << L"closure at " << recog->getRuleNames()[config->state->ruleIndex] << L" rule stop " << config << std::endl;
|
||||
if (_recog != nullptr) {
|
||||
std::wcout << L"closure at " << _recog->getRuleNames()[(size_t)config->state->ruleIndex] << L" rule stop " << config << std::endl;
|
||||
} else {
|
||||
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()) {
|
||||
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) {
|
||||
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);
|
||||
currentAltReachedAcceptState = closure(input, c, configs, currentAltReachedAcceptState, speculative);
|
||||
}
|
||||
|
@ -363,7 +365,7 @@ bool LexerATNSimulator::closure(CharStream *input, LexerATNConfig *config, ATNCo
|
|||
}
|
||||
|
||||
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);
|
||||
LexerATNConfig *c = getEpsilonTarget(input, config, t, configs, speculative);
|
||||
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) {
|
||||
// assume true if no recognizer was provided
|
||||
if (recog == nullptr) {
|
||||
if (_recog == nullptr) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!speculative) {
|
||||
return recog->sempred(nullptr, ruleIndex, predIndex);
|
||||
return _recog->sempred(nullptr, ruleIndex, predIndex);
|
||||
}
|
||||
|
||||
int savedCharPositionInLine = charPositionInLine;
|
||||
int savedLine = line;
|
||||
int index = input->index();
|
||||
int marker = input->mark();
|
||||
int savedCharPositionInLine = _charPositionInLine;
|
||||
size_t savedLine = _line;
|
||||
size_t index = input->index();
|
||||
ssize_t marker = input->mark();
|
||||
try {
|
||||
consume(input);
|
||||
return recog->sempred(nullptr, ruleIndex, predIndex);
|
||||
return _recog->sempred(nullptr, ruleIndex, predIndex);
|
||||
} catch(...) {
|
||||
charPositionInLine = savedCharPositionInLine;
|
||||
line = savedLine;
|
||||
_charPositionInLine = savedCharPositionInLine;
|
||||
_line = savedLine;
|
||||
input->seek(index);
|
||||
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) {
|
||||
settings->index = input->index();
|
||||
settings->line = line;
|
||||
settings->charPos = charPositionInLine;
|
||||
settings->index = (int)input->index();
|
||||
settings->line = _line;
|
||||
settings->charPos = _charPositionInLine;
|
||||
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
|
||||
* marker indicating dynamic predicate evaluation makes this edge
|
||||
* 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;
|
||||
}
|
||||
|
||||
void LexerATNSimulator::addDFAEdge(dfa::DFAState *p, int t, dfa::DFAState *q) {
|
||||
if (t < MIN_DFA_EDGE || t > MAX_DFA_EDGE) {
|
||||
void LexerATNSimulator::addDFAEdge(dfa::DFAState *p, size_t t, dfa::DFAState *q) {
|
||||
if (/*t < MIN_DFA_EDGE ||*/ t > MAX_DFA_EDGE) {
|
||||
// Only track edges within the DFA bounds
|
||||
return;
|
||||
}
|
||||
|
@ -528,10 +530,10 @@ dfa::DFAState *LexerATNSimulator::addDFAState(ATNConfigSet *configs) {
|
|||
proposed->isAcceptState = true;
|
||||
proposed->lexerRuleIndex = firstConfigWithRuleStopState->state->ruleIndex;
|
||||
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);
|
||||
|
@ -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];
|
||||
}
|
||||
|
||||
std::wstring LexerATNSimulator::getText(CharStream *input) {
|
||||
// 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() {
|
||||
return line;
|
||||
size_t LexerATNSimulator::getLine() const {
|
||||
return _line;
|
||||
}
|
||||
|
||||
void LexerATNSimulator::setLine(int line) {
|
||||
this->line = line;
|
||||
void LexerATNSimulator::setLine(size_t line) {
|
||||
_line = line;
|
||||
}
|
||||
|
||||
int LexerATNSimulator::getCharPositionInLine() {
|
||||
return charPositionInLine;
|
||||
return _charPositionInLine;
|
||||
}
|
||||
|
||||
void LexerATNSimulator::setCharPositionInLine(int charPositionInLine) {
|
||||
this->charPositionInLine = charPositionInLine;
|
||||
_charPositionInLine = charPositionInLine;
|
||||
}
|
||||
|
||||
void LexerATNSimulator::consume(CharStream *input) {
|
||||
int curChar = input->LA(1);
|
||||
size_t curChar = input->LA(1);
|
||||
if (curChar == L'\n') {
|
||||
line++;
|
||||
charPositionInLine = 0;
|
||||
_line++;
|
||||
_charPositionInLine = 0;
|
||||
} else {
|
||||
charPositionInLine++;
|
||||
_charPositionInLine++;
|
||||
}
|
||||
input->consume();
|
||||
}
|
||||
|
@ -596,8 +598,8 @@ std::wstring LexerATNSimulator::getTokenName(int t) {
|
|||
}
|
||||
|
||||
void LexerATNSimulator::InitializeInstanceFields() {
|
||||
startIndex = -1;
|
||||
line = 1;
|
||||
charPositionInLine = 0;
|
||||
mode = org::antlr::v4::runtime::Lexer::DEFAULT_MODE;
|
||||
_startIndex = -1;
|
||||
_line = 1;
|
||||
_charPositionInLine = 0;
|
||||
_mode = org::antlr::v4::runtime::Lexer::DEFAULT_MODE;
|
||||
}
|
||||
|
|
|
@ -46,7 +46,7 @@ namespace atn {
|
|||
class SimState {
|
||||
protected:
|
||||
int index;
|
||||
int line;
|
||||
size_t line;
|
||||
int charPos;
|
||||
dfa::DFAState *dfaState;
|
||||
virtual void reset();
|
||||
|
@ -86,7 +86,7 @@ namespace atn {
|
|||
/// can simply return the predicted token type.
|
||||
/// </summary>
|
||||
protected:
|
||||
Lexer *const recog;
|
||||
Lexer *const _recog;
|
||||
|
||||
/// <summary>
|
||||
/// 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
|
||||
/// ATN-generated exception object.
|
||||
/// </summary>
|
||||
int startIndex;
|
||||
int _startIndex;
|
||||
|
||||
/// <summary>
|
||||
/// line number 1..n within the input </summary>
|
||||
int line;
|
||||
size_t _line;
|
||||
|
||||
/// <summary>
|
||||
/// The index of the character relative to the beginning of the line 0..n-1 </summary>
|
||||
int charPositionInLine;
|
||||
int _charPositionInLine;
|
||||
|
||||
public:
|
||||
const std::vector<dfa::DFA*> _decisionToDFA;
|
||||
protected:
|
||||
int mode;
|
||||
size_t _mode;
|
||||
|
||||
/// <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 int match(CharStream *input, int mode);
|
||||
virtual int match(CharStream *input, size_t mode);
|
||||
|
||||
virtual void reset() override;
|
||||
|
||||
|
@ -140,7 +140,7 @@ namespace atn {
|
|||
/// <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
|
||||
/// already cached </returns>
|
||||
virtual dfa::DFAState *getExistingTargetState(dfa::DFAState *s, int t);
|
||||
virtual dfa::DFAState *getExistingTargetState(dfa::DFAState *s, size_t t);
|
||||
|
||||
/// <summary>
|
||||
/// 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
|
||||
/// {@code t}. If {@code t} does not lead to a valid DFA state, this method
|
||||
/// 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>
|
||||
/// Given a starting configuration set, figure out all ATN configurations
|
||||
/// we can reach upon input {@code t}. Parameter {@code reach} is a return
|
||||
/// parameter.
|
||||
/// </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);
|
||||
|
||||
|
@ -208,9 +208,9 @@ namespace atn {
|
|||
|
||||
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>
|
||||
/// 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);
|
||||
|
||||
public:
|
||||
dfa::DFA *getDFA(int mode);
|
||||
dfa::DFA *getDFA(size_t mode);
|
||||
|
||||
/// <summary>
|
||||
/// Get the text matched so far for the current token.
|
||||
/// </summary>
|
||||
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();
|
||||
|
||||
|
|
|
@ -35,17 +35,17 @@
|
|||
|
||||
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;
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
std::wstring NotSetTransition::toString() {
|
||||
std::wstring NotSetTransition::toString() const {
|
||||
return L'~' + SetTransition::toString();
|
||||
}
|
||||
|
|
|
@ -41,13 +41,13 @@ namespace atn {
|
|||
|
||||
class NotSetTransition final : public SetTransition {
|
||||
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
|
||||
|
|
|
@ -61,6 +61,8 @@
|
|||
using namespace org::antlr::v4::runtime;
|
||||
using namespace org::antlr::v4::runtime::atn;
|
||||
|
||||
using namespace antlrcpp;
|
||||
|
||||
ParserATNSimulator::ParserATNSimulator(const ATN &atn, const std::vector<dfa::DFA *>& decisionToDFA,
|
||||
PredictionContextCache *sharedContextCache)
|
||||
: ParserATNSimulator(nullptr, atn, decisionToDFA, sharedContextCache) {
|
||||
|
@ -81,12 +83,12 @@ int ParserATNSimulator::adaptivePredict(TokenStream *input, int decision, Parser
|
|||
}
|
||||
|
||||
_input = input;
|
||||
_startIndex = input->index();
|
||||
_startIndex = (int)input->index();
|
||||
_outerContext = outerContext;
|
||||
dfa::DFA *dfa = _decisionToDFA[decision];
|
||||
dfa::DFA *dfa = _decisionToDFA[(size_t)decision];
|
||||
|
||||
int m = input->mark();
|
||||
int index = input->index();
|
||||
ssize_t m = input->mark();
|
||||
size_t index = input->index();
|
||||
|
||||
// Now we are certain to have a specific decision's DFA
|
||||
// But, do we still need an initial state?
|
||||
|
@ -122,7 +124,8 @@ int ParserATNSimulator::adaptivePredict(TokenStream *input, int decision, Parser
|
|||
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) {
|
||||
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;
|
||||
}
|
||||
|
||||
int t = input->LA(1);
|
||||
size_t t = input->LA(1);
|
||||
|
||||
while (true) { // while more work
|
||||
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 PREDS, MIGHT RESOLVE TO SINGLE ALT => SLL (or syntax error)
|
||||
antlrcpp::BitSet *conflictingAlts = nullptr;
|
||||
BitSet *conflictingAlts = nullptr;
|
||||
if (D->predicates.size() != 0) {
|
||||
if (debug) {
|
||||
std::wcout << L"DFA state has preds in DFA sim LL failover" << std::endl;
|
||||
}
|
||||
int conflictIndex = input->index();
|
||||
if (conflictIndex != startIndex) {
|
||||
input->seek(startIndex);
|
||||
size_t conflictIndex = input->index();
|
||||
if (conflictIndex != (size_t)startIndex) {
|
||||
input->seek((size_t)startIndex);
|
||||
}
|
||||
|
||||
conflictingAlts = evalSemanticContext(D->predicates, outerContext, true);
|
||||
|
@ -202,9 +205,9 @@ int ParserATNSimulator::execATN(dfa::DFA *dfa, dfa::DFAState *s0, TokenStream *i
|
|||
return D->prediction;
|
||||
}
|
||||
|
||||
int stopIndex = input->index();
|
||||
size_t stopIndex = input->index();
|
||||
input->seek(startIndex);
|
||||
antlrcpp::BitSet *alts = evalSemanticContext(D->predicates, outerContext, true);
|
||||
BitSet *alts = evalSemanticContext(D->predicates, outerContext, true);
|
||||
switch (alts->count()) {
|
||||
case 0:
|
||||
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) {
|
||||
std::vector<dfa::DFAState *>edges = previousD->edges;
|
||||
if (edges.size() == 0 || t + 1 < 0 || t + 1 >= (int)edges.size()) {
|
||||
dfa::DFAState *ParserATNSimulator::getExistingTargetState(dfa::DFAState *previousD, size_t t) {
|
||||
std::vector<dfa::DFAState *> edges = previousD->edges;
|
||||
if (edges.size() == 0 || /*t + 1 < 0 ||*/ t + 1 >= edges.size()) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
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);
|
||||
if (reach == nullptr) {
|
||||
addDFAEdge(dfa, previousD, t, &ERROR);
|
||||
|
@ -252,8 +255,8 @@ dfa::DFAState *ParserATNSimulator::computeTargetState(dfa::DFA *dfa, dfa::DFASta
|
|||
|
||||
if (debug) {
|
||||
|
||||
std::vector<antlrcpp::BitSet> altSubSets = PredictionModeClass::getConflictingAltSubsets(reach);
|
||||
std::wstring altSubSetsStr = antlrcpp::BitSet::subStringRepresentation(altSubSets.begin(), altSubSets.end());
|
||||
std::vector<BitSet> altSubSets = PredictionModeClass::getConflictingAltSubsets(reach);
|
||||
std::wstring altSubSetsStr = BitSet::subStringRepresentation(altSubSets.begin(), altSubSets.end());
|
||||
std::wcout << L"SLL altSubSets=" << altSubSetsStr << L", configs="
|
||||
<< reach << L", predict=" << predictedAlt << L", allSubsetsConflict="
|
||||
<< PredictionModeClass::allSubsetsConflict(altSubSets)
|
||||
|
@ -290,10 +293,11 @@ dfa::DFAState *ParserATNSimulator::computeTargetState(dfa::DFA *dfa, dfa::DFASta
|
|||
void ParserATNSimulator::predicateDFAState(dfa::DFAState *dfaState, DecisionState *decisionState) {
|
||||
// We need to test all predicates, even in DFA states that
|
||||
// uniquely predict alternative.
|
||||
int nalts = decisionState->getNumberOfTransitions();
|
||||
size_t nalts = decisionState->getNumberOfTransitions();
|
||||
|
||||
// Update DFA so reach becomes accept state with (predicate,alt)
|
||||
// pairs if preds found for conflicting alts
|
||||
antlrcpp::BitSet *altsToCollectPredsFrom = nullptr;
|
||||
BitSet *altsToCollectPredsFrom = nullptr;
|
||||
altsToCollectPredsFrom->data = getConflictingAltsOrUniqueAlt(dfaState->configs).data;
|
||||
std::vector<SemanticContext*> altToPred = getPredsForAmbigAlts(altsToCollectPredsFrom, dfaState->configs, nalts);
|
||||
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) {
|
||||
std::cout << "execATNWithFullContext " << s0 << std::endl;
|
||||
}
|
||||
|
@ -316,12 +321,9 @@ int ParserATNSimulator::execATNWithFullContext(dfa::DFA *dfa, dfa::DFAState *D,
|
|||
ATNConfigSet *reach = nullptr;
|
||||
ATNConfigSet *previous = s0;
|
||||
input->seek(startIndex);
|
||||
int t = input->LA(1);
|
||||
size_t t = input->LA(1);
|
||||
int predictedAlt;
|
||||
while (true) { // while more work
|
||||
// System.out.println("LL REACH "+getLookaheadName(input)+
|
||||
// " from configs.size="+previous.size()+
|
||||
// " line "+input.LT(1).getLine()+":"+input.LT(1).getCharPositionInLine());
|
||||
while (true) {
|
||||
reach = computeReachSet(previous, t, fullCtx);
|
||||
if (reach == nullptr) {
|
||||
// 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);
|
||||
}
|
||||
|
||||
std::vector<antlrcpp::BitSet> altSubSets =PredictionModeClass::getConflictingAltSubsets(reach);
|
||||
std::vector<BitSet> altSubSets =PredictionModeClass::getConflictingAltSubsets(reach);
|
||||
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="
|
||||
<< PredictionModeClass::getUniqueAlt(altSubSets)
|
||||
<< 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
|
||||
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;
|
||||
}
|
||||
|
||||
atn::ATNConfigSet *ParserATNSimulator::computeReachSet(ATNConfigSet *closure, int t, bool fullCtx) {
|
||||
atn::ATNConfigSet *ParserATNSimulator::computeReachSet(ATNConfigSet *closure, size_t t, bool fullCtx) {
|
||||
if (debug) {
|
||||
std::wcout << L"in computeReachSet, starting closure: " << closure << std::endl;
|
||||
}
|
||||
|
@ -468,10 +470,10 @@ atn::ATNConfigSet *ParserATNSimulator::computeReachSet(ATNConfigSet *closure, in
|
|||
continue;
|
||||
}
|
||||
|
||||
int n = c->state->getNumberOfTransitions();
|
||||
for (int ti = 0; ti < n; ti++) { // for each transition
|
||||
size_t n = c->state->getNumberOfTransitions();
|
||||
for (size_t ti = 0; ti < n; ti++) { // for each transition
|
||||
Transition *trans = c->state->transition(ti);
|
||||
ATNState *target = getReachableTarget(trans, t);
|
||||
ATNState *target = getReachableTarget(trans, (int)t);
|
||||
if (target != nullptr) {
|
||||
intermediate->add(new ATNConfig(c, target), mergeCache);
|
||||
}
|
||||
|
@ -577,8 +579,8 @@ atn::ATNConfigSet *ParserATNSimulator::removeAllConfigsNotInRuleStopState(ATNCon
|
|||
}
|
||||
|
||||
if (lookToEndOfRule && config->state->onlyHasEpsilonTransitions()) {
|
||||
misc::IntervalSet *nextTokens = atn.nextTokens(config->state);
|
||||
if (nextTokens->contains(Token::EPSILON)) {
|
||||
misc::IntervalSet nextTokens = atn.nextTokens(config->state);
|
||||
if (nextTokens.contains(Token::EPSILON)) {
|
||||
ATNState *endOfRuleState = atn.ruleToStopState[config->state->ruleIndex];
|
||||
result->add(new ATNConfig(config, endOfRuleState), mergeCache);
|
||||
}
|
||||
|
@ -593,9 +595,9 @@ atn::ATNConfigSet *ParserATNSimulator::computeStartState(ATNState *p, RuleContex
|
|||
PredictionContext *initialContext = PredictionContext::fromRuleContext(atn, ctx);
|
||||
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;
|
||||
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*>();
|
||||
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
|
||||
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]
|
||||
/* 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:
|
||||
|
@ -630,13 +632,13 @@ std::vector<SemanticContext*> ParserATNSimulator::getPredsForAmbigAlts(antlrcpp:
|
|||
std::vector<SemanticContext*> altToPred;// = new SemanticContext[nalts + 1];
|
||||
|
||||
for (auto c : *configs->configLookup) {
|
||||
if (ambigAlts->data.test(c->alt)) {
|
||||
altToPred[c->alt] = dynamic_cast<SemanticContext*>( (new SemanticContext::OR(altToPred[c->alt], c->semanticContext)));
|
||||
if (ambigAlts->data.test((size_t)c->alt)) {
|
||||
altToPred[(size_t)c->alt] = dynamic_cast<SemanticContext*>( (new SemanticContext::OR(altToPred[(size_t)c->alt], c->semanticContext)));
|
||||
}
|
||||
}
|
||||
|
||||
int nPredAlts = 0;
|
||||
for (int i = 1; i <= nalts; i++) {
|
||||
size_t nPredAlts = 0;
|
||||
for (size_t i = 1; i <= nalts; i++) {
|
||||
if (altToPred[i] == nullptr) {
|
||||
altToPred[i] = SemanticContext::NONE;
|
||||
} else if (altToPred[i] != SemanticContext::NONE) {
|
||||
|
@ -659,10 +661,10 @@ std::vector<SemanticContext*> ParserATNSimulator::getPredsForAmbigAlts(antlrcpp:
|
|||
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*>();
|
||||
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];
|
||||
|
||||
// unpredicted is indicated by SemanticContext.NONE
|
||||
|
@ -673,7 +675,7 @@ std::vector<dfa::DFAState::PredPrediction *> ParserATNSimulator::getPredicatePre
|
|||
}
|
||||
|
||||
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) {
|
||||
containsPredicate = true;
|
||||
|
@ -700,11 +702,11 @@ int ParserATNSimulator::getAltThatFinishedDecisionEntryRule(ATNConfigSet *config
|
|||
return alts->getMinElement();
|
||||
}
|
||||
|
||||
antlrcpp::BitSet *ParserATNSimulator::evalSemanticContext(std::vector<dfa::DFAState::PredPrediction*> predPredictions, ParserRuleContext *outerContext, bool complete) {
|
||||
antlrcpp::BitSet *predictions = new antlrcpp::BitSet();
|
||||
BitSet *ParserATNSimulator::evalSemanticContext(std::vector<dfa::DFAState::PredPrediction*> predPredictions, ParserRuleContext *outerContext, bool complete) {
|
||||
BitSet *predictions = new BitSet();
|
||||
for (auto pair : predPredictions) {
|
||||
if (pair->pred == SemanticContext::NONE) {
|
||||
predictions->set(pair->alt);
|
||||
predictions->set((size_t)pair->alt);
|
||||
if (!complete) {
|
||||
break;
|
||||
}
|
||||
|
@ -720,7 +722,7 @@ antlrcpp::BitSet *ParserATNSimulator::evalSemanticContext(std::vector<dfa::DFASt
|
|||
if (debug || dfa_debug) {
|
||||
std::wcout << L"PREDICT " << pair->alt << std::endl;
|
||||
}
|
||||
predictions->set(pair->alt);
|
||||
predictions->set((size_t)pair->alt);
|
||||
if (!complete) {
|
||||
break;
|
||||
}
|
||||
|
@ -749,7 +751,7 @@ void ParserATNSimulator::closureCheckingStopState(ATNConfig *config, ATNConfigSe
|
|||
// We hit rule end. If we have context info, use it
|
||||
// run thru all possible stack tops in ctx
|
||||
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 (fullCtx) {
|
||||
configs->add(new ATNConfig(config, config->state, dynamic_cast<PredictionContext*>(PredictionContext::EMPTY)), mergeCache);
|
||||
|
@ -757,13 +759,13 @@ void ParserATNSimulator::closureCheckingStopState(ATNConfig *config, ATNConfigSe
|
|||
} else {
|
||||
// we have no context info, just chase follow links (if greedy)
|
||||
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);
|
||||
}
|
||||
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
|
||||
ATNConfig *c = new ATNConfig(returnState, config->alt, newContext, config->semanticContext);
|
||||
// While we have context to pop back from, we may have
|
||||
|
@ -785,7 +787,7 @@ void ParserATNSimulator::closureCheckingStopState(ATNConfig *config, ATNConfigSe
|
|||
} else {
|
||||
// else if we have no context info, just chase follow links (if greedy)
|
||||
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);
|
||||
}
|
||||
|
||||
for (int i = 0; i < p->getNumberOfTransitions(); i++) {
|
||||
for (size_t i = 0; i < p->getNumberOfTransitions(); i++) {
|
||||
Transition *t = p->transition(i);
|
||||
bool continueCollecting = !(dynamic_cast<ActionTransition*>(t) != nullptr) && collectPredicates;
|
||||
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) {
|
||||
if (parser != nullptr && index >= 0) {
|
||||
std::wstring ParserATNSimulator::getRuleName(size_t index) {
|
||||
if (parser != nullptr) {
|
||||
return parser->getRuleNames()[index];
|
||||
}
|
||||
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);
|
||||
}
|
||||
|
||||
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) {
|
||||
std::wcout << L"PRED (collectPredicates=" << collectPredicates << L") " << pt->precedence << L">=_p" << L", ctx dependent=true" << std::endl;
|
||||
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
|
||||
// the config sets. It also obviates the need to test predicates
|
||||
// later during conflict resolution.
|
||||
int currentPosition = _input->index();
|
||||
_input->seek(_startIndex);
|
||||
size_t currentPosition = _input->index();
|
||||
_input->seek((size_t)_startIndex);
|
||||
bool predSucceeds = pt->getPredicate()->eval(parser, _outerContext);
|
||||
_input->seek(currentPosition);
|
||||
if (predSucceeds) {
|
||||
|
@ -923,7 +926,7 @@ atn::ATNConfig *ParserATNSimulator::predTransition(ATNConfig *config, PredicateT
|
|||
if (debug) {
|
||||
std::wcout << L"PRED (collectPredicates=" << collectPredicates << L") " << pt->ruleIndex << L":" << pt->predIndex << L", ctx dependent=" << pt->isCtxDependent << std::endl;
|
||||
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
|
||||
// the config sets. It also obviates the need to test predicates
|
||||
// later during conflict resolution.
|
||||
int currentPosition = _input->index();
|
||||
_input->seek(_startIndex);
|
||||
size_t currentPosition = _input->index();
|
||||
_input->seek((size_t)_startIndex);
|
||||
bool predSucceeds = pt->getPredicate()->eval(parser, _outerContext);
|
||||
_input->seek(currentPosition);
|
||||
if (predSucceeds) {
|
||||
|
@ -957,7 +960,7 @@ atn::ATNConfig *ParserATNSimulator::predTransition(ATNConfig *config, PredicateT
|
|||
|
||||
atn::ATNConfig *ParserATNSimulator::ruleTransition(ATNConfig *config, RuleTransition *t) {
|
||||
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;
|
||||
|
@ -965,36 +968,36 @@ atn::ATNConfig *ParserATNSimulator::ruleTransition(ATNConfig *config, RuleTransi
|
|||
return new atn::ATNConfig(config, t->target, newContext);
|
||||
}
|
||||
|
||||
antlrcpp::BitSet ParserATNSimulator::getConflictingAlts(ATNConfigSet *configs) {
|
||||
std::vector<antlrcpp::BitSet> altsets = PredictionModeClass::getConflictingAltSubsets(configs);
|
||||
BitSet ParserATNSimulator::getConflictingAlts(ATNConfigSet *configs) {
|
||||
std::vector<BitSet> altsets = PredictionModeClass::getConflictingAltSubsets(configs);
|
||||
return PredictionModeClass::getAlts(altsets);
|
||||
}
|
||||
|
||||
antlrcpp::BitSet ParserATNSimulator::getConflictingAltsOrUniqueAlt(ATNConfigSet *configs) {
|
||||
antlrcpp::BitSet conflictingAlts;
|
||||
BitSet ParserATNSimulator::getConflictingAltsOrUniqueAlt(ATNConfigSet *configs) {
|
||||
BitSet conflictingAlts;
|
||||
if (configs->uniqueAlt != ATN::INVALID_ALT_NUMBER) {
|
||||
conflictingAlts.set(configs->uniqueAlt);
|
||||
conflictingAlts.set((size_t)configs->uniqueAlt);
|
||||
} else {
|
||||
conflictingAlts = *configs->conflictingAlts;
|
||||
}
|
||||
return conflictingAlts;
|
||||
}
|
||||
|
||||
std::wstring ParserATNSimulator::getTokenName(int t) {
|
||||
std::wstring ParserATNSimulator::getTokenName(size_t t) {
|
||||
if (t == Token::_EOF) {
|
||||
return L"EOF";
|
||||
}
|
||||
if (parser != nullptr) {
|
||||
std::vector<std::wstring> tokensNames = parser->getTokenNames();
|
||||
if (t >= (int)tokensNames.size()) {
|
||||
std::wcerr << t << L" type out of range: " << antlrcpp::Arrays::ListToString(tokensNames, L", ");
|
||||
if (t >= tokensNames.size()) {
|
||||
std::wcerr << t << L" type out of range: " << Arrays::listToString(tokensNames, L", ");
|
||||
// TODO
|
||||
// std::wcerr << ((CommonTokenStream*)parser->getInputStream())->getTokens();
|
||||
} else {
|
||||
return tokensNames[t] + L"<" + std::to_wstring(t) + L">";
|
||||
}
|
||||
}
|
||||
return antlrcpp::StringConverterHelper::toString(t);
|
||||
return StringConverterHelper::toString(t);
|
||||
}
|
||||
|
||||
std::wstring ParserATNSimulator::getLookaheadName(TokenStream *input) {
|
||||
|
@ -1009,20 +1012,21 @@ void ParserATNSimulator::dumpDeadEndConfigs(NoViableAltException *nvae) {
|
|||
Transition *t = c->state->transition(0);
|
||||
if (dynamic_cast<AtomTransition*>(t) != nullptr) {
|
||||
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) {
|
||||
SetTransition *st = static_cast<SetTransition*>(t);
|
||||
bool is_not = dynamic_cast<NotSetTransition*>(st) != nullptr;
|
||||
trans = (is_not ? L"~" : L"");
|
||||
trans += L"Set ";
|
||||
trans += st->set->toString();
|
||||
trans += st->set.toString();
|
||||
}
|
||||
}
|
||||
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);
|
||||
}
|
||||
|
||||
|
@ -1038,7 +1042,7 @@ int ParserATNSimulator::getUniqueAlt(ATNConfigSet *configs) {
|
|||
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) {
|
||||
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
|
||||
if (from == nullptr || t < -1 || t > atn.maxTokenType) {
|
||||
if (from == nullptr || t > (size_t)atn.maxTokenType) {
|
||||
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) {
|
||||
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;
|
||||
}
|
||||
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) {
|
||||
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;
|
||||
}
|
||||
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) {
|
||||
// ParserATNPathFinder finder = new ParserATNPathFinder(parser, atn);
|
||||
// int i = 1;
|
||||
|
@ -1136,7 +1143,7 @@ void ParserATNSimulator::reportAmbiguity(dfa::DFA *dfa, dfa::DFAState *D, int st
|
|||
// }
|
||||
// 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;
|
||||
}
|
||||
if (parser != nullptr) {
|
||||
|
|
|
@ -318,7 +318,7 @@ namespace atn {
|
|||
/// conflict + preds
|
||||
/// </summary>
|
||||
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>
|
||||
/// 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
|
||||
/// {@code t}, or {@code null} if the target state for this edge is not
|
||||
/// already cached </returns>
|
||||
virtual dfa::DFAState *getExistingTargetState(dfa::DFAState *previousD, int t);
|
||||
virtual dfa::DFAState *getExistingTargetState(dfa::DFAState *previousD, size_t t);
|
||||
|
||||
/// <summary>
|
||||
/// 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
|
||||
/// {@code t}. If {@code t} does not lead to a valid DFA state, this method
|
||||
/// 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);
|
||||
|
||||
// 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>
|
||||
/// Return a configuration set containing only the configurations from
|
||||
|
@ -377,7 +377,7 @@ namespace atn {
|
|||
|
||||
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);
|
||||
|
||||
|
@ -409,7 +409,7 @@ namespace atn {
|
|||
virtual void closure_(ATNConfig *config, ATNConfigSet *configs, std::set<ATNConfig*> *closureBusy, bool collectPredicates, bool fullCtx, int depth);
|
||||
|
||||
public:
|
||||
virtual std::wstring getRuleName(int index);
|
||||
virtual std::wstring getRuleName(size_t index);
|
||||
|
||||
protected:
|
||||
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);
|
||||
|
||||
public:
|
||||
virtual std::wstring getTokenName(int t);
|
||||
virtual std::wstring getTokenName(size_t t);
|
||||
|
||||
virtual std::wstring getLookaheadName(TokenStream *input);
|
||||
|
||||
|
@ -478,7 +478,7 @@ namespace atn {
|
|||
virtual void dumpDeadEndConfigs(NoViableAltException *nvae);
|
||||
|
||||
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);
|
||||
|
||||
|
@ -501,7 +501,7 @@ namespace atn {
|
|||
/// <returns> If {@code to} is {@code null}, this method returns {@code null};
|
||||
/// otherwise this method returns the result of calling <seealso cref="#addDFAState"/>
|
||||
/// 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>
|
||||
/// 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>
|
||||
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>
|
||||
/// 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:
|
||||
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) {
|
||||
}
|
||||
|
||||
int PrecedencePredicateTransition::getSerializationType() {
|
||||
int PrecedencePredicateTransition::getSerializationType() const {
|
||||
return PRECEDENCE;
|
||||
}
|
||||
|
||||
bool PrecedencePredicateTransition::isEpsilon() {
|
||||
bool PrecedencePredicateTransition::isEpsilon() const {
|
||||
return true;
|
||||
}
|
||||
|
||||
bool PrecedencePredicateTransition::matches(int symbol, int minVocabSymbol, int maxVocabSymbol) {
|
||||
bool PrecedencePredicateTransition::matches(int symbol, int minVocabSymbol, int maxVocabSymbol) const {
|
||||
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);
|
||||
}
|
||||
|
||||
std::wstring PrecedencePredicateTransition::toString() {
|
||||
std::wstring PrecedencePredicateTransition::toString() const {
|
||||
return std::to_wstring(precedence) + std::wstring(L" >= _p");
|
||||
}
|
||||
|
|
|
@ -50,15 +50,15 @@ namespace atn {
|
|||
|
||||
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) {
|
||||
}
|
||||
|
||||
int PredicateTransition::getSerializationType() {
|
||||
int PredicateTransition::getSerializationType() const {
|
||||
return PREDICATE;
|
||||
}
|
||||
|
||||
bool PredicateTransition::isEpsilon() {
|
||||
bool PredicateTransition::isEpsilon() const {
|
||||
return true;
|
||||
}
|
||||
|
||||
bool PredicateTransition::matches(int symbol, int minVocabSymbol, int maxVocabSymbol) {
|
||||
bool PredicateTransition::matches(int symbol, int minVocabSymbol, int maxVocabSymbol) const {
|
||||
return false;
|
||||
}
|
||||
|
||||
SemanticContext::Predicate *PredicateTransition::getPredicate() {
|
||||
SemanticContext::Predicate *PredicateTransition::getPredicate() const {
|
||||
// TODO: who is responsible for managing this memory?
|
||||
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);
|
||||
}
|
||||
|
|
|
@ -55,14 +55,14 @@ namespace atn {
|
|||
|
||||
PredicateTransition(ATNState *target, int ruleIndex, int predIndex, bool isCtxDependent);
|
||||
|
||||
virtual int getSerializationType() override;
|
||||
virtual int getSerializationType() const override;
|
||||
|
||||
virtual bool isEpsilon() override;
|
||||
virtual bool matches(int symbol, int minVocabSymbol, int maxVocabSymbol) override;
|
||||
virtual bool isEpsilon() const 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::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) {
|
||||
|
@ -66,50 +66,50 @@ PredictionContext *PredictionContext::fromRuleContext(const ATN &atn, RuleContex
|
|||
PredictionContext *parent = EMPTY;
|
||||
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));
|
||||
return SingletonPredictionContext::create(parent, transition->followState->stateNumber);
|
||||
}
|
||||
|
||||
bool PredictionContext::isEmpty() {
|
||||
bool PredictionContext::isEmpty() const {
|
||||
return this == EMPTY;
|
||||
}
|
||||
|
||||
bool PredictionContext::hasEmptyPath() {
|
||||
bool PredictionContext::hasEmptyPath() const {
|
||||
return getReturnState(size() - 1) == EMPTY_RETURN_STATE;
|
||||
}
|
||||
|
||||
int PredictionContext::hashCode() {
|
||||
size_t PredictionContext::hashCode() const {
|
||||
return cachedHashCode;
|
||||
}
|
||||
|
||||
int PredictionContext::calculateEmptyHashCode() {
|
||||
int hash = MurmurHash::initialize(INITIAL_HASH);
|
||||
size_t PredictionContext::calculateEmptyHashCode() {
|
||||
size_t hash = MurmurHash::initialize(INITIAL_HASH);
|
||||
hash = MurmurHash::finish(hash, 0);
|
||||
return hash;
|
||||
}
|
||||
|
||||
int PredictionContext::calculateHashCode(PredictionContext *parent, int returnState) {
|
||||
int hash = MurmurHash::initialize(INITIAL_HASH);
|
||||
hash = MurmurHash::update(hash, parent);
|
||||
hash = MurmurHash::update(hash, returnState);
|
||||
size_t PredictionContext::calculateHashCode(PredictionContext *parent, int returnState) {
|
||||
size_t hash = MurmurHash::initialize(INITIAL_HASH);
|
||||
hash = MurmurHash::update(hash, (size_t)parent);
|
||||
hash = MurmurHash::update(hash, (size_t)returnState);
|
||||
hash = MurmurHash::finish(hash, 2);
|
||||
return hash;
|
||||
}
|
||||
|
||||
int PredictionContext::calculateHashCode(std::vector<PredictionContext*> parents, std::vector<int> returnStates) {
|
||||
int hash = MurmurHash::initialize(INITIAL_HASH);
|
||||
size_t PredictionContext::calculateHashCode(const std::vector<PredictionContext*> &parents, const std::vector<int> &returnStates) {
|
||||
size_t hash = MurmurHash::initialize(INITIAL_HASH);
|
||||
|
||||
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++) {
|
||||
PredictionContext * parent = parents[i];
|
||||
hash = MurmurHash::update(hash, parent);
|
||||
hash = MurmurHash::update(hash, (size_t)parent);
|
||||
}
|
||||
|
||||
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]));
|
||||
|
@ -124,7 +124,7 @@ PredictionContext *PredictionContext::merge(PredictionContext *a, PredictionCont
|
|||
};
|
||||
|
||||
// share same graph if both same
|
||||
if (a == b || a->equals(b)) {
|
||||
if (a == b) {
|
||||
return a;
|
||||
}
|
||||
|
||||
|
@ -195,17 +195,17 @@ PredictionContext *PredictionContext::mergeSingletons(SingletonPredictionContext
|
|||
else { // a != b payloads differ
|
||||
// see if we can collapse parents due to $+x parents if local ctx
|
||||
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;
|
||||
}
|
||||
if (singleParent != nullptr) { // parents are same
|
||||
// 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) {
|
||||
payloads[0] = b->returnState;
|
||||
payloads[1] = a->returnState;
|
||||
}
|
||||
PredictionContext parents[2] = {*singleParent, *singleParent};
|
||||
std::vector<PredictionContext *> parents = { singleParent, singleParent };
|
||||
PredictionContext *a_ = new ArrayPredictionContext(parents, payloads);
|
||||
if (mergeCache != nullptr) {
|
||||
mergeCache->put(a, b, a_);
|
||||
|
@ -217,12 +217,12 @@ PredictionContext *PredictionContext::mergeSingletons(SingletonPredictionContext
|
|||
// ax + by = [ax,by]
|
||||
PredictionContext *a_;
|
||||
if (a->returnState > b->returnState) { // sort by payload
|
||||
int payloads[2] = {b->returnState, a->returnState};
|
||||
PredictionContext parents[2] = {*b->parent, *a->parent};
|
||||
std::vector<int> payloads = { b->returnState, a->returnState };
|
||||
std::vector<PredictionContext *> parents = { b->parent, a->parent };
|
||||
a_ = new ArrayPredictionContext(parents, payloads);
|
||||
} else {
|
||||
int payloads[2] = {a->returnState, b->returnState};
|
||||
PredictionContext parents[2] = {*a->parent, *b->parent};
|
||||
std::vector<int> payloads = {a->returnState, b->returnState};
|
||||
std::vector<PredictionContext *> parents = { a->parent, b->parent };
|
||||
a_ = new ArrayPredictionContext(parents, payloads);
|
||||
}
|
||||
|
||||
|
@ -246,14 +246,14 @@ PredictionContext *PredictionContext::mergeRoot(SingletonPredictionContext *a, S
|
|||
return (PredictionContext *)EMPTY;
|
||||
}
|
||||
if (a == EMPTY) { // $ + x = [$,x]
|
||||
int payloads[2] = {b->returnState, EMPTY_RETURN_STATE};
|
||||
PredictionContext parents[2] = {*b->parent, *EMPTY};
|
||||
std::vector<int> payloads = { b->returnState, EMPTY_RETURN_STATE };
|
||||
std::vector<PredictionContext *> parents = { b->parent, EMPTY };
|
||||
PredictionContext *joined = new ArrayPredictionContext(parents, payloads);
|
||||
return joined;
|
||||
}
|
||||
if (b == EMPTY) { // x + $ = [$,x] ($ is always first if present)
|
||||
int payloads[2] = {a->returnState, EMPTY_RETURN_STATE};
|
||||
PredictionContext parents[2] = {*a->parent, *EMPTY};
|
||||
std::vector<int> payloads = { a->returnState, EMPTY_RETURN_STATE };
|
||||
std::vector<PredictionContext *> parents = { a->parent, EMPTY };
|
||||
PredictionContext *joined = new ArrayPredictionContext(parents, payloads);
|
||||
return joined;
|
||||
}
|
||||
|
@ -283,14 +283,14 @@ PredictionContext *PredictionContext::mergeArrays(ArrayPredictionContext *a, Arr
|
|||
|
||||
// walk and merge to yield mergedParents, mergedReturnStates
|
||||
while (i < a->returnStates.size() && j < b->returnStates.size()) {
|
||||
PredictionContext *a_parent = a->parents->at(i);// [i];
|
||||
PredictionContext *b_parent = b->parents->at(i);//&b->parents[j];
|
||||
PredictionContext *a_parent = a->parents[i];
|
||||
PredictionContext *b_parent = b->parents[j];
|
||||
if (a->returnStates[i] == b->returnStates[j]) {
|
||||
// same payload (stack tops are equal), must yield merged singleton
|
||||
int payload = a->returnStates[i];
|
||||
// $+$ = $
|
||||
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) {
|
||||
mergedParents[k] = a_parent; // choose left
|
||||
mergedReturnStates[k] = payload;
|
||||
|
@ -318,13 +318,13 @@ PredictionContext *PredictionContext::mergeArrays(ArrayPredictionContext *a, Arr
|
|||
// copy over any payloads remaining in either array
|
||||
if (i < a->returnStates.size()) {
|
||||
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];
|
||||
k++;
|
||||
}
|
||||
} else {
|
||||
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];
|
||||
k++;
|
||||
}
|
||||
|
@ -348,13 +348,13 @@ PredictionContext *PredictionContext::mergeArrays(ArrayPredictionContext *a, Arr
|
|||
|
||||
// if we created same array as a or b, return that instead
|
||||
// TODO: track whether this is possible above during merge sort for speed
|
||||
if (M->equals(a)) {
|
||||
if (M == a) {
|
||||
if (mergeCache != nullptr) {
|
||||
mergeCache->put(a,b,a);
|
||||
}
|
||||
return a;
|
||||
}
|
||||
if (M->equals(b)) {
|
||||
if (M == b) {
|
||||
if (mergeCache != nullptr) {
|
||||
mergeCache->put(a,b,b);
|
||||
}
|
||||
|
@ -433,7 +433,7 @@ std::wstring PredictionContext::toDOTString(PredictionContext *context) {
|
|||
if (current == EMPTY) {
|
||||
continue;
|
||||
}
|
||||
for (int i = 0; i < current->size(); i++) {
|
||||
for (size_t i = 0; i < current->size(); i++) {
|
||||
if (current->getParent(i) == nullptr) {
|
||||
continue;
|
||||
}
|
||||
|
@ -477,12 +477,12 @@ PredictionContext *PredictionContext::getCachedContext(PredictionContext *contex
|
|||
|
||||
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);
|
||||
if (changed || parent != context->getParent(i)) {
|
||||
if (!changed) {
|
||||
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);
|
||||
}
|
||||
|
||||
|
@ -542,7 +542,7 @@ void PredictionContext::getAllContextNodes_(PredictionContext *context, std::vec
|
|||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
@ -552,15 +552,3 @@ std::wstring PredictionContext::toString() {
|
|||
// for now.)
|
||||
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>
|
||||
/// </summary>
|
||||
const int cachedHashCode;
|
||||
const size_t cachedHashCode;
|
||||
|
||||
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:
|
||||
/// Convert a RuleContext tree to a PredictionContext graph.
|
||||
/// Return EMPTY if outerContext is empty.
|
||||
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;
|
||||
|
||||
virtual int getReturnState(int index); // = 0;
|
||||
|
||||
/// <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");
|
||||
|
||||
}
|
||||
/// This means only the EMPTY context is in set.
|
||||
virtual bool isEmpty() const;
|
||||
virtual bool hasEmptyPath() const;
|
||||
virtual size_t hashCode() const;
|
||||
|
||||
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:
|
||||
// dispatch
|
||||
static PredictionContext *merge(PredictionContext *a, PredictionContext *b, bool rootIsWildcard, misc::DoubleKeyMap<PredictionContext*, PredictionContext*, PredictionContext*> *mergeCache);
|
||||
|
||||
/// <summary>
|
||||
|
@ -305,22 +290,22 @@ namespace atn {
|
|||
std::wstring *toStrings(Recognizer<T1, T2> *recognizer, PredictionContext *stop, int currentState) {
|
||||
std::vector<std::wstring> result = std::vector<std::wstring>();
|
||||
|
||||
for (int perm = 0; ; perm++) {
|
||||
int offset = 0;
|
||||
for (size_t perm = 0; ; perm++) {
|
||||
size_t offset = 0;
|
||||
bool last = true;
|
||||
PredictionContext *p = this;
|
||||
int stateNumber = currentState;
|
||||
antlrcpp::StringBuilder *localBuffer = new antlrcpp::StringBuilder();
|
||||
localBuffer->append(L"[");
|
||||
while (!p->isEmpty() && p != stop) {
|
||||
int index = 0;
|
||||
size_t index = 0;
|
||||
if (p->size() > 0) {
|
||||
int bits = 1;
|
||||
size_t bits = 1;
|
||||
while ((1 << bits) < p->size()) {
|
||||
bits++;
|
||||
}
|
||||
|
||||
int mask = (1 << bits) - 1;
|
||||
size_t mask = (1 << bits) - 1;
|
||||
index = (perm >> offset) & mask;
|
||||
last &= index >= p->size() - 1;
|
||||
if (index >= p->size()) {
|
||||
|
@ -336,7 +321,7 @@ namespace atn {
|
|||
}
|
||||
|
||||
ATN *atn = recognizer->getATN();
|
||||
ATNState *s = atn->states[stateNumber];
|
||||
ATNState *s = atn->states[(size_t)stateNumber];
|
||||
std::wstring ruleName = recognizer->getRuleNames()[s->ruleIndex];
|
||||
localBuffer->append(ruleName);
|
||||
} else if (p->getReturnState(index) != EMPTY_RETURN_STATE) {
|
||||
|
|
|
@ -39,45 +39,28 @@
|
|||
using namespace org::antlr::v4::runtime;
|
||||
using namespace org::antlr::v4::runtime::atn;
|
||||
|
||||
class AltAndContextConfigEqualityComparator : misc::EqualityComparator<ATNConfig> {
|
||||
public:
|
||||
int hashCode(ATNConfig* o);
|
||||
bool equals(ATNConfig* a, ATNConfig* b);
|
||||
|
||||
private:
|
||||
AltAndContextConfigEqualityComparator() {}
|
||||
struct AltAndContextConfigHasher
|
||||
{
|
||||
size_t operator () (const ATNConfig &o) const {
|
||||
size_t hashCode = misc::MurmurHash::initialize(7);
|
||||
hashCode = misc::MurmurHash::update(hashCode, (size_t)o.state->stateNumber);
|
||||
hashCode = misc::MurmurHash::update(hashCode, (size_t)o.context);
|
||||
return misc::MurmurHash::finish(hashCode, 2);
|
||||
}
|
||||
};
|
||||
|
||||
// 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);
|
||||
}
|
||||
|
||||
// TODO -- Determine if we need this comparator.
|
||||
bool AltAndContextConfigEqualityComparator::equals(ATNConfig* a, ATNConfig* b) {
|
||||
if (a == b) {
|
||||
return true;
|
||||
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;
|
||||
}
|
||||
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() {}
|
||||
};
|
||||
|
||||
|
||||
bool PredictionModeClass::hasSLLConflictTerminatingPrediction(PredictionMode* mode,
|
||||
ATNConfigSet* configs) {
|
||||
bool PredictionModeClass::hasSLLConflictTerminatingPrediction(PredictionMode* mode, ATNConfigSet* configs) {
|
||||
/* Configs in rule stop states indicate reaching the end of the decision
|
||||
* rule (local context) or end of start rule (full context). If all
|
||||
* 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) {
|
||||
AltAndContextMap configToAlts;
|
||||
/*
|
||||
std::unordered_map<const ATNConfig&, antlrcpp::BitSet, AltAndContextConfigHasher, AltAndContextConfigComparer> configToAlts;
|
||||
for (const ATNConfig& c : *configs->configLookup) {
|
||||
configToAlts[c].set(c.alt);
|
||||
}
|
||||
|
@ -199,12 +183,14 @@ std::vector<antlrcpp::BitSet> PredictionModeClass::getConflictingAltSubsets(ATNC
|
|||
values.push_back(it.second);
|
||||
}
|
||||
return values;
|
||||
*/
|
||||
return std::vector<antlrcpp::BitSet>();
|
||||
}
|
||||
|
||||
std::map<ATNState*, antlrcpp::BitSet> PredictionModeClass::getStateToAltMap(ATNConfigSet* configs) {
|
||||
std::map<ATNState*, antlrcpp::BitSet> m;
|
||||
for (ATNConfig c : *configs->configLookup) {
|
||||
m[c.state].set(c.alt);
|
||||
m[c.state].set((size_t)c.alt);
|
||||
}
|
||||
return m;
|
||||
}
|
||||
|
@ -223,7 +209,7 @@ int PredictionModeClass::getSingleViableAlt(const std::vector<antlrcpp::BitSet>&
|
|||
int minAlt = alts.nextSetBit(0);
|
||||
|
||||
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
|
||||
{
|
||||
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) {
|
||||
}
|
||||
|
||||
int RangeTransition::getSerializationType() {
|
||||
int RangeTransition::getSerializationType() const {
|
||||
return RANGE;
|
||||
}
|
||||
|
||||
misc::IntervalSet *RangeTransition::label() {
|
||||
misc::IntervalSet RangeTransition::label() const {
|
||||
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;
|
||||
}
|
||||
|
||||
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"'");
|
||||
}
|
||||
|
|
|
@ -46,12 +46,12 @@ namespace atn {
|
|||
|
||||
RangeTransition(ATNState *target, int from, int to);
|
||||
|
||||
virtual int getSerializationType() override;
|
||||
virtual int getSerializationType() const override;
|
||||
|
||||
virtual misc::IntervalSet *label() override;
|
||||
virtual bool matches(int symbol, int minVocabSymbol, int maxVocabSymbol) override;
|
||||
virtual misc::IntervalSet label() const override;
|
||||
virtual bool matches(int symbol, int minVocabSymbol, int maxVocabSymbol) const override;
|
||||
|
||||
virtual std::wstring toString();
|
||||
virtual std::wstring toString() const;
|
||||
};
|
||||
|
||||
} // namespace atn
|
||||
|
|
|
@ -41,14 +41,14 @@ RuleTransition::RuleTransition(RuleStartState *ruleStart, int ruleIndex, int pre
|
|||
this->followState = followState;
|
||||
}
|
||||
|
||||
int RuleTransition::getSerializationType() {
|
||||
int RuleTransition::getSerializationType() const {
|
||||
return RULE;
|
||||
}
|
||||
|
||||
bool RuleTransition::isEpsilon() {
|
||||
bool RuleTransition::isEpsilon() const {
|
||||
return true;
|
||||
}
|
||||
|
||||
bool RuleTransition::matches(int symbol, int minVocabSymbol, int maxVocabSymbol) {
|
||||
bool RuleTransition::matches(int symbol, int minVocabSymbol, int maxVocabSymbol) const {
|
||||
return false;
|
||||
}
|
||||
|
|
|
@ -57,10 +57,10 @@ namespace atn {
|
|||
|
||||
RuleTransition(RuleStartState *ruleStart, int ruleIndex, int precedence, ATNState *followState);
|
||||
|
||||
virtual int getSerializationType() override;
|
||||
virtual int getSerializationType() const override;
|
||||
|
||||
virtual bool isEpsilon() override;
|
||||
virtual bool matches(int symbol, int minVocabSymbol, int maxVocabSymbol) override;
|
||||
virtual bool isEpsilon() const override;
|
||||
virtual bool matches(int symbol, int minVocabSymbol, int maxVocabSymbol) const override;
|
||||
};
|
||||
|
||||
} // namespace atn
|
||||
|
|
|
@ -46,7 +46,7 @@ std::wstring SemanticContext::toString() const {
|
|||
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?
|
||||
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() {
|
||||
int hashCode = misc::MurmurHash::initialize();
|
||||
hashCode = misc::MurmurHash::update(hashCode, ruleIndex);
|
||||
hashCode = misc::MurmurHash::update(hashCode, predIndex);
|
||||
size_t SemanticContext::Predicate::hashCode() {
|
||||
size_t hashCode = misc::MurmurHash::initialize();
|
||||
hashCode = misc::MurmurHash::update(hashCode, (size_t)ruleIndex);
|
||||
hashCode = misc::MurmurHash::update(hashCode, (size_t)predIndex);
|
||||
hashCode = misc::MurmurHash::update(hashCode, isCtxDependent ? 1 : 0);
|
||||
hashCode = misc::MurmurHash::finish(hashCode, 3);
|
||||
return hashCode;
|
||||
|
@ -91,9 +91,9 @@ int SemanticContext::PrecedencePredicate::compareTo(PrecedencePredicate *o) {
|
|||
return precedence - o->precedence;
|
||||
}
|
||||
|
||||
int SemanticContext::PrecedencePredicate::hashCode() {
|
||||
int hashCode = 1;
|
||||
hashCode = 31 * hashCode + precedence;
|
||||
size_t SemanticContext::PrecedencePredicate::hashCode() {
|
||||
size_t hashCode = 1;
|
||||
hashCode = 31 * hashCode + (size_t)precedence;
|
||||
return hashCode;
|
||||
}
|
||||
|
||||
|
@ -165,9 +165,8 @@ bool SemanticContext::AND::equals(void *obj) {
|
|||
}
|
||||
|
||||
|
||||
int SemanticContext::AND::hashCode() {
|
||||
return misc::MurmurHash::hashCode(opnds.data(),
|
||||
opnds.size(), (int)typeid(AND).hash_code());
|
||||
size_t SemanticContext::AND::hashCode() {
|
||||
return misc::MurmurHash::hashCode(opnds.data(), opnds.size(), typeid(AND).hash_code());
|
||||
}
|
||||
|
||||
|
||||
|
@ -229,8 +228,8 @@ bool SemanticContext::OR::equals(SemanticContext *obj) {
|
|||
return this->opnds == other->opnds;
|
||||
}
|
||||
|
||||
int SemanticContext::OR::hashCode() {
|
||||
return misc::MurmurHash::hashCode(opnds.data(), opnds.size(), (int)typeid(OR).hash_code());
|
||||
size_t SemanticContext::OR::hashCode() {
|
||||
return misc::MurmurHash::hashCode(opnds.data(), opnds.size(), typeid(OR).hash_code());
|
||||
}
|
||||
|
||||
|
||||
|
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue