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

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

Issue 1803723002: Move xfa/src up to xfa/. (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@master
Patch Set: Rebase to master Created 4 years, 9 months 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/src/fxfa/fm2js/xfa_expression.h ('k') | xfa/src/fxfa/fm2js/xfa_fm2jsapi.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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 #include "xfa/src/fxfa/fm2js/xfa_expression.h"
8
9 #include "core/include/fxcrt/fx_basic.h"
10
11 namespace {
12
13 const CFX_WideStringC RUNTIMEBLOCKTEMPARRAY =
14 FX_WSTRC(L"foxit_xfa_formcalc_runtime_block_temp_array");
15
16 const CFX_WideStringC RUNTIMEBLOCKTEMPARRAYINDEX =
17 FX_WSTRC(L"foxit_xfa_formcalc_runtime_block_temp_array_index");
18
19 } // namespace
20
21 CXFA_FMExpression::CXFA_FMExpression(FX_DWORD line)
22 : m_type(XFA_FM_EXPTYPE_UNKNOWN), m_line(line) {}
23
24 CXFA_FMExpression::CXFA_FMExpression(FX_DWORD line, XFA_FM_EXPTYPE type)
25 : m_type(type), m_line(line) {}
26
27 void CXFA_FMExpression::ToJavaScript(CFX_WideTextBuf& javascript) {}
28
29 void CXFA_FMExpression::ToImpliedReturnJS(CFX_WideTextBuf& javascript) {}
30
31 CXFA_FMFunctionDefinition::CXFA_FMFunctionDefinition(
32 FX_DWORD line,
33 FX_BOOL isGlobal,
34 const CFX_WideStringC& wsName,
35 CFX_WideStringCArray* pArguments,
36 CFX_PtrArray* pExpressions)
37 : CXFA_FMExpression(line, XFA_FM_EXPTYPE_FUNC),
38 m_wsName(wsName),
39 m_pArguments(pArguments),
40 m_pExpressions(pExpressions),
41 m_isGlobal(isGlobal) {}
42
43 CXFA_FMFunctionDefinition::~CXFA_FMFunctionDefinition() {
44 if (m_pArguments) {
45 m_pArguments->RemoveAll();
46 delete m_pArguments;
47 }
48 if (m_pExpressions) {
49 for (int i = 0; i < m_pExpressions->GetSize(); ++i) {
50 delete reinterpret_cast<CXFA_FMExpression*>(m_pExpressions->GetAt(i));
51 }
52 m_pExpressions->RemoveAll();
53 delete m_pExpressions;
54 }
55 }
56
57 void CXFA_FMFunctionDefinition::ToJavaScript(CFX_WideTextBuf& javascript) {
58 if (m_isGlobal && (!m_pExpressions || m_pExpressions->GetSize() == 0)) {
59 javascript << FX_WSTRC(L"// comments only");
60 return;
61 }
62 if (m_isGlobal) {
63 javascript << FX_WSTRC(L"(\n");
64 }
65 javascript << FX_WSTRC(L"function ");
66 if (m_wsName.GetAt(0) == L'!') {
67 CFX_WideString tempName = EXCLAMATION_IN_IDENTIFIER + m_wsName.Mid(1);
68 javascript << tempName;
69 } else {
70 javascript << m_wsName;
71 }
72 javascript << FX_WSTRC(L"(");
73 if (m_pArguments != 0) {
74 CFX_WideStringC identifier = 0;
75 for (int i = 0; i < m_pArguments->GetSize(); ++i) {
76 identifier = m_pArguments->GetAt(i);
77 if (identifier.GetAt(0) == L'!') {
78 CFX_WideString tempIdentifier =
79 EXCLAMATION_IN_IDENTIFIER + identifier.Mid(1);
80 javascript << tempIdentifier;
81 } else {
82 javascript << identifier;
83 }
84 if (i + 1 < m_pArguments->GetSize()) {
85 javascript << FX_WSTRC(L", ");
86 }
87 }
88 }
89 javascript << FX_WSTRC(L")\n{\n");
90 javascript << FX_WSTRC(L"var ");
91 javascript << RUNTIMEFUNCTIONRETURNVALUE;
92 javascript << FX_WSTRC(L" = null;\n");
93 if (m_pExpressions) {
94 for (int i = 0; i < m_pExpressions->GetSize(); ++i) {
95 CXFA_FMExpression* e =
96 reinterpret_cast<CXFA_FMExpression*>(m_pExpressions->GetAt(i));
97 if (i + 1 < m_pExpressions->GetSize()) {
98 e->ToJavaScript(javascript);
99 } else {
100 e->ToImpliedReturnJS(javascript);
101 }
102 }
103 }
104 javascript << FX_WSTRC(L"return ");
105 if (m_isGlobal) {
106 javascript << XFA_FM_EXPTypeToString(GETFMVALUE);
107 javascript << FX_WSTRC(L"(");
108 javascript << RUNTIMEFUNCTIONRETURNVALUE;
109 javascript << FX_WSTRC(L")");
110 } else {
111 javascript << RUNTIMEFUNCTIONRETURNVALUE;
112 }
113 javascript << FX_WSTRC(L";\n}\n");
114 if (m_isGlobal) {
115 javascript << FX_WSTRC(L").call(this);\n");
116 }
117 }
118
119 void CXFA_FMFunctionDefinition::ToImpliedReturnJS(CFX_WideTextBuf&) {}
120
121 CXFA_FMVarExpression::CXFA_FMVarExpression(FX_DWORD line,
122 const CFX_WideStringC& wsName,
123 CXFA_FMExpression* pInit)
124 : CXFA_FMExpression(line, XFA_FM_EXPTYPE_VAR),
125 m_wsName(wsName),
126 m_pInit(pInit) {}
127
128 void CXFA_FMVarExpression::ToJavaScript(CFX_WideTextBuf& javascript) {
129 javascript << FX_WSTRC(L"var ");
130 CFX_WideString tempName = m_wsName;
131 if (m_wsName.GetAt(0) == L'!') {
132 tempName = EXCLAMATION_IN_IDENTIFIER + m_wsName.Mid(1);
133 }
134 javascript << tempName;
135 javascript << FX_WSTRC(L" = ");
136 if (m_pInit) {
137 m_pInit->ToJavaScript(javascript);
138 javascript << tempName;
139 javascript << FX_WSTRC(L" = ");
140 javascript << XFA_FM_EXPTypeToString(VARFILTER);
141 javascript << FX_WSTRC(L"(");
142 javascript << tempName;
143 javascript << FX_WSTRC(L");\n");
144 } else {
145 javascript << FX_WSTRC(L"\"\";\n");
146 }
147 }
148
149 void CXFA_FMVarExpression::ToImpliedReturnJS(CFX_WideTextBuf& javascript) {
150 javascript << FX_WSTRC(L"var ");
151 CFX_WideString tempName = m_wsName;
152 if (m_wsName.GetAt(0) == L'!') {
153 tempName = EXCLAMATION_IN_IDENTIFIER + m_wsName.Mid(1);
154 }
155 javascript << tempName;
156 javascript << FX_WSTRC(L" = ");
157 if (m_pInit) {
158 m_pInit->ToJavaScript(javascript);
159 javascript << tempName;
160 javascript << FX_WSTRC(L" = ");
161 javascript << XFA_FM_EXPTypeToString(VARFILTER);
162 javascript << FX_WSTRC(L"(");
163 javascript << tempName;
164 javascript << FX_WSTRC(L");\n");
165 } else {
166 javascript << FX_WSTRC(L"\"\";\n");
167 }
168 javascript << RUNTIMEFUNCTIONRETURNVALUE;
169 javascript << FX_WSTRC(L" = ");
170 javascript << tempName;
171 javascript << FX_WSTRC(L";\n");
172 }
173
174 CXFA_FMExpExpression::CXFA_FMExpExpression(FX_DWORD line,
175 CXFA_FMSimpleExpression* pExpression)
176 : CXFA_FMExpression(line, XFA_FM_EXPTYPE_EXP), m_pExpression(pExpression) {}
177
178 void CXFA_FMExpExpression::ToJavaScript(CFX_WideTextBuf& javascript) {
179 if (m_pExpression->GetOperatorToken() == TOKassign) {
180 m_pExpression->ToJavaScript(javascript);
181 } else {
182 m_pExpression->ToJavaScript(javascript);
183 javascript << FX_WSTRC(L";\n");
184 }
185 }
186
187 void CXFA_FMExpExpression::ToImpliedReturnJS(CFX_WideTextBuf& javascript) {
188 if (m_pExpression->GetOperatorToken() == TOKassign) {
189 m_pExpression->ToImpliedReturnJS(javascript);
190 } else {
191 if (m_pExpression->GetOperatorToken() == TOKstar ||
192 m_pExpression->GetOperatorToken() == TOKdotstar ||
193 m_pExpression->GetOperatorToken() == TOKdotscream ||
194 m_pExpression->GetOperatorToken() == TOKdotdot ||
195 m_pExpression->GetOperatorToken() == TOKdot) {
196 javascript << RUNTIMEFUNCTIONRETURNVALUE;
197 javascript << FX_WSTRC(L" = ");
198 javascript << XFA_FM_EXPTypeToString(GETFMVALUE);
199 javascript << FX_WSTRC(L"(");
200 m_pExpression->ToJavaScript(javascript);
201 javascript << FX_WSTRC(L");\n");
202 } else {
203 javascript << RUNTIMEFUNCTIONRETURNVALUE;
204 javascript << FX_WSTRC(L" = ");
205 m_pExpression->ToJavaScript(javascript);
206 javascript << FX_WSTRC(L";\n");
207 }
208 }
209 }
210
211 CXFA_FMBlockExpression::CXFA_FMBlockExpression(FX_DWORD line,
212 CFX_PtrArray* pExpressionList)
213 : CXFA_FMExpression(line, XFA_FM_EXPTYPE_BLOCK),
214 m_pExpressionList(pExpressionList) {}
215
216 CXFA_FMBlockExpression::~CXFA_FMBlockExpression() {
217 if (m_pExpressionList) {
218 for (int i = 0; i < m_pExpressionList->GetSize(); ++i) {
219 delete reinterpret_cast<CXFA_FMExpression*>(m_pExpressionList->GetAt(i));
220 }
221 m_pExpressionList->RemoveAll();
222 delete m_pExpressionList;
223 }
224 }
225
226 void CXFA_FMBlockExpression::ToJavaScript(CFX_WideTextBuf& javascript) {
227 javascript << FX_WSTRC(L"{\n");
228 if (m_pExpressionList) {
229 for (int i = 0; i < m_pExpressionList->GetSize(); ++i) {
230 CXFA_FMExpression* e =
231 reinterpret_cast<CXFA_FMExpression*>(m_pExpressionList->GetAt(i));
232 e->ToJavaScript(javascript);
233 }
234 }
235 javascript << FX_WSTRC(L"}\n");
236 }
237
238 void CXFA_FMBlockExpression::ToImpliedReturnJS(CFX_WideTextBuf& javascript) {
239 javascript << FX_WSTRC(L"{\n");
240 if (m_pExpressionList) {
241 for (int i = 0; i < m_pExpressionList->GetSize(); ++i) {
242 CXFA_FMExpression* e =
243 reinterpret_cast<CXFA_FMExpression*>(m_pExpressionList->GetAt(i));
244 if (i + 1 == m_pExpressionList->GetSize()) {
245 e->ToImpliedReturnJS(javascript);
246 } else {
247 e->ToJavaScript(javascript);
248 }
249 }
250 }
251 javascript << FX_WSTRC(L"}\n");
252 }
253
254 CXFA_FMDoExpression::CXFA_FMDoExpression(FX_DWORD line,
255 CXFA_FMExpression* pList)
256 : CXFA_FMExpression(line), m_pList(pList) {}
257
258 void CXFA_FMDoExpression::ToJavaScript(CFX_WideTextBuf& javascript) {
259 m_pList->ToJavaScript(javascript);
260 }
261
262 void CXFA_FMDoExpression::ToImpliedReturnJS(CFX_WideTextBuf& javascript) {
263 m_pList->ToImpliedReturnJS(javascript);
264 }
265
266 CXFA_FMIfExpression::CXFA_FMIfExpression(FX_DWORD line,
267 CXFA_FMSimpleExpression* pExpression,
268 CXFA_FMExpression* pIfExpression,
269 CXFA_FMExpression* pElseExpression)
270 : CXFA_FMExpression(line, XFA_FM_EXPTYPE_IF),
271 m_pExpression(pExpression),
272 m_pIfExpression(pIfExpression),
273 m_pElseExpression(pElseExpression) {}
274
275 void CXFA_FMIfExpression::ToJavaScript(CFX_WideTextBuf& javascript) {
276 javascript << FX_WSTRC(L"if (");
277 if (m_pExpression) {
278 javascript << XFA_FM_EXPTypeToString(GETFMVALUE);
279 javascript << FX_WSTRC(L"(");
280 m_pExpression->ToJavaScript(javascript);
281 javascript << FX_WSTRC(L")");
282 }
283 javascript << FX_WSTRC(L")\n");
284 if (m_pIfExpression) {
285 m_pIfExpression->ToJavaScript(javascript);
286 }
287 if (m_pElseExpression) {
288 if (m_pElseExpression->GetExpType() == XFA_FM_EXPTYPE_IF) {
289 javascript << FX_WSTRC(L"else\n");
290 javascript << FX_WSTRC(L"{\n");
291 m_pElseExpression->ToJavaScript(javascript);
292 javascript << FX_WSTRC(L"}\n");
293 } else {
294 javascript << FX_WSTRC(L"else\n");
295 m_pElseExpression->ToJavaScript(javascript);
296 }
297 }
298 }
299
300 void CXFA_FMIfExpression::ToImpliedReturnJS(CFX_WideTextBuf& javascript) {
301 javascript << RUNTIMEFUNCTIONRETURNVALUE;
302 javascript << FX_WSTRC(L" = 0;\n");
303 javascript << FX_WSTRC(L"if (");
304 if (m_pExpression) {
305 javascript << XFA_FM_EXPTypeToString(GETFMVALUE);
306 javascript << FX_WSTRC(L"(");
307 m_pExpression->ToJavaScript(javascript);
308 javascript << FX_WSTRC(L")");
309 }
310 javascript << FX_WSTRC(L")\n");
311 if (m_pIfExpression) {
312 m_pIfExpression->ToImpliedReturnJS(javascript);
313 }
314 if (m_pElseExpression) {
315 if (m_pElseExpression->GetExpType() == XFA_FM_EXPTYPE_IF) {
316 javascript << FX_WSTRC(L"else\n");
317 javascript << FX_WSTRC(L"{\n");
318 m_pElseExpression->ToImpliedReturnJS(javascript);
319 javascript << FX_WSTRC(L"}\n");
320 } else {
321 javascript << FX_WSTRC(L"else\n");
322 m_pElseExpression->ToImpliedReturnJS(javascript);
323 }
324 }
325 }
326
327 CXFA_FMLoopExpression::~CXFA_FMLoopExpression() {}
328
329 void CXFA_FMLoopExpression::ToJavaScript(CFX_WideTextBuf& javascript) {}
330
331 void CXFA_FMLoopExpression::ToImpliedReturnJS(CFX_WideTextBuf&) {}
332
333 CXFA_FMWhileExpression::CXFA_FMWhileExpression(
334 FX_DWORD line,
335 CXFA_FMSimpleExpression* pCondition,
336 CXFA_FMExpression* pExpression)
337 : CXFA_FMLoopExpression(line),
338 m_pCondition(pCondition),
339 m_pExpression(pExpression) {}
340
341 void CXFA_FMWhileExpression::ToJavaScript(CFX_WideTextBuf& javascript) {
342 javascript << FX_WSTRC(L"while (");
343 m_pCondition->ToJavaScript(javascript);
344 javascript << FX_WSTRC(L")\n");
345 m_pExpression->ToJavaScript(javascript);
346 }
347
348 void CXFA_FMWhileExpression::ToImpliedReturnJS(CFX_WideTextBuf& javascript) {
349 javascript << RUNTIMEFUNCTIONRETURNVALUE;
350 javascript << FX_WSTRC(L" = 0;\n");
351 javascript << FX_WSTRC(L"while (");
352 m_pCondition->ToJavaScript(javascript);
353 javascript << FX_WSTRC(L")\n");
354 m_pExpression->ToImpliedReturnJS(javascript);
355 }
356
357 CXFA_FMBreakExpression::CXFA_FMBreakExpression(FX_DWORD line)
358 : CXFA_FMExpression(line, XFA_FM_EXPTYPE_BREAK) {}
359
360 CXFA_FMBreakExpression::~CXFA_FMBreakExpression() {}
361
362 void CXFA_FMBreakExpression::ToJavaScript(CFX_WideTextBuf& javascript) {
363 javascript << RUNTIMEFUNCTIONRETURNVALUE;
364 javascript << FX_WSTRC(L" = 0;\n");
365 javascript << FX_WSTRC(L"break;\n");
366 }
367
368 void CXFA_FMBreakExpression::ToImpliedReturnJS(CFX_WideTextBuf& javascript) {
369 javascript << RUNTIMEFUNCTIONRETURNVALUE;
370 javascript << FX_WSTRC(L" = 0;\n");
371 javascript << FX_WSTRC(L"break;\n");
372 }
373
374 CXFA_FMContinueExpression::CXFA_FMContinueExpression(FX_DWORD line)
375 : CXFA_FMExpression(line, XFA_FM_EXPTYPE_CONTINUE) {}
376
377 CXFA_FMContinueExpression::~CXFA_FMContinueExpression() {}
378
379 void CXFA_FMContinueExpression::ToJavaScript(CFX_WideTextBuf& javascript) {
380 javascript << RUNTIMEFUNCTIONRETURNVALUE;
381 javascript << FX_WSTRC(L" = 0;\n");
382 javascript << FX_WSTRC(L"continue;\n");
383 }
384
385 void CXFA_FMContinueExpression::ToImpliedReturnJS(CFX_WideTextBuf& javascript) {
386 javascript << RUNTIMEFUNCTIONRETURNVALUE;
387 javascript << FX_WSTRC(L" = 0;\n");
388 javascript << FX_WSTRC(L"continue;\n");
389 }
390
391 CXFA_FMForExpression::CXFA_FMForExpression(FX_DWORD line,
392 const CFX_WideStringC& wsVariant,
393 CXFA_FMSimpleExpression* pAssignment,
394 CXFA_FMSimpleExpression* pAccessor,
395 int32_t iDirection,
396 CXFA_FMSimpleExpression* pStep,
397 CXFA_FMExpression* pList)
398 : CXFA_FMLoopExpression(line),
399 m_wsVariant(wsVariant),
400 m_pAssignment(pAssignment),
401 m_pAccessor(pAccessor),
402 m_iDirection(iDirection),
403 m_pStep(pStep),
404 m_pList(pList) {}
405
406 void CXFA_FMForExpression::ToJavaScript(CFX_WideTextBuf& javascript) {
407 javascript << FX_WSTRC(L"{\nvar ");
408 CFX_WideString tempVariant;
409 if (m_wsVariant.GetAt(0) == L'!') {
410 tempVariant = EXCLAMATION_IN_IDENTIFIER + m_wsVariant.Mid(1);
411 javascript << tempVariant;
412 } else {
413 tempVariant = m_wsVariant;
414 javascript << m_wsVariant;
415 }
416 javascript << FX_WSTRC(L" = null;\n");
417 javascript << FX_WSTRC(L"for (");
418 javascript << tempVariant;
419 javascript << FX_WSTRC(L" = ");
420 javascript << XFA_FM_EXPTypeToString(GETFMVALUE);
421 javascript << FX_WSTRC(L"(");
422 m_pAssignment->ToJavaScript(javascript);
423 javascript << FX_WSTRC(L"); ");
424 javascript << tempVariant;
425 if (m_iDirection == 1) {
426 javascript << FX_WSTRC(L" <= ");
427 javascript << XFA_FM_EXPTypeToString(GETFMVALUE);
428 javascript << FX_WSTRC(L"(");
429 m_pAccessor->ToJavaScript(javascript);
430 javascript << FX_WSTRC(L"); ");
431 javascript << tempVariant;
432 javascript << FX_WSTRC(L" += ");
433 } else {
434 javascript << FX_WSTRC(L" >= ");
435 javascript << XFA_FM_EXPTypeToString(GETFMVALUE);
436 javascript << FX_WSTRC(L"(");
437 m_pAccessor->ToJavaScript(javascript);
438 javascript << FX_WSTRC(L"); ");
439 javascript << tempVariant;
440 javascript << FX_WSTRC(L" -= ");
441 }
442 if (m_pStep) {
443 javascript << XFA_FM_EXPTypeToString(GETFMVALUE);
444 javascript << FX_WSTRC(L"(");
445 m_pStep->ToJavaScript(javascript);
446 javascript << FX_WSTRC(L")");
447 } else {
448 javascript << FX_WSTRC(L"1");
449 }
450 javascript << FX_WSTRC(L")\n");
451 m_pList->ToJavaScript(javascript);
452 javascript << FX_WSTRC(L"}\n");
453 }
454
455 void CXFA_FMForExpression::ToImpliedReturnJS(CFX_WideTextBuf& javascript) {
456 javascript << RUNTIMEFUNCTIONRETURNVALUE;
457 javascript << FX_WSTRC(L" = 0;\n");
458 javascript << FX_WSTRC(L"{\nvar ");
459 CFX_WideString tempVariant;
460 if (m_wsVariant.GetAt(0) == L'!') {
461 tempVariant = EXCLAMATION_IN_IDENTIFIER + m_wsVariant.Mid(1);
462 javascript << tempVariant;
463 } else {
464 tempVariant = m_wsVariant;
465 javascript << m_wsVariant;
466 }
467 javascript << FX_WSTRC(L" = null;\n");
468 javascript << FX_WSTRC(L"for (");
469 javascript << tempVariant;
470 javascript << FX_WSTRC(L" = ");
471 javascript << XFA_FM_EXPTypeToString(GETFMVALUE);
472 javascript << FX_WSTRC(L"(");
473 m_pAssignment->ToJavaScript(javascript);
474 javascript << FX_WSTRC(L"); ");
475 javascript << tempVariant;
476 if (m_iDirection == 1) {
477 javascript << FX_WSTRC(L" <= ");
478 javascript << XFA_FM_EXPTypeToString(GETFMVALUE);
479 javascript << FX_WSTRC(L"(");
480 m_pAccessor->ToJavaScript(javascript);
481 javascript << FX_WSTRC(L"); ");
482 javascript << tempVariant;
483 javascript << FX_WSTRC(L" += ");
484 } else {
485 javascript << FX_WSTRC(L" >= ");
486 javascript << XFA_FM_EXPTypeToString(GETFMVALUE);
487 javascript << FX_WSTRC(L"(");
488 m_pAccessor->ToJavaScript(javascript);
489 javascript << FX_WSTRC(L"); ");
490 javascript << tempVariant;
491 javascript << FX_WSTRC(L" -= ");
492 }
493 if (m_pStep) {
494 javascript << XFA_FM_EXPTypeToString(GETFMVALUE);
495 javascript << FX_WSTRC(L"(");
496 m_pStep->ToJavaScript(javascript);
497 javascript << FX_WSTRC(L")");
498 } else {
499 javascript << FX_WSTRC(L"1");
500 }
501 javascript << FX_WSTRC(L")\n");
502 m_pList->ToImpliedReturnJS(javascript);
503 javascript << FX_WSTRC(L"}\n");
504 }
505
506 CXFA_FMForeachExpression::CXFA_FMForeachExpression(
507 FX_DWORD line,
508 const CFX_WideStringC& wsIdentifier,
509 CFX_PtrArray* pAccessors,
510 CXFA_FMExpression* pList)
511 : CXFA_FMLoopExpression(line),
512 m_wsIdentifier(wsIdentifier),
513 m_pAccessors(pAccessors),
514 m_pList(pList) {}
515
516 CXFA_FMForeachExpression::~CXFA_FMForeachExpression() {
517 if (m_pAccessors) {
518 for (int i = 0; i < m_pAccessors->GetSize(); ++i) {
519 delete reinterpret_cast<CXFA_FMSimpleExpression*>(m_pAccessors->GetAt(i));
520 }
521 m_pAccessors->RemoveAll();
522 delete m_pAccessors;
523 }
524 }
525
526 void CXFA_FMForeachExpression::ToJavaScript(CFX_WideTextBuf& javascript) {
527 javascript << FX_WSTRC(L"{\n");
528 javascript << FX_WSTRC(L"var ");
529 if (m_wsIdentifier.GetAt(0) == L'!') {
530 CFX_WideString tempIdentifier =
531 EXCLAMATION_IN_IDENTIFIER + m_wsIdentifier.Mid(1);
532 javascript << tempIdentifier;
533 } else {
534 javascript << m_wsIdentifier;
535 }
536 javascript << FX_WSTRC(L" = null;\n");
537 javascript << FX_WSTRC(L"var ");
538 javascript << RUNTIMEBLOCKTEMPARRAY;
539 javascript << FX_WSTRC(L" = ");
540 javascript << XFA_FM_EXPTypeToString(CONCATFMOBJECT);
541 javascript << FX_WSTRC(L"(");
542
543 for (int i = 0; i < m_pAccessors->GetSize(); ++i) {
544 CXFA_FMSimpleExpression* s =
545 reinterpret_cast<CXFA_FMSimpleExpression*>(m_pAccessors->GetAt(i));
546 s->ToJavaScript(javascript);
547 if (i + 1 < m_pAccessors->GetSize()) {
548 javascript << FX_WSTRC(L", ");
549 }
550 }
551 javascript << FX_WSTRC(L");\n");
552 javascript << FX_WSTRC(L"var ");
553 javascript << RUNTIMEBLOCKTEMPARRAYINDEX;
554 javascript << FX_WSTRC(L" = 0;\n");
555 javascript << FX_WSTRC(L"while(");
556 javascript << RUNTIMEBLOCKTEMPARRAYINDEX;
557 javascript << FX_WSTRC(L" < ");
558 javascript << RUNTIMEBLOCKTEMPARRAY;
559 javascript << FX_WSTRC(L".length)\n{\n");
560 if (m_wsIdentifier.GetAt(0) == L'!') {
561 CFX_WideString tempIdentifier =
562 EXCLAMATION_IN_IDENTIFIER + m_wsIdentifier.Mid(1);
563 javascript << tempIdentifier;
564 } else {
565 javascript << m_wsIdentifier;
566 }
567 javascript << FX_WSTRC(L" = ");
568 javascript << RUNTIMEBLOCKTEMPARRAY;
569 javascript << FX_WSTRC(L"[");
570 javascript << RUNTIMEBLOCKTEMPARRAYINDEX;
571 javascript << FX_WSTRC(L"++];\n");
572 m_pList->ToJavaScript(javascript);
573 javascript << FX_WSTRC(L"}\n");
574 javascript << FX_WSTRC(L"}\n");
575 }
576
577 void CXFA_FMForeachExpression::ToImpliedReturnJS(CFX_WideTextBuf& javascript) {
578 javascript << RUNTIMEFUNCTIONRETURNVALUE;
579 javascript << FX_WSTRC(L" = 0;\n");
580 javascript << FX_WSTRC(L"{\n");
581 javascript << FX_WSTRC(L"var ");
582 if (m_wsIdentifier.GetAt(0) == L'!') {
583 CFX_WideString tempIdentifier =
584 EXCLAMATION_IN_IDENTIFIER + m_wsIdentifier.Mid(1);
585 javascript << tempIdentifier;
586 } else {
587 javascript << m_wsIdentifier;
588 }
589 javascript << FX_WSTRC(L" = null;\n");
590 javascript << FX_WSTRC(L"var ");
591 javascript << RUNTIMEBLOCKTEMPARRAY;
592 javascript << FX_WSTRC(L" = ");
593 javascript << XFA_FM_EXPTypeToString(CONCATFMOBJECT);
594 javascript << FX_WSTRC(L"(");
595 for (int i = 0; i < m_pAccessors->GetSize(); ++i) {
596 CXFA_FMSimpleExpression* s =
597 reinterpret_cast<CXFA_FMSimpleExpression*>(m_pAccessors->GetAt(i));
598 s->ToJavaScript(javascript);
599 if (i + 1 < m_pAccessors->GetSize()) {
600 javascript << FX_WSTRC(L", ");
601 }
602 }
603 javascript << FX_WSTRC(L");\n");
604 javascript << FX_WSTRC(L"var ");
605 javascript << RUNTIMEBLOCKTEMPARRAYINDEX;
606 javascript << FX_WSTRC(L" = 0;\n");
607 javascript << FX_WSTRC(L"while(");
608 javascript << RUNTIMEBLOCKTEMPARRAYINDEX;
609 javascript << FX_WSTRC(L" < ");
610 javascript << RUNTIMEBLOCKTEMPARRAY;
611 javascript << FX_WSTRC(L".length)\n{\n");
612 if (m_wsIdentifier.GetAt(0) == L'!') {
613 CFX_WideString tempIdentifier =
614 EXCLAMATION_IN_IDENTIFIER + m_wsIdentifier.Mid(1);
615 javascript << tempIdentifier;
616 } else {
617 javascript << m_wsIdentifier;
618 }
619 javascript << FX_WSTRC(L" = ");
620 javascript << RUNTIMEBLOCKTEMPARRAY;
621 javascript << FX_WSTRC(L"[");
622 javascript << RUNTIMEBLOCKTEMPARRAYINDEX;
623 javascript << FX_WSTRC(L"++];\n");
624 m_pList->ToImpliedReturnJS(javascript);
625 javascript << FX_WSTRC(L"}\n");
626 javascript << FX_WSTRC(L"}\n");
627 }
OLDNEW
« no previous file with comments | « xfa/src/fxfa/fm2js/xfa_expression.h ('k') | xfa/src/fxfa/fm2js/xfa_fm2jsapi.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698