forked from AviSynth/AviSynthPlus
-
Notifications
You must be signed in to change notification settings - Fork 23
Expand file tree
/
Copy pathexpression.h
More file actions
430 lines (328 loc) · 10.4 KB
/
expression.h
File metadata and controls
430 lines (328 loc) · 10.4 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
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
// Avisynth v2.5. Copyright 2002 Ben Rudiak-Gould et al.
// http://www.avisynth.org
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA, or visit
// http://www.gnu.org/copyleft/gpl.html .
//
// Linking Avisynth statically or dynamically with other modules is making a
// combined work based on Avisynth. Thus, the terms and conditions of the GNU
// General Public License cover the whole combination.
//
// As a special exception, the copyright holders of Avisynth give you
// permission to link Avisynth with independent modules that communicate with
// Avisynth solely through the interfaces defined in avisynth.h, regardless of the license
// terms of these independent modules, and to copy and distribute the
// resulting combined work under terms of your choice, provided that
// every copy of the combined work is accompanied by a complete copy of
// the source code of Avisynth (the version of Avisynth used to produce the
// combined work), being distributed under the terms of the GNU General
// Public License plus this exception. An independent module is a module
// which is not derived from or based on Avisynth, such as 3rd-party filters,
// import and export plugins, or graphical user interfaces.
#ifndef __Expression_H__
#define __Expression_H__
#include <avisynth.h>
#include <vector>
/********************************************************************
********************************************************************/
struct ReturnExprException
{
AVSValue value;
};
/**** Base Classes ****/
class Expression {
public:
Expression() : refcnt(0) {}
virtual AVSValue Evaluate(IScriptEnvironment* env) = 0;
virtual const char* GetLvalue() { return 0; }
virtual ~Expression() {}
private:
friend class PExpression;
int refcnt;
void AddRef() { ++refcnt; }
void Release() { if (--refcnt <= 0) delete this; }
};
class PExpression
{
public:
PExpression() { Init(0); }
PExpression(Expression* p) { Init(p); }
PExpression(const PExpression& p) { Init(p.e); }
PExpression& operator=(Expression* p) { Set(p); return *this; }
PExpression& operator=(const PExpression& p) { Set(p.e); return *this; }
int operator!() const { return !e; }
operator void*() const { return e; }
Expression* operator->() const { return e; }
~PExpression() { Release(); }
private:
Expression* e;
void Init(Expression* p) { e=p; if (e) e->AddRef(); }
void Set(Expression* p) { if (p) p->AddRef(); if (e) e->Release(); e=p; }
void Release() { if (e) e->Release(); }
};
/**** Object classes ****/
class ExpRootBlock : public Expression
{
public:
ExpRootBlock(const PExpression& e) : exp(e) {}
virtual AVSValue Evaluate(IScriptEnvironment* env);
private:
const PExpression exp;
};
class ExpConstant : public Expression
{
public:
#ifdef NEW_AVSVALUE
ExpConstant(std::vector<AVSValue>* v) : val(v->data(), (int)(v->size())) {} // array of AVSValue*
#endif
ExpConstant(AVSValue v) : val(v) {}
ExpConstant(int i) : val(i) {}
ExpConstant(float f) : val(f) {}
ExpConstant(const char* s) : val(s) {}
virtual AVSValue Evaluate(IScriptEnvironment* env) { return val; }
private:
friend class ExpNegative;
const AVSValue val;
};
class ExpSequence : public Expression
{
public:
ExpSequence(const PExpression& _a, const PExpression& _b) : a(_a), b(_b) {}
virtual AVSValue Evaluate(IScriptEnvironment* env);
private:
const PExpression a, b;
};
class ExpExceptionTranslator : public Expression
{
public:
ExpExceptionTranslator(const PExpression& _exp) : exp(_exp) {}
AVSValue Evaluate(IScriptEnvironment* env);
private:
const PExpression exp;
void TrapEval(AVSValue&, unsigned &excode, IScriptEnvironment*);
};
class ExpTryCatch : public ExpExceptionTranslator
{
public:
ExpTryCatch(const PExpression& _try_block, const char* _id, const PExpression& _catch_block)
: ExpExceptionTranslator(_try_block), id(_id), catch_block(_catch_block) {}
AVSValue Evaluate(IScriptEnvironment* env);
private:
const char* const id;
const PExpression catch_block;
};
class ExpLine : public ExpExceptionTranslator
{
public:
ExpLine(const PExpression& _exp, const char* _filename, int _line)
: ExpExceptionTranslator(_exp), filename(_filename), line(_line) {}
AVSValue Evaluate(IScriptEnvironment* env);
private:
const char* const filename;
const int line;
};
class ExpBlockConditional : public Expression
{
public:
ExpBlockConditional(const PExpression& _If, const PExpression& _Then, const PExpression& _Else)
: If(_If), Then(_Then), Else(_Else) {}
virtual AVSValue Evaluate(IScriptEnvironment* env);
private:
const PExpression If, Then, Else;
};
class ExpWhileLoop : public Expression
{
public:
ExpWhileLoop(const PExpression& _condition, const PExpression& _body)
: condition(_condition), body(_body) {}
virtual AVSValue Evaluate(IScriptEnvironment* env);
private:
const PExpression condition, body;
};
class ExpForLoop : public Expression
{
public:
ExpForLoop(const char* const _id, const PExpression& _init, const PExpression& _limit,
const PExpression& _step, const PExpression& _body)
: id(_id), init(_init), limit(_limit), step(_step), body(_body) {}
virtual AVSValue Evaluate(IScriptEnvironment* env);
private:
const char* const id;
const PExpression init, limit, step, body;
};
class ExpBreak : public Expression
{
public:
ExpBreak() {}
virtual AVSValue Evaluate(IScriptEnvironment* env);
};
class ExpConditional : public Expression
{
public:
ExpConditional(const PExpression& _If, const PExpression& _Then, const PExpression& _Else)
: If(_If), Then(_Then), Else(_Else) {}
virtual AVSValue Evaluate(IScriptEnvironment* env);
private:
const PExpression If, Then, Else;
};
class ExpReturn : public Expression
{
public:
ExpReturn(PExpression value) : value(value) {}
virtual AVSValue Evaluate(IScriptEnvironment* env);
private:
const PExpression value;
};
/**** Operator classes ****/
class ExpOr : public Expression
{
public:
ExpOr(const PExpression& _a, const PExpression& _b) : a(_a), b(_b) {}
virtual AVSValue Evaluate(IScriptEnvironment* env);
private:
const PExpression a, b;
};
class ExpAnd : public Expression
{
public:
ExpAnd(const PExpression& _a, const PExpression& _b) : a(_a), b(_b) {}
virtual AVSValue Evaluate(IScriptEnvironment* env);
private:
const PExpression a, b;
};
class ExpEqual : public Expression
{
public:
ExpEqual(const PExpression& _a, const PExpression& _b) : a(_a), b(_b) {}
virtual AVSValue Evaluate(IScriptEnvironment* env);
private:
const PExpression a, b;
};
class ExpLess : public Expression
{
public:
ExpLess(const PExpression& _a, const PExpression& _b) : a(_a), b(_b) {}
virtual AVSValue Evaluate(IScriptEnvironment* env);
private:
const PExpression a, b;
};
class ExpPlus : public Expression
{
public:
ExpPlus(const PExpression& _a, const PExpression& _b) : a(_a), b(_b) {}
virtual AVSValue Evaluate(IScriptEnvironment* env);
private:
const PExpression a, b;
};
class ExpDoublePlus : public Expression
{
public:
ExpDoublePlus(const PExpression& _a, const PExpression& _b) : a(_a), b(_b) {}
virtual AVSValue Evaluate(IScriptEnvironment* env);
private:
const PExpression a, b;
};
class ExpMinus : public Expression
{
public:
ExpMinus(const PExpression& _a, const PExpression& _b) : a(_a), b(_b) {}
virtual AVSValue Evaluate(IScriptEnvironment* env);
private:
const PExpression a, b;
};
class ExpMult : public Expression
{
public:
ExpMult(const PExpression& _a, const PExpression& _b) : a(_a), b(_b) {}
virtual AVSValue Evaluate(IScriptEnvironment* env);
private:
const PExpression a, b;
};
class ExpDiv : public Expression
{
public:
ExpDiv(const PExpression& _a, const PExpression& _b) : a(_a), b(_b) {}
virtual AVSValue Evaluate(IScriptEnvironment* env);
private:
const PExpression a, b;
};
class ExpMod : public Expression
{
public:
ExpMod(const PExpression& _a, const PExpression& _b) : a(_a), b(_b) {}
virtual AVSValue Evaluate(IScriptEnvironment* env);
private:
const PExpression a, b;
};
class ExpNegate : public Expression
{
public:
ExpNegate(const PExpression& _e) : e(_e) {}
virtual AVSValue Evaluate(IScriptEnvironment* env);
private:
const PExpression e;
};
class ExpNot : public Expression
{
public:
ExpNot(const PExpression& _e) : e(_e) {}
virtual AVSValue Evaluate(IScriptEnvironment* env);
private:
const PExpression e;
};
class ExpVariableReference : public Expression
{
public:
ExpVariableReference(const char* _name, const int _frame_number) : name(_name), frame_number(_frame_number) {}
virtual AVSValue Evaluate(IScriptEnvironment* env);
virtual const char* GetLvalue() { return name; }
private:
const char* const name;
const int frame_number; // for per-frame expressions
};
class ExpAssignment : public Expression
{
public:
ExpAssignment(const char* _lhs, const PExpression& _rhs) : lhs(_lhs), rhs(_rhs) {}
virtual AVSValue Evaluate(IScriptEnvironment* env);
private:
const char* const lhs;
PExpression rhs;
};
class ExpGlobalAssignment : public Expression
{
public:
ExpGlobalAssignment(const char* _lhs, const PExpression& _rhs) : lhs(_lhs), rhs(_rhs) {}
virtual AVSValue Evaluate(IScriptEnvironment* env);
private:
const char* const lhs;
PExpression rhs;
};
class ExpFunctionCall : public Expression
{
public:
ExpFunctionCall( const char* _name, PExpression* _arg_exprs,
const char** _arg_expr_names, int _arg_expr_count, bool _oop_notation, int _frame_number );
~ExpFunctionCall(void);
virtual AVSValue Evaluate(IScriptEnvironment* env);
bool EvaluateSyntax(AVSValue* result, const char* name, std::vector<AVSValue>* args, int extra, IScriptEnvironment2* env2);
private:
const char* const name;
PExpression* arg_exprs;
const char** arg_expr_names;
int arg_expr_count;
const bool oop_notation;
const int frame_number;
};
#endif // __Expression_H_