atlas  0.6
buffer.h
Go to the documentation of this file.
1 /*1:*/
2 #line 55 "buffer.w"
3 #ifndef BUFFER_H
4 #define BUFFER_H/*8:*/
5 #line 218 "buffer.w"
6 #include <vector>
7 #include <cstring>/*:8*//*19:*/
8 #line 476 "buffer.w"
9 #include <string>
10 #include "../Atlas.h"
11 #include "bitmap.h"
12 #include "sl_list.h" /*:19*//*23:*/
13 #line 583 "buffer.w"
14 #include <fstream>/*:23*/
15 #line 58 "buffer.w"
16 
17 
18 
19 namespace atlas
20 {namespace interpreter
21 {/*3:*/
22 #line 111 "buffer.w"
24 {public:
25 static const size_t default_block_size=512;
26 String_pool(size_t b=default_block_size);
27 char*store(const char*s,size_t length);
28 ~String_pool();
29 private:
30 String_pool(const String_pool&);
32 
33 const size_t block_size;
34 char*start;
35 char*point;
36 size_t chars_left;
38 
39 };/*:3*//*7:*/
40 #line 184 "buffer.w"
42 {
43 public:
44 typedef unsigned short id_type;
45 static const id_type empty;
46 private:
48 id_type mod;
49 std::vector<id_type>hash_tab;
50 std::vector<const char* >name_tab;
51 
52 public:
53 Hash_table(size_t init=initial_hash_mod
55 
56 id_type nr_entries()const{return name_tab.size();}
57 const char*name_of(id_type nr)const{return name_tab[nr];}
58 bool knows(const char*name)const;
59 
60 id_type match(const char*s,size_t l){return do_match(s,l,true);}
61 id_type match_literal(const char*s)
62 {return do_match(s,std::strlen(s),false);}
63 private:
64 static const id_type initial_hash_mod=97;
65 id_type hash(const char*s,size_t l)const;
66 id_type do_match(const char*s,size_t l,bool copy_string);
67 size_t max_fill()const{return static_cast<id_type>(mod*3L/4);}
68 
69 };/*:7*//*15:*/
70 #line 413 "buffer.w"
71 #include <iosfwd>/*:15*//*16:*/
72 #line 427 "buffer.w"
74 {typedef char*(*rl_type)(const char*);
75 
76 typedef void(*add_hist_type)(const char*);/*24:*/
77 #line 601 "buffer.w"
79 {std::ifstream f_stream;
81 unsigned long line_no;
82 
83 input_record(BufferedInput&,const char*file_name);
84 input_record(const input_record&rec)=delete;
85 input_record&operator=(const input_record&rec)=delete;
86 };/*:24*//*20:*/
87 #line 506 "buffer.w"
88 std::istream&base_stream;
90 const char*p;
91 const char*const prompt,*const prompt2;
92 const char*def_ext;
94 const rl_type readline;
95 const add_hist_type add_hist;
96 unsigned long line_no;
97 int cur_lines,prompt_length;
99 
102 std::istream*stream;/*:20*/
103 #line 434 "buffer.w"
104 
105 
106 public:
107 BufferedInput(std::istream&s);
108 
109 BufferedInput(const char*prompt
110 ,rl_type rl=nullptr,add_hist_type=nullptr
111 ,const char*prompt2="> "
112 ,const char*def_ext=".at");
113 
114 
115 char shift();
116 void unshift();
117 bool eol()const;
118 bool getline();
119 
120 bool push_file(const char*file_name,bool skip_seen);
121 
122 void close_includes();/*26:*/
123 #line 641 "buffer.w"
125 {return input_stack.empty()?Hash_table::empty:input_stack.back().name;}
126 const char*name_of(Hash_table::id_type f)const
127 {return
128 f==Hash_table::empty?"<standard input>":input_files_seen.name_of(f);}
129 const char*cur_fname()const
130 {return name_of(current_file());}/*:26*//*36:*/
131 #line 987 "buffer.w"
132 unsigned int include_depth()const{return input_stack.size();}
133 const char*point()const{return p==nullptr?line_buffer.c_str():p;}
134 void set_line_no(unsigned long l)
135 {line_no=l;}
136 void locate(const char*p,int&line,int&column)const;/*:36*//*38:*/
137 #line 1009 "buffer.w"
138 void show_range
139 (std::ostream&out,unsigned long l0,int c0,unsigned long l1,int c1)
140 const;/*:38*//*40:*/
141 #line 1053 "buffer.w"
142 void push_prompt(char c);
143 char top_prompt()const;
144 void pop_prompt();
145 void reset();/*:40*/
146 #line 453 "buffer.w"
147 
148 private:
149 void pop_file();
150 };/*:16*//*21:*/
151 #line 527 "buffer.w"
152 inline bool BufferedInput::eol()const{return p==nullptr or*p=='\0';}/*:21*//*35:*/
153 #line 959 "buffer.w"
154 inline char BufferedInput::shift()
155 {if(eol())
156 if(not getline())
157 {p=nullptr;return '\0';}
158 return*p++;
159 }
160 
162 {if(p!=nullptr and p>line_buffer.data())
163 --p;
164 }/*:35*//*17:*/
165 #line 463 "buffer.w"
166 extern BufferedInput*main_input_buffer;/*:17*//*27:*/
167 #line 657 "buffer.w"
168 unsigned int input_path_size();
169 const std::string&input_path_component(unsigned int i);/*:27*/
170 #line 67 "buffer.w"
171 
172 }
173 }
174 #endif/*:1*/
const std::string & input_path_component(unsigned int i)
Definition: main.cpp:143
const size_t block_size
Definition: buffer.h:33
id_type mod
Definition: buffer.h:48
Definition: buffer.h:23
String_pool & operator=(const String_pool &)
Definition: sl_list.h:1258
Definition: buffer.h:41
uA p
Definition: lists.cpp:26
id_type nr_entries() const
Definition: buffer.h:56
id_type match(const char *s, size_t l)
Definition: buffer.h:60
#define shift()
Definition: cweave.c:116
const String_pool * prev
Definition: buffer.h:37
char * point
Definition: buffer.h:35
std::string line_buffer
Definition: buffer.h:89
std::vector< id_type > hash_tab
Definition: buffer.h:49
size_type size() const
Definition: sl_list.h:959
int length
Definition: common.c:103
std::istream & base_stream
Definition: buffer.h:88
std::istream * stream
Definition: buffer.h:102
unsigned int input_path_size()
Definition: main.cpp:139
size_t chars_left
Definition: buffer.h:36
containers::mirrored_sl_list< input_record > input_stack
Definition: buffer.h:98
~String_pool()
Definition: buffer.cpp:37
bool eol() const
Definition: buffer.h:152
id_type match_literal(const char *s)
Definition: buffer.h:61
Definition: cweave.c:245
void set_line_no(unsigned long l)
Definition: buffer.h:134
static const id_type empty
Definition: buffer.h:45
char shift()
Definition: buffer.h:154
static const size_t default_block_size
Definition: buffer.h:25
BufferedInput * main_input_buffer
Definition: buffer.cpp:355
const char * p
Definition: buffer.h:90
unsigned short id_type
Definition: buffer.h:44
std::vector< const char * > name_tab
Definition: buffer.h:50
BitMap input_files_completed
Definition: buffer.h:101
Hash_table::id_type current_file() const
Definition: buffer.h:124
String_pool(size_t b=default_block_size)
Definition: buffer.cpp:15
std::ifstream f_stream
Definition: buffer.h:79
void unshift()
Definition: buffer.h:161
Definition: buffer.h:73
Hash_table input_files_seen
Definition: buffer.h:100
#define out(c)
Definition: cweave.c:205
char * start
Definition: buffer.h:34
const rl_type readline
Definition: buffer.h:94
unsigned long line_no
Definition: buffer.h:96
id_pointer hash[hash_size]
Definition: common.c:125
const char *const *const prompt2
Definition: buffer.h:91
char * store(const char *s, size_t length)
Definition: buffer.cpp:19
Definitions and declarations for the BitMap class.
unsigned int include_depth() const
Definition: buffer.h:132
const char * point() const
Definition: buffer.h:133
char * name
Definition: common.c:103
unsigned long line_no
Definition: buffer.h:81
Definition: Atlas.h:38
int prompt_length
Definition: buffer.h:97
size_t max_fill() const
Definition: buffer.h:67
const char * def_ext
Definition: buffer.h:92
const char * cur_fname() const
Definition: buffer.h:129
Definition: common.h:36
Definition: cweave.c:262
const char * name_of(Hash_table::id_type f) const
Definition: buffer.h:126
const add_hist_type add_hist
Definition: buffer.h:95
String_pool pool
Definition: buffer.h:47
bool empty() const
Definition: sl_list.h:957
const T & back(Args &&...args) const
Definition: sl_list.h:1302
std::string temp_prompt
Definition: buffer.h:93
Hash_table::id_type name
Definition: buffer.h:80
const char * name_of(id_type nr) const
Definition: buffer.h:57