| OLD | NEW |
| 1 // Copyright 2014 PDFium Authors. All rights reserved. | 1 // Copyright 2014 PDFium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com | 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com |
| 6 | 6 |
| 7 #include "xfa/fxfa/fm2js/xfa_fmparse.h" | 7 #include "xfa/fxfa/fm2js/xfa_fmparse.h" |
| 8 | 8 |
| 9 #include <memory> | 9 #include <memory> |
| 10 #include <utility> | 10 #include <utility> |
| 11 #include <vector> | 11 #include <vector> |
| 12 | 12 |
| 13 #include "third_party/base/ptr_util.h" | 13 #include "third_party/base/ptr_util.h" |
| 14 | 14 |
| 15 CXFA_FMParse::CXFA_FMParse() : m_pToken(nullptr), m_pErrorInfo(0) {} | 15 CXFA_FMParse::CXFA_FMParse() : m_pToken(nullptr), m_pErrorInfo(0) {} |
| 16 | 16 |
| 17 CXFA_FMParse::~CXFA_FMParse() {} | 17 CXFA_FMParse::~CXFA_FMParse() {} |
| 18 | 18 |
| 19 int32_t CXFA_FMParse::Init(const CFX_WideStringC& wsFormcalc, | 19 int32_t CXFA_FMParse::Init(const CFX_WideStringC& wsFormcalc, |
| 20 CXFA_FMErrorInfo* pErrorInfo) { | 20 CXFA_FMErrorInfo* pErrorInfo) { |
| 21 m_pErrorInfo = pErrorInfo; | 21 m_pErrorInfo = pErrorInfo; |
| 22 m_lexer.reset(new CXFA_FMLexer(wsFormcalc, m_pErrorInfo)); | 22 m_lexer = pdfium::MakeUnique<CXFA_FMLexer>(wsFormcalc, m_pErrorInfo); |
| 23 return 0; | 23 return 0; |
| 24 } | 24 } |
| 25 | 25 |
| 26 void CXFA_FMParse::NextToken() { | 26 void CXFA_FMParse::NextToken() { |
| 27 m_pToken = m_lexer->NextToken(); | 27 m_pToken = m_lexer->NextToken(); |
| 28 while (m_pToken->m_type == TOKreserver) { | 28 while (m_pToken->m_type == TOKreserver) { |
| 29 if (m_lexer->HasError()) { | 29 if (m_lexer->HasError()) { |
| 30 break; | 30 break; |
| 31 } | 31 } |
| 32 m_pToken = m_lexer->NextToken(); | 32 m_pToken = m_lexer->NextToken(); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 43 } | 43 } |
| 44 | 44 |
| 45 void CXFA_FMParse::Error(uint32_t lineNum, const FX_WCHAR* msg, ...) { | 45 void CXFA_FMParse::Error(uint32_t lineNum, const FX_WCHAR* msg, ...) { |
| 46 m_pErrorInfo->linenum = lineNum; | 46 m_pErrorInfo->linenum = lineNum; |
| 47 va_list ap; | 47 va_list ap; |
| 48 va_start(ap, msg); | 48 va_start(ap, msg); |
| 49 m_pErrorInfo->message.FormatV(msg, ap); | 49 m_pErrorInfo->message.FormatV(msg, ap); |
| 50 va_end(ap); | 50 va_end(ap); |
| 51 } | 51 } |
| 52 | 52 |
| 53 CFX_ArrayTemplate<CXFA_FMExpression*>* CXFA_FMParse::ParseTopExpression() { | 53 std::vector<std::unique_ptr<CXFA_FMExpression>> |
| 54 std::unique_ptr<CXFA_FMExpression> e; | 54 CXFA_FMParse::ParseTopExpression() { |
| 55 CFX_ArrayTemplate<CXFA_FMExpression*>* expression = | 55 std::unique_ptr<CXFA_FMExpression> expr; |
| 56 new CFX_ArrayTemplate<CXFA_FMExpression*>(); | 56 std::vector<std::unique_ptr<CXFA_FMExpression>> expressions; |
| 57 while (1) { | 57 while (1) { |
| 58 if (m_pToken->m_type == TOKeof || m_pToken->m_type == TOKendfunc || | 58 if (m_pToken->m_type == TOKeof || m_pToken->m_type == TOKendfunc || |
| 59 m_pToken->m_type == TOKendif || m_pToken->m_type == TOKelseif || | 59 m_pToken->m_type == TOKendif || m_pToken->m_type == TOKelseif || |
| 60 m_pToken->m_type == TOKelse || m_pToken->m_type == TOKreserver) { | 60 m_pToken->m_type == TOKelse || m_pToken->m_type == TOKreserver) { |
| 61 return expression; | 61 return expressions; |
| 62 } | 62 } |
| 63 | 63 |
| 64 if (m_pToken->m_type == TOKfunc) { | 64 if (m_pToken->m_type == TOKfunc) { |
| 65 e.reset(ParseFunction()); | 65 expr = ParseFunction(); |
| 66 if (e) { | 66 if (expr) { |
| 67 expression->Add(e.release()); | 67 expressions.push_back(std::move(expr)); |
| 68 } else { | 68 } else { |
| 69 break; | 69 break; |
| 70 } | 70 } |
| 71 } else { | 71 } else { |
| 72 e.reset(ParseExpression()); | 72 expr = ParseExpression(); |
| 73 if (e) { | 73 if (expr) { |
| 74 expression->Add(e.release()); | 74 expressions.push_back(std::move(expr)); |
| 75 } else { | 75 } else { |
| 76 break; | 76 break; |
| 77 } | 77 } |
| 78 } | 78 } |
| 79 } | 79 } |
| 80 return expression; | 80 return expressions; |
| 81 } | 81 } |
| 82 | 82 |
| 83 CXFA_FMExpression* CXFA_FMParse::ParseFunction() { | 83 std::unique_ptr<CXFA_FMExpression> CXFA_FMParse::ParseFunction() { |
| 84 std::unique_ptr<CXFA_FMExpression> e; | 84 std::unique_ptr<CXFA_FMExpression> expr; |
| 85 CFX_WideStringC ident; | 85 CFX_WideStringC ident; |
| 86 std::unique_ptr<CFX_WideStringCArray> pArguments; | 86 std::unique_ptr<CFX_WideStringCArray> pArguments; |
| 87 std::unique_ptr<CFX_ArrayTemplate<CXFA_FMExpression*>> pExpressions; | 87 std::vector<std::unique_ptr<CXFA_FMExpression>> expressions; |
| 88 uint32_t line = m_pToken->m_uLinenum; | 88 uint32_t line = m_pToken->m_uLinenum; |
| 89 NextToken(); | 89 NextToken(); |
| 90 if (m_pToken->m_type != TOKidentifier) { | 90 if (m_pToken->m_type != TOKidentifier) { |
| 91 CFX_WideString ws_TempString(m_pToken->m_wstring); | 91 CFX_WideString ws_TempString(m_pToken->m_wstring); |
| 92 Error(m_pToken->m_uLinenum, kFMErrExpectedIdentifier, | 92 Error(m_pToken->m_uLinenum, kFMErrExpectedIdentifier, |
| 93 ws_TempString.c_str()); | 93 ws_TempString.c_str()); |
| 94 } else { | 94 } else { |
| 95 ident = m_pToken->m_wstring; | 95 ident = m_pToken->m_wstring; |
| 96 NextToken(); | 96 NextToken(); |
| 97 } | 97 } |
| 98 Check(TOKlparen); | 98 Check(TOKlparen); |
| 99 if (m_pToken->m_type == TOKrparen) { | 99 if (m_pToken->m_type == TOKrparen) { |
| 100 NextToken(); | 100 NextToken(); |
| 101 } else { | 101 } else { |
| 102 pArguments.reset(new CFX_WideStringCArray()); | 102 pArguments = pdfium::MakeUnique<CFX_WideStringCArray>(); |
| 103 CFX_WideStringC p; | 103 CFX_WideStringC p; |
| 104 while (1) { | 104 while (1) { |
| 105 if (m_pToken->m_type == TOKidentifier) { | 105 if (m_pToken->m_type == TOKidentifier) { |
| 106 p = m_pToken->m_wstring; | 106 p = m_pToken->m_wstring; |
| 107 pArguments->Add(p); | 107 pArguments->Add(p); |
| 108 NextToken(); | 108 NextToken(); |
| 109 if (m_pToken->m_type == TOKcomma) { | 109 if (m_pToken->m_type == TOKcomma) { |
| 110 NextToken(); | 110 NextToken(); |
| 111 continue; | 111 continue; |
| 112 } else if (m_pToken->m_type == TOKrparen) { | 112 } else if (m_pToken->m_type == TOKrparen) { |
| 113 NextToken(); | 113 NextToken(); |
| 114 break; | 114 break; |
| 115 } else { | 115 } else { |
| 116 Check(TOKrparen); | 116 Check(TOKrparen); |
| 117 break; | 117 break; |
| 118 } | 118 } |
| 119 } else { | 119 } else { |
| 120 CFX_WideString ws_TempString(m_pToken->m_wstring); | 120 CFX_WideString ws_TempString(m_pToken->m_wstring); |
| 121 Error(m_pToken->m_uLinenum, kFMErrExpectedIdentifier, | 121 Error(m_pToken->m_uLinenum, kFMErrExpectedIdentifier, |
| 122 ws_TempString.c_str()); | 122 ws_TempString.c_str()); |
| 123 NextToken(); | 123 NextToken(); |
| 124 break; | 124 break; |
| 125 } | 125 } |
| 126 } | 126 } |
| 127 } | 127 } |
| 128 Check(TOKdo); | 128 Check(TOKdo); |
| 129 if (m_pToken->m_type == TOKendfunc) { | 129 if (m_pToken->m_type == TOKendfunc) { |
| 130 NextToken(); | 130 NextToken(); |
| 131 } else { | 131 } else { |
| 132 pExpressions.reset(ParseTopExpression()); | 132 expressions = ParseTopExpression(); |
| 133 Check(TOKendfunc); | 133 Check(TOKendfunc); |
| 134 } | 134 } |
| 135 if (m_pErrorInfo->message.IsEmpty()) { | 135 if (m_pErrorInfo->message.IsEmpty()) { |
| 136 e.reset(new CXFA_FMFunctionDefinition(line, 0, ident, std::move(pArguments), | 136 expr = pdfium::MakeUnique<CXFA_FMFunctionDefinition>( |
| 137 pExpressions.release())); | 137 line, false, ident, std::move(pArguments), std::move(expressions)); |
| 138 } else { | 138 } else if (pArguments) { |
| 139 if (pArguments) | 139 pArguments->RemoveAll(); |
| 140 pArguments->RemoveAll(); | |
| 141 if (pExpressions) { | |
| 142 for (int i = 0; i < pExpressions->GetSize(); ++i) | |
| 143 delete pExpressions->GetAt(i); | |
| 144 } | |
| 145 } | 140 } |
| 146 return e.release(); | 141 return expr; |
| 147 } | 142 } |
| 148 | 143 |
| 149 CXFA_FMExpression* CXFA_FMParse::ParseExpression() { | 144 std::unique_ptr<CXFA_FMExpression> CXFA_FMParse::ParseExpression() { |
| 150 std::unique_ptr<CXFA_FMExpression> e; | 145 std::unique_ptr<CXFA_FMExpression> expr; |
| 151 uint32_t line = m_pToken->m_uLinenum; | 146 uint32_t line = m_pToken->m_uLinenum; |
| 152 switch (m_pToken->m_type) { | 147 switch (m_pToken->m_type) { |
| 153 case TOKvar: | 148 case TOKvar: |
| 154 e.reset(ParseVarExpression()); | 149 expr = ParseVarExpression(); |
| 155 break; | 150 break; |
| 156 case TOKnull: | 151 case TOKnull: |
| 157 case TOKnumber: | 152 case TOKnumber: |
| 158 case TOKstring: | 153 case TOKstring: |
| 159 case TOKplus: | 154 case TOKplus: |
| 160 case TOKminus: | 155 case TOKminus: |
| 161 case TOKksnot: | 156 case TOKksnot: |
| 162 case TOKidentifier: | 157 case TOKidentifier: |
| 163 case TOKlparen: | 158 case TOKlparen: |
| 164 e.reset(ParseExpExpression()); | 159 expr = ParseExpExpression(); |
| 165 break; | 160 break; |
| 166 case TOKif: | 161 case TOKif: |
| 167 e.reset(ParseIfExpression()); | 162 expr = ParseIfExpression(); |
| 168 break; | 163 break; |
| 169 case TOKwhile: | 164 case TOKwhile: |
| 170 e.reset(ParseWhileExpression()); | 165 expr = ParseWhileExpression(); |
| 171 break; | 166 break; |
| 172 case TOKfor: | 167 case TOKfor: |
| 173 e.reset(ParseForExpression()); | 168 expr = ParseForExpression(); |
| 174 break; | 169 break; |
| 175 case TOKforeach: | 170 case TOKforeach: |
| 176 e.reset(ParseForeachExpression()); | 171 expr = ParseForeachExpression(); |
| 177 break; | 172 break; |
| 178 case TOKdo: | 173 case TOKdo: |
| 179 e.reset(ParseDoExpression()); | 174 expr = ParseDoExpression(); |
| 180 break; | 175 break; |
| 181 case TOKbreak: | 176 case TOKbreak: |
| 182 e.reset(new CXFA_FMBreakExpression(line)); | 177 expr = pdfium::MakeUnique<CXFA_FMBreakExpression>(line); |
| 183 NextToken(); | 178 NextToken(); |
| 184 break; | 179 break; |
| 185 case TOKcontinue: | 180 case TOKcontinue: |
| 186 e.reset(new CXFA_FMContinueExpression(line)); | 181 expr = pdfium::MakeUnique<CXFA_FMContinueExpression>(line); |
| 187 NextToken(); | 182 NextToken(); |
| 188 break; | 183 break; |
| 189 default: | 184 default: |
| 190 CFX_WideString ws_TempString(m_pToken->m_wstring); | 185 CFX_WideString ws_TempString(m_pToken->m_wstring); |
| 191 Error(m_pToken->m_uLinenum, kFMErrUnexpectedExpression, | 186 Error(m_pToken->m_uLinenum, kFMErrUnexpectedExpression, |
| 192 ws_TempString.c_str()); | 187 ws_TempString.c_str()); |
| 193 NextToken(); | 188 NextToken(); |
| 194 break; | 189 break; |
| 195 } | 190 } |
| 196 return e.release(); | 191 return expr; |
| 197 } | 192 } |
| 198 | 193 |
| 199 CXFA_FMExpression* CXFA_FMParse::ParseVarExpression() { | 194 std::unique_ptr<CXFA_FMExpression> CXFA_FMParse::ParseVarExpression() { |
| 200 std::unique_ptr<CXFA_FMExpression> e; | 195 std::unique_ptr<CXFA_FMExpression> expr; |
| 201 CFX_WideStringC ident; | 196 CFX_WideStringC ident; |
| 202 uint32_t line = m_pToken->m_uLinenum; | 197 uint32_t line = m_pToken->m_uLinenum; |
| 203 NextToken(); | 198 NextToken(); |
| 204 if (m_pToken->m_type != TOKidentifier) { | 199 if (m_pToken->m_type != TOKidentifier) { |
| 205 CFX_WideString ws_TempString(m_pToken->m_wstring); | 200 CFX_WideString ws_TempString(m_pToken->m_wstring); |
| 206 Error(m_pToken->m_uLinenum, kFMErrExpectedIdentifier, | 201 Error(m_pToken->m_uLinenum, kFMErrExpectedIdentifier, |
| 207 ws_TempString.c_str()); | 202 ws_TempString.c_str()); |
| 208 } else { | 203 } else { |
| 209 ident = m_pToken->m_wstring; | 204 ident = m_pToken->m_wstring; |
| 210 NextToken(); | 205 NextToken(); |
| 211 } | 206 } |
| 212 if (m_pToken->m_type == TOKassign) { | 207 if (m_pToken->m_type == TOKassign) { |
| 213 NextToken(); | 208 NextToken(); |
| 214 e.reset(ParseExpExpression()); | 209 expr = ParseExpExpression(); |
| 215 } | 210 } |
| 216 if (m_pErrorInfo->message.IsEmpty()) { | 211 if (m_pErrorInfo->message.IsEmpty()) { |
| 217 e.reset(new CXFA_FMVarExpression(line, ident, e.release())); | 212 expr = |
| 213 pdfium::MakeUnique<CXFA_FMVarExpression>(line, ident, expr.release()); |
| 218 } else { | 214 } else { |
| 219 e.reset(); | 215 expr.reset(); |
| 220 } | 216 } |
| 221 return e.release(); | 217 return expr; |
| 222 } | 218 } |
| 223 | 219 |
| 224 CXFA_FMSimpleExpression* CXFA_FMParse::ParseSimpleExpression() { | 220 std::unique_ptr<CXFA_FMSimpleExpression> CXFA_FMParse::ParseSimpleExpression() { |
| 225 uint32_t line = m_pToken->m_uLinenum; | 221 uint32_t line = m_pToken->m_uLinenum; |
| 226 std::unique_ptr<CXFA_FMSimpleExpression> pExp1(ParseLogicalOrExpression()); | 222 std::unique_ptr<CXFA_FMSimpleExpression> pExp1 = ParseLogicalOrExpression(); |
| 227 while (m_pToken->m_type == TOKassign) { | 223 while (m_pToken->m_type == TOKassign) { |
| 228 NextToken(); | 224 NextToken(); |
| 229 std::unique_ptr<CXFA_FMSimpleExpression> pExp2(ParseLogicalOrExpression()); | 225 std::unique_ptr<CXFA_FMSimpleExpression> pExp2 = ParseLogicalOrExpression(); |
| 230 if (m_pErrorInfo->message.IsEmpty()) { | 226 if (m_pErrorInfo->message.IsEmpty()) { |
| 231 pExp1.reset(new CXFA_FMAssignExpression(line, TOKassign, pExp1.release(), | 227 pExp1 = pdfium::MakeUnique<CXFA_FMAssignExpression>( |
| 232 pExp2.release())); | 228 line, TOKassign, pExp1.release(), pExp2.release()); |
| 233 } else { | 229 } else { |
| 234 pExp1.reset(); | 230 pExp1.reset(); |
| 235 } | 231 } |
| 236 } | 232 } |
| 237 return pExp1.release(); | 233 return pExp1; |
| 238 } | 234 } |
| 239 | 235 |
| 240 CXFA_FMExpression* CXFA_FMParse::ParseExpExpression() { | 236 std::unique_ptr<CXFA_FMExpression> CXFA_FMParse::ParseExpExpression() { |
| 241 uint32_t line = m_pToken->m_uLinenum; | 237 uint32_t line = m_pToken->m_uLinenum; |
| 242 std::unique_ptr<CXFA_FMSimpleExpression> pExp1(ParseSimpleExpression()); | 238 std::unique_ptr<CXFA_FMSimpleExpression> pExp1 = ParseSimpleExpression(); |
| 243 std::unique_ptr<CXFA_FMExpression> e; | 239 std::unique_ptr<CXFA_FMExpression> expr; |
| 244 if (m_pErrorInfo->message.IsEmpty()) { | 240 if (m_pErrorInfo->message.IsEmpty()) { |
| 245 e.reset(new CXFA_FMExpExpression(line, pExp1.release())); | 241 expr = pdfium::MakeUnique<CXFA_FMExpExpression>(line, pExp1.release()); |
| 246 } else { | 242 } else { |
| 247 e.reset(); | 243 expr.reset(); |
| 248 } | 244 } |
| 249 return e.release(); | 245 return expr; |
| 250 } | 246 } |
| 251 | 247 |
| 252 CXFA_FMSimpleExpression* CXFA_FMParse::ParseLogicalOrExpression() { | 248 std::unique_ptr<CXFA_FMSimpleExpression> |
| 249 CXFA_FMParse::ParseLogicalOrExpression() { |
| 253 uint32_t line = m_pToken->m_uLinenum; | 250 uint32_t line = m_pToken->m_uLinenum; |
| 254 std::unique_ptr<CXFA_FMSimpleExpression> e1(ParseLogicalAndExpression()); | 251 std::unique_ptr<CXFA_FMSimpleExpression> e1 = ParseLogicalAndExpression(); |
| 255 for (;;) { | 252 for (;;) { |
| 256 switch (m_pToken->m_type) { | 253 switch (m_pToken->m_type) { |
| 257 case TOKor: | 254 case TOKor: |
| 258 case TOKksor: { | 255 case TOKksor: { |
| 259 NextToken(); | 256 NextToken(); |
| 260 std::unique_ptr<CXFA_FMSimpleExpression> e2( | 257 std::unique_ptr<CXFA_FMSimpleExpression> e2( |
| 261 ParseLogicalAndExpression()); | 258 ParseLogicalAndExpression()); |
| 262 if (m_pErrorInfo->message.IsEmpty()) { | 259 if (m_pErrorInfo->message.IsEmpty()) { |
| 263 e1.reset(new CXFA_FMLogicalOrExpression(line, TOKor, e1.release(), | 260 e1 = pdfium::MakeUnique<CXFA_FMLogicalOrExpression>( |
| 264 e2.release())); | 261 line, TOKor, e1.release(), e2.release()); |
| 265 } else { | 262 } else { |
| 266 e1.reset(); | 263 e1.reset(); |
| 267 } | 264 } |
| 268 continue; | 265 continue; |
| 269 } | 266 } |
| 270 default: | 267 default: |
| 271 break; | 268 break; |
| 272 } | 269 } |
| 273 break; | 270 break; |
| 274 } | 271 } |
| 275 return e1.release(); | 272 return e1; |
| 276 } | 273 } |
| 277 | 274 |
| 278 CXFA_FMSimpleExpression* CXFA_FMParse::ParseLogicalAndExpression() { | 275 std::unique_ptr<CXFA_FMSimpleExpression> |
| 276 CXFA_FMParse::ParseLogicalAndExpression() { |
| 279 uint32_t line = m_pToken->m_uLinenum; | 277 uint32_t line = m_pToken->m_uLinenum; |
| 280 std::unique_ptr<CXFA_FMSimpleExpression> e1(ParseEqualityExpression()); | 278 std::unique_ptr<CXFA_FMSimpleExpression> e1 = ParseEqualityExpression(); |
| 281 for (;;) { | 279 for (;;) { |
| 282 switch (m_pToken->m_type) { | 280 switch (m_pToken->m_type) { |
| 283 case TOKand: | 281 case TOKand: |
| 284 case TOKksand: { | 282 case TOKksand: { |
| 285 NextToken(); | 283 NextToken(); |
| 286 std::unique_ptr<CXFA_FMSimpleExpression> e2(ParseEqualityExpression()); | 284 std::unique_ptr<CXFA_FMSimpleExpression> e2 = ParseEqualityExpression(); |
| 287 if (m_pErrorInfo->message.IsEmpty()) { | 285 if (m_pErrorInfo->message.IsEmpty()) { |
| 288 e1.reset(new CXFA_FMLogicalAndExpression(line, TOKand, e1.release(), | 286 e1 = pdfium::MakeUnique<CXFA_FMLogicalAndExpression>( |
| 289 e2.release())); | 287 line, TOKand, e1.release(), e2.release()); |
| 290 } else { | 288 } else { |
| 291 e1.reset(); | 289 e1.reset(); |
| 292 } | 290 } |
| 293 continue; | 291 continue; |
| 294 } | 292 } |
| 295 default: | 293 default: |
| 296 break; | 294 break; |
| 297 } | 295 } |
| 298 break; | 296 break; |
| 299 } | 297 } |
| 300 return e1.release(); | 298 return e1; |
| 301 } | 299 } |
| 302 | 300 |
| 303 CXFA_FMSimpleExpression* CXFA_FMParse::ParseEqualityExpression() { | 301 std::unique_ptr<CXFA_FMSimpleExpression> |
| 302 CXFA_FMParse::ParseEqualityExpression() { |
| 304 uint32_t line = m_pToken->m_uLinenum; | 303 uint32_t line = m_pToken->m_uLinenum; |
| 305 std::unique_ptr<CXFA_FMSimpleExpression> e1(ParseRelationalExpression()); | 304 std::unique_ptr<CXFA_FMSimpleExpression> e1 = ParseRelationalExpression(); |
| 306 for (;;) { | 305 for (;;) { |
| 307 std::unique_ptr<CXFA_FMSimpleExpression> e2; | 306 std::unique_ptr<CXFA_FMSimpleExpression> e2; |
| 308 switch (m_pToken->m_type) { | 307 switch (m_pToken->m_type) { |
| 309 case TOKeq: | 308 case TOKeq: |
| 310 case TOKkseq: | 309 case TOKkseq: |
| 311 NextToken(); | 310 NextToken(); |
| 312 e2.reset(ParseRelationalExpression()); | 311 e2 = ParseRelationalExpression(); |
| 313 if (m_pErrorInfo->message.IsEmpty()) { | 312 if (m_pErrorInfo->message.IsEmpty()) { |
| 314 e1.reset(new CXFA_FMEqualityExpression(line, TOKeq, e1.release(), | 313 e1 = pdfium::MakeUnique<CXFA_FMEqualityExpression>( |
| 315 e2.release())); | 314 line, TOKeq, e1.release(), e2.release()); |
| 316 } else { | 315 } else { |
| 317 e1.reset(); | 316 e1.reset(); |
| 318 } | 317 } |
| 319 continue; | 318 continue; |
| 320 case TOKne: | 319 case TOKne: |
| 321 case TOKksne: | 320 case TOKksne: |
| 322 NextToken(); | 321 NextToken(); |
| 323 e2.reset(ParseRelationalExpression()); | 322 e2 = ParseRelationalExpression(); |
| 324 if (m_pErrorInfo->message.IsEmpty()) { | 323 if (m_pErrorInfo->message.IsEmpty()) { |
| 325 e1.reset(new CXFA_FMEqualityExpression(line, TOKne, e1.release(), | 324 e1 = pdfium::MakeUnique<CXFA_FMEqualityExpression>( |
| 326 e2.release())); | 325 line, TOKne, e1.release(), e2.release()); |
| 327 } else { | 326 } else { |
| 328 e1.reset(); | 327 e1.reset(); |
| 329 } | 328 } |
| 330 continue; | 329 continue; |
| 331 default: | 330 default: |
| 332 break; | 331 break; |
| 333 } | 332 } |
| 334 break; | 333 break; |
| 335 } | 334 } |
| 336 return e1.release(); | 335 return e1; |
| 337 } | 336 } |
| 338 | 337 |
| 339 CXFA_FMSimpleExpression* CXFA_FMParse::ParseRelationalExpression() { | 338 std::unique_ptr<CXFA_FMSimpleExpression> |
| 339 CXFA_FMParse::ParseRelationalExpression() { |
| 340 uint32_t line = m_pToken->m_uLinenum; | 340 uint32_t line = m_pToken->m_uLinenum; |
| 341 std::unique_ptr<CXFA_FMSimpleExpression> e1(ParseAddtiveExpression()); | 341 std::unique_ptr<CXFA_FMSimpleExpression> e1 = ParseAddtiveExpression(); |
| 342 for (;;) { | 342 for (;;) { |
| 343 std::unique_ptr<CXFA_FMSimpleExpression> e2; | 343 std::unique_ptr<CXFA_FMSimpleExpression> e2; |
| 344 switch (m_pToken->m_type) { | 344 switch (m_pToken->m_type) { |
| 345 case TOKlt: | 345 case TOKlt: |
| 346 case TOKkslt: | 346 case TOKkslt: |
| 347 NextToken(); | 347 NextToken(); |
| 348 e2.reset(ParseAddtiveExpression()); | 348 e2 = ParseAddtiveExpression(); |
| 349 if (m_pErrorInfo->message.IsEmpty()) { | 349 if (m_pErrorInfo->message.IsEmpty()) { |
| 350 e1.reset(new CXFA_FMRelationalExpression(line, TOKlt, e1.release(), | 350 e1 = pdfium::MakeUnique<CXFA_FMRelationalExpression>( |
| 351 e2.release())); | 351 line, TOKlt, e1.release(), e2.release()); |
| 352 } else { | 352 } else { |
| 353 e1.reset(); | 353 e1.reset(); |
| 354 } | 354 } |
| 355 continue; | 355 continue; |
| 356 case TOKgt: | 356 case TOKgt: |
| 357 case TOKksgt: | 357 case TOKksgt: |
| 358 NextToken(); | 358 NextToken(); |
| 359 e2.reset(ParseAddtiveExpression()); | 359 e2 = ParseAddtiveExpression(); |
| 360 if (m_pErrorInfo->message.IsEmpty()) { | 360 if (m_pErrorInfo->message.IsEmpty()) { |
| 361 e1.reset(new CXFA_FMRelationalExpression(line, TOKgt, e1.release(), | 361 e1 = pdfium::MakeUnique<CXFA_FMRelationalExpression>( |
| 362 e2.release())); | 362 line, TOKgt, e1.release(), e2.release()); |
| 363 } else { | 363 } else { |
| 364 e1.reset(); | 364 e1.reset(); |
| 365 } | 365 } |
| 366 continue; | 366 continue; |
| 367 case TOKle: | 367 case TOKle: |
| 368 case TOKksle: | 368 case TOKksle: |
| 369 NextToken(); | 369 NextToken(); |
| 370 e2.reset(ParseAddtiveExpression()); | 370 e2 = ParseAddtiveExpression(); |
| 371 if (m_pErrorInfo->message.IsEmpty()) { | 371 if (m_pErrorInfo->message.IsEmpty()) { |
| 372 e1.reset(new CXFA_FMRelationalExpression(line, TOKle, e1.release(), | 372 e1 = pdfium::MakeUnique<CXFA_FMRelationalExpression>( |
| 373 e2.release())); | 373 line, TOKle, e1.release(), e2.release()); |
| 374 } else { | 374 } else { |
| 375 e1.reset(); | 375 e1.reset(); |
| 376 } | 376 } |
| 377 continue; | 377 continue; |
| 378 case TOKge: | 378 case TOKge: |
| 379 case TOKksge: | 379 case TOKksge: |
| 380 NextToken(); | 380 NextToken(); |
| 381 e2.reset(ParseAddtiveExpression()); | 381 e2 = ParseAddtiveExpression(); |
| 382 if (m_pErrorInfo->message.IsEmpty()) { | 382 if (m_pErrorInfo->message.IsEmpty()) { |
| 383 e1.reset(new CXFA_FMRelationalExpression(line, TOKge, e1.release(), | 383 e1 = pdfium::MakeUnique<CXFA_FMRelationalExpression>( |
| 384 e2.release())); | 384 line, TOKge, e1.release(), e2.release()); |
| 385 } else { | 385 } else { |
| 386 e1.reset(); | 386 e1.reset(); |
| 387 } | 387 } |
| 388 continue; | 388 continue; |
| 389 default: | 389 default: |
| 390 break; | 390 break; |
| 391 } | 391 } |
| 392 break; | 392 break; |
| 393 } | 393 } |
| 394 return e1.release(); | 394 return e1; |
| 395 } | 395 } |
| 396 | 396 |
| 397 CXFA_FMSimpleExpression* CXFA_FMParse::ParseAddtiveExpression() { | 397 std::unique_ptr<CXFA_FMSimpleExpression> |
| 398 CXFA_FMParse::ParseAddtiveExpression() { |
| 398 uint32_t line = m_pToken->m_uLinenum; | 399 uint32_t line = m_pToken->m_uLinenum; |
| 399 std::unique_ptr<CXFA_FMSimpleExpression> e1(ParseMultiplicativeExpression()); | 400 std::unique_ptr<CXFA_FMSimpleExpression> e1 = ParseMultiplicativeExpression(); |
| 400 for (;;) { | 401 for (;;) { |
| 401 std::unique_ptr<CXFA_FMSimpleExpression> e2; | 402 std::unique_ptr<CXFA_FMSimpleExpression> e2; |
| 402 switch (m_pToken->m_type) { | 403 switch (m_pToken->m_type) { |
| 403 case TOKplus: | 404 case TOKplus: |
| 404 NextToken(); | 405 NextToken(); |
| 405 e2.reset(ParseMultiplicativeExpression()); | 406 e2 = ParseMultiplicativeExpression(); |
| 406 if (m_pErrorInfo->message.IsEmpty()) { | 407 if (m_pErrorInfo->message.IsEmpty()) { |
| 407 e1.reset(new CXFA_FMAdditiveExpression(line, TOKplus, e1.release(), | 408 e1 = pdfium::MakeUnique<CXFA_FMAdditiveExpression>( |
| 408 e2.release())); | 409 line, TOKplus, e1.release(), e2.release()); |
| 409 } else { | 410 } else { |
| 410 e1.reset(); | 411 e1.reset(); |
| 411 } | 412 } |
| 412 continue; | 413 continue; |
| 413 case TOKminus: | 414 case TOKminus: |
| 414 NextToken(); | 415 NextToken(); |
| 415 e2.reset(ParseMultiplicativeExpression()); | 416 e2 = ParseMultiplicativeExpression(); |
| 416 if (m_pErrorInfo->message.IsEmpty()) { | 417 if (m_pErrorInfo->message.IsEmpty()) { |
| 417 e1.reset(new CXFA_FMAdditiveExpression(line, TOKminus, e1.release(), | 418 e1 = pdfium::MakeUnique<CXFA_FMAdditiveExpression>( |
| 418 e2.release())); | 419 line, TOKminus, e1.release(), e2.release()); |
| 419 } else { | 420 } else { |
| 420 e1.reset(); | 421 e1.reset(); |
| 421 } | 422 } |
| 422 continue; | 423 continue; |
| 423 default: | 424 default: |
| 424 break; | 425 break; |
| 425 } | 426 } |
| 426 break; | 427 break; |
| 427 } | 428 } |
| 428 return e1.release(); | 429 return e1; |
| 429 } | 430 } |
| 430 | 431 |
| 431 CXFA_FMSimpleExpression* CXFA_FMParse::ParseMultiplicativeExpression() { | 432 std::unique_ptr<CXFA_FMSimpleExpression> |
| 433 CXFA_FMParse::ParseMultiplicativeExpression() { |
| 432 uint32_t line = m_pToken->m_uLinenum; | 434 uint32_t line = m_pToken->m_uLinenum; |
| 433 std::unique_ptr<CXFA_FMSimpleExpression> e1(ParseUnaryExpression()); | 435 std::unique_ptr<CXFA_FMSimpleExpression> e1 = ParseUnaryExpression(); |
| 434 for (;;) { | 436 for (;;) { |
| 435 std::unique_ptr<CXFA_FMSimpleExpression> e2; | 437 std::unique_ptr<CXFA_FMSimpleExpression> e2; |
| 436 switch (m_pToken->m_type) { | 438 switch (m_pToken->m_type) { |
| 437 case TOKmul: | 439 case TOKmul: |
| 438 NextToken(); | 440 NextToken(); |
| 439 e2.reset(ParseUnaryExpression()); | 441 e2 = ParseUnaryExpression(); |
| 440 if (m_pErrorInfo->message.IsEmpty()) { | 442 if (m_pErrorInfo->message.IsEmpty()) { |
| 441 e1.reset(new CXFA_FMMultiplicativeExpression( | 443 e1 = pdfium::MakeUnique<CXFA_FMMultiplicativeExpression>( |
| 442 line, TOKmul, e1.release(), e2.release())); | 444 line, TOKmul, e1.release(), e2.release()); |
| 443 } else { | 445 } else { |
| 444 e1.reset(); | 446 e1.reset(); |
| 445 } | 447 } |
| 446 continue; | 448 continue; |
| 447 case TOKdiv: | 449 case TOKdiv: |
| 448 NextToken(); | 450 NextToken(); |
| 449 e2.reset(ParseUnaryExpression()); | 451 e2 = ParseUnaryExpression(); |
| 450 if (m_pErrorInfo->message.IsEmpty()) { | 452 if (m_pErrorInfo->message.IsEmpty()) { |
| 451 e1.reset(new CXFA_FMMultiplicativeExpression( | 453 e1 = pdfium::MakeUnique<CXFA_FMMultiplicativeExpression>( |
| 452 line, TOKdiv, e1.release(), e2.release())); | 454 line, TOKdiv, e1.release(), e2.release()); |
| 453 } else { | 455 } else { |
| 454 e1.reset(); | 456 e1.reset(); |
| 455 } | 457 } |
| 456 continue; | 458 continue; |
| 457 default: | 459 default: |
| 458 break; | 460 break; |
| 459 } | 461 } |
| 460 break; | 462 break; |
| 461 } | 463 } |
| 462 return e1.release(); | 464 return e1; |
| 463 } | 465 } |
| 464 | 466 |
| 465 CXFA_FMSimpleExpression* CXFA_FMParse::ParseUnaryExpression() { | 467 std::unique_ptr<CXFA_FMSimpleExpression> CXFA_FMParse::ParseUnaryExpression() { |
| 466 std::unique_ptr<CXFA_FMSimpleExpression> e; | 468 std::unique_ptr<CXFA_FMSimpleExpression> expr; |
| 467 uint32_t line = m_pToken->m_uLinenum; | 469 uint32_t line = m_pToken->m_uLinenum; |
| 468 switch (m_pToken->m_type) { | 470 switch (m_pToken->m_type) { |
| 469 case TOKplus: | 471 case TOKplus: |
| 470 NextToken(); | 472 NextToken(); |
| 471 e.reset(ParseUnaryExpression()); | 473 expr = ParseUnaryExpression(); |
| 472 if (m_pErrorInfo->message.IsEmpty()) { | 474 if (m_pErrorInfo->message.IsEmpty()) { |
| 473 e.reset(new CXFA_FMPosExpression(line, e.release())); | 475 expr = pdfium::MakeUnique<CXFA_FMPosExpression>(line, expr.release()); |
| 474 } else { | 476 } else { |
| 475 e.reset(); | 477 expr.reset(); |
| 476 } | 478 } |
| 477 break; | 479 break; |
| 478 case TOKminus: | 480 case TOKminus: |
| 479 NextToken(); | 481 NextToken(); |
| 480 e.reset(ParseUnaryExpression()); | 482 expr = ParseUnaryExpression(); |
| 481 if (m_pErrorInfo->message.IsEmpty()) { | 483 if (m_pErrorInfo->message.IsEmpty()) { |
| 482 e.reset(new CXFA_FMNegExpression(line, e.release())); | 484 expr = pdfium::MakeUnique<CXFA_FMNegExpression>(line, expr.release()); |
| 483 } else { | 485 } else { |
| 484 e.reset(); | 486 expr.reset(); |
| 485 } | 487 } |
| 486 break; | 488 break; |
| 487 case TOKksnot: | 489 case TOKksnot: |
| 488 NextToken(); | 490 NextToken(); |
| 489 e.reset(ParseUnaryExpression()); | 491 expr = ParseUnaryExpression(); |
| 490 if (m_pErrorInfo->message.IsEmpty()) { | 492 if (m_pErrorInfo->message.IsEmpty()) { |
| 491 e.reset(new CXFA_FMNotExpression(line, e.release())); | 493 expr = pdfium::MakeUnique<CXFA_FMNotExpression>(line, expr.release()); |
| 492 } else { | 494 } else { |
| 493 e.reset(); | 495 expr.reset(); |
| 494 } | 496 } |
| 495 break; | 497 break; |
| 496 default: | 498 default: |
| 497 e.reset(ParsePrimaryExpression()); | 499 expr = ParsePrimaryExpression(); |
| 498 break; | 500 break; |
| 499 } | 501 } |
| 500 return e.release(); | 502 return expr; |
| 501 } | 503 } |
| 502 | 504 |
| 503 CXFA_FMSimpleExpression* CXFA_FMParse::ParsePrimaryExpression() { | 505 std::unique_ptr<CXFA_FMSimpleExpression> |
| 504 std::unique_ptr<CXFA_FMSimpleExpression> e; | 506 CXFA_FMParse::ParsePrimaryExpression() { |
| 507 std::unique_ptr<CXFA_FMSimpleExpression> expr; |
| 505 uint32_t line = m_pToken->m_uLinenum; | 508 uint32_t line = m_pToken->m_uLinenum; |
| 506 switch (m_pToken->m_type) { | 509 switch (m_pToken->m_type) { |
| 507 case TOKnumber: | 510 case TOKnumber: |
| 508 e.reset(new CXFA_FMNumberExpression(line, m_pToken->m_wstring)); | 511 expr = pdfium::MakeUnique<CXFA_FMNumberExpression>(line, |
| 512 m_pToken->m_wstring); |
| 509 NextToken(); | 513 NextToken(); |
| 510 break; | 514 break; |
| 511 case TOKstring: | 515 case TOKstring: |
| 512 e.reset(new CXFA_FMStringExpression(line, m_pToken->m_wstring)); | 516 expr = pdfium::MakeUnique<CXFA_FMStringExpression>(line, |
| 517 m_pToken->m_wstring); |
| 513 NextToken(); | 518 NextToken(); |
| 514 break; | 519 break; |
| 515 case TOKidentifier: { | 520 case TOKidentifier: { |
| 516 CFX_WideStringC wsIdentifier(m_pToken->m_wstring); | 521 CFX_WideStringC wsIdentifier(m_pToken->m_wstring); |
| 517 NextToken(); | 522 NextToken(); |
| 518 if (m_pToken->m_type == TOKlbracket) { | 523 if (m_pToken->m_type == TOKlbracket) { |
| 519 CXFA_FMSimpleExpression* s = ParseIndexExpression(); | 524 std::unique_ptr<CXFA_FMSimpleExpression> s = ParseIndexExpression(); |
| 520 if (s) { | 525 if (s) { |
| 521 e.reset(new CXFA_FMDotAccessorExpression(line, nullptr, TOKdot, | 526 expr = pdfium::MakeUnique<CXFA_FMDotAccessorExpression>( |
| 522 wsIdentifier, s)); | 527 line, nullptr, TOKdot, wsIdentifier, s.release()); |
| 523 } | 528 } |
| 524 NextToken(); | 529 NextToken(); |
| 525 } else { | 530 } else { |
| 526 e.reset(new CXFA_FMIdentifierExpression(line, wsIdentifier)); | 531 expr = |
| 532 pdfium::MakeUnique<CXFA_FMIdentifierExpression>(line, wsIdentifier); |
| 527 } | 533 } |
| 528 } break; | 534 } break; |
| 529 case TOKif: | 535 case TOKif: |
| 530 e.reset(new CXFA_FMIdentifierExpression(line, m_pToken->m_wstring)); | 536 expr = pdfium::MakeUnique<CXFA_FMIdentifierExpression>( |
| 537 line, m_pToken->m_wstring); |
| 531 NextToken(); | 538 NextToken(); |
| 532 break; | 539 break; |
| 533 case TOKnull: | 540 case TOKnull: |
| 534 e.reset(new CXFA_FMNullExpression(line)); | 541 expr = pdfium::MakeUnique<CXFA_FMNullExpression>(line); |
| 535 NextToken(); | 542 NextToken(); |
| 536 break; | 543 break; |
| 537 case TOKlparen: | 544 case TOKlparen: |
| 538 e.reset(ParseParenExpression()); | 545 expr = ParseParenExpression(); |
| 539 break; | 546 break; |
| 540 default: | 547 default: |
| 541 CFX_WideString ws_TempString(m_pToken->m_wstring); | 548 CFX_WideString ws_TempString(m_pToken->m_wstring); |
| 542 Error(m_pToken->m_uLinenum, kFMErrUnexpectedExpression, | 549 Error(m_pToken->m_uLinenum, kFMErrUnexpectedExpression, |
| 543 ws_TempString.c_str()); | 550 ws_TempString.c_str()); |
| 544 NextToken(); | 551 NextToken(); |
| 545 break; | 552 break; |
| 546 } | 553 } |
| 547 e.reset(ParsePostExpression(e.release())); | 554 expr = ParsePostExpression(std::move(expr)); |
| 548 if (!(m_pErrorInfo->message.IsEmpty())) | 555 if (!(m_pErrorInfo->message.IsEmpty())) |
| 549 e.reset(); | 556 expr.reset(); |
| 550 return e.release(); | 557 return expr; |
| 551 } | 558 } |
| 552 | 559 |
| 553 CXFA_FMSimpleExpression* CXFA_FMParse::ParsePostExpression( | 560 std::unique_ptr<CXFA_FMSimpleExpression> CXFA_FMParse::ParsePostExpression( |
| 554 CXFA_FMSimpleExpression* e) { | 561 std::unique_ptr<CXFA_FMSimpleExpression> expr) { |
| 555 uint32_t line = m_pToken->m_uLinenum; | 562 uint32_t line = m_pToken->m_uLinenum; |
| 556 while (1) { | 563 while (1) { |
| 557 switch (m_pToken->m_type) { | 564 switch (m_pToken->m_type) { |
| 558 case TOKlparen: { | 565 case TOKlparen: { |
| 559 NextToken(); | 566 NextToken(); |
| 560 std::unique_ptr<CFX_ArrayTemplate<CXFA_FMSimpleExpression*>> pArray; | 567 std::vector<std::unique_ptr<CXFA_FMSimpleExpression>> expressions; |
| 561 if (m_pToken->m_type != TOKrparen) { | 568 if (m_pToken->m_type != TOKrparen) { |
| 562 pArray.reset(new CFX_ArrayTemplate<CXFA_FMSimpleExpression*>()); | |
| 563 while (m_pToken->m_type != TOKrparen) { | 569 while (m_pToken->m_type != TOKrparen) { |
| 564 if (CXFA_FMSimpleExpression* expr = ParseSimpleExpression()) | 570 if (std::unique_ptr<CXFA_FMSimpleExpression> expr = |
| 565 pArray->Add(expr); | 571 ParseSimpleExpression()) |
| 572 expressions.push_back(std::move(expr)); |
| 566 if (m_pToken->m_type == TOKcomma) { | 573 if (m_pToken->m_type == TOKcomma) { |
| 567 NextToken(); | 574 NextToken(); |
| 568 } else if (m_pToken->m_type == TOKeof || | 575 } else if (m_pToken->m_type == TOKeof || |
| 569 m_pToken->m_type == TOKreserver) { | 576 m_pToken->m_type == TOKreserver) { |
| 570 break; | 577 break; |
| 571 } | 578 } |
| 572 } | 579 } |
| 573 if (m_pToken->m_type != TOKrparen) { | 580 if (m_pToken->m_type != TOKrparen) { |
| 574 CFX_WideString ws_TempString(m_pToken->m_wstring); | 581 CFX_WideString ws_TempString(m_pToken->m_wstring); |
| 575 Error(m_pToken->m_uLinenum, kFMErrExpectedToken, | 582 Error(m_pToken->m_uLinenum, kFMErrExpectedToken, |
| 576 XFA_FM_KeywordToString(TOKrparen), ws_TempString.c_str()); | 583 XFA_FM_KeywordToString(TOKrparen), ws_TempString.c_str()); |
| 577 } | 584 } |
| 578 } | 585 } |
| 579 if (m_pErrorInfo->message.IsEmpty()) { | 586 if (m_pErrorInfo->message.IsEmpty()) { |
| 580 e = new CXFA_FMCallExpression(line, e, pArray.release(), false); | 587 expr = pdfium::MakeUnique<CXFA_FMCallExpression>( |
| 588 line, expr.release(), std::move(expressions), false); |
| 581 NextToken(); | 589 NextToken(); |
| 582 if (m_pToken->m_type != TOKlbracket) { | 590 if (m_pToken->m_type != TOKlbracket) |
| 583 continue; | 591 continue; |
| 584 } | 592 |
| 585 CXFA_FMSimpleExpression* s = ParseIndexExpression(); | 593 std::unique_ptr<CXFA_FMSimpleExpression> s = ParseIndexExpression(); |
| 586 if (s) { | 594 if (s) { |
| 587 e = new CXFA_FMDotAccessorExpression(line, e, TOKcall, | 595 expr = pdfium::MakeUnique<CXFA_FMDotAccessorExpression>( |
| 588 FX_WSTRC(L""), s); | 596 line, expr.release(), TOKcall, FX_WSTRC(L""), s.release()); |
| 589 } else { | 597 } else { |
| 590 delete e; | 598 expr.reset(); |
| 591 e = nullptr; | |
| 592 } | 599 } |
| 593 } else { | 600 } else { |
| 594 if (pArray) { | 601 expr.reset(); |
| 595 for (int32_t i = 0; i < pArray->GetSize(); ++i) | |
| 596 delete pArray->GetAt(i); | |
| 597 } | |
| 598 delete e; | |
| 599 e = nullptr; | |
| 600 } | 602 } |
| 601 } break; | 603 } break; |
| 602 case TOKdot: | 604 case TOKdot: |
| 603 NextToken(); | 605 NextToken(); |
| 604 if (m_pToken->m_type == TOKidentifier) { | 606 if (m_pToken->m_type == TOKidentifier) { |
| 605 CFX_WideStringC tempStr = m_pToken->m_wstring; | 607 CFX_WideStringC tempStr = m_pToken->m_wstring; |
| 606 uint32_t tempLine = m_pToken->m_uLinenum; | 608 uint32_t tempLine = m_pToken->m_uLinenum; |
| 607 NextToken(); | 609 NextToken(); |
| 608 if (m_pToken->m_type == TOKlparen) { | 610 if (m_pToken->m_type == TOKlparen) { |
| 609 CXFA_FMSimpleExpression* pExpAccessor; | 611 std::unique_ptr<CXFA_FMSimpleExpression> pExpCall; |
| 610 CXFA_FMSimpleExpression* pExpCall; | |
| 611 pExpAccessor = e; | |
| 612 NextToken(); | 612 NextToken(); |
| 613 std::unique_ptr<CFX_ArrayTemplate<CXFA_FMSimpleExpression*>> pArray; | 613 std::vector<std::unique_ptr<CXFA_FMSimpleExpression>> expressions; |
| 614 if (m_pToken->m_type != TOKrparen) { | 614 if (m_pToken->m_type != TOKrparen) { |
| 615 pArray.reset(new CFX_ArrayTemplate<CXFA_FMSimpleExpression*>()); | |
| 616 while (m_pToken->m_type != TOKrparen) { | 615 while (m_pToken->m_type != TOKrparen) { |
| 617 CXFA_FMSimpleExpression* exp = ParseSimpleExpression(); | 616 std::unique_ptr<CXFA_FMSimpleExpression> exp = |
| 618 pArray->Add(exp); | 617 ParseSimpleExpression(); |
| 618 expressions.push_back(std::move(exp)); |
| 619 if (m_pToken->m_type == TOKcomma) { | 619 if (m_pToken->m_type == TOKcomma) { |
| 620 NextToken(); | 620 NextToken(); |
| 621 } else if (m_pToken->m_type == TOKeof || | 621 } else if (m_pToken->m_type == TOKeof || |
| 622 m_pToken->m_type == TOKreserver) { | 622 m_pToken->m_type == TOKreserver) { |
| 623 break; | 623 break; |
| 624 } | 624 } |
| 625 } | 625 } |
| 626 if (m_pToken->m_type != TOKrparen) { | 626 if (m_pToken->m_type != TOKrparen) { |
| 627 CFX_WideString ws_TempString(m_pToken->m_wstring); | 627 CFX_WideString ws_TempString(m_pToken->m_wstring); |
| 628 Error(m_pToken->m_uLinenum, kFMErrExpectedToken, | 628 Error(m_pToken->m_uLinenum, kFMErrExpectedToken, |
| 629 XFA_FM_KeywordToString(TOKrparen), ws_TempString.c_str()); | 629 XFA_FM_KeywordToString(TOKrparen), ws_TempString.c_str()); |
| 630 } | 630 } |
| 631 } | 631 } |
| 632 if (m_pErrorInfo->message.IsEmpty()) { | 632 if (m_pErrorInfo->message.IsEmpty()) { |
| 633 CXFA_FMSimpleExpression* pIdentifier = | 633 std::unique_ptr<CXFA_FMSimpleExpression> pIdentifier = |
| 634 new CXFA_FMIdentifierExpression(tempLine, tempStr); | 634 pdfium::MakeUnique<CXFA_FMIdentifierExpression>(tempLine, |
| 635 pExpCall = new CXFA_FMCallExpression(line, pIdentifier, | 635 tempStr); |
| 636 pArray.release(), true); | 636 pExpCall = pdfium::MakeUnique<CXFA_FMCallExpression>( |
| 637 e = new CXFA_FMMethodCallExpression(line, pExpAccessor, pExpCall); | 637 line, pIdentifier.release(), std::move(expressions), true); |
| 638 expr = pdfium::MakeUnique<CXFA_FMMethodCallExpression>( |
| 639 line, expr.release(), pExpCall.release()); |
| 638 NextToken(); | 640 NextToken(); |
| 639 if (m_pToken->m_type != TOKlbracket) { | 641 if (m_pToken->m_type != TOKlbracket) |
| 640 continue; | 642 continue; |
| 641 } | 643 |
| 642 CXFA_FMSimpleExpression* s = ParseIndexExpression(); | 644 std::unique_ptr<CXFA_FMSimpleExpression> s = |
| 645 ParseIndexExpression(); |
| 643 if (s) { | 646 if (s) { |
| 644 e = new CXFA_FMDotAccessorExpression(line, e, TOKcall, | 647 expr = pdfium::MakeUnique<CXFA_FMDotAccessorExpression>( |
| 645 FX_WSTRC(L""), s); | 648 line, expr.release(), TOKcall, FX_WSTRC(L""), s.release()); |
| 646 } else { | 649 } else { |
| 647 delete e; | 650 expr.reset(); |
| 648 e = nullptr; | |
| 649 } | 651 } |
| 650 } else { | 652 } else { |
| 651 if (pArray) { | 653 expr.reset(); |
| 652 for (int32_t i = 0; i < pArray->GetSize(); ++i) | |
| 653 delete pArray->GetAt(i); | |
| 654 } | |
| 655 delete e; | |
| 656 e = nullptr; | |
| 657 } | 654 } |
| 658 } else if (m_pToken->m_type == TOKlbracket) { | 655 } else if (m_pToken->m_type == TOKlbracket) { |
| 659 std::unique_ptr<CXFA_FMSimpleExpression> s(ParseIndexExpression()); | 656 std::unique_ptr<CXFA_FMSimpleExpression> s = ParseIndexExpression(); |
| 660 if (!(m_pErrorInfo->message.IsEmpty())) { | 657 if (!(m_pErrorInfo->message.IsEmpty())) |
| 661 delete e; | |
| 662 return nullptr; | 658 return nullptr; |
| 663 } | 659 |
| 664 e = new CXFA_FMDotAccessorExpression(tempLine, e, TOKdot, tempStr, | 660 expr = pdfium::MakeUnique<CXFA_FMDotAccessorExpression>( |
| 665 s.release()); | 661 tempLine, expr.release(), TOKdot, tempStr, s.release()); |
| 666 } else { | 662 } else { |
| 667 CXFA_FMSimpleExpression* s = new CXFA_FMIndexExpression( | 663 std::unique_ptr<CXFA_FMSimpleExpression> s = |
| 668 tempLine, ACCESSOR_NO_INDEX, nullptr, false); | 664 pdfium::MakeUnique<CXFA_FMIndexExpression>( |
| 669 e = new CXFA_FMDotAccessorExpression(line, e, TOKdot, tempStr, s); | 665 tempLine, ACCESSOR_NO_INDEX, nullptr, false); |
| 666 expr = pdfium::MakeUnique<CXFA_FMDotAccessorExpression>( |
| 667 line, expr.release(), TOKdot, tempStr, s.release()); |
| 670 continue; | 668 continue; |
| 671 } | 669 } |
| 672 } else { | 670 } else { |
| 673 CFX_WideString ws_TempString(m_pToken->m_wstring); | 671 CFX_WideString ws_TempString(m_pToken->m_wstring); |
| 674 Error(m_pToken->m_uLinenum, kFMErrExpectedIdentifier, | 672 Error(m_pToken->m_uLinenum, kFMErrExpectedIdentifier, |
| 675 ws_TempString.c_str()); | 673 ws_TempString.c_str()); |
| 676 return e; | 674 return expr; |
| 677 } | 675 } |
| 678 break; | 676 break; |
| 679 case TOKdotdot: | 677 case TOKdotdot: |
| 680 NextToken(); | 678 NextToken(); |
| 681 if (m_pToken->m_type == TOKidentifier) { | 679 if (m_pToken->m_type == TOKidentifier) { |
| 682 CFX_WideStringC tempStr = m_pToken->m_wstring; | 680 CFX_WideStringC tempStr = m_pToken->m_wstring; |
| 683 uint32_t tempLine = m_pToken->m_uLinenum; | 681 uint32_t tempLine = m_pToken->m_uLinenum; |
| 684 NextToken(); | 682 NextToken(); |
| 685 if (m_pToken->m_type == TOKlbracket) { | 683 if (m_pToken->m_type == TOKlbracket) { |
| 686 std::unique_ptr<CXFA_FMSimpleExpression> s(ParseIndexExpression()); | 684 std::unique_ptr<CXFA_FMSimpleExpression> s = ParseIndexExpression(); |
| 687 if (!(m_pErrorInfo->message.IsEmpty())) { | 685 if (!(m_pErrorInfo->message.IsEmpty())) { |
| 688 delete e; | |
| 689 return nullptr; | 686 return nullptr; |
| 690 } | 687 } |
| 691 e = new CXFA_FMDotDotAccessorExpression(tempLine, e, TOKdotdot, | 688 expr = pdfium::MakeUnique<CXFA_FMDotDotAccessorExpression>( |
| 692 tempStr, s.release()); | 689 tempLine, expr.release(), TOKdotdot, tempStr, s.release()); |
| 693 } else { | 690 } else { |
| 694 CXFA_FMSimpleExpression* s = new CXFA_FMIndexExpression( | 691 std::unique_ptr<CXFA_FMSimpleExpression> s = |
| 695 tempLine, ACCESSOR_NO_INDEX, nullptr, false); | 692 pdfium::MakeUnique<CXFA_FMIndexExpression>( |
| 696 e = new CXFA_FMDotDotAccessorExpression(line, e, TOKdotdot, tempStr, | 693 tempLine, ACCESSOR_NO_INDEX, nullptr, false); |
| 697 s); | 694 expr = pdfium::MakeUnique<CXFA_FMDotDotAccessorExpression>( |
| 695 line, expr.release(), TOKdotdot, tempStr, s.release()); |
| 698 continue; | 696 continue; |
| 699 } | 697 } |
| 700 } else { | 698 } else { |
| 701 CFX_WideString ws_TempString(m_pToken->m_wstring); | 699 CFX_WideString ws_TempString(m_pToken->m_wstring); |
| 702 Error(m_pToken->m_uLinenum, kFMErrExpectedIdentifier, | 700 Error(m_pToken->m_uLinenum, kFMErrExpectedIdentifier, |
| 703 ws_TempString.c_str()); | 701 ws_TempString.c_str()); |
| 704 return e; | 702 return expr; |
| 705 } | 703 } |
| 706 break; | 704 break; |
| 707 case TOKdotscream: | 705 case TOKdotscream: |
| 708 NextToken(); | 706 NextToken(); |
| 709 if (m_pToken->m_type == TOKidentifier) { | 707 if (m_pToken->m_type == TOKidentifier) { |
| 710 CFX_WideStringC tempStr = m_pToken->m_wstring; | 708 CFX_WideStringC tempStr = m_pToken->m_wstring; |
| 711 uint32_t tempLine = m_pToken->m_uLinenum; | 709 uint32_t tempLine = m_pToken->m_uLinenum; |
| 712 NextToken(); | 710 NextToken(); |
| 713 if (m_pToken->m_type == TOKlbracket) { | 711 if (m_pToken->m_type == TOKlbracket) { |
| 714 std::unique_ptr<CXFA_FMSimpleExpression> s(ParseIndexExpression()); | 712 std::unique_ptr<CXFA_FMSimpleExpression> s = ParseIndexExpression(); |
| 715 if (!(m_pErrorInfo->message.IsEmpty())) { | 713 if (!(m_pErrorInfo->message.IsEmpty())) |
| 716 delete e; | |
| 717 return nullptr; | 714 return nullptr; |
| 718 } | 715 |
| 719 e = new CXFA_FMDotAccessorExpression(tempLine, e, TOKdotscream, | 716 expr = pdfium::MakeUnique<CXFA_FMDotAccessorExpression>( |
| 720 tempStr, s.release()); | 717 tempLine, expr.release(), TOKdotscream, tempStr, s.release()); |
| 721 } else { | 718 } else { |
| 722 CXFA_FMSimpleExpression* s = new CXFA_FMIndexExpression( | 719 std::unique_ptr<CXFA_FMSimpleExpression> s = |
| 723 tempLine, ACCESSOR_NO_INDEX, nullptr, false); | 720 pdfium::MakeUnique<CXFA_FMIndexExpression>( |
| 724 e = new CXFA_FMDotAccessorExpression(line, e, TOKdotscream, tempStr, | 721 tempLine, ACCESSOR_NO_INDEX, nullptr, false); |
| 725 s); | 722 expr = pdfium::MakeUnique<CXFA_FMDotAccessorExpression>( |
| 723 line, expr.release(), TOKdotscream, tempStr, s.release()); |
| 726 continue; | 724 continue; |
| 727 } | 725 } |
| 728 } else { | 726 } else { |
| 729 CFX_WideString ws_TempString(m_pToken->m_wstring); | 727 CFX_WideString ws_TempString(m_pToken->m_wstring); |
| 730 Error(m_pToken->m_uLinenum, kFMErrExpectedIdentifier, | 728 Error(m_pToken->m_uLinenum, kFMErrExpectedIdentifier, |
| 731 ws_TempString.c_str()); | 729 ws_TempString.c_str()); |
| 732 return e; | 730 return expr; |
| 733 } | 731 } |
| 734 break; | 732 break; |
| 735 case TOKdotstar: { | 733 case TOKdotstar: { |
| 736 CXFA_FMSimpleExpression* s = | 734 std::unique_ptr<CXFA_FMSimpleExpression> s = |
| 737 new CXFA_FMIndexExpression(line, ACCESSOR_NO_INDEX, nullptr, false); | 735 pdfium::MakeUnique<CXFA_FMIndexExpression>(line, ACCESSOR_NO_INDEX, |
| 738 e = new CXFA_FMDotAccessorExpression(line, e, TOKdotstar, | 736 nullptr, false); |
| 739 FX_WSTRC(L"*"), s); | 737 expr = pdfium::MakeUnique<CXFA_FMDotAccessorExpression>( |
| 738 line, expr.release(), TOKdotstar, FX_WSTRC(L"*"), s.release()); |
| 740 } break; | 739 } break; |
| 741 default: | 740 default: |
| 742 return e; | 741 return expr; |
| 743 } | 742 } |
| 744 NextToken(); | 743 NextToken(); |
| 745 } | 744 } |
| 746 return e; | 745 return expr; |
| 747 } | 746 } |
| 748 | 747 |
| 749 CXFA_FMSimpleExpression* CXFA_FMParse::ParseIndexExpression() { | 748 std::unique_ptr<CXFA_FMSimpleExpression> CXFA_FMParse::ParseIndexExpression() { |
| 750 std::unique_ptr<CXFA_FMSimpleExpression> pExp; | 749 std::unique_ptr<CXFA_FMSimpleExpression> pExp; |
| 751 uint32_t line = m_pToken->m_uLinenum; | 750 uint32_t line = m_pToken->m_uLinenum; |
| 752 NextToken(); | 751 NextToken(); |
| 753 std::unique_ptr<CXFA_FMSimpleExpression> s; | 752 std::unique_ptr<CXFA_FMSimpleExpression> s; |
| 754 XFA_FM_AccessorIndex accessorIndex = ACCESSOR_NO_RELATIVEINDEX; | 753 XFA_FM_AccessorIndex accessorIndex = ACCESSOR_NO_RELATIVEINDEX; |
| 755 if (m_pToken->m_type == TOKmul) { | 754 if (m_pToken->m_type == TOKmul) { |
| 756 pExp.reset( | 755 pExp = pdfium::MakeUnique<CXFA_FMIndexExpression>(line, accessorIndex, |
| 757 new CXFA_FMIndexExpression(line, accessorIndex, s.release(), true)); | 756 s.release(), true); |
| 758 NextToken(); | 757 NextToken(); |
| 759 if (m_pToken->m_type != TOKrbracket) { | 758 if (m_pToken->m_type != TOKrbracket) { |
| 760 CFX_WideString ws_TempString(m_pToken->m_wstring); | 759 CFX_WideString ws_TempString(m_pToken->m_wstring); |
| 761 Error(m_pToken->m_uLinenum, kFMErrExpectedToken, | 760 Error(m_pToken->m_uLinenum, kFMErrExpectedToken, |
| 762 XFA_FM_KeywordToString(TOKrparen), ws_TempString.c_str()); | 761 XFA_FM_KeywordToString(TOKrparen), ws_TempString.c_str()); |
| 763 pExp.reset(); | 762 pExp.reset(); |
| 764 } | 763 } |
| 765 return pExp.release(); | 764 return pExp; |
| 766 } | 765 } |
| 767 if (m_pToken->m_type == TOKplus) { | 766 if (m_pToken->m_type == TOKplus) { |
| 768 accessorIndex = ACCESSOR_POSITIVE_INDEX; | 767 accessorIndex = ACCESSOR_POSITIVE_INDEX; |
| 769 NextToken(); | 768 NextToken(); |
| 770 } else if (m_pToken->m_type == TOKminus) { | 769 } else if (m_pToken->m_type == TOKminus) { |
| 771 accessorIndex = ACCESSOR_NEGATIVE_INDEX; | 770 accessorIndex = ACCESSOR_NEGATIVE_INDEX; |
| 772 NextToken(); | 771 NextToken(); |
| 773 } | 772 } |
| 774 s.reset(ParseSimpleExpression()); | 773 s = ParseSimpleExpression(); |
| 775 if (m_pToken->m_type != TOKrbracket) { | 774 if (m_pToken->m_type != TOKrbracket) { |
| 776 CFX_WideString ws_TempString(m_pToken->m_wstring); | 775 CFX_WideString ws_TempString(m_pToken->m_wstring); |
| 777 Error(m_pToken->m_uLinenum, kFMErrExpectedToken, | 776 Error(m_pToken->m_uLinenum, kFMErrExpectedToken, |
| 778 XFA_FM_KeywordToString(TOKrparen), ws_TempString.c_str()); | 777 XFA_FM_KeywordToString(TOKrparen), ws_TempString.c_str()); |
| 779 } else { | 778 } else { |
| 780 pExp.reset( | 779 pExp = pdfium::MakeUnique<CXFA_FMIndexExpression>(line, accessorIndex, |
| 781 new CXFA_FMIndexExpression(line, accessorIndex, s.release(), false)); | 780 s.release(), false); |
| 782 } | 781 } |
| 783 return pExp.release(); | 782 return pExp; |
| 784 } | 783 } |
| 785 | 784 |
| 786 CXFA_FMSimpleExpression* CXFA_FMParse::ParseParenExpression() { | 785 std::unique_ptr<CXFA_FMSimpleExpression> CXFA_FMParse::ParseParenExpression() { |
| 787 Check(TOKlparen); | 786 Check(TOKlparen); |
| 788 | 787 |
| 789 if (m_pToken->m_type == TOKrparen) { | 788 if (m_pToken->m_type == TOKrparen) { |
| 790 Error(m_pToken->m_uLinenum, kFMErrExpectedNonEmptyExpression); | 789 Error(m_pToken->m_uLinenum, kFMErrExpectedNonEmptyExpression); |
| 791 NextToken(); | 790 NextToken(); |
| 792 return nullptr; | 791 return nullptr; |
| 793 } | 792 } |
| 794 | 793 |
| 795 uint32_t line = m_pToken->m_uLinenum; | 794 uint32_t line = m_pToken->m_uLinenum; |
| 796 std::unique_ptr<CXFA_FMSimpleExpression> pExp1(ParseLogicalOrExpression()); | 795 std::unique_ptr<CXFA_FMSimpleExpression> pExp1 = ParseLogicalOrExpression(); |
| 797 | 796 |
| 798 while (m_pToken->m_type == TOKassign) { | 797 while (m_pToken->m_type == TOKassign) { |
| 799 NextToken(); | 798 NextToken(); |
| 800 std::unique_ptr<CXFA_FMSimpleExpression> pExp2(ParseLogicalOrExpression()); | 799 std::unique_ptr<CXFA_FMSimpleExpression> pExp2 = ParseLogicalOrExpression(); |
| 801 if (m_pErrorInfo->message.IsEmpty()) { | 800 if (m_pErrorInfo->message.IsEmpty()) { |
| 802 pExp1.reset(new CXFA_FMAssignExpression(line, TOKassign, pExp1.release(), | 801 pExp1 = pdfium::MakeUnique<CXFA_FMAssignExpression>( |
| 803 pExp2.release())); | 802 line, TOKassign, pExp1.release(), pExp2.release()); |
| 804 } else { | 803 } else { |
| 805 pExp1.reset(); | 804 pExp1.reset(); |
| 806 } | 805 } |
| 807 } | 806 } |
| 808 Check(TOKrparen); | 807 Check(TOKrparen); |
| 809 return pExp1.release(); | 808 return pExp1; |
| 810 } | 809 } |
| 811 | 810 |
| 812 CXFA_FMExpression* CXFA_FMParse::ParseBlockExpression() { | 811 std::unique_ptr<CXFA_FMExpression> CXFA_FMParse::ParseBlockExpression() { |
| 813 uint32_t line = m_pToken->m_uLinenum; | 812 uint32_t line = m_pToken->m_uLinenum; |
| 814 CXFA_FMExpression* e = nullptr; | 813 std::unique_ptr<CXFA_FMExpression> expr; |
| 815 std::unique_ptr<CFX_ArrayTemplate<CXFA_FMExpression*>> expression( | 814 std::vector<std::unique_ptr<CXFA_FMExpression>> expressions; |
| 816 new CFX_ArrayTemplate<CXFA_FMExpression*>()); | |
| 817 | 815 |
| 818 while (1) { | 816 while (1) { |
| 819 switch (m_pToken->m_type) { | 817 switch (m_pToken->m_type) { |
| 820 case TOKeof: | 818 case TOKeof: |
| 821 case TOKendif: | 819 case TOKendif: |
| 822 case TOKelseif: | 820 case TOKelseif: |
| 823 case TOKelse: | 821 case TOKelse: |
| 824 case TOKendwhile: | 822 case TOKendwhile: |
| 825 case TOKendfor: | 823 case TOKendfor: |
| 826 case TOKend: | 824 case TOKend: |
| 827 case TOKendfunc: | 825 case TOKendfunc: |
| 828 case TOKreserver: | 826 case TOKreserver: |
| 829 break; | 827 break; |
| 830 case TOKfunc: | 828 case TOKfunc: |
| 831 e = ParseFunction(); | 829 expr = ParseFunction(); |
| 832 if (e) { | 830 if (expr) { |
| 833 expression->Add(e); | 831 expressions.push_back(std::move(expr)); |
| 834 } | 832 } |
| 835 continue; | 833 continue; |
| 836 default: | 834 default: |
| 837 e = ParseExpression(); | 835 expr = ParseExpression(); |
| 838 if (e) { | 836 if (expr) { |
| 839 expression->Add(e); | 837 expressions.push_back(std::move(expr)); |
| 840 } | 838 } |
| 841 continue; | 839 continue; |
| 842 } | 840 } |
| 843 break; | 841 break; |
| 844 } | 842 } |
| 845 std::unique_ptr<CXFA_FMBlockExpression> pExp; | 843 std::unique_ptr<CXFA_FMBlockExpression> pExp; |
| 846 if (m_pErrorInfo->message.IsEmpty()) { | 844 if (m_pErrorInfo->message.IsEmpty()) { |
| 847 pExp.reset(new CXFA_FMBlockExpression(line, expression.release())); | 845 pExp = pdfium::MakeUnique<CXFA_FMBlockExpression>(line, |
| 848 } else { | 846 std::move(expressions)); |
| 849 for (int i = 0; i < expression->GetSize(); ++i) | |
| 850 delete static_cast<CXFA_FMExpression*>(expression->GetAt(i)); | |
| 851 } | 847 } |
| 852 return pExp.release(); | 848 return pExp; |
| 853 } | 849 } |
| 854 | 850 |
| 855 CXFA_FMExpression* CXFA_FMParse::ParseIfExpression() { | 851 std::unique_ptr<CXFA_FMExpression> CXFA_FMParse::ParseIfExpression() { |
| 856 uint32_t line = m_pToken->m_uLinenum; | 852 uint32_t line = m_pToken->m_uLinenum; |
| 857 const FX_WCHAR* pStartPos = m_lexer->SavePos(); | 853 const FX_WCHAR* pStartPos = m_lexer->SavePos(); |
| 858 NextToken(); | 854 NextToken(); |
| 859 Check(TOKlparen); | 855 Check(TOKlparen); |
| 860 std::unique_ptr<CXFA_FMSimpleExpression> pExpression; | 856 std::unique_ptr<CXFA_FMSimpleExpression> pExpression; |
| 861 while (m_pToken->m_type != TOKrparen) { | 857 while (m_pToken->m_type != TOKrparen) { |
| 862 pExpression.reset(ParseSimpleExpression()); | 858 pExpression = ParseSimpleExpression(); |
| 863 if (m_pToken->m_type != TOKcomma) | 859 if (m_pToken->m_type != TOKcomma) |
| 864 break; | 860 break; |
| 865 NextToken(); | 861 NextToken(); |
| 866 } | 862 } |
| 867 Check(TOKrparen); | 863 Check(TOKrparen); |
| 868 if (m_pToken->m_type != TOKthen) { | 864 if (m_pToken->m_type != TOKthen) { |
| 869 m_lexer->SetCurrentLine(line); | 865 m_lexer->SetCurrentLine(line); |
| 870 m_pToken = new CXFA_FMToken(line); | 866 m_pToken = new CXFA_FMToken(line); |
| 871 m_pToken->m_type = TOKidentifier; | 867 m_pToken->m_type = TOKidentifier; |
| 872 m_pToken->m_wstring = FX_WSTRC(L"if"); | 868 m_pToken->m_wstring = FX_WSTRC(L"if"); |
| 873 m_lexer->SetToken(m_pToken); | 869 m_lexer->SetToken(m_pToken); |
| 874 m_lexer->RestorePos(pStartPos); | 870 m_lexer->RestorePos(pStartPos); |
| 875 return ParseExpExpression(); | 871 return ParseExpExpression(); |
| 876 } | 872 } |
| 877 Check(TOKthen); | 873 Check(TOKthen); |
| 878 std::unique_ptr<CXFA_FMExpression> pIfExpression(ParseBlockExpression()); | 874 std::unique_ptr<CXFA_FMExpression> pIfExpression = ParseBlockExpression(); |
| 879 std::unique_ptr<CXFA_FMExpression> pElseExpression; | 875 std::unique_ptr<CXFA_FMExpression> pElseExpression; |
| 880 switch (m_pToken->m_type) { | 876 switch (m_pToken->m_type) { |
| 881 case TOKeof: | 877 case TOKeof: |
| 882 case TOKendif: | 878 case TOKendif: |
| 883 Check(TOKendif); | 879 Check(TOKendif); |
| 884 break; | 880 break; |
| 885 case TOKif: | 881 case TOKif: |
| 886 pElseExpression.reset(ParseIfExpression()); | 882 pElseExpression = ParseIfExpression(); |
| 887 Check(TOKendif); | 883 Check(TOKendif); |
| 888 break; | 884 break; |
| 889 case TOKelseif: | 885 case TOKelseif: |
| 890 pElseExpression.reset(ParseIfExpression()); | 886 pElseExpression = ParseIfExpression(); |
| 891 break; | 887 break; |
| 892 case TOKelse: | 888 case TOKelse: |
| 893 NextToken(); | 889 NextToken(); |
| 894 pElseExpression.reset(ParseBlockExpression()); | 890 pElseExpression = ParseBlockExpression(); |
| 895 Check(TOKendif); | 891 Check(TOKendif); |
| 896 break; | 892 break; |
| 897 default: | 893 default: |
| 898 CFX_WideString ws_TempString(m_pToken->m_wstring); | 894 CFX_WideString ws_TempString(m_pToken->m_wstring); |
| 899 Error(m_pToken->m_uLinenum, kFMErrExpectedEndIf, ws_TempString.c_str()); | 895 Error(m_pToken->m_uLinenum, kFMErrExpectedEndIf, ws_TempString.c_str()); |
| 900 NextToken(); | 896 NextToken(); |
| 901 break; | 897 break; |
| 902 } | 898 } |
| 903 std::unique_ptr<CXFA_FMIfExpression> pExp; | 899 std::unique_ptr<CXFA_FMIfExpression> pExp; |
| 904 if (m_pErrorInfo->message.IsEmpty()) { | 900 if (m_pErrorInfo->message.IsEmpty()) { |
| 905 pExp.reset(new CXFA_FMIfExpression(line, pExpression.release(), | 901 pExp = pdfium::MakeUnique<CXFA_FMIfExpression>(line, pExpression.release(), |
| 906 pIfExpression.release(), | 902 pIfExpression.release(), |
| 907 pElseExpression.release())); | 903 pElseExpression.release()); |
| 908 } | 904 } |
| 909 return pExp.release(); | 905 return pExp; |
| 910 } | 906 } |
| 911 | 907 |
| 912 CXFA_FMExpression* CXFA_FMParse::ParseWhileExpression() { | 908 std::unique_ptr<CXFA_FMExpression> CXFA_FMParse::ParseWhileExpression() { |
| 913 uint32_t line = m_pToken->m_uLinenum; | 909 uint32_t line = m_pToken->m_uLinenum; |
| 914 NextToken(); | 910 NextToken(); |
| 915 std::unique_ptr<CXFA_FMSimpleExpression> pCondition(ParseParenExpression()); | 911 std::unique_ptr<CXFA_FMSimpleExpression> pCondition = ParseParenExpression(); |
| 916 Check(TOKdo); | 912 Check(TOKdo); |
| 917 std::unique_ptr<CXFA_FMExpression> pExpression(ParseBlockExpression()); | 913 std::unique_ptr<CXFA_FMExpression> pExpression = ParseBlockExpression(); |
| 918 Check(TOKendwhile); | 914 Check(TOKendwhile); |
| 919 std::unique_ptr<CXFA_FMExpression> e; | 915 std::unique_ptr<CXFA_FMExpression> expr; |
| 920 if (m_pErrorInfo->message.IsEmpty()) { | 916 if (m_pErrorInfo->message.IsEmpty()) { |
| 921 e.reset(new CXFA_FMWhileExpression(line, pCondition.release(), | 917 expr = pdfium::MakeUnique<CXFA_FMWhileExpression>( |
| 922 pExpression.release())); | 918 line, pCondition.release(), pExpression.release()); |
| 923 } | 919 } |
| 924 return e.release(); | 920 return expr; |
| 925 } | 921 } |
| 926 | 922 |
| 927 CXFA_FMSimpleExpression* CXFA_FMParse::ParseSubassignmentInForExpression() { | 923 std::unique_ptr<CXFA_FMSimpleExpression> |
| 928 std::unique_ptr<CXFA_FMSimpleExpression> e; | 924 CXFA_FMParse::ParseSubassignmentInForExpression() { |
| 925 std::unique_ptr<CXFA_FMSimpleExpression> expr; |
| 929 switch (m_pToken->m_type) { | 926 switch (m_pToken->m_type) { |
| 930 case TOKidentifier: | 927 case TOKidentifier: |
| 931 e.reset(ParseSimpleExpression()); | 928 expr = ParseSimpleExpression(); |
| 932 break; | 929 break; |
| 933 default: | 930 default: |
| 934 CFX_WideString ws_TempString(m_pToken->m_wstring); | 931 CFX_WideString ws_TempString(m_pToken->m_wstring); |
| 935 Error(m_pToken->m_uLinenum, kFMErrUnexpectedExpression, | 932 Error(m_pToken->m_uLinenum, kFMErrUnexpectedExpression, |
| 936 ws_TempString.c_str()); | 933 ws_TempString.c_str()); |
| 937 NextToken(); | 934 NextToken(); |
| 938 break; | 935 break; |
| 939 } | 936 } |
| 940 return e.release(); | 937 return expr; |
| 941 } | 938 } |
| 942 | 939 |
| 943 CXFA_FMExpression* CXFA_FMParse::ParseForExpression() { | 940 std::unique_ptr<CXFA_FMExpression> CXFA_FMParse::ParseForExpression() { |
| 944 CFX_WideStringC wsVariant; | 941 CFX_WideStringC wsVariant; |
| 945 uint32_t line = m_pToken->m_uLinenum; | 942 uint32_t line = m_pToken->m_uLinenum; |
| 946 NextToken(); | 943 NextToken(); |
| 947 if (m_pToken->m_type != TOKidentifier) { | 944 if (m_pToken->m_type != TOKidentifier) { |
| 948 CFX_WideString ws_TempString(m_pToken->m_wstring); | 945 CFX_WideString ws_TempString(m_pToken->m_wstring); |
| 949 Error(m_pToken->m_uLinenum, kFMErrExpectedToken, | 946 Error(m_pToken->m_uLinenum, kFMErrExpectedToken, |
| 950 XFA_FM_KeywordToString(m_pToken->m_type), ws_TempString.c_str()); | 947 XFA_FM_KeywordToString(m_pToken->m_type), ws_TempString.c_str()); |
| 951 } | 948 } |
| 952 wsVariant = m_pToken->m_wstring; | 949 wsVariant = m_pToken->m_wstring; |
| 953 NextToken(); | 950 NextToken(); |
| 954 std::unique_ptr<CXFA_FMSimpleExpression> pAssignment; | 951 std::unique_ptr<CXFA_FMSimpleExpression> pAssignment; |
| 955 if (m_pToken->m_type == TOKassign) { | 952 if (m_pToken->m_type == TOKassign) { |
| 956 NextToken(); | 953 NextToken(); |
| 957 pAssignment.reset(ParseSimpleExpression()); | 954 pAssignment = ParseSimpleExpression(); |
| 958 } else { | 955 } else { |
| 959 CFX_WideString ws_TempString(m_pToken->m_wstring); | 956 CFX_WideString ws_TempString(m_pToken->m_wstring); |
| 960 Error(m_pToken->m_uLinenum, kFMErrExpectedToken, | 957 Error(m_pToken->m_uLinenum, kFMErrExpectedToken, |
| 961 XFA_FM_KeywordToString(m_pToken->m_type), ws_TempString.c_str()); | 958 XFA_FM_KeywordToString(m_pToken->m_type), ws_TempString.c_str()); |
| 962 } | 959 } |
| 963 int32_t iDirection = 0; | 960 int32_t iDirection = 0; |
| 964 if (m_pToken->m_type == TOKupto) { | 961 if (m_pToken->m_type == TOKupto) { |
| 965 iDirection = 1; | 962 iDirection = 1; |
| 966 } else if (m_pToken->m_type == TOKdownto) { | 963 } else if (m_pToken->m_type == TOKdownto) { |
| 967 iDirection = -1; | 964 iDirection = -1; |
| 968 } else { | 965 } else { |
| 969 CFX_WideString ws_TempString(m_pToken->m_wstring); | 966 CFX_WideString ws_TempString(m_pToken->m_wstring); |
| 970 Error(m_pToken->m_uLinenum, kFMErrExpectedToken, L"upto or downto", | 967 Error(m_pToken->m_uLinenum, kFMErrExpectedToken, L"upto or downto", |
| 971 ws_TempString.c_str()); | 968 ws_TempString.c_str()); |
| 972 } | 969 } |
| 973 NextToken(); | 970 NextToken(); |
| 974 std::unique_ptr<CXFA_FMSimpleExpression> pAccessor(ParseSimpleExpression()); | 971 std::unique_ptr<CXFA_FMSimpleExpression> pAccessor = ParseSimpleExpression(); |
| 975 std::unique_ptr<CXFA_FMSimpleExpression> pStep; | 972 std::unique_ptr<CXFA_FMSimpleExpression> pStep; |
| 976 if (m_pToken->m_type == TOKstep) { | 973 if (m_pToken->m_type == TOKstep) { |
| 977 NextToken(); | 974 NextToken(); |
| 978 pStep.reset(ParseSimpleExpression()); | 975 pStep = ParseSimpleExpression(); |
| 979 } | 976 } |
| 980 Check(TOKdo); | 977 Check(TOKdo); |
| 981 std::unique_ptr<CXFA_FMExpression> pList(ParseBlockExpression()); | 978 std::unique_ptr<CXFA_FMExpression> pList = ParseBlockExpression(); |
| 982 Check(TOKendfor); | 979 Check(TOKendfor); |
| 983 std::unique_ptr<CXFA_FMExpression> e; | 980 std::unique_ptr<CXFA_FMExpression> expr; |
| 984 if (m_pErrorInfo->message.IsEmpty()) { | 981 if (m_pErrorInfo->message.IsEmpty()) { |
| 985 e.reset(new CXFA_FMForExpression(line, wsVariant, pAssignment.release(), | 982 expr = pdfium::MakeUnique<CXFA_FMForExpression>( |
| 986 pAccessor.release(), iDirection, | 983 line, wsVariant, pAssignment.release(), pAccessor.release(), iDirection, |
| 987 pStep.release(), pList.release())); | 984 pStep.release(), pList.release()); |
| 988 } | 985 } |
| 989 return e.release(); | 986 return expr; |
| 990 } | 987 } |
| 991 | 988 |
| 992 CXFA_FMExpression* CXFA_FMParse::ParseForeachExpression() { | 989 std::unique_ptr<CXFA_FMExpression> CXFA_FMParse::ParseForeachExpression() { |
| 993 std::unique_ptr<CXFA_FMExpression> e; | 990 std::unique_ptr<CXFA_FMExpression> expr; |
| 994 CFX_WideStringC wsIdentifier; | 991 CFX_WideStringC wsIdentifier; |
| 995 std::vector<std::unique_ptr<CXFA_FMSimpleExpression>> pAccessors; | 992 std::vector<std::unique_ptr<CXFA_FMSimpleExpression>> pAccessors; |
| 996 std::unique_ptr<CXFA_FMExpression> pList; | 993 std::unique_ptr<CXFA_FMExpression> pList; |
| 997 uint32_t line = m_pToken->m_uLinenum; | 994 uint32_t line = m_pToken->m_uLinenum; |
| 998 NextToken(); | 995 NextToken(); |
| 999 if (m_pToken->m_type != TOKidentifier) { | 996 if (m_pToken->m_type != TOKidentifier) { |
| 1000 CFX_WideString ws_TempString(m_pToken->m_wstring); | 997 CFX_WideString ws_TempString(m_pToken->m_wstring); |
| 1001 Error(m_pToken->m_uLinenum, kFMErrExpectedToken, | 998 Error(m_pToken->m_uLinenum, kFMErrExpectedToken, |
| 1002 XFA_FM_KeywordToString(m_pToken->m_type), ws_TempString.c_str()); | 999 XFA_FM_KeywordToString(m_pToken->m_type), ws_TempString.c_str()); |
| 1003 } | 1000 } |
| 1004 wsIdentifier = m_pToken->m_wstring; | 1001 wsIdentifier = m_pToken->m_wstring; |
| 1005 NextToken(); | 1002 NextToken(); |
| 1006 Check(TOKin); | 1003 Check(TOKin); |
| 1007 Check(TOKlparen); | 1004 Check(TOKlparen); |
| 1008 if (m_pToken->m_type == TOKrparen) { | 1005 if (m_pToken->m_type == TOKrparen) { |
| 1009 CFX_WideString ws_TempString(m_pToken->m_wstring); | 1006 CFX_WideString ws_TempString(m_pToken->m_wstring); |
| 1010 Error(m_pToken->m_uLinenum, kFMErrUnexpectedExpression, | 1007 Error(m_pToken->m_uLinenum, kFMErrUnexpectedExpression, |
| 1011 ws_TempString.c_str()); | 1008 ws_TempString.c_str()); |
| 1012 NextToken(); | 1009 NextToken(); |
| 1013 } else { | 1010 } else { |
| 1014 while (m_pToken->m_type != TOKrparen) { | 1011 while (m_pToken->m_type != TOKrparen) { |
| 1015 CXFA_FMSimpleExpression* s = ParseSimpleExpression(); | 1012 std::unique_ptr<CXFA_FMSimpleExpression> s = ParseSimpleExpression(); |
| 1016 if (s) | 1013 if (s) |
| 1017 pAccessors.push_back(pdfium::WrapUnique<CXFA_FMSimpleExpression>(s)); | 1014 pAccessors.push_back(std::move(s)); |
| 1018 if (m_pToken->m_type != TOKcomma) | 1015 if (m_pToken->m_type != TOKcomma) |
| 1019 break; | 1016 break; |
| 1020 NextToken(); | 1017 NextToken(); |
| 1021 } | 1018 } |
| 1022 Check(TOKrparen); | 1019 Check(TOKrparen); |
| 1023 } | 1020 } |
| 1024 Check(TOKdo); | 1021 Check(TOKdo); |
| 1025 pList.reset(ParseBlockExpression()); | 1022 pList = ParseBlockExpression(); |
| 1026 Check(TOKendfor); | 1023 Check(TOKendfor); |
| 1027 if (m_pErrorInfo->message.IsEmpty()) { | 1024 if (m_pErrorInfo->message.IsEmpty()) { |
| 1028 e = pdfium::MakeUnique<CXFA_FMForeachExpression>( | 1025 expr = pdfium::MakeUnique<CXFA_FMForeachExpression>( |
| 1029 line, wsIdentifier, std::move(pAccessors), pList.release()); | 1026 line, wsIdentifier, std::move(pAccessors), pList.release()); |
| 1030 } | 1027 } |
| 1031 return e.release(); | 1028 return expr; |
| 1032 } | 1029 } |
| 1033 | 1030 |
| 1034 CXFA_FMExpression* CXFA_FMParse::ParseDoExpression() { | 1031 std::unique_ptr<CXFA_FMExpression> CXFA_FMParse::ParseDoExpression() { |
| 1035 std::unique_ptr<CXFA_FMExpression> e; | |
| 1036 uint32_t line = m_pToken->m_uLinenum; | 1032 uint32_t line = m_pToken->m_uLinenum; |
| 1037 NextToken(); | 1033 NextToken(); |
| 1038 e.reset(ParseBlockExpression()); | 1034 std::unique_ptr<CXFA_FMExpression> expr = ParseBlockExpression(); |
| 1039 Check(TOKend); | 1035 Check(TOKend); |
| 1040 if (m_pErrorInfo->message.IsEmpty()) { | 1036 if (m_pErrorInfo->message.IsEmpty()) { |
| 1041 e.reset(new CXFA_FMDoExpression(line, e.release())); | 1037 expr = pdfium::MakeUnique<CXFA_FMDoExpression>(line, expr.release()); |
| 1042 } else { | 1038 } else { |
| 1043 e.reset(); | 1039 expr.reset(); |
| 1044 } | 1040 } |
| 1045 return e.release(); | 1041 return expr; |
| 1046 } | 1042 } |
| OLD | NEW |