80 typedef ANTLR_USE_NAMESPACE(std)vector<antlr::RefTokenWithIndex> token_list;
81 static const char* DEFAULT_PROGRAM_NAME;
82#ifndef NO_STATIC_CONSTS
83 static const size_t MIN_TOKEN_INDEX;
84 static const int PROGRAM_INIT_SIZE;
88 PROGRAM_INIT_SIZE = 100
93 tokenToStream( ANTLR_USE_NAMESPACE(std)ostream& o ) : out(o) {}
94 template <
typename T>
void operator() (
const T& t ) {
97 ANTLR_USE_NAMESPACE(std)ostream& out;
103 : index(idx), text(txt)
113 virtual size_t execute( ANTLR_USE_NAMESPACE(std)ostream& ) {
116 virtual size_t getIndex()
const {
119 virtual const char* type()
const {
120 return "RewriteOperation";
124 ANTLR_USE_NAMESPACE(std)
string text;
128 ANTLR_USE_NAMESPACE(std)ostream& out;
143 InsertBeforeOp(
size_t index,
const ANTLR_USE_NAMESPACE(std)
string& text )
148 virtual size_t execute( ANTLR_USE_NAMESPACE(std)ostream& out )
153 virtual const char* type()
const {
154 return "InsertBeforeOp";
161 ReplaceOp(
size_t from,
size_t to, ANTLR_USE_NAMESPACE(std)
string text)
167 virtual size_t execute( ANTLR_USE_NAMESPACE(std)ostream& out ) {
171 virtual const char* type()
const {
184 virtual const char* type()
const {
195 void rollback(
size_t instructionIndex) {
196 rollback(DEFAULT_PROGRAM_NAME, instructionIndex);
203 void rollback(
const ANTLR_USE_NAMESPACE(std)
string& programName,
204 size_t instructionIndex );
206 void deleteProgram() {
207 deleteProgram(DEFAULT_PROGRAM_NAME);
212 rollback(programName, MIN_TOKEN_INDEX);
216 const ANTLR_USE_NAMESPACE(std)
string& text )
218 insertAfter(DEFAULT_PROGRAM_NAME, t, text);
221 void insertAfter(
size_t index,
const ANTLR_USE_NAMESPACE(std)
string& text) {
222 insertAfter(DEFAULT_PROGRAM_NAME,
index, text);
225 void insertAfter(
const ANTLR_USE_NAMESPACE(std)
string& programName,
227 const ANTLR_USE_NAMESPACE(std)
string& text )
229 insertAfter(programName, t->getIndex(), text);
232 void insertAfter(
const ANTLR_USE_NAMESPACE(std)
string& programName,
234 const ANTLR_USE_NAMESPACE(std)
string& text )
237 insertBefore(programName,
index+1, text);
240 void insertBefore( RefTokenWithIndex t,
241 const ANTLR_USE_NAMESPACE(std)
string& text )
244 insertBefore(DEFAULT_PROGRAM_NAME, t, text);
247 void insertBefore(
size_t index,
const ANTLR_USE_NAMESPACE(std)
string& text) {
248 insertBefore(DEFAULT_PROGRAM_NAME,
index, text);
251 void insertBefore(
const ANTLR_USE_NAMESPACE(std)
string& programName,
253 const ANTLR_USE_NAMESPACE(std)
string& text )
255 insertBefore(programName, t->getIndex(), text);
258 void insertBefore(
const ANTLR_USE_NAMESPACE(std)
string& programName,
260 const ANTLR_USE_NAMESPACE(std)
string& text )
265 void replace(
size_t index,
const ANTLR_USE_NAMESPACE(std)
string& text)
267 replace(DEFAULT_PROGRAM_NAME,
index,
index, text);
270 void replace(
size_t from,
size_t to,
271 const ANTLR_USE_NAMESPACE(std)
string& text)
273 replace(DEFAULT_PROGRAM_NAME, from, to, text);
276 void replace( RefTokenWithIndex indexT,
277 const ANTLR_USE_NAMESPACE(std)
string& text )
279 replace(DEFAULT_PROGRAM_NAME, indexT->getIndex(), indexT->getIndex(), text);
282 void replace( RefTokenWithIndex from,
283 RefTokenWithIndex to,
284 const ANTLR_USE_NAMESPACE(std)
string& text )
286 replace(DEFAULT_PROGRAM_NAME, from, to, text);
289 void replace(
const ANTLR_USE_NAMESPACE(std)
string& programName,
290 size_t from,
size_t to,
291 const ANTLR_USE_NAMESPACE(std)
string& text )
296 void replace(
const ANTLR_USE_NAMESPACE(std)
string& programName,
297 RefTokenWithIndex from,
298 RefTokenWithIndex to,
299 const ANTLR_USE_NAMESPACE(std)
string& text )
307 void remove(
size_t index) {
311 void remove(
size_t from,
size_t to) {
312 remove(DEFAULT_PROGRAM_NAME, from, to);
315 void remove(RefTokenWithIndex indexT) {
316 remove(DEFAULT_PROGRAM_NAME, indexT, indexT);
319 void remove(RefTokenWithIndex from, RefTokenWithIndex to) {
320 remove(DEFAULT_PROGRAM_NAME, from, to);
323 void remove(
const ANTLR_USE_NAMESPACE(std)
string& programName,
324 size_t from,
size_t to)
326 replace(programName,from,to,
"");
329 void remove(
const ANTLR_USE_NAMESPACE(std)
string& programName,
330 RefTokenWithIndex from, RefTokenWithIndex to )
332 replace(programName,from,to,
"");
335 void discard(
int ttype) {
339 RefToken getToken(
size_t i )
341 return RefToken(
tokens.at(i));
344 size_t getTokenStreamSize()
const {
348 void originalToStream( ANTLR_USE_NAMESPACE(std)ostream& out )
const {
349 ANTLR_USE_NAMESPACE(std)for_each(
tokens.begin(),
tokens.end(), tokenToStream(out) );
352 void originalToStream( ANTLR_USE_NAMESPACE(std)ostream& out,
353 size_t start,
size_t end )
const;
355 void toStream( ANTLR_USE_NAMESPACE(std)ostream& out )
const {
356 toStream( out, MIN_TOKEN_INDEX, getTokenStreamSize());
359 void toStream( ANTLR_USE_NAMESPACE(std)ostream& out,
360 const ANTLR_USE_NAMESPACE(std)
string& programName )
const
362 toStream( out, programName, MIN_TOKEN_INDEX, getTokenStreamSize());
365 void toStream( ANTLR_USE_NAMESPACE(std)ostream& out,
366 size_t start,
size_t end )
const
368 toStream(out, DEFAULT_PROGRAM_NAME, start, end);
371 void toStream( ANTLR_USE_NAMESPACE(std)ostream& out,
372 const ANTLR_USE_NAMESPACE(std)
string& programName,
373 size_t firstToken,
size_t lastToken )
const;
375 void toDebugStream( ANTLR_USE_NAMESPACE(std)ostream& out )
const {
376 toDebugStream( out, MIN_TOKEN_INDEX, getTokenStreamSize());
379 void toDebugStream( ANTLR_USE_NAMESPACE(std)ostream& out,
380 size_t start,
size_t end )
const;
382 size_t getLastRewriteTokenIndex()
const {
383 return getLastRewriteTokenIndex(DEFAULT_PROGRAM_NAME);
391 program_map::const_iterator rewrites =
programs.find(programName);
399 operation_list::const_iterator last = prog.end();
401 return (*last)->getIndex();
414 RewriteOperation* op );