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