forked from panda3d/panda3d
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathppCommandFile.h
More file actions
200 lines (168 loc) · 4.79 KB
/
ppCommandFile.h
File metadata and controls
200 lines (168 loc) · 4.79 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
// Filename: ppCommandFile.h
// Created by: drose (25Sep00)
//
////////////////////////////////////////////////////////////////////
#ifndef PPCOMMANDFILE_H
#define PPCOMMANDFILE_H
#include "ppremake.h"
#include "filename.h"
#include <map>
#include <vector>
class PPScope;
///////////////////////////////////////////////////////////////////
// Class : PPCommandFile
// Description : This encapsulates a file that contains #commands to
// execute (like #define, #if, #begin .. #end),
// $[variables] to expand, and plain text to output.
////////////////////////////////////////////////////////////////////
class PPCommandFile {
public:
PPCommandFile(PPScope *scope);
~PPCommandFile();
void set_output(ostream *out);
void set_scope(PPScope *scope);
PPScope *get_scope() const;
bool read_file(Filename filename);
bool read_stream(istream &in, const string &filename);
bool read_stream(istream &in);
void begin_read();
bool read_line(string line);
bool end_read();
protected:
bool handle_command(const string &line);
bool handle_if_command();
bool handle_elif_command();
bool handle_else_command();
bool handle_endif_command();
bool handle_begin_command();
bool handle_while_command();
bool handle_for_command();
bool handle_forscopes_command();
bool handle_foreach_command();
bool handle_formap_command();
bool handle_defsub_command(bool is_defsub);
bool handle_output_command();
bool handle_end_command();
bool handle_format_command();
bool handle_print_command();
bool handle_printvar_command();
bool handle_include_command();
bool handle_sinclude_command();
bool handle_copy_command();
bool handle_call_command();
bool handle_error_command();
bool handle_mkdir_command();
bool handle_defer_command();
bool handle_define_command();
bool handle_set_command();
bool handle_map_command();
bool handle_addmap_command();
bool handle_push_command();
bool include_file(Filename filename);
bool replay_while(const string &name);
bool replay_for(const string &name, const vector<string> &words);
bool replay_forscopes(const string &name);
bool replay_foreach(const string &varname, const vector<string> &words);
bool replay_formap(const string &varname, const string &mapvar);
bool compare_output(const string &new_contents, Filename filename,
bool notouch, bool binary);
bool failed_if() const;
bool is_valid_formal(const string &formal_parameter_name) const;
private:
class PushFilename {
public:
PushFilename(PPScope *scope, const string &filename);
~PushFilename();
PPScope *_scope;
string _old_thisdirprefix;
string _old_thisfilename;
};
private:
class BlockNesting;
enum IfState {
IS_on, // e.g. a passed #if
IS_else, // after matching an #else
IS_off, // e.g. a failed #if
IS_done // e.g. after reaching an #else or #elif for a passed #if.
};
class IfNesting {
public:
IfNesting(IfState state);
void push(PPCommandFile *file);
void pop(PPCommandFile *file);
IfState _state;
BlockNesting *_block;
IfNesting *_next;
};
enum BlockState {
BS_begin,
BS_while,
BS_nested_while,
BS_for,
BS_nested_for,
BS_forscopes,
BS_nested_forscopes,
BS_foreach,
BS_nested_foreach,
BS_formap,
BS_nested_formap,
BS_defsub,
BS_defun,
BS_output
};
enum WriteFormat {
WF_error, // anything other than whitespace is an error.
WF_straight, // write lines directly as they come in
WF_collapse, // collapse out consecutive blank lines
WF_makefile // fancy makefile formatting
};
class WriteState {
public:
WriteState();
WriteState(const WriteState ©);
bool write_line(const string &line);
bool write_collapse_line(const string &line);
bool write_makefile_line(const string &line);
ostream *_out;
WriteFormat _format;
bool _last_blank;
};
enum OutputFlags {
OF_notouch = 0x001,
OF_binary = 0x002,
};
class BlockNesting {
public:
BlockNesting(BlockState state, const string &name);
void push(PPCommandFile *file);
void pop(PPCommandFile *file);
BlockState _state;
string _name;
IfNesting *_if;
WriteState *_write_state;
PPScope *_scope;
string _params;
#ifdef HAVE_SSTREAM
ostringstream _output;
#else
ostrstream _output;
#endif
vector<string> _words;
int _flags;
BlockNesting *_next;
};
PPScope *_native_scope;
PPScope *_scope;
bool _got_command;
bool _in_for;
IfNesting *_if_nesting;
BlockNesting *_block_nesting;
string _command;
string _params;
WriteState *_write_state;
vector<string> _saved_lines;
friend class PPCommandFile::IfNesting;
friend class PPCommandFile::WriteState;
friend class PPCommandFile::BlockNesting;
};
#endif