diff options
Diffstat (limited to 'xfa/fxfa')
-rw-r--r-- | xfa/fxfa/fm2js/cxfa_fmparser.cpp | 42 | ||||
-rw-r--r-- | xfa/fxfa/fm2js/cxfa_fmparser.h | 4 |
2 files changed, 21 insertions, 25 deletions
diff --git a/xfa/fxfa/fm2js/cxfa_fmparser.cpp b/xfa/fxfa/fm2js/cxfa_fmparser.cpp index d023159bbf..536075b298 100644 --- a/xfa/fxfa/fm2js/cxfa_fmparser.cpp +++ b/xfa/fxfa/fm2js/cxfa_fmparser.cpp @@ -30,7 +30,7 @@ CXFA_FMParser::CXFA_FMParser(const WideStringView& wsFormcalc) CXFA_FMParser::~CXFA_FMParser() {} std::unique_ptr<CXFA_FMFunctionDefinition> CXFA_FMParser::Parse() { - auto expressions = ParseTopExpression(); + auto expressions = ParseExpressionList(); if (HasError()) return nullptr; @@ -65,28 +65,28 @@ bool CXFA_FMParser::IncrementParseDepthAndCheck() { } std::vector<std::unique_ptr<CXFA_FMExpression>> -CXFA_FMParser::ParseTopExpression() { +CXFA_FMParser::ParseExpressionList() { AutoRestorer<unsigned long> restorer(&m_parse_depth); if (HasError() || !IncrementParseDepthAndCheck()) return std::vector<std::unique_ptr<CXFA_FMExpression>>(); - std::unique_ptr<CXFA_FMExpression> expr; std::vector<std::unique_ptr<CXFA_FMExpression>> expressions; while (!HasError()) { if (m_token.m_type == TOKeof || m_token.m_type == TOKendfunc || m_token.m_type == TOKendif || m_token.m_type == TOKelseif || m_token.m_type == TOKelse || m_token.m_type == TOKreserver) { - return expressions; + break; } - expr = m_token.m_type == TOKfunc ? ParseFunction() : ParseExpression(); + std::unique_ptr<CXFA_FMExpression> expr = + m_token.m_type == TOKfunc ? ParseFunction() : ParseExpression(); if (!expr) { m_error = true; - break; + return std::vector<std::unique_ptr<CXFA_FMExpression>>(); } expressions.push_back(std::move(expr)); } - return std::vector<std::unique_ptr<CXFA_FMExpression>>(); + return expressions; } std::unique_ptr<CXFA_FMExpression> CXFA_FMParser::ParseFunction() { @@ -143,7 +143,7 @@ std::unique_ptr<CXFA_FMExpression> CXFA_FMParser::ParseFunction() { if (!NextToken()) return nullptr; } else { - expressions = ParseTopExpression(); + expressions = ParseExpressionList(); if (!expressions.size() || !CheckThenNext(TOKendfunc)) return nullptr; } @@ -161,7 +161,7 @@ std::unique_ptr<CXFA_FMExpression> CXFA_FMParser::ParseExpression() { uint32_t line = m_lexer->GetCurrentLine(); switch (m_token.m_type) { case TOKvar: - expr = ParseVarExpression(); + expr = ParseDeclarationExpression(); break; case TOKnull: case TOKnumber: @@ -205,7 +205,7 @@ std::unique_ptr<CXFA_FMExpression> CXFA_FMParser::ParseExpression() { return expr; } -std::unique_ptr<CXFA_FMExpression> CXFA_FMParser::ParseVarExpression() { +std::unique_ptr<CXFA_FMExpression> CXFA_FMParser::ParseDeclarationExpression() { AutoRestorer<unsigned long> restorer(&m_parse_depth); if (HasError() || !IncrementParseDepthAndCheck()) return nullptr; @@ -241,8 +241,16 @@ CXFA_FMParser::ParseSimpleExpression() { if (HasError()) return nullptr; + return ParseLogicalOrExpression(); +} + +std::unique_ptr<CXFA_FMExpression> CXFA_FMParser::ParseExpExpression() { + AutoRestorer<unsigned long> restorer(&m_parse_depth); + if (HasError() || !IncrementParseDepthAndCheck()) + return nullptr; + uint32_t line = m_lexer->GetCurrentLine(); - std::unique_ptr<CXFA_FMSimpleExpression> pExp1 = ParseLogicalOrExpression(); + std::unique_ptr<CXFA_FMSimpleExpression> pExp1 = ParseSimpleExpression(); if (!pExp1) return nullptr; int level = 1; @@ -259,18 +267,6 @@ CXFA_FMParser::ParseSimpleExpression() { pExp1 = pdfium::MakeUnique<CXFA_FMAssignExpression>( line, TOKassign, std::move(pExp1), std::move(pExp2)); } - return pExp1; -} - -std::unique_ptr<CXFA_FMExpression> CXFA_FMParser::ParseExpExpression() { - AutoRestorer<unsigned long> restorer(&m_parse_depth); - if (HasError() || !IncrementParseDepthAndCheck()) - return nullptr; - - uint32_t line = m_lexer->GetCurrentLine(); - std::unique_ptr<CXFA_FMSimpleExpression> pExp1 = ParseSimpleExpression(); - if (!pExp1) - return nullptr; return pdfium::MakeUnique<CXFA_FMExpExpression>(line, std::move(pExp1)); } diff --git a/xfa/fxfa/fm2js/cxfa_fmparser.h b/xfa/fxfa/fm2js/cxfa_fmparser.h index 3958930224..c2da48496f 100644 --- a/xfa/fxfa/fm2js/cxfa_fmparser.h +++ b/xfa/fxfa/fm2js/cxfa_fmparser.h @@ -30,10 +30,10 @@ class CXFA_FMParser { bool CheckThenNext(XFA_FM_TOKEN op); bool IncrementParseDepthAndCheck(); - std::vector<std::unique_ptr<CXFA_FMExpression>> ParseTopExpression(); + std::vector<std::unique_ptr<CXFA_FMExpression>> ParseExpressionList(); std::unique_ptr<CXFA_FMExpression> ParseFunction(); std::unique_ptr<CXFA_FMExpression> ParseExpression(); - std::unique_ptr<CXFA_FMExpression> ParseVarExpression(); + std::unique_ptr<CXFA_FMExpression> ParseDeclarationExpression(); std::unique_ptr<CXFA_FMExpression> ParseExpExpression(); std::unique_ptr<CXFA_FMExpression> ParseBlockExpression(); std::unique_ptr<CXFA_FMExpression> ParseIfExpression(); |