]>
Commit | Line | Data |
---|---|---|
2f1a1aea | 1 | // -*- C++ -*- |
ef36f781 | 2 | // Copyright (C) 2005-2014 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 | 14 | #include <string> |
fe410f52 | 15 | #include <vector> |
2f1a1aea | 16 | #include <iostream> |
2f1a1aea | 17 | #include <stdexcept> |
47d349b1 FCE |
18 | #include "stringtable.h" |
19 | ||
2f1a1aea | 20 | |
10e7c19d | 21 | struct systemtap_session; |
1b1b4ceb | 22 | struct stapfile; |
101b0805 | 23 | struct probe; |
1b1b4ceb | 24 | |
2f1a1aea FCE |
25 | struct source_loc |
26 | { | |
2203b032 | 27 | stapfile* file; |
2f1a1aea FCE |
28 | unsigned line; |
29 | unsigned column; | |
c92d3b42 FCE |
30 | public: |
31 | source_loc(): file(0), line(0), column(0) {} | |
2f1a1aea FCE |
32 | }; |
33 | ||
0323ed4d | 34 | std::ostream& operator << (std::ostream& o, const source_loc& loc); |
2f1a1aea | 35 | |
6e213f58 DS |
36 | enum parse_context |
37 | { | |
38 | con_unknown, con_probe, con_global, con_function, con_embedded | |
39 | }; | |
40 | ||
41 | ||
dff50e09 | 42 | enum token_type |
2f1a1aea | 43 | { |
54dfabe9 | 44 | tok_junk, tok_identifier, tok_operator, tok_string, tok_number, |
6e213f58 | 45 | tok_embedded, tok_keyword |
2f1a1aea FCE |
46 | }; |
47 | ||
10e7c19d JS |
48 | // detailed tok_junk |
49 | enum token_junk_type | |
50 | { | |
51 | tok_junk_unknown, | |
52 | tok_junk_nested_arg, | |
53 | tok_junk_invalid_arg, | |
54 | tok_junk_unclosed_quote, | |
55 | tok_junk_unclosed_embedded, | |
56 | }; | |
57 | ||
0fefb486 | 58 | |
2f1a1aea FCE |
59 | struct token |
60 | { | |
61 | source_loc location; | |
47d349b1 | 62 | interned_string content; |
534aad8b | 63 | const token* chain; // macro invocation that produced this token |
174b1425 | 64 | token_type type; |
10e7c19d JS |
65 | token_junk_type junk_type; |
66 | ||
67 | std::string junk_message(systemtap_session& session) const; | |
174b1425 | 68 | |
a340930f JL |
69 | friend class parser; |
70 | friend class lexer; | |
71 | private: | |
10e7c19d JS |
72 | void make_junk (token_junk_type); |
73 | token(): chain(0), type(tok_junk), junk_type(tok_junk_unknown) {} | |
a340930f | 74 | token(const token& other): |
174b1425 | 75 | location(other.location), content(other.content), |
10e7c19d | 76 | chain(other.chain), type(other.type), junk_type(other.junk_type) {} |
2f1a1aea FCE |
77 | }; |
78 | ||
0fefb486 | 79 | |
56099f08 FCE |
80 | std::ostream& operator << (std::ostream& o, const token& t); |
81 | ||
2f1a1aea | 82 | |
fe410f52 SM |
83 | typedef enum { ctx_library, ctx_local } macro_ctx; |
84 | ||
85 | /* structs from session.h: */ | |
fe410f52 SM |
86 | struct macrodecl { |
87 | const token* tok; // NB: macrodecl owns its token | |
88 | std::string name; | |
89 | std::vector<std::string> formal_args; | |
90 | std::vector<const token*> body; | |
91 | macro_ctx context; | |
92 | ||
93 | // Used for identifying subclasses that represent e.g. parameter bindings. | |
94 | virtual bool is_closure() { return false; } | |
95 | ||
96 | macrodecl () : tok(0), context(ctx_local) { } | |
f4072542 | 97 | virtual ~macrodecl (); |
fe410f52 SM |
98 | }; |
99 | ||
dc38c0ae | 100 | |
f8405ea5 JS |
101 | enum parse_flag |
102 | { | |
103 | pf_guru = 1, | |
104 | pf_no_compatible = 2, | |
105 | pf_squash_errors = 4, | |
7b5b30a8 | 106 | pf_user_file = 8, |
e8b46a9e | 107 | pf_auto_path = 16, |
f8405ea5 JS |
108 | }; |
109 | ||
110 | ||
ba48c27a | 111 | stapfile* parse (systemtap_session& s,const std::string& n, std::istream& i, unsigned flags); |
f8405ea5 | 112 | stapfile* parse (systemtap_session& s, const std::string& n, unsigned flags); |
2b066ec1 | 113 | |
f8405ea5 | 114 | stapfile* parse_library_macros (systemtap_session& s, const std::string& n); |
2b066ec1 | 115 | |
101b0805 JS |
116 | probe* parse_synthetic_probe (systemtap_session &s, std::istream& i, const token* tok); |
117 | ||
2b066ec1 | 118 | #endif // PARSE_H |
73267b89 JS |
119 | |
120 | /* vim: set sw=2 ts=8 cino=>4,n-2,{2,^-2,t0,(0,u0,w1,M1 : */ |