From 0f9e15cf365faf025d00e7df2565c8482a245953 Mon Sep 17 00:00:00 2001 From: dan sinclair Date: Mon, 19 Feb 2018 18:23:13 +0000 Subject: 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 Commit-Queue: dsinclair --- xfa/fxfa/fm2js/cxfa_fmparser.cpp | 42 ++++++++++++++++++---------------------- 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_FMParser::Parse() { - auto expressions = ParseTopExpression(); + auto expressions = ParseExpressionList(); if (HasError()) return nullptr; @@ -65,28 +65,28 @@ bool CXFA_FMParser::IncrementParseDepthAndCheck() { } std::vector> -CXFA_FMParser::ParseTopExpression() { +CXFA_FMParser::ParseExpressionList() { AutoRestorer restorer(&m_parse_depth); if (HasError() || !IncrementParseDepthAndCheck()) return std::vector>(); - std::unique_ptr expr; std::vector> 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 expr = + m_token.m_type == TOKfunc ? ParseFunction() : ParseExpression(); if (!expr) { m_error = true; - break; + return std::vector>(); } expressions.push_back(std::move(expr)); } - return std::vector>(); + return expressions; } std::unique_ptr CXFA_FMParser::ParseFunction() { @@ -143,7 +143,7 @@ std::unique_ptr 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_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_FMParser::ParseExpression() { return expr; } -std::unique_ptr CXFA_FMParser::ParseVarExpression() { +std::unique_ptr CXFA_FMParser::ParseDeclarationExpression() { AutoRestorer 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_FMParser::ParseExpExpression() { + AutoRestorer restorer(&m_parse_depth); + if (HasError() || !IncrementParseDepthAndCheck()) + return nullptr; + uint32_t line = m_lexer->GetCurrentLine(); - std::unique_ptr pExp1 = ParseLogicalOrExpression(); + std::unique_ptr pExp1 = ParseSimpleExpression(); if (!pExp1) return nullptr; int level = 1; @@ -259,18 +267,6 @@ CXFA_FMParser::ParseSimpleExpression() { pExp1 = pdfium::MakeUnique( line, TOKassign, std::move(pExp1), std::move(pExp2)); } - return pExp1; -} - -std::unique_ptr CXFA_FMParser::ParseExpExpression() { - AutoRestorer restorer(&m_parse_depth); - if (HasError() || !IncrementParseDepthAndCheck()) - return nullptr; - - uint32_t line = m_lexer->GetCurrentLine(); - std::unique_ptr pExp1 = ParseSimpleExpression(); - if (!pExp1) - return nullptr; return pdfium::MakeUnique(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> ParseTopExpression(); + std::vector> ParseExpressionList(); std::unique_ptr ParseFunction(); std::unique_ptr ParseExpression(); - std::unique_ptr ParseVarExpression(); + std::unique_ptr ParseDeclarationExpression(); std::unique_ptr ParseExpExpression(); std::unique_ptr ParseBlockExpression(); std::unique_ptr ParseIfExpression(); -- cgit v1.2.3