No one needs to see the dirty laundry...
* parse.h (class parser, class lexer): Move to parse.cxx.
(parser::parse -> parse): Split the static interface from the class.
if (s.script_file == "-")
{
- s.user_file = parser::parse (s, cin, s.guru_mode);
+ s.user_file = parse (s, cin, s.guru_mode);
user_file_stat_rc = fstat (STDIN_FILENO, & user_file_stat);
}
else if (s.script_file != "")
{
- s.user_file = parser::parse (s, s.script_file, s.guru_mode);
+ s.user_file = parse (s, s.script_file, s.guru_mode);
user_file_stat_rc = stat (s.script_file.c_str(), & user_file_stat);
}
else
{
istringstream ii (s.cmdline_script);
- s.user_file = parser::parse (s, ii, s.guru_mode);
+ s.user_file = parse (s, ii, s.guru_mode);
}
if (s.user_file == 0)
// syntax errors already printed
break;
// XXX: privilege only for /usr/share/systemtap?
- stapfile* f = parser::parse (s, globbuf.gl_pathv[j], true);
+ stapfile* f = parse (s, globbuf.gl_pathv[j], true);
if (f == 0)
s.print_warning("tapset '" + string(globbuf.gl_pathv[j])
+ "' has errors, and will be skipped.");
using namespace std;
+
+class lexer
+{
+public:
+ token* scan (bool wildcard=false);
+ lexer (istream&, const string&, systemtap_session&);
+ void set_current_file (stapfile* f);
+
+private:
+ inline int input_get ();
+ inline int input_peek (unsigned n=0);
+ void input_put (const string&, const token*);
+ string input_name;
+ string input_contents;
+ const char *input_pointer; // index into input_contents
+ const char *input_end;
+ unsigned cursor_suspend_count;
+ unsigned cursor_suspend_line;
+ unsigned cursor_suspend_column;
+ unsigned cursor_line;
+ unsigned cursor_column;
+ systemtap_session& session;
+ stapfile* current_file;
+ static set<string> keywords;
+};
+
+
+class parser
+{
+public:
+ parser (systemtap_session& s, istream& i, bool p);
+ parser (systemtap_session& s, const string& n, bool p);
+ ~parser ();
+
+ stapfile* parse ();
+
+private:
+ typedef enum {
+ PP_NONE,
+ PP_KEEP_THEN,
+ PP_SKIP_THEN,
+ PP_KEEP_ELSE,
+ PP_SKIP_ELSE,
+ } pp_state_t;
+
+ systemtap_session& session;
+ string input_name;
+ istream* free_input;
+ lexer input;
+ bool privileged;
+ parse_context context;
+
+ // preprocessing subordinate
+ vector<pair<const token*, pp_state_t> > pp_state;
+ const token* scan_pp (bool wildcard=false);
+ const token* skip_pp ();
+
+ // scanning state
+ const token* last ();
+ const token* next (bool wildcard=false);
+ const token* peek (bool wildcard=false);
+
+ const token* last_t; // the last value returned by peek() or next()
+ const token* next_t; // lookahead token
+
+ // expectations
+ const token* expect_known (token_type tt, string const & expected);
+ const token* expect_unknown (token_type tt, string & target);
+ const token* expect_unknown2 (token_type tt1, token_type tt2,
+ string & target);
+
+ // convenience forms
+ const token* expect_op (string const & expected);
+ const token* expect_kw (string const & expected);
+ const token* expect_number (int64_t & expected);
+ const token* expect_ident (string & target);
+ const token* expect_ident_or_keyword (string & target);
+ bool peek_op (string const & op);
+ bool peek_kw (string const & kw);
+
+ void print_error (const parse_error& pe);
+ unsigned num_errors;
+
+private: // nonterminals
+ void parse_probe (vector<probe*>&, vector<probe_alias*>&);
+ void parse_global (vector<vardecl*>&, vector<probe*>&);
+ void parse_functiondecl (vector<functiondecl*>&);
+ embeddedcode* parse_embeddedcode ();
+ probe_point* parse_probe_point ();
+ literal* parse_literal ();
+ block* parse_stmt_block ();
+ try_block* parse_try_block ();
+ statement* parse_statement ();
+ if_statement* parse_if_statement ();
+ for_loop* parse_for_loop ();
+ for_loop* parse_while_loop ();
+ foreach_loop* parse_foreach_loop ();
+ expr_statement* parse_expr_statement ();
+ return_statement* parse_return_statement ();
+ delete_statement* parse_delete_statement ();
+ next_statement* parse_next_statement ();
+ break_statement* parse_break_statement ();
+ continue_statement* parse_continue_statement ();
+ indexable* parse_indexable ();
+ const token *parse_hist_op_or_bare_name (hist_op *&hop, string &name);
+ target_symbol *parse_target_symbol (const token* t);
+ expression* parse_defined_op (const token* t);
+ expression* parse_expression ();
+ expression* parse_assignment ();
+ expression* parse_ternary ();
+ expression* parse_logical_or ();
+ expression* parse_logical_and ();
+ expression* parse_boolean_or ();
+ expression* parse_boolean_xor ();
+ expression* parse_boolean_and ();
+ expression* parse_array_in ();
+ expression* parse_comparison ();
+ expression* parse_shift ();
+ expression* parse_concatenation ();
+ expression* parse_additive ();
+ expression* parse_multiplicative ();
+ expression* parse_unary ();
+ expression* parse_crement ();
+ expression* parse_value ();
+ expression* parse_symbol ();
+
+ void parse_target_symbol_components (target_symbol* e);
+};
+
+
// ------------------------------------------------------------------------
+stapfile*
+parse (systemtap_session& s, istream& i, bool pr)
+{
+ parser p (s, i, pr);
+ return p.parse ();
+}
+
+
+stapfile*
+parse (systemtap_session& s, const string& n, bool pr)
+{
+ parser p (s, n, pr);
+ return p.parse ();
+}
+
+// ------------------------------------------------------------------------
parser::parser (systemtap_session& s, istream& i, bool p):
if (free_input) delete free_input;
}
-
-stapfile*
-parser::parse (systemtap_session& s, std::istream& i, bool pr)
-{
- parser p (s, i, pr);
- return p.parse ();
-}
-
-
-stapfile*
-parser::parse (systemtap_session& s, const std::string& n, bool pr)
-{
- parser p (s, n, pr);
- return p.parse ();
-}
-
static string
tt2str(token_type tt)
{
#define PARSE_H
#include <string>
-#include <fstream>
#include <iostream>
-#include <vector>
-#include <set>
#include <stdexcept>
-#include <stdint.h>
struct stapfile;
struct systemtap_session;
-class lexer
-{
-public:
- token* scan (bool wildcard=false);
- lexer (std::istream&, const std::string&, systemtap_session&);
- void set_current_file (stapfile* f);
-
-private:
- inline int input_get ();
- inline int input_peek (unsigned n=0);
- void input_put (const std::string&, const token*);
- std::string input_name;
- std::string input_contents;
- const char *input_pointer; // index into input_contents
- const char *input_end;
- unsigned cursor_suspend_count;
- unsigned cursor_suspend_line;
- unsigned cursor_suspend_column;
- unsigned cursor_line;
- unsigned cursor_column;
- systemtap_session& session;
- stapfile* current_file;
- static std::set<std::string> keywords;
-};
-
-struct probe;
-struct probe_alias;
-struct vardecl;
-struct functiondecl;
-struct embeddedcode;
-struct probe_point;
-struct literal;
-struct block;
-struct try_block;
-struct for_loop;
-struct statement;
-struct if_statement;
-struct foreach_loop;
-struct expr_statement;
-struct return_statement;
-struct delete_statement;
-struct break_statement;
-struct next_statement;
-struct continue_statement;
-struct indexable;
-struct expression;
-struct target_symbol;
-struct hist_op;
-
-class parser
-{
-public:
- parser (systemtap_session& s, std::istream& i, bool p);
- parser (systemtap_session& s, const std::string& n, bool p);
- ~parser ();
-
- stapfile* parse ();
-
- static stapfile* parse (systemtap_session& s, std::istream& i, bool privileged);
- static stapfile* parse (systemtap_session& s, const std::string& n, bool privileged);
-
-private:
- typedef enum {
- PP_NONE,
- PP_KEEP_THEN,
- PP_SKIP_THEN,
- PP_KEEP_ELSE,
- PP_SKIP_ELSE,
- } pp_state_t;
-
- systemtap_session& session;
- std::string input_name;
- std::istream* free_input;
- lexer input;
- bool privileged;
- parse_context context;
-
- // preprocessing subordinate
- std::vector<std::pair<const token*, pp_state_t> > pp_state;
- const token* scan_pp (bool wildcard=false);
- const token* skip_pp ();
-
- // scanning state
- const token* last ();
- const token* next (bool wildcard=false);
- const token* peek (bool wildcard=false);
-
- const token* last_t; // the last value returned by peek() or next()
- const token* next_t; // lookahead token
-
- // expectations
- const token* expect_known (token_type tt, std::string const & expected);
- const token* expect_unknown (token_type tt, std::string & target);
- const token* expect_unknown2 (token_type tt1, token_type tt2,
- std::string & target);
-
- // convenience forms
- const token* expect_op (std::string const & expected);
- const token* expect_kw (std::string const & expected);
- const token* expect_number (int64_t & expected);
- const token* expect_ident (std::string & target);
- const token* expect_ident_or_keyword (std::string & target);
- bool peek_op (std::string const & op);
- bool peek_kw (std::string const & kw);
-
- void print_error (const parse_error& pe);
- unsigned num_errors;
-
-private: // nonterminals
- void parse_probe (std::vector<probe*>&, std::vector<probe_alias*>&);
- void parse_global (std::vector<vardecl*>&, std::vector<probe*>&);
- void parse_functiondecl (std::vector<functiondecl*>&);
- embeddedcode* parse_embeddedcode ();
- probe_point* parse_probe_point ();
- literal* parse_literal ();
- block* parse_stmt_block ();
- try_block* parse_try_block ();
- statement* parse_statement ();
- if_statement* parse_if_statement ();
- for_loop* parse_for_loop ();
- for_loop* parse_while_loop ();
- foreach_loop* parse_foreach_loop ();
- expr_statement* parse_expr_statement ();
- return_statement* parse_return_statement ();
- delete_statement* parse_delete_statement ();
- next_statement* parse_next_statement ();
- break_statement* parse_break_statement ();
- continue_statement* parse_continue_statement ();
- indexable* parse_indexable ();
- const token *parse_hist_op_or_bare_name (hist_op *&hop, std::string &name);
- target_symbol *parse_target_symbol (const token* t);
- expression* parse_defined_op (const token* t);
- expression* parse_expression ();
- expression* parse_assignment ();
- expression* parse_ternary ();
- expression* parse_logical_or ();
- expression* parse_logical_and ();
- expression* parse_boolean_or ();
- expression* parse_boolean_xor ();
- expression* parse_boolean_and ();
- expression* parse_array_in ();
- expression* parse_comparison ();
- expression* parse_shift ();
- expression* parse_concatenation ();
- expression* parse_additive ();
- expression* parse_multiplicative ();
- expression* parse_unary ();
- expression* parse_crement ();
- expression* parse_value ();
- expression* parse_symbol ();
-
- void parse_target_symbol_components (target_symbol* e);
-};
-
+stapfile* parse (systemtap_session& s, std::istream& i, bool privileged);
+stapfile* parse (systemtap_session& s, const std::string& n, bool privileged);
#endif // PARSE_H