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

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

Issue 1701363003: Fix some issues with CXFA_FMParse/CXFA_FMLexer infinite looping. (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@master
Patch Set: address nits Created 4 years, 10 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/src/fm2js/xfa_fmparse.h ('k') | xfa/src/fxfa/src/fm2js/xfa_lexer.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_fm2js.h" 7 #include "xfa_fm2js.h"
8 CXFA_FMParse::CXFA_FMParse() { 8
9 m_pScript = 0; 9 CXFA_FMParse::CXFA_FMParse() : m_pToken(nullptr), m_pErrorInfo(0) {}
10 m_uLength = 0; 10
11 m_pErrorInfo = 0;
12 m_lexer = 0;
13 m_pToken = 0;
14 }
15 CXFA_FMParse::~CXFA_FMParse() {
16 if (m_lexer) {
17 delete m_lexer;
18 }
19 m_lexer = 0;
20 m_pErrorInfo = 0;
21 m_pScript = 0;
22 m_pToken = 0;
23 }
24 int32_t CXFA_FMParse::Init(const CFX_WideStringC& wsFormcalc, 11 int32_t CXFA_FMParse::Init(const CFX_WideStringC& wsFormcalc,
25 CXFA_FMErrorInfo* pErrorInfo) { 12 CXFA_FMErrorInfo* pErrorInfo) {
26 m_pScript = wsFormcalc.GetPtr();
27 m_uLength = wsFormcalc.GetLength();
28 m_pErrorInfo = pErrorInfo; 13 m_pErrorInfo = pErrorInfo;
29 m_lexer = new CXFA_FMLexer(wsFormcalc, m_pErrorInfo); 14 m_lexer.reset(new CXFA_FMLexer(wsFormcalc, m_pErrorInfo));
30 if (m_lexer == 0) {
31 return -1;
32 }
33 return 0; 15 return 0;
34 } 16 }
17
35 void CXFA_FMParse::NextToken() { 18 void CXFA_FMParse::NextToken() {
36 m_pToken = m_lexer->NextToken(); 19 m_pToken = m_lexer->NextToken();
37 while (m_pToken->m_type == TOKreserver) { 20 while (m_pToken->m_type == TOKreserver) {
38 if (m_lexer->HasError()) { 21 if (m_lexer->HasError()) {
39 break; 22 break;
40 } 23 }
41 m_pToken = m_lexer->NextToken(); 24 m_pToken = m_lexer->NextToken();
42 } 25 }
43 } 26 }
27
44 void CXFA_FMParse::Check(XFA_FM_TOKEN op) { 28 void CXFA_FMParse::Check(XFA_FM_TOKEN op) {
45 if (m_pToken->m_type != op) { 29 if (m_pToken->m_type != op) {
46 CFX_WideString ws_TempString = m_pToken->m_wstring; 30 CFX_WideString ws_TempString = m_pToken->m_wstring;
47 Error(m_pToken->m_uLinenum, FMERR_EXPECTED_TOKEN, 31 Error(m_pToken->m_uLinenum, FMERR_EXPECTED_TOKEN,
48 XFA_FM_KeywordToString(op), ws_TempString.c_str()); 32 XFA_FM_KeywordToString(op), ws_TempString.c_str());
49 } 33 }
50 NextToken(); 34 NextToken();
51 } 35 }
36
52 void CXFA_FMParse::Error(FX_DWORD lineNum, XFA_FM_ERRMSG msg, ...) { 37 void CXFA_FMParse::Error(FX_DWORD lineNum, XFA_FM_ERRMSG msg, ...) {
53 m_pErrorInfo->linenum = lineNum; 38 m_pErrorInfo->linenum = lineNum;
54 const FX_WCHAR* lpMessageInfo = XFA_FM_ErrorMsg(msg); 39 const FX_WCHAR* lpMessageInfo = XFA_FM_ErrorMsg(msg);
55 va_list ap; 40 va_list ap;
56 va_start(ap, msg); 41 va_start(ap, msg);
57 m_pErrorInfo->message.FormatV(lpMessageInfo, ap); 42 m_pErrorInfo->message.FormatV(lpMessageInfo, ap);
58 va_end(ap); 43 va_end(ap);
59 } 44 }
45
60 CFX_PtrArray* CXFA_FMParse::ParseTopExpression() { 46 CFX_PtrArray* CXFA_FMParse::ParseTopExpression() {
61 CXFA_FMExpression* e = 0; 47 CXFA_FMExpression* e = 0;
62 CFX_PtrArray* expression = new CFX_PtrArray(); 48 CFX_PtrArray* expression = new CFX_PtrArray();
63 while (1) { 49 while (1) {
64 if (m_pToken->m_type == TOKeof) { 50 if (m_pToken->m_type == TOKeof || m_pToken->m_type == TOKendfunc ||
51 m_pToken->m_type == TOKendif || m_pToken->m_type == TOKelseif ||
52 m_pToken->m_type == TOKelse || m_pToken->m_type == TOKreserver) {
65 return expression; 53 return expression;
66 } 54 }
67 if (m_pToken->m_type == TOKendfunc) { 55
68 return expression;
69 }
70 if (m_pToken->m_type == TOKendif) {
71 return expression;
72 }
73 if (m_pToken->m_type == TOKelseif) {
74 return expression;
75 }
76 if (m_pToken->m_type == TOKelse) {
77 return expression;
78 }
79 if (m_pToken->m_type == TOKfunc) { 56 if (m_pToken->m_type == TOKfunc) {
80 e = ParseFunction(); 57 e = ParseFunction();
81 if (e) { 58 if (e) {
82 expression->Add(e); 59 expression->Add(e);
83 } else { 60 } else {
84 break; 61 break;
85 } 62 }
86 } else { 63 } else {
87 e = ParseExpression(); 64 e = ParseExpression();
88 if (e) { 65 if (e) {
89 expression->Add(e); 66 expression->Add(e);
90 } else { 67 } else {
91 break; 68 break;
92 } 69 }
93 } 70 }
94 } 71 }
95 return expression; 72 return expression;
96 } 73 }
74
97 CXFA_FMExpression* CXFA_FMParse::ParseFunction() { 75 CXFA_FMExpression* CXFA_FMParse::ParseFunction() {
98 CXFA_FMExpression* e = 0; 76 CXFA_FMExpression* e = 0;
99 CFX_WideStringC ident; 77 CFX_WideStringC ident;
100 CFX_WideStringCArray* pArguments = 0; 78 CFX_WideStringCArray* pArguments = 0;
101 CFX_PtrArray* pExpressions = 0; 79 CFX_PtrArray* pExpressions = 0;
102 FX_DWORD line = m_pToken->m_uLinenum; 80 FX_DWORD line = m_pToken->m_uLinenum;
103 NextToken(); 81 NextToken();
104 if (m_pToken->m_type != TOKidentifier) { 82 if (m_pToken->m_type != TOKidentifier) {
105 CFX_WideString ws_TempString = m_pToken->m_wstring; 83 CFX_WideString ws_TempString = m_pToken->m_wstring;
106 Error(m_pToken->m_uLinenum, FMERR_EXPECTED_IDENTIFIER, 84 Error(m_pToken->m_uLinenum, FMERR_EXPECTED_IDENTIFIER,
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
165 delete e1; 143 delete e1;
166 index++; 144 index++;
167 } 145 }
168 pExpressions->RemoveAll(); 146 pExpressions->RemoveAll();
169 delete pExpressions; 147 delete pExpressions;
170 pExpressions = 0; 148 pExpressions = 0;
171 } 149 }
172 } 150 }
173 return e; 151 return e;
174 } 152 }
153
175 CXFA_FMExpression* CXFA_FMParse::ParseExpression() { 154 CXFA_FMExpression* CXFA_FMParse::ParseExpression() {
176 CXFA_FMExpression* e = 0; 155 CXFA_FMExpression* e = 0;
177 FX_DWORD line = m_pToken->m_uLinenum; 156 FX_DWORD line = m_pToken->m_uLinenum;
178 switch (m_pToken->m_type) { 157 switch (m_pToken->m_type) {
179 case TOKvar: 158 case TOKvar:
180 e = ParseVarExpression(); 159 e = ParseVarExpression();
181 break; 160 break;
182 case TOKnull: 161 case TOKnull:
183 case TOKnumber: 162 case TOKnumber:
184 case TOKstring: 163 case TOKstring:
(...skipping 29 matching lines...) Expand all
214 break; 193 break;
215 default: 194 default:
216 CFX_WideString ws_TempString = m_pToken->m_wstring; 195 CFX_WideString ws_TempString = m_pToken->m_wstring;
217 Error(m_pToken->m_uLinenum, FMERR_UNEXPECTED_EXPRESSION, 196 Error(m_pToken->m_uLinenum, FMERR_UNEXPECTED_EXPRESSION,
218 ws_TempString.c_str()); 197 ws_TempString.c_str());
219 NextToken(); 198 NextToken();
220 break; 199 break;
221 } 200 }
222 return e; 201 return e;
223 } 202 }
203
224 CXFA_FMExpression* CXFA_FMParse::ParseVarExpression() { 204 CXFA_FMExpression* CXFA_FMParse::ParseVarExpression() {
225 CXFA_FMExpression* e = 0; 205 CXFA_FMExpression* e = 0;
226 CFX_WideStringC ident; 206 CFX_WideStringC ident;
227 FX_DWORD line = m_pToken->m_uLinenum; 207 FX_DWORD line = m_pToken->m_uLinenum;
228 NextToken(); 208 NextToken();
229 if (m_pToken->m_type != TOKidentifier) { 209 if (m_pToken->m_type != TOKidentifier) {
230 CFX_WideString ws_TempString = m_pToken->m_wstring; 210 CFX_WideString ws_TempString = m_pToken->m_wstring;
231 Error(m_pToken->m_uLinenum, FMERR_EXPECTED_IDENTIFIER, 211 Error(m_pToken->m_uLinenum, FMERR_EXPECTED_IDENTIFIER,
232 ws_TempString.c_str()); 212 ws_TempString.c_str());
233 } else { 213 } else {
234 ident = m_pToken->m_wstring; 214 ident = m_pToken->m_wstring;
235 NextToken(); 215 NextToken();
236 } 216 }
237 if (m_pToken->m_type == TOKassign) { 217 if (m_pToken->m_type == TOKassign) {
238 NextToken(); 218 NextToken();
239 e = ParseExpExpression(); 219 e = ParseExpExpression();
240 } 220 }
241 if (m_pErrorInfo->message.IsEmpty()) { 221 if (m_pErrorInfo->message.IsEmpty()) {
242 e = new CXFA_FMVarExpression(line, ident, e); 222 e = new CXFA_FMVarExpression(line, ident, e);
243 } else { 223 } else {
244 delete e; 224 delete e;
245 e = 0; 225 e = 0;
246 } 226 }
247 return e; 227 return e;
248 } 228 }
229
249 CXFA_FMSimpleExpression* CXFA_FMParse::ParseSimpleExpression() { 230 CXFA_FMSimpleExpression* CXFA_FMParse::ParseSimpleExpression() {
250 FX_DWORD line = m_pToken->m_uLinenum; 231 FX_DWORD line = m_pToken->m_uLinenum;
251 CXFA_FMSimpleExpression *pExp1 = 0, *pExp2 = 0; 232 CXFA_FMSimpleExpression *pExp1 = 0, *pExp2 = 0;
252 pExp1 = ParseLogicalOrExpression(); 233 pExp1 = ParseLogicalOrExpression();
253 while (m_pToken->m_type == TOKassign) { 234 while (m_pToken->m_type == TOKassign) {
254 NextToken(); 235 NextToken();
255 pExp2 = ParseLogicalOrExpression(); 236 pExp2 = ParseLogicalOrExpression();
256 if (m_pErrorInfo->message.IsEmpty()) { 237 if (m_pErrorInfo->message.IsEmpty()) {
257 pExp1 = new CXFA_FMAssignExpression(line, TOKassign, pExp1, pExp2); 238 pExp1 = new CXFA_FMAssignExpression(line, TOKassign, pExp1, pExp2);
258 } else { 239 } else {
259 delete pExp1; 240 delete pExp1;
260 pExp1 = 0; 241 pExp1 = 0;
261 } 242 }
262 } 243 }
263 return pExp1; 244 return pExp1;
264 } 245 }
246
265 CXFA_FMExpression* CXFA_FMParse::ParseExpExpression() { 247 CXFA_FMExpression* CXFA_FMParse::ParseExpExpression() {
266 CXFA_FMExpression* e = 0; 248 CXFA_FMExpression* e = 0;
267 FX_DWORD line = m_pToken->m_uLinenum; 249 FX_DWORD line = m_pToken->m_uLinenum;
268 CXFA_FMSimpleExpression* pExp1 = 0; 250 CXFA_FMSimpleExpression* pExp1 = 0;
269 pExp1 = ParseSimpleExpression(); 251 pExp1 = ParseSimpleExpression();
270 if (m_pErrorInfo->message.IsEmpty()) { 252 if (m_pErrorInfo->message.IsEmpty()) {
271 e = new CXFA_FMExpExpression(line, pExp1); 253 e = new CXFA_FMExpExpression(line, pExp1);
272 } else { 254 } else {
273 delete pExp1; 255 delete pExp1;
274 e = 0; 256 e = 0;
275 } 257 }
276 return e; 258 return e;
277 } 259 }
260
278 CXFA_FMSimpleExpression* CXFA_FMParse::ParseLogicalOrExpression() { 261 CXFA_FMSimpleExpression* CXFA_FMParse::ParseLogicalOrExpression() {
279 CXFA_FMSimpleExpression *e1 = 0, *e2 = 0; 262 CXFA_FMSimpleExpression *e1 = 0, *e2 = 0;
280 FX_DWORD line = m_pToken->m_uLinenum; 263 FX_DWORD line = m_pToken->m_uLinenum;
281 e1 = ParseLogicalAndExpression(); 264 e1 = ParseLogicalAndExpression();
282 for (;;) { 265 for (;;) {
283 switch (m_pToken->m_type) { 266 switch (m_pToken->m_type) {
284 case TOKor: 267 case TOKor:
285 case TOKksor: 268 case TOKksor:
286 NextToken(); 269 NextToken();
287 e2 = ParseLogicalAndExpression(); 270 e2 = ParseLogicalAndExpression();
288 if (m_pErrorInfo->message.IsEmpty()) { 271 if (m_pErrorInfo->message.IsEmpty()) {
289 e1 = new CXFA_FMLogicalOrExpression(line, TOKor, e1, e2); 272 e1 = new CXFA_FMLogicalOrExpression(line, TOKor, e1, e2);
290 } else { 273 } else {
291 delete e1; 274 delete e1;
292 e1 = 0; 275 e1 = 0;
293 } 276 }
294 continue; 277 continue;
295 default: 278 default:
296 break; 279 break;
297 } 280 }
298 break; 281 break;
299 } 282 }
300 return e1; 283 return e1;
301 } 284 }
285
302 CXFA_FMSimpleExpression* CXFA_FMParse::ParseLogicalAndExpression() { 286 CXFA_FMSimpleExpression* CXFA_FMParse::ParseLogicalAndExpression() {
303 CXFA_FMSimpleExpression *e1 = 0, *e2 = 0; 287 CXFA_FMSimpleExpression *e1 = 0, *e2 = 0;
304 FX_DWORD line = m_pToken->m_uLinenum; 288 FX_DWORD line = m_pToken->m_uLinenum;
305 e1 = ParseEqualityExpression(); 289 e1 = ParseEqualityExpression();
306 for (;;) { 290 for (;;) {
307 switch (m_pToken->m_type) { 291 switch (m_pToken->m_type) {
308 case TOKand: 292 case TOKand:
309 case TOKksand: 293 case TOKksand:
310 NextToken(); 294 NextToken();
311 e2 = ParseEqualityExpression(); 295 e2 = ParseEqualityExpression();
312 if (m_pErrorInfo->message.IsEmpty()) { 296 if (m_pErrorInfo->message.IsEmpty()) {
313 e1 = new CXFA_FMLogicalAndExpression(line, TOKand, e1, e2); 297 e1 = new CXFA_FMLogicalAndExpression(line, TOKand, e1, e2);
314 } else { 298 } else {
315 delete e1; 299 delete e1;
316 e1 = 0; 300 e1 = 0;
317 } 301 }
318 continue; 302 continue;
319 default: 303 default:
320 break; 304 break;
321 } 305 }
322 break; 306 break;
323 } 307 }
324 return e1; 308 return e1;
325 } 309 }
310
326 CXFA_FMSimpleExpression* CXFA_FMParse::ParseEqualityExpression() { 311 CXFA_FMSimpleExpression* CXFA_FMParse::ParseEqualityExpression() {
327 CXFA_FMSimpleExpression *e1 = 0, *e2 = 0; 312 CXFA_FMSimpleExpression *e1 = 0, *e2 = 0;
328 FX_DWORD line = m_pToken->m_uLinenum; 313 FX_DWORD line = m_pToken->m_uLinenum;
329 e1 = ParseRelationalExpression(); 314 e1 = ParseRelationalExpression();
330 for (;;) { 315 for (;;) {
331 switch (m_pToken->m_type) { 316 switch (m_pToken->m_type) {
332 case TOKeq: 317 case TOKeq:
333 case TOKkseq: 318 case TOKkseq:
334 NextToken(); 319 NextToken();
335 e2 = ParseRelationalExpression(); 320 e2 = ParseRelationalExpression();
(...skipping 15 matching lines...) Expand all
351 e1 = 0; 336 e1 = 0;
352 } 337 }
353 continue; 338 continue;
354 default: 339 default:
355 break; 340 break;
356 } 341 }
357 break; 342 break;
358 } 343 }
359 return e1; 344 return e1;
360 } 345 }
346
361 CXFA_FMSimpleExpression* CXFA_FMParse::ParseRelationalExpression() { 347 CXFA_FMSimpleExpression* CXFA_FMParse::ParseRelationalExpression() {
362 CXFA_FMSimpleExpression *e1 = 0, *e2 = 0; 348 CXFA_FMSimpleExpression *e1 = 0, *e2 = 0;
363 FX_DWORD line = m_pToken->m_uLinenum; 349 FX_DWORD line = m_pToken->m_uLinenum;
364 e1 = ParseAddtiveExpression(); 350 e1 = ParseAddtiveExpression();
365 for (;;) { 351 for (;;) {
366 switch (m_pToken->m_type) { 352 switch (m_pToken->m_type) {
367 case TOKlt: 353 case TOKlt:
368 case TOKkslt: 354 case TOKkslt:
369 NextToken(); 355 NextToken();
370 e2 = ParseAddtiveExpression(); 356 e2 = ParseAddtiveExpression();
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
408 e1 = 0; 394 e1 = 0;
409 } 395 }
410 continue; 396 continue;
411 default: 397 default:
412 break; 398 break;
413 } 399 }
414 break; 400 break;
415 } 401 }
416 return e1; 402 return e1;
417 } 403 }
404
418 CXFA_FMSimpleExpression* CXFA_FMParse::ParseAddtiveExpression() { 405 CXFA_FMSimpleExpression* CXFA_FMParse::ParseAddtiveExpression() {
419 CXFA_FMSimpleExpression *e1 = 0, *e2 = 0; 406 CXFA_FMSimpleExpression *e1 = 0, *e2 = 0;
420 FX_DWORD line = m_pToken->m_uLinenum; 407 FX_DWORD line = m_pToken->m_uLinenum;
421 e1 = ParseMultiplicativeExpression(); 408 e1 = ParseMultiplicativeExpression();
422 for (;;) { 409 for (;;) {
423 switch (m_pToken->m_type) { 410 switch (m_pToken->m_type) {
424 case TOKplus: 411 case TOKplus:
425 NextToken(); 412 NextToken();
426 e2 = ParseMultiplicativeExpression(); 413 e2 = ParseMultiplicativeExpression();
427 if (m_pErrorInfo->message.IsEmpty()) { 414 if (m_pErrorInfo->message.IsEmpty()) {
(...skipping 13 matching lines...) Expand all
441 e1 = 0; 428 e1 = 0;
442 } 429 }
443 continue; 430 continue;
444 default: 431 default:
445 break; 432 break;
446 } 433 }
447 break; 434 break;
448 } 435 }
449 return e1; 436 return e1;
450 } 437 }
438
451 CXFA_FMSimpleExpression* CXFA_FMParse::ParseMultiplicativeExpression() { 439 CXFA_FMSimpleExpression* CXFA_FMParse::ParseMultiplicativeExpression() {
452 CXFA_FMSimpleExpression *e1 = 0, *e2 = 0; 440 CXFA_FMSimpleExpression *e1 = 0, *e2 = 0;
453 FX_DWORD line = m_pToken->m_uLinenum; 441 FX_DWORD line = m_pToken->m_uLinenum;
454 e1 = ParseUnaryExpression(); 442 e1 = ParseUnaryExpression();
455 for (;;) { 443 for (;;) {
456 switch (m_pToken->m_type) { 444 switch (m_pToken->m_type) {
457 case TOKmul: 445 case TOKmul:
458 NextToken(); 446 NextToken();
459 e2 = ParseUnaryExpression(); 447 e2 = ParseUnaryExpression();
460 if (m_pErrorInfo->message.IsEmpty()) { 448 if (m_pErrorInfo->message.IsEmpty()) {
(...skipping 13 matching lines...) Expand all
474 e1 = 0; 462 e1 = 0;
475 } 463 }
476 continue; 464 continue;
477 default: 465 default:
478 break; 466 break;
479 } 467 }
480 break; 468 break;
481 } 469 }
482 return e1; 470 return e1;
483 } 471 }
472
484 CXFA_FMSimpleExpression* CXFA_FMParse::ParseUnaryExpression() { 473 CXFA_FMSimpleExpression* CXFA_FMParse::ParseUnaryExpression() {
485 CXFA_FMSimpleExpression* e = 0; 474 CXFA_FMSimpleExpression* e = 0;
486 FX_DWORD line = m_pToken->m_uLinenum; 475 FX_DWORD line = m_pToken->m_uLinenum;
487 switch (m_pToken->m_type) { 476 switch (m_pToken->m_type) {
488 case TOKplus: 477 case TOKplus:
489 NextToken(); 478 NextToken();
490 e = ParseUnaryExpression(); 479 e = ParseUnaryExpression();
491 if (m_pErrorInfo->message.IsEmpty()) { 480 if (m_pErrorInfo->message.IsEmpty()) {
492 e = new CXFA_FMPosExpression(line, e); 481 e = new CXFA_FMPosExpression(line, e);
493 } else { 482 } else {
(...skipping 17 matching lines...) Expand all
511 } else { 500 } else {
512 e = 0; 501 e = 0;
513 } 502 }
514 break; 503 break;
515 default: 504 default:
516 e = ParsePrimaryExpression(); 505 e = ParsePrimaryExpression();
517 break; 506 break;
518 } 507 }
519 return e; 508 return e;
520 } 509 }
510
521 CXFA_FMSimpleExpression* CXFA_FMParse::ParsePrimaryExpression() { 511 CXFA_FMSimpleExpression* CXFA_FMParse::ParsePrimaryExpression() {
522 CXFA_FMSimpleExpression* e = 0; 512 CXFA_FMSimpleExpression* e = 0;
523 FX_DWORD line = m_pToken->m_uLinenum; 513 FX_DWORD line = m_pToken->m_uLinenum;
524 switch (m_pToken->m_type) { 514 switch (m_pToken->m_type) {
525 case TOKnumber: 515 case TOKnumber:
526 e = new CXFA_FMNumberExpression(line, m_pToken->m_wstring); 516 e = new CXFA_FMNumberExpression(line, m_pToken->m_wstring);
527 NextToken(); 517 NextToken();
528 break; 518 break;
529 case TOKstring: 519 case TOKstring:
530 e = new CXFA_FMStringExpression(line, m_pToken->m_wstring); 520 e = new CXFA_FMStringExpression(line, m_pToken->m_wstring);
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
562 NextToken(); 552 NextToken();
563 break; 553 break;
564 } 554 }
565 e = ParsePostExpression(e); 555 e = ParsePostExpression(e);
566 if (!(m_pErrorInfo->message.IsEmpty())) { 556 if (!(m_pErrorInfo->message.IsEmpty())) {
567 delete e; 557 delete e;
568 e = 0; 558 e = 0;
569 } 559 }
570 return e; 560 return e;
571 } 561 }
562
572 CXFA_FMSimpleExpression* CXFA_FMParse::ParsePostExpression( 563 CXFA_FMSimpleExpression* CXFA_FMParse::ParsePostExpression(
573 CXFA_FMSimpleExpression* e) { 564 CXFA_FMSimpleExpression* e) {
574 FX_DWORD line = m_pToken->m_uLinenum; 565 FX_DWORD line = m_pToken->m_uLinenum;
575 while (1) { 566 while (1) {
576 switch (m_pToken->m_type) { 567 switch (m_pToken->m_type) {
577 case TOKlparen: { 568 case TOKlparen: {
578 NextToken(); 569 NextToken();
579 CFX_PtrArray* pArray = 0; 570 CFX_PtrArray* pArray = 0;
580 if (m_pToken->m_type != TOKrparen) { 571 if (m_pToken->m_type != TOKrparen) {
581 pArray = new CFX_PtrArray(); 572 pArray = new CFX_PtrArray();
582 while (m_pToken->m_type != TOKrparen) { 573 while (m_pToken->m_type != TOKrparen) {
583 CXFA_FMSimpleExpression* e = ParseSimpleExpression(); 574 CXFA_FMSimpleExpression* e = ParseSimpleExpression();
584 if (e) { 575 if (e) {
585 pArray->Add(e); 576 pArray->Add(e);
586 } 577 }
587 if (m_pToken->m_type == TOKcomma) { 578 if (m_pToken->m_type == TOKcomma) {
588 NextToken(); 579 NextToken();
589 } else if (m_pToken->m_type == TOKeof) { 580 } else if (m_pToken->m_type == TOKeof ||
581 m_pToken->m_type == TOKreserver) {
590 break; 582 break;
591 } 583 }
592 } 584 }
593 if (m_pToken->m_type != TOKrparen) { 585 if (m_pToken->m_type != TOKrparen) {
594 CFX_WideString ws_TempString = m_pToken->m_wstring; 586 CFX_WideString ws_TempString = m_pToken->m_wstring;
595 Error(m_pToken->m_uLinenum, FMERR_EXPECTED_TOKEN, 587 Error(m_pToken->m_uLinenum, FMERR_EXPECTED_TOKEN,
596 XFA_FM_KeywordToString(TOKrparen), ws_TempString.c_str()); 588 XFA_FM_KeywordToString(TOKrparen), ws_TempString.c_str());
597 } 589 }
598 } 590 }
599 if (m_pErrorInfo->message.IsEmpty()) { 591 if (m_pErrorInfo->message.IsEmpty()) {
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
634 pExpAccessor = e; 626 pExpAccessor = e;
635 NextToken(); 627 NextToken();
636 CFX_PtrArray* pArray = 0; 628 CFX_PtrArray* pArray = 0;
637 if (m_pToken->m_type != TOKrparen) { 629 if (m_pToken->m_type != TOKrparen) {
638 pArray = new CFX_PtrArray(); 630 pArray = new CFX_PtrArray();
639 while (m_pToken->m_type != TOKrparen) { 631 while (m_pToken->m_type != TOKrparen) {
640 CXFA_FMSimpleExpression* exp = ParseSimpleExpression(); 632 CXFA_FMSimpleExpression* exp = ParseSimpleExpression();
641 pArray->Add(exp); 633 pArray->Add(exp);
642 if (m_pToken->m_type == TOKcomma) { 634 if (m_pToken->m_type == TOKcomma) {
643 NextToken(); 635 NextToken();
644 } else if (m_pToken->m_type == TOKeof) { 636 } else if (m_pToken->m_type == TOKeof ||
637 m_pToken->m_type == TOKreserver) {
645 break; 638 break;
646 } 639 }
647 } 640 }
648 if (m_pToken->m_type != TOKrparen) { 641 if (m_pToken->m_type != TOKrparen) {
649 CFX_WideString ws_TempString = m_pToken->m_wstring; 642 CFX_WideString ws_TempString = m_pToken->m_wstring;
650 Error(m_pToken->m_uLinenum, FMERR_EXPECTED_TOKEN, 643 Error(m_pToken->m_uLinenum, FMERR_EXPECTED_TOKEN,
651 XFA_FM_KeywordToString(TOKrparen), ws_TempString.c_str()); 644 XFA_FM_KeywordToString(TOKrparen), ws_TempString.c_str());
652 } 645 }
653 } 646 }
654 if (m_pErrorInfo->message.IsEmpty()) { 647 if (m_pErrorInfo->message.IsEmpty()) {
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after
784 e = new CXFA_FMDotAccessorExpression(line, e, TOKdotstar, 777 e = new CXFA_FMDotAccessorExpression(line, e, TOKdotstar,
785 FX_WSTRC(L"*"), s); 778 FX_WSTRC(L"*"), s);
786 } break; 779 } break;
787 default: 780 default:
788 return e; 781 return e;
789 } 782 }
790 NextToken(); 783 NextToken();
791 } 784 }
792 return e; 785 return e;
793 } 786 }
787
794 CXFA_FMSimpleExpression* CXFA_FMParse::ParseIndexExpression() { 788 CXFA_FMSimpleExpression* CXFA_FMParse::ParseIndexExpression() {
795 CXFA_FMSimpleExpression* pExp = 0; 789 CXFA_FMSimpleExpression* pExp = 0;
796 FX_DWORD line = m_pToken->m_uLinenum; 790 FX_DWORD line = m_pToken->m_uLinenum;
797 NextToken(); 791 NextToken();
798 CXFA_FMSimpleExpression* s = 0; 792 CXFA_FMSimpleExpression* s = 0;
799 XFA_FM_AccessorIndex accessorIndex = ACCESSOR_NO_RELATIVEINDEX; 793 XFA_FM_AccessorIndex accessorIndex = ACCESSOR_NO_RELATIVEINDEX;
800 if (m_pToken->m_type == TOKmul) { 794 if (m_pToken->m_type == TOKmul) {
801 pExp = new CXFA_FMIndexExpression(line, accessorIndex, s, TRUE); 795 pExp = new CXFA_FMIndexExpression(line, accessorIndex, s, TRUE);
802 NextToken(); 796 NextToken();
803 if (m_pToken->m_type != TOKrbracket) { 797 if (m_pToken->m_type != TOKrbracket) {
(...skipping 20 matching lines...) Expand all
824 Error(m_pToken->m_uLinenum, FMERR_EXPECTED_TOKEN, 818 Error(m_pToken->m_uLinenum, FMERR_EXPECTED_TOKEN,
825 XFA_FM_KeywordToString(TOKrparen), ws_TempString.c_str()); 819 XFA_FM_KeywordToString(TOKrparen), ws_TempString.c_str());
826 if (s) { 820 if (s) {
827 delete s; 821 delete s;
828 } 822 }
829 } else { 823 } else {
830 pExp = new CXFA_FMIndexExpression(line, accessorIndex, s, FALSE); 824 pExp = new CXFA_FMIndexExpression(line, accessorIndex, s, FALSE);
831 } 825 }
832 return pExp; 826 return pExp;
833 } 827 }
828
834 CXFA_FMSimpleExpression* CXFA_FMParse::ParseParenExpression() { 829 CXFA_FMSimpleExpression* CXFA_FMParse::ParseParenExpression() {
835 CXFA_FMSimpleExpression *pExp1 = 0, *pExp2 = 0; 830 CXFA_FMSimpleExpression *pExp1 = 0, *pExp2 = 0;
836 FX_DWORD line = m_pToken->m_uLinenum; 831 FX_DWORD line = m_pToken->m_uLinenum;
837 Check(TOKlparen); 832 Check(TOKlparen);
838 if (m_pToken->m_type != TOKrparen) { 833 if (m_pToken->m_type != TOKrparen) {
839 pExp1 = ParseLogicalOrExpression(); 834 pExp1 = ParseLogicalOrExpression();
840 while (m_pToken->m_type == TOKassign) { 835 while (m_pToken->m_type == TOKassign) {
841 NextToken(); 836 NextToken();
842 pExp2 = ParseLogicalOrExpression(); 837 pExp2 = ParseLogicalOrExpression();
843 if (m_pErrorInfo->message.IsEmpty()) { 838 if (m_pErrorInfo->message.IsEmpty()) {
844 pExp1 = new CXFA_FMAssignExpression(line, TOKassign, pExp1, pExp2); 839 pExp1 = new CXFA_FMAssignExpression(line, TOKassign, pExp1, pExp2);
845 } else { 840 } else {
846 delete pExp1; 841 delete pExp1;
847 pExp1 = 0; 842 pExp1 = 0;
848 } 843 }
849 } 844 }
850 Check(TOKrparen); 845 Check(TOKrparen);
851 } else { 846 } else {
852 NextToken(); 847 NextToken();
853 } 848 }
854 return pExp1; 849 return pExp1;
855 } 850 }
851
856 CXFA_FMExpression* CXFA_FMParse::ParseBlockExpression() { 852 CXFA_FMExpression* CXFA_FMParse::ParseBlockExpression() {
857 FX_DWORD line = m_pToken->m_uLinenum; 853 FX_DWORD line = m_pToken->m_uLinenum;
858 CXFA_FMExpression* e = 0; 854 CXFA_FMExpression* e = 0;
859 CFX_PtrArray* expression = new CFX_PtrArray(); 855 CFX_PtrArray* expression = new CFX_PtrArray();
860 while (1) { 856 while (1) {
861 switch (m_pToken->m_type) { 857 switch (m_pToken->m_type) {
862 case TOKeof: 858 case TOKeof:
863 case TOKendif: 859 case TOKendif:
864 case TOKelseif: 860 case TOKelseif:
865 case TOKelse: 861 case TOKelse:
866 case TOKendwhile: 862 case TOKendwhile:
867 case TOKendfor: 863 case TOKendfor:
868 case TOKend: 864 case TOKend:
869 case TOKendfunc: 865 case TOKendfunc:
866 case TOKreserver:
870 break; 867 break;
871 case TOKfunc: 868 case TOKfunc:
872 e = ParseFunction(); 869 e = ParseFunction();
873 if (e) { 870 if (e) {
874 expression->Add(e); 871 expression->Add(e);
875 } 872 }
876 continue; 873 continue;
877 default: 874 default:
878 e = ParseExpression(); 875 e = ParseExpression();
879 if (e) { 876 if (e) {
(...skipping 13 matching lines...) Expand all
893 e = (CXFA_FMExpression*)expression->GetAt(index); 890 e = (CXFA_FMExpression*)expression->GetAt(index);
894 delete e; 891 delete e;
895 index++; 892 index++;
896 } 893 }
897 expression->RemoveAll(); 894 expression->RemoveAll();
898 delete expression; 895 delete expression;
899 expression = 0; 896 expression = 0;
900 } 897 }
901 return pExp; 898 return pExp;
902 } 899 }
900
903 CXFA_FMExpression* CXFA_FMParse::ParseIfExpression() { 901 CXFA_FMExpression* CXFA_FMParse::ParseIfExpression() {
904 CXFA_FMSimpleExpression* pExpression = 0; 902 CXFA_FMSimpleExpression* pExpression = 0;
905 CXFA_FMExpression* pIfExpression = 0; 903 CXFA_FMExpression* pIfExpression = 0;
906 CXFA_FMExpression* pElseExpression = 0; 904 CXFA_FMExpression* pElseExpression = 0;
907 FX_DWORD line = m_pToken->m_uLinenum; 905 FX_DWORD line = m_pToken->m_uLinenum;
908 const FX_WCHAR* pStartPos = m_lexer->SavePos(); 906 const FX_WCHAR* pStartPos = m_lexer->SavePos();
909 NextToken(); 907 NextToken();
910 Check(TOKlparen); 908 Check(TOKlparen);
911 while (m_pToken->m_type != TOKrparen) { 909 while (m_pToken->m_type != TOKrparen) {
912 if (pExpression) { 910 if (pExpression) {
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
967 } 965 }
968 if (pIfExpression) { 966 if (pIfExpression) {
969 delete pIfExpression; 967 delete pIfExpression;
970 } 968 }
971 if (pElseExpression) { 969 if (pElseExpression) {
972 delete pElseExpression; 970 delete pElseExpression;
973 } 971 }
974 } 972 }
975 return pExp; 973 return pExp;
976 } 974 }
975
977 CXFA_FMExpression* CXFA_FMParse::ParseWhileExpression() { 976 CXFA_FMExpression* CXFA_FMParse::ParseWhileExpression() {
978 CXFA_FMExpression* e = 0; 977 CXFA_FMExpression* e = 0;
979 CXFA_FMSimpleExpression* pCondition = 0; 978 CXFA_FMSimpleExpression* pCondition = 0;
980 CXFA_FMExpression* pExpression = 0; 979 CXFA_FMExpression* pExpression = 0;
981 FX_DWORD line = m_pToken->m_uLinenum; 980 FX_DWORD line = m_pToken->m_uLinenum;
982 NextToken(); 981 NextToken();
983 pCondition = ParseParenExpression(); 982 pCondition = ParseParenExpression();
984 Check(TOKdo); 983 Check(TOKdo);
985 pExpression = ParseBlockExpression(); 984 pExpression = ParseBlockExpression();
986 Check(TOKendwhile); 985 Check(TOKendwhile);
987 if (!m_pErrorInfo->message.IsEmpty()) { 986 if (!m_pErrorInfo->message.IsEmpty()) {
988 if (pCondition) { 987 if (pCondition) {
989 delete pCondition; 988 delete pCondition;
990 } 989 }
991 if (pExpression) { 990 if (pExpression) {
992 delete pExpression; 991 delete pExpression;
993 } 992 }
994 delete e; 993 delete e;
995 e = 0; 994 e = 0;
996 } else { 995 } else {
997 e = new CXFA_FMWhileExpression(line, pCondition, pExpression); 996 e = new CXFA_FMWhileExpression(line, pCondition, pExpression);
998 } 997 }
999 return e; 998 return e;
1000 } 999 }
1000
1001 CXFA_FMSimpleExpression* CXFA_FMParse::ParseSubassignmentInForExpression() { 1001 CXFA_FMSimpleExpression* CXFA_FMParse::ParseSubassignmentInForExpression() {
1002 CXFA_FMSimpleExpression* e = 0; 1002 CXFA_FMSimpleExpression* e = 0;
1003 switch (m_pToken->m_type) { 1003 switch (m_pToken->m_type) {
1004 case TOKidentifier: 1004 case TOKidentifier:
1005 e = ParseSimpleExpression(); 1005 e = ParseSimpleExpression();
1006 break; 1006 break;
1007 default: 1007 default:
1008 CFX_WideString ws_TempString = m_pToken->m_wstring; 1008 CFX_WideString ws_TempString = m_pToken->m_wstring;
1009 Error(m_pToken->m_uLinenum, FMERR_UNEXPECTED_EXPRESSION, 1009 Error(m_pToken->m_uLinenum, FMERR_UNEXPECTED_EXPRESSION,
1010 ws_TempString.c_str()); 1010 ws_TempString.c_str());
1011 NextToken(); 1011 NextToken();
1012 break; 1012 break;
1013 } 1013 }
1014 return e; 1014 return e;
1015 } 1015 }
1016
1016 CXFA_FMExpression* CXFA_FMParse::ParseForExpression() { 1017 CXFA_FMExpression* CXFA_FMParse::ParseForExpression() {
1017 CXFA_FMExpression* e = 0; 1018 CXFA_FMExpression* e = 0;
1018 CFX_WideStringC wsVariant; 1019 CFX_WideStringC wsVariant;
1019 CXFA_FMSimpleExpression* pAssignment = 0; 1020 CXFA_FMSimpleExpression* pAssignment = 0;
1020 CXFA_FMSimpleExpression* pAccessor = 0; 1021 CXFA_FMSimpleExpression* pAccessor = 0;
1021 CXFA_FMSimpleExpression* pStep = 0; 1022 CXFA_FMSimpleExpression* pStep = 0;
1022 CXFA_FMExpression* pList = 0; 1023 CXFA_FMExpression* pList = 0;
1023 FX_DWORD line = m_pToken->m_uLinenum; 1024 FX_DWORD line = m_pToken->m_uLinenum;
1024 NextToken(); 1025 NextToken();
1025 if (m_pToken->m_type != TOKidentifier) { 1026 if (m_pToken->m_type != TOKidentifier) {
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
1068 } 1069 }
1069 if (pStep) { 1070 if (pStep) {
1070 delete pStep; 1071 delete pStep;
1071 } 1072 }
1072 if (pList) { 1073 if (pList) {
1073 delete pList; 1074 delete pList;
1074 } 1075 }
1075 } 1076 }
1076 return e; 1077 return e;
1077 } 1078 }
1079
1078 CXFA_FMExpression* CXFA_FMParse::ParseForeachExpression() { 1080 CXFA_FMExpression* CXFA_FMParse::ParseForeachExpression() {
1079 CXFA_FMExpression* e = 0; 1081 CXFA_FMExpression* e = 0;
1080 CFX_WideStringC wsIdentifier; 1082 CFX_WideStringC wsIdentifier;
1081 CFX_PtrArray* pAccessors = 0; 1083 CFX_PtrArray* pAccessors = 0;
1082 CXFA_FMExpression* pList = 0; 1084 CXFA_FMExpression* pList = 0;
1083 FX_DWORD line = m_pToken->m_uLinenum; 1085 FX_DWORD line = m_pToken->m_uLinenum;
1084 NextToken(); 1086 NextToken();
1085 if (m_pToken->m_type != TOKidentifier) { 1087 if (m_pToken->m_type != TOKidentifier) {
1086 CFX_WideString ws_TempString = m_pToken->m_wstring; 1088 CFX_WideString ws_TempString = m_pToken->m_wstring;
1087 Error(m_pToken->m_uLinenum, FMERR_EXPECTED_TOKEN, 1089 Error(m_pToken->m_uLinenum, FMERR_EXPECTED_TOKEN,
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
1129 pAccessors->RemoveAll(); 1131 pAccessors->RemoveAll();
1130 delete pAccessors; 1132 delete pAccessors;
1131 pAccessors = 0; 1133 pAccessors = 0;
1132 } 1134 }
1133 if (pList) { 1135 if (pList) {
1134 delete pList; 1136 delete pList;
1135 } 1137 }
1136 } 1138 }
1137 return e; 1139 return e;
1138 } 1140 }
1141
1139 CXFA_FMExpression* CXFA_FMParse::ParseDoExpression() { 1142 CXFA_FMExpression* CXFA_FMParse::ParseDoExpression() {
1140 CXFA_FMExpression* e = 0; 1143 CXFA_FMExpression* e = 0;
1141 FX_DWORD line = m_pToken->m_uLinenum; 1144 FX_DWORD line = m_pToken->m_uLinenum;
1142 NextToken(); 1145 NextToken();
1143 e = ParseBlockExpression(); 1146 e = ParseBlockExpression();
1144 Check(TOKend); 1147 Check(TOKend);
1145 if (m_pErrorInfo->message.IsEmpty()) { 1148 if (m_pErrorInfo->message.IsEmpty()) {
1146 e = new CXFA_FMDoExpression(line, e); 1149 e = new CXFA_FMDoExpression(line, e);
1147 } else { 1150 } else {
1148 delete e; 1151 delete e;
1149 e = 0; 1152 e = 0;
1150 } 1153 }
1151 return e; 1154 return e;
1152 } 1155 }
OLDNEW
« no previous file with comments | « xfa/src/fxfa/src/fm2js/xfa_fmparse.h ('k') | xfa/src/fxfa/src/fm2js/xfa_lexer.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698