#include "xfa/fxfa/formcalc/cxfa_fmexpression.h"
#include <algorithm>
#include <utility>
#include "core/fxcrt/autorestorer.h"
#include "core/fxcrt/check.h"
#include "core/fxcrt/fx_extension.h"
#include "core/fxcrt/widetext_buffer.h"
#include "fxjs/gc/container_trace.h"
#include "v8/include/cppgc/visitor.h"
#include "xfa/fxfa/formcalc/cxfa_fmtojavascriptdepth.h"
namespace {
const wchar_t kLessEqual[] = …;
const wchar_t kGreaterEqual[] = …;
const wchar_t kPlusEqual[] = …;
const wchar_t kMinusEqual[] = …;
const wchar_t* const kBuiltInFuncs[] = …;
const size_t kBuiltInFuncsMaxLen = …;
struct XFA_FMSOMMethod { … };
const XFA_FMSOMMethod kFMSomMethods[] = …;
WideString IdentifierToName(const WideString& ident) { … }
}
CXFA_FMExpression::CXFA_FMExpression() = default;
CXFA_FMExpression::~CXFA_FMExpression() = default;
void CXFA_FMExpression::Trace(cppgc::Visitor* visitor) const { … }
CXFA_FMSimpleExpression::CXFA_FMSimpleExpression(XFA_FM_TOKEN op) : … { … }
CXFA_FMSimpleExpression::~CXFA_FMSimpleExpression() = default;
CXFA_FMChainableExpression::CXFA_FMChainableExpression(
XFA_FM_TOKEN op,
CXFA_FMSimpleExpression* pExp1,
CXFA_FMSimpleExpression* pExp2)
: … { … }
CXFA_FMChainableExpression::~CXFA_FMChainableExpression() = default;
void CXFA_FMChainableExpression::Trace(cppgc::Visitor* visitor) const { … }
CXFA_FMNullExpression::CXFA_FMNullExpression()
: … { … }
CXFA_FMNullExpression::~CXFA_FMNullExpression() = default;
bool CXFA_FMNullExpression::ToJavaScript(WideTextBuffer* js,
ReturnType type) const { … }
CXFA_FMNumberExpression::CXFA_FMNumberExpression(WideString wsNumber)
: … { … }
CXFA_FMNumberExpression::~CXFA_FMNumberExpression() = default;
bool CXFA_FMNumberExpression::ToJavaScript(WideTextBuffer* js,
ReturnType type) const { … }
CXFA_FMStringExpression::CXFA_FMStringExpression(WideString wsString)
: … { … }
CXFA_FMStringExpression::~CXFA_FMStringExpression() = default;
bool CXFA_FMStringExpression::ToJavaScript(WideTextBuffer* js,
ReturnType type) const { … }
CXFA_FMIdentifierExpression::CXFA_FMIdentifierExpression(
WideString wsIdentifier)
: … { … }
CXFA_FMIdentifierExpression::~CXFA_FMIdentifierExpression() = default;
bool CXFA_FMIdentifierExpression::ToJavaScript(WideTextBuffer* js,
ReturnType type) const { … }
CXFA_FMAssignExpression::CXFA_FMAssignExpression(XFA_FM_TOKEN op,
CXFA_FMSimpleExpression* pExp1,
CXFA_FMSimpleExpression* pExp2)
: … { … }
CXFA_FMAssignExpression::~CXFA_FMAssignExpression() = default;
bool CXFA_FMAssignExpression::ToJavaScript(WideTextBuffer* js,
ReturnType type) const { … }
CXFA_FMBinExpression::CXFA_FMBinExpression(const WideString& opName,
XFA_FM_TOKEN op,
CXFA_FMSimpleExpression* pExp1,
CXFA_FMSimpleExpression* pExp2)
: … { … }
CXFA_FMBinExpression::~CXFA_FMBinExpression() = default;
bool CXFA_FMBinExpression::ToJavaScript(WideTextBuffer* js,
ReturnType type) const { … }
CXFA_FMLogicalOrExpression::CXFA_FMLogicalOrExpression(
XFA_FM_TOKEN op,
CXFA_FMSimpleExpression* pExp1,
CXFA_FMSimpleExpression* pExp2)
: … { … }
CXFA_FMLogicalOrExpression::~CXFA_FMLogicalOrExpression() = default;
CXFA_FMLogicalAndExpression::CXFA_FMLogicalAndExpression(
XFA_FM_TOKEN op,
CXFA_FMSimpleExpression* pExp1,
CXFA_FMSimpleExpression* pExp2)
: … { … }
CXFA_FMLogicalAndExpression::~CXFA_FMLogicalAndExpression() = default;
CXFA_FMEqualExpression::CXFA_FMEqualExpression(XFA_FM_TOKEN op,
CXFA_FMSimpleExpression* pExp1,
CXFA_FMSimpleExpression* pExp2)
: … { … }
CXFA_FMEqualExpression::~CXFA_FMEqualExpression() = default;
CXFA_FMNotEqualExpression::CXFA_FMNotEqualExpression(
XFA_FM_TOKEN op,
CXFA_FMSimpleExpression* pExp1,
CXFA_FMSimpleExpression* pExp2)
: … { … }
CXFA_FMNotEqualExpression::~CXFA_FMNotEqualExpression() = default;
CXFA_FMGtExpression::CXFA_FMGtExpression(XFA_FM_TOKEN op,
CXFA_FMSimpleExpression* pExp1,
CXFA_FMSimpleExpression* pExp2)
: … { … }
CXFA_FMGtExpression::~CXFA_FMGtExpression() = default;
CXFA_FMGeExpression::CXFA_FMGeExpression(XFA_FM_TOKEN op,
CXFA_FMSimpleExpression* pExp1,
CXFA_FMSimpleExpression* pExp2)
: … { … }
CXFA_FMGeExpression::~CXFA_FMGeExpression() = default;
CXFA_FMLtExpression::CXFA_FMLtExpression(XFA_FM_TOKEN op,
CXFA_FMSimpleExpression* pExp1,
CXFA_FMSimpleExpression* pExp2)
: … { … }
CXFA_FMLtExpression::~CXFA_FMLtExpression() = default;
CXFA_FMLeExpression::CXFA_FMLeExpression(XFA_FM_TOKEN op,
CXFA_FMSimpleExpression* pExp1,
CXFA_FMSimpleExpression* pExp2)
: … { … }
CXFA_FMLeExpression::~CXFA_FMLeExpression() = default;
CXFA_FMPlusExpression::CXFA_FMPlusExpression(XFA_FM_TOKEN op,
CXFA_FMSimpleExpression* pExp1,
CXFA_FMSimpleExpression* pExp2)
: … { … }
CXFA_FMPlusExpression::~CXFA_FMPlusExpression() = default;
CXFA_FMMinusExpression::CXFA_FMMinusExpression(XFA_FM_TOKEN op,
CXFA_FMSimpleExpression* pExp1,
CXFA_FMSimpleExpression* pExp2)
: … { … }
CXFA_FMMinusExpression::~CXFA_FMMinusExpression() = default;
CXFA_FMMulExpression::CXFA_FMMulExpression(XFA_FM_TOKEN op,
CXFA_FMSimpleExpression* pExp1,
CXFA_FMSimpleExpression* pExp2)
: … { … }
CXFA_FMMulExpression::~CXFA_FMMulExpression() = default;
CXFA_FMDivExpression::CXFA_FMDivExpression(XFA_FM_TOKEN op,
CXFA_FMSimpleExpression* pExp1,
CXFA_FMSimpleExpression* pExp2)
: … { … }
CXFA_FMDivExpression::~CXFA_FMDivExpression() = default;
CXFA_FMUnaryExpression::CXFA_FMUnaryExpression(const WideString& opName,
XFA_FM_TOKEN op,
CXFA_FMSimpleExpression* pExp)
: … { … }
CXFA_FMUnaryExpression::~CXFA_FMUnaryExpression() = default;
void CXFA_FMUnaryExpression::Trace(cppgc::Visitor* visitor) const { … }
bool CXFA_FMUnaryExpression::ToJavaScript(WideTextBuffer* js,
ReturnType type) const { … }
CXFA_FMPosExpression::CXFA_FMPosExpression(CXFA_FMSimpleExpression* pExp)
: … { … }
CXFA_FMPosExpression::~CXFA_FMPosExpression() = default;
CXFA_FMNegExpression::CXFA_FMNegExpression(CXFA_FMSimpleExpression* pExp)
: … { … }
CXFA_FMNegExpression::~CXFA_FMNegExpression() = default;
CXFA_FMNotExpression::CXFA_FMNotExpression(CXFA_FMSimpleExpression* pExp)
: … { … }
CXFA_FMNotExpression::~CXFA_FMNotExpression() = default;
CXFA_FMCallExpression::CXFA_FMCallExpression(
CXFA_FMSimpleExpression* pExp,
std::vector<cppgc::Member<CXFA_FMSimpleExpression>>&& pArguments,
bool bIsSomMethod)
: … { … }
CXFA_FMCallExpression::~CXFA_FMCallExpression() = default;
void CXFA_FMCallExpression::Trace(cppgc::Visitor* visitor) const { … }
bool CXFA_FMCallExpression::IsBuiltInFunc(WideTextBuffer* funcName) const { … }
uint32_t CXFA_FMCallExpression::IsMethodWithObjParam(
const WideString& methodName) const { … }
bool CXFA_FMCallExpression::ToJavaScript(WideTextBuffer* js,
ReturnType type) const { … }
CXFA_FMDotAccessorExpression::CXFA_FMDotAccessorExpression(
CXFA_FMSimpleExpression* pAccessor,
XFA_FM_TOKEN op,
WideString wsIdentifier,
CXFA_FMSimpleExpression* pIndexExp)
: … { … }
CXFA_FMDotAccessorExpression::~CXFA_FMDotAccessorExpression() = default;
bool CXFA_FMDotAccessorExpression::ToJavaScript(WideTextBuffer* js,
ReturnType type) const { … }
CXFA_FMIndexExpression::CXFA_FMIndexExpression(
AccessorIndex accessorIndex,
CXFA_FMSimpleExpression* pIndexExp,
bool bIsStarIndex)
: … { … }
CXFA_FMIndexExpression::~CXFA_FMIndexExpression() = default;
void CXFA_FMIndexExpression::Trace(cppgc::Visitor* visitor) const { … }
bool CXFA_FMIndexExpression::ToJavaScript(WideTextBuffer* js,
ReturnType type) const { … }
CXFA_FMDotDotAccessorExpression::CXFA_FMDotDotAccessorExpression(
CXFA_FMSimpleExpression* pAccessor,
XFA_FM_TOKEN op,
WideString wsIdentifier,
CXFA_FMSimpleExpression* pIndexExp)
: … { … }
CXFA_FMDotDotAccessorExpression::~CXFA_FMDotDotAccessorExpression() = default;
bool CXFA_FMDotDotAccessorExpression::ToJavaScript(WideTextBuffer* js,
ReturnType type) const { … }
CXFA_FMMethodCallExpression::CXFA_FMMethodCallExpression(
CXFA_FMSimpleExpression* pAccessorExp1,
CXFA_FMSimpleExpression* pCallExp)
: … { … }
CXFA_FMMethodCallExpression::~CXFA_FMMethodCallExpression() = default;
bool CXFA_FMMethodCallExpression::ToJavaScript(WideTextBuffer* js,
ReturnType type) const { … }
CXFA_FMFunctionDefinition::CXFA_FMFunctionDefinition(
WideString wsName,
std::vector<WideString>&& arguments,
std::vector<cppgc::Member<CXFA_FMExpression>>&& expressions)
: … { … }
CXFA_FMFunctionDefinition::~CXFA_FMFunctionDefinition() = default;
void CXFA_FMFunctionDefinition::Trace(cppgc::Visitor* visitor) const { … }
bool CXFA_FMFunctionDefinition::ToJavaScript(WideTextBuffer* js,
ReturnType type) const { … }
CXFA_FMAST::CXFA_FMAST(
std::vector<cppgc::Member<CXFA_FMExpression>> expressions)
: … { … }
CXFA_FMAST::~CXFA_FMAST() = default;
void CXFA_FMAST::Trace(cppgc::Visitor* visitor) const { … }
std::optional<WideTextBuffer> CXFA_FMAST::ToJavaScript() const { … }
CXFA_FMVarExpression::CXFA_FMVarExpression(WideString wsName,
CXFA_FMSimpleExpression* pInit)
: … { … }
CXFA_FMVarExpression::~CXFA_FMVarExpression() = default;
void CXFA_FMVarExpression::Trace(cppgc::Visitor* visitor) const { … }
bool CXFA_FMVarExpression::ToJavaScript(WideTextBuffer* js,
ReturnType type) const { … }
CXFA_FMExpExpression::CXFA_FMExpExpression(CXFA_FMSimpleExpression* pExpression)
: … { … }
CXFA_FMExpExpression::~CXFA_FMExpExpression() = default;
void CXFA_FMExpExpression::Trace(cppgc::Visitor* visitor) const { … }
bool CXFA_FMExpExpression::ToJavaScript(WideTextBuffer* js,
ReturnType type) const { … }
CXFA_FMBlockExpression::CXFA_FMBlockExpression(
std::vector<cppgc::Member<CXFA_FMExpression>>&& pExpressionList)
: … { … }
CXFA_FMBlockExpression::~CXFA_FMBlockExpression() = default;
void CXFA_FMBlockExpression::Trace(cppgc::Visitor* visitor) const { … }
bool CXFA_FMBlockExpression::ToJavaScript(WideTextBuffer* js,
ReturnType type) const { … }
CXFA_FMDoExpression::CXFA_FMDoExpression(CXFA_FMExpression* pList)
: … { … }
CXFA_FMDoExpression::~CXFA_FMDoExpression() = default;
void CXFA_FMDoExpression::Trace(cppgc::Visitor* visitor) const { … }
bool CXFA_FMDoExpression::ToJavaScript(WideTextBuffer* js,
ReturnType type) const { … }
CXFA_FMIfExpression::CXFA_FMIfExpression(
CXFA_FMSimpleExpression* pExpression,
CXFA_FMExpression* pIfExpression,
std::vector<cppgc::Member<CXFA_FMIfExpression>>&& pElseIfExpressions,
CXFA_FMExpression* pElseExpression)
: … { … }
CXFA_FMIfExpression::~CXFA_FMIfExpression() = default;
void CXFA_FMIfExpression::Trace(cppgc::Visitor* visitor) const { … }
bool CXFA_FMIfExpression::ToJavaScript(WideTextBuffer* js,
ReturnType type) const { … }
CXFA_FMWhileExpression::CXFA_FMWhileExpression(
CXFA_FMSimpleExpression* pCondition,
CXFA_FMExpression* pExpression)
: … { … }
CXFA_FMWhileExpression::~CXFA_FMWhileExpression() = default;
void CXFA_FMWhileExpression::Trace(cppgc::Visitor* visitor) const { … }
bool CXFA_FMWhileExpression::ToJavaScript(WideTextBuffer* js,
ReturnType type) const { … }
CXFA_FMBreakExpression::CXFA_FMBreakExpression() = default;
CXFA_FMBreakExpression::~CXFA_FMBreakExpression() = default;
bool CXFA_FMBreakExpression::ToJavaScript(WideTextBuffer* js,
ReturnType type) const { … }
CXFA_FMContinueExpression::CXFA_FMContinueExpression() = default;
CXFA_FMContinueExpression::~CXFA_FMContinueExpression() = default;
bool CXFA_FMContinueExpression::ToJavaScript(WideTextBuffer* js,
ReturnType type) const { … }
CXFA_FMForExpression::CXFA_FMForExpression(WideString wsVariant,
CXFA_FMSimpleExpression* pAssignment,
CXFA_FMSimpleExpression* pAccessor,
int32_t iDirection,
CXFA_FMSimpleExpression* pStep,
CXFA_FMExpression* pList)
: … { … }
CXFA_FMForExpression::~CXFA_FMForExpression() = default;
void CXFA_FMForExpression::Trace(cppgc::Visitor* visitor) const { … }
bool CXFA_FMForExpression::ToJavaScript(WideTextBuffer* js,
ReturnType type) const { … }
CXFA_FMForeachExpression::CXFA_FMForeachExpression(
WideString wsIdentifier,
std::vector<cppgc::Member<CXFA_FMSimpleExpression>>&& pAccessors,
CXFA_FMExpression* pList)
: … { … }
CXFA_FMForeachExpression::~CXFA_FMForeachExpression() = default;
void CXFA_FMForeachExpression::Trace(cppgc::Visitor* visitor) const { … }
bool CXFA_FMForeachExpression::ToJavaScript(WideTextBuffer* js,
ReturnType type) const { … }
bool CXFA_IsTooBig(const WideTextBuffer& js) { … }