]>
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> |
41baefe8 | 18 | #include <staptree.h> |
47d349b1 FCE |
19 | #include "stringtable.h" |
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; | |
db79925e SM |
68 | |
69 | // Creates a new token with the same content but different coordinates. | |
70 | // Can be used for exact error reporting *within* a token e.g. embedded-code. | |
71 | token *adjust_location(const source_loc &adjusted_loc) const | |
72 | { // TODO split from header | |
73 | token *new_tok = new token; | |
74 | new_tok->location = adjusted_loc; | |
75 | new_tok->content = content; | |
76 | new_tok->chain = chain; | |
77 | new_tok->type = type; | |
78 | new_tok->junk_type = junk_type; | |
79 | return new_tok; | |
80 | } | |
174b1425 | 81 | |
a340930f JL |
82 | friend class parser; |
83 | friend class lexer; | |
84 | private: | |
10e7c19d | 85 | void make_junk (token_junk_type); |
db79925e | 86 | |
10e7c19d | 87 | token(): chain(0), type(tok_junk), junk_type(tok_junk_unknown) {} |
a340930f | 88 | token(const token& other): |
174b1425 | 89 | location(other.location), content(other.content), |
10e7c19d | 90 | chain(other.chain), type(other.type), junk_type(other.junk_type) {} |
2f1a1aea FCE |
91 | }; |
92 | ||
0fefb486 | 93 | |
56099f08 FCE |
94 | std::ostream& operator << (std::ostream& o, const token& t); |
95 | ||
2f1a1aea | 96 | |
fe410f52 SM |
97 | typedef enum { ctx_library, ctx_local } macro_ctx; |
98 | ||
99 | /* structs from session.h: */ | |
fe410f52 SM |
100 | struct macrodecl { |
101 | const token* tok; // NB: macrodecl owns its token | |
102 | std::string name; | |
103 | std::vector<std::string> formal_args; | |
104 | std::vector<const token*> body; | |
105 | macro_ctx context; | |
106 | ||
107 | // Used for identifying subclasses that represent e.g. parameter bindings. | |
108 | virtual bool is_closure() { return false; } | |
109 | ||
110 | macrodecl () : tok(0), context(ctx_local) { } | |
f4072542 | 111 | virtual ~macrodecl (); |
fe410f52 SM |
112 | }; |
113 | ||
41baefe8 RG |
114 | /* Tracks some of the data from within the paser, which |
115 | * will survive past the parser's lifetime. This is currently | |
116 | * used to pass on some completion data to the language server | |
117 | */ | |
118 | struct parser_completion_state{ | |
119 | // The top level context in which the parser failed | |
120 | parse_context context; | |
121 | // The token on which the parser had it's failure (may be the same as the parse_error tok) | |
122 | const token *tok; | |
123 | // The last parsed probe point (might may or may not be completed) | |
124 | probe_point* pp; | |
125 | // The last (possibly incomplete) probe point component. Might have a valid functor | |
126 | // but invalid arg for example | |
127 | probe_point::component* comp; | |
128 | // true iff the parser failed within parse_stmt_block which is refered to as the 'body' | |
129 | bool in_body; | |
130 | ||
131 | parser_completion_state() : context{con_unknown}, tok{0}, pp{0}, comp{0}, in_body{false} {} | |
132 | parser_completion_state(parser_completion_state* other): | |
133 | context{other->context}, tok{other->tok}, pp{other->pp}, | |
134 | comp{other->comp}, in_body{other->in_body} {} | |
135 | }; | |
dc38c0ae | 136 | |
f8405ea5 JS |
137 | enum parse_flag |
138 | { | |
139 | pf_guru = 1, | |
140 | pf_no_compatible = 2, | |
141 | pf_squash_errors = 4, | |
7b5b30a8 | 142 | pf_user_file = 8, |
e8b46a9e | 143 | pf_auto_path = 16, |
f8405ea5 JS |
144 | }; |
145 | ||
146 | ||
ba48c27a | 147 | stapfile* parse (systemtap_session& s,const std::string& n, std::istream& i, unsigned flags); |
f8405ea5 | 148 | stapfile* parse (systemtap_session& s, const std::string& n, unsigned flags); |
2b066ec1 | 149 | |
f8405ea5 | 150 | stapfile* parse_library_macros (systemtap_session& s, const std::string& n); |
2b066ec1 | 151 | |
101b0805 JS |
152 | probe* parse_synthetic_probe (systemtap_session &s, std::istream& i, const token* tok); |
153 | ||
2b066ec1 | 154 | #endif // PARSE_H |
73267b89 JS |
155 | |
156 | /* vim: set sw=2 ts=8 cino=>4,n-2,{2,^-2,t0,(0,u0,w1,M1 : */ |