+2008-09-10 Frank Ch. Eigler <fche@elastic.org>
+
+ * parse.cxx, parse.h: Rewrite scanner lookahead data structure
+ to a simple ~fixed vector.
+
2008-09-10 Frank Ch. Eigler <fche@elastic.org>
PR6876: translator speedup for many $vars
#include "util.h"
#include <iostream>
+
#include <fstream>
#include <cctype>
#include <cstdlib>
#include <sstream>
#include <cstring>
#include <cctype>
+#include <iterator>
+
extern "C" {
#include <fnmatch.h>
}
lexer::lexer (istream& i, const string& in, systemtap_session& s):
- input (i), input_name (in), cursor_suspend_count(0),
+ input (i), input_name (in),
+ input_pointer (0), cursor_suspend_count(0),
cursor_line (1), cursor_column (1), session(s)
-{ }
+{
+ char c;
+ while(input.get(c))
+ input_contents.push_back(c);
+}
int
lexer::input_peek (unsigned n)
{
- while (lookahead.size() <= n)
- {
- int c = input.get ();
- lookahead.push_back (input ? c : -1);
- }
- return lookahead[n];
+ if (input_contents.size() > (input_pointer + n))
+ return (int)(unsigned char)input_contents[input_pointer+n];
+ else
+ return -1;
}
lexer::input_get ()
{
int c = input_peek (0);
- lookahead.erase (lookahead.begin ());
+ input_pointer ++;
if (c < 0) return c; // EOF
cursor_column ++;
}
+ // clog << "[" << (char)c << "]";
return c;
}
void
lexer::input_put (const string& chars)
{
- // clog << "[put:" << chars << "]";
- for (int i=chars.size()-1; i>=0; i--)
- {
- int c = chars[i];
- lookahead.insert (lookahead.begin(), c);
- cursor_suspend_count ++;
- }
+ // clog << "[put:" << chars << " @" << input_pointer << "]";
+ input_contents.insert (input_contents.begin() + input_pointer, chars.begin(), chars.end());
+ cursor_suspend_count += chars.size();
}
int input_peek (unsigned n=0);
std::istream& input;
std::string input_name;
- std::vector<int> lookahead;
+ std::vector<char> input_contents;
+ int input_pointer; // index into input_contents
unsigned cursor_suspend_count;
unsigned cursor_line;
unsigned cursor_column;