diff options
author | dan sinclair <dsinclair@chromium.org> | 2018-02-19 18:23:13 +0000 |
---|---|---|
committer | Chromium commit bot <commit-bot@chromium.org> | 2018-02-19 18:23:13 +0000 |
commit | 0f9e15cf365faf025d00e7df2565c8482a245953 (patch) | |
tree | 9a4db2247c0fb8f4764f9d1630ab493ec31bb52d /xfa | |
parent | 43e0be7b93c24d6a37aa3a0dca1f8c89dc78b165 (diff) | |
download | pdfium-0f9e15cf365faf025d00e7df2565c8482a245953.tar.xz |
FormCalc Assignment is not a SimpleExpression
Currently the parser builds assignment statements as part of the
SimpleExpression declaration. This isn't correct according to the
grammar where AssignmentExpression and SimpleExpression are siblings.
This CL moves the assignment calculation into the ExpExpression
declaration to make it a sibling of the SimpleExpression.
Change-Id: I6afac2379ab6783b84ee619863c8308ca0db454d
Reviewed-on: https://pdfium-review.googlesource.com/27310
Reviewed-by: Ryan Harrison <rharrison@chromium.org>
Commit-Queue: dsinclair <dsinclair@chromium.org>
Diffstat (limited to 'xfa')
-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(); |