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 class CFX_WideTextBuf; 16 17 class CXFA_FMExpression { 18 public: 19 virtual ~CXFA_FMExpression() = default; 20 virtual bool ToJavaScript(CFX_WideTextBuf* js, ReturnType type) = 0; 21 22 protected: 23 CXFA_FMExpression(); 24 }; 25 26 class CXFA_FMFunctionDefinition final : public CXFA_FMExpression { 27 public: 28 CXFA_FMFunctionDefinition( 29 WideStringView wsName, 30 std::vector<WideStringView>&& arguments, 31 std::vector<std::unique_ptr<CXFA_FMExpression>>&& expressions); 32 ~CXFA_FMFunctionDefinition() override; 33 34 bool ToJavaScript(CFX_WideTextBuf* js, ReturnType type) override; 35 36 private: 37 WideStringView m_wsName; 38 std::vector<WideStringView> m_pArguments; 39 std::vector<std::unique_ptr<CXFA_FMExpression>> m_pExpressions; 40 }; 41 42 class CXFA_FMAST { 43 public: 44 explicit CXFA_FMAST( 45 std::vector<std::unique_ptr<CXFA_FMExpression>> expressions); 46 ~CXFA_FMAST(); 47 48 bool ToJavaScript(CFX_WideTextBuf* js); 49 50 private: 51 std::vector<std::unique_ptr<CXFA_FMExpression>> expressions_; 52 }; 53 54 class CXFA_FMVarExpression final : public CXFA_FMExpression { 55 public: 56 CXFA_FMVarExpression(WideStringView wsName, 57 std::unique_ptr<CXFA_FMSimpleExpression> pInit); 58 ~CXFA_FMVarExpression() override; 59 60 bool ToJavaScript(CFX_WideTextBuf* js, ReturnType type) override; 61 62 private: 63 WideStringView m_wsName; 64 std::unique_ptr<CXFA_FMSimpleExpression> m_pInit; 65 }; 66 67 class CXFA_FMExpExpression final : public CXFA_FMExpression { 68 public: 69 explicit CXFA_FMExpExpression( 70 std::unique_ptr<CXFA_FMSimpleExpression> pExpression); 71 ~CXFA_FMExpExpression() override; 72 73 bool ToJavaScript(CFX_WideTextBuf* js, ReturnType type) override; 74 75 private: 76 std::unique_ptr<CXFA_FMSimpleExpression> m_pExpression; 77 }; 78 79 class CXFA_FMBlockExpression final : public CXFA_FMExpression { 80 public: 81 CXFA_FMBlockExpression( 82 std::vector<std::unique_ptr<CXFA_FMExpression>>&& pExpressionList); 83 ~CXFA_FMBlockExpression() override; 84 85 bool ToJavaScript(CFX_WideTextBuf* js, ReturnType type) override; 86 87 private: 88 std::vector<std::unique_ptr<CXFA_FMExpression>> m_ExpressionList; 89 }; 90 91 class CXFA_FMDoExpression final : public CXFA_FMExpression { 92 public: 93 explicit CXFA_FMDoExpression(std::unique_ptr<CXFA_FMExpression> pList); 94 ~CXFA_FMDoExpression() override; 95 96 bool ToJavaScript(CFX_WideTextBuf* js, ReturnType type) override; 97 98 private: 99 std::unique_ptr<CXFA_FMExpression> m_pList; 100 }; 101 102 class CXFA_FMIfExpression final : public CXFA_FMExpression { 103 public: 104 CXFA_FMIfExpression( 105 std::unique_ptr<CXFA_FMSimpleExpression> pExpression, 106 std::unique_ptr<CXFA_FMExpression> pIfExpression, 107 std::vector<std::unique_ptr<CXFA_FMIfExpression>> pElseIfExpressions, 108 std::unique_ptr<CXFA_FMExpression> pElseExpression); 109 ~CXFA_FMIfExpression() override; 110 111 bool ToJavaScript(CFX_WideTextBuf* js, ReturnType type) override; 112 113 private: 114 std::unique_ptr<CXFA_FMSimpleExpression> m_pExpression; 115 std::unique_ptr<CXFA_FMExpression> m_pIfExpression; 116 std::vector<std::unique_ptr<CXFA_FMIfExpression>> m_pElseIfExpressions; 117 std::unique_ptr<CXFA_FMExpression> m_pElseExpression; 118 }; 119 120 class CXFA_FMWhileExpression final : public CXFA_FMExpression { 121 public: 122 CXFA_FMWhileExpression(std::unique_ptr<CXFA_FMSimpleExpression> pCodition, 123 std::unique_ptr<CXFA_FMExpression> pExpression); 124 ~CXFA_FMWhileExpression() override; 125 126 bool ToJavaScript(CFX_WideTextBuf* js, ReturnType type) override; 127 128 private: 129 std::unique_ptr<CXFA_FMSimpleExpression> m_pCondition; 130 std::unique_ptr<CXFA_FMExpression> m_pExpression; 131 }; 132 133 class CXFA_FMBreakExpression final : public CXFA_FMExpression { 134 public: 135 CXFA_FMBreakExpression(); 136 ~CXFA_FMBreakExpression() override; 137 138 bool ToJavaScript(CFX_WideTextBuf* js, ReturnType type) override; 139 }; 140 141 class CXFA_FMContinueExpression final : public CXFA_FMExpression { 142 public: 143 CXFA_FMContinueExpression(); 144 ~CXFA_FMContinueExpression() override; 145 146 bool ToJavaScript(CFX_WideTextBuf* js, ReturnType type) override; 147 }; 148 149 class CXFA_FMForExpression final : public CXFA_FMExpression { 150 public: 151 CXFA_FMForExpression(WideStringView wsVariant, 152 std::unique_ptr<CXFA_FMSimpleExpression> pAssignment, 153 std::unique_ptr<CXFA_FMSimpleExpression> pAccessor, 154 int32_t iDirection, 155 std::unique_ptr<CXFA_FMSimpleExpression> pStep, 156 std::unique_ptr<CXFA_FMExpression> pList); 157 ~CXFA_FMForExpression() override; 158 159 bool ToJavaScript(CFX_WideTextBuf* js, ReturnType type) override; 160 161 private: 162 WideStringView m_wsVariant; 163 std::unique_ptr<CXFA_FMSimpleExpression> m_pAssignment; 164 std::unique_ptr<CXFA_FMSimpleExpression> m_pAccessor; 165 const bool m_bDirection; 166 std::unique_ptr<CXFA_FMSimpleExpression> m_pStep; 167 std::unique_ptr<CXFA_FMExpression> m_pList; 168 }; 169 170 class CXFA_FMForeachExpression final : public CXFA_FMExpression { 171 public: 172 // Takes ownership of |pAccessors|. 173 CXFA_FMForeachExpression( 174 WideStringView wsIdentifier, 175 std::vector<std::unique_ptr<CXFA_FMSimpleExpression>>&& pAccessors, 176 std::unique_ptr<CXFA_FMExpression> pList); 177 ~CXFA_FMForeachExpression() override; 178 179 bool ToJavaScript(CFX_WideTextBuf* js, ReturnType type) override; 180 181 private: 182 WideStringView m_wsIdentifier; 183 std::vector<std::unique_ptr<CXFA_FMSimpleExpression>> m_pAccessors; 184 std::unique_ptr<CXFA_FMExpression> m_pList; 185 }; 186 187 #endif // XFA_FXFA_FM2JS_CXFA_FMEXPRESSION_H_ 188