• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2014 PDFium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
6 
7 #ifndef XFA_FXFA_FM2JS_XFA_SIMPLEEXPRESSION_H_
8 #define XFA_FXFA_FM2JS_XFA_SIMPLEEXPRESSION_H_
9 
10 #include <memory>
11 #include <vector>
12 
13 #include "core/fxcrt/fx_basic.h"
14 #include "xfa/fxfa/fm2js/xfa_lexer.h"
15 
16 #define RUNTIMEFUNCTIONRETURNVALUE \
17   (L"foxit_xfa_formcalc_runtime_func_return_value")
18 #define EXCLAMATION_IN_IDENTIFIER (L"foxit_xfa_formcalc__exclamation__")
19 
20 enum XFA_FM_SimpleExpressionType {
21   ASSIGN,
22   LOGICALOR,
23   LOGICALAND,
24   EQUALITY,
25   NOTEQUALITY,
26   LESS,
27   LESSEQUAL,
28   GREATER,
29   GREATEREQUAL,
30   PLUS,
31   MINUS,
32   MULTIPLE,
33   DIVIDE,
34   POSITIVE,
35   NEGATIVE,
36   NOT,
37   CALL,
38   DOT,
39   DOTDOT,
40   CONCATFMOBJECT,
41   ISFMOBJECT,
42   ISFMARRAY,
43   GETFMVALUE,
44   GETFMJSOBJ,
45   VARFILTER
46 };
47 
48 CFX_WideStringC XFA_FM_EXPTypeToString(
49     XFA_FM_SimpleExpressionType simpleExpType);
50 
51 enum XFA_FM_AccessorIndex {
52   ACCESSOR_NO_INDEX,
53   ACCESSOR_NO_RELATIVEINDEX,
54   ACCESSOR_POSITIVE_INDEX,
55   ACCESSOR_NEGATIVE_INDEX
56 };
57 
58 class CXFA_FMSimpleExpression {
59  public:
60   CXFA_FMSimpleExpression(uint32_t line, XFA_FM_TOKEN op);
~CXFA_FMSimpleExpression()61   virtual ~CXFA_FMSimpleExpression() {}
62   virtual void ToJavaScript(CFX_WideTextBuf& javascript);
63   virtual void ToImpliedReturnJS(CFX_WideTextBuf& javascript);
64 
65   XFA_FM_TOKEN GetOperatorToken() const;
66 
67  protected:
68   uint32_t m_line;
69   XFA_FM_TOKEN m_op;
70 };
71 
72 class CXFA_FMNullExpression : public CXFA_FMSimpleExpression {
73  public:
74   explicit CXFA_FMNullExpression(uint32_t line);
~CXFA_FMNullExpression()75   ~CXFA_FMNullExpression() override {}
76   void ToJavaScript(CFX_WideTextBuf& javascript) override;
77 };
78 
79 class CXFA_FMNumberExpression : public CXFA_FMSimpleExpression {
80  public:
81   CXFA_FMNumberExpression(uint32_t line, CFX_WideStringC wsNumber);
82   ~CXFA_FMNumberExpression() override;
83   void ToJavaScript(CFX_WideTextBuf& javascript) override;
84 
85  private:
86   CFX_WideStringC m_wsNumber;
87 };
88 
89 class CXFA_FMStringExpression : public CXFA_FMSimpleExpression {
90  public:
91   CXFA_FMStringExpression(uint32_t line, CFX_WideStringC wsString);
92   ~CXFA_FMStringExpression() override;
93   void ToJavaScript(CFX_WideTextBuf& javascript) override;
94 
95  private:
96   CFX_WideStringC m_wsString;
97 };
98 
99 class CXFA_FMIdentifierExpression : public CXFA_FMSimpleExpression {
100  public:
101   CXFA_FMIdentifierExpression(uint32_t line, CFX_WideStringC wsIdentifier);
102   ~CXFA_FMIdentifierExpression() override;
103   void ToJavaScript(CFX_WideTextBuf& javascript) override;
104 
105  private:
106   CFX_WideStringC m_wsIdentifier;
107 };
108 
109 class CXFA_FMUnaryExpression : public CXFA_FMSimpleExpression {
110  public:
111   CXFA_FMUnaryExpression(uint32_t line,
112                          XFA_FM_TOKEN op,
113                          std::unique_ptr<CXFA_FMSimpleExpression> pExp);
114   ~CXFA_FMUnaryExpression() override;
115 
116   void ToJavaScript(CFX_WideTextBuf& javascript) override;
117 
118  protected:
119   std::unique_ptr<CXFA_FMSimpleExpression> m_pExp;
120 };
121 
122 class CXFA_FMBinExpression : public CXFA_FMSimpleExpression {
123  public:
124   CXFA_FMBinExpression(uint32_t line,
125                        XFA_FM_TOKEN op,
126                        std::unique_ptr<CXFA_FMSimpleExpression> pExp1,
127                        std::unique_ptr<CXFA_FMSimpleExpression> pExp2);
128   ~CXFA_FMBinExpression() override;
129 
130   void ToJavaScript(CFX_WideTextBuf& javascript) override;
131 
132  protected:
133   std::unique_ptr<CXFA_FMSimpleExpression> m_pExp1;
134   std::unique_ptr<CXFA_FMSimpleExpression> m_pExp2;
135 };
136 
137 class CXFA_FMAssignExpression : public CXFA_FMBinExpression {
138  public:
139   CXFA_FMAssignExpression(uint32_t line,
140                           XFA_FM_TOKEN op,
141                           std::unique_ptr<CXFA_FMSimpleExpression> pExp1,
142                           std::unique_ptr<CXFA_FMSimpleExpression> pExp2);
~CXFA_FMAssignExpression()143   ~CXFA_FMAssignExpression() override {}
144   void ToJavaScript(CFX_WideTextBuf& javascript) override;
145   void ToImpliedReturnJS(CFX_WideTextBuf& javascript) override;
146 };
147 
148 class CXFA_FMLogicalOrExpression : public CXFA_FMBinExpression {
149  public:
150   CXFA_FMLogicalOrExpression(uint32_t line,
151                              XFA_FM_TOKEN op,
152                              std::unique_ptr<CXFA_FMSimpleExpression> pExp1,
153                              std::unique_ptr<CXFA_FMSimpleExpression> pExp2);
~CXFA_FMLogicalOrExpression()154   ~CXFA_FMLogicalOrExpression() override {}
155   void ToJavaScript(CFX_WideTextBuf& javascript) override;
156 };
157 
158 class CXFA_FMLogicalAndExpression : public CXFA_FMBinExpression {
159  public:
160   CXFA_FMLogicalAndExpression(uint32_t line,
161                               XFA_FM_TOKEN op,
162                               std::unique_ptr<CXFA_FMSimpleExpression> pExp1,
163                               std::unique_ptr<CXFA_FMSimpleExpression> pExp2);
~CXFA_FMLogicalAndExpression()164   ~CXFA_FMLogicalAndExpression() override {}
165   void ToJavaScript(CFX_WideTextBuf& javascript) override;
166 };
167 
168 class CXFA_FMEqualityExpression : public CXFA_FMBinExpression {
169  public:
170   CXFA_FMEqualityExpression(uint32_t line,
171                             XFA_FM_TOKEN op,
172                             std::unique_ptr<CXFA_FMSimpleExpression> pExp1,
173                             std::unique_ptr<CXFA_FMSimpleExpression> pExp2);
~CXFA_FMEqualityExpression()174   ~CXFA_FMEqualityExpression() override {}
175   void ToJavaScript(CFX_WideTextBuf& javascript) override;
176 };
177 
178 class CXFA_FMRelationalExpression : public CXFA_FMBinExpression {
179  public:
180   CXFA_FMRelationalExpression(uint32_t line,
181                               XFA_FM_TOKEN op,
182                               std::unique_ptr<CXFA_FMSimpleExpression> pExp1,
183                               std::unique_ptr<CXFA_FMSimpleExpression> pExp2);
~CXFA_FMRelationalExpression()184   ~CXFA_FMRelationalExpression() override {}
185   void ToJavaScript(CFX_WideTextBuf& javascript) override;
186 };
187 
188 class CXFA_FMAdditiveExpression : public CXFA_FMBinExpression {
189  public:
190   CXFA_FMAdditiveExpression(uint32_t line,
191                             XFA_FM_TOKEN op,
192                             std::unique_ptr<CXFA_FMSimpleExpression> pExp1,
193                             std::unique_ptr<CXFA_FMSimpleExpression> pExp2);
~CXFA_FMAdditiveExpression()194   ~CXFA_FMAdditiveExpression() override {}
195   void ToJavaScript(CFX_WideTextBuf& javascript) override;
196 };
197 
198 class CXFA_FMMultiplicativeExpression : public CXFA_FMBinExpression {
199  public:
200   CXFA_FMMultiplicativeExpression(
201       uint32_t line,
202       XFA_FM_TOKEN op,
203       std::unique_ptr<CXFA_FMSimpleExpression> pExp1,
204       std::unique_ptr<CXFA_FMSimpleExpression> pExp2);
~CXFA_FMMultiplicativeExpression()205   ~CXFA_FMMultiplicativeExpression() override {}
206   void ToJavaScript(CFX_WideTextBuf& javascript) override;
207 };
208 
209 class CXFA_FMPosExpression : public CXFA_FMUnaryExpression {
210  public:
211   CXFA_FMPosExpression(uint32_t line,
212                        std::unique_ptr<CXFA_FMSimpleExpression> pExp);
~CXFA_FMPosExpression()213   ~CXFA_FMPosExpression() override {}
214   void ToJavaScript(CFX_WideTextBuf& javascript) override;
215 };
216 
217 class CXFA_FMNegExpression : public CXFA_FMUnaryExpression {
218  public:
219   CXFA_FMNegExpression(uint32_t line,
220                        std::unique_ptr<CXFA_FMSimpleExpression> pExp);
~CXFA_FMNegExpression()221   ~CXFA_FMNegExpression() override {}
222   void ToJavaScript(CFX_WideTextBuf& javascript) override;
223 };
224 
225 class CXFA_FMNotExpression : public CXFA_FMUnaryExpression {
226  public:
227   CXFA_FMNotExpression(uint32_t line,
228                        std::unique_ptr<CXFA_FMSimpleExpression> pExp);
~CXFA_FMNotExpression()229   ~CXFA_FMNotExpression() override {}
230   void ToJavaScript(CFX_WideTextBuf& javascript) override;
231 };
232 
233 class CXFA_FMCallExpression : public CXFA_FMUnaryExpression {
234  public:
235   CXFA_FMCallExpression(
236       uint32_t line,
237       std::unique_ptr<CXFA_FMSimpleExpression> pExp,
238       std::vector<std::unique_ptr<CXFA_FMSimpleExpression>>&& pArguments,
239       bool bIsSomMethod);
240   ~CXFA_FMCallExpression() override;
241 
242   bool IsBuildInFunc(CFX_WideTextBuf* funcName);
243   uint32_t IsMethodWithObjParam(const CFX_WideStringC& methodName);
244   void ToJavaScript(CFX_WideTextBuf& javascript) override;
245 
246  private:
247   bool m_bIsSomMethod;
248   std::vector<std::unique_ptr<CXFA_FMSimpleExpression>> m_Arguments;
249 };
250 
251 class CXFA_FMDotAccessorExpression : public CXFA_FMBinExpression {
252  public:
253   CXFA_FMDotAccessorExpression(
254       uint32_t line,
255       std::unique_ptr<CXFA_FMSimpleExpression> pAccessor,
256       XFA_FM_TOKEN op,
257       CFX_WideStringC wsIdentifier,
258       std::unique_ptr<CXFA_FMSimpleExpression> pIndexExp);
259   ~CXFA_FMDotAccessorExpression() override;
260   void ToJavaScript(CFX_WideTextBuf& javascript) override;
261 
262  private:
263   CFX_WideStringC m_wsIdentifier;
264 };
265 
266 class CXFA_FMIndexExpression : public CXFA_FMUnaryExpression {
267  public:
268   CXFA_FMIndexExpression(uint32_t line,
269                          XFA_FM_AccessorIndex accessorIndex,
270                          std::unique_ptr<CXFA_FMSimpleExpression> pIndexExp,
271                          bool bIsStarIndex);
~CXFA_FMIndexExpression()272   ~CXFA_FMIndexExpression() override {}
273   void ToJavaScript(CFX_WideTextBuf& javascript) override;
274 
275  private:
276   XFA_FM_AccessorIndex m_accessorIndex;
277   bool m_bIsStarIndex;
278 };
279 
280 class CXFA_FMDotDotAccessorExpression : public CXFA_FMBinExpression {
281  public:
282   CXFA_FMDotDotAccessorExpression(
283       uint32_t line,
284       std::unique_ptr<CXFA_FMSimpleExpression> pAccessor,
285       XFA_FM_TOKEN op,
286       CFX_WideStringC wsIdentifier,
287       std::unique_ptr<CXFA_FMSimpleExpression> pIndexExp);
288   ~CXFA_FMDotDotAccessorExpression() override;
289 
290   void ToJavaScript(CFX_WideTextBuf& javascript) override;
291 
292  private:
293   CFX_WideStringC m_wsIdentifier;
294 };
295 
296 class CXFA_FMMethodCallExpression : public CXFA_FMBinExpression {
297  public:
298   CXFA_FMMethodCallExpression(
299       uint32_t line,
300       std::unique_ptr<CXFA_FMSimpleExpression> pAccessorExp1,
301       std::unique_ptr<CXFA_FMSimpleExpression> pCallExp);
~CXFA_FMMethodCallExpression()302   ~CXFA_FMMethodCallExpression() override {}
303   void ToJavaScript(CFX_WideTextBuf& javascript) override;
304 };
305 
306 #endif  // XFA_FXFA_FM2JS_XFA_SIMPLEEXPRESSION_H_
307