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