Home | History | Annotate | Download | only in fm2js
      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/fxfa/fm2js/xfa_program.h"
      8 
      9 #include <utility>
     10 #include <vector>
     11 
     12 #include "third_party/base/ptr_util.h"
     13 
     14 CXFA_FMProgram::CXFA_FMProgram(const CFX_WideStringC& wsFormcalc)
     15     : m_parse(wsFormcalc, &m_pErrorInfo) {}
     16 
     17 CXFA_FMProgram::~CXFA_FMProgram() {}
     18 
     19 int32_t CXFA_FMProgram::ParseProgram() {
     20   m_parse.NextToken();
     21   if (!m_pErrorInfo.message.IsEmpty())
     22     return -1;
     23 
     24   std::vector<std::unique_ptr<CXFA_FMExpression>> expressions =
     25       m_parse.ParseTopExpression();
     26   if (!m_pErrorInfo.message.IsEmpty())
     27     return -1;
     28 
     29   std::vector<CFX_WideStringC> arguments;
     30   m_globalFunction = pdfium::MakeUnique<CXFA_FMFunctionDefinition>(
     31       1, true, L"", std::move(arguments), std::move(expressions));
     32   return 0;
     33 }
     34 
     35 int32_t CXFA_FMProgram::TranslateProgram(CFX_WideTextBuf& wsJavaScript) {
     36   m_globalFunction->ToJavaScript(wsJavaScript);
     37   wsJavaScript.AppendChar(0);
     38   return 0;
     39 }
     40