Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(8)

Side by Side Diff: xfa/fxfa/fm2js/xfa_expression.cpp

Issue 2530933002: Use unique pointers in CXFA_FMParse (Closed)
Patch Set: Address comments Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « xfa/fxfa/fm2js/xfa_expression.h ('k') | xfa/fxfa/fm2js/xfa_fmparse.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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
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 (const auto& expr : m_pExpressions) {
91 for (int i = 0; i < m_pExpressions->GetSize(); ++i) { 84 if (expr == m_pExpressions.back())
92 CXFA_FMExpression* e = m_pExpressions->GetAt(i); 85 expr->ToImpliedReturnJS(javascript);
93 if (i + 1 < m_pExpressions->GetSize()) { 86 else
94 e->ToJavaScript(javascript); 87 expr->ToJavaScript(javascript);
95 } else {
96 e->ToImpliedReturnJS(javascript);
97 }
98 }
99 } 88 }
100 javascript << FX_WSTRC(L"return "); 89 javascript << FX_WSTRC(L"return ");
101 if (m_isGlobal) { 90 if (m_isGlobal) {
102 javascript << XFA_FM_EXPTypeToString(GETFMVALUE); 91 javascript << XFA_FM_EXPTypeToString(GETFMVALUE);
103 javascript << FX_WSTRC(L"("); 92 javascript << FX_WSTRC(L"(");
104 javascript << RUNTIMEFUNCTIONRETURNVALUE; 93 javascript << RUNTIMEFUNCTIONRETURNVALUE;
105 javascript << FX_WSTRC(L")"); 94 javascript << FX_WSTRC(L")");
106 } else { 95 } else {
107 javascript << RUNTIMEFUNCTIONRETURNVALUE; 96 javascript << RUNTIMEFUNCTIONRETURNVALUE;
108 } 97 }
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
203 javascript << RUNTIMEFUNCTIONRETURNVALUE; 192 javascript << RUNTIMEFUNCTIONRETURNVALUE;
204 javascript << FX_WSTRC(L" = "); 193 javascript << FX_WSTRC(L" = ");
205 m_pExpression->ToJavaScript(javascript); 194 m_pExpression->ToJavaScript(javascript);
206 javascript << FX_WSTRC(L";\n"); 195 javascript << FX_WSTRC(L";\n");
207 } 196 }
208 } 197 }
209 } 198 }
210 199
211 CXFA_FMBlockExpression::CXFA_FMBlockExpression( 200 CXFA_FMBlockExpression::CXFA_FMBlockExpression(
212 uint32_t line, 201 uint32_t line,
213 CFX_ArrayTemplate<CXFA_FMExpression*>* pExpressionList) 202 std::vector<std::unique_ptr<CXFA_FMExpression>>&& pExpressionList)
214 : CXFA_FMExpression(line, XFA_FM_EXPTYPE_BLOCK), 203 : CXFA_FMExpression(line, XFA_FM_EXPTYPE_BLOCK),
215 m_pExpressionList(pExpressionList) {} 204 m_ExpressionList(std::move(pExpressionList)) {}
216 205
217 CXFA_FMBlockExpression::~CXFA_FMBlockExpression() { 206 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 207
226 void CXFA_FMBlockExpression::ToJavaScript(CFX_WideTextBuf& javascript) { 208 void CXFA_FMBlockExpression::ToJavaScript(CFX_WideTextBuf& javascript) {
227 javascript << FX_WSTRC(L"{\n"); 209 javascript << FX_WSTRC(L"{\n");
228 if (m_pExpressionList) { 210 for (const auto& expr : m_ExpressionList)
229 for (int i = 0; i < m_pExpressionList->GetSize(); ++i) 211 expr->ToJavaScript(javascript);
230 m_pExpressionList->GetAt(i)->ToJavaScript(javascript);
231 }
232 javascript << FX_WSTRC(L"}\n"); 212 javascript << FX_WSTRC(L"}\n");
233 } 213 }
234 214
235 void CXFA_FMBlockExpression::ToImpliedReturnJS(CFX_WideTextBuf& javascript) { 215 void CXFA_FMBlockExpression::ToImpliedReturnJS(CFX_WideTextBuf& javascript) {
236 javascript << FX_WSTRC(L"{\n"); 216 javascript << FX_WSTRC(L"{\n");
237 if (m_pExpressionList) { 217 for (const auto& expr : m_ExpressionList) {
238 for (int i = 0; i < m_pExpressionList->GetSize(); ++i) { 218 if (expr == m_ExpressionList.back())
239 CXFA_FMExpression* e = m_pExpressionList->GetAt(i); 219 expr->ToImpliedReturnJS(javascript);
240 if (i + 1 == m_pExpressionList->GetSize()) { 220 else
241 e->ToImpliedReturnJS(javascript); 221 expr->ToJavaScript(javascript);
242 } else {
243 e->ToJavaScript(javascript);
244 }
245 }
246 } 222 }
247 javascript << FX_WSTRC(L"}\n"); 223 javascript << FX_WSTRC(L"}\n");
248 } 224 }
249 225
250 CXFA_FMDoExpression::CXFA_FMDoExpression(uint32_t line, 226 CXFA_FMDoExpression::CXFA_FMDoExpression(uint32_t line,
251 CXFA_FMExpression* pList) 227 CXFA_FMExpression* pList)
252 : CXFA_FMExpression(line), m_pList(pList) {} 228 : CXFA_FMExpression(line), m_pList(pList) {}
253 229
254 CXFA_FMDoExpression::~CXFA_FMDoExpression() {} 230 CXFA_FMDoExpression::~CXFA_FMDoExpression() {}
255 231
(...skipping 273 matching lines...) Expand 10 before | Expand all | Expand 10 after
529 } else { 505 } else {
530 javascript << m_wsIdentifier; 506 javascript << m_wsIdentifier;
531 } 507 }
532 javascript << FX_WSTRC(L" = null;\n"); 508 javascript << FX_WSTRC(L" = null;\n");
533 javascript << FX_WSTRC(L"var "); 509 javascript << FX_WSTRC(L"var ");
534 javascript << RUNTIMEBLOCKTEMPARRAY; 510 javascript << RUNTIMEBLOCKTEMPARRAY;
535 javascript << FX_WSTRC(L" = "); 511 javascript << FX_WSTRC(L" = ");
536 javascript << XFA_FM_EXPTypeToString(CONCATFMOBJECT); 512 javascript << XFA_FM_EXPTypeToString(CONCATFMOBJECT);
537 javascript << FX_WSTRC(L"("); 513 javascript << FX_WSTRC(L"(");
538 514
539 for (size_t i = 0; i < m_pAccessors.size(); ++i) { 515 for (const auto& expr : m_pAccessors) {
540 CXFA_FMSimpleExpression* s = m_pAccessors.at(i).get(); 516 expr->ToJavaScript(javascript);
541 s->ToJavaScript(javascript); 517 if (expr != m_pAccessors.back())
542 if (i + 1 < m_pAccessors.size()) { 518 javascript << L", ";
543 javascript << FX_WSTRC(L", ");
544 }
545 } 519 }
546 javascript << FX_WSTRC(L");\n"); 520 javascript << FX_WSTRC(L");\n");
547 javascript << FX_WSTRC(L"var "); 521 javascript << FX_WSTRC(L"var ");
548 javascript << RUNTIMEBLOCKTEMPARRAYINDEX; 522 javascript << RUNTIMEBLOCKTEMPARRAYINDEX;
549 javascript << FX_WSTRC(L" = 0;\n"); 523 javascript << FX_WSTRC(L" = 0;\n");
550 javascript << FX_WSTRC(L"while("); 524 javascript << FX_WSTRC(L"while(");
551 javascript << RUNTIMEBLOCKTEMPARRAYINDEX; 525 javascript << RUNTIMEBLOCKTEMPARRAYINDEX;
552 javascript << FX_WSTRC(L" < "); 526 javascript << FX_WSTRC(L" < ");
553 javascript << RUNTIMEBLOCKTEMPARRAY; 527 javascript << RUNTIMEBLOCKTEMPARRAY;
554 javascript << FX_WSTRC(L".length)\n{\n"); 528 javascript << FX_WSTRC(L".length)\n{\n");
(...skipping 25 matching lines...) Expand all
580 javascript << tempIdentifier; 554 javascript << tempIdentifier;
581 } else { 555 } else {
582 javascript << m_wsIdentifier; 556 javascript << m_wsIdentifier;
583 } 557 }
584 javascript << FX_WSTRC(L" = null;\n"); 558 javascript << FX_WSTRC(L" = null;\n");
585 javascript << FX_WSTRC(L"var "); 559 javascript << FX_WSTRC(L"var ");
586 javascript << RUNTIMEBLOCKTEMPARRAY; 560 javascript << RUNTIMEBLOCKTEMPARRAY;
587 javascript << FX_WSTRC(L" = "); 561 javascript << FX_WSTRC(L" = ");
588 javascript << XFA_FM_EXPTypeToString(CONCATFMOBJECT); 562 javascript << XFA_FM_EXPTypeToString(CONCATFMOBJECT);
589 javascript << FX_WSTRC(L"("); 563 javascript << FX_WSTRC(L"(");
590 for (size_t i = 0; i < m_pAccessors.size(); ++i) { 564 for (const auto& expr : m_pAccessors) {
591 CXFA_FMSimpleExpression* s = m_pAccessors.at(i).get(); 565 expr->ToJavaScript(javascript);
592 s->ToJavaScript(javascript); 566 if (expr != m_pAccessors.back())
593 if (i + 1 < m_pAccessors.size()) { 567 javascript << L", ";
594 javascript << FX_WSTRC(L", ");
595 }
596 } 568 }
597 javascript << FX_WSTRC(L");\n"); 569 javascript << FX_WSTRC(L");\n");
598 javascript << FX_WSTRC(L"var "); 570 javascript << FX_WSTRC(L"var ");
599 javascript << RUNTIMEBLOCKTEMPARRAYINDEX; 571 javascript << RUNTIMEBLOCKTEMPARRAYINDEX;
600 javascript << FX_WSTRC(L" = 0;\n"); 572 javascript << FX_WSTRC(L" = 0;\n");
601 javascript << FX_WSTRC(L"while("); 573 javascript << FX_WSTRC(L"while(");
602 javascript << RUNTIMEBLOCKTEMPARRAYINDEX; 574 javascript << RUNTIMEBLOCKTEMPARRAYINDEX;
603 javascript << FX_WSTRC(L" < "); 575 javascript << FX_WSTRC(L" < ");
604 javascript << RUNTIMEBLOCKTEMPARRAY; 576 javascript << RUNTIMEBLOCKTEMPARRAY;
605 javascript << FX_WSTRC(L".length)\n{\n"); 577 javascript << FX_WSTRC(L".length)\n{\n");
606 if (m_wsIdentifier.GetAt(0) == L'!') { 578 if (m_wsIdentifier.GetAt(0) == L'!') {
607 CFX_WideString tempIdentifier = 579 CFX_WideString tempIdentifier =
608 EXCLAMATION_IN_IDENTIFIER + m_wsIdentifier.Mid(1); 580 EXCLAMATION_IN_IDENTIFIER + m_wsIdentifier.Mid(1);
609 javascript << tempIdentifier; 581 javascript << tempIdentifier;
610 } else { 582 } else {
611 javascript << m_wsIdentifier; 583 javascript << m_wsIdentifier;
612 } 584 }
613 javascript << FX_WSTRC(L" = "); 585 javascript << FX_WSTRC(L" = ");
614 javascript << RUNTIMEBLOCKTEMPARRAY; 586 javascript << RUNTIMEBLOCKTEMPARRAY;
615 javascript << FX_WSTRC(L"["); 587 javascript << FX_WSTRC(L"[");
616 javascript << RUNTIMEBLOCKTEMPARRAYINDEX; 588 javascript << RUNTIMEBLOCKTEMPARRAYINDEX;
617 javascript << FX_WSTRC(L"++];\n"); 589 javascript << FX_WSTRC(L"++];\n");
618 m_pList->ToImpliedReturnJS(javascript); 590 m_pList->ToImpliedReturnJS(javascript);
619 javascript << FX_WSTRC(L"}\n"); 591 javascript << FX_WSTRC(L"}\n");
620 javascript << FX_WSTRC(L"}\n"); 592 javascript << FX_WSTRC(L"}\n");
621 } 593 }
OLDNEW
« no previous file with comments | « xfa/fxfa/fm2js/xfa_expression.h ('k') | xfa/fxfa/fm2js/xfa_fmparse.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698