diff options
Diffstat (limited to 'xfa/fxfa/fm2js')
-rw-r--r-- | xfa/fxfa/fm2js/xfa_expression.cpp | 54 | ||||
-rw-r--r-- | xfa/fxfa/fm2js/xfa_expression.h | 36 | ||||
-rw-r--r-- | xfa/fxfa/fm2js/xfa_fmparse.cpp | 33 | ||||
-rw-r--r-- | xfa/fxfa/fm2js/xfa_fmparse.h | 2 | ||||
-rw-r--r-- | xfa/fxfa/fm2js/xfa_program.cpp | 12 | ||||
-rw-r--r-- | xfa/fxfa/fm2js/xfa_simpleexpression.cpp | 30 | ||||
-rw-r--r-- | xfa/fxfa/fm2js/xfa_simpleexpression.h | 5 |
7 files changed, 81 insertions, 91 deletions
diff --git a/xfa/fxfa/fm2js/xfa_expression.cpp b/xfa/fxfa/fm2js/xfa_expression.cpp index be9fb09c0d..cecffb9112 100644 --- a/xfa/fxfa/fm2js/xfa_expression.cpp +++ b/xfa/fxfa/fm2js/xfa_expression.cpp @@ -33,7 +33,7 @@ CXFA_FMFunctionDefinition::CXFA_FMFunctionDefinition( FX_BOOL isGlobal, const CFX_WideStringC& wsName, CFX_WideStringCArray* pArguments, - CFX_PtrArray* pExpressions) + CFX_ArrayTemplate<CXFA_FMExpression*>* pExpressions) : CXFA_FMExpression(line, XFA_FM_EXPTYPE_FUNC), m_wsName(wsName), m_pArguments(pArguments), @@ -41,15 +41,11 @@ CXFA_FMFunctionDefinition::CXFA_FMFunctionDefinition( m_isGlobal(isGlobal) {} CXFA_FMFunctionDefinition::~CXFA_FMFunctionDefinition() { - if (m_pArguments) { - m_pArguments->RemoveAll(); - delete m_pArguments; - } + delete m_pArguments; if (m_pExpressions) { - for (int i = 0; i < m_pExpressions->GetSize(); ++i) { - delete reinterpret_cast<CXFA_FMExpression*>(m_pExpressions->GetAt(i)); - } - m_pExpressions->RemoveAll(); + for (int i = 0; i < m_pExpressions->GetSize(); ++i) + delete m_pExpressions->GetAt(i); + delete m_pExpressions; } } @@ -92,8 +88,7 @@ void CXFA_FMFunctionDefinition::ToJavaScript(CFX_WideTextBuf& javascript) { javascript << FX_WSTRC(L" = null;\n"); if (m_pExpressions) { for (int i = 0; i < m_pExpressions->GetSize(); ++i) { - CXFA_FMExpression* e = - reinterpret_cast<CXFA_FMExpression*>(m_pExpressions->GetAt(i)); + CXFA_FMExpression* e = m_pExpressions->GetAt(i); if (i + 1 < m_pExpressions->GetSize()) { e->ToJavaScript(javascript); } else { @@ -208,17 +203,17 @@ void CXFA_FMExpExpression::ToImpliedReturnJS(CFX_WideTextBuf& javascript) { } } -CXFA_FMBlockExpression::CXFA_FMBlockExpression(uint32_t line, - CFX_PtrArray* pExpressionList) +CXFA_FMBlockExpression::CXFA_FMBlockExpression( + uint32_t line, + CFX_ArrayTemplate<CXFA_FMExpression*>* pExpressionList) : CXFA_FMExpression(line, XFA_FM_EXPTYPE_BLOCK), m_pExpressionList(pExpressionList) {} CXFA_FMBlockExpression::~CXFA_FMBlockExpression() { if (m_pExpressionList) { - for (int i = 0; i < m_pExpressionList->GetSize(); ++i) { - delete reinterpret_cast<CXFA_FMExpression*>(m_pExpressionList->GetAt(i)); - } - m_pExpressionList->RemoveAll(); + for (int i = 0; i < m_pExpressionList->GetSize(); ++i) + delete m_pExpressionList->GetAt(i); + delete m_pExpressionList; } } @@ -226,11 +221,8 @@ CXFA_FMBlockExpression::~CXFA_FMBlockExpression() { void CXFA_FMBlockExpression::ToJavaScript(CFX_WideTextBuf& javascript) { javascript << FX_WSTRC(L"{\n"); if (m_pExpressionList) { - for (int i = 0; i < m_pExpressionList->GetSize(); ++i) { - CXFA_FMExpression* e = - reinterpret_cast<CXFA_FMExpression*>(m_pExpressionList->GetAt(i)); - e->ToJavaScript(javascript); - } + for (int i = 0; i < m_pExpressionList->GetSize(); ++i) + m_pExpressionList->GetAt(i)->ToJavaScript(javascript); } javascript << FX_WSTRC(L"}\n"); } @@ -239,8 +231,7 @@ void CXFA_FMBlockExpression::ToImpliedReturnJS(CFX_WideTextBuf& javascript) { javascript << FX_WSTRC(L"{\n"); if (m_pExpressionList) { for (int i = 0; i < m_pExpressionList->GetSize(); ++i) { - CXFA_FMExpression* e = - reinterpret_cast<CXFA_FMExpression*>(m_pExpressionList->GetAt(i)); + CXFA_FMExpression* e = m_pExpressionList->GetAt(i); if (i + 1 == m_pExpressionList->GetSize()) { e->ToImpliedReturnJS(javascript); } else { @@ -506,7 +497,7 @@ void CXFA_FMForExpression::ToImpliedReturnJS(CFX_WideTextBuf& javascript) { CXFA_FMForeachExpression::CXFA_FMForeachExpression( uint32_t line, const CFX_WideStringC& wsIdentifier, - CFX_PtrArray* pAccessors, + CFX_ArrayTemplate<CXFA_FMSimpleExpression*>* pAccessors, CXFA_FMExpression* pList) : CXFA_FMLoopExpression(line), m_wsIdentifier(wsIdentifier), @@ -515,10 +506,9 @@ CXFA_FMForeachExpression::CXFA_FMForeachExpression( CXFA_FMForeachExpression::~CXFA_FMForeachExpression() { if (m_pAccessors) { - for (int i = 0; i < m_pAccessors->GetSize(); ++i) { - delete reinterpret_cast<CXFA_FMSimpleExpression*>(m_pAccessors->GetAt(i)); - } - m_pAccessors->RemoveAll(); + for (int i = 0; i < m_pAccessors->GetSize(); ++i) + m_pAccessors->GetAt(i); + delete m_pAccessors; } } @@ -541,8 +531,7 @@ void CXFA_FMForeachExpression::ToJavaScript(CFX_WideTextBuf& javascript) { javascript << FX_WSTRC(L"("); for (int i = 0; i < m_pAccessors->GetSize(); ++i) { - CXFA_FMSimpleExpression* s = - reinterpret_cast<CXFA_FMSimpleExpression*>(m_pAccessors->GetAt(i)); + CXFA_FMSimpleExpression* s = m_pAccessors->GetAt(i); s->ToJavaScript(javascript); if (i + 1 < m_pAccessors->GetSize()) { javascript << FX_WSTRC(L", "); @@ -593,8 +582,7 @@ void CXFA_FMForeachExpression::ToImpliedReturnJS(CFX_WideTextBuf& javascript) { javascript << XFA_FM_EXPTypeToString(CONCATFMOBJECT); javascript << FX_WSTRC(L"("); for (int i = 0; i < m_pAccessors->GetSize(); ++i) { - CXFA_FMSimpleExpression* s = - reinterpret_cast<CXFA_FMSimpleExpression*>(m_pAccessors->GetAt(i)); + CXFA_FMSimpleExpression* s = m_pAccessors->GetAt(i); s->ToJavaScript(javascript); if (i + 1 < m_pAccessors->GetSize()) { javascript << FX_WSTRC(L", "); diff --git a/xfa/fxfa/fm2js/xfa_expression.h b/xfa/fxfa/fm2js/xfa_expression.h index 9bd0c9b89f..ff898a9c41 100644 --- a/xfa/fxfa/fm2js/xfa_expression.h +++ b/xfa/fxfa/fm2js/xfa_expression.h @@ -39,19 +39,22 @@ class CXFA_FMExpression { class CXFA_FMFunctionDefinition : public CXFA_FMExpression { public: - CXFA_FMFunctionDefinition(uint32_t line, - FX_BOOL isGlobal, - const CFX_WideStringC& wsName, - CFX_WideStringCArray* pArguments, - CFX_PtrArray* pExpressions); + // Takes ownership of |pExpressions|. + CXFA_FMFunctionDefinition( + uint32_t line, + FX_BOOL isGlobal, + const CFX_WideStringC& wsName, + CFX_WideStringCArray* pArguments, + CFX_ArrayTemplate<CXFA_FMExpression*>* pExpressions); ~CXFA_FMFunctionDefinition() override; + void ToJavaScript(CFX_WideTextBuf& javascript) override; void ToImpliedReturnJS(CFX_WideTextBuf&) override; private: CFX_WideStringC m_wsName; CFX_WideStringCArray* m_pArguments; - CFX_PtrArray* m_pExpressions; + CFX_ArrayTemplate<CXFA_FMExpression*>* m_pExpressions; FX_BOOL m_isGlobal; }; @@ -80,13 +83,17 @@ class CXFA_FMExpExpression : public CXFA_FMExpression { class CXFA_FMBlockExpression : public CXFA_FMExpression { public: - CXFA_FMBlockExpression(uint32_t line, CFX_PtrArray* pExpressionList); + // Takes ownership of |pExpressionList|. + CXFA_FMBlockExpression( + uint32_t line, + CFX_ArrayTemplate<CXFA_FMExpression*>* pExpressionList); ~CXFA_FMBlockExpression() override; + void ToJavaScript(CFX_WideTextBuf& javascript) override; void ToImpliedReturnJS(CFX_WideTextBuf&) override; private: - CFX_PtrArray* m_pExpressionList; + CFX_ArrayTemplate<CXFA_FMExpression*>* m_pExpressionList; }; class CXFA_FMDoExpression : public CXFA_FMExpression { @@ -174,17 +181,20 @@ class CXFA_FMForExpression : public CXFA_FMLoopExpression { class CXFA_FMForeachExpression : public CXFA_FMLoopExpression { public: - CXFA_FMForeachExpression(uint32_t line, - const CFX_WideStringC& wsIdentifier, - CFX_PtrArray* pAccessors, - CXFA_FMExpression* pList); + // Takes ownership of |pAccessors|. + CXFA_FMForeachExpression( + uint32_t line, + const CFX_WideStringC& wsIdentifier, + CFX_ArrayTemplate<CXFA_FMSimpleExpression*>* pAccessors, + CXFA_FMExpression* pList); ~CXFA_FMForeachExpression() override; + void ToJavaScript(CFX_WideTextBuf& javascript) override; void ToImpliedReturnJS(CFX_WideTextBuf&) override; private: CFX_WideStringC m_wsIdentifier; - CFX_PtrArray* m_pAccessors; + CFX_ArrayTemplate<CXFA_FMSimpleExpression*>* m_pAccessors; std::unique_ptr<CXFA_FMExpression> m_pList; }; diff --git a/xfa/fxfa/fm2js/xfa_fmparse.cpp b/xfa/fxfa/fm2js/xfa_fmparse.cpp index a917e23b8b..0a9fa81bad 100644 --- a/xfa/fxfa/fm2js/xfa_fmparse.cpp +++ b/xfa/fxfa/fm2js/xfa_fmparse.cpp @@ -44,9 +44,10 @@ void CXFA_FMParse::Error(uint32_t lineNum, const FX_WCHAR* msg, ...) { va_end(ap); } -CFX_PtrArray* CXFA_FMParse::ParseTopExpression() { +CFX_ArrayTemplate<CXFA_FMExpression*>* CXFA_FMParse::ParseTopExpression() { std::unique_ptr<CXFA_FMExpression> e; - CFX_PtrArray* expression = new CFX_PtrArray(); + CFX_ArrayTemplate<CXFA_FMExpression*>* expression = + new CFX_ArrayTemplate<CXFA_FMExpression*>(); while (1) { if (m_pToken->m_type == TOKeof || m_pToken->m_type == TOKendfunc || m_pToken->m_type == TOKendif || m_pToken->m_type == TOKelseif || @@ -77,7 +78,7 @@ CXFA_FMExpression* CXFA_FMParse::ParseFunction() { std::unique_ptr<CXFA_FMExpression> e; CFX_WideStringC ident; std::unique_ptr<CFX_WideStringCArray> pArguments; - std::unique_ptr<CFX_PtrArray> pExpressions; + std::unique_ptr<CFX_ArrayTemplate<CXFA_FMExpression*>> pExpressions; uint32_t line = m_pToken->m_uLinenum; NextToken(); if (m_pToken->m_type != TOKidentifier) { @@ -133,7 +134,7 @@ CXFA_FMExpression* CXFA_FMParse::ParseFunction() { pArguments->RemoveAll(); if (pExpressions) { for (int i = 0; i < pExpressions->GetSize(); ++i) - delete static_cast<CXFA_FMExpression*>(pExpressions->GetAt(i)); + delete pExpressions->GetAt(i); } } return e.release(); @@ -550,9 +551,9 @@ CXFA_FMSimpleExpression* CXFA_FMParse::ParsePostExpression( switch (m_pToken->m_type) { case TOKlparen: { NextToken(); - std::unique_ptr<CFX_PtrArray> pArray; + std::unique_ptr<CFX_ArrayTemplate<CXFA_FMSimpleExpression*>> pArray; if (m_pToken->m_type != TOKrparen) { - pArray.reset(new CFX_PtrArray()); + pArray.reset(new CFX_ArrayTemplate<CXFA_FMSimpleExpression*>()); while (m_pToken->m_type != TOKrparen) { CXFA_FMSimpleExpression* e = ParseSimpleExpression(); if (e) { @@ -588,7 +589,7 @@ CXFA_FMSimpleExpression* CXFA_FMParse::ParsePostExpression( } else { if (pArray) { for (int32_t i = 0; i < pArray->GetSize(); ++i) - delete static_cast<CXFA_FMSimpleExpression*>(pArray->GetAt(i)); + delete pArray->GetAt(i); } delete e; e = nullptr; @@ -605,9 +606,9 @@ CXFA_FMSimpleExpression* CXFA_FMParse::ParsePostExpression( CXFA_FMSimpleExpression* pExpCall; pExpAccessor = e; NextToken(); - std::unique_ptr<CFX_PtrArray> pArray; + std::unique_ptr<CFX_ArrayTemplate<CXFA_FMSimpleExpression*>> pArray; if (m_pToken->m_type != TOKrparen) { - pArray.reset(new CFX_PtrArray()); + pArray.reset(new CFX_ArrayTemplate<CXFA_FMSimpleExpression*>()); while (m_pToken->m_type != TOKrparen) { CXFA_FMSimpleExpression* exp = ParseSimpleExpression(); pArray->Add(exp); @@ -644,10 +645,8 @@ CXFA_FMSimpleExpression* CXFA_FMParse::ParsePostExpression( } } else { if (pArray) { - for (int32_t i = 0; i < pArray->GetSize(); ++i) { - delete static_cast<CXFA_FMSimpleExpression*>( - pArray->GetAt(i)); - } + for (int32_t i = 0; i < pArray->GetSize(); ++i) + delete pArray->GetAt(i); } delete e; e = nullptr; @@ -809,7 +808,9 @@ CXFA_FMSimpleExpression* CXFA_FMParse::ParseParenExpression() { CXFA_FMExpression* CXFA_FMParse::ParseBlockExpression() { uint32_t line = m_pToken->m_uLinenum; CXFA_FMExpression* e = nullptr; - std::unique_ptr<CFX_PtrArray> expression(new CFX_PtrArray()); + std::unique_ptr<CFX_ArrayTemplate<CXFA_FMExpression*>> expression( + new CFX_ArrayTemplate<CXFA_FMExpression*>()); + while (1) { switch (m_pToken->m_type) { case TOKeof: @@ -987,7 +988,7 @@ CXFA_FMExpression* CXFA_FMParse::ParseForExpression() { CXFA_FMExpression* CXFA_FMParse::ParseForeachExpression() { std::unique_ptr<CXFA_FMExpression> e; CFX_WideStringC wsIdentifier; - std::unique_ptr<CFX_PtrArray> pAccessors; + std::unique_ptr<CFX_ArrayTemplate<CXFA_FMSimpleExpression*>> pAccessors; std::unique_ptr<CXFA_FMExpression> pList; uint32_t line = m_pToken->m_uLinenum; NextToken(); @@ -1006,7 +1007,7 @@ CXFA_FMExpression* CXFA_FMParse::ParseForeachExpression() { ws_TempString.c_str()); NextToken(); } else { - pAccessors.reset(new CFX_PtrArray()); + pAccessors.reset(new CFX_ArrayTemplate<CXFA_FMSimpleExpression*>()); while (m_pToken->m_type != TOKrparen) { CXFA_FMSimpleExpression* s = ParseSimpleExpression(); if (s) { diff --git a/xfa/fxfa/fm2js/xfa_fmparse.h b/xfa/fxfa/fm2js/xfa_fmparse.h index 014eccee08..3c11a73572 100644 --- a/xfa/fxfa/fm2js/xfa_fmparse.h +++ b/xfa/fxfa/fm2js/xfa_fmparse.h @@ -19,7 +19,7 @@ class CXFA_FMParse { void NextToken(); void Check(XFA_FM_TOKEN op); void Error(uint32_t lineNum, const FX_WCHAR* msg, ...); - CFX_PtrArray* ParseTopExpression(); + CFX_ArrayTemplate<CXFA_FMExpression*>* ParseTopExpression(); CXFA_FMExpression* ParseFunction(); CXFA_FMExpression* ParseExpression(); CXFA_FMExpression* ParseVarExpression(); diff --git a/xfa/fxfa/fm2js/xfa_program.cpp b/xfa/fxfa/fm2js/xfa_program.cpp index ef5efb214c..a5c429765f 100644 --- a/xfa/fxfa/fm2js/xfa_program.cpp +++ b/xfa/fxfa/fm2js/xfa_program.cpp @@ -17,20 +17,16 @@ int32_t CXFA_FMProgram::Init(const CFX_WideStringC& wsFormcalc) { return m_parse.Init(wsFormcalc, &m_pErrorInfo); } int32_t CXFA_FMProgram::ParseProgram() { - CFX_PtrArray* expressions = 0; + CFX_ArrayTemplate<CXFA_FMExpression*>* expressions = nullptr; m_parse.NextToken(); if (!m_pErrorInfo.message.IsEmpty()) { return -1; } expressions = m_parse.ParseTopExpression(); if (!m_pErrorInfo.message.IsEmpty()) { - CXFA_FMExpression* e = 0; - for (int32_t u = 0; u < expressions->GetSize(); ++u) { - e = (CXFA_FMExpression*)expressions->GetAt(u); - if (e) { - delete e; - } - } + for (int32_t u = 0; u < expressions->GetSize(); ++u) + delete expressions->GetAt(u); + delete expressions; return -1; } diff --git a/xfa/fxfa/fm2js/xfa_simpleexpression.cpp b/xfa/fxfa/fm2js/xfa_simpleexpression.cpp index 468bb3bf89..aad8f7bed0 100644 --- a/xfa/fxfa/fm2js/xfa_simpleexpression.cpp +++ b/xfa/fxfa/fm2js/xfa_simpleexpression.cpp @@ -464,20 +464,20 @@ void CXFA_FMNotExpression::ToJavaScript(CFX_WideTextBuf& javascript) { javascript << FX_WSTRC(L")"); } -CXFA_FMCallExpression::CXFA_FMCallExpression(uint32_t line, - CXFA_FMSimpleExpression* pExp, - CFX_PtrArray* pArguments, - FX_BOOL bIsSomMethod) +CXFA_FMCallExpression::CXFA_FMCallExpression( + uint32_t line, + CXFA_FMSimpleExpression* pExp, + CFX_ArrayTemplate<CXFA_FMSimpleExpression*>* pArguments, + FX_BOOL bIsSomMethod) : CXFA_FMUnaryExpression(line, TOKcall, pExp), m_bIsSomMethod(bIsSomMethod), m_pArguments(pArguments) {} CXFA_FMCallExpression::~CXFA_FMCallExpression() { if (m_pArguments) { - for (int i = 0; i < m_pArguments->GetSize(); ++i) { - delete reinterpret_cast<CXFA_FMSimpleExpression*>(m_pArguments->GetAt(i)); - } - m_pArguments->RemoveAll(); + for (int i = 0; i < m_pArguments->GetSize(); ++i) + delete m_pArguments->GetAt(i); + delete m_pArguments; } } @@ -537,9 +537,7 @@ void CXFA_FMCallExpression::ToJavaScript(CFX_WideTextBuf& javascript) { javascript << gs_lpStrExpFuncName[GETFMVALUE]; } javascript << FX_WSTRC(L"("); - CXFA_FMSimpleExpression* e = - reinterpret_cast<CXFA_FMSimpleExpression*>( - m_pArguments->GetAt(i)); + CXFA_FMSimpleExpression* e = m_pArguments->GetAt(i); e->ToJavaScript(javascript); javascript << FX_WSTRC(L")"); if (i + 1 < m_pArguments->GetSize()) { @@ -550,9 +548,7 @@ void CXFA_FMCallExpression::ToJavaScript(CFX_WideTextBuf& javascript) { for (int i = 0; i < m_pArguments->GetSize(); ++i) { javascript << gs_lpStrExpFuncName[GETFMVALUE]; javascript << FX_WSTRC(L"("); - CXFA_FMSimpleExpression* e = - reinterpret_cast<CXFA_FMSimpleExpression*>( - m_pArguments->GetAt(i)); + CXFA_FMSimpleExpression* e = m_pArguments->GetAt(i); e->ToJavaScript(javascript); javascript << FX_WSTRC(L")"); if (i + 1 < m_pArguments->GetSize()) { @@ -586,8 +582,7 @@ void CXFA_FMCallExpression::ToJavaScript(CFX_WideTextBuf& javascript) { if (isExistsFunc) { javascript << FX_WSTRC(L"\n(\nfunction ()\n{\ntry\n{\n"); if (m_pArguments && m_pArguments->GetSize() > 0) { - CXFA_FMSimpleExpression* e = - reinterpret_cast<CXFA_FMSimpleExpression*>(m_pArguments->GetAt(0)); + CXFA_FMSimpleExpression* e = m_pArguments->GetAt(0); javascript << FX_WSTRC(L"return "); e->ToJavaScript(javascript); javascript << FX_WSTRC(L";\n}\n"); @@ -598,8 +593,7 @@ void CXFA_FMCallExpression::ToJavaScript(CFX_WideTextBuf& javascript) { L"catch(accessExceptions)\n{\nreturn 0;\n}\n}\n).call(this)\n"); } else if (m_pArguments) { for (int i = 0; i < m_pArguments->GetSize(); ++i) { - CXFA_FMSimpleExpression* e = - reinterpret_cast<CXFA_FMSimpleExpression*>(m_pArguments->GetAt(i)); + CXFA_FMSimpleExpression* e = m_pArguments->GetAt(i); e->ToJavaScript(javascript); if (i + 1 < m_pArguments->GetSize()) { javascript << FX_WSTRC(L", "); diff --git a/xfa/fxfa/fm2js/xfa_simpleexpression.h b/xfa/fxfa/fm2js/xfa_simpleexpression.h index 94f628b09b..2530128846 100644 --- a/xfa/fxfa/fm2js/xfa_simpleexpression.h +++ b/xfa/fxfa/fm2js/xfa_simpleexpression.h @@ -226,16 +226,17 @@ class CXFA_FMCallExpression : public CXFA_FMUnaryExpression { public: CXFA_FMCallExpression(uint32_t line, CXFA_FMSimpleExpression* pExp, - CFX_PtrArray* pArguments, + CFX_ArrayTemplate<CXFA_FMSimpleExpression*>* pArguments, FX_BOOL bIsSomMethod); ~CXFA_FMCallExpression() override; + bool IsBuildInFunc(CFX_WideTextBuf* funcName); uint32_t IsMethodWithObjParam(const CFX_WideStringC& methodName); void ToJavaScript(CFX_WideTextBuf& javascript) override; private: FX_BOOL m_bIsSomMethod; - CFX_PtrArray* m_pArguments; + CFX_ArrayTemplate<CXFA_FMSimpleExpression*>* m_pArguments; }; class CXFA_FMDotAccessorExpression : public CXFA_FMBinExpression { |