forked from jasder/antlr
Removed the need for a separate VectorHelper class + other improvements.
Some cleanup too.
This commit is contained in:
parent
9006d241fa
commit
2aa40c779e
|
@ -451,8 +451,6 @@
|
|||
27C669151C9585230021E494 /* guid.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 27C668F51C9585230021E494 /* guid.cpp */; };
|
||||
27C669161C9585230021E494 /* guid.h in Headers */ = {isa = PBXBuildFile; fileRef = 27C668F61C9585230021E494 /* guid.h */; };
|
||||
27C669171C9585230021E494 /* guid.h in Headers */ = {isa = PBXBuildFile; fileRef = 27C668F61C9585230021E494 /* guid.h */; };
|
||||
27C669181C9585230021E494 /* vectorhelper.h in Headers */ = {isa = PBXBuildFile; fileRef = 27C668F71C9585230021E494 /* vectorhelper.h */; };
|
||||
27C669191C9585230021E494 /* vectorhelper.h in Headers */ = {isa = PBXBuildFile; fileRef = 27C668F71C9585230021E494 /* vectorhelper.h */; };
|
||||
27C6698B1C9585B80021E494 /* AbstractParseTreeVisitor.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 27C6696F1C9585B80021E494 /* AbstractParseTreeVisitor.cpp */; };
|
||||
27C6698C1C9585B80021E494 /* AbstractParseTreeVisitor.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 27C6696F1C9585B80021E494 /* AbstractParseTreeVisitor.cpp */; };
|
||||
27C6698D1C9585B80021E494 /* AbstractParseTreeVisitor.h in Headers */ = {isa = PBXBuildFile; fileRef = 27C669701C9585B80021E494 /* AbstractParseTreeVisitor.h */; };
|
||||
|
@ -692,7 +690,7 @@
|
|||
27C666A11C9584050021E494 /* TokenSource.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = TokenSource.h; path = ../../runtime/TokenSource.h; sourceTree = SOURCE_ROOT; };
|
||||
27C666A21C9584050021E494 /* TokenStream.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = TokenStream.cpp; path = ../../runtime/TokenStream.cpp; sourceTree = SOURCE_ROOT; };
|
||||
27C666A31C9584050021E494 /* TokenStream.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = TokenStream.h; path = ../../runtime/TokenStream.h; sourceTree = SOURCE_ROOT; };
|
||||
27C666A41C9584050021E494 /* TokenStreamRewriter.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = TokenStreamRewriter.cpp; path = ../../runtime/TokenStreamRewriter.cpp; 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; };
|
||||
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; };
|
||||
|
@ -702,7 +700,7 @@
|
|||
27C666AB1C9584050021E494 /* WritableToken.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = WritableToken.h; path = ../../runtime/WritableToken.h; sourceTree = SOURCE_ROOT; };
|
||||
27C667471C95846E0021E494 /* AbstractPredicateTransition.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = AbstractPredicateTransition.cpp; sourceTree = "<group>"; };
|
||||
27C667481C95846E0021E494 /* AbstractPredicateTransition.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AbstractPredicateTransition.h; sourceTree = "<group>"; };
|
||||
27C667491C95846E0021E494 /* ActionTransition.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ActionTransition.cpp; sourceTree = "<group>"; };
|
||||
27C667491C95846E0021E494 /* ActionTransition.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ActionTransition.cpp; sourceTree = "<group>"; wrapsLines = 0; };
|
||||
27C6674A1C95846E0021E494 /* ActionTransition.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ActionTransition.h; sourceTree = "<group>"; };
|
||||
27C6674B1C95846E0021E494 /* ArrayPredictionContext.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ArrayPredictionContext.cpp; sourceTree = "<group>"; };
|
||||
27C6674C1C95846E0021E494 /* ArrayPredictionContext.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ArrayPredictionContext.h; sourceTree = "<group>"; };
|
||||
|
@ -740,7 +738,7 @@
|
|||
27C6676C1C95846E0021E494 /* EmptyPredictionContext.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = EmptyPredictionContext.h; sourceTree = "<group>"; };
|
||||
27C6676D1C95846E0021E494 /* EpsilonTransition.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = EpsilonTransition.cpp; sourceTree = "<group>"; };
|
||||
27C6676E1C95846E0021E494 /* EpsilonTransition.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = EpsilonTransition.h; sourceTree = "<group>"; };
|
||||
27C6676F1C95846E0021E494 /* LexerATNConfig.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = LexerATNConfig.cpp; sourceTree = "<group>"; };
|
||||
27C6676F1C95846E0021E494 /* LexerATNConfig.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = LexerATNConfig.cpp; sourceTree = "<group>"; wrapsLines = 0; };
|
||||
27C667701C95846E0021E494 /* LexerATNConfig.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = LexerATNConfig.h; sourceTree = "<group>"; };
|
||||
27C667711C95846E0021E494 /* LexerATNSimulator.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = LexerATNSimulator.cpp; sourceTree = "<group>"; };
|
||||
27C667721C95846E0021E494 /* LexerATNSimulator.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = LexerATNSimulator.h; sourceTree = "<group>"; };
|
||||
|
@ -844,7 +842,6 @@
|
|||
27C668F41C9585230021E494 /* Strings.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Strings.h; sourceTree = "<group>"; };
|
||||
27C668F51C9585230021E494 /* guid.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = guid.cpp; sourceTree = "<group>"; };
|
||||
27C668F61C9585230021E494 /* guid.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = guid.h; sourceTree = "<group>"; };
|
||||
27C668F71C9585230021E494 /* vectorhelper.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = vectorhelper.h; sourceTree = "<group>"; };
|
||||
27C6696F1C9585B80021E494 /* AbstractParseTreeVisitor.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = AbstractParseTreeVisitor.cpp; sourceTree = "<group>"; };
|
||||
27C669701C9585B80021E494 /* AbstractParseTreeVisitor.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AbstractParseTreeVisitor.h; sourceTree = "<group>"; };
|
||||
27C669711C9585B80021E494 /* ErrorNode.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ErrorNode.cpp; sourceTree = "<group>"; };
|
||||
|
@ -1132,7 +1129,6 @@
|
|||
27C668F41C9585230021E494 /* Strings.h */,
|
||||
27C668F51C9585230021E494 /* guid.cpp */,
|
||||
27C668F61C9585230021E494 /* guid.h */,
|
||||
27C668F71C9585230021E494 /* vectorhelper.h */,
|
||||
27B4CE501C9F417D00E766E7 /* Any.h */,
|
||||
);
|
||||
path = support;
|
||||
|
@ -1496,7 +1492,6 @@
|
|||
27C6683F1C95846E0021E494 /* RuleTransition.h in Headers */,
|
||||
27C667231C9584050021E494 /* Recognizer.h in Headers */,
|
||||
27C6690D1C9585230021E494 /* StringBuilder.h in Headers */,
|
||||
27C669191C9585230021E494 /* vectorhelper.h in Headers */,
|
||||
27C667F11C95846E0021E494 /* EmptyPredictionContext.h in Headers */,
|
||||
27C667331C9584050021E494 /* TokenSource.h in Headers */,
|
||||
27C66A531C958AC10021E494 /* XPathRuleElement.h in Headers */,
|
||||
|
@ -1573,7 +1568,6 @@
|
|||
27C668E41C9584FA0021E494 /* Utils.h in Headers */,
|
||||
27C66A1C1C958AB30021E494 /* TextChunk.h in Headers */,
|
||||
27C667EC1C95846E0021E494 /* DecisionState.h in Headers */,
|
||||
27C669181C9585230021E494 /* vectorhelper.h in Headers */,
|
||||
27C667001C9584050021E494 /* LexerInterpreter.h in Headers */,
|
||||
27C667AC1C95846E0021E494 /* ActionTransition.h in Headers */,
|
||||
27C669911C9585B80021E494 /* ErrorNode.h in Headers */,
|
||||
|
@ -1777,7 +1771,7 @@
|
|||
37D727A21867AF1E007B6D10 /* Project object */ = {
|
||||
isa = PBXProject;
|
||||
attributes = {
|
||||
LastUpgradeCheck = 0720;
|
||||
LastUpgradeCheck = 0730;
|
||||
ORGANIZATIONNAME = "Dan McLaughlin";
|
||||
TargetAttributes = {
|
||||
27C66A661C9591280021E494 = {
|
||||
|
@ -2248,7 +2242,6 @@
|
|||
isa = XCBuildConfiguration;
|
||||
buildSettings = {
|
||||
ALWAYS_SEARCH_USER_PATHS = NO;
|
||||
ARCHS = "$(ARCHS_STANDARD_64_BIT)";
|
||||
CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x";
|
||||
CLANG_CXX_LIBRARY = "libc++";
|
||||
CLANG_ENABLE_OBJC_ARC = YES;
|
||||
|
@ -2288,7 +2281,6 @@
|
|||
isa = XCBuildConfiguration;
|
||||
buildSettings = {
|
||||
ALWAYS_SEARCH_USER_PATHS = NO;
|
||||
ARCHS = "$(ARCHS_STANDARD_64_BIT)";
|
||||
CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x";
|
||||
CLANG_CXX_LIBRARY = "libc++";
|
||||
CLANG_ENABLE_OBJC_ARC = YES;
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<Scheme
|
||||
LastUpgradeVersion = "0720"
|
||||
LastUpgradeVersion = "0730"
|
||||
version = "1.3">
|
||||
<BuildAction
|
||||
parallelizeBuildables = "YES"
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<Scheme
|
||||
LastUpgradeVersion = "0720"
|
||||
LastUpgradeVersion = "0730"
|
||||
version = "1.3">
|
||||
<BuildAction
|
||||
parallelizeBuildables = "YES"
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<Scheme
|
||||
LastUpgradeVersion = "0720"
|
||||
LastUpgradeVersion = "0730"
|
||||
version = "1.3">
|
||||
<BuildAction
|
||||
parallelizeBuildables = "YES"
|
||||
|
|
|
@ -43,28 +43,25 @@ ANTLRInputStream::ANTLRInputStream() {
|
|||
InitializeInstanceFields();
|
||||
}
|
||||
|
||||
ANTLRInputStream::ANTLRInputStream(const std::wstring &input) {
|
||||
InitializeInstanceFields();
|
||||
ANTLRInputStream::ANTLRInputStream(const std::wstring &input) : ANTLRInputStream() {
|
||||
this->data = input;
|
||||
this->n = (int)input.length();
|
||||
}
|
||||
|
||||
ANTLRInputStream::ANTLRInputStream(wchar_t data[], int numberOfActualCharsInArray) {
|
||||
InitializeInstanceFields();
|
||||
ANTLRInputStream::ANTLRInputStream(wchar_t data[], int numberOfActualCharsInArray) : ANTLRInputStream() {
|
||||
this->data = data;
|
||||
this->n = numberOfActualCharsInArray;
|
||||
}
|
||||
|
||||
|
||||
ANTLRInputStream::ANTLRInputStream(std::wifstream *r) {
|
||||
ANTLRInputStream::ANTLRInputStream(std::wifstream *r) : ANTLRInputStream() {
|
||||
}
|
||||
|
||||
|
||||
ANTLRInputStream::ANTLRInputStream(std::wifstream *r, int initialSize) {
|
||||
ANTLRInputStream::ANTLRInputStream(std::wifstream *r, int initialSize) : ANTLRInputStream() {
|
||||
}
|
||||
|
||||
ANTLRInputStream::ANTLRInputStream(std::wifstream *r, int initialSize, int readChunkSize) {
|
||||
InitializeInstanceFields();
|
||||
ANTLRInputStream::ANTLRInputStream(std::wifstream *r, int initialSize, int readChunkSize) : ANTLRInputStream() {
|
||||
load(r, initialSize, readChunkSize);
|
||||
}
|
||||
|
||||
|
@ -73,13 +70,15 @@ void ANTLRInputStream::load(std::wifstream *r, int size, int readChunkSize) {
|
|||
if (r == nullptr) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (size <= 0) {
|
||||
size = INITIAL_BUFFER_SIZE;
|
||||
}
|
||||
|
||||
if (readChunkSize <= 0) {
|
||||
readChunkSize = READ_BUFFER_SIZE;
|
||||
}
|
||||
// System.out.println("load "+size+" in chunks of "+readChunkSize);
|
||||
|
||||
try {
|
||||
// alloc initial buffer size.
|
||||
data = new wchar_t[size];
|
||||
|
@ -88,20 +87,17 @@ void ANTLRInputStream::load(std::wifstream *r, int size, int readChunkSize) {
|
|||
int p = 0;
|
||||
do {
|
||||
if (p + readChunkSize > (int)data.length()) { // overflow?
|
||||
// System.out.println("### overflow p="+p+", data.length="+data.length);
|
||||
data = antlrcpp::Arrays::copyOf(data, (int)data.length() * 2);
|
||||
}
|
||||
r->read(new wchar_t[100], p);
|
||||
|
||||
// System.out.println("read "+numRead+" chars; p was "+p+" is now "+(p+numRead));
|
||||
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;
|
||||
//System.out.println("n="+n);
|
||||
}
|
||||
catch (void *){
|
||||
catch (void *) {
|
||||
r->close();
|
||||
}
|
||||
|
||||
|
@ -117,10 +113,8 @@ void ANTLRInputStream::consume() {
|
|||
throw IllegalStateException(L"cannot consume EOF");
|
||||
}
|
||||
|
||||
//System.out.println("prev p="+p+", c="+(char)data[p]);
|
||||
if (p < n) {
|
||||
p++;
|
||||
//System.out.println("p moves to "+p+" (c='"+(char)data[p]+"')");
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -136,11 +130,9 @@ int ANTLRInputStream::LA(int i) {
|
|||
}
|
||||
|
||||
if ((p + i - 1) >= n) {
|
||||
//System.out.println("char LA("+i+")=EOF; p="+p);
|
||||
return IntStream::_EOF;
|
||||
}
|
||||
//System.out.println("char LA("+i+")="+(char)data[p+i-1]+"; p="+p);
|
||||
//System.out.println("LA("+i+"); p="+p+" n="+n+" data.length="+data.length);
|
||||
|
||||
return data[p + i - 1];
|
||||
}
|
||||
|
||||
|
@ -184,10 +176,8 @@ std::wstring ANTLRInputStream::getText(Interval *interval) {
|
|||
if (start >= n) {
|
||||
return L"";
|
||||
}
|
||||
// System.err.println("data: "+Arrays.toString(data)+", n="+n+
|
||||
// ", start="+start+
|
||||
// ", stop="+stop);
|
||||
return std::wstring(data, start, count);
|
||||
|
||||
return data.substr(start, count);
|
||||
}
|
||||
|
||||
std::string ANTLRInputStream::getSourceName() {
|
||||
|
@ -195,7 +185,7 @@ std::string ANTLRInputStream::getSourceName() {
|
|||
}
|
||||
|
||||
std::wstring ANTLRInputStream::toString() {
|
||||
return std::wstring(data);
|
||||
return data;
|
||||
}
|
||||
|
||||
void ANTLRInputStream::InitializeInstanceFields() {
|
||||
|
|
|
@ -38,10 +38,8 @@ namespace antlr {
|
|||
namespace v4 {
|
||||
namespace runtime {
|
||||
|
||||
/// <summary>
|
||||
/// Vacuum all input from a <seealso cref="Reader"/>/<seealso cref="InputStream"/> and then treat it
|
||||
/// like a {@code char[]} buffer. Can also pass in a <seealso cref="String"/> or
|
||||
/// {@code char[]} to use.
|
||||
/// 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>
|
||||
|
|
|
@ -31,7 +31,6 @@
|
|||
|
||||
#include "WritableToken.h"
|
||||
#include "Lexer.h"
|
||||
#include "vectorhelper.h"
|
||||
#include "RuleContext.h"
|
||||
#include "Interval.h"
|
||||
#include "StringBuilder.h"
|
||||
|
@ -90,7 +89,7 @@ void BufferedTokenStream::consume() {
|
|||
bool BufferedTokenStream::sync(int i) {
|
||||
assert(i >= 0);
|
||||
size_t n = i - tokens.size() + 1; // how many more elements we need?
|
||||
//System.out.println("sync("+i+") needs "+n);
|
||||
|
||||
if (n > 0) {
|
||||
size_t fetched = fetch((int)n);
|
||||
return fetched >= n;
|
||||
|
@ -398,7 +397,7 @@ void BufferedTokenStream::fill() {
|
|||
}
|
||||
|
||||
void BufferedTokenStream::InitializeInstanceFields() {
|
||||
tokens = antlrcpp::VectorHelper::VectorWithReservedSize<Token*>(100);
|
||||
tokens.reserve(100);
|
||||
p = -1;
|
||||
fetchedEOF = false;
|
||||
}
|
||||
|
|
|
@ -38,15 +38,14 @@ namespace antlr {
|
|||
namespace v4 {
|
||||
namespace runtime {
|
||||
|
||||
/// <summary>
|
||||
/// A source of characters for an ANTLR lexer. </summary>
|
||||
/// A source of characters for an ANTLR lexer.
|
||||
class CharStream : public IntStream {
|
||||
/// <summary>
|
||||
|
||||
/// 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
|
||||
/// specified {@code interval} lies entirely within a marked range. For more
|
||||
/// information about marked ranges, see <seealso cref="IntStream#mark"/>.
|
||||
/// </summary>
|
||||
/// specified interval lies entirely within a marked range. For more
|
||||
/// information about marked ranges, see IntStream::mark.
|
||||
///
|
||||
/// <param name="interval"> an interval within the stream </param>
|
||||
/// <returns> the text of the specified interval
|
||||
/// </returns>
|
||||
|
|
|
@ -39,9 +39,7 @@ CommonTokenStream::CommonTokenStream(TokenSource *tokenSource) : BufferedTokenSt
|
|||
InitializeInstanceFields();
|
||||
}
|
||||
|
||||
CommonTokenStream::CommonTokenStream(TokenSource *tokenSource, int channel)
|
||||
: BufferedTokenStream(tokenSource)
|
||||
{
|
||||
CommonTokenStream::CommonTokenStream(TokenSource *tokenSource, int channel) : BufferedTokenStream(tokenSource) {
|
||||
this->channel = channel;
|
||||
}
|
||||
|
||||
|
|
|
@ -47,7 +47,7 @@
|
|||
|
||||
using namespace org::antlr::v4::runtime;
|
||||
|
||||
std::map<std::wstring, atn::ATN*> * Parser::bypassAltsAtnCache = new std::map<std::wstring, atn::ATN*>();
|
||||
std::map<std::wstring, atn::ATN *> Parser::bypassAltsAtnCache;
|
||||
|
||||
Parser::TraceListener::TraceListener(Parser *outerInstance) : outerInstance(outerInstance) {
|
||||
}
|
||||
|
@ -98,11 +98,6 @@ void Parser::TrimToSizeListener::exitEveryRule(ParserRuleContext *ctx) {
|
|||
Parser::Parser(TokenStream* input) {
|
||||
InitializeInstanceFields();
|
||||
setInputStream(input);
|
||||
|
||||
// TODO: Initialize this safely and handle concurrent accesses.
|
||||
// TODO: For now treat this as a member variable but it should be shared across instances for speed.
|
||||
Parser::bypassAltsAtnCache =
|
||||
new std::map<std::wstring, atn::ATN*>();
|
||||
}
|
||||
|
||||
void Parser::reset() {
|
||||
|
@ -240,18 +235,24 @@ TokenFactory<CommonToken*> *Parser::getTokenFactory() {
|
|||
|
||||
atn::ATN *Parser::getATNWithBypassAlts() {
|
||||
std::wstring serializedAtn = getSerializedATN();
|
||||
if (serializedAtn == L"") {
|
||||
if (serializedAtn.empty()) {
|
||||
throw UnsupportedOperationException(L"The current parser does not support an ATN with bypass alternatives.");
|
||||
}
|
||||
|
||||
if (bypassAltsAtnCache != nullptr) {
|
||||
{
|
||||
std::lock_guard<std::mutex> lck(mtx);
|
||||
atn::ATN *result = bypassAltsAtnCache->at(serializedAtn);
|
||||
|
||||
// XXX: using the entire serialized ATN as key into the map is a big resource waste.
|
||||
// How large can that thing become? Not only may the storage become an issue but also
|
||||
// creating a hash over a large string.
|
||||
atn::ATN *result = bypassAltsAtnCache[serializedAtn];
|
||||
if (result == nullptr) {
|
||||
atn::ATNDeserializationOptions *deserializationOptions = new atn::ATNDeserializationOptions();
|
||||
deserializationOptions->setGenerateRuleBypassTransitions(true);
|
||||
result = (new atn::ATNDeserializer(deserializationOptions))->deserialize(serializedAtn);
|
||||
bypassAltsAtnCache->emplace(serializedAtn, result);
|
||||
|
||||
atn::ATNDeserializer deserializer(deserializationOptions);
|
||||
result = deserializer.deserialize(serializedAtn);
|
||||
bypassAltsAtnCache.emplace(serializedAtn, result);
|
||||
}
|
||||
|
||||
return result;
|
||||
|
@ -607,3 +608,4 @@ void Parser::InitializeInstanceFields() {
|
|||
_buildParseTrees = true;
|
||||
_syntaxErrors = 0;
|
||||
}
|
||||
|
||||
|
|
|
@ -79,7 +79,7 @@ namespace runtime {
|
|||
/// </summary>
|
||||
/// <seealso cref= ATNDeserializationOptions#isGenerateRuleBypassTransitions() </seealso>
|
||||
private:
|
||||
static std::map<std::wstring, atn::ATN*> * bypassAltsAtnCache;
|
||||
static std::map<std::wstring, atn::ATN *> bypassAltsAtnCache;
|
||||
|
||||
/// <summary>
|
||||
/// The error handling strategy for the parser. The default value is a new
|
||||
|
|
|
@ -47,7 +47,6 @@ RuleContext::RuleContext() {
|
|||
RuleContext::RuleContext(RuleContext *parent, int invokingState) {
|
||||
InitializeInstanceFields();
|
||||
this->parent = parent;
|
||||
//if ( parent!=null ) System.out.println("invoke "+stateNumber+" from "+parent);
|
||||
this->invokingState = invokingState;
|
||||
}
|
||||
|
||||
|
|
|
@ -29,7 +29,6 @@
|
|||
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include "vectorhelper.h"
|
||||
#include "Exceptions.h"
|
||||
#include "Interval.h"
|
||||
#include "Token.h"
|
||||
|
@ -106,7 +105,7 @@ void TokenStreamRewriter::ReplaceOp::InitializeInstanceFields() {
|
|||
const std::wstring TokenStreamRewriter::DEFAULT_PROGRAM_NAME = L"default";
|
||||
|
||||
TokenStreamRewriter::TokenStreamRewriter(TokenStream *tokens) : tokens(tokens), programs(new std::map<std::wstring, std::vector<RewriteOperation*>>()), lastRewriteTokenIndexes(new std::map<std::wstring, int>()) {
|
||||
programs->insert(std::pair<std::wstring, std::vector<RewriteOperation*>>(DEFAULT_PROGRAM_NAME, antlrcpp::VectorHelper::VectorWithReservedSize<RewriteOperation*>(PROGRAM_INIT_SIZE)));
|
||||
programs->insert({ DEFAULT_PROGRAM_NAME, std::vector<RewriteOperation*>(PROGRAM_INIT_SIZE) });
|
||||
}
|
||||
|
||||
TokenStream *TokenStreamRewriter::getTokenStream() {
|
||||
|
@ -118,9 +117,9 @@ void TokenStreamRewriter::rollback(int instructionIndex) {
|
|||
}
|
||||
|
||||
void TokenStreamRewriter::rollback(const std::wstring &programName, int instructionIndex) {
|
||||
std::vector<RewriteOperation*> is = programs->at(programName);
|
||||
std::vector<RewriteOperation*> is = (*programs)[programName];
|
||||
if (is.size() > 0) {
|
||||
programs->insert(std::pair<std::wstring, std::vector<RewriteOperation*> >(programName, antlrcpp::VectorHelper::VectorSublist(is, MIN_TOKEN_INDEX, instructionIndex)));
|
||||
programs->insert({ programName, std::vector<RewriteOperation*>(is.begin() + MIN_TOKEN_INDEX, is.begin() + instructionIndex) });
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -246,7 +245,7 @@ std::vector<TokenStreamRewriter::RewriteOperation*> TokenStreamRewriter::getProg
|
|||
}
|
||||
|
||||
std::vector<TokenStreamRewriter::RewriteOperation*> TokenStreamRewriter::initializeProgram(const std::wstring &name) {
|
||||
std::vector<TokenStreamRewriter::RewriteOperation*> is = antlrcpp::VectorHelper::VectorWithReservedSize<RewriteOperation*>(PROGRAM_INIT_SIZE);
|
||||
std::vector<TokenStreamRewriter::RewriteOperation*> is(PROGRAM_INIT_SIZE);
|
||||
programs->insert({ name, is });
|
||||
return is;
|
||||
}
|
||||
|
|
|
@ -531,8 +531,9 @@ dfa::DFAState *LexerATNSimulator::addDFAState(ATNConfigSet *configs) {
|
|||
|
||||
dfa::DFA *dfa = _decisionToDFA[mode];
|
||||
|
||||
if(true) {
|
||||
{
|
||||
std::lock_guard<std::mutex> lck(mtx);
|
||||
|
||||
dfa::DFAState *existing = dfa->states->at(proposed);
|
||||
if (existing != nullptr) {
|
||||
return existing;
|
||||
|
|
|
@ -1,31 +0,0 @@
|
|||
#pragma once
|
||||
|
||||
//----------------------------------------------------------------------------------------
|
||||
// Copyright © 2007 - 2013 Tangible Software Solutions Inc.
|
||||
// This class can be used by anyone provided that the copyright notice remains intact.
|
||||
//
|
||||
// This class is used to simulate list constructor calls which reserve the list size.
|
||||
//----------------------------------------------------------------------------------------
|
||||
#include <vector>
|
||||
namespace antlrcpp {
|
||||
|
||||
class VectorHelper
|
||||
{
|
||||
public:
|
||||
template<typename T>
|
||||
static std::vector<T> VectorWithReservedSize(int size)
|
||||
{
|
||||
std::vector<T> vector;
|
||||
vector.reserve(size);
|
||||
return vector;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
static std::vector<T> VectorSublist(const std::vector<T>& vec, int start, int end)
|
||||
{
|
||||
std::vector<T> vector(vec.begin() + start, vec.begin() + end);
|
||||
return vector;
|
||||
}
|
||||
};
|
||||
|
||||
}
|
Loading…
Reference in New Issue