1 // Copyright 2014 PDFium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
6 
7 #include "xfa_fm2js.h"
CXFA_FMProgram()8 CXFA_FMProgram::CXFA_FMProgram() : m_globalFunction(0) {}
~CXFA_FMProgram()9 CXFA_FMProgram::~CXFA_FMProgram() {
10   if (m_globalFunction != 0) {
11     delete m_globalFunction;
12     m_globalFunction = 0;
13   }
14 }
Init(const CFX_WideStringC & wsFormcalc)15 int32_t CXFA_FMProgram::Init(const CFX_WideStringC& wsFormcalc) {
16   return m_parse.Init(wsFormcalc, &m_pErrorInfo);
17 }
ParseProgram()18 int32_t CXFA_FMProgram::ParseProgram() {
19   CFX_PtrArray* expressions = 0;
20   m_parse.NextToken();
21   if (!m_pErrorInfo.message.IsEmpty()) {
22     return -1;
23   }
24   expressions = m_parse.ParseTopExpression();
25   if (!m_pErrorInfo.message.IsEmpty()) {
26     CXFA_FMExpression* e = 0;
27     for (int32_t u = 0; u < expressions->GetSize(); ++u) {
28       e = (CXFA_FMExpression*)expressions->GetAt(u);
29       if (e) {
30         delete e;
31       }
32     }
33     delete expressions;
34     return -1;
35   }
36   m_globalFunction =
37       new CXFA_FMFunctionDefinition(1, 1, FX_WSTRC(L""), 0, expressions);
38   return 0;
39 }
TranslateProgram(CFX_WideTextBuf & wsJavaScript)40 int32_t CXFA_FMProgram::TranslateProgram(CFX_WideTextBuf& wsJavaScript) {
41   m_globalFunction->ToJavaScript(wsJavaScript);
42   wsJavaScript.AppendChar(0);
43   return 0;
44 }
45