comparison src/tokenizer.h @ 19:b24369330483 stable-1-0-7

Fedora 9 compile and const correctness.
author Carl Byington <carl@five-ten-sg.com>
date Thu, 12 Jun 2008 18:17:33 -0700
parents 75e1a9bcbc2e
children
comparison
equal deleted inserted replaced
18:e1a028daceb9 19:b24369330483
3 Copyright (c) 2007 Carl Byington - 510 Software Group, released under 3 Copyright (c) 2007 Carl Byington - 510 Software Group, released under
4 the GPL version 3 or any later version at your choice available at 4 the GPL version 3 or any later version at your choice available at
5 http://www.gnu.org/licenses/gpl-3.0.txt 5 http://www.gnu.org/licenses/gpl-3.0.txt
6 6
7 */ 7 */
8 #ifndef tokenizer_include
9 #define tokenizer_include
10
11 #include <fstream>
12 #include <list>
13 #include <set>
14 #include <stdio.h>
15 #include <ctype.h>
16
17 8
18 using namespace std; 9 using namespace std;
19 10
20 struct ltstr { 11 struct ltstr {
21 bool operator()(char* s1, char* s2) const { 12 bool operator()(const char* s1, const char* s2) const {
22 return strcmp(s1, s2) < 0; 13 return strcmp(s1, s2) < 0;
23 } 14 }
24 }; 15 };
25 16
26 typedef list<ifstream *> stream_list; 17 typedef list<ifstream *> stream_list;
27 typedef list<char *> string_list; 18 typedef list<const char *> string_list;
28 typedef set<char *, ltstr> string_set; 19 typedef set<const char *, ltstr> string_set;
29 typedef list<int> line_list; 20 typedef list<int> line_list;
30 21
31 class TOKEN { 22 class TOKEN {
32 stream_list streams; 23 stream_list streams;
33 string_list filenames; 24 string_list filenames;
34 string_set filenamess; 25 string_set filenamess;
35 line_list linenumbers; 26 line_list linenumbers;
36 string_list pending_tokens; 27 string_list pending_tokens;
37 string_set *include_files; 28 string_set *include_files;
38 bool pushed; 29 bool pushed;
39 u_char pushed_char; 30 u_char pushed_char;
40 31
41 void pop(); 32 void pop();
42 bool next_char(u_char &c); 33 bool next_char(u_char &c);
43 void push_char(u_char c); 34 void push_char(u_char c);
44 35
45 public: 36 public:
46 TOKEN(char *fn, string_set *includes); 37 TOKEN(const char *fn, string_set *includes);
47 ~TOKEN(); 38 ~TOKEN();
48 bool include(char *fn); 39 bool include(const char *fn);
49 char *next(); // return next token 40 const char *next(); // return next token
50 int nextint(); 41 int nextint();
51 void skipeol(); // skip to eol 42 void skipeol(); // skip to eol
52 void push(char *token) {pending_tokens.push_front(token);}; 43 void push(const char *token) {pending_tokens.push_front(token);};
53 char *cur_fn() {return filenames.front();}; 44 const char *cur_fn() {return filenames.empty() ? "" : filenames.front();};
54 int cur_line() {return linenumbers.front();}; 45 int cur_line() {return linenumbers.empty() ? 0 : linenumbers.front();};
55 void token_error(const char *err); 46 void token_error(const char *err);
56 void token_error(const char *fmt, int d, const char *s); 47 void token_error(const char *fmt, int d, const char *s);
57 void token_error(const char *fmt, const char *t, const char *h); 48 void token_error(const char *fmt, const char *t, const char *h);
58 void token_error(const char *want, const char *have); 49 void token_error(const char *want, const char *have);
59 void token_error(); 50 void token_error();
60 }; 51 };
61 52
62 #endif