diff --git a/SqlScriptDom/GenerateFiles.props b/SqlScriptDom/GenerateFiles.props
index ea6f573..48e8717 100644
--- a/SqlScriptDom/GenerateFiles.props
+++ b/SqlScriptDom/GenerateFiles.props
@@ -60,8 +60,8 @@
-
-
+
+
@@ -70,8 +70,8 @@
-
-
+
+
@@ -80,4 +80,4 @@
-
\ No newline at end of file
+
diff --git a/SqlScriptDom/antlr/antlr/ByteBuffer.cs b/SqlScriptDom/antlr/antlr/ByteBuffer.cs
index 6410067..bd860d9 100644
--- a/SqlScriptDom/antlr/antlr/ByteBuffer.cs
+++ b/SqlScriptDom/antlr/antlr/ByteBuffer.cs
@@ -62,7 +62,7 @@ override public void fill(int amount)
// {
syncConsume();
// Fill the buffer sufficiently to hold needed characters
- int bytesToRead = (amount + markerOffset) - queue.Count;
+ int bytesToRead = (amount + markerOffset) - queue.nbrEntries;
int c;
while (bytesToRead > 0)
@@ -72,15 +72,15 @@ override public void fill(int amount)
for (int i = 0; i < c; i++)
{
// Append the next character
- queue.Add(unchecked((char) buf[i]));
+ queue.append(unchecked((char) buf[i]));
}
- bytesToRead -= c;
- if (c < BUF_SIZE)
+ bytesToRead -= c;
+ if (c < BUF_SIZE)
{
- while (bytesToRead-- > 0)
- {
- queue.Add(CharScanner.EOF_CHAR);
- }
+ while (bytesToRead-- > 0)
+ {
+ queue.append(CharScanner.EOF_CHAR);
+ }
break;
}
}
@@ -91,4 +91,4 @@ override public void fill(int amount)
// }
}
}
-}
\ No newline at end of file
+}
diff --git a/SqlScriptDom/antlr/antlr/CharBuffer.cs b/SqlScriptDom/antlr/antlr/CharBuffer.cs
index 687e413..f7f4bf9 100644
--- a/SqlScriptDom/antlr/antlr/CharBuffer.cs
+++ b/SqlScriptDom/antlr/antlr/CharBuffer.cs
@@ -61,7 +61,7 @@ override public void fill(int amount)
//{
syncConsume();
// Fill the buffer sufficiently to hold needed characters
- int charsToRead = (amount + markerOffset) - queue.Count;
+ int charsToRead = (amount + markerOffset) - queue.nbrEntries;
int c;
while (charsToRead > 0)
@@ -71,16 +71,16 @@ override public void fill(int amount)
for (int i = 0; i < c; i++)
{
// Append the next character
- queue.Add(buf[i]);
+ queue.append(buf[i]);
}
- charsToRead -= c;
- if (c < BUF_SIZE)
+ charsToRead -= c;
+ if (c < BUF_SIZE)
{
- while (charsToRead-- > 0)
- {
- queue.Add(CharScanner.EOF_CHAR);
- }
- break;
+ while (charsToRead-- > 0)
+ {
+ queue.append(CharScanner.EOF_CHAR);
+ }
+ break;
}
}
//}
@@ -90,4 +90,4 @@ override public void fill(int amount)
//}
}
}
-}
\ No newline at end of file
+}
diff --git a/SqlScriptDom/antlr/antlr/CharQueue.cs b/SqlScriptDom/antlr/antlr/CharQueue.cs
index 5350655..dd79caa 100644
--- a/SqlScriptDom/antlr/antlr/CharQueue.cs
+++ b/SqlScriptDom/antlr/antlr/CharQueue.cs
@@ -20,8 +20,8 @@ namespace antlr
/*A circular buffer object used by CharBuffer */
internal class CharQueue
{
- /*Physical circular buffer of tokens */
- protected internal char[] buffer;
+ /*Physical circular buffer of character values and the EOF sentinel */
+ protected internal int[] buffer;
/*buffer.length-1 for quick modulos */
private int sizeLessOne;
/*physical index of front token */
@@ -54,7 +54,7 @@ public CharQueue(int minSize)
/*Add token to end of the queue
* @param tok The token to add
*/
- public void append(char tok)
+ public void append(int tok)
{
if (nbrEntries == buffer.Length)
{
@@ -67,7 +67,7 @@ public void append(char tok)
/*Fetch a token from the queue by index
* @param idx The index of the token to fetch, where zero is the token at the front of the queue
*/
- public char elementAt(int idx)
+ public int elementAt(int idx)
{
return buffer[(offset + idx) & sizeLessOne];
}
@@ -75,7 +75,7 @@ public char elementAt(int idx)
/*Expand the token buffer by doubling its capacity */
private void expand()
{
- char[] newBuffer = new char[buffer.Length * 2];
+ int[] newBuffer = new int[buffer.Length * 2];
// Copy the contents to the new buffer
// Note that this will store the first logical item in the
// first physical array element.
@@ -95,7 +95,7 @@ private void expand()
public virtual void init(int size)
{
// Allocate buffer
- buffer = new char[size];
+ buffer = new int[size];
// Other initialization
sizeLessOne = size - 1;
offset = 0;
@@ -116,5 +116,12 @@ public void removeFirst()
offset = (offset + 1) & sizeLessOne;
nbrEntries--;
}
+
+ /* Remove chars from the front of the queue */
+ public void remove(int count)
+ {
+ offset = (offset + count) & sizeLessOne;
+ nbrEntries -= count;
+ }
}
-}
\ No newline at end of file
+}
diff --git a/SqlScriptDom/antlr/antlr/InputBuffer.cs b/SqlScriptDom/antlr/antlr/InputBuffer.cs
index 5f3eb42..4bc424a 100644
--- a/SqlScriptDom/antlr/antlr/InputBuffer.cs
+++ b/SqlScriptDom/antlr/antlr/InputBuffer.cs
@@ -1,7 +1,6 @@
namespace antlr
{
using System;
- using ArrayList = System.Collections.ArrayList;
using StringBuilder = System.Text.StringBuilder;
/*ANTLR Translator Generator
@@ -48,12 +47,14 @@ internal abstract class InputBuffer
protected internal int numToConsume = 0;
// Circular queue
- protected ArrayList queue;
+ protected CharQueue queue;
+
+ private const int CompactionThreshold = 1024;
/*Create an input buffer */
public InputBuffer()
{
- queue = new ArrayList();
+ queue = new CharQueue(16);
}
/*This method updates the state of the input buffer so that
@@ -81,11 +82,11 @@ public virtual string getLAChars()
{
StringBuilder la = new StringBuilder();
- // copy buffer contents to array before looping thru contents (it's usually faster)
- char[] fastBuf = new char[queue.Count-markerOffset];
- queue.CopyTo(fastBuf, markerOffset);
+ for (int i = markerOffset; i < queue.nbrEntries; i++)
+ {
+ la.Append((char)queue.elementAt(i));
+ }
- la.Append(fastBuf);
return la.ToString();
}
@@ -93,11 +94,11 @@ public virtual string getMarkedChars()
{
StringBuilder marked = new StringBuilder();
- // copy buffer contents to array before looping thru contents (it's usually faster)
- char[] fastBuf = new char[queue.Count-markerOffset];
- queue.CopyTo(fastBuf, markerOffset);
+ for (int i = markerOffset; i < queue.nbrEntries; i++)
+ {
+ marked.Append((char)queue.elementAt(i));
+ }
- marked.Append(fastBuf);
return marked.ToString();
}
@@ -113,7 +114,7 @@ public virtual int LA(int i)
// Entries are boxed char values for real input and a boxed int sentinel
// (CharScanner.EOF_CHAR) for end-of-input; Convert.ToInt32 handles both so a
// real U+FFFF (65535) stays distinct from the EOF sentinel (65536).
- return Convert.ToInt32(queue[markerOffset + i - 1]);
+ return queue.elementAt(markerOffset + i - 1);
}
/*Return an integer marker that can be used to rewind the buffer to
@@ -143,26 +144,25 @@ public virtual void reset()
nMarkers = 0;
markerOffset = 0;
numToConsume = 0;
- queue.Clear();
+ queue.reset();
}
/*Sync up deferred consumption */
protected internal virtual void syncConsume()
{
- if (numToConsume > 0)
+ if (numToConsume == 0)
+ {
+ return;
+ }
+
+ markerOffset += numToConsume;
+ numToConsume = 0;
+
+ if (nMarkers == 0 && markerOffset >= CompactionThreshold)
{
- if (nMarkers > 0)
- {
- // guess mode -- leave leading characters and bump offset.
- markerOffset += numToConsume;
- }
- else
- {
- // normal mode -- remove "consumed" characters from buffer
- queue.RemoveRange(0, numToConsume);
- }
- numToConsume = 0;
+ queue.remove(markerOffset);
+ markerOffset = 0;
}
}
}
-}
\ No newline at end of file
+}