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> |
| 12 |
| 13 #include "third_party/base/ptr_util.h" |
11 | 14 |
12 CXFA_FMParse::CXFA_FMParse() : m_pToken(nullptr), m_pErrorInfo(0) {} | 15 CXFA_FMParse::CXFA_FMParse() : m_pToken(nullptr), m_pErrorInfo(0) {} |
13 | 16 |
14 CXFA_FMParse::~CXFA_FMParse() {} | 17 CXFA_FMParse::~CXFA_FMParse() {} |
15 | 18 |
16 int32_t CXFA_FMParse::Init(const CFX_WideStringC& wsFormcalc, | 19 int32_t CXFA_FMParse::Init(const CFX_WideStringC& wsFormcalc, |
17 CXFA_FMErrorInfo* pErrorInfo) { | 20 CXFA_FMErrorInfo* pErrorInfo) { |
18 m_pErrorInfo = pErrorInfo; | 21 m_pErrorInfo = pErrorInfo; |
19 m_lexer.reset(new CXFA_FMLexer(wsFormcalc, m_pErrorInfo)); | 22 m_lexer.reset(new CXFA_FMLexer(wsFormcalc, m_pErrorInfo)); |
20 return 0; | 23 return 0; |
(...skipping 961 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
982 e.reset(new CXFA_FMForExpression(line, wsVariant, pAssignment.release(), | 985 e.reset(new CXFA_FMForExpression(line, wsVariant, pAssignment.release(), |
983 pAccessor.release(), iDirection, | 986 pAccessor.release(), iDirection, |
984 pStep.release(), pList.release())); | 987 pStep.release(), pList.release())); |
985 } | 988 } |
986 return e.release(); | 989 return e.release(); |
987 } | 990 } |
988 | 991 |
989 CXFA_FMExpression* CXFA_FMParse::ParseForeachExpression() { | 992 CXFA_FMExpression* CXFA_FMParse::ParseForeachExpression() { |
990 std::unique_ptr<CXFA_FMExpression> e; | 993 std::unique_ptr<CXFA_FMExpression> e; |
991 CFX_WideStringC wsIdentifier; | 994 CFX_WideStringC wsIdentifier; |
992 std::unique_ptr<CFX_ArrayTemplate<CXFA_FMSimpleExpression*>> pAccessors; | 995 std::vector<std::unique_ptr<CXFA_FMSimpleExpression>> pAccessors; |
993 std::unique_ptr<CXFA_FMExpression> pList; | 996 std::unique_ptr<CXFA_FMExpression> pList; |
994 uint32_t line = m_pToken->m_uLinenum; | 997 uint32_t line = m_pToken->m_uLinenum; |
995 NextToken(); | 998 NextToken(); |
996 if (m_pToken->m_type != TOKidentifier) { | 999 if (m_pToken->m_type != TOKidentifier) { |
997 CFX_WideString ws_TempString(m_pToken->m_wstring); | 1000 CFX_WideString ws_TempString(m_pToken->m_wstring); |
998 Error(m_pToken->m_uLinenum, kFMErrExpectedToken, | 1001 Error(m_pToken->m_uLinenum, kFMErrExpectedToken, |
999 XFA_FM_KeywordToString(m_pToken->m_type), ws_TempString.c_str()); | 1002 XFA_FM_KeywordToString(m_pToken->m_type), ws_TempString.c_str()); |
1000 } | 1003 } |
1001 wsIdentifier = m_pToken->m_wstring; | 1004 wsIdentifier = m_pToken->m_wstring; |
1002 NextToken(); | 1005 NextToken(); |
1003 Check(TOKin); | 1006 Check(TOKin); |
1004 Check(TOKlparen); | 1007 Check(TOKlparen); |
1005 if (m_pToken->m_type == TOKrparen) { | 1008 if (m_pToken->m_type == TOKrparen) { |
1006 CFX_WideString ws_TempString(m_pToken->m_wstring); | 1009 CFX_WideString ws_TempString(m_pToken->m_wstring); |
1007 Error(m_pToken->m_uLinenum, kFMErrUnexpectedExpression, | 1010 Error(m_pToken->m_uLinenum, kFMErrUnexpectedExpression, |
1008 ws_TempString.c_str()); | 1011 ws_TempString.c_str()); |
1009 NextToken(); | 1012 NextToken(); |
1010 } else { | 1013 } else { |
1011 pAccessors.reset(new CFX_ArrayTemplate<CXFA_FMSimpleExpression*>()); | |
1012 while (m_pToken->m_type != TOKrparen) { | 1014 while (m_pToken->m_type != TOKrparen) { |
1013 CXFA_FMSimpleExpression* s = ParseSimpleExpression(); | 1015 CXFA_FMSimpleExpression* s = ParseSimpleExpression(); |
1014 if (s) { | 1016 if (s) |
1015 pAccessors->Add(s); | 1017 pAccessors.push_back(pdfium::WrapUnique<CXFA_FMSimpleExpression>(s)); |
1016 } | 1018 if (m_pToken->m_type != TOKcomma) |
1017 if (m_pToken->m_type == TOKcomma) { | |
1018 NextToken(); | |
1019 } else { | |
1020 break; | 1019 break; |
1021 } | 1020 NextToken(); |
1022 } | 1021 } |
1023 Check(TOKrparen); | 1022 Check(TOKrparen); |
1024 } | 1023 } |
1025 Check(TOKdo); | 1024 Check(TOKdo); |
1026 pList.reset(ParseBlockExpression()); | 1025 pList.reset(ParseBlockExpression()); |
1027 Check(TOKendfor); | 1026 Check(TOKendfor); |
1028 if (m_pErrorInfo->message.IsEmpty()) { | 1027 if (m_pErrorInfo->message.IsEmpty()) { |
1029 e.reset(new CXFA_FMForeachExpression( | 1028 e = pdfium::MakeUnique<CXFA_FMForeachExpression>( |
1030 line, wsIdentifier, pAccessors.release(), pList.release())); | 1029 line, wsIdentifier, std::move(pAccessors), pList.release()); |
1031 } else { | |
1032 if (pAccessors) { | |
1033 for (int i = 0; i < pAccessors->GetSize(); ++i) | |
1034 delete static_cast<CXFA_FMSimpleExpression*>(pAccessors->GetAt(i)); | |
1035 } | |
1036 } | 1030 } |
1037 return e.release(); | 1031 return e.release(); |
1038 } | 1032 } |
1039 | 1033 |
1040 CXFA_FMExpression* CXFA_FMParse::ParseDoExpression() { | 1034 CXFA_FMExpression* CXFA_FMParse::ParseDoExpression() { |
1041 std::unique_ptr<CXFA_FMExpression> e; | 1035 std::unique_ptr<CXFA_FMExpression> e; |
1042 uint32_t line = m_pToken->m_uLinenum; | 1036 uint32_t line = m_pToken->m_uLinenum; |
1043 NextToken(); | 1037 NextToken(); |
1044 e.reset(ParseBlockExpression()); | 1038 e.reset(ParseBlockExpression()); |
1045 Check(TOKend); | 1039 Check(TOKend); |
1046 if (m_pErrorInfo->message.IsEmpty()) { | 1040 if (m_pErrorInfo->message.IsEmpty()) { |
1047 e.reset(new CXFA_FMDoExpression(line, e.release())); | 1041 e.reset(new CXFA_FMDoExpression(line, e.release())); |
1048 } else { | 1042 } else { |
1049 e.reset(); | 1043 e.reset(); |
1050 } | 1044 } |
1051 return e.release(); | 1045 return e.release(); |
1052 } | 1046 } |
OLD | NEW |