• 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_CXFA_FMEXPRESSION_H_
8 #define XFA_FXFA_FM2JS_CXFA_FMEXPRESSION_H_
9 
10 #include <memory>
11 #include <vector>
12 
13 #include "xfa/fxfa/fm2js/cxfa_fmsimpleexpression.h"
14 
15 enum XFA_FM_EXPTYPE {
16   XFA_FM_EXPTYPE_UNKNOWN,
17   XFA_FM_EXPTYPE_FUNC,
18   XFA_FM_EXPTYPE_VAR,
19   XFA_FM_EXPTYPE_EXP,
20   XFA_FM_EXPTYPE_BLOCK,
21   XFA_FM_EXPTYPE_IF,
22   XFA_FM_EXPTYPE_BREAK,
23   XFA_FM_EXPTYPE_CONTINUE,
24 };
25 
26 class CFX_WideTextBuf;
27 
28 class CXFA_FMExpression {
29  public:
30   explicit CXFA_FMExpression(uint32_t line);
31   CXFA_FMExpression(uint32_t line, XFA_FM_EXPTYPE type);
~CXFA_FMExpression()32   virtual ~CXFA_FMExpression() {}
33 
34   virtual bool ToJavaScript(CFX_WideTextBuf& javascript);
35   virtual bool ToImpliedReturnJS(CFX_WideTextBuf&);
GetLine()36   uint32_t GetLine() { return m_line; }
GetExpType()37   XFA_FM_EXPTYPE GetExpType() const { return m_type; }
38 
39  private:
40   XFA_FM_EXPTYPE m_type;
41   uint32_t m_line;
42 };
43 
44 class CXFA_FMFunctionDefinition : public CXFA_FMExpression {
45  public:
46   // Takes ownership of |arguments| and |expressions|.
47   CXFA_FMFunctionDefinition(
48       uint32_t line,
49       bool isGlobal,
50       const WideStringView& wsName,
51       std::vector<WideStringView>&& arguments,
52       std::vector<std::unique_ptr<CXFA_FMExpression>>&& expressions);
53   ~CXFA_FMFunctionDefinition() override;
54 
55   bool ToJavaScript(CFX_WideTextBuf& javascript) override;
56   bool ToImpliedReturnJS(CFX_WideTextBuf&) override;
57 
58  private:
59   WideStringView m_wsName;
60   std::vector<WideStringView> m_pArguments;
61   std::vector<std::unique_ptr<CXFA_FMExpression>> m_pExpressions;
62   bool m_isGlobal;
63 };
64 
65 class CXFA_FMVarExpression : public CXFA_FMExpression {
66  public:
67   CXFA_FMVarExpression(uint32_t line,
68                        const WideStringView& wsName,
69                        std::unique_ptr<CXFA_FMExpression> pInit);
70   ~CXFA_FMVarExpression() override;
71 
72   bool ToJavaScript(CFX_WideTextBuf& javascript) override;
73   bool ToImpliedReturnJS(CFX_WideTextBuf&) override;
74 
75  private:
76   WideStringView m_wsName;
77   std::unique_ptr<CXFA_FMExpression> m_pInit;
78 };
79 
80 class CXFA_FMExpExpression : public CXFA_FMExpression {
81  public:
82   CXFA_FMExpExpression(uint32_t line,
83                        std::unique_ptr<CXFA_FMSimpleExpression> pExpression);
84   ~CXFA_FMExpExpression() override;
85 
86   bool ToJavaScript(CFX_WideTextBuf& javascript) override;
87   bool ToImpliedReturnJS(CFX_WideTextBuf&) override;
88 
89  private:
90   std::unique_ptr<CXFA_FMSimpleExpression> m_pExpression;
91 };
92 
93 class CXFA_FMBlockExpression : public CXFA_FMExpression {
94  public:
95   CXFA_FMBlockExpression(
96       uint32_t line,
97       std::vector<std::unique_ptr<CXFA_FMExpression>>&& pExpressionList);
98   ~CXFA_FMBlockExpression() override;
99 
100   bool ToJavaScript(CFX_WideTextBuf& javascript) override;
101   bool ToImpliedReturnJS(CFX_WideTextBuf&) override;
102 
103  private:
104   std::vector<std::unique_ptr<CXFA_FMExpression>> m_ExpressionList;
105 };
106 
107 class CXFA_FMDoExpression : public CXFA_FMExpression {
108  public:
109   CXFA_FMDoExpression(uint32_t line, std::unique_ptr<CXFA_FMExpression> pList);
110   ~CXFA_FMDoExpression() override;
111 
112   bool ToJavaScript(CFX_WideTextBuf& javascript) override;
113   bool ToImpliedReturnJS(CFX_WideTextBuf&) override;
114 
115  private:
116   std::unique_ptr<CXFA_FMExpression> m_pList;
117 };
118 
119 class CXFA_FMIfExpression : public CXFA_FMExpression {
120  public:
121   CXFA_FMIfExpression(uint32_t line,
122                       std::unique_ptr<CXFA_FMSimpleExpression> pExpression,
123                       std::unique_ptr<CXFA_FMExpression> pIfExpression,
124                       std::unique_ptr<CXFA_FMExpression> pElseExpression);
125   ~CXFA_FMIfExpression() override;
126 
127   bool ToJavaScript(CFX_WideTextBuf& javascript) override;
128   bool ToImpliedReturnJS(CFX_WideTextBuf&) override;
129 
130  private:
131   std::unique_ptr<CXFA_FMSimpleExpression> m_pExpression;
132   std::unique_ptr<CXFA_FMExpression> m_pIfExpression;
133   std::unique_ptr<CXFA_FMExpression> m_pElseExpression;
134 };
135 
136 class CXFA_FMLoopExpression : public CXFA_FMExpression {
137  public:
CXFA_FMLoopExpression(uint32_t line)138   explicit CXFA_FMLoopExpression(uint32_t line) : CXFA_FMExpression(line) {}
139   ~CXFA_FMLoopExpression() override;
140   bool ToJavaScript(CFX_WideTextBuf& javascript) override;
141   bool ToImpliedReturnJS(CFX_WideTextBuf&) override;
142 };
143 
144 class CXFA_FMWhileExpression : public CXFA_FMLoopExpression {
145  public:
146   CXFA_FMWhileExpression(uint32_t line,
147                          std::unique_ptr<CXFA_FMSimpleExpression> pCodition,
148                          std::unique_ptr<CXFA_FMExpression> pExpression);
149   ~CXFA_FMWhileExpression() override;
150 
151   bool ToJavaScript(CFX_WideTextBuf& javascript) override;
152   bool ToImpliedReturnJS(CFX_WideTextBuf&) override;
153 
154  private:
155   std::unique_ptr<CXFA_FMSimpleExpression> m_pCondition;
156   std::unique_ptr<CXFA_FMExpression> m_pExpression;
157 };
158 
159 class CXFA_FMBreakExpression : public CXFA_FMExpression {
160  public:
161   explicit CXFA_FMBreakExpression(uint32_t line);
162   ~CXFA_FMBreakExpression() override;
163   bool ToJavaScript(CFX_WideTextBuf& javascript) override;
164   bool ToImpliedReturnJS(CFX_WideTextBuf&) override;
165 };
166 
167 class CXFA_FMContinueExpression : public CXFA_FMExpression {
168  public:
169   explicit CXFA_FMContinueExpression(uint32_t line);
170   ~CXFA_FMContinueExpression() override;
171   bool ToJavaScript(CFX_WideTextBuf& javascript) override;
172   bool ToImpliedReturnJS(CFX_WideTextBuf&) override;
173 };
174 
175 class CXFA_FMForExpression : public CXFA_FMLoopExpression {
176  public:
177   CXFA_FMForExpression(uint32_t line,
178                        const WideStringView& wsVariant,
179                        std::unique_ptr<CXFA_FMSimpleExpression> pAssignment,
180                        std::unique_ptr<CXFA_FMSimpleExpression> pAccessor,
181                        int32_t iDirection,
182                        std::unique_ptr<CXFA_FMSimpleExpression> pStep,
183                        std::unique_ptr<CXFA_FMExpression> pList);
184   ~CXFA_FMForExpression() override;
185 
186   bool ToJavaScript(CFX_WideTextBuf& javascript) override;
187   bool ToImpliedReturnJS(CFX_WideTextBuf&) override;
188 
189  private:
190   WideStringView m_wsVariant;
191   std::unique_ptr<CXFA_FMSimpleExpression> m_pAssignment;
192   std::unique_ptr<CXFA_FMSimpleExpression> m_pAccessor;
193   const bool m_bDirection;
194   std::unique_ptr<CXFA_FMSimpleExpression> m_pStep;
195   std::unique_ptr<CXFA_FMExpression> m_pList;
196 };
197 
198 class CXFA_FMForeachExpression : public CXFA_FMLoopExpression {
199  public:
200   // Takes ownership of |pAccessors|.
201   CXFA_FMForeachExpression(
202       uint32_t line,
203       const WideStringView& wsIdentifier,
204       std::vector<std::unique_ptr<CXFA_FMSimpleExpression>>&& pAccessors,
205       std::unique_ptr<CXFA_FMExpression> pList);
206   ~CXFA_FMForeachExpression() override;
207 
208   bool ToJavaScript(CFX_WideTextBuf& javascript) override;
209   bool ToImpliedReturnJS(CFX_WideTextBuf&) override;
210 
211  private:
212   WideStringView m_wsIdentifier;
213   std::vector<std::unique_ptr<CXFA_FMSimpleExpression>> m_pAccessors;
214   std::unique_ptr<CXFA_FMExpression> m_pList;
215 };
216 
217 #endif  // XFA_FXFA_FM2JS_CXFA_FMEXPRESSION_H_
218