]> sourceware.org Git - systemtap.git/blob - parse.h
Fix typo in mq_timedreceive probe point.
[systemtap.git] / parse.h
1 // -*- C++ -*-
2 // Copyright (C) 2005-2007 Red Hat Inc.
3 // Copyright (C) 2007 Bull S.A.S
4 //
5 // This file is part of systemtap, and is free software. You can
6 // redistribute it and/or modify it under the terms of the GNU General
7 // Public License (GPL); either version 2, or (at your option) any
8 // later version.
9
10
11 #ifndef PARSE_H
12 #define PARSE_H
13
14 #include <string>
15 #include <fstream>
16 #include <iostream>
17 #include <vector>
18 #include <stdexcept>
19 #include <stdint.h>
20
21 struct stapfile;
22
23 struct source_loc
24 {
25 std::string file;
26 unsigned line;
27 unsigned column;
28 stapfile* stap_file;
29 };
30
31 std::ostream& operator << (std::ostream& o, const source_loc& loc);
32
33 enum parse_context
34 {
35 con_unknown, con_probe, con_global, con_function, con_embedded
36 };
37
38
39 enum token_type
40 {
41 tok_junk, tok_identifier, tok_operator, tok_string, tok_number,
42 tok_embedded, tok_keyword
43 };
44
45
46 struct token
47 {
48 source_loc location;
49 token_type type;
50 std::string content;
51 };
52
53
54 std::ostream& operator << (std::ostream& o, const token& t);
55
56
57 struct parse_error: public std::runtime_error
58 {
59 const token* tok;
60 bool skip_some;
61 parse_error (const std::string& msg):
62 runtime_error (msg), tok (0), skip_some (true) {}
63 parse_error (const std::string& msg, const token* t):
64 runtime_error (msg), tok (t), skip_some (true) {}
65 parse_error (const std::string& msg, bool skip):
66 runtime_error (msg), tok (0), skip_some (skip) {}
67 };
68
69
70 struct systemtap_session;
71
72 class lexer
73 {
74 public:
75 token* scan (bool wildcard=false);
76 lexer (std::istream&, const std::string&, systemtap_session&);
77 std::string get_input_contents ();
78 void set_current_file (stapfile* f);
79
80 private:
81 int input_get ();
82 void input_put (int);
83 void input_put (const std::string&);
84 int input_peek (unsigned n=0);
85 std::istream& input;
86 std::string input_name;
87 std::string input_contents;
88 int input_pointer; // index into input_contents
89 unsigned cursor_suspend_count;
90 unsigned cursor_line;
91 unsigned cursor_column;
92 systemtap_session& session;
93 stapfile* current_file;
94 };
95
96 struct probe;
97 struct probe_alias;
98 struct vardecl;
99 struct functiondecl;
100 struct embeddedcode;
101 struct probe_point;
102 struct literal;
103 struct block;
104 struct for_loop;
105 struct statement;
106 struct if_statement;
107 struct foreach_loop;
108 struct expr_statement;
109 struct return_statement;
110 struct delete_statement;
111 struct break_statement;
112 struct next_statement;
113 struct continue_statement;
114 struct indexable;
115 struct expression;
116 struct hist_op;
117
118 class parser
119 {
120 public:
121 parser (systemtap_session& s, std::istream& i, bool p);
122 parser (systemtap_session& s, const std::string& n, bool p);
123 ~parser ();
124
125 stapfile* parse ();
126
127 static stapfile* parse (systemtap_session& s, std::istream& i, bool privileged);
128 static stapfile* parse (systemtap_session& s, const std::string& n, bool privileged);
129
130 private:
131 systemtap_session& session;
132 std::string input_name;
133 std::istream* free_input;
134 lexer input;
135 bool privileged;
136 parse_context context;
137
138 // preprocessing subordinate
139 std::vector<const token*> enqueued_pp;
140 const token* scan_pp (bool wildcard=false);
141
142 // scanning state
143 const token* last ();
144 const token* next (bool wildcard=false);
145 const token* peek (bool wildcard=false);
146
147 const token* last_t; // the last value returned by peek() or next()
148 const token* next_t; // lookahead token
149
150 // expectations
151 const token* expect_known (token_type tt, std::string const & expected);
152 const token* expect_unknown (token_type tt, std::string & target);
153 const token* expect_unknown2 (token_type tt1, token_type tt2,
154 std::string & target);
155
156 // convenience forms
157 const token* expect_op (std::string const & expected);
158 const token* expect_kw (std::string const & expected);
159 const token* expect_number (int64_t & expected);
160 const token* expect_ident (std::string & target);
161 const token* expect_ident_or_keyword (std::string & target);
162 bool peek_op (std::string const & op);
163 bool peek_kw (std::string const & kw);
164
165 void print_error (const parse_error& pe);
166 unsigned num_errors;
167
168 private: // nonterminals
169 void parse_probe (std::vector<probe*>&, std::vector<probe_alias*>&);
170 void parse_global (std::vector<vardecl*>&, std::vector<probe*>&);
171 void parse_functiondecl (std::vector<functiondecl*>&);
172 embeddedcode* parse_embeddedcode ();
173 probe_point* parse_probe_point ();
174 literal* parse_literal ();
175 block* parse_stmt_block ();
176 statement* parse_statement ();
177 if_statement* parse_if_statement ();
178 for_loop* parse_for_loop ();
179 for_loop* parse_while_loop ();
180 foreach_loop* parse_foreach_loop ();
181 expr_statement* parse_expr_statement ();
182 return_statement* parse_return_statement ();
183 delete_statement* parse_delete_statement ();
184 next_statement* parse_next_statement ();
185 break_statement* parse_break_statement ();
186 continue_statement* parse_continue_statement ();
187 indexable* parse_indexable ();
188 const token *parse_hist_op_or_bare_name (hist_op *&hop, std::string &name);
189 expression* parse_expression ();
190 expression* parse_assignment ();
191 expression* parse_ternary ();
192 expression* parse_logical_or ();
193 expression* parse_logical_and ();
194 expression* parse_boolean_or ();
195 expression* parse_boolean_xor ();
196 expression* parse_boolean_and ();
197 expression* parse_array_in ();
198 expression* parse_comparison ();
199 expression* parse_shift ();
200 expression* parse_concatenation ();
201 expression* parse_additive ();
202 expression* parse_multiplicative ();
203 expression* parse_unary ();
204 expression* parse_crement ();
205 expression* parse_value ();
206 expression* parse_symbol ();
207 };
208
209
210
211 #endif // PARSE_H
212
213 /* vim: set sw=2 ts=8 cino=>4,n-2,{2,^-2,t0,(0,u0,w1,M1 : */
This page took 0.044091 seconds and 5 git commands to generate.