1 |
/* ANTLR Translator Generator |
2 |
* Project led by Terence Parr at http://www.jGuru.com |
3 |
* Software rights: http://www.antlr.org/license.html |
4 |
* |
5 |
* $Id$ |
6 |
*/ |
7 |
|
8 |
#include "antlr/config.hpp" |
9 |
#include "antlr/InputBuffer.hpp" |
10 |
#include <iostream> |
11 |
#ifdef IS_MPI |
12 |
#include "mpi.h" |
13 |
#endif |
14 |
|
15 |
|
16 |
#ifdef ANTLR_CXX_SUPPORTS_NAMESPACE |
17 |
namespace antlr { |
18 |
#endif |
19 |
|
20 |
/** Ensure that the character buffer is sufficiently full */ |
21 |
void InputBuffer::fill(unsigned int amount) |
22 |
{ |
23 |
syncConsume(); |
24 |
|
25 |
// Fill the buffer sufficiently to hold needed characters |
26 |
while (queue.entries() < amount + markerOffset) |
27 |
{ |
28 |
// Append the next character |
29 |
queue.append(getChar()); |
30 |
} |
31 |
} |
32 |
|
33 |
/** get the current lookahead characters as a string |
34 |
* @warning it may treat 0 and EOF values wrong |
35 |
*/ |
36 |
ANTLR_USE_NAMESPACE(std)string InputBuffer::getLAChars( void ) const |
37 |
{ |
38 |
ANTLR_USE_NAMESPACE(std)string ret; |
39 |
|
40 |
for(unsigned int i = markerOffset; i < queue.entries(); i++) |
41 |
ret += queue.elementAt(i); |
42 |
|
43 |
return ret; |
44 |
} |
45 |
|
46 |
/** get the current marked characters as a string |
47 |
* @warning it may treat 0 and EOF values wrong |
48 |
*/ |
49 |
ANTLR_USE_NAMESPACE(std)string InputBuffer::getMarkedChars( void ) const |
50 |
{ |
51 |
ANTLR_USE_NAMESPACE(std)string ret; |
52 |
|
53 |
for(unsigned int i = 0; i < markerOffset; i++) |
54 |
ret += queue.elementAt(i); |
55 |
|
56 |
return ret; |
57 |
} |
58 |
|
59 |
/** Return an integer marker that can be used to rewind the buffer to |
60 |
* its current state. |
61 |
*/ |
62 |
unsigned int InputBuffer::mark() |
63 |
{ |
64 |
syncConsume(); |
65 |
nMarkers++; |
66 |
return markerOffset; |
67 |
} |
68 |
|
69 |
/** Rewind the character buffer to a marker. |
70 |
* @param mark Marker returned previously from mark() |
71 |
*/ |
72 |
void InputBuffer::rewind(unsigned int mark) |
73 |
{ |
74 |
syncConsume(); |
75 |
markerOffset = mark; |
76 |
nMarkers--; |
77 |
} |
78 |
|
79 |
unsigned int InputBuffer::entries() const |
80 |
{ |
81 |
//assert(queue.entries() >= markerOffset); |
82 |
return queue.entries() - markerOffset; |
83 |
} |
84 |
|
85 |
#ifdef ANTLR_CXX_SUPPORTS_NAMESPACE |
86 |
} |
87 |
#endif |