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
|
// Copyright 2014 PDFium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
#ifndef XFA_FXFA_FM2JS_CXFA_FMSIMPLEEXPRESSION_H_
#define XFA_FXFA_FM2JS_CXFA_FMSIMPLEEXPRESSION_H_
#include <memory>
#include <vector>
#include "xfa/fxfa/fm2js/cxfa_fmlexer.h"
enum XFA_FM_AccessorIndex {
ACCESSOR_NO_INDEX,
ACCESSOR_NO_RELATIVEINDEX,
ACCESSOR_POSITIVE_INDEX,
ACCESSOR_NEGATIVE_INDEX
};
enum class ReturnType { kImplied, kInfered };
class CFX_WideTextBuf;
class CXFA_FMSimpleExpression {
public:
virtual ~CXFA_FMSimpleExpression() {}
virtual bool ToJavaScript(CFX_WideTextBuf& javascript, ReturnType type) = 0;
XFA_FM_TOKEN GetOperatorToken() const;
protected:
explicit CXFA_FMSimpleExpression(XFA_FM_TOKEN op);
const XFA_FM_TOKEN m_op;
};
class CXFA_FMNullExpression : public CXFA_FMSimpleExpression {
public:
CXFA_FMNullExpression();
~CXFA_FMNullExpression() override {}
bool ToJavaScript(CFX_WideTextBuf& javascript, ReturnType type) override;
};
class CXFA_FMNumberExpression : public CXFA_FMSimpleExpression {
public:
explicit CXFA_FMNumberExpression(WideStringView wsNumber);
~CXFA_FMNumberExpression() override;
bool ToJavaScript(CFX_WideTextBuf& javascript, ReturnType type) override;
private:
WideStringView m_wsNumber;
};
class CXFA_FMStringExpression : public CXFA_FMSimpleExpression {
public:
explicit CXFA_FMStringExpression(WideStringView wsString);
~CXFA_FMStringExpression() override;
bool ToJavaScript(CFX_WideTextBuf& javascript, ReturnType type) override;
private:
WideStringView m_wsString;
};
class CXFA_FMIdentifierExpression : public CXFA_FMSimpleExpression {
public:
explicit CXFA_FMIdentifierExpression(WideStringView wsIdentifier);
~CXFA_FMIdentifierExpression() override;
bool ToJavaScript(CFX_WideTextBuf& javascript, ReturnType type) override;
private:
WideStringView m_wsIdentifier;
};
class CXFA_FMAssignExpression : public CXFA_FMSimpleExpression {
public:
CXFA_FMAssignExpression(XFA_FM_TOKEN op,
std::unique_ptr<CXFA_FMSimpleExpression> pExp1,
std::unique_ptr<CXFA_FMSimpleExpression> pExp2);
~CXFA_FMAssignExpression() override;
bool ToJavaScript(CFX_WideTextBuf& javascript, ReturnType type) override;
private:
std::unique_ptr<CXFA_FMSimpleExpression> m_pExp1;
std::unique_ptr<CXFA_FMSimpleExpression> m_pExp2;
};
class CXFA_FMBinExpression : public CXFA_FMSimpleExpression {
public:
~CXFA_FMBinExpression() override;
bool ToJavaScript(CFX_WideTextBuf& javascript, ReturnType type) override;
protected:
CXFA_FMBinExpression(const WideString& opName,
XFA_FM_TOKEN op,
std::unique_ptr<CXFA_FMSimpleExpression> pExp1,
std::unique_ptr<CXFA_FMSimpleExpression> pExp2);
private:
WideString m_OpName;
std::unique_ptr<CXFA_FMSimpleExpression> m_pExp1;
std::unique_ptr<CXFA_FMSimpleExpression> m_pExp2;
};
class CXFA_FMLogicalOrExpression : public CXFA_FMBinExpression {
public:
CXFA_FMLogicalOrExpression(XFA_FM_TOKEN op,
std::unique_ptr<CXFA_FMSimpleExpression> pExp1,
std::unique_ptr<CXFA_FMSimpleExpression> pExp2);
~CXFA_FMLogicalOrExpression() override {}
};
class CXFA_FMLogicalAndExpression : public CXFA_FMBinExpression {
public:
CXFA_FMLogicalAndExpression(XFA_FM_TOKEN op,
std::unique_ptr<CXFA_FMSimpleExpression> pExp1,
std::unique_ptr<CXFA_FMSimpleExpression> pExp2);
~CXFA_FMLogicalAndExpression() override {}
};
class CXFA_FMEqualExpression : public CXFA_FMBinExpression {
public:
CXFA_FMEqualExpression(XFA_FM_TOKEN op,
std::unique_ptr<CXFA_FMSimpleExpression> pExp1,
std::unique_ptr<CXFA_FMSimpleExpression> pExp2);
~CXFA_FMEqualExpression() override {}
};
class CXFA_FMNotEqualExpression : public CXFA_FMBinExpression {
public:
CXFA_FMNotEqualExpression(XFA_FM_TOKEN op,
std::unique_ptr<CXFA_FMSimpleExpression> pExp1,
std::unique_ptr<CXFA_FMSimpleExpression> pExp2);
~CXFA_FMNotEqualExpression() override {}
};
class CXFA_FMGtExpression : public CXFA_FMBinExpression {
public:
CXFA_FMGtExpression(XFA_FM_TOKEN op,
std::unique_ptr<CXFA_FMSimpleExpression> pExp1,
std::unique_ptr<CXFA_FMSimpleExpression> pExp2);
~CXFA_FMGtExpression() override {}
};
class CXFA_FMGeExpression : public CXFA_FMBinExpression {
public:
CXFA_FMGeExpression(XFA_FM_TOKEN op,
std::unique_ptr<CXFA_FMSimpleExpression> pExp1,
std::unique_ptr<CXFA_FMSimpleExpression> pExp2);
~CXFA_FMGeExpression() override {}
};
class CXFA_FMLtExpression : public CXFA_FMBinExpression {
public:
CXFA_FMLtExpression(XFA_FM_TOKEN op,
std::unique_ptr<CXFA_FMSimpleExpression> pExp1,
std::unique_ptr<CXFA_FMSimpleExpression> pExp2);
~CXFA_FMLtExpression() override {}
};
class CXFA_FMLeExpression : public CXFA_FMBinExpression {
public:
CXFA_FMLeExpression(XFA_FM_TOKEN op,
std::unique_ptr<CXFA_FMSimpleExpression> pExp1,
std::unique_ptr<CXFA_FMSimpleExpression> pExp2);
~CXFA_FMLeExpression() override {}
};
class CXFA_FMPlusExpression : public CXFA_FMBinExpression {
public:
CXFA_FMPlusExpression(XFA_FM_TOKEN op,
std::unique_ptr<CXFA_FMSimpleExpression> pExp1,
std::unique_ptr<CXFA_FMSimpleExpression> pExp2);
~CXFA_FMPlusExpression() override {}
};
class CXFA_FMMinusExpression : public CXFA_FMBinExpression {
public:
CXFA_FMMinusExpression(XFA_FM_TOKEN op,
std::unique_ptr<CXFA_FMSimpleExpression> pExp1,
std::unique_ptr<CXFA_FMSimpleExpression> pExp2);
~CXFA_FMMinusExpression() override {}
};
class CXFA_FMMulExpression : public CXFA_FMBinExpression {
public:
CXFA_FMMulExpression(XFA_FM_TOKEN op,
std::unique_ptr<CXFA_FMSimpleExpression> pExp1,
std::unique_ptr<CXFA_FMSimpleExpression> pExp2);
~CXFA_FMMulExpression() override {}
};
class CXFA_FMDivExpression : public CXFA_FMBinExpression {
public:
CXFA_FMDivExpression(XFA_FM_TOKEN op,
std::unique_ptr<CXFA_FMSimpleExpression> pExp1,
std::unique_ptr<CXFA_FMSimpleExpression> pExp2);
~CXFA_FMDivExpression() override {}
};
class CXFA_FMUnaryExpression : public CXFA_FMSimpleExpression {
public:
~CXFA_FMUnaryExpression() override;
bool ToJavaScript(CFX_WideTextBuf& javascript, ReturnType type) override;
protected:
CXFA_FMUnaryExpression(const WideString& opName,
XFA_FM_TOKEN op,
std::unique_ptr<CXFA_FMSimpleExpression> pExp);
private:
WideString m_OpName;
std::unique_ptr<CXFA_FMSimpleExpression> m_pExp;
};
class CXFA_FMPosExpression : public CXFA_FMUnaryExpression {
public:
explicit CXFA_FMPosExpression(std::unique_ptr<CXFA_FMSimpleExpression> pExp);
~CXFA_FMPosExpression() override {}
};
class CXFA_FMNegExpression : public CXFA_FMUnaryExpression {
public:
explicit CXFA_FMNegExpression(std::unique_ptr<CXFA_FMSimpleExpression> pExp);
~CXFA_FMNegExpression() override {}
};
class CXFA_FMNotExpression : public CXFA_FMUnaryExpression {
public:
explicit CXFA_FMNotExpression(std::unique_ptr<CXFA_FMSimpleExpression> pExp);
~CXFA_FMNotExpression() override {}
};
class CXFA_FMCallExpression : public CXFA_FMSimpleExpression {
public:
CXFA_FMCallExpression(
std::unique_ptr<CXFA_FMSimpleExpression> pExp,
std::vector<std::unique_ptr<CXFA_FMSimpleExpression>>&& pArguments,
bool bIsSomMethod);
~CXFA_FMCallExpression() override;
bool IsBuiltInFunc(CFX_WideTextBuf* funcName);
uint32_t IsMethodWithObjParam(const WideString& methodName);
bool ToJavaScript(CFX_WideTextBuf& javascript, ReturnType type) override;
private:
std::unique_ptr<CXFA_FMSimpleExpression> m_pExp;
bool m_bIsSomMethod;
std::vector<std::unique_ptr<CXFA_FMSimpleExpression>> m_Arguments;
};
class CXFA_FMDotAccessorExpression : public CXFA_FMSimpleExpression {
public:
CXFA_FMDotAccessorExpression(
std::unique_ptr<CXFA_FMSimpleExpression> pAccessor,
XFA_FM_TOKEN op,
WideStringView wsIdentifier,
std::unique_ptr<CXFA_FMSimpleExpression> pIndexExp);
~CXFA_FMDotAccessorExpression() override;
bool ToJavaScript(CFX_WideTextBuf& javascript, ReturnType type) override;
private:
WideStringView m_wsIdentifier;
std::unique_ptr<CXFA_FMSimpleExpression> m_pExp1;
std::unique_ptr<CXFA_FMSimpleExpression> m_pExp2;
};
class CXFA_FMIndexExpression : public CXFA_FMSimpleExpression {
public:
CXFA_FMIndexExpression(XFA_FM_AccessorIndex accessorIndex,
std::unique_ptr<CXFA_FMSimpleExpression> pIndexExp,
bool bIsStarIndex);
~CXFA_FMIndexExpression() override;
bool ToJavaScript(CFX_WideTextBuf& javascript, ReturnType type) override;
private:
std::unique_ptr<CXFA_FMSimpleExpression> m_pExp;
XFA_FM_AccessorIndex m_accessorIndex;
bool m_bIsStarIndex;
};
class CXFA_FMDotDotAccessorExpression : public CXFA_FMSimpleExpression {
public:
CXFA_FMDotDotAccessorExpression(
std::unique_ptr<CXFA_FMSimpleExpression> pAccessor,
XFA_FM_TOKEN op,
WideStringView wsIdentifier,
std::unique_ptr<CXFA_FMSimpleExpression> pIndexExp);
~CXFA_FMDotDotAccessorExpression() override;
bool ToJavaScript(CFX_WideTextBuf& javascript, ReturnType type) override;
private:
WideStringView m_wsIdentifier;
std::unique_ptr<CXFA_FMSimpleExpression> m_pExp1;
std::unique_ptr<CXFA_FMSimpleExpression> m_pExp2;
};
class CXFA_FMMethodCallExpression : public CXFA_FMSimpleExpression {
public:
CXFA_FMMethodCallExpression(
std::unique_ptr<CXFA_FMSimpleExpression> pAccessorExp1,
std::unique_ptr<CXFA_FMSimpleExpression> pCallExp);
~CXFA_FMMethodCallExpression() override;
bool ToJavaScript(CFX_WideTextBuf& javascript, ReturnType type) override;
private:
std::unique_ptr<CXFA_FMSimpleExpression> m_pExp1;
std::unique_ptr<CXFA_FMSimpleExpression> m_pExp2;
};
bool CXFA_IsTooBig(const CFX_WideTextBuf& javascript);
#endif // XFA_FXFA_FM2JS_CXFA_FMSIMPLEEXPRESSION_H_
|