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