OLD | NEW |
---|---|
1 // Copyright 2014 PDFium Authors. All rights reserved. | 1 // Copyright 2014 PDFium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com | 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com |
6 | 6 |
7 #include "xfa/fxfa/fm2js/xfa_expression.h" | 7 #include "xfa/fxfa/fm2js/xfa_expression.h" |
8 | 8 |
9 #include <utility> | 9 #include <utility> |
10 | 10 |
(...skipping 17 matching lines...) Expand all Loading... | |
28 | 28 |
29 void CXFA_FMExpression::ToJavaScript(CFX_WideTextBuf& javascript) {} | 29 void CXFA_FMExpression::ToJavaScript(CFX_WideTextBuf& javascript) {} |
30 | 30 |
31 void CXFA_FMExpression::ToImpliedReturnJS(CFX_WideTextBuf& javascript) {} | 31 void CXFA_FMExpression::ToImpliedReturnJS(CFX_WideTextBuf& javascript) {} |
32 | 32 |
33 CXFA_FMFunctionDefinition::CXFA_FMFunctionDefinition( | 33 CXFA_FMFunctionDefinition::CXFA_FMFunctionDefinition( |
34 uint32_t line, | 34 uint32_t line, |
35 bool isGlobal, | 35 bool isGlobal, |
36 const CFX_WideStringC& wsName, | 36 const CFX_WideStringC& wsName, |
37 std::unique_ptr<CFX_WideStringCArray> pArguments, | 37 std::unique_ptr<CFX_WideStringCArray> pArguments, |
38 CFX_ArrayTemplate<CXFA_FMExpression*>* pExpressions) | 38 std::vector<std::unique_ptr<CXFA_FMExpression>>&& pExpressions) |
39 : CXFA_FMExpression(line, XFA_FM_EXPTYPE_FUNC), | 39 : CXFA_FMExpression(line, XFA_FM_EXPTYPE_FUNC), |
40 m_wsName(wsName), | 40 m_wsName(wsName), |
41 m_pArguments(std::move(pArguments)), | 41 m_pArguments(std::move(pArguments)), |
42 m_pExpressions(pExpressions), | 42 m_pExpressions(std::move(pExpressions)), |
43 m_isGlobal(isGlobal) {} | 43 m_isGlobal(isGlobal) {} |
44 | 44 |
45 CXFA_FMFunctionDefinition::~CXFA_FMFunctionDefinition() { | 45 CXFA_FMFunctionDefinition::~CXFA_FMFunctionDefinition() {} |
46 if (m_pExpressions) { | |
47 for (int i = 0; i < m_pExpressions->GetSize(); ++i) | |
48 delete m_pExpressions->GetAt(i); | |
49 | |
50 delete m_pExpressions; | |
51 } | |
52 } | |
53 | 46 |
54 void CXFA_FMFunctionDefinition::ToJavaScript(CFX_WideTextBuf& javascript) { | 47 void CXFA_FMFunctionDefinition::ToJavaScript(CFX_WideTextBuf& javascript) { |
55 if (m_isGlobal && (!m_pExpressions || m_pExpressions->GetSize() == 0)) { | 48 if (m_isGlobal && m_pExpressions.empty()) { |
56 javascript << FX_WSTRC(L"// comments only"); | 49 javascript << FX_WSTRC(L"// comments only"); |
57 return; | 50 return; |
58 } | 51 } |
59 if (m_isGlobal) { | 52 if (m_isGlobal) { |
60 javascript << FX_WSTRC(L"(\n"); | 53 javascript << FX_WSTRC(L"(\n"); |
61 } | 54 } |
62 javascript << FX_WSTRC(L"function "); | 55 javascript << FX_WSTRC(L"function "); |
63 if (m_wsName.GetAt(0) == L'!') { | 56 if (m_wsName.GetAt(0) == L'!') { |
64 CFX_WideString tempName = EXCLAMATION_IN_IDENTIFIER + m_wsName.Mid(1); | 57 CFX_WideString tempName = EXCLAMATION_IN_IDENTIFIER + m_wsName.Mid(1); |
65 javascript << tempName; | 58 javascript << tempName; |
(...skipping 14 matching lines...) Expand all Loading... | |
80 } | 73 } |
81 if (i + 1 < m_pArguments->GetSize()) { | 74 if (i + 1 < m_pArguments->GetSize()) { |
82 javascript << FX_WSTRC(L", "); | 75 javascript << FX_WSTRC(L", "); |
83 } | 76 } |
84 } | 77 } |
85 } | 78 } |
86 javascript << FX_WSTRC(L")\n{\n"); | 79 javascript << FX_WSTRC(L")\n{\n"); |
87 javascript << FX_WSTRC(L"var "); | 80 javascript << FX_WSTRC(L"var "); |
88 javascript << RUNTIMEFUNCTIONRETURNVALUE; | 81 javascript << RUNTIMEFUNCTIONRETURNVALUE; |
89 javascript << FX_WSTRC(L" = null;\n"); | 82 javascript << FX_WSTRC(L" = null;\n"); |
90 if (m_pExpressions) { | 83 for (size_t i = 0; i < m_pExpressions.size(); ++i) { |
91 for (int i = 0; i < m_pExpressions->GetSize(); ++i) { | 84 CXFA_FMExpression* e = m_pExpressions.at(i).get(); |
Tom Sepez
2016/11/28 18:09:11
nit: or just const auto& e = m_pExpressions[i]; si
npm
2016/11/28 20:04:39
Done.
| |
92 CXFA_FMExpression* e = m_pExpressions->GetAt(i); | 85 if (i + 1 < m_pExpressions.size()) { |
93 if (i + 1 < m_pExpressions->GetSize()) { | 86 e->ToJavaScript(javascript); |
94 e->ToJavaScript(javascript); | 87 } else { |
95 } else { | 88 e->ToImpliedReturnJS(javascript); |
96 e->ToImpliedReturnJS(javascript); | |
97 } | |
98 } | 89 } |
99 } | 90 } |
100 javascript << FX_WSTRC(L"return "); | 91 javascript << FX_WSTRC(L"return "); |
101 if (m_isGlobal) { | 92 if (m_isGlobal) { |
102 javascript << XFA_FM_EXPTypeToString(GETFMVALUE); | 93 javascript << XFA_FM_EXPTypeToString(GETFMVALUE); |
103 javascript << FX_WSTRC(L"("); | 94 javascript << FX_WSTRC(L"("); |
104 javascript << RUNTIMEFUNCTIONRETURNVALUE; | 95 javascript << RUNTIMEFUNCTIONRETURNVALUE; |
105 javascript << FX_WSTRC(L")"); | 96 javascript << FX_WSTRC(L")"); |
106 } else { | 97 } else { |
107 javascript << RUNTIMEFUNCTIONRETURNVALUE; | 98 javascript << RUNTIMEFUNCTIONRETURNVALUE; |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
203 javascript << RUNTIMEFUNCTIONRETURNVALUE; | 194 javascript << RUNTIMEFUNCTIONRETURNVALUE; |
204 javascript << FX_WSTRC(L" = "); | 195 javascript << FX_WSTRC(L" = "); |
205 m_pExpression->ToJavaScript(javascript); | 196 m_pExpression->ToJavaScript(javascript); |
206 javascript << FX_WSTRC(L";\n"); | 197 javascript << FX_WSTRC(L";\n"); |
207 } | 198 } |
208 } | 199 } |
209 } | 200 } |
210 | 201 |
211 CXFA_FMBlockExpression::CXFA_FMBlockExpression( | 202 CXFA_FMBlockExpression::CXFA_FMBlockExpression( |
212 uint32_t line, | 203 uint32_t line, |
213 CFX_ArrayTemplate<CXFA_FMExpression*>* pExpressionList) | 204 std::vector<std::unique_ptr<CXFA_FMExpression>>&& pExpressionList) |
214 : CXFA_FMExpression(line, XFA_FM_EXPTYPE_BLOCK), | 205 : CXFA_FMExpression(line, XFA_FM_EXPTYPE_BLOCK), |
215 m_pExpressionList(pExpressionList) {} | 206 m_ExpressionList(std::move(pExpressionList)) {} |
216 | 207 |
217 CXFA_FMBlockExpression::~CXFA_FMBlockExpression() { | 208 CXFA_FMBlockExpression::~CXFA_FMBlockExpression() {} |
218 if (m_pExpressionList) { | |
219 for (int i = 0; i < m_pExpressionList->GetSize(); ++i) | |
220 delete m_pExpressionList->GetAt(i); | |
221 | |
222 delete m_pExpressionList; | |
223 } | |
224 } | |
225 | 209 |
226 void CXFA_FMBlockExpression::ToJavaScript(CFX_WideTextBuf& javascript) { | 210 void CXFA_FMBlockExpression::ToJavaScript(CFX_WideTextBuf& javascript) { |
227 javascript << FX_WSTRC(L"{\n"); | 211 javascript << FX_WSTRC(L"{\n"); |
228 if (m_pExpressionList) { | 212 for (size_t i = 0; i < m_ExpressionList.size(); ++i) |
Tom Sepez
2016/11/28 18:09:11
nit: or just
for (const auto& expr : m_Express
npm
2016/11/28 20:04:39
Done.
| |
229 for (int i = 0; i < m_pExpressionList->GetSize(); ++i) | 213 m_ExpressionList.at(i)->ToJavaScript(javascript); |
230 m_pExpressionList->GetAt(i)->ToJavaScript(javascript); | |
231 } | |
232 javascript << FX_WSTRC(L"}\n"); | 214 javascript << FX_WSTRC(L"}\n"); |
233 } | 215 } |
234 | 216 |
235 void CXFA_FMBlockExpression::ToImpliedReturnJS(CFX_WideTextBuf& javascript) { | 217 void CXFA_FMBlockExpression::ToImpliedReturnJS(CFX_WideTextBuf& javascript) { |
236 javascript << FX_WSTRC(L"{\n"); | 218 javascript << FX_WSTRC(L"{\n"); |
237 if (m_pExpressionList) { | 219 for (size_t i = 0; i < m_ExpressionList.size(); ++i) { |
238 for (int i = 0; i < m_pExpressionList->GetSize(); ++i) { | 220 CXFA_FMExpression* e = m_ExpressionList.at(i).get(); |
239 CXFA_FMExpression* e = m_pExpressionList->GetAt(i); | 221 if (i + 1 == m_ExpressionList.size()) { |
240 if (i + 1 == m_pExpressionList->GetSize()) { | 222 e->ToImpliedReturnJS(javascript); |
241 e->ToImpliedReturnJS(javascript); | 223 } else { |
242 } else { | 224 e->ToJavaScript(javascript); |
243 e->ToJavaScript(javascript); | |
244 } | |
245 } | 225 } |
246 } | 226 } |
247 javascript << FX_WSTRC(L"}\n"); | 227 javascript << FX_WSTRC(L"}\n"); |
248 } | 228 } |
249 | 229 |
250 CXFA_FMDoExpression::CXFA_FMDoExpression(uint32_t line, | 230 CXFA_FMDoExpression::CXFA_FMDoExpression(uint32_t line, |
251 CXFA_FMExpression* pList) | 231 CXFA_FMExpression* pList) |
252 : CXFA_FMExpression(line), m_pList(pList) {} | 232 : CXFA_FMExpression(line), m_pList(pList) {} |
253 | 233 |
254 CXFA_FMDoExpression::~CXFA_FMDoExpression() {} | 234 CXFA_FMDoExpression::~CXFA_FMDoExpression() {} |
(...skipping 357 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
612 } | 592 } |
613 javascript << FX_WSTRC(L" = "); | 593 javascript << FX_WSTRC(L" = "); |
614 javascript << RUNTIMEBLOCKTEMPARRAY; | 594 javascript << RUNTIMEBLOCKTEMPARRAY; |
615 javascript << FX_WSTRC(L"["); | 595 javascript << FX_WSTRC(L"["); |
616 javascript << RUNTIMEBLOCKTEMPARRAYINDEX; | 596 javascript << RUNTIMEBLOCKTEMPARRAYINDEX; |
617 javascript << FX_WSTRC(L"++];\n"); | 597 javascript << FX_WSTRC(L"++];\n"); |
618 m_pList->ToImpliedReturnJS(javascript); | 598 m_pList->ToImpliedReturnJS(javascript); |
619 javascript << FX_WSTRC(L"}\n"); | 599 javascript << FX_WSTRC(L"}\n"); |
620 javascript << FX_WSTRC(L"}\n"); | 600 javascript << FX_WSTRC(L"}\n"); |
621 } | 601 } |
OLD | NEW |