Branch data Line data Source code
1 : : // -*- C++ -*-
2 : : // Copyright (C) 2005-2010 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 <vector>
16 : : #include <iostream>
17 : : #include <stdexcept>
18 : :
19 : : struct stapfile;
20 : :
21 : : struct source_loc
22 : : {
23 : : stapfile* file;
24 : : unsigned line;
25 : : unsigned column;
26 : : };
27 : :
28 : : std::ostream& operator << (std::ostream& o, const source_loc& loc);
29 : :
30 : : enum parse_context
31 : : {
32 : : con_unknown, con_probe, con_global, con_function, con_embedded
33 : : };
34 : :
35 : :
36 : : enum token_type
37 : : {
38 : : tok_junk, tok_identifier, tok_operator, tok_string, tok_number,
39 : : tok_embedded, tok_keyword
40 : : };
41 : :
42 : :
43 [ + - ][ + - ]: 486565942 : struct token
[ + - ][ # ]
44 : : {
45 : : source_loc location;
46 : : token_type type;
47 : : std::string content;
48 : : std::string msg; // for tok_junk
49 : : void make_junk (std::string msg);
50 : : const token* chain; // macro invocation that produced this token
51 : : };
52 : :
53 : :
54 : : std::ostream& operator << (std::ostream& o, const token& t);
55 : :
56 : :
57 [ - + ]: 141 : struct parse_error: public std::runtime_error
58 : : {
59 : : const token* tok;
60 : : bool skip_some;
61 : 96 : parse_error (const std::string& msg):
62 : 96 : runtime_error (msg), tok (0), skip_some (true) {}
63 : 43 : parse_error (const std::string& msg, const token* t):
64 : 43 : runtime_error (msg), tok (t), skip_some (true) {}
65 : 2 : parse_error (const std::string& msg, bool skip):
66 : 2 : runtime_error (msg), tok (0), skip_some (skip) {}
67 : : };
68 : :
69 : :
70 : : typedef enum { ctx_library, ctx_local } macro_ctx;
71 : :
72 : : /* structs from session.h: */
73 : : struct systemtap_session;
74 : : struct macrodecl {
75 : : const token* tok; // NB: macrodecl owns its token
76 : : std::string name;
77 : : std::vector<std::string> formal_args;
78 : : std::vector<const token*> body;
79 : : macro_ctx context;
80 : :
81 : : // Used for identifying subclasses that represent e.g. parameter bindings.
82 : 553673 : virtual bool is_closure() { return false; }
83 : :
84 [ + - ][ + - ]: 956543 : macrodecl () : tok(0), context(ctx_local) { }
85 : : virtual ~macrodecl ();
86 : : };
87 : :
88 : :
89 : : stapfile* parse (systemtap_session& s, std::istream& i, bool privileged);
90 : : stapfile* parse (systemtap_session& s, const std::string& n, bool privileged);
91 : :
92 : : stapfile* parse_library_macros (systemtap_session& s, const std::string& n);
93 : :
94 : : #endif // PARSE_H
95 : :
96 : : /* vim: set sw=2 ts=8 cino=>4,n-2,{2,^-2,t0,(0,u0,w1,M1 : */
|