diff options
author | dan sinclair <dsinclair@chromium.org> | 2018-02-19 18:13:03 +0000 |
---|---|---|
committer | Chromium commit bot <commit-bot@chromium.org> | 2018-02-19 18:13:03 +0000 |
commit | 636259244a298b09aab0195258e76b51784766ff (patch) | |
tree | 26e0c1704f591d533839f19d701fa0c2dd30eaf2 /xfa/fxfa/fm2js | |
parent | efb648866f9582845d4788c945e523d565464cb9 (diff) | |
download | pdfium-636259244a298b09aab0195258e76b51784766ff.tar.xz |
Inline FormCalc method names
This CL inlines the FormCalc method names instead of using a lookup
array. Many of the names were only referenced once and this makes the
code a lot simpler to read.
Change-Id: Ib80f5bfa0097e4f1bad232e7de452f067db2a758
Reviewed-on: https://pdfium-review.googlesource.com/27211
Reviewed-by: Ryan Harrison <rharrison@chromium.org>
Commit-Queue: dsinclair <dsinclair@chromium.org>
Diffstat (limited to 'xfa/fxfa/fm2js')
-rw-r--r-- | xfa/fxfa/fm2js/cxfa_fmexpression.cpp | 56 | ||||
-rw-r--r-- | xfa/fxfa/fm2js/cxfa_fmsimpleexpression.cpp | 83 | ||||
-rw-r--r-- | xfa/fxfa/fm2js/cxfa_fmsimpleexpression.h | 35 |
3 files changed, 43 insertions, 131 deletions
diff --git a/xfa/fxfa/fm2js/cxfa_fmexpression.cpp b/xfa/fxfa/fm2js/cxfa_fmexpression.cpp index 42d6546ef1..9381e7f8a1 100644 --- a/xfa/fxfa/fm2js/cxfa_fmexpression.cpp +++ b/xfa/fxfa/fm2js/cxfa_fmexpression.cpp @@ -14,10 +14,6 @@ namespace { -const wchar_t RUNTIMEBLOCKTEMPARRAY[] = L"pfm_ary"; - -const wchar_t RUNTIMEBLOCKTEMPARRAYINDEX[] = L"pfm_ary_idx"; - const wchar_t kLessEqual[] = L" <= "; const wchar_t kGreaterEqual[] = L" >= "; const wchar_t kPlusEqual[] = L" += "; @@ -103,12 +99,11 @@ bool CXFA_FMFunctionDefinition::ToJavaScript(CFX_WideTextBuf& javascript, return false; } javascript << L"return "; - if (m_isGlobal) { - javascript << XFA_FM_EXPTypeToString(GETFMVALUE); - javascript << L"(pfm_ret)"; - } else { + if (m_isGlobal) + javascript << L"pfm_rt.get_val(pfm_ret)"; + else javascript << L"pfm_ret"; - } + javascript << L";\n}\n"; if (m_isGlobal) { javascript << L").call(this);\n"; @@ -143,9 +138,7 @@ bool CXFA_FMVarExpression::ToJavaScript(CFX_WideTextBuf& javascript, if (!m_pInit->ToJavaScript(javascript, ReturnType::kInfered)) return false; javascript << tempName; - javascript << L" = "; - javascript << XFA_FM_EXPTypeToString(VARFILTER); - javascript << L"("; + javascript << L" = pfm_rt.var_filter("; javascript << tempName; javascript << L");\n"; } else { @@ -189,9 +182,7 @@ bool CXFA_FMExpExpression::ToJavaScript(CFX_WideTextBuf& javascript, m_pExpression->GetOperatorToken() == TOKdotscream || m_pExpression->GetOperatorToken() == TOKdotdot || m_pExpression->GetOperatorToken() == TOKdot) { - javascript << L"pfm_ret = "; - javascript << XFA_FM_EXPTypeToString(GETFMVALUE); - javascript << L"("; + javascript << L"pfm_ret = pfm_rt.get_val("; if (!m_pExpression->ToJavaScript(javascript, ReturnType::kInfered)) return false; javascript << L");\n"; @@ -278,8 +269,7 @@ bool CXFA_FMIfExpression::ToJavaScript(CFX_WideTextBuf& javascript, javascript << L"if ("; if (m_pExpression) { - javascript << XFA_FM_EXPTypeToString(GETFMVALUE); - javascript << L"("; + javascript << L"pfm_rt.get_val("; if (!m_pExpression->ToJavaScript(javascript, ReturnType::kInfered)) return false; javascript << L")"; @@ -422,17 +412,14 @@ bool CXFA_FMForExpression::ToJavaScript(CFX_WideTextBuf& javascript, javascript << L" = null;\n"; javascript << L"for ("; javascript << tempVariant; - javascript << L" = "; - javascript << XFA_FM_EXPTypeToString(GETFMVALUE); - javascript << L"("; + javascript << L" = pfm_rt.get_val("; if (!m_pAssignment->ToJavaScript(javascript, ReturnType::kInfered)) return false; javascript << L"); "; javascript << tempVariant; javascript << (m_bDirection ? kLessEqual : kGreaterEqual); - javascript << XFA_FM_EXPTypeToString(GETFMVALUE); - javascript << L"("; + javascript << L"pfm_rt.get_val("; if (!m_pAccessor->ToJavaScript(javascript, ReturnType::kInfered)) return false; javascript << L"); "; @@ -443,8 +430,7 @@ bool CXFA_FMForExpression::ToJavaScript(CFX_WideTextBuf& javascript, return false; if (m_pStep) { - javascript << XFA_FM_EXPTypeToString(GETFMVALUE); - javascript << L"("; + javascript << L"pfm_rt.get_val("; if (!m_pStep->ToJavaScript(javascript, ReturnType::kInfered)) return false; javascript << L")"; @@ -492,11 +478,7 @@ bool CXFA_FMForeachExpression::ToJavaScript(CFX_WideTextBuf& javascript, javascript << m_wsIdentifier; } javascript << L" = null;\n"; - javascript << L"var "; - javascript << RUNTIMEBLOCKTEMPARRAY; - javascript << L" = "; - javascript << XFA_FM_EXPTypeToString(CONCATFMOBJECT); - javascript << L"("; + javascript << L"var pfm_ary = pfm_rt.concat_obj("; for (const auto& expr : m_pAccessors) { if (!expr->ToJavaScript(javascript, ReturnType::kInfered)) @@ -505,14 +487,8 @@ bool CXFA_FMForeachExpression::ToJavaScript(CFX_WideTextBuf& javascript, javascript << L", "; } javascript << L");\n"; - javascript << L"var "; - javascript << RUNTIMEBLOCKTEMPARRAYINDEX; - javascript << (L" = 0;\n"); - javascript << L"while("; - javascript << RUNTIMEBLOCKTEMPARRAYINDEX; - javascript << L" < "; - javascript << RUNTIMEBLOCKTEMPARRAY; - javascript << L".length)\n{\n"; + javascript << L"var pfm_ary_idx = 0;\n"; + javascript << L"while(pfm_ary_idx < pfm_ary.length)\n{\n"; if (m_wsIdentifier[0] == L'!') { WideString tempIdentifier = L"pfm__excl__" + m_wsIdentifier.Right(m_wsIdentifier.GetLength() - 1); @@ -520,11 +496,7 @@ bool CXFA_FMForeachExpression::ToJavaScript(CFX_WideTextBuf& javascript, } else { javascript << m_wsIdentifier; } - javascript << L" = "; - javascript << RUNTIMEBLOCKTEMPARRAY; - javascript << L"["; - javascript << RUNTIMEBLOCKTEMPARRAYINDEX; - javascript << L"++];\n"; + javascript << L" = pfm_ary[pfm_ary_idx++];\n"; if (!m_pList->ToJavaScript(javascript, type)) return false; javascript << L"}\n"; diff --git a/xfa/fxfa/fm2js/cxfa_fmsimpleexpression.cpp b/xfa/fxfa/fm2js/cxfa_fmsimpleexpression.cpp index c634a512d1..76f780f962 100644 --- a/xfa/fxfa/fm2js/cxfa_fmsimpleexpression.cpp +++ b/xfa/fxfa/fm2js/cxfa_fmsimpleexpression.cpp @@ -18,19 +18,6 @@ namespace { -// Indexed by XFA_FM_SimpleExpressionType -const wchar_t* const gs_lpStrExpFuncName[] = { - L"pfm_rt.asgn_val_op", L"pfm_rt.log_or_op", L"pfm_rt.log_and_op", - L"pfm_rt.eq_op", L"pfm_rt.neq_op", L"pfm_rt.lt_op", - L"pfm_rt.le_op", L"pfm_rt.gt_op", L"pfm_rt.ge_op", - L"pfm_rt.plus_op", L"pfm_rt.minus_op", L"pfm_rt.mul_op", - L"pfm_rt.div_op", L"pfm_rt.pos_op", L"pfm_rt.neg_op", - L"pfm_rt.log_not_op", L"pfm_rt.", L"pfm_rt.dot_acc", - L"pfm_rt.dotdot_acc", L"pfm_rt.concat_obj", L"pfm_rt.is_obj", - L"pfm_rt.is_ary", L"pfm_rt.get_val", L"pfm_rt.get_jsobj", - L"pfm_rt.var_filter", -}; - const wchar_t* const g_BuiltInFuncs[] = { L"Abs", L"Apr", L"At", L"Avg", L"Ceil", L"Choose", L"Concat", L"Count", @@ -84,11 +71,6 @@ const XFA_FMSOMMethod gs_FMSomMethods[] = { } // namespace -WideStringView XFA_FM_EXPTypeToString( - XFA_FM_SimpleExpressionType simpleExpType) { - return gs_lpStrExpFuncName[simpleExpType]; -} - CXFA_FMSimpleExpression::CXFA_FMSimpleExpression(uint32_t line, XFA_FM_TOKEN op) : m_line(line), m_op(op) {} @@ -251,9 +233,7 @@ bool CXFA_FMAssignExpression::ToJavaScript(CFX_WideTextBuf& javascript, if (CXFA_IsTooBig(javascript) || !depthManager.IsWithinMaxDepth()) return false; - javascript << L"if ("; - javascript << gs_lpStrExpFuncName[ISFMOBJECT]; - javascript << L"("; + javascript << L"if (pfm_rt.is_obj("; CFX_WideTextBuf tempExp1; if (!m_pExp1->ToJavaScript(tempExp1, ReturnType::kInfered)) return false; @@ -263,8 +243,7 @@ bool CXFA_FMAssignExpression::ToJavaScript(CFX_WideTextBuf& javascript, if (type == ReturnType::kImplied) javascript << L"pfm_ret = "; - javascript << gs_lpStrExpFuncName[ASSIGN]; - javascript << L"("; + javascript << L"pfm_rt.asgn_val_op("; javascript << tempExp1; javascript << L", "; @@ -280,9 +259,7 @@ bool CXFA_FMAssignExpression::ToJavaScript(CFX_WideTextBuf& javascript, javascript << L"pfm_ret = "; javascript << tempExp1; - javascript << L" = "; - javascript << gs_lpStrExpFuncName[ASSIGN]; - javascript << L"("; + javascript << L" = pfm_rt.asgn_val_op("; javascript << tempExp1; javascript << L", "; javascript << tempExp2; @@ -304,8 +281,7 @@ bool CXFA_FMLogicalOrExpression::ToJavaScript(CFX_WideTextBuf& javascript, if (CXFA_IsTooBig(javascript) || !depthManager.IsWithinMaxDepth()) return false; - javascript << gs_lpStrExpFuncName[LOGICALOR]; - javascript << L"("; + javascript << L"pfm_rt.log_or_op("; if (!m_pExp1->ToJavaScript(javascript, ReturnType::kInfered)) return false; javascript << L", "; @@ -328,8 +304,7 @@ bool CXFA_FMLogicalAndExpression::ToJavaScript(CFX_WideTextBuf& javascript, if (CXFA_IsTooBig(javascript) || !depthManager.IsWithinMaxDepth()) return false; - javascript << gs_lpStrExpFuncName[LOGICALAND]; - javascript << L"("; + javascript << L"pfm_rt.log_and_op("; if (!m_pExp1->ToJavaScript(javascript, ReturnType::kInfered)) return false; javascript << L", "; @@ -355,11 +330,11 @@ bool CXFA_FMEqualityExpression::ToJavaScript(CFX_WideTextBuf& javascript, switch (m_op) { case TOKeq: case TOKkseq: - javascript << gs_lpStrExpFuncName[EQUALITY]; + javascript << L"pfm_rt.eq_op"; break; case TOKne: case TOKksne: - javascript << gs_lpStrExpFuncName[NOTEQUALITY]; + javascript << L"pfm_rt.neq_op"; break; default: NOTREACHED(); @@ -391,19 +366,19 @@ bool CXFA_FMRelationalExpression::ToJavaScript(CFX_WideTextBuf& javascript, switch (m_op) { case TOKlt: case TOKkslt: - javascript << gs_lpStrExpFuncName[LESS]; + javascript << L"pfm_rt.lt_op"; break; case TOKgt: case TOKksgt: - javascript << gs_lpStrExpFuncName[GREATER]; + javascript << L"pfm_rt.gt_op"; break; case TOKle: case TOKksle: - javascript << gs_lpStrExpFuncName[LESSEQUAL]; + javascript << L"pfm_rt.le_op"; break; case TOKge: case TOKksge: - javascript << gs_lpStrExpFuncName[GREATEREQUAL]; + javascript << L"pfm_rt.ge_op"; break; default: NOTREACHED(); @@ -434,10 +409,10 @@ bool CXFA_FMAdditiveExpression::ToJavaScript(CFX_WideTextBuf& javascript, switch (m_op) { case TOKplus: - javascript << gs_lpStrExpFuncName[PLUS]; + javascript << L"pfm_rt.plus_op"; break; case TOKminus: - javascript << gs_lpStrExpFuncName[MINUS]; + javascript << L"pfm_rt.minus_op"; break; default: NOTREACHED(); @@ -468,10 +443,10 @@ bool CXFA_FMMultiplicativeExpression::ToJavaScript(CFX_WideTextBuf& javascript, switch (m_op) { case TOKmul: - javascript << gs_lpStrExpFuncName[MULTIPLE]; + javascript << L"pfm_rt.mul_op"; break; case TOKdiv: - javascript << gs_lpStrExpFuncName[DIVIDE]; + javascript << L"pfm_rt.div_op"; break; default: NOTREACHED(); @@ -498,7 +473,7 @@ bool CXFA_FMPosExpression::ToJavaScript(CFX_WideTextBuf& javascript, if (CXFA_IsTooBig(javascript) || !depthManager.IsWithinMaxDepth()) return false; - javascript << gs_lpStrExpFuncName[POSITIVE]; + javascript << L"pfm_rt.pos_op"; javascript << L"("; if (!m_pExp->ToJavaScript(javascript, ReturnType::kInfered)) return false; @@ -517,7 +492,7 @@ bool CXFA_FMNegExpression::ToJavaScript(CFX_WideTextBuf& javascript, if (CXFA_IsTooBig(javascript) || !depthManager.IsWithinMaxDepth()) return false; - javascript << gs_lpStrExpFuncName[NEGATIVE]; + javascript << L"pfm_rt.neg_op"; javascript << L"("; if (!m_pExp->ToJavaScript(javascript, ReturnType::kInfered)) return false; @@ -536,7 +511,7 @@ bool CXFA_FMNotExpression::ToJavaScript(CFX_WideTextBuf& javascript, if (CXFA_IsTooBig(javascript) || !depthManager.IsWithinMaxDepth()) return false; - javascript << gs_lpStrExpFuncName[NOT]; + javascript << L"pfm_rt.log_not_op"; javascript << L"("; if (!m_pExp->ToJavaScript(javascript, ReturnType::kInfered)) return false; @@ -608,9 +583,9 @@ bool CXFA_FMCallExpression::ToJavaScript(CFX_WideTextBuf& javascript, // the 6th. Make sure we don't overflow the shift when doing this // check. If we ever need more the 32 object params we can revisit. if (i < 32 && (methodPara & (0x01 << i)) > 0) { - javascript << gs_lpStrExpFuncName[GETFMJSOBJ]; + javascript << L"pfm_rt.get_jsobj"; } else { - javascript << gs_lpStrExpFuncName[GETFMVALUE]; + javascript << L"pfm_rt.get_val"; } javascript << L"("; const auto& expr = m_Arguments[i]; @@ -623,7 +598,7 @@ bool CXFA_FMCallExpression::ToJavaScript(CFX_WideTextBuf& javascript, } } else { for (const auto& expr : m_Arguments) { - javascript << gs_lpStrExpFuncName[GETFMVALUE]; + javascript << L"pfm_rt.get_val"; javascript << L"("; if (!expr->ToJavaScript(javascript, ReturnType::kInfered)) return false; @@ -639,15 +614,13 @@ bool CXFA_FMCallExpression::ToJavaScript(CFX_WideTextBuf& javascript, if (IsBuiltInFunc(&funcName)) { if (funcName.AsStringView() == L"Eval") { isEvalFunc = true; - javascript << L"eval.call(this, "; - javascript << gs_lpStrExpFuncName[CALL]; - javascript << L"Translate"; + javascript << L"eval.call(this, pfm_rt.Translate"; } else if (funcName.AsStringView() == L"Exists") { isExistsFunc = true; - javascript << gs_lpStrExpFuncName[CALL]; + javascript << L"pfm_rt."; javascript << funcName; } else { - javascript << gs_lpStrExpFuncName[CALL]; + javascript << L"pfm_rt."; javascript << funcName; } } else { @@ -707,7 +680,7 @@ bool CXFA_FMDotAccessorExpression::ToJavaScript(CFX_WideTextBuf& javascript, if (CXFA_IsTooBig(javascript) || !depthManager.IsWithinMaxDepth()) return false; - javascript << gs_lpStrExpFuncName[DOT]; + javascript << L"pfm_rt.dot_acc"; javascript << L"("; CFX_WideTextBuf tempExp1; if (m_pExp1) { @@ -805,7 +778,7 @@ bool CXFA_FMDotDotAccessorExpression::ToJavaScript(CFX_WideTextBuf& javascript, if (CXFA_IsTooBig(javascript) || !depthManager.IsWithinMaxDepth()) return false; - javascript << gs_lpStrExpFuncName[DOTDOT]; + javascript << L"pfm_rt.dotdot_acc"; javascript << L"("; CFX_WideTextBuf tempExp1; if (!m_pExp1->ToJavaScript(tempExp1, ReturnType::kInfered)) @@ -847,9 +820,7 @@ bool CXFA_FMMethodCallExpression::ToJavaScript(CFX_WideTextBuf& javascript, if (!m_pExp1->ToJavaScript(javascript, ReturnType::kInfered)) return false; javascript << L";\n"; - javascript << L"if ("; - javascript << gs_lpStrExpFuncName[ISFMARRAY]; - javascript << L"(accessor_object))\n{\n"; + javascript << L"if (pfm_rt.is_ary(accessor_object))\n{\n"; javascript << L"for(var index = accessor_object.length - 1; index > 1; " L"index--)\n{\n"; javascript << L"method_return_value = accessor_object[index]."; diff --git a/xfa/fxfa/fm2js/cxfa_fmsimpleexpression.h b/xfa/fxfa/fm2js/cxfa_fmsimpleexpression.h index 3196fa0273..57f4d2ed11 100644 --- a/xfa/fxfa/fm2js/cxfa_fmsimpleexpression.h +++ b/xfa/fxfa/fm2js/cxfa_fmsimpleexpression.h @@ -12,39 +12,6 @@ #include "xfa/fxfa/fm2js/cxfa_fmlexer.h" -enum XFA_FM_SimpleExpressionType { - ASSIGN, - LOGICALOR, - LOGICALAND, - EQUALITY, - NOTEQUALITY, - LESS, - LESSEQUAL, - GREATER, - GREATEREQUAL, - PLUS, - MINUS, - MULTIPLE, - DIVIDE, - POSITIVE, - NEGATIVE, - NOT, - CALL, - DOT, - DOTDOT, - CONCATFMOBJECT, - ISFMOBJECT, - ISFMARRAY, - GETFMVALUE, - GETFMJSOBJ, - VARFILTER -}; - -class CFX_WideTextBuf; - -WideStringView XFA_FM_EXPTypeToString( - XFA_FM_SimpleExpressionType simpleExpType); - enum XFA_FM_AccessorIndex { ACCESSOR_NO_INDEX, ACCESSOR_NO_RELATIVEINDEX, @@ -54,6 +21,8 @@ enum XFA_FM_AccessorIndex { enum class ReturnType { kImplied, kInfered }; +class CFX_WideTextBuf; + class CXFA_FMSimpleExpression { public: CXFA_FMSimpleExpression(uint32_t line, XFA_FM_TOKEN op); |