diff options
Diffstat (limited to 'xfa/fxfa/fm2js/xfa_fmparse.cpp')
-rw-r--r-- | xfa/fxfa/fm2js/xfa_fmparse.cpp | 580 |
1 files changed, 288 insertions, 292 deletions
diff --git a/xfa/fxfa/fm2js/xfa_fmparse.cpp b/xfa/fxfa/fm2js/xfa_fmparse.cpp index 36663fce2d..07edc32c3d 100644 --- a/xfa/fxfa/fm2js/xfa_fmparse.cpp +++ b/xfa/fxfa/fm2js/xfa_fmparse.cpp @@ -19,7 +19,7 @@ CXFA_FMParse::~CXFA_FMParse() {} int32_t CXFA_FMParse::Init(const CFX_WideStringC& wsFormcalc, CXFA_FMErrorInfo* pErrorInfo) { m_pErrorInfo = pErrorInfo; - m_lexer.reset(new CXFA_FMLexer(wsFormcalc, m_pErrorInfo)); + m_lexer = pdfium::MakeUnique<CXFA_FMLexer>(wsFormcalc, m_pErrorInfo); return 0; } @@ -50,41 +50,41 @@ void CXFA_FMParse::Error(uint32_t lineNum, const FX_WCHAR* msg, ...) { va_end(ap); } -CFX_ArrayTemplate<CXFA_FMExpression*>* CXFA_FMParse::ParseTopExpression() { - std::unique_ptr<CXFA_FMExpression> e; - CFX_ArrayTemplate<CXFA_FMExpression*>* expression = - new CFX_ArrayTemplate<CXFA_FMExpression*>(); +std::vector<std::unique_ptr<CXFA_FMExpression>> +CXFA_FMParse::ParseTopExpression() { + std::unique_ptr<CXFA_FMExpression> expr; + std::vector<std::unique_ptr<CXFA_FMExpression>> expressions; while (1) { if (m_pToken->m_type == TOKeof || m_pToken->m_type == TOKendfunc || m_pToken->m_type == TOKendif || m_pToken->m_type == TOKelseif || m_pToken->m_type == TOKelse || m_pToken->m_type == TOKreserver) { - return expression; + return expressions; } if (m_pToken->m_type == TOKfunc) { - e.reset(ParseFunction()); - if (e) { - expression->Add(e.release()); + expr = ParseFunction(); + if (expr) { + expressions.push_back(std::move(expr)); } else { break; } } else { - e.reset(ParseExpression()); - if (e) { - expression->Add(e.release()); + expr = ParseExpression(); + if (expr) { + expressions.push_back(std::move(expr)); } else { break; } } } - return expression; + return expressions; } -CXFA_FMExpression* CXFA_FMParse::ParseFunction() { - std::unique_ptr<CXFA_FMExpression> e; +std::unique_ptr<CXFA_FMExpression> CXFA_FMParse::ParseFunction() { + std::unique_ptr<CXFA_FMExpression> expr; CFX_WideStringC ident; std::unique_ptr<CFX_WideStringCArray> pArguments; - std::unique_ptr<CFX_ArrayTemplate<CXFA_FMExpression*>> pExpressions; + std::vector<std::unique_ptr<CXFA_FMExpression>> expressions; uint32_t line = m_pToken->m_uLinenum; NextToken(); if (m_pToken->m_type != TOKidentifier) { @@ -99,7 +99,7 @@ CXFA_FMExpression* CXFA_FMParse::ParseFunction() { if (m_pToken->m_type == TOKrparen) { NextToken(); } else { - pArguments.reset(new CFX_WideStringCArray()); + pArguments = pdfium::MakeUnique<CFX_WideStringCArray>(); CFX_WideStringC p; while (1) { if (m_pToken->m_type == TOKidentifier) { @@ -129,29 +129,24 @@ CXFA_FMExpression* CXFA_FMParse::ParseFunction() { if (m_pToken->m_type == TOKendfunc) { NextToken(); } else { - pExpressions.reset(ParseTopExpression()); + expressions = ParseTopExpression(); Check(TOKendfunc); } if (m_pErrorInfo->message.IsEmpty()) { - e.reset(new CXFA_FMFunctionDefinition(line, 0, ident, std::move(pArguments), - pExpressions.release())); - } else { - if (pArguments) - pArguments->RemoveAll(); - if (pExpressions) { - for (int i = 0; i < pExpressions->GetSize(); ++i) - delete pExpressions->GetAt(i); - } + expr = pdfium::MakeUnique<CXFA_FMFunctionDefinition>( + line, false, ident, std::move(pArguments), std::move(expressions)); + } else if (pArguments) { + pArguments->RemoveAll(); } - return e.release(); + return expr; } -CXFA_FMExpression* CXFA_FMParse::ParseExpression() { - std::unique_ptr<CXFA_FMExpression> e; +std::unique_ptr<CXFA_FMExpression> CXFA_FMParse::ParseExpression() { + std::unique_ptr<CXFA_FMExpression> expr; uint32_t line = m_pToken->m_uLinenum; switch (m_pToken->m_type) { case TOKvar: - e.reset(ParseVarExpression()); + expr = ParseVarExpression(); break; case TOKnull: case TOKnumber: @@ -161,29 +156,29 @@ CXFA_FMExpression* CXFA_FMParse::ParseExpression() { case TOKksnot: case TOKidentifier: case TOKlparen: - e.reset(ParseExpExpression()); + expr = ParseExpExpression(); break; case TOKif: - e.reset(ParseIfExpression()); + expr = ParseIfExpression(); break; case TOKwhile: - e.reset(ParseWhileExpression()); + expr = ParseWhileExpression(); break; case TOKfor: - e.reset(ParseForExpression()); + expr = ParseForExpression(); break; case TOKforeach: - e.reset(ParseForeachExpression()); + expr = ParseForeachExpression(); break; case TOKdo: - e.reset(ParseDoExpression()); + expr = ParseDoExpression(); break; case TOKbreak: - e.reset(new CXFA_FMBreakExpression(line)); + expr = pdfium::MakeUnique<CXFA_FMBreakExpression>(line); NextToken(); break; case TOKcontinue: - e.reset(new CXFA_FMContinueExpression(line)); + expr = pdfium::MakeUnique<CXFA_FMContinueExpression>(line); NextToken(); break; default: @@ -193,11 +188,11 @@ CXFA_FMExpression* CXFA_FMParse::ParseExpression() { NextToken(); break; } - return e.release(); + return expr; } -CXFA_FMExpression* CXFA_FMParse::ParseVarExpression() { - std::unique_ptr<CXFA_FMExpression> e; +std::unique_ptr<CXFA_FMExpression> CXFA_FMParse::ParseVarExpression() { + std::unique_ptr<CXFA_FMExpression> expr; CFX_WideStringC ident; uint32_t line = m_pToken->m_uLinenum; NextToken(); @@ -211,47 +206,49 @@ CXFA_FMExpression* CXFA_FMParse::ParseVarExpression() { } if (m_pToken->m_type == TOKassign) { NextToken(); - e.reset(ParseExpExpression()); + expr = ParseExpExpression(); } if (m_pErrorInfo->message.IsEmpty()) { - e.reset(new CXFA_FMVarExpression(line, ident, e.release())); + expr = + pdfium::MakeUnique<CXFA_FMVarExpression>(line, ident, expr.release()); } else { - e.reset(); + expr.reset(); } - return e.release(); + return expr; } -CXFA_FMSimpleExpression* CXFA_FMParse::ParseSimpleExpression() { +std::unique_ptr<CXFA_FMSimpleExpression> CXFA_FMParse::ParseSimpleExpression() { uint32_t line = m_pToken->m_uLinenum; - std::unique_ptr<CXFA_FMSimpleExpression> pExp1(ParseLogicalOrExpression()); + std::unique_ptr<CXFA_FMSimpleExpression> pExp1 = ParseLogicalOrExpression(); while (m_pToken->m_type == TOKassign) { NextToken(); - std::unique_ptr<CXFA_FMSimpleExpression> pExp2(ParseLogicalOrExpression()); + std::unique_ptr<CXFA_FMSimpleExpression> pExp2 = ParseLogicalOrExpression(); if (m_pErrorInfo->message.IsEmpty()) { - pExp1.reset(new CXFA_FMAssignExpression(line, TOKassign, pExp1.release(), - pExp2.release())); + pExp1 = pdfium::MakeUnique<CXFA_FMAssignExpression>( + line, TOKassign, pExp1.release(), pExp2.release()); } else { pExp1.reset(); } } - return pExp1.release(); + return pExp1; } -CXFA_FMExpression* CXFA_FMParse::ParseExpExpression() { +std::unique_ptr<CXFA_FMExpression> CXFA_FMParse::ParseExpExpression() { uint32_t line = m_pToken->m_uLinenum; - std::unique_ptr<CXFA_FMSimpleExpression> pExp1(ParseSimpleExpression()); - std::unique_ptr<CXFA_FMExpression> e; + std::unique_ptr<CXFA_FMSimpleExpression> pExp1 = ParseSimpleExpression(); + std::unique_ptr<CXFA_FMExpression> expr; if (m_pErrorInfo->message.IsEmpty()) { - e.reset(new CXFA_FMExpExpression(line, pExp1.release())); + expr = pdfium::MakeUnique<CXFA_FMExpExpression>(line, pExp1.release()); } else { - e.reset(); + expr.reset(); } - return e.release(); + return expr; } -CXFA_FMSimpleExpression* CXFA_FMParse::ParseLogicalOrExpression() { +std::unique_ptr<CXFA_FMSimpleExpression> +CXFA_FMParse::ParseLogicalOrExpression() { uint32_t line = m_pToken->m_uLinenum; - std::unique_ptr<CXFA_FMSimpleExpression> e1(ParseLogicalAndExpression()); + std::unique_ptr<CXFA_FMSimpleExpression> e1 = ParseLogicalAndExpression(); for (;;) { switch (m_pToken->m_type) { case TOKor: @@ -260,8 +257,8 @@ CXFA_FMSimpleExpression* CXFA_FMParse::ParseLogicalOrExpression() { std::unique_ptr<CXFA_FMSimpleExpression> e2( ParseLogicalAndExpression()); if (m_pErrorInfo->message.IsEmpty()) { - e1.reset(new CXFA_FMLogicalOrExpression(line, TOKor, e1.release(), - e2.release())); + e1 = pdfium::MakeUnique<CXFA_FMLogicalOrExpression>( + line, TOKor, e1.release(), e2.release()); } else { e1.reset(); } @@ -272,21 +269,22 @@ CXFA_FMSimpleExpression* CXFA_FMParse::ParseLogicalOrExpression() { } break; } - return e1.release(); + return e1; } -CXFA_FMSimpleExpression* CXFA_FMParse::ParseLogicalAndExpression() { +std::unique_ptr<CXFA_FMSimpleExpression> +CXFA_FMParse::ParseLogicalAndExpression() { uint32_t line = m_pToken->m_uLinenum; - std::unique_ptr<CXFA_FMSimpleExpression> e1(ParseEqualityExpression()); + std::unique_ptr<CXFA_FMSimpleExpression> e1 = ParseEqualityExpression(); for (;;) { switch (m_pToken->m_type) { case TOKand: case TOKksand: { NextToken(); - std::unique_ptr<CXFA_FMSimpleExpression> e2(ParseEqualityExpression()); + std::unique_ptr<CXFA_FMSimpleExpression> e2 = ParseEqualityExpression(); if (m_pErrorInfo->message.IsEmpty()) { - e1.reset(new CXFA_FMLogicalAndExpression(line, TOKand, e1.release(), - e2.release())); + e1 = pdfium::MakeUnique<CXFA_FMLogicalAndExpression>( + line, TOKand, e1.release(), e2.release()); } else { e1.reset(); } @@ -297,22 +295,23 @@ CXFA_FMSimpleExpression* CXFA_FMParse::ParseLogicalAndExpression() { } break; } - return e1.release(); + return e1; } -CXFA_FMSimpleExpression* CXFA_FMParse::ParseEqualityExpression() { +std::unique_ptr<CXFA_FMSimpleExpression> +CXFA_FMParse::ParseEqualityExpression() { uint32_t line = m_pToken->m_uLinenum; - std::unique_ptr<CXFA_FMSimpleExpression> e1(ParseRelationalExpression()); + std::unique_ptr<CXFA_FMSimpleExpression> e1 = ParseRelationalExpression(); for (;;) { std::unique_ptr<CXFA_FMSimpleExpression> e2; switch (m_pToken->m_type) { case TOKeq: case TOKkseq: NextToken(); - e2.reset(ParseRelationalExpression()); + e2 = ParseRelationalExpression(); if (m_pErrorInfo->message.IsEmpty()) { - e1.reset(new CXFA_FMEqualityExpression(line, TOKeq, e1.release(), - e2.release())); + e1 = pdfium::MakeUnique<CXFA_FMEqualityExpression>( + line, TOKeq, e1.release(), e2.release()); } else { e1.reset(); } @@ -320,10 +319,10 @@ CXFA_FMSimpleExpression* CXFA_FMParse::ParseEqualityExpression() { case TOKne: case TOKksne: NextToken(); - e2.reset(ParseRelationalExpression()); + e2 = ParseRelationalExpression(); if (m_pErrorInfo->message.IsEmpty()) { - e1.reset(new CXFA_FMEqualityExpression(line, TOKne, e1.release(), - e2.release())); + e1 = pdfium::MakeUnique<CXFA_FMEqualityExpression>( + line, TOKne, e1.release(), e2.release()); } else { e1.reset(); } @@ -333,22 +332,23 @@ CXFA_FMSimpleExpression* CXFA_FMParse::ParseEqualityExpression() { } break; } - return e1.release(); + return e1; } -CXFA_FMSimpleExpression* CXFA_FMParse::ParseRelationalExpression() { +std::unique_ptr<CXFA_FMSimpleExpression> +CXFA_FMParse::ParseRelationalExpression() { uint32_t line = m_pToken->m_uLinenum; - std::unique_ptr<CXFA_FMSimpleExpression> e1(ParseAddtiveExpression()); + std::unique_ptr<CXFA_FMSimpleExpression> e1 = ParseAddtiveExpression(); for (;;) { std::unique_ptr<CXFA_FMSimpleExpression> e2; switch (m_pToken->m_type) { case TOKlt: case TOKkslt: NextToken(); - e2.reset(ParseAddtiveExpression()); + e2 = ParseAddtiveExpression(); if (m_pErrorInfo->message.IsEmpty()) { - e1.reset(new CXFA_FMRelationalExpression(line, TOKlt, e1.release(), - e2.release())); + e1 = pdfium::MakeUnique<CXFA_FMRelationalExpression>( + line, TOKlt, e1.release(), e2.release()); } else { e1.reset(); } @@ -356,10 +356,10 @@ CXFA_FMSimpleExpression* CXFA_FMParse::ParseRelationalExpression() { case TOKgt: case TOKksgt: NextToken(); - e2.reset(ParseAddtiveExpression()); + e2 = ParseAddtiveExpression(); if (m_pErrorInfo->message.IsEmpty()) { - e1.reset(new CXFA_FMRelationalExpression(line, TOKgt, e1.release(), - e2.release())); + e1 = pdfium::MakeUnique<CXFA_FMRelationalExpression>( + line, TOKgt, e1.release(), e2.release()); } else { e1.reset(); } @@ -367,10 +367,10 @@ CXFA_FMSimpleExpression* CXFA_FMParse::ParseRelationalExpression() { case TOKle: case TOKksle: NextToken(); - e2.reset(ParseAddtiveExpression()); + e2 = ParseAddtiveExpression(); if (m_pErrorInfo->message.IsEmpty()) { - e1.reset(new CXFA_FMRelationalExpression(line, TOKle, e1.release(), - e2.release())); + e1 = pdfium::MakeUnique<CXFA_FMRelationalExpression>( + line, TOKle, e1.release(), e2.release()); } else { e1.reset(); } @@ -378,10 +378,10 @@ CXFA_FMSimpleExpression* CXFA_FMParse::ParseRelationalExpression() { case TOKge: case TOKksge: NextToken(); - e2.reset(ParseAddtiveExpression()); + e2 = ParseAddtiveExpression(); if (m_pErrorInfo->message.IsEmpty()) { - e1.reset(new CXFA_FMRelationalExpression(line, TOKge, e1.release(), - e2.release())); + e1 = pdfium::MakeUnique<CXFA_FMRelationalExpression>( + line, TOKge, e1.release(), e2.release()); } else { e1.reset(); } @@ -391,31 +391,32 @@ CXFA_FMSimpleExpression* CXFA_FMParse::ParseRelationalExpression() { } break; } - return e1.release(); + return e1; } -CXFA_FMSimpleExpression* CXFA_FMParse::ParseAddtiveExpression() { +std::unique_ptr<CXFA_FMSimpleExpression> +CXFA_FMParse::ParseAddtiveExpression() { uint32_t line = m_pToken->m_uLinenum; - std::unique_ptr<CXFA_FMSimpleExpression> e1(ParseMultiplicativeExpression()); + std::unique_ptr<CXFA_FMSimpleExpression> e1 = ParseMultiplicativeExpression(); for (;;) { std::unique_ptr<CXFA_FMSimpleExpression> e2; switch (m_pToken->m_type) { case TOKplus: NextToken(); - e2.reset(ParseMultiplicativeExpression()); + e2 = ParseMultiplicativeExpression(); if (m_pErrorInfo->message.IsEmpty()) { - e1.reset(new CXFA_FMAdditiveExpression(line, TOKplus, e1.release(), - e2.release())); + e1 = pdfium::MakeUnique<CXFA_FMAdditiveExpression>( + line, TOKplus, e1.release(), e2.release()); } else { e1.reset(); } continue; case TOKminus: NextToken(); - e2.reset(ParseMultiplicativeExpression()); + e2 = ParseMultiplicativeExpression(); if (m_pErrorInfo->message.IsEmpty()) { - e1.reset(new CXFA_FMAdditiveExpression(line, TOKminus, e1.release(), - e2.release())); + e1 = pdfium::MakeUnique<CXFA_FMAdditiveExpression>( + line, TOKminus, e1.release(), e2.release()); } else { e1.reset(); } @@ -425,31 +426,32 @@ CXFA_FMSimpleExpression* CXFA_FMParse::ParseAddtiveExpression() { } break; } - return e1.release(); + return e1; } -CXFA_FMSimpleExpression* CXFA_FMParse::ParseMultiplicativeExpression() { +std::unique_ptr<CXFA_FMSimpleExpression> +CXFA_FMParse::ParseMultiplicativeExpression() { uint32_t line = m_pToken->m_uLinenum; - std::unique_ptr<CXFA_FMSimpleExpression> e1(ParseUnaryExpression()); + std::unique_ptr<CXFA_FMSimpleExpression> e1 = ParseUnaryExpression(); for (;;) { std::unique_ptr<CXFA_FMSimpleExpression> e2; switch (m_pToken->m_type) { case TOKmul: NextToken(); - e2.reset(ParseUnaryExpression()); + e2 = ParseUnaryExpression(); if (m_pErrorInfo->message.IsEmpty()) { - e1.reset(new CXFA_FMMultiplicativeExpression( - line, TOKmul, e1.release(), e2.release())); + e1 = pdfium::MakeUnique<CXFA_FMMultiplicativeExpression>( + line, TOKmul, e1.release(), e2.release()); } else { e1.reset(); } continue; case TOKdiv: NextToken(); - e2.reset(ParseUnaryExpression()); + e2 = ParseUnaryExpression(); if (m_pErrorInfo->message.IsEmpty()) { - e1.reset(new CXFA_FMMultiplicativeExpression( - line, TOKdiv, e1.release(), e2.release())); + e1 = pdfium::MakeUnique<CXFA_FMMultiplicativeExpression>( + line, TOKdiv, e1.release(), e2.release()); } else { e1.reset(); } @@ -459,83 +461,88 @@ CXFA_FMSimpleExpression* CXFA_FMParse::ParseMultiplicativeExpression() { } break; } - return e1.release(); + return e1; } -CXFA_FMSimpleExpression* CXFA_FMParse::ParseUnaryExpression() { - std::unique_ptr<CXFA_FMSimpleExpression> e; +std::unique_ptr<CXFA_FMSimpleExpression> CXFA_FMParse::ParseUnaryExpression() { + std::unique_ptr<CXFA_FMSimpleExpression> expr; uint32_t line = m_pToken->m_uLinenum; switch (m_pToken->m_type) { case TOKplus: NextToken(); - e.reset(ParseUnaryExpression()); + expr = ParseUnaryExpression(); if (m_pErrorInfo->message.IsEmpty()) { - e.reset(new CXFA_FMPosExpression(line, e.release())); + expr = pdfium::MakeUnique<CXFA_FMPosExpression>(line, expr.release()); } else { - e.reset(); + expr.reset(); } break; case TOKminus: NextToken(); - e.reset(ParseUnaryExpression()); + expr = ParseUnaryExpression(); if (m_pErrorInfo->message.IsEmpty()) { - e.reset(new CXFA_FMNegExpression(line, e.release())); + expr = pdfium::MakeUnique<CXFA_FMNegExpression>(line, expr.release()); } else { - e.reset(); + expr.reset(); } break; case TOKksnot: NextToken(); - e.reset(ParseUnaryExpression()); + expr = ParseUnaryExpression(); if (m_pErrorInfo->message.IsEmpty()) { - e.reset(new CXFA_FMNotExpression(line, e.release())); + expr = pdfium::MakeUnique<CXFA_FMNotExpression>(line, expr.release()); } else { - e.reset(); + expr.reset(); } break; default: - e.reset(ParsePrimaryExpression()); + expr = ParsePrimaryExpression(); break; } - return e.release(); + return expr; } -CXFA_FMSimpleExpression* CXFA_FMParse::ParsePrimaryExpression() { - std::unique_ptr<CXFA_FMSimpleExpression> e; +std::unique_ptr<CXFA_FMSimpleExpression> +CXFA_FMParse::ParsePrimaryExpression() { + std::unique_ptr<CXFA_FMSimpleExpression> expr; uint32_t line = m_pToken->m_uLinenum; switch (m_pToken->m_type) { case TOKnumber: - e.reset(new CXFA_FMNumberExpression(line, m_pToken->m_wstring)); + expr = pdfium::MakeUnique<CXFA_FMNumberExpression>(line, + m_pToken->m_wstring); NextToken(); break; case TOKstring: - e.reset(new CXFA_FMStringExpression(line, m_pToken->m_wstring)); + expr = pdfium::MakeUnique<CXFA_FMStringExpression>(line, + m_pToken->m_wstring); NextToken(); break; case TOKidentifier: { CFX_WideStringC wsIdentifier(m_pToken->m_wstring); NextToken(); if (m_pToken->m_type == TOKlbracket) { - CXFA_FMSimpleExpression* s = ParseIndexExpression(); + std::unique_ptr<CXFA_FMSimpleExpression> s = ParseIndexExpression(); if (s) { - e.reset(new CXFA_FMDotAccessorExpression(line, nullptr, TOKdot, - wsIdentifier, s)); + expr = pdfium::MakeUnique<CXFA_FMDotAccessorExpression>( + line, nullptr, TOKdot, wsIdentifier, s.release()); } NextToken(); } else { - e.reset(new CXFA_FMIdentifierExpression(line, wsIdentifier)); + expr = + pdfium::MakeUnique<CXFA_FMIdentifierExpression>(line, wsIdentifier); } } break; case TOKif: - e.reset(new CXFA_FMIdentifierExpression(line, m_pToken->m_wstring)); + expr = pdfium::MakeUnique<CXFA_FMIdentifierExpression>( + line, m_pToken->m_wstring); NextToken(); break; case TOKnull: - e.reset(new CXFA_FMNullExpression(line)); + expr = pdfium::MakeUnique<CXFA_FMNullExpression>(line); NextToken(); break; case TOKlparen: - e.reset(ParseParenExpression()); + expr = ParseParenExpression(); break; default: CFX_WideString ws_TempString(m_pToken->m_wstring); @@ -544,25 +551,25 @@ CXFA_FMSimpleExpression* CXFA_FMParse::ParsePrimaryExpression() { NextToken(); break; } - e.reset(ParsePostExpression(e.release())); + expr = ParsePostExpression(std::move(expr)); if (!(m_pErrorInfo->message.IsEmpty())) - e.reset(); - return e.release(); + expr.reset(); + return expr; } -CXFA_FMSimpleExpression* CXFA_FMParse::ParsePostExpression( - CXFA_FMSimpleExpression* e) { +std::unique_ptr<CXFA_FMSimpleExpression> CXFA_FMParse::ParsePostExpression( + std::unique_ptr<CXFA_FMSimpleExpression> expr) { uint32_t line = m_pToken->m_uLinenum; while (1) { switch (m_pToken->m_type) { case TOKlparen: { NextToken(); - std::unique_ptr<CFX_ArrayTemplate<CXFA_FMSimpleExpression*>> pArray; + std::vector<std::unique_ptr<CXFA_FMSimpleExpression>> expressions; if (m_pToken->m_type != TOKrparen) { - pArray.reset(new CFX_ArrayTemplate<CXFA_FMSimpleExpression*>()); while (m_pToken->m_type != TOKrparen) { - if (CXFA_FMSimpleExpression* expr = ParseSimpleExpression()) - pArray->Add(expr); + if (std::unique_ptr<CXFA_FMSimpleExpression> expr = + ParseSimpleExpression()) + expressions.push_back(std::move(expr)); if (m_pToken->m_type == TOKcomma) { NextToken(); } else if (m_pToken->m_type == TOKeof || @@ -577,26 +584,21 @@ CXFA_FMSimpleExpression* CXFA_FMParse::ParsePostExpression( } } if (m_pErrorInfo->message.IsEmpty()) { - e = new CXFA_FMCallExpression(line, e, pArray.release(), false); + expr = pdfium::MakeUnique<CXFA_FMCallExpression>( + line, expr.release(), std::move(expressions), false); NextToken(); - if (m_pToken->m_type != TOKlbracket) { + if (m_pToken->m_type != TOKlbracket) continue; - } - CXFA_FMSimpleExpression* s = ParseIndexExpression(); + + std::unique_ptr<CXFA_FMSimpleExpression> s = ParseIndexExpression(); if (s) { - e = new CXFA_FMDotAccessorExpression(line, e, TOKcall, - FX_WSTRC(L""), s); + expr = pdfium::MakeUnique<CXFA_FMDotAccessorExpression>( + line, expr.release(), TOKcall, FX_WSTRC(L""), s.release()); } else { - delete e; - e = nullptr; + expr.reset(); } } else { - if (pArray) { - for (int32_t i = 0; i < pArray->GetSize(); ++i) - delete pArray->GetAt(i); - } - delete e; - e = nullptr; + expr.reset(); } } break; case TOKdot: @@ -606,16 +608,14 @@ CXFA_FMSimpleExpression* CXFA_FMParse::ParsePostExpression( uint32_t tempLine = m_pToken->m_uLinenum; NextToken(); if (m_pToken->m_type == TOKlparen) { - CXFA_FMSimpleExpression* pExpAccessor; - CXFA_FMSimpleExpression* pExpCall; - pExpAccessor = e; + std::unique_ptr<CXFA_FMSimpleExpression> pExpCall; NextToken(); - std::unique_ptr<CFX_ArrayTemplate<CXFA_FMSimpleExpression*>> pArray; + std::vector<std::unique_ptr<CXFA_FMSimpleExpression>> expressions; if (m_pToken->m_type != TOKrparen) { - pArray.reset(new CFX_ArrayTemplate<CXFA_FMSimpleExpression*>()); while (m_pToken->m_type != TOKrparen) { - CXFA_FMSimpleExpression* exp = ParseSimpleExpression(); - pArray->Add(exp); + std::unique_ptr<CXFA_FMSimpleExpression> exp = + ParseSimpleExpression(); + expressions.push_back(std::move(exp)); if (m_pToken->m_type == TOKcomma) { NextToken(); } else if (m_pToken->m_type == TOKeof || @@ -630,50 +630,48 @@ CXFA_FMSimpleExpression* CXFA_FMParse::ParsePostExpression( } } if (m_pErrorInfo->message.IsEmpty()) { - CXFA_FMSimpleExpression* pIdentifier = - new CXFA_FMIdentifierExpression(tempLine, tempStr); - pExpCall = new CXFA_FMCallExpression(line, pIdentifier, - pArray.release(), true); - e = new CXFA_FMMethodCallExpression(line, pExpAccessor, pExpCall); + std::unique_ptr<CXFA_FMSimpleExpression> pIdentifier = + pdfium::MakeUnique<CXFA_FMIdentifierExpression>(tempLine, + tempStr); + pExpCall = pdfium::MakeUnique<CXFA_FMCallExpression>( + line, pIdentifier.release(), std::move(expressions), true); + expr = pdfium::MakeUnique<CXFA_FMMethodCallExpression>( + line, expr.release(), pExpCall.release()); NextToken(); - if (m_pToken->m_type != TOKlbracket) { + if (m_pToken->m_type != TOKlbracket) continue; - } - CXFA_FMSimpleExpression* s = ParseIndexExpression(); + + std::unique_ptr<CXFA_FMSimpleExpression> s = + ParseIndexExpression(); if (s) { - e = new CXFA_FMDotAccessorExpression(line, e, TOKcall, - FX_WSTRC(L""), s); + expr = pdfium::MakeUnique<CXFA_FMDotAccessorExpression>( + line, expr.release(), TOKcall, FX_WSTRC(L""), s.release()); } else { - delete e; - e = nullptr; + expr.reset(); } } else { - if (pArray) { - for (int32_t i = 0; i < pArray->GetSize(); ++i) - delete pArray->GetAt(i); - } - delete e; - e = nullptr; + expr.reset(); } } else if (m_pToken->m_type == TOKlbracket) { - std::unique_ptr<CXFA_FMSimpleExpression> s(ParseIndexExpression()); - if (!(m_pErrorInfo->message.IsEmpty())) { - delete e; + std::unique_ptr<CXFA_FMSimpleExpression> s = ParseIndexExpression(); + if (!(m_pErrorInfo->message.IsEmpty())) return nullptr; - } - e = new CXFA_FMDotAccessorExpression(tempLine, e, TOKdot, tempStr, - s.release()); + + expr = pdfium::MakeUnique<CXFA_FMDotAccessorExpression>( + tempLine, expr.release(), TOKdot, tempStr, s.release()); } else { - CXFA_FMSimpleExpression* s = new CXFA_FMIndexExpression( - tempLine, ACCESSOR_NO_INDEX, nullptr, false); - e = new CXFA_FMDotAccessorExpression(line, e, TOKdot, tempStr, s); + std::unique_ptr<CXFA_FMSimpleExpression> s = + pdfium::MakeUnique<CXFA_FMIndexExpression>( + tempLine, ACCESSOR_NO_INDEX, nullptr, false); + expr = pdfium::MakeUnique<CXFA_FMDotAccessorExpression>( + line, expr.release(), TOKdot, tempStr, s.release()); continue; } } else { CFX_WideString ws_TempString(m_pToken->m_wstring); Error(m_pToken->m_uLinenum, kFMErrExpectedIdentifier, ws_TempString.c_str()); - return e; + return expr; } break; case TOKdotdot: @@ -683,25 +681,25 @@ CXFA_FMSimpleExpression* CXFA_FMParse::ParsePostExpression( uint32_t tempLine = m_pToken->m_uLinenum; NextToken(); if (m_pToken->m_type == TOKlbracket) { - std::unique_ptr<CXFA_FMSimpleExpression> s(ParseIndexExpression()); + std::unique_ptr<CXFA_FMSimpleExpression> s = ParseIndexExpression(); if (!(m_pErrorInfo->message.IsEmpty())) { - delete e; return nullptr; } - e = new CXFA_FMDotDotAccessorExpression(tempLine, e, TOKdotdot, - tempStr, s.release()); + expr = pdfium::MakeUnique<CXFA_FMDotDotAccessorExpression>( + tempLine, expr.release(), TOKdotdot, tempStr, s.release()); } else { - CXFA_FMSimpleExpression* s = new CXFA_FMIndexExpression( - tempLine, ACCESSOR_NO_INDEX, nullptr, false); - e = new CXFA_FMDotDotAccessorExpression(line, e, TOKdotdot, tempStr, - s); + std::unique_ptr<CXFA_FMSimpleExpression> s = + pdfium::MakeUnique<CXFA_FMIndexExpression>( + tempLine, ACCESSOR_NO_INDEX, nullptr, false); + expr = pdfium::MakeUnique<CXFA_FMDotDotAccessorExpression>( + line, expr.release(), TOKdotdot, tempStr, s.release()); continue; } } else { CFX_WideString ws_TempString(m_pToken->m_wstring); Error(m_pToken->m_uLinenum, kFMErrExpectedIdentifier, ws_TempString.c_str()); - return e; + return expr; } break; case TOKdotscream: @@ -711,50 +709,51 @@ CXFA_FMSimpleExpression* CXFA_FMParse::ParsePostExpression( uint32_t tempLine = m_pToken->m_uLinenum; NextToken(); if (m_pToken->m_type == TOKlbracket) { - std::unique_ptr<CXFA_FMSimpleExpression> s(ParseIndexExpression()); - if (!(m_pErrorInfo->message.IsEmpty())) { - delete e; + std::unique_ptr<CXFA_FMSimpleExpression> s = ParseIndexExpression(); + if (!(m_pErrorInfo->message.IsEmpty())) return nullptr; - } - e = new CXFA_FMDotAccessorExpression(tempLine, e, TOKdotscream, - tempStr, s.release()); + + expr = pdfium::MakeUnique<CXFA_FMDotAccessorExpression>( + tempLine, expr.release(), TOKdotscream, tempStr, s.release()); } else { - CXFA_FMSimpleExpression* s = new CXFA_FMIndexExpression( - tempLine, ACCESSOR_NO_INDEX, nullptr, false); - e = new CXFA_FMDotAccessorExpression(line, e, TOKdotscream, tempStr, - s); + std::unique_ptr<CXFA_FMSimpleExpression> s = + pdfium::MakeUnique<CXFA_FMIndexExpression>( + tempLine, ACCESSOR_NO_INDEX, nullptr, false); + expr = pdfium::MakeUnique<CXFA_FMDotAccessorExpression>( + line, expr.release(), TOKdotscream, tempStr, s.release()); continue; } } else { CFX_WideString ws_TempString(m_pToken->m_wstring); Error(m_pToken->m_uLinenum, kFMErrExpectedIdentifier, ws_TempString.c_str()); - return e; + return expr; } break; case TOKdotstar: { - CXFA_FMSimpleExpression* s = - new CXFA_FMIndexExpression(line, ACCESSOR_NO_INDEX, nullptr, false); - e = new CXFA_FMDotAccessorExpression(line, e, TOKdotstar, - FX_WSTRC(L"*"), s); + std::unique_ptr<CXFA_FMSimpleExpression> s = + pdfium::MakeUnique<CXFA_FMIndexExpression>(line, ACCESSOR_NO_INDEX, + nullptr, false); + expr = pdfium::MakeUnique<CXFA_FMDotAccessorExpression>( + line, expr.release(), TOKdotstar, FX_WSTRC(L"*"), s.release()); } break; default: - return e; + return expr; } NextToken(); } - return e; + return expr; } -CXFA_FMSimpleExpression* CXFA_FMParse::ParseIndexExpression() { +std::unique_ptr<CXFA_FMSimpleExpression> CXFA_FMParse::ParseIndexExpression() { std::unique_ptr<CXFA_FMSimpleExpression> pExp; uint32_t line = m_pToken->m_uLinenum; NextToken(); std::unique_ptr<CXFA_FMSimpleExpression> s; XFA_FM_AccessorIndex accessorIndex = ACCESSOR_NO_RELATIVEINDEX; if (m_pToken->m_type == TOKmul) { - pExp.reset( - new CXFA_FMIndexExpression(line, accessorIndex, s.release(), true)); + pExp = pdfium::MakeUnique<CXFA_FMIndexExpression>(line, accessorIndex, + s.release(), true); NextToken(); if (m_pToken->m_type != TOKrbracket) { CFX_WideString ws_TempString(m_pToken->m_wstring); @@ -762,7 +761,7 @@ CXFA_FMSimpleExpression* CXFA_FMParse::ParseIndexExpression() { XFA_FM_KeywordToString(TOKrparen), ws_TempString.c_str()); pExp.reset(); } - return pExp.release(); + return pExp; } if (m_pToken->m_type == TOKplus) { accessorIndex = ACCESSOR_POSITIVE_INDEX; @@ -771,19 +770,19 @@ CXFA_FMSimpleExpression* CXFA_FMParse::ParseIndexExpression() { accessorIndex = ACCESSOR_NEGATIVE_INDEX; NextToken(); } - s.reset(ParseSimpleExpression()); + s = ParseSimpleExpression(); if (m_pToken->m_type != TOKrbracket) { CFX_WideString ws_TempString(m_pToken->m_wstring); Error(m_pToken->m_uLinenum, kFMErrExpectedToken, XFA_FM_KeywordToString(TOKrparen), ws_TempString.c_str()); } else { - pExp.reset( - new CXFA_FMIndexExpression(line, accessorIndex, s.release(), false)); + pExp = pdfium::MakeUnique<CXFA_FMIndexExpression>(line, accessorIndex, + s.release(), false); } - return pExp.release(); + return pExp; } -CXFA_FMSimpleExpression* CXFA_FMParse::ParseParenExpression() { +std::unique_ptr<CXFA_FMSimpleExpression> CXFA_FMParse::ParseParenExpression() { Check(TOKlparen); if (m_pToken->m_type == TOKrparen) { @@ -793,27 +792,26 @@ CXFA_FMSimpleExpression* CXFA_FMParse::ParseParenExpression() { } uint32_t line = m_pToken->m_uLinenum; - std::unique_ptr<CXFA_FMSimpleExpression> pExp1(ParseLogicalOrExpression()); + std::unique_ptr<CXFA_FMSimpleExpression> pExp1 = ParseLogicalOrExpression(); while (m_pToken->m_type == TOKassign) { NextToken(); - std::unique_ptr<CXFA_FMSimpleExpression> pExp2(ParseLogicalOrExpression()); + std::unique_ptr<CXFA_FMSimpleExpression> pExp2 = ParseLogicalOrExpression(); if (m_pErrorInfo->message.IsEmpty()) { - pExp1.reset(new CXFA_FMAssignExpression(line, TOKassign, pExp1.release(), - pExp2.release())); + pExp1 = pdfium::MakeUnique<CXFA_FMAssignExpression>( + line, TOKassign, pExp1.release(), pExp2.release()); } else { pExp1.reset(); } } Check(TOKrparen); - return pExp1.release(); + return pExp1; } -CXFA_FMExpression* CXFA_FMParse::ParseBlockExpression() { +std::unique_ptr<CXFA_FMExpression> CXFA_FMParse::ParseBlockExpression() { uint32_t line = m_pToken->m_uLinenum; - CXFA_FMExpression* e = nullptr; - std::unique_ptr<CFX_ArrayTemplate<CXFA_FMExpression*>> expression( - new CFX_ArrayTemplate<CXFA_FMExpression*>()); + std::unique_ptr<CXFA_FMExpression> expr; + std::vector<std::unique_ptr<CXFA_FMExpression>> expressions; while (1) { switch (m_pToken->m_type) { @@ -828,15 +826,15 @@ CXFA_FMExpression* CXFA_FMParse::ParseBlockExpression() { case TOKreserver: break; case TOKfunc: - e = ParseFunction(); - if (e) { - expression->Add(e); + expr = ParseFunction(); + if (expr) { + expressions.push_back(std::move(expr)); } continue; default: - e = ParseExpression(); - if (e) { - expression->Add(e); + expr = ParseExpression(); + if (expr) { + expressions.push_back(std::move(expr)); } continue; } @@ -844,22 +842,20 @@ CXFA_FMExpression* CXFA_FMParse::ParseBlockExpression() { } std::unique_ptr<CXFA_FMBlockExpression> pExp; if (m_pErrorInfo->message.IsEmpty()) { - pExp.reset(new CXFA_FMBlockExpression(line, expression.release())); - } else { - for (int i = 0; i < expression->GetSize(); ++i) - delete static_cast<CXFA_FMExpression*>(expression->GetAt(i)); + pExp = pdfium::MakeUnique<CXFA_FMBlockExpression>(line, + std::move(expressions)); } - return pExp.release(); + return pExp; } -CXFA_FMExpression* CXFA_FMParse::ParseIfExpression() { +std::unique_ptr<CXFA_FMExpression> CXFA_FMParse::ParseIfExpression() { uint32_t line = m_pToken->m_uLinenum; const FX_WCHAR* pStartPos = m_lexer->SavePos(); NextToken(); Check(TOKlparen); std::unique_ptr<CXFA_FMSimpleExpression> pExpression; while (m_pToken->m_type != TOKrparen) { - pExpression.reset(ParseSimpleExpression()); + pExpression = ParseSimpleExpression(); if (m_pToken->m_type != TOKcomma) break; NextToken(); @@ -875,7 +871,7 @@ CXFA_FMExpression* CXFA_FMParse::ParseIfExpression() { return ParseExpExpression(); } Check(TOKthen); - std::unique_ptr<CXFA_FMExpression> pIfExpression(ParseBlockExpression()); + std::unique_ptr<CXFA_FMExpression> pIfExpression = ParseBlockExpression(); std::unique_ptr<CXFA_FMExpression> pElseExpression; switch (m_pToken->m_type) { case TOKeof: @@ -883,15 +879,15 @@ CXFA_FMExpression* CXFA_FMParse::ParseIfExpression() { Check(TOKendif); break; case TOKif: - pElseExpression.reset(ParseIfExpression()); + pElseExpression = ParseIfExpression(); Check(TOKendif); break; case TOKelseif: - pElseExpression.reset(ParseIfExpression()); + pElseExpression = ParseIfExpression(); break; case TOKelse: NextToken(); - pElseExpression.reset(ParseBlockExpression()); + pElseExpression = ParseBlockExpression(); Check(TOKendif); break; default: @@ -902,33 +898,34 @@ CXFA_FMExpression* CXFA_FMParse::ParseIfExpression() { } std::unique_ptr<CXFA_FMIfExpression> pExp; if (m_pErrorInfo->message.IsEmpty()) { - pExp.reset(new CXFA_FMIfExpression(line, pExpression.release(), - pIfExpression.release(), - pElseExpression.release())); + pExp = pdfium::MakeUnique<CXFA_FMIfExpression>(line, pExpression.release(), + pIfExpression.release(), + pElseExpression.release()); } - return pExp.release(); + return pExp; } -CXFA_FMExpression* CXFA_FMParse::ParseWhileExpression() { +std::unique_ptr<CXFA_FMExpression> CXFA_FMParse::ParseWhileExpression() { uint32_t line = m_pToken->m_uLinenum; NextToken(); - std::unique_ptr<CXFA_FMSimpleExpression> pCondition(ParseParenExpression()); + std::unique_ptr<CXFA_FMSimpleExpression> pCondition = ParseParenExpression(); Check(TOKdo); - std::unique_ptr<CXFA_FMExpression> pExpression(ParseBlockExpression()); + std::unique_ptr<CXFA_FMExpression> pExpression = ParseBlockExpression(); Check(TOKendwhile); - std::unique_ptr<CXFA_FMExpression> e; + std::unique_ptr<CXFA_FMExpression> expr; if (m_pErrorInfo->message.IsEmpty()) { - e.reset(new CXFA_FMWhileExpression(line, pCondition.release(), - pExpression.release())); + expr = pdfium::MakeUnique<CXFA_FMWhileExpression>( + line, pCondition.release(), pExpression.release()); } - return e.release(); + return expr; } -CXFA_FMSimpleExpression* CXFA_FMParse::ParseSubassignmentInForExpression() { - std::unique_ptr<CXFA_FMSimpleExpression> e; +std::unique_ptr<CXFA_FMSimpleExpression> +CXFA_FMParse::ParseSubassignmentInForExpression() { + std::unique_ptr<CXFA_FMSimpleExpression> expr; switch (m_pToken->m_type) { case TOKidentifier: - e.reset(ParseSimpleExpression()); + expr = ParseSimpleExpression(); break; default: CFX_WideString ws_TempString(m_pToken->m_wstring); @@ -937,10 +934,10 @@ CXFA_FMSimpleExpression* CXFA_FMParse::ParseSubassignmentInForExpression() { NextToken(); break; } - return e.release(); + return expr; } -CXFA_FMExpression* CXFA_FMParse::ParseForExpression() { +std::unique_ptr<CXFA_FMExpression> CXFA_FMParse::ParseForExpression() { CFX_WideStringC wsVariant; uint32_t line = m_pToken->m_uLinenum; NextToken(); @@ -954,7 +951,7 @@ CXFA_FMExpression* CXFA_FMParse::ParseForExpression() { std::unique_ptr<CXFA_FMSimpleExpression> pAssignment; if (m_pToken->m_type == TOKassign) { NextToken(); - pAssignment.reset(ParseSimpleExpression()); + pAssignment = ParseSimpleExpression(); } else { CFX_WideString ws_TempString(m_pToken->m_wstring); Error(m_pToken->m_uLinenum, kFMErrExpectedToken, @@ -971,26 +968,26 @@ CXFA_FMExpression* CXFA_FMParse::ParseForExpression() { ws_TempString.c_str()); } NextToken(); - std::unique_ptr<CXFA_FMSimpleExpression> pAccessor(ParseSimpleExpression()); + std::unique_ptr<CXFA_FMSimpleExpression> pAccessor = ParseSimpleExpression(); std::unique_ptr<CXFA_FMSimpleExpression> pStep; if (m_pToken->m_type == TOKstep) { NextToken(); - pStep.reset(ParseSimpleExpression()); + pStep = ParseSimpleExpression(); } Check(TOKdo); - std::unique_ptr<CXFA_FMExpression> pList(ParseBlockExpression()); + std::unique_ptr<CXFA_FMExpression> pList = ParseBlockExpression(); Check(TOKendfor); - std::unique_ptr<CXFA_FMExpression> e; + std::unique_ptr<CXFA_FMExpression> expr; if (m_pErrorInfo->message.IsEmpty()) { - e.reset(new CXFA_FMForExpression(line, wsVariant, pAssignment.release(), - pAccessor.release(), iDirection, - pStep.release(), pList.release())); + expr = pdfium::MakeUnique<CXFA_FMForExpression>( + line, wsVariant, pAssignment.release(), pAccessor.release(), iDirection, + pStep.release(), pList.release()); } - return e.release(); + return expr; } -CXFA_FMExpression* CXFA_FMParse::ParseForeachExpression() { - std::unique_ptr<CXFA_FMExpression> e; +std::unique_ptr<CXFA_FMExpression> CXFA_FMParse::ParseForeachExpression() { + std::unique_ptr<CXFA_FMExpression> expr; CFX_WideStringC wsIdentifier; std::vector<std::unique_ptr<CXFA_FMSimpleExpression>> pAccessors; std::unique_ptr<CXFA_FMExpression> pList; @@ -1012,9 +1009,9 @@ CXFA_FMExpression* CXFA_FMParse::ParseForeachExpression() { NextToken(); } else { while (m_pToken->m_type != TOKrparen) { - CXFA_FMSimpleExpression* s = ParseSimpleExpression(); + std::unique_ptr<CXFA_FMSimpleExpression> s = ParseSimpleExpression(); if (s) - pAccessors.push_back(pdfium::WrapUnique<CXFA_FMSimpleExpression>(s)); + pAccessors.push_back(std::move(s)); if (m_pToken->m_type != TOKcomma) break; NextToken(); @@ -1022,25 +1019,24 @@ CXFA_FMExpression* CXFA_FMParse::ParseForeachExpression() { Check(TOKrparen); } Check(TOKdo); - pList.reset(ParseBlockExpression()); + pList = ParseBlockExpression(); Check(TOKendfor); if (m_pErrorInfo->message.IsEmpty()) { - e = pdfium::MakeUnique<CXFA_FMForeachExpression>( + expr = pdfium::MakeUnique<CXFA_FMForeachExpression>( line, wsIdentifier, std::move(pAccessors), pList.release()); } - return e.release(); + return expr; } -CXFA_FMExpression* CXFA_FMParse::ParseDoExpression() { - std::unique_ptr<CXFA_FMExpression> e; +std::unique_ptr<CXFA_FMExpression> CXFA_FMParse::ParseDoExpression() { uint32_t line = m_pToken->m_uLinenum; NextToken(); - e.reset(ParseBlockExpression()); + std::unique_ptr<CXFA_FMExpression> expr = ParseBlockExpression(); Check(TOKend); if (m_pErrorInfo->message.IsEmpty()) { - e.reset(new CXFA_FMDoExpression(line, e.release())); + expr = pdfium::MakeUnique<CXFA_FMDoExpression>(line, expr.release()); } else { - e.reset(); + expr.reset(); } - return e.release(); + return expr; } |