summaryrefslogtreecommitdiff
path: root/xfa/fxfa/fm2js/cxfa_fmexpression.cpp
diff options
context:
space:
mode:
authorDan Sinclair <dsinclair@chromium.org>2018-02-21 22:16:26 +0000
committerChromium commit bot <commit-bot@chromium.org>2018-02-21 22:16:26 +0000
commitaa2aff78e082f14e4bc418f68b27817f90e3f07a (patch)
treee646df3a814cb66508350049ec2132635f231f36 /xfa/fxfa/fm2js/cxfa_fmexpression.cpp
parent00c1d0b07542611d295dc666ff55d46b0d3f712b (diff)
downloadpdfium-aa2aff78e082f14e4bc418f68b27817f90e3f07a.tar.xz
[formcalc] Cleanup if expression parsing.
This CL simplifies the if expression parsing. The elseif construct has been split into its own list of IfExpressions and no longer gets stuffed into the elseExpression. A loop was added into the output methods for the elseif expressions, which also means we can go from having: if () { } else { if () { } else { } } to if () { } else if () { } else { } Which is a bit nicer. Change-Id: I6edf75215500d6a32a8d7218d477b6960f03de51 Reviewed-on: https://pdfium-review.googlesource.com/27571 Reviewed-by: Ryan Harrison <rharrison@chromium.org> Commit-Queue: dsinclair <dsinclair@chromium.org>
Diffstat (limited to 'xfa/fxfa/fm2js/cxfa_fmexpression.cpp')
-rw-r--r--xfa/fxfa/fm2js/cxfa_fmexpression.cpp28
1 files changed, 16 insertions, 12 deletions
diff --git a/xfa/fxfa/fm2js/cxfa_fmexpression.cpp b/xfa/fxfa/fm2js/cxfa_fmexpression.cpp
index a4dee6353b..db93a38e50 100644
--- a/xfa/fxfa/fm2js/cxfa_fmexpression.cpp
+++ b/xfa/fxfa/fm2js/cxfa_fmexpression.cpp
@@ -220,11 +220,15 @@ bool CXFA_FMDoExpression::ToJavaScript(CFX_WideTextBuf& js, ReturnType type) {
CXFA_FMIfExpression::CXFA_FMIfExpression(
std::unique_ptr<CXFA_FMSimpleExpression> pExpression,
std::unique_ptr<CXFA_FMExpression> pIfExpression,
+ std::vector<std::unique_ptr<CXFA_FMIfExpression>> pElseIfExpressions,
std::unique_ptr<CXFA_FMExpression> pElseExpression)
: CXFA_FMExpression(),
m_pExpression(std::move(pExpression)),
m_pIfExpression(std::move(pIfExpression)),
- m_pElseExpression(std::move(pElseExpression)) {}
+ m_pElseIfExpressions(std::move(pElseIfExpressions)),
+ m_pElseExpression(std::move(pElseExpression)) {
+ ASSERT(m_pExpression);
+}
CXFA_FMIfExpression::~CXFA_FMIfExpression() = default;
@@ -236,15 +240,10 @@ bool CXFA_FMIfExpression::ToJavaScript(CFX_WideTextBuf& js, ReturnType type) {
if (type == ReturnType::kImplied)
js << L"pfm_ret = 0;\n";
- js << L"if (";
- if (m_pExpression) {
- js << L"pfm_rt.get_val(";
- if (!m_pExpression->ToJavaScript(js, ReturnType::kInfered))
- return false;
-
- js << L")";
- }
- js << L")\n";
+ js << L"if (pfm_rt.get_val(";
+ if (!m_pExpression->ToJavaScript(js, ReturnType::kInfered))
+ return false;
+ js << L"))\n";
if (CXFA_IsTooBig(js))
return false;
@@ -256,11 +255,16 @@ bool CXFA_FMIfExpression::ToJavaScript(CFX_WideTextBuf& js, ReturnType type) {
return false;
}
+ for (auto& expr : m_pElseIfExpressions) {
+ js << L"else ";
+ if (!expr->ToJavaScript(js, ReturnType::kInfered))
+ return false;
+ }
+
if (m_pElseExpression) {
- js << L"else\n{\n";
+ js << L"else ";
if (!m_pElseExpression->ToJavaScript(js, type))
return false;
- js << L"}\n";
}
return !CXFA_IsTooBig(js);
}