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

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: delete more stuff 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
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) {
Tom Sepez 2016/02/18 00:39:14 nit: combine with || while you're at it.
Oliver Chang 2016/02/18 00:49:02 Done.
65 return expression; 51 return expression;
66 } 52 }
67 if (m_pToken->m_type == TOKendfunc) { 53 if (m_pToken->m_type == TOKendfunc) {
68 return expression; 54 return expression;
69 } 55 }
70 if (m_pToken->m_type == TOKendif) { 56 if (m_pToken->m_type == TOKendif) {
71 return expression; 57 return expression;
72 } 58 }
73 if (m_pToken->m_type == TOKelseif) { 59 if (m_pToken->m_type == TOKelseif) {
74 return expression; 60 return expression;
75 } 61 }
76 if (m_pToken->m_type == TOKelse) { 62 if (m_pToken->m_type == TOKelse) {
77 return expression; 63 return expression;
78 } 64 }
65 if (m_pToken->m_type == TOKreserver) {
66 return expression;
67 }
68
79 if (m_pToken->m_type == TOKfunc) { 69 if (m_pToken->m_type == TOKfunc) {
80 e = ParseFunction(); 70 e = ParseFunction();
81 if (e) { 71 if (e) {
82 expression->Add(e); 72 expression->Add(e);
83 } else { 73 } else {
84 break; 74 break;
85 } 75 }
86 } else { 76 } else {
87 e = ParseExpression(); 77 e = ParseExpression();
88 if (e) { 78 if (e) {
89 expression->Add(e); 79 expression->Add(e);
90 } else { 80 } else {
91 break; 81 break;
92 } 82 }
93 } 83 }
94 } 84 }
95 return expression; 85 return expression;
96 } 86 }
87
97 CXFA_FMExpression* CXFA_FMParse::ParseFunction() { 88 CXFA_FMExpression* CXFA_FMParse::ParseFunction() {
98 CXFA_FMExpression* e = 0; 89 CXFA_FMExpression* e = 0;
99 CFX_WideStringC ident; 90 CFX_WideStringC ident;
100 CFX_WideStringCArray* pArguments = 0; 91 CFX_WideStringCArray* pArguments = 0;
101 CFX_PtrArray* pExpressions = 0; 92 CFX_PtrArray* pExpressions = 0;
102 FX_DWORD line = m_pToken->m_uLinenum; 93 FX_DWORD line = m_pToken->m_uLinenum;
103 NextToken(); 94 NextToken();
104 if (m_pToken->m_type != TOKidentifier) { 95 if (m_pToken->m_type != TOKidentifier) {
105 CFX_WideString ws_TempString = m_pToken->m_wstring; 96 CFX_WideString ws_TempString = m_pToken->m_wstring;
106 Error(m_pToken->m_uLinenum, FMERR_EXPECTED_IDENTIFIER, 97 Error(m_pToken->m_uLinenum, FMERR_EXPECTED_IDENTIFIER,
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
165 delete e1; 156 delete e1;
166 index++; 157 index++;
167 } 158 }
168 pExpressions->RemoveAll(); 159 pExpressions->RemoveAll();
169 delete pExpressions; 160 delete pExpressions;
170 pExpressions = 0; 161 pExpressions = 0;
171 } 162 }
172 } 163 }
173 return e; 164 return e;
174 } 165 }
166
175 CXFA_FMExpression* CXFA_FMParse::ParseExpression() { 167 CXFA_FMExpression* CXFA_FMParse::ParseExpression() {
176 CXFA_FMExpression* e = 0; 168 CXFA_FMExpression* e = 0;
177 FX_DWORD line = m_pToken->m_uLinenum; 169 FX_DWORD line = m_pToken->m_uLinenum;
178 switch (m_pToken->m_type) { 170 switch (m_pToken->m_type) {
179 case TOKvar: 171 case TOKvar:
180 e = ParseVarExpression(); 172 e = ParseVarExpression();
181 break; 173 break;
182 case TOKnull: 174 case TOKnull:
183 case TOKnumber: 175 case TOKnumber:
184 case TOKstring: 176 case TOKstring:
(...skipping 29 matching lines...) Expand all
214 break; 206 break;
215 default: 207 default:
216 CFX_WideString ws_TempString = m_pToken->m_wstring; 208 CFX_WideString ws_TempString = m_pToken->m_wstring;
217 Error(m_pToken->m_uLinenum, FMERR_UNEXPECTED_EXPRESSION, 209 Error(m_pToken->m_uLinenum, FMERR_UNEXPECTED_EXPRESSION,
218 ws_TempString.c_str()); 210 ws_TempString.c_str());
219 NextToken(); 211 NextToken();
220 break; 212 break;
221 } 213 }
222 return e; 214 return e;
223 } 215 }
216
224 CXFA_FMExpression* CXFA_FMParse::ParseVarExpression() { 217 CXFA_FMExpression* CXFA_FMParse::ParseVarExpression() {
225 CXFA_FMExpression* e = 0; 218 CXFA_FMExpression* e = 0;
226 CFX_WideStringC ident; 219 CFX_WideStringC ident;
227 FX_DWORD line = m_pToken->m_uLinenum; 220 FX_DWORD line = m_pToken->m_uLinenum;
228 NextToken(); 221 NextToken();
229 if (m_pToken->m_type != TOKidentifier) { 222 if (m_pToken->m_type != TOKidentifier) {
230 CFX_WideString ws_TempString = m_pToken->m_wstring; 223 CFX_WideString ws_TempString = m_pToken->m_wstring;
231 Error(m_pToken->m_uLinenum, FMERR_EXPECTED_IDENTIFIER, 224 Error(m_pToken->m_uLinenum, FMERR_EXPECTED_IDENTIFIER,
232 ws_TempString.c_str()); 225 ws_TempString.c_str());
233 } else { 226 } else {
234 ident = m_pToken->m_wstring; 227 ident = m_pToken->m_wstring;
235 NextToken(); 228 NextToken();
236 } 229 }
237 if (m_pToken->m_type == TOKassign) { 230 if (m_pToken->m_type == TOKassign) {
238 NextToken(); 231 NextToken();
239 e = ParseExpExpression(); 232 e = ParseExpExpression();
240 } 233 }
241 if (m_pErrorInfo->message.IsEmpty()) { 234 if (m_pErrorInfo->message.IsEmpty()) {
242 e = new CXFA_FMVarExpression(line, ident, e); 235 e = new CXFA_FMVarExpression(line, ident, e);
243 } else { 236 } else {
244 delete e; 237 delete e;
245 e = 0; 238 e = 0;
246 } 239 }
247 return e; 240 return e;
248 } 241 }
242
249 CXFA_FMSimpleExpression* CXFA_FMParse::ParseSimpleExpression() { 243 CXFA_FMSimpleExpression* CXFA_FMParse::ParseSimpleExpression() {
250 FX_DWORD line = m_pToken->m_uLinenum; 244 FX_DWORD line = m_pToken->m_uLinenum;
251 CXFA_FMSimpleExpression *pExp1 = 0, *pExp2 = 0; 245 CXFA_FMSimpleExpression *pExp1 = 0, *pExp2 = 0;
252 pExp1 = ParseLogicalOrExpression(); 246 pExp1 = ParseLogicalOrExpression();
253 while (m_pToken->m_type == TOKassign) { 247 while (m_pToken->m_type == TOKassign) {
254 NextToken(); 248 NextToken();
255 pExp2 = ParseLogicalOrExpression(); 249 pExp2 = ParseLogicalOrExpression();
256 if (m_pErrorInfo->message.IsEmpty()) { 250 if (m_pErrorInfo->message.IsEmpty()) {
257 pExp1 = new CXFA_FMAssignExpression(line, TOKassign, pExp1, pExp2); 251 pExp1 = new CXFA_FMAssignExpression(line, TOKassign, pExp1, pExp2);
258 } else { 252 } else {
259 delete pExp1; 253 delete pExp1;
260 pExp1 = 0; 254 pExp1 = 0;
261 } 255 }
262 } 256 }
263 return pExp1; 257 return pExp1;
264 } 258 }
259
265 CXFA_FMExpression* CXFA_FMParse::ParseExpExpression() { 260 CXFA_FMExpression* CXFA_FMParse::ParseExpExpression() {
266 CXFA_FMExpression* e = 0; 261 CXFA_FMExpression* e = 0;
267 FX_DWORD line = m_pToken->m_uLinenum; 262 FX_DWORD line = m_pToken->m_uLinenum;
268 CXFA_FMSimpleExpression* pExp1 = 0; 263 CXFA_FMSimpleExpression* pExp1 = 0;
269 pExp1 = ParseSimpleExpression(); 264 pExp1 = ParseSimpleExpression();
270 if (m_pErrorInfo->message.IsEmpty()) { 265 if (m_pErrorInfo->message.IsEmpty()) {
271 e = new CXFA_FMExpExpression(line, pExp1); 266 e = new CXFA_FMExpExpression(line, pExp1);
272 } else { 267 } else {
273 delete pExp1; 268 delete pExp1;
274 e = 0; 269 e = 0;
275 } 270 }
276 return e; 271 return e;
277 } 272 }
273
278 CXFA_FMSimpleExpression* CXFA_FMParse::ParseLogicalOrExpression() { 274 CXFA_FMSimpleExpression* CXFA_FMParse::ParseLogicalOrExpression() {
279 CXFA_FMSimpleExpression *e1 = 0, *e2 = 0; 275 CXFA_FMSimpleExpression *e1 = 0, *e2 = 0;
280 FX_DWORD line = m_pToken->m_uLinenum; 276 FX_DWORD line = m_pToken->m_uLinenum;
281 e1 = ParseLogicalAndExpression(); 277 e1 = ParseLogicalAndExpression();
282 for (;;) { 278 for (;;) {
283 switch (m_pToken->m_type) { 279 switch (m_pToken->m_type) {
284 case TOKor: 280 case TOKor:
285 case TOKksor: 281 case TOKksor:
286 NextToken(); 282 NextToken();
287 e2 = ParseLogicalAndExpression(); 283 e2 = ParseLogicalAndExpression();
288 if (m_pErrorInfo->message.IsEmpty()) { 284 if (m_pErrorInfo->message.IsEmpty()) {
289 e1 = new CXFA_FMLogicalOrExpression(line, TOKor, e1, e2); 285 e1 = new CXFA_FMLogicalOrExpression(line, TOKor, e1, e2);
290 } else { 286 } else {
291 delete e1; 287 delete e1;
292 e1 = 0; 288 e1 = 0;
293 } 289 }
294 continue; 290 continue;
295 default: 291 default:
296 break; 292 break;
297 } 293 }
298 break; 294 break;
299 } 295 }
300 return e1; 296 return e1;
301 } 297 }
298
302 CXFA_FMSimpleExpression* CXFA_FMParse::ParseLogicalAndExpression() { 299 CXFA_FMSimpleExpression* CXFA_FMParse::ParseLogicalAndExpression() {
303 CXFA_FMSimpleExpression *e1 = 0, *e2 = 0; 300 CXFA_FMSimpleExpression *e1 = 0, *e2 = 0;
304 FX_DWORD line = m_pToken->m_uLinenum; 301 FX_DWORD line = m_pToken->m_uLinenum;
305 e1 = ParseEqualityExpression(); 302 e1 = ParseEqualityExpression();
306 for (;;) { 303 for (;;) {
307 switch (m_pToken->m_type) { 304 switch (m_pToken->m_type) {
308 case TOKand: 305 case TOKand:
309 case TOKksand: 306 case TOKksand:
310 NextToken(); 307 NextToken();
311 e2 = ParseEqualityExpression(); 308 e2 = ParseEqualityExpression();
312 if (m_pErrorInfo->message.IsEmpty()) { 309 if (m_pErrorInfo->message.IsEmpty()) {
313 e1 = new CXFA_FMLogicalAndExpression(line, TOKand, e1, e2); 310 e1 = new CXFA_FMLogicalAndExpression(line, TOKand, e1, e2);
314 } else { 311 } else {
315 delete e1; 312 delete e1;
316 e1 = 0; 313 e1 = 0;
317 } 314 }
318 continue; 315 continue;
319 default: 316 default:
320 break; 317 break;
321 } 318 }
322 break; 319 break;
323 } 320 }
324 return e1; 321 return e1;
325 } 322 }
323
326 CXFA_FMSimpleExpression* CXFA_FMParse::ParseEqualityExpression() { 324 CXFA_FMSimpleExpression* CXFA_FMParse::ParseEqualityExpression() {
327 CXFA_FMSimpleExpression *e1 = 0, *e2 = 0; 325 CXFA_FMSimpleExpression *e1 = 0, *e2 = 0;
328 FX_DWORD line = m_pToken->m_uLinenum; 326 FX_DWORD line = m_pToken->m_uLinenum;
329 e1 = ParseRelationalExpression(); 327 e1 = ParseRelationalExpression();
330 for (;;) { 328 for (;;) {
331 switch (m_pToken->m_type) { 329 switch (m_pToken->m_type) {
332 case TOKeq: 330 case TOKeq:
333 case TOKkseq: 331 case TOKkseq:
334 NextToken(); 332 NextToken();
335 e2 = ParseRelationalExpression(); 333 e2 = ParseRelationalExpression();
(...skipping 15 matching lines...) Expand all
351 e1 = 0; 349 e1 = 0;
352 } 350 }
353 continue; 351 continue;
354 default: 352 default:
355 break; 353 break;
356 } 354 }
357 break; 355 break;
358 } 356 }
359 return e1; 357 return e1;
360 } 358 }
359
361 CXFA_FMSimpleExpression* CXFA_FMParse::ParseRelationalExpression() { 360 CXFA_FMSimpleExpression* CXFA_FMParse::ParseRelationalExpression() {
362 CXFA_FMSimpleExpression *e1 = 0, *e2 = 0; 361 CXFA_FMSimpleExpression *e1 = 0, *e2 = 0;
363 FX_DWORD line = m_pToken->m_uLinenum; 362 FX_DWORD line = m_pToken->m_uLinenum;
364 e1 = ParseAddtiveExpression(); 363 e1 = ParseAddtiveExpression();
365 for (;;) { 364 for (;;) {
366 switch (m_pToken->m_type) { 365 switch (m_pToken->m_type) {
367 case TOKlt: 366 case TOKlt:
368 case TOKkslt: 367 case TOKkslt:
369 NextToken(); 368 NextToken();
370 e2 = ParseAddtiveExpression(); 369 e2 = ParseAddtiveExpression();
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
408 e1 = 0; 407 e1 = 0;
409 } 408 }
410 continue; 409 continue;
411 default: 410 default:
412 break; 411 break;
413 } 412 }
414 break; 413 break;
415 } 414 }
416 return e1; 415 return e1;
417 } 416 }
417
418 CXFA_FMSimpleExpression* CXFA_FMParse::ParseAddtiveExpression() { 418 CXFA_FMSimpleExpression* CXFA_FMParse::ParseAddtiveExpression() {
419 CXFA_FMSimpleExpression *e1 = 0, *e2 = 0; 419 CXFA_FMSimpleExpression *e1 = 0, *e2 = 0;
420 FX_DWORD line = m_pToken->m_uLinenum; 420 FX_DWORD line = m_pToken->m_uLinenum;
421 e1 = ParseMultiplicativeExpression(); 421 e1 = ParseMultiplicativeExpression();
422 for (;;) { 422 for (;;) {
423 switch (m_pToken->m_type) { 423 switch (m_pToken->m_type) {
424 case TOKplus: 424 case TOKplus:
425 NextToken(); 425 NextToken();
426 e2 = ParseMultiplicativeExpression(); 426 e2 = ParseMultiplicativeExpression();
427 if (m_pErrorInfo->message.IsEmpty()) { 427 if (m_pErrorInfo->message.IsEmpty()) {
(...skipping 13 matching lines...) Expand all
441 e1 = 0; 441 e1 = 0;
442 } 442 }
443 continue; 443 continue;
444 default: 444 default:
445 break; 445 break;
446 } 446 }
447 break; 447 break;
448 } 448 }
449 return e1; 449 return e1;
450 } 450 }
451
451 CXFA_FMSimpleExpression* CXFA_FMParse::ParseMultiplicativeExpression() { 452 CXFA_FMSimpleExpression* CXFA_FMParse::ParseMultiplicativeExpression() {
452 CXFA_FMSimpleExpression *e1 = 0, *e2 = 0; 453 CXFA_FMSimpleExpression *e1 = 0, *e2 = 0;
453 FX_DWORD line = m_pToken->m_uLinenum; 454 FX_DWORD line = m_pToken->m_uLinenum;
454 e1 = ParseUnaryExpression(); 455 e1 = ParseUnaryExpression();
455 for (;;) { 456 for (;;) {
456 switch (m_pToken->m_type) { 457 switch (m_pToken->m_type) {
457 case TOKmul: 458 case TOKmul:
458 NextToken(); 459 NextToken();
459 e2 = ParseUnaryExpression(); 460 e2 = ParseUnaryExpression();
460 if (m_pErrorInfo->message.IsEmpty()) { 461 if (m_pErrorInfo->message.IsEmpty()) {
(...skipping 13 matching lines...) Expand all
474 e1 = 0; 475 e1 = 0;
475 } 476 }
476 continue; 477 continue;
477 default: 478 default:
478 break; 479 break;
479 } 480 }
480 break; 481 break;
481 } 482 }
482 return e1; 483 return e1;
483 } 484 }
485
484 CXFA_FMSimpleExpression* CXFA_FMParse::ParseUnaryExpression() { 486 CXFA_FMSimpleExpression* CXFA_FMParse::ParseUnaryExpression() {
485 CXFA_FMSimpleExpression* e = 0; 487 CXFA_FMSimpleExpression* e = 0;
486 FX_DWORD line = m_pToken->m_uLinenum; 488 FX_DWORD line = m_pToken->m_uLinenum;
487 switch (m_pToken->m_type) { 489 switch (m_pToken->m_type) {
488 case TOKplus: 490 case TOKplus:
489 NextToken(); 491 NextToken();
490 e = ParseUnaryExpression(); 492 e = ParseUnaryExpression();
491 if (m_pErrorInfo->message.IsEmpty()) { 493 if (m_pErrorInfo->message.IsEmpty()) {
492 e = new CXFA_FMPosExpression(line, e); 494 e = new CXFA_FMPosExpression(line, e);
493 } else { 495 } else {
(...skipping 17 matching lines...) Expand all
511 } else { 513 } else {
512 e = 0; 514 e = 0;
513 } 515 }
514 break; 516 break;
515 default: 517 default:
516 e = ParsePrimaryExpression(); 518 e = ParsePrimaryExpression();
517 break; 519 break;
518 } 520 }
519 return e; 521 return e;
520 } 522 }
523
521 CXFA_FMSimpleExpression* CXFA_FMParse::ParsePrimaryExpression() { 524 CXFA_FMSimpleExpression* CXFA_FMParse::ParsePrimaryExpression() {
522 CXFA_FMSimpleExpression* e = 0; 525 CXFA_FMSimpleExpression* e = 0;
523 FX_DWORD line = m_pToken->m_uLinenum; 526 FX_DWORD line = m_pToken->m_uLinenum;
524 switch (m_pToken->m_type) { 527 switch (m_pToken->m_type) {
525 case TOKnumber: 528 case TOKnumber:
526 e = new CXFA_FMNumberExpression(line, m_pToken->m_wstring); 529 e = new CXFA_FMNumberExpression(line, m_pToken->m_wstring);
527 NextToken(); 530 NextToken();
528 break; 531 break;
529 case TOKstring: 532 case TOKstring:
530 e = new CXFA_FMStringExpression(line, m_pToken->m_wstring); 533 e = new CXFA_FMStringExpression(line, m_pToken->m_wstring);
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
562 NextToken(); 565 NextToken();
563 break; 566 break;
564 } 567 }
565 e = ParsePostExpression(e); 568 e = ParsePostExpression(e);
566 if (!(m_pErrorInfo->message.IsEmpty())) { 569 if (!(m_pErrorInfo->message.IsEmpty())) {
567 delete e; 570 delete e;
568 e = 0; 571 e = 0;
569 } 572 }
570 return e; 573 return e;
571 } 574 }
575
572 CXFA_FMSimpleExpression* CXFA_FMParse::ParsePostExpression( 576 CXFA_FMSimpleExpression* CXFA_FMParse::ParsePostExpression(
573 CXFA_FMSimpleExpression* e) { 577 CXFA_FMSimpleExpression* e) {
574 FX_DWORD line = m_pToken->m_uLinenum; 578 FX_DWORD line = m_pToken->m_uLinenum;
575 while (1) { 579 while (1) {
576 switch (m_pToken->m_type) { 580 switch (m_pToken->m_type) {
577 case TOKlparen: { 581 case TOKlparen: {
578 NextToken(); 582 NextToken();
579 CFX_PtrArray* pArray = 0; 583 CFX_PtrArray* pArray = 0;
580 if (m_pToken->m_type != TOKrparen) { 584 if (m_pToken->m_type != TOKrparen) {
581 pArray = new CFX_PtrArray(); 585 pArray = new CFX_PtrArray();
582 while (m_pToken->m_type != TOKrparen) { 586 while (m_pToken->m_type != TOKrparen) {
583 CXFA_FMSimpleExpression* e = ParseSimpleExpression(); 587 CXFA_FMSimpleExpression* e = ParseSimpleExpression();
584 if (e) { 588 if (e) {
585 pArray->Add(e); 589 pArray->Add(e);
586 } 590 }
587 if (m_pToken->m_type == TOKcomma) { 591 if (m_pToken->m_type == TOKcomma) {
588 NextToken(); 592 NextToken();
589 } else if (m_pToken->m_type == TOKeof) { 593 } else if (m_pToken->m_type == TOKeof ||
594 m_pToken->m_type == TOKreserver) {
590 break; 595 break;
591 } 596 }
592 } 597 }
593 if (m_pToken->m_type != TOKrparen) { 598 if (m_pToken->m_type != TOKrparen) {
594 CFX_WideString ws_TempString = m_pToken->m_wstring; 599 CFX_WideString ws_TempString = m_pToken->m_wstring;
595 Error(m_pToken->m_uLinenum, FMERR_EXPECTED_TOKEN, 600 Error(m_pToken->m_uLinenum, FMERR_EXPECTED_TOKEN,
596 XFA_FM_KeywordToString(TOKrparen), ws_TempString.c_str()); 601 XFA_FM_KeywordToString(TOKrparen), ws_TempString.c_str());
597 } 602 }
598 } 603 }
599 if (m_pErrorInfo->message.IsEmpty()) { 604 if (m_pErrorInfo->message.IsEmpty()) {
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
634 pExpAccessor = e; 639 pExpAccessor = e;
635 NextToken(); 640 NextToken();
636 CFX_PtrArray* pArray = 0; 641 CFX_PtrArray* pArray = 0;
637 if (m_pToken->m_type != TOKrparen) { 642 if (m_pToken->m_type != TOKrparen) {
638 pArray = new CFX_PtrArray(); 643 pArray = new CFX_PtrArray();
639 while (m_pToken->m_type != TOKrparen) { 644 while (m_pToken->m_type != TOKrparen) {
640 CXFA_FMSimpleExpression* exp = ParseSimpleExpression(); 645 CXFA_FMSimpleExpression* exp = ParseSimpleExpression();
641 pArray->Add(exp); 646 pArray->Add(exp);
642 if (m_pToken->m_type == TOKcomma) { 647 if (m_pToken->m_type == TOKcomma) {
643 NextToken(); 648 NextToken();
644 } else if (m_pToken->m_type == TOKeof) { 649 } else if (m_pToken->m_type == TOKeof ||
650 m_pToken->m_type == TOKreserver) {
645 break; 651 break;
646 } 652 }
647 } 653 }
648 if (m_pToken->m_type != TOKrparen) { 654 if (m_pToken->m_type != TOKrparen) {
649 CFX_WideString ws_TempString = m_pToken->m_wstring; 655 CFX_WideString ws_TempString = m_pToken->m_wstring;
650 Error(m_pToken->m_uLinenum, FMERR_EXPECTED_TOKEN, 656 Error(m_pToken->m_uLinenum, FMERR_EXPECTED_TOKEN,
651 XFA_FM_KeywordToString(TOKrparen), ws_TempString.c_str()); 657 XFA_FM_KeywordToString(TOKrparen), ws_TempString.c_str());
652 } 658 }
653 } 659 }
654 if (m_pErrorInfo->message.IsEmpty()) { 660 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, 790 e = new CXFA_FMDotAccessorExpression(line, e, TOKdotstar,
785 FX_WSTRC(L"*"), s); 791 FX_WSTRC(L"*"), s);
786 } break; 792 } break;
787 default: 793 default:
788 return e; 794 return e;
789 } 795 }
790 NextToken(); 796 NextToken();
791 } 797 }
792 return e; 798 return e;
793 } 799 }
800
794 CXFA_FMSimpleExpression* CXFA_FMParse::ParseIndexExpression() { 801 CXFA_FMSimpleExpression* CXFA_FMParse::ParseIndexExpression() {
795 CXFA_FMSimpleExpression* pExp = 0; 802 CXFA_FMSimpleExpression* pExp = 0;
796 FX_DWORD line = m_pToken->m_uLinenum; 803 FX_DWORD line = m_pToken->m_uLinenum;
797 NextToken(); 804 NextToken();
798 CXFA_FMSimpleExpression* s = 0; 805 CXFA_FMSimpleExpression* s = 0;
799 XFA_FM_AccessorIndex accessorIndex = ACCESSOR_NO_RELATIVEINDEX; 806 XFA_FM_AccessorIndex accessorIndex = ACCESSOR_NO_RELATIVEINDEX;
800 if (m_pToken->m_type == TOKmul) { 807 if (m_pToken->m_type == TOKmul) {
801 pExp = new CXFA_FMIndexExpression(line, accessorIndex, s, TRUE); 808 pExp = new CXFA_FMIndexExpression(line, accessorIndex, s, TRUE);
802 NextToken(); 809 NextToken();
803 if (m_pToken->m_type != TOKrbracket) { 810 if (m_pToken->m_type != TOKrbracket) {
(...skipping 20 matching lines...) Expand all
824 Error(m_pToken->m_uLinenum, FMERR_EXPECTED_TOKEN, 831 Error(m_pToken->m_uLinenum, FMERR_EXPECTED_TOKEN,
825 XFA_FM_KeywordToString(TOKrparen), ws_TempString.c_str()); 832 XFA_FM_KeywordToString(TOKrparen), ws_TempString.c_str());
826 if (s) { 833 if (s) {
827 delete s; 834 delete s;
828 } 835 }
829 } else { 836 } else {
830 pExp = new CXFA_FMIndexExpression(line, accessorIndex, s, FALSE); 837 pExp = new CXFA_FMIndexExpression(line, accessorIndex, s, FALSE);
831 } 838 }
832 return pExp; 839 return pExp;
833 } 840 }
841
834 CXFA_FMSimpleExpression* CXFA_FMParse::ParseParenExpression() { 842 CXFA_FMSimpleExpression* CXFA_FMParse::ParseParenExpression() {
835 CXFA_FMSimpleExpression *pExp1 = 0, *pExp2 = 0; 843 CXFA_FMSimpleExpression *pExp1 = 0, *pExp2 = 0;
836 FX_DWORD line = m_pToken->m_uLinenum; 844 FX_DWORD line = m_pToken->m_uLinenum;
837 Check(TOKlparen); 845 Check(TOKlparen);
838 if (m_pToken->m_type != TOKrparen) { 846 if (m_pToken->m_type != TOKrparen) {
839 pExp1 = ParseLogicalOrExpression(); 847 pExp1 = ParseLogicalOrExpression();
840 while (m_pToken->m_type == TOKassign) { 848 while (m_pToken->m_type == TOKassign) {
841 NextToken(); 849 NextToken();
842 pExp2 = ParseLogicalOrExpression(); 850 pExp2 = ParseLogicalOrExpression();
843 if (m_pErrorInfo->message.IsEmpty()) { 851 if (m_pErrorInfo->message.IsEmpty()) {
844 pExp1 = new CXFA_FMAssignExpression(line, TOKassign, pExp1, pExp2); 852 pExp1 = new CXFA_FMAssignExpression(line, TOKassign, pExp1, pExp2);
845 } else { 853 } else {
846 delete pExp1; 854 delete pExp1;
847 pExp1 = 0; 855 pExp1 = 0;
848 } 856 }
849 } 857 }
850 Check(TOKrparen); 858 Check(TOKrparen);
851 } else { 859 } else {
852 NextToken(); 860 NextToken();
853 } 861 }
854 return pExp1; 862 return pExp1;
855 } 863 }
864
856 CXFA_FMExpression* CXFA_FMParse::ParseBlockExpression() { 865 CXFA_FMExpression* CXFA_FMParse::ParseBlockExpression() {
857 FX_DWORD line = m_pToken->m_uLinenum; 866 FX_DWORD line = m_pToken->m_uLinenum;
858 CXFA_FMExpression* e = 0; 867 CXFA_FMExpression* e = 0;
859 CFX_PtrArray* expression = new CFX_PtrArray(); 868 CFX_PtrArray* expression = new CFX_PtrArray();
860 while (1) { 869 while (1) {
861 switch (m_pToken->m_type) { 870 switch (m_pToken->m_type) {
862 case TOKeof: 871 case TOKeof:
863 case TOKendif: 872 case TOKendif:
864 case TOKelseif: 873 case TOKelseif:
865 case TOKelse: 874 case TOKelse:
866 case TOKendwhile: 875 case TOKendwhile:
867 case TOKendfor: 876 case TOKendfor:
868 case TOKend: 877 case TOKend:
869 case TOKendfunc: 878 case TOKendfunc:
879 case TOKreserver:
870 break; 880 break;
871 case TOKfunc: 881 case TOKfunc:
872 e = ParseFunction(); 882 e = ParseFunction();
873 if (e) { 883 if (e) {
874 expression->Add(e); 884 expression->Add(e);
875 } 885 }
876 continue; 886 continue;
877 default: 887 default:
878 e = ParseExpression(); 888 e = ParseExpression();
879 if (e) { 889 if (e) {
(...skipping 13 matching lines...) Expand all
893 e = (CXFA_FMExpression*)expression->GetAt(index); 903 e = (CXFA_FMExpression*)expression->GetAt(index);
894 delete e; 904 delete e;
895 index++; 905 index++;
896 } 906 }
897 expression->RemoveAll(); 907 expression->RemoveAll();
898 delete expression; 908 delete expression;
899 expression = 0; 909 expression = 0;
900 } 910 }
901 return pExp; 911 return pExp;
902 } 912 }
913
903 CXFA_FMExpression* CXFA_FMParse::ParseIfExpression() { 914 CXFA_FMExpression* CXFA_FMParse::ParseIfExpression() {
904 CXFA_FMSimpleExpression* pExpression = 0; 915 CXFA_FMSimpleExpression* pExpression = 0;
905 CXFA_FMExpression* pIfExpression = 0; 916 CXFA_FMExpression* pIfExpression = 0;
906 CXFA_FMExpression* pElseExpression = 0; 917 CXFA_FMExpression* pElseExpression = 0;
907 FX_DWORD line = m_pToken->m_uLinenum; 918 FX_DWORD line = m_pToken->m_uLinenum;
908 const FX_WCHAR* pStartPos = m_lexer->SavePos(); 919 const FX_WCHAR* pStartPos = m_lexer->SavePos();
909 NextToken(); 920 NextToken();
910 Check(TOKlparen); 921 Check(TOKlparen);
911 while (m_pToken->m_type != TOKrparen) { 922 while (m_pToken->m_type != TOKrparen) {
912 if (pExpression) { 923 if (pExpression) {
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
967 } 978 }
968 if (pIfExpression) { 979 if (pIfExpression) {
969 delete pIfExpression; 980 delete pIfExpression;
970 } 981 }
971 if (pElseExpression) { 982 if (pElseExpression) {
972 delete pElseExpression; 983 delete pElseExpression;
973 } 984 }
974 } 985 }
975 return pExp; 986 return pExp;
976 } 987 }
988
977 CXFA_FMExpression* CXFA_FMParse::ParseWhileExpression() { 989 CXFA_FMExpression* CXFA_FMParse::ParseWhileExpression() {
978 CXFA_FMExpression* e = 0; 990 CXFA_FMExpression* e = 0;
979 CXFA_FMSimpleExpression* pCondition = 0; 991 CXFA_FMSimpleExpression* pCondition = 0;
980 CXFA_FMExpression* pExpression = 0; 992 CXFA_FMExpression* pExpression = 0;
981 FX_DWORD line = m_pToken->m_uLinenum; 993 FX_DWORD line = m_pToken->m_uLinenum;
982 NextToken(); 994 NextToken();
983 pCondition = ParseParenExpression(); 995 pCondition = ParseParenExpression();
984 Check(TOKdo); 996 Check(TOKdo);
985 pExpression = ParseBlockExpression(); 997 pExpression = ParseBlockExpression();
986 Check(TOKendwhile); 998 Check(TOKendwhile);
987 if (!m_pErrorInfo->message.IsEmpty()) { 999 if (!m_pErrorInfo->message.IsEmpty()) {
988 if (pCondition) { 1000 if (pCondition) {
989 delete pCondition; 1001 delete pCondition;
990 } 1002 }
991 if (pExpression) { 1003 if (pExpression) {
992 delete pExpression; 1004 delete pExpression;
993 } 1005 }
994 delete e; 1006 delete e;
995 e = 0; 1007 e = 0;
996 } else { 1008 } else {
997 e = new CXFA_FMWhileExpression(line, pCondition, pExpression); 1009 e = new CXFA_FMWhileExpression(line, pCondition, pExpression);
998 } 1010 }
999 return e; 1011 return e;
1000 } 1012 }
1013
1001 CXFA_FMSimpleExpression* CXFA_FMParse::ParseSubassignmentInForExpression() { 1014 CXFA_FMSimpleExpression* CXFA_FMParse::ParseSubassignmentInForExpression() {
1002 CXFA_FMSimpleExpression* e = 0; 1015 CXFA_FMSimpleExpression* e = 0;
1003 switch (m_pToken->m_type) { 1016 switch (m_pToken->m_type) {
1004 case TOKidentifier: 1017 case TOKidentifier:
1005 e = ParseSimpleExpression(); 1018 e = ParseSimpleExpression();
1006 break; 1019 break;
1007 default: 1020 default:
1008 CFX_WideString ws_TempString = m_pToken->m_wstring; 1021 CFX_WideString ws_TempString = m_pToken->m_wstring;
1009 Error(m_pToken->m_uLinenum, FMERR_UNEXPECTED_EXPRESSION, 1022 Error(m_pToken->m_uLinenum, FMERR_UNEXPECTED_EXPRESSION,
1010 ws_TempString.c_str()); 1023 ws_TempString.c_str());
1011 NextToken(); 1024 NextToken();
1012 break; 1025 break;
1013 } 1026 }
1014 return e; 1027 return e;
1015 } 1028 }
1029
1016 CXFA_FMExpression* CXFA_FMParse::ParseForExpression() { 1030 CXFA_FMExpression* CXFA_FMParse::ParseForExpression() {
1017 CXFA_FMExpression* e = 0; 1031 CXFA_FMExpression* e = 0;
1018 CFX_WideStringC wsVariant; 1032 CFX_WideStringC wsVariant;
1019 CXFA_FMSimpleExpression* pAssignment = 0; 1033 CXFA_FMSimpleExpression* pAssignment = 0;
1020 CXFA_FMSimpleExpression* pAccessor = 0; 1034 CXFA_FMSimpleExpression* pAccessor = 0;
1021 CXFA_FMSimpleExpression* pStep = 0; 1035 CXFA_FMSimpleExpression* pStep = 0;
1022 CXFA_FMExpression* pList = 0; 1036 CXFA_FMExpression* pList = 0;
1023 FX_DWORD line = m_pToken->m_uLinenum; 1037 FX_DWORD line = m_pToken->m_uLinenum;
1024 NextToken(); 1038 NextToken();
1025 if (m_pToken->m_type != TOKidentifier) { 1039 if (m_pToken->m_type != TOKidentifier) {
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
1068 } 1082 }
1069 if (pStep) { 1083 if (pStep) {
1070 delete pStep; 1084 delete pStep;
1071 } 1085 }
1072 if (pList) { 1086 if (pList) {
1073 delete pList; 1087 delete pList;
1074 } 1088 }
1075 } 1089 }
1076 return e; 1090 return e;
1077 } 1091 }
1092
1078 CXFA_FMExpression* CXFA_FMParse::ParseForeachExpression() { 1093 CXFA_FMExpression* CXFA_FMParse::ParseForeachExpression() {
1079 CXFA_FMExpression* e = 0; 1094 CXFA_FMExpression* e = 0;
1080 CFX_WideStringC wsIdentifier; 1095 CFX_WideStringC wsIdentifier;
1081 CFX_PtrArray* pAccessors = 0; 1096 CFX_PtrArray* pAccessors = 0;
1082 CXFA_FMExpression* pList = 0; 1097 CXFA_FMExpression* pList = 0;
1083 FX_DWORD line = m_pToken->m_uLinenum; 1098 FX_DWORD line = m_pToken->m_uLinenum;
1084 NextToken(); 1099 NextToken();
1085 if (m_pToken->m_type != TOKidentifier) { 1100 if (m_pToken->m_type != TOKidentifier) {
1086 CFX_WideString ws_TempString = m_pToken->m_wstring; 1101 CFX_WideString ws_TempString = m_pToken->m_wstring;
1087 Error(m_pToken->m_uLinenum, FMERR_EXPECTED_TOKEN, 1102 Error(m_pToken->m_uLinenum, FMERR_EXPECTED_TOKEN,
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
1129 pAccessors->RemoveAll(); 1144 pAccessors->RemoveAll();
1130 delete pAccessors; 1145 delete pAccessors;
1131 pAccessors = 0; 1146 pAccessors = 0;
1132 } 1147 }
1133 if (pList) { 1148 if (pList) {
1134 delete pList; 1149 delete pList;
1135 } 1150 }
1136 } 1151 }
1137 return e; 1152 return e;
1138 } 1153 }
1154
1139 CXFA_FMExpression* CXFA_FMParse::ParseDoExpression() { 1155 CXFA_FMExpression* CXFA_FMParse::ParseDoExpression() {
1140 CXFA_FMExpression* e = 0; 1156 CXFA_FMExpression* e = 0;
1141 FX_DWORD line = m_pToken->m_uLinenum; 1157 FX_DWORD line = m_pToken->m_uLinenum;
1142 NextToken(); 1158 NextToken();
1143 e = ParseBlockExpression(); 1159 e = ParseBlockExpression();
1144 Check(TOKend); 1160 Check(TOKend);
1145 if (m_pErrorInfo->message.IsEmpty()) { 1161 if (m_pErrorInfo->message.IsEmpty()) {
1146 e = new CXFA_FMDoExpression(line, e); 1162 e = new CXFA_FMDoExpression(line, e);
1147 } else { 1163 } else {
1148 delete e; 1164 delete e;
1149 e = 0; 1165 e = 0;
1150 } 1166 }
1151 return e; 1167 return e;
1152 } 1168 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698