diff --git a/CMakeLists.txt b/CMakeLists.txt index 9d5f17ccb08..981b9b620fc 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -84,10 +84,6 @@ endif() option(WarpX_MPI_THREAD_MULTIPLE "MPI thread-multiple support, i.e. for async_io" ON) mark_as_advanced(WarpX_MPI_THREAD_MULTIPLE) -set(WarpX_PARSER_DEPTH 24 CACHE STRING - "Maximum parser depth for input file functions") -mark_as_advanced(WarpX_PARSER_DEPTH) - option(WarpX_amrex_internal "Download & build AMReX" ON) # change the default build type to RelWithDebInfo (or Release) instead of Debug @@ -192,7 +188,6 @@ add_subdirectory(Source/Filter) add_subdirectory(Source/Initialization) add_subdirectory(Source/Laser) add_subdirectory(Source/Parallelization) -add_subdirectory(Source/Parser) add_subdirectory(Source/Particles) add_subdirectory(Source/Python) add_subdirectory(Source/Utils) @@ -291,14 +286,9 @@ if(WarpX_PSATD) target_compile_definitions(WarpX PUBLIC WARPX_USE_PSATD) endif() -target_compile_definitions(WarpX PUBLIC - WARPX_PARSER_DEPTH=${WarpX_PARSER_DEPTH}) - # : M_PI -# : parser if(WIN32) target_compile_definitions(WarpX PRIVATE _USE_MATH_DEFINES) - target_compile_definitions(WarpX PRIVATE YY_NO_UNISTD_H) endif() diff --git a/Docs/source/install/cmake.rst b/Docs/source/install/cmake.rst index e864dc612e0..466cb29dcf3 100644 --- a/Docs/source/install/cmake.rst +++ b/Docs/source/install/cmake.rst @@ -86,7 +86,6 @@ CMake Option Default & Values Descr ``WarpX_MPI`` **ON**/OFF Multi-node support (message-passing) ``WarpX_MPI_THREAD_MULTIPLE`` **ON**/OFF MPI thread-multiple support, i.e. for ``async_io`` ``WarpX_OPENPMD`` ON/**OFF** openPMD I/O (HDF5, ADIOS) -``WarpX_PARSER_DEPTH`` **24** Maximum parser depth for input file functions ``WarpX_PRECISION`` SINGLE/**DOUBLE** Floating point precision (single/double) ``WarpX_PSATD`` ON/**OFF** Spectral solver ``WarpX_QED`` **ON**/OFF QED support (requires PICSAR) diff --git a/Docs/source/usage/parameters.rst b/Docs/source/usage/parameters.rst index 4816afcb11f..4829d52bf98 100644 --- a/Docs/source/usage/parameters.rst +++ b/Docs/source/usage/parameters.rst @@ -4,7 +4,7 @@ Input Parameters ================ .. note:: - The WarpXParser (see :ref:`running-cpp-parameters-parser`) is used for the right-hand-side of all input parameters that consist of one or more floats, so expressions like ``.density_max = "2.+1."`` and/or using user-defined constants are accepted. See below for more detail. + :cpp:`amrex::Parser` (see :ref:`running-cpp-parameters-parser`) is used for the right-hand-side of all input parameters that consist of one or more floats, so expressions like ``.density_max = "2.+1."`` and/or using user-defined constants are accepted. See below for more detail. .. _running-cpp-parameters-overall: @@ -353,7 +353,7 @@ Distribution across MPI ranks and parallelization Math parser and user-defined constants -------------------------------------- -WarpX provides a math parser that reads expressions in the input file. +WarpX uses AMReX's math parser that reads expressions in the input file. It can be used in all input parameters that consist of one or more floats. Note that when multiple floats are expected, the expressions are space delimited. @@ -402,9 +402,6 @@ user-defined constant (see below) and ``x`` and ``y`` are spatial coordinates. T ``(x>0)`` is ``1`` where ``x>0`` and ``0`` where ``x<=0``. It allows the user to define functions by intervals. Alternatively the expression above can be written as ``if(x>0, a0*x**2 * (1-y*1.e2), 0)``. -The parser reads mathematical functions into an `abstract syntax tree (AST) `_, which supports a maximum depth (see :ref:`build options `). -Additional terms in a function can create a level of depth in the AST, e.g. ``a+b+c+d`` is parsed in groups of ``[+ a [+ b [+ c [+ d]]]]`` (depth: 4). -A trick to reduce this depth for the parser, e.g. when reaching the limit, is to group explicitly, e.g. via ``(a+b)+(c+d)``, which is parsed in groups of ``[+ [+ a b] [+ c d]]`` (depth: 2). .. _running-cpp-parameters-particle: diff --git a/Source/Diagnostics/FlushFormats/FlushFormatPlotfile.cpp b/Source/Diagnostics/FlushFormats/FlushFormatPlotfile.cpp index e63ddc20075..542a86bcd16 100644 --- a/Source/Diagnostics/FlushFormats/FlushFormatPlotfile.cpp +++ b/Source/Diagnostics/FlushFormats/FlushFormatPlotfile.cpp @@ -1,7 +1,6 @@ #include "FlushFormatPlotfile.H" #include "Diagnostics/ParticleDiag/ParticleDiag.H" -#include "Parser/WarpXParserWrapper.H" #include "Particles/Filter/FilterFunctors.H" #include "Particles/WarpXParticleContainer.H" #include "Utils/Interpolate.H" @@ -353,7 +352,7 @@ FlushFormatPlotfile::WriteParticles(const std::string& dir, UniformFilter const uniform_filter(particle_diags[i].m_do_uniform_filter, particle_diags[i].m_uniform_stride); ParserFilter parser_filter(particle_diags[i].m_do_parser_filter, - getParser(particle_diags[i].m_particle_filter_parser), + particle_diags[i].m_particle_filter_parser->compile<7>(), pc->getMass()); parser_filter.m_units = InputUnits::SI; GeometryFilter const geometry_filter(particle_diags[i].m_do_geom_filter, diff --git a/Source/Diagnostics/ParticleDiag/ParticleDiag.H b/Source/Diagnostics/ParticleDiag/ParticleDiag.H index 0ac5ab69e7d..16ad6ad62c0 100644 --- a/Source/Diagnostics/ParticleDiag/ParticleDiag.H +++ b/Source/Diagnostics/ParticleDiag/ParticleDiag.H @@ -4,8 +4,8 @@ #include "ParticleDiag_fwd.H" #include "Particles/WarpXParticleContainer_fwd.H" -#include "Parser/WarpXParserWrapper_fwd.H" +#include #include #include #include @@ -27,7 +27,7 @@ public: bool m_do_geom_filter = false; amrex::Real m_random_fraction = 1.0; int m_uniform_stride = 1; - std::unique_ptr> m_particle_filter_parser; + std::unique_ptr m_particle_filter_parser; amrex::RealBox m_diag_domain; private: diff --git a/Source/Diagnostics/ParticleDiag/ParticleDiag.cpp b/Source/Diagnostics/ParticleDiag/ParticleDiag.cpp index 258ab7903a9..29461ae1fbc 100644 --- a/Source/Diagnostics/ParticleDiag/ParticleDiag.cpp +++ b/Source/Diagnostics/ParticleDiag/ParticleDiag.cpp @@ -1,7 +1,6 @@ #include "ParticleDiag.H" #include "Diagnostics/ParticleDiag/ParticleDiag.H" -#include "Parser/WarpXParserWrapper.H" #include "Particles/WarpXParticleContainer.H" #include "Utils/WarpXUtil.H" #include "WarpX.H" @@ -82,7 +81,7 @@ ParticleDiag::ParticleDiag(std::string diag_name, std::string name, WarpXParticl std::string function_string = ""; Store_parserString(pp,"plot_filter_function(t,x,y,z,ux,uy,uz)", function_string); - m_particle_filter_parser = std::make_unique>( + m_particle_filter_parser = std::make_unique( makeParser(function_string,{"t","x","y","z","ux","uy","uz"})); } } diff --git a/Source/Diagnostics/ReducedDiags/FieldReduction.H b/Source/Diagnostics/ReducedDiags/FieldReduction.H index e6dc8d8c55a..a4a0db78658 100644 --- a/Source/Diagnostics/ReducedDiags/FieldReduction.H +++ b/Source/Diagnostics/ReducedDiags/FieldReduction.H @@ -8,7 +8,6 @@ #ifndef WARPX_DIAGNOSTICS_REDUCEDDIAGS_FIELDREDUCTION_H_ #define WARPX_DIAGNOSTICS_REDUCEDDIAGS_FIELDREDUCTION_H_ -#include "Parser/WarpXParserWrapper.H" #include "ReducedDiags.H" #include "Utils/CoarsenIO.H" #include "WarpX.H" @@ -25,6 +24,7 @@ #include #include #include +#include #include #include #include @@ -63,7 +63,7 @@ private: /// Parser to read expression to be reduced from the input file. /// 9 elements are x, y, z, Ex, Ey, Ez, Bx, By, Bz static constexpr int m_nvars = 9; - std::unique_ptr> m_parser; + std::unique_ptr m_parser; // Type of reduction (e.g. Maximum, Minimum or Sum) int m_reduction_type; @@ -127,7 +127,7 @@ public: } // get parser - HostDeviceParser reduction_function_parser = getParser(m_parser); + auto reduction_function_parser = m_parser->compile(); // MFIter loop to interpolate fields to cell center and perform reduction #ifdef AMREX_USE_OMP diff --git a/Source/Diagnostics/ReducedDiags/FieldReduction.cpp b/Source/Diagnostics/ReducedDiags/FieldReduction.cpp index be0c15033c3..0ebc89a7d06 100644 --- a/Source/Diagnostics/ReducedDiags/FieldReduction.cpp +++ b/Source/Diagnostics/ReducedDiags/FieldReduction.cpp @@ -50,7 +50,7 @@ FieldReduction::FieldReduction (std::string rd_name) std::string parser_string = ""; Store_parserString(pp_rd_name,"reduced_function(x,y,z,Ex,Ey,Ez,Bx,By,Bz)", parser_string); - m_parser = std::make_unique>( + m_parser = std::make_unique( makeParser(parser_string,{"x","y","z","Ex","Ey","Ez","Bx","By","Bz"})); // Replace all newlines and possible following whitespaces with a single whitespace. This diff --git a/Source/Diagnostics/ReducedDiags/ParticleHistogram.H b/Source/Diagnostics/ReducedDiags/ParticleHistogram.H index e44a21b6226..07a2b9599fb 100644 --- a/Source/Diagnostics/ReducedDiags/ParticleHistogram.H +++ b/Source/Diagnostics/ReducedDiags/ParticleHistogram.H @@ -8,9 +8,9 @@ #ifndef WARPX_DIAGNOSTICS_REDUCEDDIAGS_PARTICLEHISTOGRAM_H_ #define WARPX_DIAGNOSTICS_REDUCEDDIAGS_PARTICLEHISTOGRAM_H_ -#include "Parser/WarpXParserWrapper.H" #include "ReducedDiags.H" +#include #include #include @@ -49,10 +49,10 @@ public: /// Parser to read expression for particle quantity from the input file. /// 7 elements are t, x, y, z, ux, uy, uz static constexpr int m_nvars = 7; - std::unique_ptr> m_parser; + std::unique_ptr m_parser; /// Optional parser to filter particles before doing the histogram - std::unique_ptr> m_parser_filter; + std::unique_ptr m_parser_filter; /// Whether the filter is activated bool m_do_parser_filter = false; diff --git a/Source/Diagnostics/ReducedDiags/ParticleHistogram.cpp b/Source/Diagnostics/ReducedDiags/ParticleHistogram.cpp index b5737a23e95..c690539c8fb 100644 --- a/Source/Diagnostics/ReducedDiags/ParticleHistogram.cpp +++ b/Source/Diagnostics/ReducedDiags/ParticleHistogram.cpp @@ -69,7 +69,7 @@ ParticleHistogram::ParticleHistogram (std::string rd_name) std::string function_string = ""; Store_parserString(pp_rd_name,"histogram_function(t,x,y,z,ux,uy,uz)", function_string); - m_parser = std::make_unique>( + m_parser = std::make_unique( makeParser(function_string,{"t","x","y","z","ux","uy","uz"})); // read normalization type @@ -111,7 +111,7 @@ ParticleHistogram::ParticleHistogram (std::string rd_name) if (m_do_parser_filter) { std::string filter_string = ""; Store_parserString(pp_rd_name,"filter_function(t,x,y,z,ux,uy,uz)", filter_string); - m_parser_filter = std::make_unique>( + m_parser_filter = std::make_unique( makeParser(filter_string,{"t","x","y","z","ux","uy","uz"})); } @@ -165,10 +165,10 @@ void ParticleHistogram::ComputeDiags (int step) auto & myspc = mypc.GetParticleContainer(m_selected_species_id); // get parser - HostDeviceParser fun_partparser = getParser(m_parser); + auto fun_partparser = m_parser->compile(); // get filter parser - HostDeviceParser fun_filterparser = getParser(m_parser_filter); + auto fun_filterparser = m_parser_filter->compile(); // declare local variables auto const num_bins = m_bin_num; diff --git a/Source/Diagnostics/WarpXOpenPMD.cpp b/Source/Diagnostics/WarpXOpenPMD.cpp index 6df03d6e082..f7239e34554 100644 --- a/Source/Diagnostics/WarpXOpenPMD.cpp +++ b/Source/Diagnostics/WarpXOpenPMD.cpp @@ -8,7 +8,6 @@ #include "Diagnostics/ParticleDiag/ParticleDiag.H" #include "FieldIO.H" -#include "Parser/WarpXParserWrapper.H" #include "Particles/Filter/FilterFunctors.H" #include "Utils/RelativeCellPosition.H" #include "Utils/WarpXAlgorithmSelection.H" @@ -459,7 +458,7 @@ WarpXOpenPMDPlot::WriteOpenPMDParticles (const amrex::Vector& part UniformFilter const uniform_filter(particle_diags[i].m_do_uniform_filter, particle_diags[i].m_uniform_stride); ParserFilter parser_filter(particle_diags[i].m_do_parser_filter, - getParser(particle_diags[i].m_particle_filter_parser), + particle_diags[i].m_particle_filter_parser->compile<7>(), pc->getMass()); parser_filter.m_units = InputUnits::SI; GeometryFilter const geometry_filter(particle_diags[i].m_do_geom_filter, diff --git a/Source/EmbeddedBoundary/WarpXInitEB.cpp b/Source/EmbeddedBoundary/WarpXInitEB.cpp index cd575491a29..5af7bb9ff71 100644 --- a/Source/EmbeddedBoundary/WarpXInitEB.cpp +++ b/Source/EmbeddedBoundary/WarpXInitEB.cpp @@ -1,40 +1,40 @@ -#include "Parser/WarpXParser.H" -#include "Parser/WarpXParserWrapper.H" -#include "Utils/WarpXUtil.H" #include "WarpX.H" -#include -#include -#include -#include -#include -#include -#include -#include #ifdef AMREX_USE_EB -# include -#endif -#include -#include -#include -#include -#include -#include -#include -#include -#include -#ifdef AMREX_USE_EB -# include -#endif -#include -#include -#include -#include -#include -#include -#include -#include +# include "Utils/WarpXUtil.H" + +# include +# include +# include +# include +# include +# include +# include +# include +# include +# include +# include +# include +# include +# include +# include +# include +# include +# include +# include +# include +# include +# include +# include + +# include +# include +# include +# include +# include + +#endif #ifdef AMREX_USE_EB namespace { @@ -42,8 +42,8 @@ namespace { : public amrex::GPUable { public: - ParserIF (const ParserWrapper<3>& a_parser) - : m_parser(a_parser.getParser()) + ParserIF (const ParserExecutor<3>& a_parser) + : m_parser(a_parser) {} ParserIF (const ParserIF& rhs) noexcept = default; @@ -66,7 +66,7 @@ namespace { } private: - HostDeviceParser<3> m_parser; + ParserExecutor<3> m_parser; }; } #endif @@ -81,10 +81,9 @@ WarpX::InitEB () std::string impf; pp_warpx.query("eb_implicit_function", impf); if (! impf.empty()) { - WarpXParser wp = makeParser(impf, {"x", "y", "z"}); - m_eb_if_parser = std::make_unique >(wp); - ParserIF pif(*m_eb_if_parser); - auto gshop = amrex::EB2::makeShop(pif); + auto eb_if_parser = makeParser(impf, {"x", "y", "z"}); + ParserIF pif(m_eb_if_parser->compile<3>()); + auto gshop = amrex::EB2::makeShop(pif, eb_if_parser); amrex::EB2::Build(gshop, Geom(maxLevel()), maxLevel(), maxLevel()); } else { amrex::ParmParse pp_eb2("eb2"); diff --git a/Source/FieldSolver/ElectrostaticSolver.cpp b/Source/FieldSolver/ElectrostaticSolver.cpp index 991c1fcae53..bd6831a9fb5 100644 --- a/Source/FieldSolver/ElectrostaticSolver.cpp +++ b/Source/FieldSolver/ElectrostaticSolver.cpp @@ -7,7 +7,6 @@ #include "WarpX.H" #include "Parallelization/GuardCellManager.H" -#include "Parser/WarpXParser.H" #include "Particles/MultiParticleContainer.H" #include "Particles/WarpXParticleContainer.H" #include "Utils/WarpXAlgorithmSelection.H" @@ -39,6 +38,7 @@ #endif #include #include +#include #include #include #include @@ -548,9 +548,11 @@ WarpX::getPhiBC( const int idim, amrex::Real &pot_lo, amrex::Real &pot_hi ) cons #endif auto parser_lo = makeParser(potential_lo_str, {"t"}); - pot_lo = parser_lo.eval(gett_new(0)); + auto parser_lo_exe = parser_lo.compileHost<1>(); + pot_lo = parser_lo_exe(gett_new(0)); auto parser_hi = makeParser(potential_hi_str, {"t"}); - pot_hi = parser_hi.eval(gett_new(0)); + auto parser_hi_exe = parser_hi.compileHost<1>(); + pot_hi = parser_hi_exe(gett_new(0)); } /* \bried Compute the electric field that corresponds to `phi`, and diff --git a/Source/FieldSolver/FiniteDifferenceSolver/MacroscopicProperties/MacroscopicProperties.H b/Source/FieldSolver/FiniteDifferenceSolver/MacroscopicProperties/MacroscopicProperties.H index 3597212c43c..e638be1c5ae 100644 --- a/Source/FieldSolver/FiniteDifferenceSolver/MacroscopicProperties/MacroscopicProperties.H +++ b/Source/FieldSolver/FiniteDifferenceSolver/MacroscopicProperties/MacroscopicProperties.H @@ -3,13 +3,13 @@ #include "MacroscopicProperties_fwd.H" -#include "Parser/WarpXParserWrapper.H" #include "Utils/WarpXConst.H" #include #include #include #include +#include #include #include @@ -40,7 +40,8 @@ public: * with user-defined functions(x,y,z). */ void InitializeMacroMultiFabUsingParser (amrex::MultiFab *macro_mf, - HostDeviceParser<3> const& macro_parser, int lev); + amrex::ParserExecutor<3> const& macro_parser, + int lev); /** Gpu Vector with index type of the conductivity multifab */ amrex::GpuArray sigma_IndexType; /** Gpu Vector with index type of the permittivity multifab */ @@ -81,9 +82,9 @@ private: std::string m_str_epsilon_function; std::string m_str_mu_function; /** Parser Wrappers */ - std::unique_ptr > m_sigma_parser; - std::unique_ptr > m_epsilon_parser; - std::unique_ptr > m_mu_parser; + std::unique_ptr m_sigma_parser; + std::unique_ptr m_epsilon_parser; + std::unique_ptr m_mu_parser; }; /** diff --git a/Source/FieldSolver/FiniteDifferenceSolver/MacroscopicProperties/MacroscopicProperties.cpp b/Source/FieldSolver/FiniteDifferenceSolver/MacroscopicProperties/MacroscopicProperties.cpp index 579296e14cd..a1e4d325269 100644 --- a/Source/FieldSolver/FiniteDifferenceSolver/MacroscopicProperties/MacroscopicProperties.cpp +++ b/Source/FieldSolver/FiniteDifferenceSolver/MacroscopicProperties/MacroscopicProperties.cpp @@ -52,7 +52,7 @@ MacroscopicProperties::ReadParameters () // initialization of sigma (conductivity) with parser if (m_sigma_s == "parse_sigma_function") { Store_parserString(pp_macroscopic, "sigma_function(x,y,z)", m_str_sigma_function); - m_sigma_parser = std::make_unique>( + m_sigma_parser = std::make_unique( makeParser(m_str_sigma_function,{"x","y","z"})); } @@ -72,7 +72,7 @@ MacroscopicProperties::ReadParameters () // initialization of epsilon (permittivity) with parser if (m_epsilon_s == "parse_epsilon_function") { Store_parserString(pp_macroscopic, "epsilon_function(x,y,z)", m_str_epsilon_function); - m_epsilon_parser = std::make_unique>( + m_epsilon_parser = std::make_unique( makeParser(m_str_epsilon_function,{"x","y","z"})); } @@ -93,7 +93,7 @@ MacroscopicProperties::ReadParameters () // initialization of mu (permeability) with parser if (m_mu_s == "parse_mu_function") { Store_parserString(pp_macroscopic, "mu_function(x,y,z)", m_str_mu_function); - m_mu_parser = std::make_unique>( + m_mu_parser = std::make_unique( makeParser(m_str_mu_function,{"x","y","z"})); } @@ -124,7 +124,7 @@ MacroscopicProperties::InitData () } else if (m_sigma_s == "parse_sigma_function") { - InitializeMacroMultiFabUsingParser(m_sigma_mf.get(), getParser(m_sigma_parser), lev); + InitializeMacroMultiFabUsingParser(m_sigma_mf.get(), m_sigma_parser->compile<3>(), lev); } // Initialize epsilon if (m_epsilon_s == "constant") { @@ -133,7 +133,7 @@ MacroscopicProperties::InitData () } else if (m_epsilon_s == "parse_epsilon_function") { - InitializeMacroMultiFabUsingParser(m_eps_mf.get(), getParser(m_epsilon_parser), lev); + InitializeMacroMultiFabUsingParser(m_eps_mf.get(), m_epsilon_parser->compile<3>(), lev); } // Initialize mu @@ -143,7 +143,7 @@ MacroscopicProperties::InitData () } else if (m_mu_s == "parse_mu_function") { - InitializeMacroMultiFabUsingParser(m_mu_mf.get(), getParser(m_mu_parser), lev); + InitializeMacroMultiFabUsingParser(m_mu_mf.get(), m_mu_parser->compile<3>(), lev); } @@ -179,7 +179,7 @@ MacroscopicProperties::InitData () void MacroscopicProperties::InitializeMacroMultiFabUsingParser ( - MultiFab *macro_mf, HostDeviceParser<3> const& macro_parser, + MultiFab *macro_mf, ParserExecutor<3> const& macro_parser, int lev) { auto& warpx = WarpX::GetInstance(); diff --git a/Source/Initialization/InjectorDensity.H b/Source/Initialization/InjectorDensity.H index 5b57fd23a95..e124301384c 100644 --- a/Source/Initialization/InjectorDensity.H +++ b/Source/Initialization/InjectorDensity.H @@ -10,14 +10,13 @@ #define INJECTOR_DENSITY_H_ #include "CustomDensityProb.H" -#include "Parser/GpuParser.H" -#include "Parser/WarpXParser.H" #include "Utils/WarpXConst.H" #include #include #include #include +#include #include #include @@ -42,7 +41,7 @@ private: // struct whose getDensity returns local density computed from parser. struct InjectorDensityParser { - InjectorDensityParser (WarpXParser const& a_parser) noexcept + InjectorDensityParser (amrex::ParserExecutor<3> const& a_parser) noexcept : m_parser(a_parser) {} AMREX_GPU_HOST_DEVICE @@ -52,8 +51,7 @@ struct InjectorDensityParser return m_parser(x,y,z); } - // InjectorDensityParser constructs this GpuParser from WarpXParser. - GpuParser<3> m_parser; + amrex::ParserExecutor<3> m_parser; }; // struct whose getDensity returns local density computed from predefined profile. @@ -136,7 +134,7 @@ struct InjectorDensity { } // This constructor stores a InjectorDensityParser in union object. - InjectorDensity (InjectorDensityParser* t, WarpXParser const& a_parser) + InjectorDensity (InjectorDensityParser* t, amrex::ParserExecutor<3> const& a_parser) : type(Type::parser), object(t,a_parser) { } @@ -203,7 +201,7 @@ private: union Object { Object (InjectorDensityConstant*, amrex::Real a_rho) noexcept : constant(a_rho) {} - Object (InjectorDensityParser*, WarpXParser const& a_parser) noexcept + Object (InjectorDensityParser*, amrex::ParserExecutor<3> const& a_parser) noexcept : parser(a_parser) {} Object (InjectorDensityCustom*, std::string const& a_species_name) noexcept : custom(a_species_name) {} diff --git a/Source/Initialization/InjectorDensity.cpp b/Source/Initialization/InjectorDensity.cpp index 572b37d9eb6..d0e7d43b559 100644 --- a/Source/Initialization/InjectorDensity.cpp +++ b/Source/Initialization/InjectorDensity.cpp @@ -25,7 +25,6 @@ void InjectorDensity::clear () { case Type::parser: { - object.parser.m_parser.clear(); break; } case Type::custom: diff --git a/Source/Initialization/InjectorMomentum.H b/Source/Initialization/InjectorMomentum.H index fe7d8aaea12..473d51a3c4e 100644 --- a/Source/Initialization/InjectorMomentum.H +++ b/Source/Initialization/InjectorMomentum.H @@ -9,8 +9,6 @@ #define INJECTOR_MOMENTUM_H_ #include "CustomMomentumProb.H" -#include "Parser/GpuParser.H" -#include "Parser/WarpXParser.H" #include "Utils/WarpXConst.H" #include @@ -18,6 +16,7 @@ #include #include #include +#include #include #include @@ -326,9 +325,9 @@ private: // struct whose getMomentumm returns local momentum computed from parser. struct InjectorMomentumParser { - InjectorMomentumParser (WarpXParser const& a_ux_parser, - WarpXParser const& a_uy_parser, - WarpXParser const& a_uz_parser) noexcept + InjectorMomentumParser (amrex::ParserExecutor<3> const& a_ux_parser, + amrex::ParserExecutor<3> const& a_uy_parser, + amrex::ParserExecutor<3> const& a_uz_parser) noexcept : m_ux_parser(a_ux_parser), m_uy_parser(a_uy_parser), m_uz_parser(a_uz_parser) {} @@ -347,7 +346,7 @@ struct InjectorMomentumParser return amrex::XDim3{m_ux_parser(x,y,z),m_uy_parser(x,y,z),m_uz_parser(x,y,z)}; } - GpuParser<3> m_ux_parser, m_uy_parser, m_uz_parser; + amrex::ParserExecutor<3> m_ux_parser, m_uy_parser, m_uz_parser; }; // Base struct for momentum injector. @@ -371,9 +370,9 @@ struct InjectorMomentum // This constructor stores a InjectorMomentumParser in union object. InjectorMomentum (InjectorMomentumParser* t, - WarpXParser const& a_ux_parser, - WarpXParser const& a_uy_parser, - WarpXParser const& a_uz_parser) + amrex::ParserExecutor<3> const& a_ux_parser, + amrex::ParserExecutor<3> const& a_uy_parser, + amrex::ParserExecutor<3> const& a_uz_parser) : type(Type::parser), object(t, a_ux_parser, a_uy_parser, a_uz_parser) { } @@ -563,9 +562,9 @@ private: amrex::Real u_over_r) noexcept : radial_expansion(u_over_r) {} Object (InjectorMomentumParser*, - WarpXParser const& a_ux_parser, - WarpXParser const& a_uy_parser, - WarpXParser const& a_uz_parser) noexcept + amrex::ParserExecutor<3> const& a_ux_parser, + amrex::ParserExecutor<3> const& a_uy_parser, + amrex::ParserExecutor<3> const& a_uz_parser) noexcept : parser(a_ux_parser, a_uy_parser, a_uz_parser) {} InjectorMomentumConstant constant; InjectorMomentumCustom custom; diff --git a/Source/Initialization/InjectorMomentum.cpp b/Source/Initialization/InjectorMomentum.cpp index 0bdb80857c5..3c52df1bafb 100644 --- a/Source/Initialization/InjectorMomentum.cpp +++ b/Source/Initialization/InjectorMomentum.cpp @@ -14,12 +14,6 @@ void InjectorMomentum::clear () switch (type) { case Type::parser: - { - object.parser.m_ux_parser.clear(); - object.parser.m_uy_parser.clear(); - object.parser.m_uz_parser.clear(); - break; - } case Type::gaussian: case Type::gaussianflux: case Type::boltzmann: diff --git a/Source/Initialization/PlasmaInjector.H b/Source/Initialization/PlasmaInjector.H index 86964a33acf..55be9ff9f33 100644 --- a/Source/Initialization/PlasmaInjector.H +++ b/Source/Initialization/PlasmaInjector.H @@ -141,9 +141,13 @@ protected: std::unique_ptr h_inj_rho; InjectorDensity* d_inj_rho = nullptr; + std::unique_ptr density_parser; std::unique_ptr h_inj_mom; InjectorMomentum* d_inj_mom = nullptr; + std::unique_ptr ux_parser; + std::unique_ptr uy_parser; + std::unique_ptr uz_parser; void parseDensity (amrex::ParmParse& pp); void parseMomentum (amrex::ParmParse& pp); diff --git a/Source/Initialization/PlasmaInjector.cpp b/Source/Initialization/PlasmaInjector.cpp index 3fd8a42c7b1..d85cbc2df2d 100644 --- a/Source/Initialization/PlasmaInjector.cpp +++ b/Source/Initialization/PlasmaInjector.cpp @@ -24,6 +24,7 @@ #include #include #include +#include #include #include @@ -459,8 +460,9 @@ void PlasmaInjector::parseDensity (ParmParse& pp) } else if (rho_prof_s == "parse_density_function") { Store_parserString(pp, "density_function(x,y,z)", str_density_function); // Construct InjectorDensity with InjectorDensityParser. + density_parser = std::make_unique(makeParser(str_density_function,{"x","y","z"})); h_inj_rho.reset(new InjectorDensity((InjectorDensityParser*)nullptr, - makeParser(str_density_function,{"x","y","z"}))); + density_parser->compile<3>())); } else { //No need for profile definition if external file is used std::string s_inj_style; @@ -606,10 +608,13 @@ void PlasmaInjector::parseMomentum (ParmParse& pp) Store_parserString(pp, "momentum_function_uz(x,y,z)", str_momentum_function_uz); // Construct InjectorMomentum with InjectorMomentumParser. + ux_parser = std::make_unique(makeParser(str_momentum_function_ux,{"x","y","z"})); + uy_parser = std::make_unique(makeParser(str_momentum_function_uy,{"x","y","z"})); + uz_parser = std::make_unique(makeParser(str_momentum_function_uz,{"x","y","z"})); h_inj_mom.reset(new InjectorMomentum((InjectorMomentumParser*)nullptr, - makeParser(str_momentum_function_ux,{"x","y","z"}), - makeParser(str_momentum_function_uy,{"x","y","z"}), - makeParser(str_momentum_function_uz,{"x","y","z"}))); + ux_parser->compile<3>(), + uy_parser->compile<3>(), + uz_parser->compile<3>())); } else { //No need for momentum definition if external file is used std::string s_inj_style; diff --git a/Source/Initialization/WarpXInitData.cpp b/Source/Initialization/WarpXInitData.cpp index 0c4a6426d81..0176e4aaaa6 100644 --- a/Source/Initialization/WarpXInitData.cpp +++ b/Source/Initialization/WarpXInitData.cpp @@ -17,8 +17,6 @@ #include "FieldSolver/FiniteDifferenceSolver/MacroscopicProperties/MacroscopicProperties.H" #include "Filter/BilinearFilter.H" #include "Filter/NCIGodfreyFilter.H" -#include "Parser/GpuParser.H" -#include "Parser/WarpXParserWrapper.H" #include "Particles/MultiParticleContainer.H" #include "Utils/WarpXAlgorithmSelection.H" #include "Utils/WarpXConst.H" @@ -48,6 +46,7 @@ #include #include #include +#include #include #include #include @@ -521,36 +520,36 @@ WarpX::InitLevelData (int lev, Real /*time*/) str_By_ext_grid_function); Store_parserString(pp_warpx, "Bz_external_grid_function(x,y,z)", str_Bz_ext_grid_function); - Bxfield_parser = std::make_unique>( + Bxfield_parser = std::make_unique( makeParser(str_Bx_ext_grid_function,{"x","y","z"})); - Byfield_parser = std::make_unique>( + Byfield_parser = std::make_unique( makeParser(str_By_ext_grid_function,{"x","y","z"})); - Bzfield_parser = std::make_unique>( + Bzfield_parser = std::make_unique( makeParser(str_Bz_ext_grid_function,{"x","y","z"})); // Initialize Bfield_fp with external function InitializeExternalFieldsOnGridUsingParser(Bfield_fp[lev][0].get(), Bfield_fp[lev][1].get(), Bfield_fp[lev][2].get(), - getParser(Bxfield_parser), - getParser(Byfield_parser), - getParser(Bzfield_parser), + Bxfield_parser->compile<3>(), + Byfield_parser->compile<3>(), + Bzfield_parser->compile<3>(), lev); if (lev > 0) { InitializeExternalFieldsOnGridUsingParser(Bfield_aux[lev][0].get(), Bfield_aux[lev][1].get(), Bfield_aux[lev][2].get(), - getParser(Bxfield_parser), - getParser(Byfield_parser), - getParser(Bzfield_parser), + Bxfield_parser->compile<3>(), + Byfield_parser->compile<3>(), + Bzfield_parser->compile<3>(), lev); InitializeExternalFieldsOnGridUsingParser(Bfield_cp[lev][0].get(), Bfield_cp[lev][1].get(), Bfield_cp[lev][2].get(), - getParser(Bxfield_parser), - getParser(Byfield_parser), - getParser(Bzfield_parser), + Bxfield_parser->compile<3>(), + Byfield_parser->compile<3>(), + Bzfield_parser->compile<3>(), lev); } } @@ -570,36 +569,36 @@ WarpX::InitLevelData (int lev, Real /*time*/) Store_parserString(pp_warpx, "Ez_external_grid_function(x,y,z)", str_Ez_ext_grid_function); - Exfield_parser = std::make_unique>( + Exfield_parser = std::make_unique( makeParser(str_Ex_ext_grid_function,{"x","y","z"})); - Eyfield_parser = std::make_unique>( + Eyfield_parser = std::make_unique( makeParser(str_Ey_ext_grid_function,{"x","y","z"})); - Ezfield_parser = std::make_unique>( + Ezfield_parser = std::make_unique( makeParser(str_Ez_ext_grid_function,{"x","y","z"})); // Initialize Efield_fp with external function InitializeExternalFieldsOnGridUsingParser(Efield_fp[lev][0].get(), Efield_fp[lev][1].get(), Efield_fp[lev][2].get(), - getParser(Exfield_parser), - getParser(Eyfield_parser), - getParser(Ezfield_parser), + Exfield_parser->compile<3>(), + Eyfield_parser->compile<3>(), + Ezfield_parser->compile<3>(), lev); if (lev > 0) { InitializeExternalFieldsOnGridUsingParser(Efield_aux[lev][0].get(), Efield_aux[lev][1].get(), Efield_aux[lev][2].get(), - getParser(Exfield_parser), - getParser(Eyfield_parser), - getParser(Ezfield_parser), + Exfield_parser->compile<3>(), + Eyfield_parser->compile<3>(), + Ezfield_parser->compile<3>(), lev); InitializeExternalFieldsOnGridUsingParser(Efield_cp[lev][0].get(), Efield_cp[lev][1].get(), Efield_cp[lev][2].get(), - getParser(Exfield_parser), - getParser(Eyfield_parser), - getParser(Ezfield_parser), + Exfield_parser->compile<3>(), + Eyfield_parser->compile<3>(), + Ezfield_parser->compile<3>(), lev); } } @@ -639,8 +638,8 @@ WarpX::InitLevelData (int lev, Real /*time*/) void WarpX::InitializeExternalFieldsOnGridUsingParser ( MultiFab *mfx, MultiFab *mfy, MultiFab *mfz, - HostDeviceParser<3> const& xfield_parser, HostDeviceParser<3> const& yfield_parser, - HostDeviceParser<3> const& zfield_parser, const int lev) + ParserExecutor<3> const& xfield_parser, ParserExecutor<3> const& yfield_parser, + ParserExecutor<3> const& zfield_parser, const int lev) { const auto dx_lev = geom[lev].CellSizeArray(); diff --git a/Source/Laser/LaserProfiles.H b/Source/Laser/LaserProfiles.H index 22b2187cd3b..9677bb9c2aa 100644 --- a/Source/Laser/LaserProfiles.H +++ b/Source/Laser/LaserProfiles.H @@ -7,10 +7,9 @@ #ifndef WARPX_LaserProfiles_H_ #define WARPX_LaserProfiles_H_ -#include "Parser/WarpXParserWrapper.H" - #include #include +#include #include #include @@ -208,8 +207,7 @@ private: std::string field_function; } m_params; - WarpXParser m_parser; - std::unique_ptr > m_gpu_parser; + amrex::Parser m_parser; }; /** diff --git a/Source/Laser/LaserProfilesImpl/LaserProfileFieldFunction.cpp b/Source/Laser/LaserProfilesImpl/LaserProfileFieldFunction.cpp index 8dd1a6218eb..63d7beea224 100644 --- a/Source/Laser/LaserProfilesImpl/LaserProfileFieldFunction.cpp +++ b/Source/Laser/LaserProfilesImpl/LaserProfileFieldFunction.cpp @@ -6,8 +6,6 @@ */ #include "Laser/LaserProfiles.H" -#include "Parser/WarpXParser.H" -#include "Parser/WarpXParserWrapper.H" #include "Utils/WarpX_Complex.H" #include @@ -51,8 +49,6 @@ WarpXLaserProfiles::FieldFunctionLaserProfile::init ( for (auto const& s : symbols) { // make sure there no unknown symbols amrex::Abort("Laser Profile: Unknown symbol "+s); } - - m_gpu_parser = std::make_unique< ParserWrapper<3> >(m_parser); } void @@ -60,7 +56,7 @@ WarpXLaserProfiles::FieldFunctionLaserProfile::fill_amplitude ( const int np, Real const * AMREX_RESTRICT const Xp, Real const * AMREX_RESTRICT const Yp, Real t, Real * AMREX_RESTRICT const amplitude) const { - auto parser = getParser(m_gpu_parser); + auto parser = m_parser.compile<3>(); amrex::ParallelFor(np, [=] AMREX_GPU_DEVICE (int i) noexcept { amplitude[i] = parser(Xp[i], Yp[i], t); diff --git a/Source/Make.WarpX b/Source/Make.WarpX index 4f36b2d254f..2da08da3fc1 100644 --- a/Source/Make.WarpX +++ b/Source/Make.WarpX @@ -76,7 +76,6 @@ include $(WARPX_HOME)/Source/Filter/Make.package include $(WARPX_HOME)/Source/Initialization/Make.package include $(WARPX_HOME)/Source/Laser/Make.package include $(WARPX_HOME)/Source/Parallelization/Make.package -include $(WARPX_HOME)/Source/Parser/Make.package include $(WARPX_HOME)/Source/Particles/Make.package include $(WARPX_HOME)/Source/Python/Make.package include $(WARPX_HOME)/Source/Utils/Make.package @@ -138,12 +137,6 @@ DEFINES += -DPICSAR_GIT_VERSION=\"$(PICSAR_GIT_VERSION)\" DEFINES += -DPICSAR_NO_ASSUMED_ALIGNMENT DEFINES += -DWARPX -ifdef PARSER_DEPTH - DEFINES += -DWARPX_PARSER_DEPTH=$(PARSER_DEPTH) -else - DEFINES += -DWARPX_PARSER_DEPTH=24 -endif - ifeq ($(USE_OPENBC_POISSON),TRUE) include $(OPENBC_HOME)/Make.package DEFINES += -DFFT_FFTW -DMPIPARALLEL -DUSE_OPENBC_POISSON diff --git a/Source/Parser/CMakeLists.txt b/Source/Parser/CMakeLists.txt deleted file mode 100644 index 2c9a93942d3..00000000000 --- a/Source/Parser/CMakeLists.txt +++ /dev/null @@ -1,8 +0,0 @@ -target_sources(WarpX - PRIVATE - WarpXParser.cpp - wp_parser_c.cpp - wp_parser.lex.cpp - wp_parser.tab.cpp - wp_parser_y.cpp -) diff --git a/Source/Parser/GNUmakefile b/Source/Parser/GNUmakefile deleted file mode 100644 index e3d3d7276d7..00000000000 --- a/Source/Parser/GNUmakefile +++ /dev/null @@ -1,5 +0,0 @@ - -default: - bison -d --no-lines wp_parser.y - flex --noline -o wp_parser.lex.cpp --header-file=wp_parser.lex.h wp_parser.l - mv -f wp_parser.tab.c wp_parser.tab.cpp diff --git a/Source/Parser/GpuParser.H b/Source/Parser/GpuParser.H deleted file mode 100644 index 3d7a631d73a..00000000000 --- a/Source/Parser/GpuParser.H +++ /dev/null @@ -1,179 +0,0 @@ -/* Copyright 2019-2020 Maxence Thevenet, Revathi Jambunathan, Weiqun Zhang - * - * This file is part of WarpX. - * - * License: BSD-3-Clause-LBNL - */ -#ifndef WARPX_GPU_PARSER_H_ -#define WARPX_GPU_PARSER_H_ - -#include "Parser/WarpXParser.H" - -#include -#include -#include -#include - -// When compiled for CPU, wrap WarpXParser and enable threading. -// When compiled for GPU, store one copy of the parser in -// device memory for __device__ code, and one copy of the parser -// in host memory for __host__ code. This way, the parser can be -// efficiently called from both host and device. -template -class GpuParser -{ -public: - GpuParser (WarpXParser const& wp); - - GpuParser (GpuParser const&) = delete; - GpuParser (GpuParser &&) = delete; - void operator= (GpuParser const&) = delete; - void operator= (GpuParser &&) = delete; - - void clear (); - - template - AMREX_GPU_HOST_DEVICE - std::enable_if_t::value, - amrex::Real> - operator() (Ts... var) const noexcept - { -#ifdef AMREX_USE_GPU -#if AMREX_DEVICE_COMPILE -// WarpX compiled for GPU, function compiled for __device__ - amrex::GpuArray l_var{var...}; - return wp_ast_eval<0>(m_gpu_parser_ast, l_var.data()); -#else -// WarpX compiled for GPU, function compiled for __host__ - amrex::ignore_unused(var...); - return wp_ast_eval<0>(m_cpu_parser->ast, nullptr); -#endif - -#else -// WarpX compiled for CPU -#ifdef AMREX_USE_OMP - int tid = omp_get_thread_num(); -#else - int tid = 0; -#endif - m_var[tid] = amrex::GpuArray{var...}; - return wp_ast_eval<0>(m_parser[tid]->ast, nullptr); -#endif - } - - void init_gpu_parser (WarpXParser const& wp); // public for CUDA - -protected: - -#ifdef AMREX_USE_GPU - // Copy of the parser running on __device__ - struct wp_node* m_gpu_parser_ast; - // Copy of the parser running on __host__ - struct wp_parser* m_cpu_parser; - mutable amrex::GpuArray m_var; -#else - // Only one parser - struct wp_parser** m_parser; - mutable amrex::GpuArray* m_var; - int nthreads; -#endif -}; - -template -GpuParser::GpuParser (WarpXParser const& wp) -{ - AMREX_ALWAYS_ASSERT(wp.depth() <= WARPX_PARSER_DEPTH); - -#ifdef AMREX_USE_GPU - - struct wp_parser* a_wp = wp.m_parser; - - // Initialize CPU parser: - m_cpu_parser = wp_parser_dup(a_wp); - for (int i = 0; i < N; ++i) { - wp_parser_regvar(m_cpu_parser, wp.m_varnames[i].c_str(), &m_var[i]); - } - - // Initialize GPU parser - init_gpu_parser(wp); - -#else // not defined AMREX_USE_GPU - -#ifdef AMREX_USE_OMP - nthreads = omp_get_max_threads(); -#else // AMREX_USE_OMP - nthreads = 1; -#endif // AMREX_USE_OMP - - m_parser = ::new struct wp_parser*[nthreads]; - m_var = ::new amrex::GpuArray[nthreads]; - - for (int tid = 0; tid < nthreads; ++tid) - { -#ifdef AMREX_USE_OMP - m_parser[tid] = wp_parser_dup(wp.m_parser[tid]); - for (int i = 0; i < N; ++i) { - wp_parser_regvar(m_parser[tid], wp.m_varnames[tid][i].c_str(), &(m_var[tid][i])); - } -#else // AMREX_USE_OMP - m_parser[tid] = wp_parser_dup(wp.m_parser); - for (int i = 0; i < N; ++i) { - wp_parser_regvar(m_parser[tid], wp.m_varnames[i].c_str(), &(m_var[tid][i])); - } -#endif // AMREX_USE_OMP - } - -#endif // AMREX_USE_GPU -} - -template -void GpuParser::init_gpu_parser (WarpXParser const& wp) -{ -#ifdef AMREX_USE_GPU - - // We create a temporary Parser on CPU for memcpy. We cannot use - // m_cpu_parser for this because the variables in m_cpu_parser are - // registered for CPU use. - struct wp_parser* cpu_tmp = wp_parser_dup(m_cpu_parser); - for (int i = 0; i < N; ++i) { - wp_parser_regvar_gpu(cpu_tmp, wp.m_varnames[i].c_str(), i); - } - - m_gpu_parser_ast = (struct wp_node*) - amrex::The_Arena()->alloc(cpu_tmp->sz_mempool); - amrex::Gpu::htod_memcpy_async(m_gpu_parser_ast, cpu_tmp->ast, cpu_tmp->sz_mempool); - - auto dp = m_gpu_parser_ast; - char* droot = (char*)dp; - char* croot = (char*)(cpu_tmp->ast); - amrex::single_task([=] AMREX_GPU_DEVICE () noexcept - { - wp_ast_update_device_ptr<0>(dp, droot, croot); - }); - - amrex::Gpu::synchronize(); - - wp_parser_delete(cpu_tmp); -#endif - amrex::ignore_unused(wp); -} - -template -void -GpuParser::clear () -{ -#ifdef AMREX_USE_GPU - amrex::The_Arena()->free(m_gpu_parser_ast); - wp_parser_delete(m_cpu_parser); -#else - for (int tid = 0; tid < nthreads; ++tid) - { - wp_parser_delete(m_parser[tid]); - } - ::delete[] m_parser; - ::delete[] m_var; -#endif -} - -#endif diff --git a/Source/Parser/Make.package b/Source/Parser/Make.package deleted file mode 100644 index c1fce951cca..00000000000 --- a/Source/Parser/Make.package +++ /dev/null @@ -1,4 +0,0 @@ -CEXE_sources += wp_parser_y.cpp wp_parser.tab.cpp wp_parser.lex.cpp wp_parser_c.cpp WarpXParser.cpp - -VPATH_LOCATIONS += $(WARPX_HOME)/Source/Parser - diff --git a/Source/Parser/README b/Source/Parser/README deleted file mode 100644 index 9784d58c828..00000000000 --- a/Source/Parser/README +++ /dev/null @@ -1,44 +0,0 @@ - -* List of files - -** GNUmakefile - - This is not needed by WarpX. This is used to invoke bison and flex - to generate wp_parser.lex.c wp_parser.lex.c, wp_parser.tab.c, and - wp_parser.tab.h. - -** Make.package - - This is used by WarpX make system. - -** WarpXParser.H & WarpXParser.cpp - - WarpXParser class is the interface for the parser. - -** wp_parser.c & wp_parser_c.h - - This is an intermediate layer between WarpXParser class and the C - codes of the parser. - -** wp_parser.l - - This is a flex file. Note that this file is not needed to compile - WarpX, because the files have already been generated. - -** wp_parser.lex.c & wp_parser.lex.h - - They are generated by flex. - -** wp_parser.y - - This is a bison file. Note that this file is not needed to compile - WarpX, because the files have already been generated. - -** wp_parser.tab.c & wp_parser.tab.h - - They are generated by bison. - -** wp_parser_y.c & wp_parser_y.h - - These contain C codes that are used to evaluate a mathematical - expression given in string format. diff --git a/Source/Parser/WarpXParser.H b/Source/Parser/WarpXParser.H deleted file mode 100644 index f29abb11c9e..00000000000 --- a/Source/Parser/WarpXParser.H +++ /dev/null @@ -1,125 +0,0 @@ -/* Copyright 2019 Weiqun Zhang - * - * This file is part of WarpX. - * - * License: BSD-3-Clause-LBNL - */ -#ifndef WARPX_PARSER_H_ -#define WARPX_PARSER_H_ - -#include "wp_parser_c.h" -#include "wp_parser_y.h" - -#include -#include - -#ifdef AMREX_USE_OMP -# include -#endif - -#include -#include -#include -#include -#include - -class WarpXParser -{ -public: - WarpXParser (std::string const& func_body); - WarpXParser () = default; - ~WarpXParser (); - void define (std::string const& func_body); - - void setConstant (std::string const& name, amrex::Real c); - - // - // Option 1: Register every variable to an address provided. - // Assign values to external variables. - // Call eval(). - void registerVariable (std::string const& name, amrex::Real& var); - // - inline amrex::Real eval () const noexcept; - - // - // Option 2: Register all variables at once. Parser will create - // variables internally. - // Call eval(...) with variable values. - void registerVariables (std::vector const& names); - // - template inline - amrex::Real eval (T x, Ts... yz) const noexcept; - - void print () const; - - int depth () const; - - std::string const& expr () const; - - std::set symbols () const; - - template friend class GpuParser; - -private: - void clear (); - - template inline - void unpack (amrex::Real* p, T x) const noexcept; - - template inline - void unpack (amrex::Real* p, T x, Ts... yz) const noexcept; - - std::string m_expression; -#ifdef AMREX_USE_OMP - std::vector m_parser; - mutable std::vector > m_variables; - mutable std::vector > m_varnames; -#else - struct wp_parser* m_parser = nullptr; - mutable std::array m_variables; - mutable std::vector m_varnames; -#endif -}; - -inline -amrex::Real -WarpXParser::eval () const noexcept -{ -#ifdef AMREX_USE_OMP - return wp_ast_eval<0>(m_parser[omp_get_thread_num()]->ast,nullptr); -#else - return wp_ast_eval<0>(m_parser->ast,nullptr); -#endif -} - -template -inline -amrex::Real -WarpXParser::eval (T x, Ts... yz) const noexcept -{ -#ifdef AMREX_USE_OMP - unpack(m_variables[omp_get_thread_num()].data(), x, yz...); -#else - unpack(m_variables.data(), x, yz...); -#endif - return eval(); -} - -template -inline -void -WarpXParser::unpack (amrex::Real* p, T x) const noexcept -{ - *p = x; -} - -template -inline -void -WarpXParser::unpack (amrex::Real* p, T x, Ts... yz) const noexcept -{ - *p++ = x; - unpack(p, yz...); -} - -#endif diff --git a/Source/Parser/WarpXParser.cpp b/Source/Parser/WarpXParser.cpp deleted file mode 100644 index 4f228aedf69..00000000000 --- a/Source/Parser/WarpXParser.cpp +++ /dev/null @@ -1,177 +0,0 @@ -/* Copyright 2019 Weiqun Zhang - * - * This file is part of WarpX. - * - * License: BSD-3-Clause-LBNL - */ -#include "WarpXParser.H" - -#include - -WarpXParser::WarpXParser (std::string const& func_body) -{ - define(func_body); -} - -void -WarpXParser::define (std::string const& func_body) -{ - clear(); - - m_expression = func_body; - m_expression.erase(std::remove(m_expression.begin(),m_expression.end(),'\n'), - m_expression.end()); - std::string f = m_expression + "\n"; - -#ifdef AMREX_USE_OMP - - int nthreads = omp_get_max_threads(); - m_variables.resize(nthreads); - m_varnames.resize(nthreads); - m_parser.resize(nthreads); - m_parser[0] = wp_c_parser_new(f.c_str()); -#pragma omp parallel - { - int tid = omp_get_thread_num(); - if (tid > 0) { - m_parser[tid] = wp_parser_dup(m_parser[0]); - } - } - -#else - - m_parser = wp_c_parser_new(f.c_str()); - -#endif -} - -WarpXParser::~WarpXParser () -{ - clear(); -} - -void -WarpXParser::clear () -{ - m_expression.clear(); - m_varnames.clear(); - -#ifdef AMREX_USE_OMP - - if (!m_parser.empty()) - { -#pragma omp parallel - { - wp_parser_delete(m_parser[omp_get_thread_num()]); - } - } - m_parser.clear(); - m_variables.clear(); - -#else - - if (m_parser) wp_parser_delete(m_parser); - m_parser = nullptr; - -#endif -} - -void -WarpXParser::registerVariable (std::string const& name, amrex::Real& var) -{ - // We assume this is called inside OMP parallel region -#ifdef AMREX_USE_OMP - wp_parser_regvar(m_parser[omp_get_thread_num()], name.c_str(), &var); - m_varnames[omp_get_thread_num()].push_back(name); -#else - wp_parser_regvar(m_parser, name.c_str(), &var); - m_varnames.push_back(name); -#endif -} - -void -WarpXParser::registerVariables (std::vector const& names) -{ -#ifdef AMREX_USE_OMP - -// This must be called outside OpenMP parallel region. -#pragma omp parallel - { - const int tid = omp_get_thread_num(); - struct wp_parser* p = m_parser[tid]; - auto& v = m_variables[tid]; - for (int j = 0; j < static_cast(names.size()); ++j) { - wp_parser_regvar(p, names[j].c_str(), &(v[j])); - m_varnames[tid].push_back(names[j]); - } - } - -#else - - for (auto j = 0u; j < names.size(); ++j) { - wp_parser_regvar(m_parser, names[j].c_str(), &(m_variables[j])); - m_varnames.push_back(names[j]); - } - -#endif -} - -void -WarpXParser::setConstant (std::string const& name, amrex::Real c) -{ -#ifdef AMREX_USE_OMP - - bool in_parallel = omp_in_parallel(); - // We don't know if this is inside OMP parallel region or not -#pragma omp parallel if (!in_parallel) - { - wp_parser_setconst(m_parser[omp_get_thread_num()], name.c_str(), c); - } - -#else - - wp_parser_setconst(m_parser, name.c_str(), c); - -#endif -} - -void -WarpXParser::print () const -{ -#ifdef AMREX_USE_OMP -#pragma omp critical(warpx_parser_pint) - wp_ast_print(m_parser[omp_get_thread_num()]->ast); -#else - wp_ast_print(m_parser->ast); -#endif -} - -int -WarpXParser::depth () const -{ - int n = 0; -#ifdef AMREX_USE_OMP - wp_ast_depth(m_parser[omp_get_thread_num()]->ast, &n); -#else - wp_ast_depth(m_parser->ast, &n); -#endif - return n; -} - -std::string const& -WarpXParser::expr () const -{ - return m_expression; -} - -std::set -WarpXParser::symbols () const -{ - std::set results; -#ifdef AMREX_USE_OMP - wp_ast_get_symbols(m_parser[omp_get_thread_num()]->ast, results); -#else - wp_ast_get_symbols(m_parser->ast, results); -#endif - return results; -} diff --git a/Source/Parser/WarpXParserWrapper.H b/Source/Parser/WarpXParserWrapper.H deleted file mode 100644 index 96035861092..00000000000 --- a/Source/Parser/WarpXParserWrapper.H +++ /dev/null @@ -1,98 +0,0 @@ -/* Copyright 2020 Revathi Jambunathan, Weiqun Zhang - * - * This file is part of WarpX. - * - * License: BSD-3-Clause-LBNL - */ -#ifndef WARPX_PARSER_WRAPPER_H_ -#define WARPX_PARSER_WRAPPER_H_ - -#include "WarpXParserWrapper_fwd.H" - -#include "Parser/GpuParser.H" -#include "Parser/WarpXParser.H" - -#include - -#include - -/** - * \brief - * The HostDeviceParser struct is non-owning and is suitable for being - * value captured by device lamba. - */ - -template -struct HostDeviceParser -{ - template - AMREX_GPU_HOST_DEVICE - std::enable_if_t::value, - amrex::Real> - operator() (Ts... var) const noexcept - { -#ifdef AMREX_USE_GPU -#if AMREX_DEVICE_COMPILE -// WarpX compiled for GPU, function compiled for __device__ - amrex::GpuArray l_var{var...}; - return wp_ast_eval<0>(m_gpu_parser_ast, l_var.data()); -#else -// WarpX compiled for GPU, function compiled for __host__ - return (*m_gpu_parser)(var...); -#endif -#else -// WarpX compiled for CPU - return (*m_gpu_parser)(var...); -#endif - } - -#ifdef AMREX_USE_GPU - struct wp_node * m_gpu_parser_ast = nullptr; -#endif - GpuParser const* m_gpu_parser = nullptr; -}; - -/** - * \brief - * The ParserWrapper struct is constructed to safely use the GpuParser class - * that can essentially be though of as a raw pointer. The GpuParser does - * not have an explicit destructor and the AddPlasma subroutines handle the GpuParser - * in a safe way. The ParserWrapper struct is used to avoid memory leak - * in the EB parser functions. - */ -template -struct ParserWrapper - : public GpuParser -{ - using GpuParser::GpuParser; - - ParserWrapper (ParserWrapper const&) = delete; - void operator= (ParserWrapper const&) = delete; - - ~ParserWrapper() { GpuParser::clear(); } - - void operator() () const = delete; // Hide GpuParser::operator() - - HostDeviceParser getParser () const { -#ifdef AMREX_USE_GPU - return HostDeviceParser{this->m_gpu_parser_ast, static_cast const*>(this)}; -#else - return HostDeviceParser{static_cast const*>(this)}; -#endif - } -}; - -template -HostDeviceParser getParser (ParserWrapper const* parser_wrapper) -{ - return parser_wrapper ? parser_wrapper->getParser() : HostDeviceParser{}; -} - -template -HostDeviceParser getParser (std::unique_ptr > const& parser_wrapper) -{ - return parser_wrapper ? parser_wrapper->getParser() : HostDeviceParser{}; -} - -#endif diff --git a/Source/Parser/WarpXParserWrapper_fwd.H b/Source/Parser/WarpXParserWrapper_fwd.H deleted file mode 100644 index 6e0f9bcebd0..00000000000 --- a/Source/Parser/WarpXParserWrapper_fwd.H +++ /dev/null @@ -1,9 +0,0 @@ -/* Copyright 2021 Luca Fedeli - * - * This file is part of WarpX. - * - * License: BSD-3-Clause-LBNL - */ - -template struct HostDeviceParser; -template struct ParserWrapper; diff --git a/Source/Parser/wp_parser.l b/Source/Parser/wp_parser.l deleted file mode 100644 index 1aa0c60aaef..00000000000 --- a/Source/Parser/wp_parser.l +++ /dev/null @@ -1,81 +0,0 @@ -%option noyywrap nodefault -%option never-interactive -%{ -#include "wp_parser_y.h" -#include "wp_parser.tab.h" -%} - -%option nounput -%option noinput -%option prefix="wxparser" - - /* Tokens NUMBER, SYMBOL, F1, POW, F2, etc. are defined in wp_parser.y. */ - /* Types WP_SQRT, WP_SQRT, etc. are defined in wp_parser_y.h. */ - - /* Used later to define NUMBER */ -EXP ([Ee][-+]?[0-9]+) - -%% - -"+" | -"-" | -"*" | -"/" | -"=" | -"|" | -"," | -"<" | -">" | -"(" | -")" { return wxparsertext[0]; } /* simply pass through */ - - /* wxparserlval is union type defined in wp_parser.tab.h that is generated - * by bison with wp_parser.y */ - -"sqrt" { wxparserlval.f1 = WP_SQRT; return F1; } -"exp" { wxparserlval.f1 = WP_EXP; return F1; } -"log" { wxparserlval.f1 = WP_LOG; return F1; } -"log10" { wxparserlval.f1 = WP_LOG10; return F1; } -"sin" { wxparserlval.f1 = WP_SIN; return F1; } -"cos" { wxparserlval.f1 = WP_COS; return F1; } -"tan" { wxparserlval.f1 = WP_TAN; return F1; } -"asin" { wxparserlval.f1 = WP_ASIN; return F1; } -"acos" { wxparserlval.f1 = WP_ACOS; return F1; } -"atan" { wxparserlval.f1 = WP_ATAN; return F1; } -"sinh" { wxparserlval.f1 = WP_SINH; return F1; } -"cosh" { wxparserlval.f1 = WP_COSH; return F1; } -"tanh" { wxparserlval.f1 = WP_TANH; return F1; } -"abs" { wxparserlval.f1 = WP_ABS; return F1; } -"fabs" { wxparserlval.f1 = WP_ABS; return F1; } -"**" { wxparserlval.f2 = WP_POW; return POW;} -"^" { wxparserlval.f2 = WP_POW; return POW;} -">=" { wxparserlval.f2 = WP_GEQ; return GEQ;} -"<=" { wxparserlval.f2 = WP_LEQ; return LEQ;} -"==" { wxparserlval.f2 = WP_EQ; return EQ;} -"!=" { wxparserlval.f2 = WP_NEQ; return NEQ;} -"and" { wxparserlval.f2 = WP_AND; return AND;} -"or" { wxparserlval.f2 = WP_OR; return OR;} -"pow" { wxparserlval.f2 = WP_POW; return F2; } -"heaviside" { wxparserlval.f2 = WP_HEAVISIDE; return F2; } -"jn" { wxparserlval.f2 = WP_JN; return F2; } -"min" { wxparserlval.f2 = WP_MIN; return F2; } -"max" { wxparserlval.f2 = WP_MAX; return F2; } -"if" { wxparserlval.f3 = WP_IF; return F3; } - - /* We use SYMBOL to hold variables and constants */ -[a-zA-Z_][a-zA-Z0-9_]* { wxparserlval.s = wp_makesymbol(wxparsertext); return SYMBOL; } - - /* Number */ -[0-9]+"."[0-9]*{EXP}? | -"."?[0-9]+{EXP}? { wxparserlval.d = atof(wxparsertext); return NUMBER; } - - /* Special characters */ -"//".* -[ \t] /* ignore white space */ -\\\n /* ignore line continuation */ -"\n" { return EOL; } - - /* everything else */ -. { wxparsererror("Unknown character %c\n", *wxparsertext); } - -%% diff --git a/Source/Parser/wp_parser.lex.cpp b/Source/Parser/wp_parser.lex.cpp deleted file mode 100644 index a7685720957..00000000000 --- a/Source/Parser/wp_parser.lex.cpp +++ /dev/null @@ -1,2190 +0,0 @@ - -#define YY_INT_ALIGNED short int - -/* A lexical scanner generated by flex */ - -#define yy_create_buffer wxparser_create_buffer -#define yy_delete_buffer wxparser_delete_buffer -#define yy_scan_buffer wxparser_scan_buffer -#define yy_scan_string wxparser_scan_string -#define yy_scan_bytes wxparser_scan_bytes -#define yy_init_buffer wxparser_init_buffer -#define yy_flush_buffer wxparser_flush_buffer -#define yy_load_buffer_state wxparser_load_buffer_state -#define yy_switch_to_buffer wxparser_switch_to_buffer -#define yypush_buffer_state wxparserpush_buffer_state -#define yypop_buffer_state wxparserpop_buffer_state -#define yyensure_buffer_stack wxparserensure_buffer_stack -#define yy_flex_debug wxparser_flex_debug -#define yyin wxparserin -#define yyleng wxparserleng -#define yylex wxparserlex -#define yylineno wxparserlineno -#define yyout wxparserout -#define yyrestart wxparserrestart -#define yytext wxparsertext -#define yywrap wxparserwrap -#define yyalloc wxparseralloc -#define yyrealloc wxparserrealloc -#define yyfree wxparserfree - -#define FLEX_SCANNER -#define YY_FLEX_MAJOR_VERSION 2 -#define YY_FLEX_MINOR_VERSION 6 -#define YY_FLEX_SUBMINOR_VERSION 4 -#if YY_FLEX_SUBMINOR_VERSION > 0 -#define FLEX_BETA -#endif - -#ifdef yy_create_buffer -#define wxparser_create_buffer_ALREADY_DEFINED -#else -#define yy_create_buffer wxparser_create_buffer -#endif - -#ifdef yy_delete_buffer -#define wxparser_delete_buffer_ALREADY_DEFINED -#else -#define yy_delete_buffer wxparser_delete_buffer -#endif - -#ifdef yy_scan_buffer -#define wxparser_scan_buffer_ALREADY_DEFINED -#else -#define yy_scan_buffer wxparser_scan_buffer -#endif - -#ifdef yy_scan_string -#define wxparser_scan_string_ALREADY_DEFINED -#else -#define yy_scan_string wxparser_scan_string -#endif - -#ifdef yy_scan_bytes -#define wxparser_scan_bytes_ALREADY_DEFINED -#else -#define yy_scan_bytes wxparser_scan_bytes -#endif - -#ifdef yy_init_buffer -#define wxparser_init_buffer_ALREADY_DEFINED -#else -#define yy_init_buffer wxparser_init_buffer -#endif - -#ifdef yy_flush_buffer -#define wxparser_flush_buffer_ALREADY_DEFINED -#else -#define yy_flush_buffer wxparser_flush_buffer -#endif - -#ifdef yy_load_buffer_state -#define wxparser_load_buffer_state_ALREADY_DEFINED -#else -#define yy_load_buffer_state wxparser_load_buffer_state -#endif - -#ifdef yy_switch_to_buffer -#define wxparser_switch_to_buffer_ALREADY_DEFINED -#else -#define yy_switch_to_buffer wxparser_switch_to_buffer -#endif - -#ifdef yypush_buffer_state -#define wxparserpush_buffer_state_ALREADY_DEFINED -#else -#define yypush_buffer_state wxparserpush_buffer_state -#endif - -#ifdef yypop_buffer_state -#define wxparserpop_buffer_state_ALREADY_DEFINED -#else -#define yypop_buffer_state wxparserpop_buffer_state -#endif - -#ifdef yyensure_buffer_stack -#define wxparserensure_buffer_stack_ALREADY_DEFINED -#else -#define yyensure_buffer_stack wxparserensure_buffer_stack -#endif - -#ifdef yylex -#define wxparserlex_ALREADY_DEFINED -#else -#define yylex wxparserlex -#endif - -#ifdef yyrestart -#define wxparserrestart_ALREADY_DEFINED -#else -#define yyrestart wxparserrestart -#endif - -#ifdef yylex_init -#define wxparserlex_init_ALREADY_DEFINED -#else -#define yylex_init wxparserlex_init -#endif - -#ifdef yylex_init_extra -#define wxparserlex_init_extra_ALREADY_DEFINED -#else -#define yylex_init_extra wxparserlex_init_extra -#endif - -#ifdef yylex_destroy -#define wxparserlex_destroy_ALREADY_DEFINED -#else -#define yylex_destroy wxparserlex_destroy -#endif - -#ifdef yyget_debug -#define wxparserget_debug_ALREADY_DEFINED -#else -#define yyget_debug wxparserget_debug -#endif - -#ifdef yyset_debug -#define wxparserset_debug_ALREADY_DEFINED -#else -#define yyset_debug wxparserset_debug -#endif - -#ifdef yyget_extra -#define wxparserget_extra_ALREADY_DEFINED -#else -#define yyget_extra wxparserget_extra -#endif - -#ifdef yyset_extra -#define wxparserset_extra_ALREADY_DEFINED -#else -#define yyset_extra wxparserset_extra -#endif - -#ifdef yyget_in -#define wxparserget_in_ALREADY_DEFINED -#else -#define yyget_in wxparserget_in -#endif - -#ifdef yyset_in -#define wxparserset_in_ALREADY_DEFINED -#else -#define yyset_in wxparserset_in -#endif - -#ifdef yyget_out -#define wxparserget_out_ALREADY_DEFINED -#else -#define yyget_out wxparserget_out -#endif - -#ifdef yyset_out -#define wxparserset_out_ALREADY_DEFINED -#else -#define yyset_out wxparserset_out -#endif - -#ifdef yyget_leng -#define wxparserget_leng_ALREADY_DEFINED -#else -#define yyget_leng wxparserget_leng -#endif - -#ifdef yyget_text -#define wxparserget_text_ALREADY_DEFINED -#else -#define yyget_text wxparserget_text -#endif - -#ifdef yyget_lineno -#define wxparserget_lineno_ALREADY_DEFINED -#else -#define yyget_lineno wxparserget_lineno -#endif - -#ifdef yyset_lineno -#define wxparserset_lineno_ALREADY_DEFINED -#else -#define yyset_lineno wxparserset_lineno -#endif - -#ifdef yywrap -#define wxparserwrap_ALREADY_DEFINED -#else -#define yywrap wxparserwrap -#endif - -#ifdef yyalloc -#define wxparseralloc_ALREADY_DEFINED -#else -#define yyalloc wxparseralloc -#endif - -#ifdef yyrealloc -#define wxparserrealloc_ALREADY_DEFINED -#else -#define yyrealloc wxparserrealloc -#endif - -#ifdef yyfree -#define wxparserfree_ALREADY_DEFINED -#else -#define yyfree wxparserfree -#endif - -#ifdef yytext -#define wxparsertext_ALREADY_DEFINED -#else -#define yytext wxparsertext -#endif - -#ifdef yyleng -#define wxparserleng_ALREADY_DEFINED -#else -#define yyleng wxparserleng -#endif - -#ifdef yyin -#define wxparserin_ALREADY_DEFINED -#else -#define yyin wxparserin -#endif - -#ifdef yyout -#define wxparserout_ALREADY_DEFINED -#else -#define yyout wxparserout -#endif - -#ifdef yy_flex_debug -#define wxparser_flex_debug_ALREADY_DEFINED -#else -#define yy_flex_debug wxparser_flex_debug -#endif - -#ifdef yylineno -#define wxparserlineno_ALREADY_DEFINED -#else -#define yylineno wxparserlineno -#endif - -/* First, we deal with platform-specific or compiler-specific issues. */ - -/* begin standard C headers. */ -#include -#include -#include -#include - -/* end standard C headers. */ - -/* flex integer type definitions */ - -#ifndef FLEXINT_H -#define FLEXINT_H - -/* C99 systems have . Non-C99 systems may or may not. */ - -#if defined (__STDC_VERSION__) && __STDC_VERSION__ >= 199901L - -/* C99 says to define __STDC_LIMIT_MACROS before including stdint.h, - * if you want the limit (max/min) macros for int types. - */ -#ifndef __STDC_LIMIT_MACROS -#define __STDC_LIMIT_MACROS 1 -#endif - -#include -typedef int8_t flex_int8_t; -typedef uint8_t flex_uint8_t; -typedef int16_t flex_int16_t; -typedef uint16_t flex_uint16_t; -typedef int32_t flex_int32_t; -typedef uint32_t flex_uint32_t; -#else -typedef signed char flex_int8_t; -typedef short int flex_int16_t; -typedef int flex_int32_t; -typedef unsigned char flex_uint8_t; -typedef unsigned short int flex_uint16_t; -typedef unsigned int flex_uint32_t; - -/* Limits of integral types. */ -#ifndef INT8_MIN -#define INT8_MIN (-128) -#endif -#ifndef INT16_MIN -#define INT16_MIN (-32767-1) -#endif -#ifndef INT32_MIN -#define INT32_MIN (-2147483647-1) -#endif -#ifndef INT8_MAX -#define INT8_MAX (127) -#endif -#ifndef INT16_MAX -#define INT16_MAX (32767) -#endif -#ifndef INT32_MAX -#define INT32_MAX (2147483647) -#endif -#ifndef UINT8_MAX -#define UINT8_MAX (255U) -#endif -#ifndef UINT16_MAX -#define UINT16_MAX (65535U) -#endif -#ifndef UINT32_MAX -#define UINT32_MAX (4294967295U) -#endif - -#ifndef SIZE_MAX -#define SIZE_MAX (~(size_t)0) -#endif - -#endif /* ! C99 */ - -#endif /* ! FLEXINT_H */ - -/* begin standard C++ headers. */ - -/* TODO: this is always defined, so inline it */ -#define yyconst const - -#if defined(__GNUC__) && __GNUC__ >= 3 -#define yynoreturn __attribute__((__noreturn__)) -#else -#define yynoreturn -#endif - -/* Returned upon end-of-file. */ -#define YY_NULL 0 - -/* Promotes a possibly negative, possibly signed char to an - * integer in range [0..255] for use as an array index. - */ -#define YY_SC_TO_UI(c) ((YY_CHAR) (c)) - -/* Enter a start condition. This macro really ought to take a parameter, - * but we do it the disgusting crufty way forced on us by the ()-less - * definition of BEGIN. - */ -#define BEGIN (yy_start) = 1 + 2 * -/* Translate the current start state into a value that can be later handed - * to BEGIN to return to the state. The YYSTATE alias is for lex - * compatibility. - */ -#define YY_START (((yy_start) - 1) / 2) -#define YYSTATE YY_START -/* Action number for EOF rule of a given start state. */ -#define YY_STATE_EOF(state) (YY_END_OF_BUFFER + state + 1) -/* Special action meaning "start processing a new file". */ -#define YY_NEW_FILE yyrestart( yyin ) -#define YY_END_OF_BUFFER_CHAR 0 - -/* Size of default input buffer. */ -#ifndef YY_BUF_SIZE -#ifdef __ia64__ -/* On IA-64, the buffer size is 16k, not 8k. - * Moreover, YY_BUF_SIZE is 2*YY_READ_BUF_SIZE in the general case. - * Ditto for the __ia64__ case accordingly. - */ -#define YY_BUF_SIZE 32768 -#else -#define YY_BUF_SIZE 16384 -#endif /* __ia64__ */ -#endif - -/* The state buf must be large enough to hold one state per character in the main buffer. - */ -#define YY_STATE_BUF_SIZE ((YY_BUF_SIZE + 2) * sizeof(yy_state_type)) - -#ifndef YY_TYPEDEF_YY_BUFFER_STATE -#define YY_TYPEDEF_YY_BUFFER_STATE -typedef struct yy_buffer_state *YY_BUFFER_STATE; -#endif - -#ifndef YY_TYPEDEF_YY_SIZE_T -#define YY_TYPEDEF_YY_SIZE_T -typedef size_t yy_size_t; -#endif - -extern int yyleng; - -extern FILE *yyin, *yyout; - -#define EOB_ACT_CONTINUE_SCAN 0 -#define EOB_ACT_END_OF_FILE 1 -#define EOB_ACT_LAST_MATCH 2 - - #define YY_LESS_LINENO(n) - #define YY_LINENO_REWIND_TO(ptr) - -/* Return all but the first "n" matched characters back to the input stream. */ -#define yyless(n) \ - do \ - { \ - /* Undo effects of setting up yytext. */ \ - int yyless_macro_arg = (n); \ - YY_LESS_LINENO(yyless_macro_arg);\ - *yy_cp = (yy_hold_char); \ - YY_RESTORE_YY_MORE_OFFSET \ - (yy_c_buf_p) = yy_cp = yy_bp + yyless_macro_arg - YY_MORE_ADJ; \ - YY_DO_BEFORE_ACTION; /* set up yytext again */ \ - } \ - while ( 0 ) -#define unput(c) yyunput( c, (yytext_ptr) ) - -#ifndef YY_STRUCT_YY_BUFFER_STATE -#define YY_STRUCT_YY_BUFFER_STATE -struct yy_buffer_state - { - FILE *yy_input_file; - - char *yy_ch_buf; /* input buffer */ - char *yy_buf_pos; /* current position in input buffer */ - - /* Size of input buffer in bytes, not including room for EOB - * characters. - */ - int yy_buf_size; - - /* Number of characters read into yy_ch_buf, not including EOB - * characters. - */ - int yy_n_chars; - - /* Whether we "own" the buffer - i.e., we know we created it, - * and can realloc() it to grow it, and should free() it to - * delete it. - */ - int yy_is_our_buffer; - - /* Whether this is an "interactive" input source; if so, and - * if we're using stdio for input, then we want to use getc() - * instead of fread(), to make sure we stop fetching input after - * each newline. - */ - int yy_is_interactive; - - /* Whether we're considered to be at the beginning of a line. - * If so, '^' rules will be active on the next match, otherwise - * not. - */ - int yy_at_bol; - - int yy_bs_lineno; /**< The line count. */ - int yy_bs_column; /**< The column count. */ - - /* Whether to try to fill the input buffer when we reach the - * end of it. - */ - int yy_fill_buffer; - - int yy_buffer_status; - -#define YY_BUFFER_NEW 0 -#define YY_BUFFER_NORMAL 1 - /* When an EOF's been seen but there's still some text to process - * then we mark the buffer as YY_EOF_PENDING, to indicate that we - * shouldn't try reading from the input source any more. We might - * still have a bunch of tokens to match, though, because of - * possible backing-up. - * - * When we actually see the EOF, we change the status to "new" - * (via yyrestart()), so that the user can continue scanning by - * just pointing yyin at a new input file. - */ -#define YY_BUFFER_EOF_PENDING 2 - - }; -#endif /* !YY_STRUCT_YY_BUFFER_STATE */ - -/* Stack of input buffers. */ -static size_t yy_buffer_stack_top = 0; /**< index of top of stack. */ -static size_t yy_buffer_stack_max = 0; /**< capacity of stack. */ -static YY_BUFFER_STATE * yy_buffer_stack = NULL; /**< Stack as an array. */ - -/* We provide macros for accessing buffer states in case in the - * future we want to put the buffer states in a more general - * "scanner state". - * - * Returns the top of the stack, or NULL. - */ -#define YY_CURRENT_BUFFER ( (yy_buffer_stack) \ - ? (yy_buffer_stack)[(yy_buffer_stack_top)] \ - : NULL) -/* Same as previous macro, but useful when we know that the buffer stack is not - * NULL or when we need an lvalue. For internal use only. - */ -#define YY_CURRENT_BUFFER_LVALUE (yy_buffer_stack)[(yy_buffer_stack_top)] - -/* yy_hold_char holds the character lost when yytext is formed. */ -static char yy_hold_char; -static int yy_n_chars; /* number of characters read into yy_ch_buf */ -int yyleng; - -/* Points to current character in buffer. */ -static char *yy_c_buf_p = NULL; -static int yy_init = 0; /* whether we need to initialize */ -static int yy_start = 0; /* start state number */ - -/* Flag which is used to allow yywrap()'s to do buffer switches - * instead of setting up a fresh yyin. A bit of a hack ... - */ -static int yy_did_buffer_switch_on_eof; - -void yyrestart ( FILE *input_file ); -void yy_switch_to_buffer ( YY_BUFFER_STATE new_buffer ); -YY_BUFFER_STATE yy_create_buffer ( FILE *file, int size ); -void yy_delete_buffer ( YY_BUFFER_STATE b ); -void yy_flush_buffer ( YY_BUFFER_STATE b ); -void yypush_buffer_state ( YY_BUFFER_STATE new_buffer ); -void yypop_buffer_state ( void ); - -static void yyensure_buffer_stack ( void ); -static void yy_load_buffer_state ( void ); -static void yy_init_buffer ( YY_BUFFER_STATE b, FILE *file ); -#define YY_FLUSH_BUFFER yy_flush_buffer( YY_CURRENT_BUFFER ) - -YY_BUFFER_STATE yy_scan_buffer ( char *base, yy_size_t size ); -YY_BUFFER_STATE yy_scan_string ( const char *yy_str ); -YY_BUFFER_STATE yy_scan_bytes ( const char *bytes, int len ); - -void *yyalloc ( yy_size_t ); -void *yyrealloc ( void *, yy_size_t ); -void yyfree ( void * ); - -#define yy_new_buffer yy_create_buffer -#define yy_set_interactive(is_interactive) \ - { \ - if ( ! YY_CURRENT_BUFFER ){ \ - yyensure_buffer_stack (); \ - YY_CURRENT_BUFFER_LVALUE = \ - yy_create_buffer( yyin, YY_BUF_SIZE ); \ - } \ - YY_CURRENT_BUFFER_LVALUE->yy_is_interactive = is_interactive; \ - } -#define yy_set_bol(at_bol) \ - { \ - if ( ! YY_CURRENT_BUFFER ){\ - yyensure_buffer_stack (); \ - YY_CURRENT_BUFFER_LVALUE = \ - yy_create_buffer( yyin, YY_BUF_SIZE ); \ - } \ - YY_CURRENT_BUFFER_LVALUE->yy_at_bol = at_bol; \ - } -#define YY_AT_BOL() (YY_CURRENT_BUFFER_LVALUE->yy_at_bol) - -/* Begin user sect3 */ - -#define wxparserwrap() (/*CONSTCOND*/1) -#define YY_SKIP_YYWRAP -typedef flex_uint8_t YY_CHAR; - -FILE *yyin = NULL, *yyout = NULL; - -typedef int yy_state_type; - -extern int yylineno; -int yylineno = 1; - -extern char *yytext; -#ifdef yytext_ptr -#undef yytext_ptr -#endif -#define yytext_ptr yytext - -static yy_state_type yy_get_previous_state ( void ); -static yy_state_type yy_try_NUL_trans ( yy_state_type current_state ); -static int yy_get_next_buffer ( void ); -static void yynoreturn yy_fatal_error ( const char* msg ); - -/* Done after the current pattern has been matched and before the - * corresponding action - sets up yytext. - */ -#define YY_DO_BEFORE_ACTION \ - (yytext_ptr) = yy_bp; \ - yyleng = (int) (yy_cp - yy_bp); \ - (yy_hold_char) = *yy_cp; \ - *yy_cp = '\0'; \ - (yy_c_buf_p) = yy_cp; -#define YY_NUM_RULES 49 -#define YY_END_OF_BUFFER 50 -/* This struct is not used in this scanner, - but its presence is necessary. */ -struct yy_trans_info - { - flex_int32_t yy_verify; - flex_int32_t yy_nxt; - }; -static const flex_int16_t yy_accept[108] = - { 0, - 0, 0, 50, 48, 45, 47, 48, 10, 11, 3, - 1, 7, 2, 48, 4, 43, 8, 5, 9, 41, - 48, 28, 41, 41, 41, 41, 41, 41, 41, 41, - 41, 41, 41, 41, 41, 6, 32, 27, 43, 44, - 42, 43, 0, 30, 31, 29, 41, 46, 41, 41, - 41, 41, 41, 41, 41, 41, 41, 40, 37, 41, - 41, 41, 34, 41, 41, 41, 41, 44, 42, 0, - 0, 43, 25, 41, 33, 41, 41, 17, 13, 41, - 41, 14, 39, 38, 35, 16, 41, 18, 0, 42, - 20, 19, 21, 23, 26, 41, 41, 22, 12, 24, - - 41, 15, 41, 41, 41, 36, 0 - } ; - -static const YY_CHAR yy_ec[256] = - { 0, - 1, 1, 1, 1, 1, 1, 1, 1, 2, 3, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 2, 4, 1, 1, 1, 1, 1, 1, 5, - 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, - 15, 15, 15, 15, 15, 15, 15, 1, 1, 16, - 17, 18, 1, 1, 19, 19, 19, 19, 20, 19, - 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, - 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, - 1, 21, 1, 22, 19, 1, 23, 24, 25, 26, - - 27, 28, 29, 30, 31, 32, 19, 33, 34, 35, - 36, 37, 38, 39, 40, 41, 19, 42, 43, 44, - 19, 19, 1, 45, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1 - } ; - -static const YY_CHAR yy_meta[46] = - { 0, - 1, 1, 2, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 3, 3, 3, 1, 1, 1, 3, 3, - 1, 1, 3, 3, 3, 3, 3, 3, 3, 3, - 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, - 3, 3, 3, 3, 1 - } ; - -static const flex_int16_t yy_base[110] = - { 0, - 0, 0, 159, 160, 160, 160, 141, 160, 160, 150, - 160, 160, 160, 33, 144, 38, 138, 137, 136, 0, - 149, 160, 31, 115, 106, 126, 121, 119, 111, 109, - 31, 105, 107, 19, 119, 160, 160, 160, 54, 0, - 62, 72, 80, 160, 160, 160, 0, 160, 101, 104, - 113, 107, 114, 96, 98, 110, 110, 0, 0, 103, - 87, 95, 0, 86, 93, 88, 91, 0, 83, 92, - 46, 65, 0, 85, 0, 89, 88, 92, 0, 81, - 78, 104, 0, 0, 0, 79, 67, 74, 98, 101, - 0, 0, 0, 0, 0, 70, 78, 0, 0, 0, - - 44, 0, 42, 44, 37, 0, 160, 60, 116 - } ; - -static const flex_int16_t yy_def[110] = - { 0, - 107, 1, 107, 107, 107, 107, 107, 107, 107, 107, - 107, 107, 107, 107, 107, 107, 107, 107, 107, 108, - 107, 107, 108, 108, 108, 108, 108, 108, 108, 108, - 108, 108, 108, 108, 108, 107, 107, 107, 107, 109, - 107, 107, 107, 107, 107, 107, 108, 107, 108, 108, - 108, 108, 108, 108, 108, 108, 108, 108, 108, 108, - 108, 108, 108, 108, 108, 108, 108, 109, 107, 107, - 107, 107, 108, 108, 108, 108, 108, 108, 108, 108, - 108, 108, 108, 108, 108, 108, 108, 108, 107, 107, - 108, 108, 108, 108, 108, 108, 108, 108, 108, 108, - - 108, 108, 108, 108, 108, 108, 0, 107, 107 - } ; - -static const flex_int16_t yy_nxt[206] = - { 0, - 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, - 14, 15, 16, 16, 16, 17, 18, 19, 20, 20, - 21, 22, 23, 20, 24, 20, 25, 26, 20, 27, - 28, 29, 30, 31, 20, 32, 33, 20, 20, 34, - 35, 20, 20, 20, 36, 39, 39, 39, 41, 65, - 42, 42, 42, 61, 49, 50, 66, 43, 72, 72, - 72, 62, 47, 106, 43, 51, 39, 39, 39, 105, - 52, 53, 104, 43, 69, 69, 69, 72, 72, 72, - 43, 70, 41, 103, 42, 42, 42, 71, 70, 71, - 102, 43, 72, 72, 72, 69, 69, 69, 43, 89, - - 101, 89, 70, 100, 90, 90, 90, 99, 98, 70, - 90, 90, 90, 90, 90, 90, 68, 97, 68, 96, - 95, 94, 93, 92, 91, 88, 87, 86, 85, 84, - 83, 82, 81, 80, 79, 78, 77, 76, 75, 74, - 73, 67, 64, 63, 60, 59, 58, 57, 56, 55, - 54, 48, 46, 45, 44, 40, 38, 37, 107, 3, - 107, 107, 107, 107, 107, 107, 107, 107, 107, 107, - 107, 107, 107, 107, 107, 107, 107, 107, 107, 107, - 107, 107, 107, 107, 107, 107, 107, 107, 107, 107, - 107, 107, 107, 107, 107, 107, 107, 107, 107, 107, - - 107, 107, 107, 107, 107 - } ; - -static const flex_int16_t yy_chk[206] = - { 0, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 14, 14, 14, 16, 34, - 16, 16, 16, 31, 23, 23, 34, 16, 71, 71, - 71, 31, 108, 105, 16, 23, 39, 39, 39, 104, - 23, 23, 103, 39, 41, 41, 41, 72, 72, 72, - 39, 41, 42, 101, 42, 42, 42, 43, 41, 43, - 97, 42, 43, 43, 43, 69, 69, 69, 42, 70, - - 96, 70, 69, 88, 70, 70, 70, 87, 86, 69, - 89, 89, 89, 90, 90, 90, 109, 82, 109, 81, - 80, 78, 77, 76, 74, 67, 66, 65, 64, 62, - 61, 60, 57, 56, 55, 54, 53, 52, 51, 50, - 49, 35, 33, 32, 30, 29, 28, 27, 26, 25, - 24, 21, 19, 18, 17, 15, 10, 7, 3, 107, - 107, 107, 107, 107, 107, 107, 107, 107, 107, 107, - 107, 107, 107, 107, 107, 107, 107, 107, 107, 107, - 107, 107, 107, 107, 107, 107, 107, 107, 107, 107, - 107, 107, 107, 107, 107, 107, 107, 107, 107, 107, - - 107, 107, 107, 107, 107 - } ; - -static yy_state_type yy_last_accepting_state; -static char *yy_last_accepting_cpos; - -extern int yy_flex_debug; -int yy_flex_debug = 0; - -/* The intent behind this definition is that it'll catch - * any uses of REJECT which flex missed. - */ -#define REJECT reject_used_but_not_detected -#define yymore() yymore_used_but_not_detected -#define YY_MORE_ADJ 0 -#define YY_RESTORE_YY_MORE_OFFSET -char *yytext; -#include "wp_parser_y.h" -#include "wp_parser.tab.h" -#define YY_NO_INPUT 1 - /* Tokens NUMBER, SYMBOL, F1, POW, F2, etc. are defined in wp_parser.y. */ - /* Types WP_SQRT, WP_SQRT, etc. are defined in wp_parser_y.h. */ - /* Used later to define NUMBER */ - -#define INITIAL 0 - -#ifndef YY_NO_UNISTD_H -/* Special case for "unistd.h", since it is non-ANSI. We include it way - * down here because we want the user's section 1 to have been scanned first. - * The user has a chance to override it with an option. - */ -#include -#endif - -#ifndef YY_EXTRA_TYPE -#define YY_EXTRA_TYPE void * -#endif - -static int yy_init_globals ( void ); - -/* Accessor methods to globals. - These are made visible to non-reentrant scanners for convenience. */ - -int yylex_destroy ( void ); - -int yyget_debug ( void ); - -void yyset_debug ( int debug_flag ); - -YY_EXTRA_TYPE yyget_extra ( void ); - -void yyset_extra ( YY_EXTRA_TYPE user_defined ); - -FILE *yyget_in ( void ); - -void yyset_in ( FILE * _in_str ); - -FILE *yyget_out ( void ); - -void yyset_out ( FILE * _out_str ); - - int yyget_leng ( void ); - -char *yyget_text ( void ); - -int yyget_lineno ( void ); - -void yyset_lineno ( int _line_number ); - -/* Macros after this point can all be overridden by user definitions in - * section 1. - */ - -#ifndef YY_SKIP_YYWRAP -#ifdef __cplusplus -extern "C" int yywrap ( void ); -#else -extern int yywrap ( void ); -#endif -#endif - -#ifndef YY_NO_UNPUT - -#endif - -#ifndef yytext_ptr -static void yy_flex_strncpy ( char *, const char *, int ); -#endif - -#ifdef YY_NEED_STRLEN -static int yy_flex_strlen ( const char * ); -#endif - -#ifndef YY_NO_INPUT -#ifdef __cplusplus -static int yyinput ( void ); -#else -static int input ( void ); -#endif - -#endif - -/* Amount of stuff to slurp up with each read. */ -#ifndef YY_READ_BUF_SIZE -#ifdef __ia64__ -/* On IA-64, the buffer size is 16k, not 8k */ -#define YY_READ_BUF_SIZE 16384 -#else -#define YY_READ_BUF_SIZE 8192 -#endif /* __ia64__ */ -#endif - -/* Copy whatever the last rule matched to the standard output. */ -#ifndef ECHO -/* This used to be an fputs(), but since the string might contain NUL's, - * we now use fwrite(). - */ -#define ECHO do { if (fwrite( yytext, (size_t) yyleng, 1, yyout )) {} } while (0) -#endif - -/* Gets input and stuffs it into "buf". number of characters read, or YY_NULL, - * is returned in "result". - */ -#ifndef YY_INPUT -#define YY_INPUT(buf,result,max_size) \ - if ( YY_CURRENT_BUFFER_LVALUE->yy_is_interactive ) \ - { \ - int c = '*'; \ - int n; \ - for ( n = 0; n < max_size && \ - (c = getc( yyin )) != EOF && c != '\n'; ++n ) \ - buf[n] = (char) c; \ - if ( c == '\n' ) \ - buf[n++] = (char) c; \ - if ( c == EOF && ferror( yyin ) ) \ - YY_FATAL_ERROR( "input in flex scanner failed" ); \ - result = n; \ - } \ - else \ - { \ - errno=0; \ - while ( (result = (int) fread(buf, 1, (yy_size_t) max_size, yyin)) == 0 && ferror(yyin)) \ - { \ - if( errno != EINTR) \ - { \ - YY_FATAL_ERROR( "input in flex scanner failed" ); \ - break; \ - } \ - errno=0; \ - clearerr(yyin); \ - } \ - }\ -\ - -#endif - -/* No semi-colon after return; correct usage is to write "yyterminate();" - - * we don't want an extra ';' after the "return" because that will cause - * some compilers to complain about unreachable statements. - */ -#ifndef yyterminate -#define yyterminate() return YY_NULL -#endif - -/* Number of entries by which start-condition stack grows. */ -#ifndef YY_START_STACK_INCR -#define YY_START_STACK_INCR 25 -#endif - -/* Report a fatal error. */ -#ifndef YY_FATAL_ERROR -#define YY_FATAL_ERROR(msg) yy_fatal_error( msg ) -#endif - -/* end tables serialization structures and prototypes */ - -/* Default declaration of generated scanner - a define so the user can - * easily add parameters. - */ -#ifndef YY_DECL -#define YY_DECL_IS_OURS 1 - -extern int yylex (void); - -#define YY_DECL int yylex (void) -#endif /* !YY_DECL */ - -/* Code executed at the beginning of each rule, after yytext and yyleng - * have been set up. - */ -#ifndef YY_USER_ACTION -#define YY_USER_ACTION -#endif - -/* Code executed at the end of each rule. */ -#ifndef YY_BREAK -#define YY_BREAK /*LINTED*/break; -#endif - -#define YY_RULE_SETUP \ - YY_USER_ACTION - -/** The main scanner function which does all the work. - */ -YY_DECL -{ - yy_state_type yy_current_state; - char *yy_cp, *yy_bp; - int yy_act; - - if ( !(yy_init) ) - { - (yy_init) = 1; - -#ifdef YY_USER_INIT - YY_USER_INIT; -#endif - - if ( ! (yy_start) ) - (yy_start) = 1; /* first start state */ - - if ( ! yyin ) - yyin = stdin; - - if ( ! yyout ) - yyout = stdout; - - if ( ! YY_CURRENT_BUFFER ) { - yyensure_buffer_stack (); - YY_CURRENT_BUFFER_LVALUE = - yy_create_buffer( yyin, YY_BUF_SIZE ); - } - - yy_load_buffer_state( ); - } - - { - - while ( /*CONSTCOND*/1 ) /* loops until end-of-file is reached */ - { - yy_cp = (yy_c_buf_p); - - /* Support of yytext. */ - *yy_cp = (yy_hold_char); - - /* yy_bp points to the position in yy_ch_buf of the start of - * the current run. - */ - yy_bp = yy_cp; - - yy_current_state = (yy_start); -yy_match: - do - { - YY_CHAR yy_c = yy_ec[YY_SC_TO_UI(*yy_cp)] ; - if ( yy_accept[yy_current_state] ) - { - (yy_last_accepting_state) = yy_current_state; - (yy_last_accepting_cpos) = yy_cp; - } - while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state ) - { - yy_current_state = (int) yy_def[yy_current_state]; - if ( yy_current_state >= 108 ) - yy_c = yy_meta[yy_c]; - } - yy_current_state = yy_nxt[yy_base[yy_current_state] + yy_c]; - ++yy_cp; - } - while ( yy_current_state != 107 ); - yy_cp = (yy_last_accepting_cpos); - yy_current_state = (yy_last_accepting_state); - -yy_find_action: - yy_act = yy_accept[yy_current_state]; - - YY_DO_BEFORE_ACTION; - -do_action: /* This label is used only to access EOF actions. */ - - switch ( yy_act ) - { /* beginning of action switch */ - case 0: /* must back up */ - /* undo the effects of YY_DO_BEFORE_ACTION */ - *yy_cp = (yy_hold_char); - yy_cp = (yy_last_accepting_cpos); - yy_current_state = (yy_last_accepting_state); - goto yy_find_action; - -case 1: -case 2: -case 3: -case 4: -case 5: -case 6: -case 7: -case 8: -case 9: -case 10: -case 11: -YY_RULE_SETUP -{ return wxparsertext[0]; } /* simply pass through */ - YY_BREAK -/* wxparserlval is union type defined in wp_parser.tab.h that is generated - * by bison with wp_parser.y */ -case 12: -YY_RULE_SETUP -{ wxparserlval.f1 = WP_SQRT; return F1; } - YY_BREAK -case 13: -YY_RULE_SETUP -{ wxparserlval.f1 = WP_EXP; return F1; } - YY_BREAK -case 14: -YY_RULE_SETUP -{ wxparserlval.f1 = WP_LOG; return F1; } - YY_BREAK -case 15: -YY_RULE_SETUP -{ wxparserlval.f1 = WP_LOG10; return F1; } - YY_BREAK -case 16: -YY_RULE_SETUP -{ wxparserlval.f1 = WP_SIN; return F1; } - YY_BREAK -case 17: -YY_RULE_SETUP -{ wxparserlval.f1 = WP_COS; return F1; } - YY_BREAK -case 18: -YY_RULE_SETUP -{ wxparserlval.f1 = WP_TAN; return F1; } - YY_BREAK -case 19: -YY_RULE_SETUP -{ wxparserlval.f1 = WP_ASIN; return F1; } - YY_BREAK -case 20: -YY_RULE_SETUP -{ wxparserlval.f1 = WP_ACOS; return F1; } - YY_BREAK -case 21: -YY_RULE_SETUP -{ wxparserlval.f1 = WP_ATAN; return F1; } - YY_BREAK -case 22: -YY_RULE_SETUP -{ wxparserlval.f1 = WP_SINH; return F1; } - YY_BREAK -case 23: -YY_RULE_SETUP -{ wxparserlval.f1 = WP_COSH; return F1; } - YY_BREAK -case 24: -YY_RULE_SETUP -{ wxparserlval.f1 = WP_TANH; return F1; } - YY_BREAK -case 25: -YY_RULE_SETUP -{ wxparserlval.f1 = WP_ABS; return F1; } - YY_BREAK -case 26: -YY_RULE_SETUP -{ wxparserlval.f1 = WP_ABS; return F1; } - YY_BREAK -case 27: -YY_RULE_SETUP -{ wxparserlval.f2 = WP_POW; return POW;} - YY_BREAK -case 28: -YY_RULE_SETUP -{ wxparserlval.f2 = WP_POW; return POW;} - YY_BREAK -case 29: -YY_RULE_SETUP -{ wxparserlval.f2 = WP_GEQ; return GEQ;} - YY_BREAK -case 30: -YY_RULE_SETUP -{ wxparserlval.f2 = WP_LEQ; return LEQ;} - YY_BREAK -case 31: -YY_RULE_SETUP -{ wxparserlval.f2 = WP_EQ; return EQ;} - YY_BREAK -case 32: -YY_RULE_SETUP -{ wxparserlval.f2 = WP_NEQ; return NEQ;} - YY_BREAK -case 33: -YY_RULE_SETUP -{ wxparserlval.f2 = WP_AND; return AND;} - YY_BREAK -case 34: -YY_RULE_SETUP -{ wxparserlval.f2 = WP_OR; return OR;} - YY_BREAK -case 35: -YY_RULE_SETUP -{ wxparserlval.f2 = WP_POW; return F2; } - YY_BREAK -case 36: -YY_RULE_SETUP -{ wxparserlval.f2 = WP_HEAVISIDE; return F2; } - YY_BREAK -case 37: -YY_RULE_SETUP -{ wxparserlval.f2 = WP_JN; return F2; } - YY_BREAK -case 38: -YY_RULE_SETUP -{ wxparserlval.f2 = WP_MIN; return F2; } - YY_BREAK -case 39: -YY_RULE_SETUP -{ wxparserlval.f2 = WP_MAX; return F2; } - YY_BREAK -case 40: -YY_RULE_SETUP -{ wxparserlval.f3 = WP_IF; return F3; } - YY_BREAK -/* We use SYMBOL to hold variables and constants */ -case 41: -YY_RULE_SETUP -{ wxparserlval.s = wp_makesymbol(wxparsertext); return SYMBOL; } - YY_BREAK -/* Number */ -case 42: -case 43: -YY_RULE_SETUP -{ wxparserlval.d = atof(wxparsertext); return NUMBER; } - YY_BREAK -/* Special characters */ -case 44: -YY_RULE_SETUP - - YY_BREAK -case 45: -YY_RULE_SETUP -/* ignore white space */ - YY_BREAK -case 46: -/* rule 46 can match eol */ -YY_RULE_SETUP -/* ignore line continuation */ - YY_BREAK -case 47: -/* rule 47 can match eol */ -YY_RULE_SETUP -{ return EOL; } - YY_BREAK -/* everything else */ -case 48: -YY_RULE_SETUP -{ wxparsererror("Unknown character %c\n", *wxparsertext); } - YY_BREAK -case 49: -YY_RULE_SETUP -YY_FATAL_ERROR( "flex scanner jammed" ); - YY_BREAK -case YY_STATE_EOF(INITIAL): - yyterminate(); - - case YY_END_OF_BUFFER: - { - /* Amount of text matched not including the EOB char. */ - int yy_amount_of_matched_text = (int) (yy_cp - (yytext_ptr)) - 1; - - /* Undo the effects of YY_DO_BEFORE_ACTION. */ - *yy_cp = (yy_hold_char); - YY_RESTORE_YY_MORE_OFFSET - - if ( YY_CURRENT_BUFFER_LVALUE->yy_buffer_status == YY_BUFFER_NEW ) - { - /* We're scanning a new file or input source. It's - * possible that this happened because the user - * just pointed yyin at a new source and called - * yylex(). If so, then we have to assure - * consistency between YY_CURRENT_BUFFER and our - * globals. Here is the right place to do so, because - * this is the first action (other than possibly a - * back-up) that will match for the new input source. - */ - (yy_n_chars) = YY_CURRENT_BUFFER_LVALUE->yy_n_chars; - YY_CURRENT_BUFFER_LVALUE->yy_input_file = yyin; - YY_CURRENT_BUFFER_LVALUE->yy_buffer_status = YY_BUFFER_NORMAL; - } - - /* Note that here we test for yy_c_buf_p "<=" to the position - * of the first EOB in the buffer, since yy_c_buf_p will - * already have been incremented past the NUL character - * (since all states make transitions on EOB to the - * end-of-buffer state). Contrast this with the test - * in input(). - */ - if ( (yy_c_buf_p) <= &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars)] ) - { /* This was really a NUL. */ - yy_state_type yy_next_state; - - (yy_c_buf_p) = (yytext_ptr) + yy_amount_of_matched_text; - - yy_current_state = yy_get_previous_state( ); - - /* Okay, we're now positioned to make the NUL - * transition. We couldn't have - * yy_get_previous_state() go ahead and do it - * for us because it doesn't know how to deal - * with the possibility of jamming (and we don't - * want to build jamming into it because then it - * will run more slowly). - */ - - yy_next_state = yy_try_NUL_trans( yy_current_state ); - - yy_bp = (yytext_ptr) + YY_MORE_ADJ; - - if ( yy_next_state ) - { - /* Consume the NUL. */ - yy_cp = ++(yy_c_buf_p); - yy_current_state = yy_next_state; - goto yy_match; - } - - else - { - yy_cp = (yy_last_accepting_cpos); - yy_current_state = (yy_last_accepting_state); - goto yy_find_action; - } - } - - else switch ( yy_get_next_buffer( ) ) - { - case EOB_ACT_END_OF_FILE: - { - (yy_did_buffer_switch_on_eof) = 0; - - if ( yywrap( ) ) - { - /* Note: because we've taken care in - * yy_get_next_buffer() to have set up - * yytext, we can now set up - * yy_c_buf_p so that if some total - * hoser (like flex itself) wants to - * call the scanner after we return the - * YY_NULL, it'll still work - another - * YY_NULL will get returned. - */ - (yy_c_buf_p) = (yytext_ptr) + YY_MORE_ADJ; - - yy_act = YY_STATE_EOF(YY_START); - goto do_action; - } - - else - { - if ( ! (yy_did_buffer_switch_on_eof) ) - YY_NEW_FILE; - } - break; - } - - case EOB_ACT_CONTINUE_SCAN: - (yy_c_buf_p) = - (yytext_ptr) + yy_amount_of_matched_text; - - yy_current_state = yy_get_previous_state( ); - - yy_cp = (yy_c_buf_p); - yy_bp = (yytext_ptr) + YY_MORE_ADJ; - goto yy_match; - - case EOB_ACT_LAST_MATCH: - (yy_c_buf_p) = - &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars)]; - - yy_current_state = yy_get_previous_state( ); - - yy_cp = (yy_c_buf_p); - yy_bp = (yytext_ptr) + YY_MORE_ADJ; - goto yy_find_action; - } - break; - } - - default: - YY_FATAL_ERROR( - "fatal flex scanner internal error--no action found" ); - } /* end of action switch */ - } /* end of scanning one token */ - } /* end of user's declarations */ -} /* end of yylex */ - -/* yy_get_next_buffer - try to read in a new buffer - * - * Returns a code representing an action: - * EOB_ACT_LAST_MATCH - - * EOB_ACT_CONTINUE_SCAN - continue scanning from current position - * EOB_ACT_END_OF_FILE - end of file - */ -static int yy_get_next_buffer (void) -{ - char *dest = YY_CURRENT_BUFFER_LVALUE->yy_ch_buf; - char *source = (yytext_ptr); - int number_to_move, i; - int ret_val; - - if ( (yy_c_buf_p) > &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars) + 1] ) - YY_FATAL_ERROR( - "fatal flex scanner internal error--end of buffer missed" ); - - if ( YY_CURRENT_BUFFER_LVALUE->yy_fill_buffer == 0 ) - { /* Don't try to fill the buffer, so this is an EOF. */ - if ( (yy_c_buf_p) - (yytext_ptr) - YY_MORE_ADJ == 1 ) - { - /* We matched a single character, the EOB, so - * treat this as a final EOF. - */ - return EOB_ACT_END_OF_FILE; - } - - else - { - /* We matched some text prior to the EOB, first - * process it. - */ - return EOB_ACT_LAST_MATCH; - } - } - - /* Try to read more data. */ - - /* First move last chars to start of buffer. */ - number_to_move = (int) ((yy_c_buf_p) - (yytext_ptr) - 1); - - for ( i = 0; i < number_to_move; ++i ) - *(dest++) = *(source++); - - if ( YY_CURRENT_BUFFER_LVALUE->yy_buffer_status == YY_BUFFER_EOF_PENDING ) - /* don't do the read, it's not guaranteed to return an EOF, - * just force an EOF - */ - YY_CURRENT_BUFFER_LVALUE->yy_n_chars = (yy_n_chars) = 0; - - else - { - int num_to_read = - YY_CURRENT_BUFFER_LVALUE->yy_buf_size - number_to_move - 1; - - while ( num_to_read <= 0 ) - { /* Not enough room in the buffer - grow it. */ - - /* just a shorter name for the current buffer */ - YY_BUFFER_STATE b = YY_CURRENT_BUFFER_LVALUE; - - int yy_c_buf_p_offset = - (int) ((yy_c_buf_p) - b->yy_ch_buf); - - if ( b->yy_is_our_buffer ) - { - int new_size = b->yy_buf_size * 2; - - if ( new_size <= 0 ) - b->yy_buf_size += b->yy_buf_size / 8; - else - b->yy_buf_size *= 2; - - b->yy_ch_buf = (char *) - /* Include room in for 2 EOB chars. */ - yyrealloc( (void *) b->yy_ch_buf, - (yy_size_t) (b->yy_buf_size + 2) ); - } - else - /* Can't grow it, we don't own it. */ - b->yy_ch_buf = NULL; - - if ( ! b->yy_ch_buf ) - YY_FATAL_ERROR( - "fatal error - scanner input buffer overflow" ); - - (yy_c_buf_p) = &b->yy_ch_buf[yy_c_buf_p_offset]; - - num_to_read = YY_CURRENT_BUFFER_LVALUE->yy_buf_size - - number_to_move - 1; - - } - - if ( num_to_read > YY_READ_BUF_SIZE ) - num_to_read = YY_READ_BUF_SIZE; - - /* Read in more data. */ - YY_INPUT( (&YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[number_to_move]), - (yy_n_chars), num_to_read ); - - YY_CURRENT_BUFFER_LVALUE->yy_n_chars = (yy_n_chars); - } - - if ( (yy_n_chars) == 0 ) - { - if ( number_to_move == YY_MORE_ADJ ) - { - ret_val = EOB_ACT_END_OF_FILE; - yyrestart( yyin ); - } - - else - { - ret_val = EOB_ACT_LAST_MATCH; - YY_CURRENT_BUFFER_LVALUE->yy_buffer_status = - YY_BUFFER_EOF_PENDING; - } - } - - else - ret_val = EOB_ACT_CONTINUE_SCAN; - - if (((yy_n_chars) + number_to_move) > YY_CURRENT_BUFFER_LVALUE->yy_buf_size) { - /* Extend the array by 50%, plus the number we really need. */ - int new_size = (yy_n_chars) + number_to_move + ((yy_n_chars) >> 1); - YY_CURRENT_BUFFER_LVALUE->yy_ch_buf = (char *) yyrealloc( - (void *) YY_CURRENT_BUFFER_LVALUE->yy_ch_buf, (yy_size_t) new_size ); - if ( ! YY_CURRENT_BUFFER_LVALUE->yy_ch_buf ) - YY_FATAL_ERROR( "out of dynamic memory in yy_get_next_buffer()" ); - /* "- 2" to take care of EOB's */ - YY_CURRENT_BUFFER_LVALUE->yy_buf_size = (int) (new_size - 2); - } - - (yy_n_chars) += number_to_move; - YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars)] = YY_END_OF_BUFFER_CHAR; - YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars) + 1] = YY_END_OF_BUFFER_CHAR; - - (yytext_ptr) = &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[0]; - - return ret_val; -} - -/* yy_get_previous_state - get the state just before the EOB char was reached */ - - static yy_state_type yy_get_previous_state (void) -{ - yy_state_type yy_current_state; - char *yy_cp; - - yy_current_state = (yy_start); - - for ( yy_cp = (yytext_ptr) + YY_MORE_ADJ; yy_cp < (yy_c_buf_p); ++yy_cp ) - { - YY_CHAR yy_c = (*yy_cp ? yy_ec[YY_SC_TO_UI(*yy_cp)] : 1); - if ( yy_accept[yy_current_state] ) - { - (yy_last_accepting_state) = yy_current_state; - (yy_last_accepting_cpos) = yy_cp; - } - while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state ) - { - yy_current_state = (int) yy_def[yy_current_state]; - if ( yy_current_state >= 108 ) - yy_c = yy_meta[yy_c]; - } - yy_current_state = yy_nxt[yy_base[yy_current_state] + yy_c]; - } - - return yy_current_state; -} - -/* yy_try_NUL_trans - try to make a transition on the NUL character - * - * synopsis - * next_state = yy_try_NUL_trans( current_state ); - */ - static yy_state_type yy_try_NUL_trans (yy_state_type yy_current_state ) -{ - int yy_is_jam; - char *yy_cp = (yy_c_buf_p); - - YY_CHAR yy_c = 1; - if ( yy_accept[yy_current_state] ) - { - (yy_last_accepting_state) = yy_current_state; - (yy_last_accepting_cpos) = yy_cp; - } - while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state ) - { - yy_current_state = (int) yy_def[yy_current_state]; - if ( yy_current_state >= 108 ) - yy_c = yy_meta[yy_c]; - } - yy_current_state = yy_nxt[yy_base[yy_current_state] + yy_c]; - yy_is_jam = (yy_current_state == 107); - - return yy_is_jam ? 0 : yy_current_state; -} - -#ifndef YY_NO_UNPUT - -#endif - -#ifndef YY_NO_INPUT -#ifdef __cplusplus - static int yyinput (void) -#else - static int input (void) -#endif - -{ - int c; - - *(yy_c_buf_p) = (yy_hold_char); - - if ( *(yy_c_buf_p) == YY_END_OF_BUFFER_CHAR ) - { - /* yy_c_buf_p now points to the character we want to return. - * If this occurs *before* the EOB characters, then it's a - * valid NUL; if not, then we've hit the end of the buffer. - */ - if ( (yy_c_buf_p) < &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars)] ) - /* This was really a NUL. */ - *(yy_c_buf_p) = '\0'; - - else - { /* need more input */ - int offset = (int) ((yy_c_buf_p) - (yytext_ptr)); - ++(yy_c_buf_p); - - switch ( yy_get_next_buffer( ) ) - { - case EOB_ACT_LAST_MATCH: - /* This happens because yy_g_n_b() - * sees that we've accumulated a - * token and flags that we need to - * try matching the token before - * proceeding. But for input(), - * there's no matching to consider. - * So convert the EOB_ACT_LAST_MATCH - * to EOB_ACT_END_OF_FILE. - */ - - /* Reset buffer status. */ - yyrestart( yyin ); - - /*FALLTHROUGH*/ - - case EOB_ACT_END_OF_FILE: - { - if ( yywrap( ) ) - return 0; - - if ( ! (yy_did_buffer_switch_on_eof) ) - YY_NEW_FILE; -#ifdef __cplusplus - return yyinput(); -#else - return input(); -#endif - } - - case EOB_ACT_CONTINUE_SCAN: - (yy_c_buf_p) = (yytext_ptr) + offset; - break; - } - } - } - - c = *(unsigned char *) (yy_c_buf_p); /* cast for 8-bit char's */ - *(yy_c_buf_p) = '\0'; /* preserve yytext */ - (yy_hold_char) = *++(yy_c_buf_p); - - return c; -} -#endif /* ifndef YY_NO_INPUT */ - -/** Immediately switch to a different input stream. - * @param input_file A readable stream. - * - * @note This function does not reset the start condition to @c INITIAL . - */ - void yyrestart (FILE * input_file ) -{ - - if ( ! YY_CURRENT_BUFFER ){ - yyensure_buffer_stack (); - YY_CURRENT_BUFFER_LVALUE = - yy_create_buffer( yyin, YY_BUF_SIZE ); - } - - yy_init_buffer( YY_CURRENT_BUFFER, input_file ); - yy_load_buffer_state( ); -} - -/** Switch to a different input buffer. - * @param new_buffer The new input buffer. - * - */ - void yy_switch_to_buffer (YY_BUFFER_STATE new_buffer ) -{ - - /* TODO. We should be able to replace this entire function body - * with - * yypop_buffer_state(); - * yypush_buffer_state(new_buffer); - */ - yyensure_buffer_stack (); - if ( YY_CURRENT_BUFFER == new_buffer ) - return; - - if ( YY_CURRENT_BUFFER ) - { - /* Flush out information for old buffer. */ - *(yy_c_buf_p) = (yy_hold_char); - YY_CURRENT_BUFFER_LVALUE->yy_buf_pos = (yy_c_buf_p); - YY_CURRENT_BUFFER_LVALUE->yy_n_chars = (yy_n_chars); - } - - YY_CURRENT_BUFFER_LVALUE = new_buffer; - yy_load_buffer_state( ); - - /* We don't actually know whether we did this switch during - * EOF (yywrap()) processing, but the only time this flag - * is looked at is after yywrap() is called, so it's safe - * to go ahead and always set it. - */ - (yy_did_buffer_switch_on_eof) = 1; -} - -static void yy_load_buffer_state (void) -{ - (yy_n_chars) = YY_CURRENT_BUFFER_LVALUE->yy_n_chars; - (yytext_ptr) = (yy_c_buf_p) = YY_CURRENT_BUFFER_LVALUE->yy_buf_pos; - yyin = YY_CURRENT_BUFFER_LVALUE->yy_input_file; - (yy_hold_char) = *(yy_c_buf_p); -} - -/** Allocate and initialize an input buffer state. - * @param file A readable stream. - * @param size The character buffer size in bytes. When in doubt, use @c YY_BUF_SIZE. - * - * @return the allocated buffer state. - */ - YY_BUFFER_STATE yy_create_buffer (FILE * file, int size ) -{ - YY_BUFFER_STATE b; - - b = (YY_BUFFER_STATE) yyalloc( sizeof( struct yy_buffer_state ) ); - if ( ! b ) - YY_FATAL_ERROR( "out of dynamic memory in yy_create_buffer()" ); - - b->yy_buf_size = size; - - /* yy_ch_buf has to be 2 characters longer than the size given because - * we need to put in 2 end-of-buffer characters. - */ - b->yy_ch_buf = (char *) yyalloc( (yy_size_t) (b->yy_buf_size + 2) ); - if ( ! b->yy_ch_buf ) - YY_FATAL_ERROR( "out of dynamic memory in yy_create_buffer()" ); - - b->yy_is_our_buffer = 1; - - yy_init_buffer( b, file ); - - return b; -} - -/** Destroy the buffer. - * @param b a buffer created with yy_create_buffer() - * - */ - void yy_delete_buffer (YY_BUFFER_STATE b ) -{ - - if ( ! b ) - return; - - if ( b == YY_CURRENT_BUFFER ) /* Not sure if we should pop here. */ - YY_CURRENT_BUFFER_LVALUE = (YY_BUFFER_STATE) 0; - - if ( b->yy_is_our_buffer ) - yyfree( (void *) b->yy_ch_buf ); - - yyfree( (void *) b ); -} - -/* Initializes or reinitializes a buffer. - * This function is sometimes called more than once on the same buffer, - * such as during a yyrestart() or at EOF. - */ - static void yy_init_buffer (YY_BUFFER_STATE b, FILE * file ) - -{ - int oerrno = errno; - - yy_flush_buffer( b ); - - b->yy_input_file = file; - b->yy_fill_buffer = 1; - - /* If b is the current buffer, then yy_init_buffer was _probably_ - * called from yyrestart() or through yy_get_next_buffer. - * In that case, we don't want to reset the lineno or column. - */ - if (b != YY_CURRENT_BUFFER){ - b->yy_bs_lineno = 1; - b->yy_bs_column = 0; - } - - b->yy_is_interactive = 0; - - errno = oerrno; -} - -/** Discard all buffered characters. On the next scan, YY_INPUT will be called. - * @param b the buffer state to be flushed, usually @c YY_CURRENT_BUFFER. - * - */ - void yy_flush_buffer (YY_BUFFER_STATE b ) -{ - if ( ! b ) - return; - - b->yy_n_chars = 0; - - /* We always need two end-of-buffer characters. The first causes - * a transition to the end-of-buffer state. The second causes - * a jam in that state. - */ - b->yy_ch_buf[0] = YY_END_OF_BUFFER_CHAR; - b->yy_ch_buf[1] = YY_END_OF_BUFFER_CHAR; - - b->yy_buf_pos = &b->yy_ch_buf[0]; - - b->yy_at_bol = 1; - b->yy_buffer_status = YY_BUFFER_NEW; - - if ( b == YY_CURRENT_BUFFER ) - yy_load_buffer_state( ); -} - -/** Pushes the new state onto the stack. The new state becomes - * the current state. This function will allocate the stack - * if necessary. - * @param new_buffer The new state. - * - */ -void yypush_buffer_state (YY_BUFFER_STATE new_buffer ) -{ - if (new_buffer == NULL) - return; - - yyensure_buffer_stack(); - - /* This block is copied from yy_switch_to_buffer. */ - if ( YY_CURRENT_BUFFER ) - { - /* Flush out information for old buffer. */ - *(yy_c_buf_p) = (yy_hold_char); - YY_CURRENT_BUFFER_LVALUE->yy_buf_pos = (yy_c_buf_p); - YY_CURRENT_BUFFER_LVALUE->yy_n_chars = (yy_n_chars); - } - - /* Only push if top exists. Otherwise, replace top. */ - if (YY_CURRENT_BUFFER) - (yy_buffer_stack_top)++; - YY_CURRENT_BUFFER_LVALUE = new_buffer; - - /* copied from yy_switch_to_buffer. */ - yy_load_buffer_state( ); - (yy_did_buffer_switch_on_eof) = 1; -} - -/** Removes and deletes the top of the stack, if present. - * The next element becomes the new top. - * - */ -void yypop_buffer_state (void) -{ - if (!YY_CURRENT_BUFFER) - return; - - yy_delete_buffer(YY_CURRENT_BUFFER ); - YY_CURRENT_BUFFER_LVALUE = NULL; - if ((yy_buffer_stack_top) > 0) - --(yy_buffer_stack_top); - - if (YY_CURRENT_BUFFER) { - yy_load_buffer_state( ); - (yy_did_buffer_switch_on_eof) = 1; - } -} - -/* Allocates the stack if it does not exist. - * Guarantees space for at least one push. - */ -static void yyensure_buffer_stack (void) -{ - yy_size_t num_to_alloc; - - if (!(yy_buffer_stack)) { - - /* First allocation is just for 2 elements, since we don't know if this - * scanner will even need a stack. We use 2 instead of 1 to avoid an - * immediate realloc on the next call. - */ - num_to_alloc = 1; /* After all that talk, this was set to 1 anyways... */ - (yy_buffer_stack) = (struct yy_buffer_state**)yyalloc - (num_to_alloc * sizeof(struct yy_buffer_state*) - ); - if ( ! (yy_buffer_stack) ) - YY_FATAL_ERROR( "out of dynamic memory in yyensure_buffer_stack()" ); - - memset((yy_buffer_stack), 0, num_to_alloc * sizeof(struct yy_buffer_state*)); - - (yy_buffer_stack_max) = num_to_alloc; - (yy_buffer_stack_top) = 0; - return; - } - - if ((yy_buffer_stack_top) >= ((yy_buffer_stack_max)) - 1){ - - /* Increase the buffer to prepare for a possible push. */ - yy_size_t grow_size = 8 /* arbitrary grow size */; - - num_to_alloc = (yy_buffer_stack_max) + grow_size; - (yy_buffer_stack) = (struct yy_buffer_state**)yyrealloc - ((yy_buffer_stack), - num_to_alloc * sizeof(struct yy_buffer_state*) - ); - if ( ! (yy_buffer_stack) ) - YY_FATAL_ERROR( "out of dynamic memory in yyensure_buffer_stack()" ); - - /* zero only the new slots.*/ - memset((yy_buffer_stack) + (yy_buffer_stack_max), 0, grow_size * sizeof(struct yy_buffer_state*)); - (yy_buffer_stack_max) = num_to_alloc; - } -} - -/** Setup the input buffer state to scan directly from a user-specified character buffer. - * @param base the character buffer - * @param size the size in bytes of the character buffer - * - * @return the newly allocated buffer state object. - */ -YY_BUFFER_STATE yy_scan_buffer (char * base, yy_size_t size ) -{ - YY_BUFFER_STATE b; - - if ( size < 2 || - base[size-2] != YY_END_OF_BUFFER_CHAR || - base[size-1] != YY_END_OF_BUFFER_CHAR ) - /* They forgot to leave room for the EOB's. */ - return NULL; - - b = (YY_BUFFER_STATE) yyalloc( sizeof( struct yy_buffer_state ) ); - if ( ! b ) - YY_FATAL_ERROR( "out of dynamic memory in yy_scan_buffer()" ); - - b->yy_buf_size = (int) (size - 2); /* "- 2" to take care of EOB's */ - b->yy_buf_pos = b->yy_ch_buf = base; - b->yy_is_our_buffer = 0; - b->yy_input_file = NULL; - b->yy_n_chars = b->yy_buf_size; - b->yy_is_interactive = 0; - b->yy_at_bol = 1; - b->yy_fill_buffer = 0; - b->yy_buffer_status = YY_BUFFER_NEW; - - yy_switch_to_buffer( b ); - - return b; -} - -/** Setup the input buffer state to scan a string. The next call to yylex() will - * scan from a @e copy of @a str. - * @param yystr a NUL-terminated string to scan - * - * @return the newly allocated buffer state object. - * @note If you want to scan bytes that may contain NUL values, then use - * yy_scan_bytes() instead. - */ -YY_BUFFER_STATE yy_scan_string (const char * yystr ) -{ - - return yy_scan_bytes( yystr, (int) strlen(yystr) ); -} - -/** Setup the input buffer state to scan the given bytes. The next call to yylex() will - * scan from a @e copy of @a bytes. - * @param yybytes the byte buffer to scan - * @param _yybytes_len the number of bytes in the buffer pointed to by @a bytes. - * - * @return the newly allocated buffer state object. - */ -YY_BUFFER_STATE yy_scan_bytes (const char * yybytes, int _yybytes_len ) -{ - YY_BUFFER_STATE b; - char *buf; - yy_size_t n; - int i; - - /* Get memory for full buffer, including space for trailing EOB's. */ - n = (yy_size_t) (_yybytes_len + 2); - buf = (char *) yyalloc( n ); - if ( ! buf ) - YY_FATAL_ERROR( "out of dynamic memory in yy_scan_bytes()" ); - - for ( i = 0; i < _yybytes_len; ++i ) - buf[i] = yybytes[i]; - - buf[_yybytes_len] = buf[_yybytes_len+1] = YY_END_OF_BUFFER_CHAR; - - b = yy_scan_buffer( buf, n ); - if ( ! b ) - YY_FATAL_ERROR( "bad buffer in yy_scan_bytes()" ); - - /* It's okay to grow etc. this buffer, and we should throw it - * away when we're done. - */ - b->yy_is_our_buffer = 1; - - return b; -} - -#ifndef YY_EXIT_FAILURE -#define YY_EXIT_FAILURE 2 -#endif - -static void yynoreturn yy_fatal_error (const char* msg ) -{ - fprintf( stderr, "%s\n", msg ); - exit( YY_EXIT_FAILURE ); -} - -/* Redefine yyless() so it works in section 3 code. */ - -#undef yyless -#define yyless(n) \ - do \ - { \ - /* Undo effects of setting up yytext. */ \ - int yyless_macro_arg = (n); \ - YY_LESS_LINENO(yyless_macro_arg);\ - yytext[yyleng] = (yy_hold_char); \ - (yy_c_buf_p) = yytext + yyless_macro_arg; \ - (yy_hold_char) = *(yy_c_buf_p); \ - *(yy_c_buf_p) = '\0'; \ - yyleng = yyless_macro_arg; \ - } \ - while ( 0 ) - -/* Accessor methods (get/set functions) to struct members. */ - -/** Get the current line number. - * - */ -int yyget_lineno (void) -{ - - return yylineno; -} - -/** Get the input stream. - * - */ -FILE *yyget_in (void) -{ - return yyin; -} - -/** Get the output stream. - * - */ -FILE *yyget_out (void) -{ - return yyout; -} - -/** Get the length of the current token. - * - */ -int yyget_leng (void) -{ - return yyleng; -} - -/** Get the current token. - * - */ - -char *yyget_text (void) -{ - return yytext; -} - -/** Set the current line number. - * @param _line_number line number - * - */ -void yyset_lineno (int _line_number ) -{ - - yylineno = _line_number; -} - -/** Set the input stream. This does not discard the current - * input buffer. - * @param _in_str A readable stream. - * - * @see yy_switch_to_buffer - */ -void yyset_in (FILE * _in_str ) -{ - yyin = _in_str ; -} - -void yyset_out (FILE * _out_str ) -{ - yyout = _out_str ; -} - -int yyget_debug (void) -{ - return yy_flex_debug; -} - -void yyset_debug (int _bdebug ) -{ - yy_flex_debug = _bdebug ; -} - -static int yy_init_globals (void) -{ - /* Initialization is the same as for the non-reentrant scanner. - * This function is called from yylex_destroy(), so don't allocate here. - */ - - (yy_buffer_stack) = NULL; - (yy_buffer_stack_top) = 0; - (yy_buffer_stack_max) = 0; - (yy_c_buf_p) = NULL; - (yy_init) = 0; - (yy_start) = 0; - -/* Defined in main.c */ -#ifdef YY_STDINIT - yyin = stdin; - yyout = stdout; -#else - yyin = NULL; - yyout = NULL; -#endif - - /* For future reference: Set errno on error, since we are called by - * yylex_init() - */ - return 0; -} - -/* yylex_destroy is for both reentrant and non-reentrant scanners. */ -int yylex_destroy (void) -{ - - /* Pop the buffer stack, destroying each element. */ - while(YY_CURRENT_BUFFER){ - yy_delete_buffer( YY_CURRENT_BUFFER ); - YY_CURRENT_BUFFER_LVALUE = NULL; - yypop_buffer_state(); - } - - /* Destroy the stack itself. */ - yyfree((yy_buffer_stack) ); - (yy_buffer_stack) = NULL; - - /* Reset the globals. This is important in a non-reentrant scanner so the next time - * yylex() is called, initialization will occur. */ - yy_init_globals( ); - - return 0; -} - -/* - * Internal utility routines. - */ - -#ifndef yytext_ptr -static void yy_flex_strncpy (char* s1, const char * s2, int n ) -{ - - int i; - for ( i = 0; i < n; ++i ) - s1[i] = s2[i]; -} -#endif - -#ifdef YY_NEED_STRLEN -static int yy_flex_strlen (const char * s ) -{ - int n; - for ( n = 0; s[n]; ++n ) - ; - - return n; -} -#endif - -void *yyalloc (yy_size_t size ) -{ - return malloc(size); -} - -void *yyrealloc (void * ptr, yy_size_t size ) -{ - - /* The cast to (char *) in the following accommodates both - * implementations that use char* generic pointers, and those - * that use void* generic pointers. It works with the latter - * because both ANSI C and C++ allow castless assignment from - * any pointer type to void*, and deal with argument conversions - * as though doing an assignment. - */ - return realloc(ptr, size); -} - -void yyfree (void * ptr ) -{ - free( (char *) ptr ); /* see yyrealloc() for (char *) cast */ -} - -#define YYTABLES_NAME "yytables" - diff --git a/Source/Parser/wp_parser.lex.h b/Source/Parser/wp_parser.lex.h deleted file mode 100644 index 31321f12f0e..00000000000 --- a/Source/Parser/wp_parser.lex.h +++ /dev/null @@ -1,703 +0,0 @@ -#ifndef wxparserHEADER_H -#define wxparserHEADER_H 1 -#define wxparserIN_HEADER 1 - -#define YY_INT_ALIGNED short int - -/* A lexical scanner generated by flex */ - -#define FLEX_SCANNER -#define YY_FLEX_MAJOR_VERSION 2 -#define YY_FLEX_MINOR_VERSION 6 -#define YY_FLEX_SUBMINOR_VERSION 4 -#if YY_FLEX_SUBMINOR_VERSION > 0 -#define FLEX_BETA -#endif - -#ifdef yy_create_buffer -#define wxparser_create_buffer_ALREADY_DEFINED -#else -#define yy_create_buffer wxparser_create_buffer -#endif - -#ifdef yy_delete_buffer -#define wxparser_delete_buffer_ALREADY_DEFINED -#else -#define yy_delete_buffer wxparser_delete_buffer -#endif - -#ifdef yy_scan_buffer -#define wxparser_scan_buffer_ALREADY_DEFINED -#else -#define yy_scan_buffer wxparser_scan_buffer -#endif - -#ifdef yy_scan_string -#define wxparser_scan_string_ALREADY_DEFINED -#else -#define yy_scan_string wxparser_scan_string -#endif - -#ifdef yy_scan_bytes -#define wxparser_scan_bytes_ALREADY_DEFINED -#else -#define yy_scan_bytes wxparser_scan_bytes -#endif - -#ifdef yy_init_buffer -#define wxparser_init_buffer_ALREADY_DEFINED -#else -#define yy_init_buffer wxparser_init_buffer -#endif - -#ifdef yy_flush_buffer -#define wxparser_flush_buffer_ALREADY_DEFINED -#else -#define yy_flush_buffer wxparser_flush_buffer -#endif - -#ifdef yy_load_buffer_state -#define wxparser_load_buffer_state_ALREADY_DEFINED -#else -#define yy_load_buffer_state wxparser_load_buffer_state -#endif - -#ifdef yy_switch_to_buffer -#define wxparser_switch_to_buffer_ALREADY_DEFINED -#else -#define yy_switch_to_buffer wxparser_switch_to_buffer -#endif - -#ifdef yypush_buffer_state -#define wxparserpush_buffer_state_ALREADY_DEFINED -#else -#define yypush_buffer_state wxparserpush_buffer_state -#endif - -#ifdef yypop_buffer_state -#define wxparserpop_buffer_state_ALREADY_DEFINED -#else -#define yypop_buffer_state wxparserpop_buffer_state -#endif - -#ifdef yyensure_buffer_stack -#define wxparserensure_buffer_stack_ALREADY_DEFINED -#else -#define yyensure_buffer_stack wxparserensure_buffer_stack -#endif - -#ifdef yylex -#define wxparserlex_ALREADY_DEFINED -#else -#define yylex wxparserlex -#endif - -#ifdef yyrestart -#define wxparserrestart_ALREADY_DEFINED -#else -#define yyrestart wxparserrestart -#endif - -#ifdef yylex_init -#define wxparserlex_init_ALREADY_DEFINED -#else -#define yylex_init wxparserlex_init -#endif - -#ifdef yylex_init_extra -#define wxparserlex_init_extra_ALREADY_DEFINED -#else -#define yylex_init_extra wxparserlex_init_extra -#endif - -#ifdef yylex_destroy -#define wxparserlex_destroy_ALREADY_DEFINED -#else -#define yylex_destroy wxparserlex_destroy -#endif - -#ifdef yyget_debug -#define wxparserget_debug_ALREADY_DEFINED -#else -#define yyget_debug wxparserget_debug -#endif - -#ifdef yyset_debug -#define wxparserset_debug_ALREADY_DEFINED -#else -#define yyset_debug wxparserset_debug -#endif - -#ifdef yyget_extra -#define wxparserget_extra_ALREADY_DEFINED -#else -#define yyget_extra wxparserget_extra -#endif - -#ifdef yyset_extra -#define wxparserset_extra_ALREADY_DEFINED -#else -#define yyset_extra wxparserset_extra -#endif - -#ifdef yyget_in -#define wxparserget_in_ALREADY_DEFINED -#else -#define yyget_in wxparserget_in -#endif - -#ifdef yyset_in -#define wxparserset_in_ALREADY_DEFINED -#else -#define yyset_in wxparserset_in -#endif - -#ifdef yyget_out -#define wxparserget_out_ALREADY_DEFINED -#else -#define yyget_out wxparserget_out -#endif - -#ifdef yyset_out -#define wxparserset_out_ALREADY_DEFINED -#else -#define yyset_out wxparserset_out -#endif - -#ifdef yyget_leng -#define wxparserget_leng_ALREADY_DEFINED -#else -#define yyget_leng wxparserget_leng -#endif - -#ifdef yyget_text -#define wxparserget_text_ALREADY_DEFINED -#else -#define yyget_text wxparserget_text -#endif - -#ifdef yyget_lineno -#define wxparserget_lineno_ALREADY_DEFINED -#else -#define yyget_lineno wxparserget_lineno -#endif - -#ifdef yyset_lineno -#define wxparserset_lineno_ALREADY_DEFINED -#else -#define yyset_lineno wxparserset_lineno -#endif - -#ifdef yywrap -#define wxparserwrap_ALREADY_DEFINED -#else -#define yywrap wxparserwrap -#endif - -#ifdef yyalloc -#define wxparseralloc_ALREADY_DEFINED -#else -#define yyalloc wxparseralloc -#endif - -#ifdef yyrealloc -#define wxparserrealloc_ALREADY_DEFINED -#else -#define yyrealloc wxparserrealloc -#endif - -#ifdef yyfree -#define wxparserfree_ALREADY_DEFINED -#else -#define yyfree wxparserfree -#endif - -#ifdef yytext -#define wxparsertext_ALREADY_DEFINED -#else -#define yytext wxparsertext -#endif - -#ifdef yyleng -#define wxparserleng_ALREADY_DEFINED -#else -#define yyleng wxparserleng -#endif - -#ifdef yyin -#define wxparserin_ALREADY_DEFINED -#else -#define yyin wxparserin -#endif - -#ifdef yyout -#define wxparserout_ALREADY_DEFINED -#else -#define yyout wxparserout -#endif - -#ifdef yy_flex_debug -#define wxparser_flex_debug_ALREADY_DEFINED -#else -#define yy_flex_debug wxparser_flex_debug -#endif - -#ifdef yylineno -#define wxparserlineno_ALREADY_DEFINED -#else -#define yylineno wxparserlineno -#endif - -/* First, we deal with platform-specific or compiler-specific issues. */ - -/* begin standard C headers. */ -#include -#include -#include -#include - -/* end standard C headers. */ - -/* flex integer type definitions */ - -#ifndef FLEXINT_H -#define FLEXINT_H - -/* C99 systems have . Non-C99 systems may or may not. */ - -#if defined (__STDC_VERSION__) && __STDC_VERSION__ >= 199901L - -/* C99 says to define __STDC_LIMIT_MACROS before including stdint.h, - * if you want the limit (max/min) macros for int types. - */ -#ifndef __STDC_LIMIT_MACROS -#define __STDC_LIMIT_MACROS 1 -#endif - -#include -typedef int8_t flex_int8_t; -typedef uint8_t flex_uint8_t; -typedef int16_t flex_int16_t; -typedef uint16_t flex_uint16_t; -typedef int32_t flex_int32_t; -typedef uint32_t flex_uint32_t; -#else -typedef signed char flex_int8_t; -typedef short int flex_int16_t; -typedef int flex_int32_t; -typedef unsigned char flex_uint8_t; -typedef unsigned short int flex_uint16_t; -typedef unsigned int flex_uint32_t; - -/* Limits of integral types. */ -#ifndef INT8_MIN -#define INT8_MIN (-128) -#endif -#ifndef INT16_MIN -#define INT16_MIN (-32767-1) -#endif -#ifndef INT32_MIN -#define INT32_MIN (-2147483647-1) -#endif -#ifndef INT8_MAX -#define INT8_MAX (127) -#endif -#ifndef INT16_MAX -#define INT16_MAX (32767) -#endif -#ifndef INT32_MAX -#define INT32_MAX (2147483647) -#endif -#ifndef UINT8_MAX -#define UINT8_MAX (255U) -#endif -#ifndef UINT16_MAX -#define UINT16_MAX (65535U) -#endif -#ifndef UINT32_MAX -#define UINT32_MAX (4294967295U) -#endif - -#ifndef SIZE_MAX -#define SIZE_MAX (~(size_t)0) -#endif - -#endif /* ! C99 */ - -#endif /* ! FLEXINT_H */ - -/* begin standard C++ headers. */ - -/* TODO: this is always defined, so inline it */ -#define yyconst const - -#if defined(__GNUC__) && __GNUC__ >= 3 -#define yynoreturn __attribute__((__noreturn__)) -#else -#define yynoreturn -#endif - -/* Size of default input buffer. */ -#ifndef YY_BUF_SIZE -#ifdef __ia64__ -/* On IA-64, the buffer size is 16k, not 8k. - * Moreover, YY_BUF_SIZE is 2*YY_READ_BUF_SIZE in the general case. - * Ditto for the __ia64__ case accordingly. - */ -#define YY_BUF_SIZE 32768 -#else -#define YY_BUF_SIZE 16384 -#endif /* __ia64__ */ -#endif - -#ifndef YY_TYPEDEF_YY_BUFFER_STATE -#define YY_TYPEDEF_YY_BUFFER_STATE -typedef struct yy_buffer_state *YY_BUFFER_STATE; -#endif - -#ifndef YY_TYPEDEF_YY_SIZE_T -#define YY_TYPEDEF_YY_SIZE_T -typedef size_t yy_size_t; -#endif - -extern int yyleng; - -extern FILE *yyin, *yyout; - -#ifndef YY_STRUCT_YY_BUFFER_STATE -#define YY_STRUCT_YY_BUFFER_STATE -struct yy_buffer_state - { - FILE *yy_input_file; - - char *yy_ch_buf; /* input buffer */ - char *yy_buf_pos; /* current position in input buffer */ - - /* Size of input buffer in bytes, not including room for EOB - * characters. - */ - int yy_buf_size; - - /* Number of characters read into yy_ch_buf, not including EOB - * characters. - */ - int yy_n_chars; - - /* Whether we "own" the buffer - i.e., we know we created it, - * and can realloc() it to grow it, and should free() it to - * delete it. - */ - int yy_is_our_buffer; - - /* Whether this is an "interactive" input source; if so, and - * if we're using stdio for input, then we want to use getc() - * instead of fread(), to make sure we stop fetching input after - * each newline. - */ - int yy_is_interactive; - - /* Whether we're considered to be at the beginning of a line. - * If so, '^' rules will be active on the next match, otherwise - * not. - */ - int yy_at_bol; - - int yy_bs_lineno; /**< The line count. */ - int yy_bs_column; /**< The column count. */ - - /* Whether to try to fill the input buffer when we reach the - * end of it. - */ - int yy_fill_buffer; - - int yy_buffer_status; - - }; -#endif /* !YY_STRUCT_YY_BUFFER_STATE */ - -void yyrestart ( FILE *input_file ); -void yy_switch_to_buffer ( YY_BUFFER_STATE new_buffer ); -YY_BUFFER_STATE yy_create_buffer ( FILE *file, int size ); -void yy_delete_buffer ( YY_BUFFER_STATE b ); -void yy_flush_buffer ( YY_BUFFER_STATE b ); -void yypush_buffer_state ( YY_BUFFER_STATE new_buffer ); -void yypop_buffer_state ( void ); - -YY_BUFFER_STATE yy_scan_buffer ( char *base, yy_size_t size ); -YY_BUFFER_STATE yy_scan_string ( const char *yy_str ); -YY_BUFFER_STATE yy_scan_bytes ( const char *bytes, int len ); - -void *yyalloc ( yy_size_t ); -void *yyrealloc ( void *, yy_size_t ); -void yyfree ( void * ); - -/* Begin user sect3 */ - -#define wxparserwrap() (/*CONSTCOND*/1) -#define YY_SKIP_YYWRAP - -extern int yylineno; - -extern char *yytext; -#ifdef yytext_ptr -#undef yytext_ptr -#endif -#define yytext_ptr yytext - -#ifdef YY_HEADER_EXPORT_START_CONDITIONS -#define INITIAL 0 - -#endif - -#ifndef YY_NO_UNISTD_H -/* Special case for "unistd.h", since it is non-ANSI. We include it way - * down here because we want the user's section 1 to have been scanned first. - * The user has a chance to override it with an option. - */ -#include -#endif - -#ifndef YY_EXTRA_TYPE -#define YY_EXTRA_TYPE void * -#endif - -/* Accessor methods to globals. - These are made visible to non-reentrant scanners for convenience. */ - -int yylex_destroy ( void ); - -int yyget_debug ( void ); - -void yyset_debug ( int debug_flag ); - -YY_EXTRA_TYPE yyget_extra ( void ); - -void yyset_extra ( YY_EXTRA_TYPE user_defined ); - -FILE *yyget_in ( void ); - -void yyset_in ( FILE * _in_str ); - -FILE *yyget_out ( void ); - -void yyset_out ( FILE * _out_str ); - - int yyget_leng ( void ); - -char *yyget_text ( void ); - -int yyget_lineno ( void ); - -void yyset_lineno ( int _line_number ); - -/* Macros after this point can all be overridden by user definitions in - * section 1. - */ - -#ifndef YY_SKIP_YYWRAP -#ifdef __cplusplus -extern "C" int yywrap ( void ); -#else -extern int yywrap ( void ); -#endif -#endif - -#ifndef yytext_ptr -static void yy_flex_strncpy ( char *, const char *, int ); -#endif - -#ifdef YY_NEED_STRLEN -static int yy_flex_strlen ( const char * ); -#endif - -#ifndef YY_NO_INPUT - -#endif - -/* Amount of stuff to slurp up with each read. */ -#ifndef YY_READ_BUF_SIZE -#ifdef __ia64__ -/* On IA-64, the buffer size is 16k, not 8k */ -#define YY_READ_BUF_SIZE 16384 -#else -#define YY_READ_BUF_SIZE 8192 -#endif /* __ia64__ */ -#endif - -/* Number of entries by which start-condition stack grows. */ -#ifndef YY_START_STACK_INCR -#define YY_START_STACK_INCR 25 -#endif - -/* Default declaration of generated scanner - a define so the user can - * easily add parameters. - */ -#ifndef YY_DECL -#define YY_DECL_IS_OURS 1 - -extern int yylex (void); - -#define YY_DECL int yylex (void) -#endif /* !YY_DECL */ - -/* yy_get_previous_state - get the state just before the EOB char was reached */ - -#undef YY_NEW_FILE -#undef YY_FLUSH_BUFFER -#undef yy_set_bol -#undef yy_new_buffer -#undef yy_set_interactive -#undef YY_DO_BEFORE_ACTION - -#ifdef YY_DECL_IS_OURS -#undef YY_DECL_IS_OURS -#undef YY_DECL -#endif - -#ifndef wxparser_create_buffer_ALREADY_DEFINED -#undef yy_create_buffer -#endif -#ifndef wxparser_delete_buffer_ALREADY_DEFINED -#undef yy_delete_buffer -#endif -#ifndef wxparser_scan_buffer_ALREADY_DEFINED -#undef yy_scan_buffer -#endif -#ifndef wxparser_scan_string_ALREADY_DEFINED -#undef yy_scan_string -#endif -#ifndef wxparser_scan_bytes_ALREADY_DEFINED -#undef yy_scan_bytes -#endif -#ifndef wxparser_init_buffer_ALREADY_DEFINED -#undef yy_init_buffer -#endif -#ifndef wxparser_flush_buffer_ALREADY_DEFINED -#undef yy_flush_buffer -#endif -#ifndef wxparser_load_buffer_state_ALREADY_DEFINED -#undef yy_load_buffer_state -#endif -#ifndef wxparser_switch_to_buffer_ALREADY_DEFINED -#undef yy_switch_to_buffer -#endif -#ifndef wxparserpush_buffer_state_ALREADY_DEFINED -#undef yypush_buffer_state -#endif -#ifndef wxparserpop_buffer_state_ALREADY_DEFINED -#undef yypop_buffer_state -#endif -#ifndef wxparserensure_buffer_stack_ALREADY_DEFINED -#undef yyensure_buffer_stack -#endif -#ifndef wxparserlex_ALREADY_DEFINED -#undef yylex -#endif -#ifndef wxparserrestart_ALREADY_DEFINED -#undef yyrestart -#endif -#ifndef wxparserlex_init_ALREADY_DEFINED -#undef yylex_init -#endif -#ifndef wxparserlex_init_extra_ALREADY_DEFINED -#undef yylex_init_extra -#endif -#ifndef wxparserlex_destroy_ALREADY_DEFINED -#undef yylex_destroy -#endif -#ifndef wxparserget_debug_ALREADY_DEFINED -#undef yyget_debug -#endif -#ifndef wxparserset_debug_ALREADY_DEFINED -#undef yyset_debug -#endif -#ifndef wxparserget_extra_ALREADY_DEFINED -#undef yyget_extra -#endif -#ifndef wxparserset_extra_ALREADY_DEFINED -#undef yyset_extra -#endif -#ifndef wxparserget_in_ALREADY_DEFINED -#undef yyget_in -#endif -#ifndef wxparserset_in_ALREADY_DEFINED -#undef yyset_in -#endif -#ifndef wxparserget_out_ALREADY_DEFINED -#undef yyget_out -#endif -#ifndef wxparserset_out_ALREADY_DEFINED -#undef yyset_out -#endif -#ifndef wxparserget_leng_ALREADY_DEFINED -#undef yyget_leng -#endif -#ifndef wxparserget_text_ALREADY_DEFINED -#undef yyget_text -#endif -#ifndef wxparserget_lineno_ALREADY_DEFINED -#undef yyget_lineno -#endif -#ifndef wxparserset_lineno_ALREADY_DEFINED -#undef yyset_lineno -#endif -#ifndef wxparserget_column_ALREADY_DEFINED -#undef yyget_column -#endif -#ifndef wxparserset_column_ALREADY_DEFINED -#undef yyset_column -#endif -#ifndef wxparserwrap_ALREADY_DEFINED -#undef yywrap -#endif -#ifndef wxparserget_lval_ALREADY_DEFINED -#undef yyget_lval -#endif -#ifndef wxparserset_lval_ALREADY_DEFINED -#undef yyset_lval -#endif -#ifndef wxparserget_lloc_ALREADY_DEFINED -#undef yyget_lloc -#endif -#ifndef wxparserset_lloc_ALREADY_DEFINED -#undef yyset_lloc -#endif -#ifndef wxparseralloc_ALREADY_DEFINED -#undef yyalloc -#endif -#ifndef wxparserrealloc_ALREADY_DEFINED -#undef yyrealloc -#endif -#ifndef wxparserfree_ALREADY_DEFINED -#undef yyfree -#endif -#ifndef wxparsertext_ALREADY_DEFINED -#undef yytext -#endif -#ifndef wxparserleng_ALREADY_DEFINED -#undef yyleng -#endif -#ifndef wxparserin_ALREADY_DEFINED -#undef yyin -#endif -#ifndef wxparserout_ALREADY_DEFINED -#undef yyout -#endif -#ifndef wxparser_flex_debug_ALREADY_DEFINED -#undef yy_flex_debug -#endif -#ifndef wxparserlineno_ALREADY_DEFINED -#undef yylineno -#endif -#ifndef wxparsertables_fload_ALREADY_DEFINED -#undef yytables_fload -#endif -#ifndef wxparsertables_destroy_ALREADY_DEFINED -#undef yytables_destroy -#endif -#ifndef wxparserTABLES_NAME_ALREADY_DEFINED -#undef yyTABLES_NAME -#endif - -#undef wxparserIN_HEADER -#endif /* wxparserHEADER_H */ diff --git a/Source/Parser/wp_parser.tab.cpp b/Source/Parser/wp_parser.tab.cpp deleted file mode 100644 index e5168a17731..00000000000 --- a/Source/Parser/wp_parser.tab.cpp +++ /dev/null @@ -1,1451 +0,0 @@ -/* A Bison parser, made by GNU Bison 3.7.5. */ - -/* Bison implementation for Yacc-like parsers in C - - Copyright (C) 1984, 1989-1990, 2000-2015, 2018-2021 Free Software Foundation, - Inc. - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see . */ - -/* As a special exception, you may create a larger work that contains - part or all of the Bison parser skeleton and distribute that work - under terms of your choice, so long as that work isn't itself a - parser generator using the skeleton or a modified version thereof - as a parser skeleton. Alternatively, if you modify or redistribute - the parser skeleton itself, you may (at your option) remove this - special exception, which will cause the skeleton and the resulting - Bison output files to be licensed under the GNU General Public - License without this special exception. - - This special exception was added by the Free Software Foundation in - version 2.2 of Bison. */ - -/* C LALR(1) parser skeleton written by Richard Stallman, by - simplifying the original so-called "semantic" parser. */ - -/* DO NOT RELY ON FEATURES THAT ARE NOT DOCUMENTED in the manual, - especially those whose name start with YY_ or yy_. They are - private implementation details that can be changed or removed. */ - -/* All symbols defined below should begin with yy or YY, to avoid - infringing on user name space. This should be done even for local - variables, as they might otherwise be expanded by user macros. - There are some unavoidable exceptions within include files to - define necessary library symbols; they are noted "INFRINGES ON - USER NAME SPACE" below. */ - -/* Identify Bison output, and Bison version. */ -#define YYBISON 30705 - -/* Bison version string. */ -#define YYBISON_VERSION "3.7.5" - -/* Skeleton name. */ -#define YYSKELETON_NAME "yacc.c" - -/* Pure parsers. */ -#define YYPURE 0 - -/* Push parsers. */ -#define YYPUSH 0 - -/* Pull parsers. */ -#define YYPULL 1 - -/* Substitute the type names. */ -#define YYSTYPE WXPARSERSTYPE -/* Substitute the variable and function names. */ -#define yyparse wxparserparse -#define yylex wxparserlex -#define yyerror wxparsererror -#define yydebug wxparserdebug -#define yynerrs wxparsernerrs -#define yylval wxparserlval -#define yychar wxparserchar - -/* First part of user prologue. */ - - #include - #include - #include - #include "wp_parser_y.h" - int wxparserlex (void); - - -# ifndef YY_CAST -# ifdef __cplusplus -# define YY_CAST(Type, Val) static_cast (Val) -# define YY_REINTERPRET_CAST(Type, Val) reinterpret_cast (Val) -# else -# define YY_CAST(Type, Val) ((Type) (Val)) -# define YY_REINTERPRET_CAST(Type, Val) ((Type) (Val)) -# endif -# endif -# ifndef YY_NULLPTR -# if defined __cplusplus -# if 201103L <= __cplusplus -# define YY_NULLPTR nullptr -# else -# define YY_NULLPTR 0 -# endif -# else -# define YY_NULLPTR ((void*)0) -# endif -# endif - -#include "wp_parser.tab.h" -/* Symbol kind. */ -enum yysymbol_kind_t -{ - YYSYMBOL_YYEMPTY = -2, - YYSYMBOL_YYEOF = 0, /* "end of file" */ - YYSYMBOL_YYerror = 1, /* error */ - YYSYMBOL_YYUNDEF = 2, /* "invalid token" */ - YYSYMBOL_NODE = 3, /* NODE */ - YYSYMBOL_NUMBER = 4, /* NUMBER */ - YYSYMBOL_SYMBOL = 5, /* SYMBOL */ - YYSYMBOL_F1 = 6, /* F1 */ - YYSYMBOL_F2 = 7, /* F2 */ - YYSYMBOL_F3 = 8, /* F3 */ - YYSYMBOL_EOL = 9, /* EOL */ - YYSYMBOL_POW = 10, /* "**" */ - YYSYMBOL_11_ = 11, /* '^' */ - YYSYMBOL_GEQ = 12, /* ">=" */ - YYSYMBOL_LEQ = 13, /* "<=" */ - YYSYMBOL_EQ = 14, /* "==" */ - YYSYMBOL_NEQ = 15, /* "!=" */ - YYSYMBOL_AND = 16, /* "and" */ - YYSYMBOL_OR = 17, /* "or" */ - YYSYMBOL_18_ = 18, /* '=' */ - YYSYMBOL_19_ = 19, /* '<' */ - YYSYMBOL_20_ = 20, /* '>' */ - YYSYMBOL_21_ = 21, /* '+' */ - YYSYMBOL_22_ = 22, /* '-' */ - YYSYMBOL_23_ = 23, /* '*' */ - YYSYMBOL_24_ = 24, /* '/' */ - YYSYMBOL_NEG = 25, /* NEG */ - YYSYMBOL_UPLUS = 26, /* UPLUS */ - YYSYMBOL_27_ = 27, /* '(' */ - YYSYMBOL_28_ = 28, /* ')' */ - YYSYMBOL_29_ = 29, /* ',' */ - YYSYMBOL_YYACCEPT = 30, /* $accept */ - YYSYMBOL_input = 31, /* input */ - YYSYMBOL_exp = 32 /* exp */ -}; -typedef enum yysymbol_kind_t yysymbol_kind_t; - - - - -#ifdef short -# undef short -#endif - -/* On compilers that do not define __PTRDIFF_MAX__ etc., make sure - and (if available) are included - so that the code can choose integer types of a good width. */ - -#ifndef __PTRDIFF_MAX__ -# include /* INFRINGES ON USER NAME SPACE */ -# if defined __STDC_VERSION__ && 199901 <= __STDC_VERSION__ -# include /* INFRINGES ON USER NAME SPACE */ -# define YY_STDINT_H -# endif -#endif - -/* Narrow types that promote to a signed type and that can represent a - signed or unsigned integer of at least N bits. In tables they can - save space and decrease cache pressure. Promoting to a signed type - helps avoid bugs in integer arithmetic. */ - -#ifdef __INT_LEAST8_MAX__ -typedef __INT_LEAST8_TYPE__ yytype_int8; -#elif defined YY_STDINT_H -typedef int_least8_t yytype_int8; -#else -typedef signed char yytype_int8; -#endif - -#ifdef __INT_LEAST16_MAX__ -typedef __INT_LEAST16_TYPE__ yytype_int16; -#elif defined YY_STDINT_H -typedef int_least16_t yytype_int16; -#else -typedef short yytype_int16; -#endif - -/* Work around bug in HP-UX 11.23, which defines these macros - incorrectly for preprocessor constants. This workaround can likely - be removed in 2023, as HPE has promised support for HP-UX 11.23 - (aka HP-UX 11i v2) only through the end of 2022; see Table 2 of - . */ -#ifdef __hpux -# undef UINT_LEAST8_MAX -# undef UINT_LEAST16_MAX -# define UINT_LEAST8_MAX 255 -# define UINT_LEAST16_MAX 65535 -#endif - -#if defined __UINT_LEAST8_MAX__ && __UINT_LEAST8_MAX__ <= __INT_MAX__ -typedef __UINT_LEAST8_TYPE__ yytype_uint8; -#elif (!defined __UINT_LEAST8_MAX__ && defined YY_STDINT_H \ - && UINT_LEAST8_MAX <= INT_MAX) -typedef uint_least8_t yytype_uint8; -#elif !defined __UINT_LEAST8_MAX__ && UCHAR_MAX <= INT_MAX -typedef unsigned char yytype_uint8; -#else -typedef short yytype_uint8; -#endif - -#if defined __UINT_LEAST16_MAX__ && __UINT_LEAST16_MAX__ <= __INT_MAX__ -typedef __UINT_LEAST16_TYPE__ yytype_uint16; -#elif (!defined __UINT_LEAST16_MAX__ && defined YY_STDINT_H \ - && UINT_LEAST16_MAX <= INT_MAX) -typedef uint_least16_t yytype_uint16; -#elif !defined __UINT_LEAST16_MAX__ && USHRT_MAX <= INT_MAX -typedef unsigned short yytype_uint16; -#else -typedef int yytype_uint16; -#endif - -#ifndef YYPTRDIFF_T -# if defined __PTRDIFF_TYPE__ && defined __PTRDIFF_MAX__ -# define YYPTRDIFF_T __PTRDIFF_TYPE__ -# define YYPTRDIFF_MAXIMUM __PTRDIFF_MAX__ -# elif defined PTRDIFF_MAX -# ifndef ptrdiff_t -# include /* INFRINGES ON USER NAME SPACE */ -# endif -# define YYPTRDIFF_T ptrdiff_t -# define YYPTRDIFF_MAXIMUM PTRDIFF_MAX -# else -# define YYPTRDIFF_T long -# define YYPTRDIFF_MAXIMUM LONG_MAX -# endif -#endif - -#ifndef YYSIZE_T -# ifdef __SIZE_TYPE__ -# define YYSIZE_T __SIZE_TYPE__ -# elif defined size_t -# define YYSIZE_T size_t -# elif defined __STDC_VERSION__ && 199901 <= __STDC_VERSION__ -# include /* INFRINGES ON USER NAME SPACE */ -# define YYSIZE_T size_t -# else -# define YYSIZE_T unsigned -# endif -#endif - -#define YYSIZE_MAXIMUM \ - YY_CAST (YYPTRDIFF_T, \ - (YYPTRDIFF_MAXIMUM < YY_CAST (YYSIZE_T, -1) \ - ? YYPTRDIFF_MAXIMUM \ - : YY_CAST (YYSIZE_T, -1))) - -#define YYSIZEOF(X) YY_CAST (YYPTRDIFF_T, sizeof (X)) - - -/* Stored state numbers (used for stacks). */ -typedef yytype_int8 yy_state_t; - -/* State numbers in computations. */ -typedef int yy_state_fast_t; - -#ifndef YY_ -# if defined YYENABLE_NLS && YYENABLE_NLS -# if ENABLE_NLS -# include /* INFRINGES ON USER NAME SPACE */ -# define YY_(Msgid) dgettext ("bison-runtime", Msgid) -# endif -# endif -# ifndef YY_ -# define YY_(Msgid) Msgid -# endif -#endif - - -#ifndef YY_ATTRIBUTE_PURE -# if defined __GNUC__ && 2 < __GNUC__ + (96 <= __GNUC_MINOR__) -# define YY_ATTRIBUTE_PURE __attribute__ ((__pure__)) -# else -# define YY_ATTRIBUTE_PURE -# endif -#endif - -#ifndef YY_ATTRIBUTE_UNUSED -# if defined __GNUC__ && 2 < __GNUC__ + (7 <= __GNUC_MINOR__) -# define YY_ATTRIBUTE_UNUSED __attribute__ ((__unused__)) -# else -# define YY_ATTRIBUTE_UNUSED -# endif -#endif - -/* Suppress unused-variable warnings by "using" E. */ -#if ! defined lint || defined __GNUC__ -# define YY_USE(E) ((void) (E)) -#else -# define YY_USE(E) /* empty */ -#endif - -#if defined __GNUC__ && ! defined __ICC && 407 <= __GNUC__ * 100 + __GNUC_MINOR__ -/* Suppress an incorrect diagnostic about yylval being uninitialized. */ -# define YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN \ - _Pragma ("GCC diagnostic push") \ - _Pragma ("GCC diagnostic ignored \"-Wuninitialized\"") \ - _Pragma ("GCC diagnostic ignored \"-Wmaybe-uninitialized\"") -# define YY_IGNORE_MAYBE_UNINITIALIZED_END \ - _Pragma ("GCC diagnostic pop") -#else -# define YY_INITIAL_VALUE(Value) Value -#endif -#ifndef YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN -# define YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN -# define YY_IGNORE_MAYBE_UNINITIALIZED_END -#endif -#ifndef YY_INITIAL_VALUE -# define YY_INITIAL_VALUE(Value) /* Nothing. */ -#endif - -#if defined __cplusplus && defined __GNUC__ && ! defined __ICC && 6 <= __GNUC__ -# define YY_IGNORE_USELESS_CAST_BEGIN \ - _Pragma ("GCC diagnostic push") \ - _Pragma ("GCC diagnostic ignored \"-Wuseless-cast\"") -# define YY_IGNORE_USELESS_CAST_END \ - _Pragma ("GCC diagnostic pop") -#endif -#ifndef YY_IGNORE_USELESS_CAST_BEGIN -# define YY_IGNORE_USELESS_CAST_BEGIN -# define YY_IGNORE_USELESS_CAST_END -#endif - - -#define YY_ASSERT(E) ((void) (0 && (E))) - -#if !defined yyoverflow - -/* The parser invokes alloca or malloc; define the necessary symbols. */ - -# ifdef YYSTACK_USE_ALLOCA -# if YYSTACK_USE_ALLOCA -# ifdef __GNUC__ -# define YYSTACK_ALLOC __builtin_alloca -# elif defined __BUILTIN_VA_ARG_INCR -# include /* INFRINGES ON USER NAME SPACE */ -# elif defined _AIX -# define YYSTACK_ALLOC __alloca -# elif defined _MSC_VER -# include /* INFRINGES ON USER NAME SPACE */ -# define alloca _alloca -# else -# define YYSTACK_ALLOC alloca -# if ! defined _ALLOCA_H && ! defined EXIT_SUCCESS -# include /* INFRINGES ON USER NAME SPACE */ - /* Use EXIT_SUCCESS as a witness for stdlib.h. */ -# ifndef EXIT_SUCCESS -# define EXIT_SUCCESS 0 -# endif -# endif -# endif -# endif -# endif - -# ifdef YYSTACK_ALLOC - /* Pacify GCC's 'empty if-body' warning. */ -# define YYSTACK_FREE(Ptr) do { /* empty */; } while (0) -# ifndef YYSTACK_ALLOC_MAXIMUM - /* The OS might guarantee only one guard page at the bottom of the stack, - and a page size can be as small as 4096 bytes. So we cannot safely - invoke alloca (N) if N exceeds 4096. Use a slightly smaller number - to allow for a few compiler-allocated temporary stack slots. */ -# define YYSTACK_ALLOC_MAXIMUM 4032 /* reasonable circa 2006 */ -# endif -# else -# define YYSTACK_ALLOC YYMALLOC -# define YYSTACK_FREE YYFREE -# ifndef YYSTACK_ALLOC_MAXIMUM -# define YYSTACK_ALLOC_MAXIMUM YYSIZE_MAXIMUM -# endif -# if (defined __cplusplus && ! defined EXIT_SUCCESS \ - && ! ((defined YYMALLOC || defined malloc) \ - && (defined YYFREE || defined free))) -# include /* INFRINGES ON USER NAME SPACE */ -# ifndef EXIT_SUCCESS -# define EXIT_SUCCESS 0 -# endif -# endif -# ifndef YYMALLOC -# define YYMALLOC malloc -# if ! defined malloc && ! defined EXIT_SUCCESS -void *malloc (YYSIZE_T); /* INFRINGES ON USER NAME SPACE */ -# endif -# endif -# ifndef YYFREE -# define YYFREE free -# if ! defined free && ! defined EXIT_SUCCESS -void free (void *); /* INFRINGES ON USER NAME SPACE */ -# endif -# endif -# endif -#endif /* !defined yyoverflow */ - -#if (! defined yyoverflow \ - && (! defined __cplusplus \ - || (defined WXPARSERSTYPE_IS_TRIVIAL && WXPARSERSTYPE_IS_TRIVIAL))) - -/* A type that is properly aligned for any stack member. */ -union yyalloc -{ - yy_state_t yyss_alloc; - YYSTYPE yyvs_alloc; -}; - -/* The size of the maximum gap between one aligned stack and the next. */ -# define YYSTACK_GAP_MAXIMUM (YYSIZEOF (union yyalloc) - 1) - -/* The size of an array large to enough to hold all stacks, each with - N elements. */ -# define YYSTACK_BYTES(N) \ - ((N) * (YYSIZEOF (yy_state_t) + YYSIZEOF (YYSTYPE)) \ - + YYSTACK_GAP_MAXIMUM) - -# define YYCOPY_NEEDED 1 - -/* Relocate STACK from its old location to the new one. The - local variables YYSIZE and YYSTACKSIZE give the old and new number of - elements in the stack, and YYPTR gives the new location of the - stack. Advance YYPTR to a properly aligned location for the next - stack. */ -# define YYSTACK_RELOCATE(Stack_alloc, Stack) \ - do \ - { \ - YYPTRDIFF_T yynewbytes; \ - YYCOPY (&yyptr->Stack_alloc, Stack, yysize); \ - Stack = &yyptr->Stack_alloc; \ - yynewbytes = yystacksize * YYSIZEOF (*Stack) + YYSTACK_GAP_MAXIMUM; \ - yyptr += yynewbytes / YYSIZEOF (*yyptr); \ - } \ - while (0) - -#endif - -#if defined YYCOPY_NEEDED && YYCOPY_NEEDED -/* Copy COUNT objects from SRC to DST. The source and destination do - not overlap. */ -# ifndef YYCOPY -# if defined __GNUC__ && 1 < __GNUC__ -# define YYCOPY(Dst, Src, Count) \ - __builtin_memcpy (Dst, Src, YY_CAST (YYSIZE_T, (Count)) * sizeof (*(Src))) -# else -# define YYCOPY(Dst, Src, Count) \ - do \ - { \ - YYPTRDIFF_T yyi; \ - for (yyi = 0; yyi < (Count); yyi++) \ - (Dst)[yyi] = (Src)[yyi]; \ - } \ - while (0) -# endif -# endif -#endif /* !YYCOPY_NEEDED */ - -/* YYFINAL -- State number of the termination state. */ -#define YYFINAL 2 -/* YYLAST -- Last index in YYTABLE. */ -#define YYLAST 238 - -/* YYNTOKENS -- Number of terminals. */ -#define YYNTOKENS 30 -/* YYNNTS -- Number of nonterminals. */ -#define YYNNTS 3 -/* YYNRULES -- Number of rules. */ -#define YYNRULES 24 -/* YYNSTATES -- Number of states. */ -#define YYNSTATES 58 - -/* YYMAXUTOK -- Last valid token kind. */ -#define YYMAXUTOK 273 - - -/* YYTRANSLATE(TOKEN-NUM) -- Symbol number corresponding to TOKEN-NUM - as returned by yylex, with out-of-bounds checking. */ -#define YYTRANSLATE(YYX) \ - (0 <= (YYX) && (YYX) <= YYMAXUTOK \ - ? YY_CAST (yysymbol_kind_t, yytranslate[YYX]) \ - : YYSYMBOL_YYUNDEF) - -/* YYTRANSLATE[TOKEN-NUM] -- Symbol number corresponding to TOKEN-NUM - as returned by yylex. */ -static const yytype_int8 yytranslate[] = -{ - 0, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 27, 28, 23, 21, 29, 22, 2, 24, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 19, 18, 20, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 11, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 1, 2, 3, 4, - 5, 6, 7, 8, 9, 10, 12, 13, 14, 15, - 16, 17, 25, 26 -}; - -#if WXPARSERDEBUG - /* YYRLINE[YYN] -- Source line where rule number YYN was defined. */ -static const yytype_int8 yyrline[] = -{ - 0, 70, 70, 71, 80, 81, 82, 83, 84, 85, - 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, - 96, 97, 98, 99, 100 -}; -#endif - -/** Accessing symbol of state STATE. */ -#define YY_ACCESSING_SYMBOL(State) YY_CAST (yysymbol_kind_t, yystos[State]) - -#if WXPARSERDEBUG || 0 -/* The user-facing name of the symbol whose (internal) number is - YYSYMBOL. No bounds checking. */ -static const char *yysymbol_name (yysymbol_kind_t yysymbol) YY_ATTRIBUTE_UNUSED; - -/* YYTNAME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM. - First, the terminals, then, starting at YYNTOKENS, nonterminals. */ -static const char *const yytname[] = -{ - "\"end of file\"", "error", "\"invalid token\"", "NODE", "NUMBER", - "SYMBOL", "F1", "F2", "F3", "EOL", "\"**\"", "'^'", "\">=\"", "\"<=\"", - "\"==\"", "\"!=\"", "\"and\"", "\"or\"", "'='", "'<'", "'>'", "'+'", - "'-'", "'*'", "'/'", "NEG", "UPLUS", "'('", "')'", "','", "$accept", - "input", "exp", YY_NULLPTR -}; - -static const char * -yysymbol_name (yysymbol_kind_t yysymbol) -{ - return yytname[yysymbol]; -} -#endif - -#ifdef YYPRINT -/* YYTOKNUM[NUM] -- (External) token number corresponding to the - (internal) symbol number NUM (which must be that of a token). */ -static const yytype_int16 yytoknum[] = -{ - 0, 256, 257, 258, 259, 260, 261, 262, 263, 264, - 265, 94, 266, 267, 268, 269, 270, 271, 61, 60, - 62, 43, 45, 42, 47, 272, 273, 40, 41, 44 -}; -#endif - -#define YYPACT_NINF (-25) - -#define yypact_value_is_default(Yyn) \ - ((Yyn) == YYPACT_NINF) - -#define YYTABLE_NINF (-1) - -#define yytable_value_is_error(Yyn) \ - 0 - - /* YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing - STATE-NUM. */ -static const yytype_int16 yypact[] = -{ - -25, 24, -25, -25, -25, -24, -20, -19, 31, 31, - 31, 169, 31, 31, 31, -1, -1, 101, -25, 31, - 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, - 31, 31, 118, 47, 65, -25, -1, 207, 207, 214, - 214, 199, 184, 207, 207, 17, 17, -1, -1, -25, - 31, 31, 135, 83, -25, 31, 152, -25 -}; - - /* YYDEFACT[STATE-NUM] -- Default reduction number in state STATE-NUM. - Performed when YYTABLE does not specify something else to do. Zero - means the default is an error. */ -static const yytype_int8 yydefact[] = -{ - 2, 0, 1, 4, 5, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 20, 19, 0, 3, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 10, 21, 14, 13, 15, - 16, 17, 18, 11, 12, 6, 7, 8, 9, 22, - 0, 0, 0, 0, 23, 0, 0, 24 -}; - - /* YYPGOTO[NTERM-NUM]. */ -static const yytype_int8 yypgoto[] = -{ - -25, -25, -8 -}; - - /* YYDEFGOTO[NTERM-NUM]. */ -static const yytype_int8 yydefgoto[] = -{ - 0, 1, 11 -}; - - /* YYTABLE[YYPACT[STATE-NUM]] -- What to do in state STATE-NUM. If - positive, shift that token. If negative, reduce the rule whose - number is the opposite. If YYTABLE_NINF, syntax error. */ -static const yytype_int8 yytable[] = -{ - 15, 16, 17, 12, 32, 33, 34, 13, 14, 19, - 0, 36, 37, 38, 39, 40, 41, 42, 43, 44, - 45, 46, 47, 48, 2, 0, 0, 19, 3, 4, - 5, 6, 7, 0, 0, 3, 4, 5, 6, 7, - 30, 31, 52, 53, 0, 8, 9, 56, 0, 0, - 0, 10, 8, 9, 0, 0, 0, 19, 10, 20, - 21, 22, 23, 24, 25, 0, 26, 27, 28, 29, - 30, 31, 0, 0, 0, 19, 50, 20, 21, 22, - 23, 24, 25, 0, 26, 27, 28, 29, 30, 31, - 0, 0, 0, 19, 51, 20, 21, 22, 23, 24, - 25, 0, 26, 27, 28, 29, 30, 31, 0, 0, - 0, 19, 55, 20, 21, 22, 23, 24, 25, 0, - 26, 27, 28, 29, 30, 31, 0, 0, 19, 35, - 20, 21, 22, 23, 24, 25, 0, 26, 27, 28, - 29, 30, 31, 0, 0, 19, 49, 20, 21, 22, - 23, 24, 25, 0, 26, 27, 28, 29, 30, 31, - 0, 0, 19, 54, 20, 21, 22, 23, 24, 25, - 0, 26, 27, 28, 29, 30, 31, 0, 18, 19, - 57, 20, 21, 22, 23, 24, 25, 0, 26, 27, - 28, 29, 30, 31, 19, 0, 20, 21, 22, 23, - 24, 0, 0, 26, 27, 28, 29, 30, 31, 19, - 0, 20, 21, 22, 23, 0, 0, 19, 26, 27, - 28, 29, 30, 31, 19, 0, 20, 21, 28, 29, - 30, 31, 0, 26, 27, 28, 29, 30, 31 -}; - -static const yytype_int8 yycheck[] = -{ - 8, 9, 10, 27, 12, 13, 14, 27, 27, 10, - -1, 19, 20, 21, 22, 23, 24, 25, 26, 27, - 28, 29, 30, 31, 0, -1, -1, 10, 4, 5, - 6, 7, 8, -1, -1, 4, 5, 6, 7, 8, - 23, 24, 50, 51, -1, 21, 22, 55, -1, -1, - -1, 27, 21, 22, -1, -1, -1, 10, 27, 12, - 13, 14, 15, 16, 17, -1, 19, 20, 21, 22, - 23, 24, -1, -1, -1, 10, 29, 12, 13, 14, - 15, 16, 17, -1, 19, 20, 21, 22, 23, 24, - -1, -1, -1, 10, 29, 12, 13, 14, 15, 16, - 17, -1, 19, 20, 21, 22, 23, 24, -1, -1, - -1, 10, 29, 12, 13, 14, 15, 16, 17, -1, - 19, 20, 21, 22, 23, 24, -1, -1, 10, 28, - 12, 13, 14, 15, 16, 17, -1, 19, 20, 21, - 22, 23, 24, -1, -1, 10, 28, 12, 13, 14, - 15, 16, 17, -1, 19, 20, 21, 22, 23, 24, - -1, -1, 10, 28, 12, 13, 14, 15, 16, 17, - -1, 19, 20, 21, 22, 23, 24, -1, 9, 10, - 28, 12, 13, 14, 15, 16, 17, -1, 19, 20, - 21, 22, 23, 24, 10, -1, 12, 13, 14, 15, - 16, -1, -1, 19, 20, 21, 22, 23, 24, 10, - -1, 12, 13, 14, 15, -1, -1, 10, 19, 20, - 21, 22, 23, 24, 10, -1, 12, 13, 21, 22, - 23, 24, -1, 19, 20, 21, 22, 23, 24 -}; - - /* YYSTOS[STATE-NUM] -- The (internal number of the) accessing - symbol of state STATE-NUM. */ -static const yytype_int8 yystos[] = -{ - 0, 31, 0, 4, 5, 6, 7, 8, 21, 22, - 27, 32, 27, 27, 27, 32, 32, 32, 9, 10, - 12, 13, 14, 15, 16, 17, 19, 20, 21, 22, - 23, 24, 32, 32, 32, 28, 32, 32, 32, 32, - 32, 32, 32, 32, 32, 32, 32, 32, 32, 28, - 29, 29, 32, 32, 28, 29, 32, 28 -}; - - /* YYR1[YYN] -- Symbol number of symbol that rule YYN derives. */ -static const yytype_int8 yyr1[] = -{ - 0, 30, 31, 31, 32, 32, 32, 32, 32, 32, - 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, - 32, 32, 32, 32, 32 -}; - - /* YYR2[YYN] -- Number of symbols on the right hand side of rule YYN. */ -static const yytype_int8 yyr2[] = -{ - 0, 2, 0, 3, 1, 1, 3, 3, 3, 3, - 3, 3, 3, 3, 3, 3, 3, 3, 3, 2, - 2, 3, 4, 6, 8 -}; - - -enum { YYENOMEM = -2 }; - -#define yyerrok (yyerrstatus = 0) -#define yyclearin (yychar = WXPARSEREMPTY) - -#define YYACCEPT goto yyacceptlab -#define YYABORT goto yyabortlab -#define YYERROR goto yyerrorlab - - -#define YYRECOVERING() (!!yyerrstatus) - -#define YYBACKUP(Token, Value) \ - do \ - if (yychar == WXPARSEREMPTY) \ - { \ - yychar = (Token); \ - yylval = (Value); \ - YYPOPSTACK (yylen); \ - yystate = *yyssp; \ - goto yybackup; \ - } \ - else \ - { \ - yyerror (YY_("syntax error: cannot back up")); \ - YYERROR; \ - } \ - while (0) - -/* Backward compatibility with an undocumented macro. - Use WXPARSERerror or WXPARSERUNDEF. */ -#define YYERRCODE WXPARSERUNDEF - - -/* Enable debugging if requested. */ -#if WXPARSERDEBUG - -# ifndef YYFPRINTF -# include /* INFRINGES ON USER NAME SPACE */ -# define YYFPRINTF fprintf -# endif - -# define YYDPRINTF(Args) \ -do { \ - if (yydebug) \ - YYFPRINTF Args; \ -} while (0) - -/* This macro is provided for backward compatibility. */ -# ifndef YY_LOCATION_PRINT -# define YY_LOCATION_PRINT(File, Loc) ((void) 0) -# endif - - -# define YY_SYMBOL_PRINT(Title, Kind, Value, Location) \ -do { \ - if (yydebug) \ - { \ - YYFPRINTF (stderr, "%s ", Title); \ - yy_symbol_print (stderr, \ - Kind, Value); \ - YYFPRINTF (stderr, "\n"); \ - } \ -} while (0) - - -/*-----------------------------------. -| Print this symbol's value on YYO. | -`-----------------------------------*/ - -static void -yy_symbol_value_print (FILE *yyo, - yysymbol_kind_t yykind, YYSTYPE const * const yyvaluep) -{ - FILE *yyoutput = yyo; - YY_USE (yyoutput); - if (!yyvaluep) - return; -# ifdef YYPRINT - if (yykind < YYNTOKENS) - YYPRINT (yyo, yytoknum[yykind], *yyvaluep); -# endif - YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN - YY_USE (yykind); - YY_IGNORE_MAYBE_UNINITIALIZED_END -} - - -/*---------------------------. -| Print this symbol on YYO. | -`---------------------------*/ - -static void -yy_symbol_print (FILE *yyo, - yysymbol_kind_t yykind, YYSTYPE const * const yyvaluep) -{ - YYFPRINTF (yyo, "%s %s (", - yykind < YYNTOKENS ? "token" : "nterm", yysymbol_name (yykind)); - - yy_symbol_value_print (yyo, yykind, yyvaluep); - YYFPRINTF (yyo, ")"); -} - -/*------------------------------------------------------------------. -| yy_stack_print -- Print the state stack from its BOTTOM up to its | -| TOP (included). | -`------------------------------------------------------------------*/ - -static void -yy_stack_print (yy_state_t *yybottom, yy_state_t *yytop) -{ - YYFPRINTF (stderr, "Stack now"); - for (; yybottom <= yytop; yybottom++) - { - int yybot = *yybottom; - YYFPRINTF (stderr, " %d", yybot); - } - YYFPRINTF (stderr, "\n"); -} - -# define YY_STACK_PRINT(Bottom, Top) \ -do { \ - if (yydebug) \ - yy_stack_print ((Bottom), (Top)); \ -} while (0) - - -/*------------------------------------------------. -| Report that the YYRULE is going to be reduced. | -`------------------------------------------------*/ - -static void -yy_reduce_print (yy_state_t *yyssp, YYSTYPE *yyvsp, - int yyrule) -{ - int yylno = yyrline[yyrule]; - int yynrhs = yyr2[yyrule]; - int yyi; - YYFPRINTF (stderr, "Reducing stack by rule %d (line %d):\n", - yyrule - 1, yylno); - /* The symbols being reduced. */ - for (yyi = 0; yyi < yynrhs; yyi++) - { - YYFPRINTF (stderr, " $%d = ", yyi + 1); - yy_symbol_print (stderr, - YY_ACCESSING_SYMBOL (+yyssp[yyi + 1 - yynrhs]), - &yyvsp[(yyi + 1) - (yynrhs)]); - YYFPRINTF (stderr, "\n"); - } -} - -# define YY_REDUCE_PRINT(Rule) \ -do { \ - if (yydebug) \ - yy_reduce_print (yyssp, yyvsp, Rule); \ -} while (0) - -/* Nonzero means print parse trace. It is left uninitialized so that - multiple parsers can coexist. */ -int yydebug; -#else /* !WXPARSERDEBUG */ -# define YYDPRINTF(Args) ((void) 0) -# define YY_SYMBOL_PRINT(Title, Kind, Value, Location) -# define YY_STACK_PRINT(Bottom, Top) -# define YY_REDUCE_PRINT(Rule) -#endif /* !WXPARSERDEBUG */ - - -/* YYINITDEPTH -- initial size of the parser's stacks. */ -#ifndef YYINITDEPTH -# define YYINITDEPTH 200 -#endif - -/* YYMAXDEPTH -- maximum size the stacks can grow to (effective only - if the built-in stack extension method is used). - - Do not make this value too large; the results are undefined if - YYSTACK_ALLOC_MAXIMUM < YYSTACK_BYTES (YYMAXDEPTH) - evaluated with infinite-precision integer arithmetic. */ - -#ifndef YYMAXDEPTH -# define YYMAXDEPTH 10000 -#endif - - - - - - -/*-----------------------------------------------. -| Release the memory associated to this symbol. | -`-----------------------------------------------*/ - -static void -yydestruct (const char *yymsg, - yysymbol_kind_t yykind, YYSTYPE *yyvaluep) -{ - YY_USE (yyvaluep); - if (!yymsg) - yymsg = "Deleting"; - YY_SYMBOL_PRINT (yymsg, yykind, yyvaluep, yylocationp); - - YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN - YY_USE (yykind); - YY_IGNORE_MAYBE_UNINITIALIZED_END -} - - -/* Lookahead token kind. */ -int yychar; - -/* The semantic value of the lookahead symbol. */ -YYSTYPE yylval; -/* Number of syntax errors so far. */ -int yynerrs; - - - - -/*----------. -| yyparse. | -`----------*/ - -int -yyparse (void) -{ - yy_state_fast_t yystate = 0; - /* Number of tokens to shift before error messages enabled. */ - int yyerrstatus = 0; - - /* Refer to the stacks through separate pointers, to allow yyoverflow - to reallocate them elsewhere. */ - - /* Their size. */ - YYPTRDIFF_T yystacksize = YYINITDEPTH; - - /* The state stack: array, bottom, top. */ - yy_state_t yyssa[YYINITDEPTH]; - yy_state_t *yyss = yyssa; - yy_state_t *yyssp = yyss; - - /* The semantic value stack: array, bottom, top. */ - YYSTYPE yyvsa[YYINITDEPTH]; - YYSTYPE *yyvs = yyvsa; - YYSTYPE *yyvsp = yyvs; - - int yyn; - /* The return value of yyparse. */ - int yyresult; - /* Lookahead symbol kind. */ - yysymbol_kind_t yytoken = YYSYMBOL_YYEMPTY; - /* The variables used to return semantic value and location from the - action routines. */ - YYSTYPE yyval; - - - -#define YYPOPSTACK(N) (yyvsp -= (N), yyssp -= (N)) - - /* The number of symbols on the RHS of the reduced rule. - Keep to zero when no symbol should be popped. */ - int yylen = 0; - - YYDPRINTF ((stderr, "Starting parse\n")); - - yychar = WXPARSEREMPTY; /* Cause a token to be read. */ - goto yysetstate; - - -/*------------------------------------------------------------. -| yynewstate -- push a new state, which is found in yystate. | -`------------------------------------------------------------*/ -yynewstate: - /* In all cases, when you get here, the value and location stacks - have just been pushed. So pushing a state here evens the stacks. */ - yyssp++; - - -/*--------------------------------------------------------------------. -| yysetstate -- set current state (the top of the stack) to yystate. | -`--------------------------------------------------------------------*/ -yysetstate: - YYDPRINTF ((stderr, "Entering state %d\n", yystate)); - YY_ASSERT (0 <= yystate && yystate < YYNSTATES); - YY_IGNORE_USELESS_CAST_BEGIN - *yyssp = YY_CAST (yy_state_t, yystate); - YY_IGNORE_USELESS_CAST_END - YY_STACK_PRINT (yyss, yyssp); - - if (yyss + yystacksize - 1 <= yyssp) -#if !defined yyoverflow && !defined YYSTACK_RELOCATE - goto yyexhaustedlab; -#else - { - /* Get the current used size of the three stacks, in elements. */ - YYPTRDIFF_T yysize = yyssp - yyss + 1; - -# if defined yyoverflow - { - /* Give user a chance to reallocate the stack. Use copies of - these so that the &'s don't force the real ones into - memory. */ - yy_state_t *yyss1 = yyss; - YYSTYPE *yyvs1 = yyvs; - - /* Each stack pointer address is followed by the size of the - data in use in that stack, in bytes. This used to be a - conditional around just the two extra args, but that might - be undefined if yyoverflow is a macro. */ - yyoverflow (YY_("memory exhausted"), - &yyss1, yysize * YYSIZEOF (*yyssp), - &yyvs1, yysize * YYSIZEOF (*yyvsp), - &yystacksize); - yyss = yyss1; - yyvs = yyvs1; - } -# else /* defined YYSTACK_RELOCATE */ - /* Extend the stack our own way. */ - if (YYMAXDEPTH <= yystacksize) - goto yyexhaustedlab; - yystacksize *= 2; - if (YYMAXDEPTH < yystacksize) - yystacksize = YYMAXDEPTH; - - { - yy_state_t *yyss1 = yyss; - union yyalloc *yyptr = - YY_CAST (union yyalloc *, - YYSTACK_ALLOC (YY_CAST (YYSIZE_T, YYSTACK_BYTES (yystacksize)))); - if (! yyptr) - goto yyexhaustedlab; - YYSTACK_RELOCATE (yyss_alloc, yyss); - YYSTACK_RELOCATE (yyvs_alloc, yyvs); -# undef YYSTACK_RELOCATE - if (yyss1 != yyssa) - YYSTACK_FREE (yyss1); - } -# endif - - yyssp = yyss + yysize - 1; - yyvsp = yyvs + yysize - 1; - - YY_IGNORE_USELESS_CAST_BEGIN - YYDPRINTF ((stderr, "Stack size increased to %ld\n", - YY_CAST (long, yystacksize))); - YY_IGNORE_USELESS_CAST_END - - if (yyss + yystacksize - 1 <= yyssp) - YYABORT; - } -#endif /* !defined yyoverflow && !defined YYSTACK_RELOCATE */ - - if (yystate == YYFINAL) - YYACCEPT; - - goto yybackup; - - -/*-----------. -| yybackup. | -`-----------*/ -yybackup: - /* Do appropriate processing given the current state. Read a - lookahead token if we need one and don't already have one. */ - - /* First try to decide what to do without reference to lookahead token. */ - yyn = yypact[yystate]; - if (yypact_value_is_default (yyn)) - goto yydefault; - - /* Not known => get a lookahead token if don't already have one. */ - - /* YYCHAR is either empty, or end-of-input, or a valid lookahead. */ - if (yychar == WXPARSEREMPTY) - { - YYDPRINTF ((stderr, "Reading a token\n")); - yychar = yylex (); - } - - if (yychar <= WXPARSEREOF) - { - yychar = WXPARSEREOF; - yytoken = YYSYMBOL_YYEOF; - YYDPRINTF ((stderr, "Now at end of input.\n")); - } - else if (yychar == WXPARSERerror) - { - /* The scanner already issued an error message, process directly - to error recovery. But do not keep the error token as - lookahead, it is too special and may lead us to an endless - loop in error recovery. */ - yychar = WXPARSERUNDEF; - yytoken = YYSYMBOL_YYerror; - goto yyerrlab1; - } - else - { - yytoken = YYTRANSLATE (yychar); - YY_SYMBOL_PRINT ("Next token is", yytoken, &yylval, &yylloc); - } - - /* If the proper action on seeing token YYTOKEN is to reduce or to - detect an error, take that action. */ - yyn += yytoken; - if (yyn < 0 || YYLAST < yyn || yycheck[yyn] != yytoken) - goto yydefault; - yyn = yytable[yyn]; - if (yyn <= 0) - { - if (yytable_value_is_error (yyn)) - goto yyerrlab; - yyn = -yyn; - goto yyreduce; - } - - /* Count tokens shifted since error; after three, turn off error - status. */ - if (yyerrstatus) - yyerrstatus--; - - /* Shift the lookahead token. */ - YY_SYMBOL_PRINT ("Shifting", yytoken, &yylval, &yylloc); - yystate = yyn; - YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN - *++yyvsp = yylval; - YY_IGNORE_MAYBE_UNINITIALIZED_END - - /* Discard the shifted token. */ - yychar = WXPARSEREMPTY; - goto yynewstate; - - -/*-----------------------------------------------------------. -| yydefault -- do the default action for the current state. | -`-----------------------------------------------------------*/ -yydefault: - yyn = yydefact[yystate]; - if (yyn == 0) - goto yyerrlab; - goto yyreduce; - - -/*-----------------------------. -| yyreduce -- do a reduction. | -`-----------------------------*/ -yyreduce: - /* yyn is the number of a rule to reduce with. */ - yylen = yyr2[yyn]; - - /* If YYLEN is nonzero, implement the default value of the action: - '$$ = $1'. - - Otherwise, the following line sets YYVAL to garbage. - This behavior is undocumented and Bison - users should not rely upon it. Assigning to YYVAL - unconditionally makes the parser a bit smaller, and it avoids a - GCC warning that YYVAL may be used uninitialized. */ - yyval = yyvsp[1-yylen]; - - - YY_REDUCE_PRINT (yyn); - switch (yyn) - { - case 3: /* input: input exp EOL */ - { - wp_defexpr((yyvsp[-1].n)); - } - break; - - case 4: /* exp: NUMBER */ - { (yyval.n) = wp_newnumber((yyvsp[0].d)); } - break; - - case 5: /* exp: SYMBOL */ - { (yyval.n) = wp_newsymbol((yyvsp[0].s)); } - break; - - case 6: /* exp: exp '+' exp */ - { (yyval.n) = wp_newnode(WP_ADD, (yyvsp[-2].n), (yyvsp[0].n)); } - break; - - case 7: /* exp: exp '-' exp */ - { (yyval.n) = wp_newnode(WP_SUB, (yyvsp[-2].n), (yyvsp[0].n)); } - break; - - case 8: /* exp: exp '*' exp */ - { (yyval.n) = wp_newnode(WP_MUL, (yyvsp[-2].n), (yyvsp[0].n)); } - break; - - case 9: /* exp: exp '/' exp */ - { (yyval.n) = wp_newnode(WP_DIV, (yyvsp[-2].n), (yyvsp[0].n)); } - break; - - case 10: /* exp: '(' exp ')' */ - { (yyval.n) = (yyvsp[-1].n); } - break; - - case 11: /* exp: exp '<' exp */ - { (yyval.n) = wp_newf2(WP_LT, (yyvsp[-2].n), (yyvsp[0].n)); } - break; - - case 12: /* exp: exp '>' exp */ - { (yyval.n) = wp_newf2(WP_GT, (yyvsp[-2].n), (yyvsp[0].n)); } - break; - - case 13: /* exp: exp "<=" exp */ - { (yyval.n) = wp_newf2(WP_LEQ, (yyvsp[-2].n), (yyvsp[0].n)); } - break; - - case 14: /* exp: exp ">=" exp */ - { (yyval.n) = wp_newf2(WP_GEQ, (yyvsp[-2].n), (yyvsp[0].n)); } - break; - - case 15: /* exp: exp "==" exp */ - { (yyval.n) = wp_newf2(WP_EQ, (yyvsp[-2].n), (yyvsp[0].n)); } - break; - - case 16: /* exp: exp "!=" exp */ - { (yyval.n) = wp_newf2(WP_NEQ, (yyvsp[-2].n), (yyvsp[0].n)); } - break; - - case 17: /* exp: exp "and" exp */ - { (yyval.n) = wp_newf2(WP_AND, (yyvsp[-2].n), (yyvsp[0].n)); } - break; - - case 18: /* exp: exp "or" exp */ - { (yyval.n) = wp_newf2(WP_OR, (yyvsp[-2].n), (yyvsp[0].n)); } - break; - - case 19: /* exp: '-' exp */ - { (yyval.n) = wp_newnode(WP_NEG, (yyvsp[0].n), NULL); } - break; - - case 20: /* exp: '+' exp */ - { (yyval.n) = (yyvsp[0].n); } - break; - - case 21: /* exp: exp "**" exp */ - { (yyval.n) = wp_newf2(WP_POW, (yyvsp[-2].n), (yyvsp[0].n)); } - break; - - case 22: /* exp: F1 '(' exp ')' */ - { (yyval.n) = wp_newf1((yyvsp[-3].f1), (yyvsp[-1].n)); } - break; - - case 23: /* exp: F2 '(' exp ',' exp ')' */ - { (yyval.n) = wp_newf2((yyvsp[-5].f2), (yyvsp[-3].n), (yyvsp[-1].n)); } - break; - - case 24: /* exp: F3 '(' exp ',' exp ',' exp ')' */ - { (yyval.n) = wp_newf3((yyvsp[-7].f3), (yyvsp[-5].n), (yyvsp[-3].n), (yyvsp[-1].n)); } - break; - - - - default: break; - } - /* User semantic actions sometimes alter yychar, and that requires - that yytoken be updated with the new translation. We take the - approach of translating immediately before every use of yytoken. - One alternative is translating here after every semantic action, - but that translation would be missed if the semantic action invokes - YYABORT, YYACCEPT, or YYERROR immediately after altering yychar or - if it invokes YYBACKUP. In the case of YYABORT or YYACCEPT, an - incorrect destructor might then be invoked immediately. In the - case of YYERROR or YYBACKUP, subsequent parser actions might lead - to an incorrect destructor call or verbose syntax error message - before the lookahead is translated. */ - YY_SYMBOL_PRINT ("-> $$ =", YY_CAST (yysymbol_kind_t, yyr1[yyn]), &yyval, &yyloc); - - YYPOPSTACK (yylen); - yylen = 0; - - *++yyvsp = yyval; - - /* Now 'shift' the result of the reduction. Determine what state - that goes to, based on the state we popped back to and the rule - number reduced by. */ - { - const int yylhs = yyr1[yyn] - YYNTOKENS; - const int yyi = yypgoto[yylhs] + *yyssp; - yystate = (0 <= yyi && yyi <= YYLAST && yycheck[yyi] == *yyssp - ? yytable[yyi] - : yydefgoto[yylhs]); - } - - goto yynewstate; - - -/*--------------------------------------. -| yyerrlab -- here on detecting error. | -`--------------------------------------*/ -yyerrlab: - /* Make sure we have latest lookahead translation. See comments at - user semantic actions for why this is necessary. */ - yytoken = yychar == WXPARSEREMPTY ? YYSYMBOL_YYEMPTY : YYTRANSLATE (yychar); - /* If not already recovering from an error, report this error. */ - if (!yyerrstatus) - { - ++yynerrs; - yyerror (YY_("syntax error")); - } - - if (yyerrstatus == 3) - { - /* If just tried and failed to reuse lookahead token after an - error, discard it. */ - - if (yychar <= WXPARSEREOF) - { - /* Return failure if at end of input. */ - if (yychar == WXPARSEREOF) - YYABORT; - } - else - { - yydestruct ("Error: discarding", - yytoken, &yylval); - yychar = WXPARSEREMPTY; - } - } - - /* Else will try to reuse lookahead token after shifting the error - token. */ - goto yyerrlab1; - - -/*---------------------------------------------------. -| yyerrorlab -- error raised explicitly by YYERROR. | -`---------------------------------------------------*/ -yyerrorlab: - /* Pacify compilers when the user code never invokes YYERROR and the - label yyerrorlab therefore never appears in user code. */ - if (0) - YYERROR; - - /* Do not reclaim the symbols of the rule whose action triggered - this YYERROR. */ - YYPOPSTACK (yylen); - yylen = 0; - YY_STACK_PRINT (yyss, yyssp); - yystate = *yyssp; - goto yyerrlab1; - - -/*-------------------------------------------------------------. -| yyerrlab1 -- common code for both syntax error and YYERROR. | -`-------------------------------------------------------------*/ -yyerrlab1: - yyerrstatus = 3; /* Each real token shifted decrements this. */ - - /* Pop stack until we find a state that shifts the error token. */ - for (;;) - { - yyn = yypact[yystate]; - if (!yypact_value_is_default (yyn)) - { - yyn += YYSYMBOL_YYerror; - if (0 <= yyn && yyn <= YYLAST && yycheck[yyn] == YYSYMBOL_YYerror) - { - yyn = yytable[yyn]; - if (0 < yyn) - break; - } - } - - /* Pop the current state because it cannot handle the error token. */ - if (yyssp == yyss) - YYABORT; - - - yydestruct ("Error: popping", - YY_ACCESSING_SYMBOL (yystate), yyvsp); - YYPOPSTACK (1); - yystate = *yyssp; - YY_STACK_PRINT (yyss, yyssp); - } - - YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN - *++yyvsp = yylval; - YY_IGNORE_MAYBE_UNINITIALIZED_END - - - /* Shift the error token. */ - YY_SYMBOL_PRINT ("Shifting", YY_ACCESSING_SYMBOL (yyn), yyvsp, yylsp); - - yystate = yyn; - goto yynewstate; - - -/*-------------------------------------. -| yyacceptlab -- YYACCEPT comes here. | -`-------------------------------------*/ -yyacceptlab: - yyresult = 0; - goto yyreturn; - - -/*-----------------------------------. -| yyabortlab -- YYABORT comes here. | -`-----------------------------------*/ -yyabortlab: - yyresult = 1; - goto yyreturn; - - -#if !defined yyoverflow -/*-------------------------------------------------. -| yyexhaustedlab -- memory exhaustion comes here. | -`-------------------------------------------------*/ -yyexhaustedlab: - yyerror (YY_("memory exhausted")); - yyresult = 2; - goto yyreturn; -#endif - - -/*-------------------------------------------------------. -| yyreturn -- parsing is finished, clean up and return. | -`-------------------------------------------------------*/ -yyreturn: - if (yychar != WXPARSEREMPTY) - { - /* Make sure we have latest lookahead translation. See comments at - user semantic actions for why this is necessary. */ - yytoken = YYTRANSLATE (yychar); - yydestruct ("Cleanup: discarding lookahead", - yytoken, &yylval); - } - /* Do not reclaim the symbols of the rule whose action triggered - this YYABORT or YYACCEPT. */ - YYPOPSTACK (yylen); - YY_STACK_PRINT (yyss, yyssp); - while (yyssp != yyss) - { - yydestruct ("Cleanup: popping", - YY_ACCESSING_SYMBOL (+*yyssp), yyvsp); - YYPOPSTACK (1); - } -#ifndef yyoverflow - if (yyss != yyssa) - YYSTACK_FREE (yyss); -#endif - - return yyresult; -} - - diff --git a/Source/Parser/wp_parser.tab.h b/Source/Parser/wp_parser.tab.h deleted file mode 100644 index 60d3baeca02..00000000000 --- a/Source/Parser/wp_parser.tab.h +++ /dev/null @@ -1,109 +0,0 @@ -/* A Bison parser, made by GNU Bison 3.7.5. */ - -/* Bison interface for Yacc-like parsers in C - - Copyright (C) 1984, 1989-1990, 2000-2015, 2018-2021 Free Software Foundation, - Inc. - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see . */ - -/* As a special exception, you may create a larger work that contains - part or all of the Bison parser skeleton and distribute that work - under terms of your choice, so long as that work isn't itself a - parser generator using the skeleton or a modified version thereof - as a parser skeleton. Alternatively, if you modify or redistribute - the parser skeleton itself, you may (at your option) remove this - special exception, which will cause the skeleton and the resulting - Bison output files to be licensed under the GNU General Public - License without this special exception. - - This special exception was added by the Free Software Foundation in - version 2.2 of Bison. */ - -/* DO NOT RELY ON FEATURES THAT ARE NOT DOCUMENTED in the manual, - especially those whose name start with YY_ or yy_. They are - private implementation details that can be changed or removed. */ - -#ifndef YY_WXPARSER_WP_PARSER_TAB_H_INCLUDED -# define YY_WXPARSER_WP_PARSER_TAB_H_INCLUDED -/* Debug traces. */ -#ifndef WXPARSERDEBUG -# if defined YYDEBUG -#if YYDEBUG -# define WXPARSERDEBUG 1 -# else -# define WXPARSERDEBUG 0 -# endif -# else /* ! defined YYDEBUG */ -# define WXPARSERDEBUG 0 -# endif /* ! defined YYDEBUG */ -#endif /* ! defined WXPARSERDEBUG */ -#if WXPARSERDEBUG -extern int wxparserdebug; -#endif - -/* Token kinds. */ -#ifndef WXPARSERTOKENTYPE -# define WXPARSERTOKENTYPE - enum wxparsertokentype - { - WXPARSEREMPTY = -2, - WXPARSEREOF = 0, /* "end of file" */ - WXPARSERerror = 256, /* error */ - WXPARSERUNDEF = 257, /* "invalid token" */ - NODE = 258, /* NODE */ - NUMBER = 259, /* NUMBER */ - SYMBOL = 260, /* SYMBOL */ - F1 = 261, /* F1 */ - F2 = 262, /* F2 */ - F3 = 263, /* F3 */ - EOL = 264, /* EOL */ - POW = 265, /* "**" */ - GEQ = 266, /* ">=" */ - LEQ = 267, /* "<=" */ - EQ = 268, /* "==" */ - NEQ = 269, /* "!=" */ - AND = 270, /* "and" */ - OR = 271, /* "or" */ - NEG = 272, /* NEG */ - UPLUS = 273 /* UPLUS */ - }; - typedef enum wxparsertokentype wxparsertoken_kind_t; -#endif - -/* Value type. */ -#if ! defined WXPARSERSTYPE && ! defined WXPARSERSTYPE_IS_DECLARED -union WXPARSERSTYPE -{ - - struct wp_node* n; - amrex_real d; - struct wp_symbol* s; - enum wp_f1_t f1; - enum wp_f2_t f2; - enum wp_f3_t f3; - - -}; -typedef union WXPARSERSTYPE WXPARSERSTYPE; -# define WXPARSERSTYPE_IS_TRIVIAL 1 -# define WXPARSERSTYPE_IS_DECLARED 1 -#endif - - -extern WXPARSERSTYPE wxparserlval; - -int wxparserparse (void); - -#endif /* !YY_WXPARSER_WP_PARSER_TAB_H_INCLUDED */ diff --git a/Source/Parser/wp_parser.y b/Source/Parser/wp_parser.y deleted file mode 100644 index 5b6c7e14b97..00000000000 --- a/Source/Parser/wp_parser.y +++ /dev/null @@ -1,103 +0,0 @@ - -%{ - #include - #include - #include - #include "wp_parser_y.h" - int wxparserlex (void); -%} - -/* We do not need to make this reentrant safe, because we use flex and - bison for generating AST only and this part doesn't need to be - thread safe. -*/ -/*%define api.pure full */ -%define api.prefix {wxparser} - -/* This is the type returned by functions wp_new* declared in - wp_parser_y.h. See also bison rules at the end of this file. -*/ -%union { - struct wp_node* n; - amrex_real d; - struct wp_symbol* s; - enum wp_f1_t f1; - enum wp_f2_t f2; - enum wp_f3_t f3; -} - -/* Define tokens. They are used by flex too. */ -%token NODE -%token NUMBER -%token SYMBOL -%token F1 -%token F2 -%token F3 -%token EOL -%token POW "**" '^' -%token GEQ ">=" -%token LEQ "<=" -%token EQ "==" -%token NEQ "!=" -%token AND "and" -%token OR "or" - -%nonassoc F1 F2 F3 -%right '=' -%left OR -%left AND -%left EQ NEQ -%left '<' '>' GEQ LEQ -%left '+' '-' -%left '*' '/' -%nonassoc NEG UPLUS -%right POW - -/* This specifies the type of `exp` (i.e., struct wp_node*). Rules - specified later pass `exp` to wp_new* functions declared in - wp_parser_y.h. -*/ -%type exp - -%start input - -%% - -/* Given `\n` terminated input, a tree is generated and passed to - * function wp_defexpr defined in wp_parser_y.c. - */ -input: - %empty -| input exp EOL { - wp_defexpr($2); - } -; - -/* Enum types WP_ADD, WP_SUB, etc. are defined in wp_parser_y.h. - * Functions wp_new* are also declared in that file. - */ -exp: - NUMBER { $$ = wp_newnumber($1); } -| SYMBOL { $$ = wp_newsymbol($1); } -| exp '+' exp { $$ = wp_newnode(WP_ADD, $1, $3); } -| exp '-' exp { $$ = wp_newnode(WP_SUB, $1, $3); } -| exp '*' exp { $$ = wp_newnode(WP_MUL, $1, $3); } -| exp '/' exp { $$ = wp_newnode(WP_DIV, $1, $3); } -| '(' exp ')' { $$ = $2; } -| exp '<' exp { $$ = wp_newf2(WP_LT, $1, $3); } -| exp '>' exp { $$ = wp_newf2(WP_GT, $1, $3); } -| exp LEQ exp { $$ = wp_newf2(WP_LEQ, $1, $3); } -| exp GEQ exp { $$ = wp_newf2(WP_GEQ, $1, $3); } -| exp EQ exp { $$ = wp_newf2(WP_EQ, $1, $3); } -| exp NEQ exp { $$ = wp_newf2(WP_NEQ, $1, $3); } -| exp AND exp { $$ = wp_newf2(WP_AND, $1, $3); } -| exp OR exp { $$ = wp_newf2(WP_OR, $1, $3); } -| '-'exp %prec NEG { $$ = wp_newnode(WP_NEG, $2, NULL); } -| '+'exp %prec UPLUS { $$ = $2; } -| exp POW exp { $$ = wp_newf2(WP_POW, $1, $3); } -| F1 '(' exp ')' { $$ = wp_newf1($1, $3); } -| F2 '(' exp ',' exp ')' { $$ = wp_newf2($1, $3, $5); } -| F3 '(' exp ',' exp ',' exp ')' { $$ = wp_newf3($1, $3, $5, $7); } -; - -%% diff --git a/Source/Parser/wp_parser_c.cpp b/Source/Parser/wp_parser_c.cpp deleted file mode 100644 index fe217fdcc83..00000000000 --- a/Source/Parser/wp_parser_c.cpp +++ /dev/null @@ -1,13 +0,0 @@ -#include "wp_parser_c.h" -#include "wp_parser.lex.h" -#include "wp_parser.tab.h" - -struct wp_parser* -wp_c_parser_new (char const* body) -{ - YY_BUFFER_STATE buffer = wxparser_scan_string(body); - wxparserparse(); - struct wp_parser* parser = wp_parser_new(); - wxparser_delete_buffer(buffer); - return parser; -} diff --git a/Source/Parser/wp_parser_c.h b/Source/Parser/wp_parser_c.h deleted file mode 100644 index 92c8a5c6774..00000000000 --- a/Source/Parser/wp_parser_c.h +++ /dev/null @@ -1,390 +0,0 @@ -#ifndef WP_PARSER_C_H_ -#define WP_PARSER_C_H_ - -#include "wp_parser_y.h" - -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include -#include - -struct wp_parser* wp_c_parser_new (char const* function_body); - -#ifdef AMREX_USE_GPU - -template = 0> -AMREX_GPU_DEVICE AMREX_NO_INLINE -void wp_ast_update_device_ptr (struct wp_node* node, char* droot, char* hroot) -{ - switch (node->type) - { - case WP_NUMBER: - break; - case WP_SYMBOL: - { - auto p = (struct wp_symbol*)node; - p->name = droot + (p->name - hroot); - break; - } - case WP_ADD: - case WP_SUB: - case WP_MUL: - case WP_DIV: - { - node->l = (wp_node*)(droot + ((char*)node->l - hroot)); - node->r = (wp_node*)(droot + ((char*)node->r - hroot)); - wp_ast_update_device_ptr(node->l, droot, hroot); - wp_ast_update_device_ptr(node->r, droot, hroot); - break; - } - case WP_NEG: - { - node->l = (wp_node*)(droot + ((char*)node->l - hroot)); - wp_ast_update_device_ptr(node->l, droot, hroot); - break; - } - case WP_F1: - { - auto p = (struct wp_f1*)node; - p->l = (wp_node*)(droot + ((char*)p->l - hroot)); - wp_ast_update_device_ptr(p->l, droot, hroot); - break; - } - case WP_F2: - { - auto p = (struct wp_f2*)node; - p->l = (wp_node*)(droot + ((char*)p->l - hroot)); - p->r = (wp_node*)(droot + ((char*)p->r - hroot)); - wp_ast_update_device_ptr(p->l, droot, hroot); - wp_ast_update_device_ptr(p->r, droot, hroot); - break; - } - case WP_F3: - { - auto p = (struct wp_f3*)node; - p->n1 = (wp_node*)(droot + ((char*)p->n1 - hroot)); - p->n2 = (wp_node*)(droot + ((char*)p->n2 - hroot)); - p->n3 = (wp_node*)(droot + ((char*)p->n3 - hroot)); - wp_ast_update_device_ptr(p->n1, droot, hroot); - wp_ast_update_device_ptr(p->n2, droot, hroot); - wp_ast_update_device_ptr(p->n3, droot, hroot); - break; - } - case WP_ADD_VP: - case WP_ADD_PP: - case WP_SUB_VP: - case WP_SUB_PP: - case WP_MUL_VP: - case WP_MUL_PP: - case WP_DIV_VP: - case WP_DIV_PP: - case WP_NEG_P: - { - // No need to update node->l and node->r that contain a string for - // variable name because we don't need them for device code. - break; - } - default: - { -#if AMREX_DEVICE_COMPILE - AMREX_DEVICE_PRINTF("wp_ast_update_device_ptr: unknown node type %d\n", - static_cast(node->type)); - amrex::Abort(); -#endif - } - } -} - -template = 0> -AMREX_GPU_DEVICE AMREX_NO_INLINE -void wp_ast_update_device_ptr (struct wp_node*, char*, char*) -{ -#if AMREX_DEVICE_COMPILE - AMREX_DEVICE_PRINTF("wp_ast_update_device_ptr: WARPX_PARSER_DEPTH %d not big enough\n", - WARPX_PARSER_DEPTH); - amrex::Abort(); -#endif -} - -#endif - -template = 0> -AMREX_GPU_HOST_DEVICE -#ifdef AMREX_USE_GPU -AMREX_NO_INLINE -#endif -amrex::Real -wp_ast_eval (struct wp_node* node, amrex::Real const* x) -{ - amrex::Real result = 0.0; - - switch (node->type) - { - case WP_NUMBER: - { - result = ((struct wp_number*)node)->value; - break; - } - case WP_SYMBOL: - { -#if AMREX_DEVICE_COMPILE - int i =((struct wp_symbol*)node)->ip.i; - result = x[i]; -#else - result = *(((struct wp_symbol*)node)->ip.p); -#endif - break; - } - case WP_ADD: - { - result = wp_ast_eval(node->l,x) + wp_ast_eval(node->r,x); - break; - } - case WP_SUB: - { - result = wp_ast_eval(node->l,x) - wp_ast_eval(node->r,x); - break; - } - case WP_MUL: - { - result = wp_ast_eval(node->l,x) * wp_ast_eval(node->r,x); - break; - } - case WP_DIV: - { - result = wp_ast_eval(node->l,x) / wp_ast_eval(node->r,x); - break; - } - case WP_NEG: - { - result = -wp_ast_eval(node->l,x); - break; - } - case WP_F1: - { - result = wp_call_f1(((struct wp_f1*)node)->ftype, - wp_ast_eval(((struct wp_f1*)node)->l,x)); - break; - } - case WP_F2: - { - result = wp_call_f2(((struct wp_f2*)node)->ftype, - wp_ast_eval(((struct wp_f2*)node)->l,x), - wp_ast_eval(((struct wp_f2*)node)->r,x)); - break; - } - case WP_F3: - { - if (wp_ast_eval(((struct wp_f3*)node)->n1,x) != amrex::Real(0.)) { - result = wp_ast_eval(((struct wp_f3*)node)->n2,x); - } else { - result = wp_ast_eval(((struct wp_f3*)node)->n3,x); - } - break; - } - case WP_ADD_VP: - { -#if AMREX_DEVICE_COMPILE - int i = node->rip.i; - result = node->lvp.v + x[i]; -#else - result = node->lvp.v + *(node->rip.p); -#endif - break; - } - case WP_ADD_PP: - { -#if AMREX_DEVICE_COMPILE - int i = node->lvp.ip.i; - int j = node->rip.i; - result = x[i] + x[j]; -#else - result = *(node->lvp.ip.p) + *(node->rip.p); -#endif - break; - } - case WP_SUB_VP: - { -#if AMREX_DEVICE_COMPILE - int i = node->rip.i; - result = node->lvp.v - x[i]; -#else - result = node->lvp.v - *(node->rip.p); -#endif - break; - } - case WP_SUB_PP: - { -#if AMREX_DEVICE_COMPILE - int i = node->lvp.ip.i; - int j = node->rip.i; - result = x[i] - x[j]; -#else - result = *(node->lvp.ip.p) - *(node->rip.p); -#endif - break; - } - case WP_MUL_VP: - { -#if AMREX_DEVICE_COMPILE - int i = node->rip.i; - result = node->lvp.v * x[i]; -#else - result = node->lvp.v * *(node->rip.p); -#endif - break; - } - case WP_MUL_PP: - { -#if AMREX_DEVICE_COMPILE - int i = node->lvp.ip.i; - int j = node->rip.i; - result = x[i] * x[j]; -#else - result = *(node->lvp.ip.p) * *(node->rip.p); -#endif - break; - } - case WP_DIV_VP: - { -#if AMREX_DEVICE_COMPILE - int i = node->rip.i; - result = node->lvp.v / x[i]; -#else - result = node->lvp.v / *(node->rip.p); -#endif - break; - } - case WP_DIV_PP: - { -#if AMREX_DEVICE_COMPILE - int i = node->lvp.ip.i; - int j = node->rip.i; - result = x[i] / x[j]; -#else - result = *(node->lvp.ip.p) / *(node->rip.p); -#endif - break; - } - case WP_NEG_P: - { -#if AMREX_DEVICE_COMPILE - int i = node->rip.i; - result = -x[i]; -#else - result = -*(node->lvp.ip.p); -#endif - break; - } - default: - { -#if AMREX_DEVICE_COMPILE - AMREX_DEVICE_PRINTF("wp_ast_eval: unknown node type %d\n", node->type); -#else - amrex::AllPrint() << "wp_ast_eval: unknown node type " << node->type << "\n"; -#endif - } - } - - // check for NaN & Infs, e.g. if individual terms invalidate the whole - // expression in piecewise constructed functions, etc. - if -#if __cplusplus >= 201703L - constexpr -#endif - (Depth == 0) - { - if (!amrex::Math::isfinite(result)) - { - constexpr char const * const err_msg = - "wp_ast_eval: function parser encountered an invalid result value (NaN or Inf)!"; -#if AMREX_DEVICE_COMPILE - AMREX_DEVICE_PRINTF("%s\n", err_msg); -#else - amrex::AllPrint() << err_msg << "\n"; -#endif - amrex::Abort(err_msg); - } - } - - return result; -} - -template = 0> -AMREX_GPU_HOST_DEVICE -#ifdef AMREX_USE_GPU -AMREX_NO_INLINE -#endif -amrex::Real -wp_ast_eval (struct wp_node* node, amrex::Real const* x) -{ -#if AMREX_DEVICE_COMPILE - AMREX_DEVICE_PRINTF("wp_ast_eval: WARPX_PARSER_DEPTH %d not big enough\n", - WARPX_PARSER_DEPTH); -#else - amrex::AllPrint() << "wp_ast_eval: WARPX_PARSER_DEPTH" << WARPX_PARSER_DEPTH - << "not big enough\n"; -#endif - amrex::ignore_unused(node, x); - return 0.; -} - -inline -void -wp_ast_get_symbols (struct wp_node* node, std::set& symbols) -{ - switch (node->type) - { - case WP_NUMBER: - break; - case WP_SYMBOL: - symbols.emplace(((struct wp_symbol*)node)->name); - break; - case WP_ADD: - case WP_SUB: - case WP_MUL: - case WP_DIV: - case WP_ADD_PP: - case WP_SUB_PP: - case WP_MUL_PP: - case WP_DIV_PP: - wp_ast_get_symbols(node->l, symbols); - wp_ast_get_symbols(node->r, symbols); - break; - case WP_NEG: - case WP_NEG_P: - wp_ast_get_symbols(node->l, symbols); - break; - case WP_F1: - wp_ast_get_symbols(((struct wp_f1*)node)->l, symbols); - break; - case WP_F2: - wp_ast_get_symbols(((struct wp_f2*)node)->l, symbols); - wp_ast_get_symbols(((struct wp_f2*)node)->r, symbols); - break; - case WP_F3: - wp_ast_get_symbols(((struct wp_f3*)node)->n1, symbols); - wp_ast_get_symbols(((struct wp_f3*)node)->n2, symbols); - wp_ast_get_symbols(((struct wp_f3*)node)->n3, symbols); - break; - case WP_ADD_VP: - case WP_SUB_VP: - case WP_MUL_VP: - case WP_DIV_VP: - wp_ast_get_symbols(node->r, symbols); - break; - default: - amrex::AllPrint() << "wp_ast_get_symbols: unknown node type " << node->type << "\n"; - } -} - -#endif diff --git a/Source/Parser/wp_parser_y.cpp b/Source/Parser/wp_parser_y.cpp deleted file mode 100644 index a3f7386c824..00000000000 --- a/Source/Parser/wp_parser_y.cpp +++ /dev/null @@ -1,1188 +0,0 @@ -#include "wp_parser_y.h" -#include "wp_parser.tab.h" - -#include - -static struct wp_node* wp_root = NULL; - -/* This is called by a bison rule to store the original AST in a - * static variable. Accessing this directly is not thread safe. So - * this will be duplicated later for each thread. - */ -void -wp_defexpr (struct wp_node* body) -{ - wp_root = body; -} - -struct wp_node* -wp_newnumber (amrex_real d) -{ - struct wp_number* r = (struct wp_number*) std::malloc(sizeof(struct wp_number)); - r->type = WP_NUMBER; - r->value = d; - return (struct wp_node*) r; -} - -struct wp_symbol* -wp_makesymbol (char* name) -{ - struct wp_symbol* symbol = (struct wp_symbol*) std::malloc(sizeof(struct wp_symbol)); - symbol->type = WP_SYMBOL; - symbol->name = strdup(name); - symbol->ip.p = nullptr; - return symbol; -} - -struct wp_node* -wp_newsymbol (struct wp_symbol* symbol) -{ - return (struct wp_node*) symbol; -} - -struct wp_node* -wp_newnode (enum wp_node_t type, struct wp_node* l, struct wp_node* r) -{ - struct wp_node* tmp = (struct wp_node*) std::malloc(sizeof(struct wp_node)); - tmp->type = type; - tmp->l = l; - tmp->r = r; - return tmp; -} - -struct wp_node* -wp_newf1 (enum wp_f1_t ftype, struct wp_node* l) -{ - struct wp_f1* tmp = (struct wp_f1*) std::malloc(sizeof(struct wp_f1)); - tmp->type = WP_F1; - tmp->l = l; - tmp->ftype = ftype; - return (struct wp_node*) tmp; -} - -struct wp_node* -wp_newf2 (enum wp_f2_t ftype, struct wp_node* l, struct wp_node* r) -{ - struct wp_f2* tmp = (struct wp_f2*) std::malloc(sizeof(struct wp_f2)); - tmp->type = WP_F2; - tmp->l = l; - tmp->r = r; - tmp->ftype = ftype; - return (struct wp_node*) tmp; -} - -struct wp_node* -wp_newf3 (enum wp_f3_t ftype, struct wp_node* n1, struct wp_node* n2, - struct wp_node* n3) -{ - struct wp_f3* tmp = (struct wp_f3*) std::malloc(sizeof(struct wp_f3)); - tmp->type = WP_F3; - tmp->n1 = n1; - tmp->n2 = n2; - tmp->n3 = n3; - tmp->ftype = ftype; - return (struct wp_node*) tmp; -} - -void -wxparsererror (char const *s, ...) -{ - std::va_list vl; - va_start(vl, s); - std::vfprintf(stderr, s, vl); - std::fprintf(stderr, "\n"); - va_end(vl); -} - -/*******************************************************************/ - -struct wp_parser* -wp_parser_new (void) -{ - struct wp_parser* my_parser = (struct wp_parser*) std::malloc(sizeof(struct wp_parser)); - - my_parser->sz_mempool = wp_ast_size(wp_root); - my_parser->p_root = std::malloc(my_parser->sz_mempool); - my_parser->p_free = my_parser->p_root; - - my_parser->ast = wp_parser_ast_dup(my_parser, wp_root,1); /* 1: free the source wp_root */ - - if ((char*)my_parser->p_root + my_parser->sz_mempool != (char*)my_parser->p_free) { - amrex::Abort("wp_parser_new: error in memory size"); - } - - wp_ast_optimize(my_parser->ast); - - return my_parser; -} - -void -wp_parser_delete (struct wp_parser* parser) -{ - std::free(parser->p_root); - std::free(parser); -} - -static size_t -wp_aligned_size (size_t N) -{ - const unsigned int align_size = 16; - size_t x = N + (align_size-1); - x -= x & (align_size-1); - return x; -} - -static -void* -wp_parser_allocate (struct wp_parser* my_parser, size_t N) -{ - void* r = my_parser->p_free; - my_parser->p_free = (char*)r + wp_aligned_size(N); - return r; -} - -struct wp_parser* -wp_parser_dup (struct wp_parser* source) -{ - struct wp_parser* dest = (struct wp_parser*) std::malloc(sizeof(struct wp_parser)); - dest->sz_mempool = source->sz_mempool; - dest->p_root = std::malloc(dest->sz_mempool); - dest->p_free = dest->p_root; - - dest->ast = wp_parser_ast_dup(dest, source->ast, 0); /* 0: don't free the source */ - - return dest; -} - -size_t -wp_ast_size (struct wp_node* node) -{ - size_t result = 0; - - switch (node->type) - { - case WP_NUMBER: - result = wp_aligned_size(sizeof(struct wp_number)); - break; - case WP_SYMBOL: - result = wp_aligned_size(sizeof(struct wp_symbol)) - + wp_aligned_size(strlen(((struct wp_symbol*)node)->name)+1); - break; - case WP_ADD: - case WP_SUB: - case WP_MUL: - case WP_DIV: - case WP_ADD_PP: - case WP_SUB_PP: - case WP_MUL_PP: - case WP_DIV_PP: - result = wp_aligned_size(sizeof(struct wp_node)) - + wp_ast_size(node->l) + wp_ast_size(node->r); - break; - case WP_NEG: - result = wp_aligned_size(sizeof(struct wp_node)) - + wp_ast_size(node->l); - break; - case WP_F1: - result = wp_aligned_size(sizeof(struct wp_f1)) - + wp_ast_size(node->l); - break; - case WP_F2: - result = wp_aligned_size(sizeof(struct wp_f2)) - + wp_ast_size(node->l) + wp_ast_size(node->r); - break; - case WP_F3: - result = wp_aligned_size(sizeof(struct wp_f3)) - + wp_ast_size(((struct wp_f3*)node)->n1) - + wp_ast_size(((struct wp_f3*)node)->n2) - + wp_ast_size(((struct wp_f3*)node)->n3); - break; - case WP_ADD_VP: - case WP_SUB_VP: - case WP_MUL_VP: - case WP_DIV_VP: - result = wp_aligned_size(sizeof(struct wp_node)) - + wp_ast_size(node->r); - break; - case WP_NEG_P: - result = wp_aligned_size(sizeof(struct wp_node)) - + wp_ast_size(node->l); - break; - default: - amrex::AllPrint() << "wp_ast_size: unknown node type " <type << "\n"; - amrex::Abort(); - } - - return result; -} - -struct wp_node* -wp_parser_ast_dup (struct wp_parser* my_parser, struct wp_node* node, int move) -{ - void* result = nullptr; - - switch (node->type) - { - case WP_NUMBER: - result = wp_parser_allocate(my_parser, sizeof(struct wp_number)); - memcpy(result, node , sizeof(struct wp_number)); - break; - case WP_SYMBOL: - result = wp_parser_allocate(my_parser, sizeof(struct wp_symbol)); - memcpy(result, node , sizeof(struct wp_symbol)); - ((struct wp_symbol*)result)->name = (char*) wp_parser_allocate - (my_parser, strlen(((struct wp_symbol*)node)->name)+1); - strcpy(((struct wp_symbol*)result)->name, - ((struct wp_symbol*)node )->name); - break; - case WP_ADD: - case WP_SUB: - case WP_MUL: - case WP_DIV: - case WP_ADD_PP: - case WP_SUB_PP: - case WP_MUL_PP: - case WP_DIV_PP: - result = wp_parser_allocate(my_parser, sizeof(struct wp_node)); - memcpy(result, node , sizeof(struct wp_node)); - ((struct wp_node*)result)->l = wp_parser_ast_dup(my_parser, node->l, move); - ((struct wp_node*)result)->r = wp_parser_ast_dup(my_parser, node->r, move); - break; - case WP_NEG: - result = wp_parser_allocate(my_parser, sizeof(struct wp_node)); - memcpy(result, node , sizeof(struct wp_node)); - ((struct wp_node*)result)->l = wp_parser_ast_dup(my_parser, node->l, move); - ((struct wp_node*)result)->r = NULL; - break; - case WP_F1: - result = wp_parser_allocate(my_parser, sizeof(struct wp_f1)); - memcpy(result, node , sizeof(struct wp_f1)); - ((struct wp_f1*)result)->l = wp_parser_ast_dup(my_parser, ((struct wp_f1*)node)->l, move); - break; - case WP_F2: - result = wp_parser_allocate(my_parser, sizeof(struct wp_f2)); - memcpy(result, node , sizeof(struct wp_f2)); - ((struct wp_f2*)result)->l = wp_parser_ast_dup(my_parser, ((struct wp_f2*)node)->l, move); - ((struct wp_f2*)result)->r = wp_parser_ast_dup(my_parser, ((struct wp_f2*)node)->r, move); - break; - case WP_F3: - result = wp_parser_allocate(my_parser, sizeof(struct wp_f3)); - memcpy(result, node , sizeof(struct wp_f3)); - ((struct wp_f3*)result)->n1 = wp_parser_ast_dup(my_parser, ((struct wp_f3*)node)->n1, move); - ((struct wp_f3*)result)->n2 = wp_parser_ast_dup(my_parser, ((struct wp_f3*)node)->n2, move); - ((struct wp_f3*)result)->n3 = wp_parser_ast_dup(my_parser, ((struct wp_f3*)node)->n3, move); - break; - case WP_ADD_VP: - case WP_SUB_VP: - case WP_MUL_VP: - case WP_DIV_VP: - result = wp_parser_allocate(my_parser, sizeof(struct wp_node)); - memcpy(result, node , sizeof(struct wp_node)); - ((struct wp_node*)result)->r = wp_parser_ast_dup(my_parser, node->r, move); - break; - case WP_NEG_P: - result = wp_parser_allocate(my_parser, sizeof(struct wp_node)); - memcpy(result, node , sizeof(struct wp_node)); - ((struct wp_node*)result)->l = wp_parser_ast_dup(my_parser, node->l, move); - break; - default: - amrex::AllPrint() << "wp_ast_dup: unknown node type " << node->type << "\n"; - amrex::Abort(); - } - if (move) { - /* Note that we only do this on the original AST. We do not - * need to call free for AST stored in wp_parser because the - * memory is not allocated with std::malloc directly. - */ - if (node->type == WP_SYMBOL) { - std::free(((struct wp_symbol*)node)->name); - } - std::free((void*)node); - } - return (struct wp_node*)result; -} - -#define WP_MOVEUP_R(node, v) \ - struct wp_node* n = node->r->r; \ - amrex_real* p = node->r->rip.p; \ - node->r = n; \ - node->lvp.v = v; \ - node->rip.p = p; -#define WP_MOVEUP_L(node, v) \ - struct wp_node* n = node->l->r; \ - amrex_real* p = node->l->rip.p; \ - node->r = n; \ - node->lvp.v = v; \ - node->rip.p = p; -#define WP_EVAL_R(node) node->r->lvp.v -#define WP_EVAL_L(node) node->l->lvp.v - -#define WP_NEG_MOVEUP(node) \ - node->r = node->l->r; \ - node->lvp.v = -node->l->lvp.v; \ - node->rip.p = node->l->rip.p; - -void -wp_ast_optimize (struct wp_node* node) -{ - /* No need to free memory because we only call this on ASTs in - * wp_parser that are allocated from the memory pool. - */ - switch (node->type) - { - case WP_NUMBER: - case WP_SYMBOL: - break; - case WP_ADD: - case WP_ADD_PP: - wp_ast_optimize(node->l); - wp_ast_optimize(node->r); - if (node->l->type == WP_NUMBER && - node->r->type == WP_NUMBER) - { - amrex_real v = ((struct wp_number*)(node->l))->value - + ((struct wp_number*)(node->r))->value; - ((struct wp_number*)node)->type = WP_NUMBER; - ((struct wp_number*)node)->value = v; - } - else if (node->l->type == WP_NUMBER && - node->r->type == WP_SYMBOL) - { - node->lvp.v = ((struct wp_number*)(node->l))->value; - node->rip.p = ((struct wp_symbol*)(node->r))->ip.p; - node->type = WP_ADD_VP; - } - else if (node->l->type == WP_SYMBOL && - node->r->type == WP_NUMBER) - { - node->lvp.v = ((struct wp_number*)(node->r))->value; - node->rip.p = ((struct wp_symbol*)(node->l))->ip.p; - node->r = node->l; - node->type = WP_ADD_VP; - } - else if (node->l->type == WP_SYMBOL && - node->r->type == WP_SYMBOL) - { - node->lvp.ip.p = ((struct wp_symbol*)(node->l))->ip.p; - node->rip.p = ((struct wp_symbol*)(node->r))->ip.p; - node->type = WP_ADD_PP; - } - else if (node->l->type == WP_NUMBER && - node->r->type == WP_ADD_VP) - { - amrex_real v = ((struct wp_number*)(node->l))->value + WP_EVAL_R(node); - WP_MOVEUP_R(node, v); - node->type = WP_ADD_VP; - } - else if (node->l->type == WP_NUMBER && - node->r->type == WP_SUB_VP) - { - amrex_real v = ((struct wp_number*)(node->l))->value + WP_EVAL_R(node); - WP_MOVEUP_R(node, v); - node->type = WP_SUB_VP; - } - else if (node->l->type == WP_ADD_VP && - node->r->type == WP_NUMBER) - { - amrex_real v = WP_EVAL_L(node) + ((struct wp_number*)(node->r))->value; - WP_MOVEUP_L(node, v); - node->type = WP_ADD_VP; - } - else if (node->l->type == WP_SUB_VP && - node->r->type == WP_NUMBER) - { - amrex_real v = WP_EVAL_L(node) + ((struct wp_number*)(node->r))->value; - WP_MOVEUP_L(node, v); - node->type = WP_SUB_VP; - } - break; - case WP_SUB: - case WP_SUB_PP: - wp_ast_optimize(node->l); - wp_ast_optimize(node->r); - if (node->l->type == WP_NUMBER && - node->r->type == WP_NUMBER) - { - amrex_real v = ((struct wp_number*)(node->l))->value - - ((struct wp_number*)(node->r))->value; - ((struct wp_number*)node)->type = WP_NUMBER; - ((struct wp_number*)node)->value = v; - } - else if (node->l->type == WP_NUMBER && - node->r->type == WP_SYMBOL) - { - node->lvp.v = ((struct wp_number*)(node->l))->value; - node->rip.p = ((struct wp_symbol*)(node->r))->ip.p; - node->type = WP_SUB_VP; - } - else if (node->l->type == WP_SYMBOL && - node->r->type == WP_NUMBER) - { - node->lvp.v = -((struct wp_number*)(node->r))->value; - node->rip.p = ((struct wp_symbol*)(node->l))->ip.p; - node->r = node->l; - node->type = WP_ADD_VP; - } - else if (node->l->type == WP_SYMBOL && - node->r->type == WP_SYMBOL) - { - node->lvp.ip.p = ((struct wp_symbol*)(node->l))->ip.p; - node->rip.p = ((struct wp_symbol*)(node->r))->ip.p; - node->type = WP_SUB_PP; - } - else if (node->l->type == WP_NUMBER && - node->r->type == WP_ADD_VP) - { - amrex_real v = ((struct wp_number*)(node->l))->value - WP_EVAL_R(node); - WP_MOVEUP_R(node, v); - node->type = WP_SUB_VP; - } - else if (node->l->type == WP_NUMBER && - node->r->type == WP_SUB_VP) - { - amrex_real v = ((struct wp_number*)(node->l))->value - WP_EVAL_R(node); - WP_MOVEUP_R(node, v); - node->type = WP_ADD_VP; - } - else if (node->l->type == WP_ADD_VP && - node->r->type == WP_NUMBER) - { - amrex_real v = WP_EVAL_L(node) - ((struct wp_number*)(node->r))->value; - WP_MOVEUP_L(node, v); - node->type = WP_ADD_VP; - } - else if (node->l->type == WP_SUB_VP && - node->r->type == WP_NUMBER) - { - amrex_real v = WP_EVAL_L(node) - ((struct wp_number*)(node->r))->value; - WP_MOVEUP_L(node, v); - node->type = WP_SUB_VP; - } - break; - case WP_MUL: - case WP_MUL_PP: - wp_ast_optimize(node->l); - wp_ast_optimize(node->r); - if (node->l->type == WP_NUMBER && - node->r->type == WP_NUMBER) - { - amrex_real v = ((struct wp_number*)(node->l))->value - * ((struct wp_number*)(node->r))->value; - ((struct wp_number*)node)->type = WP_NUMBER; - ((struct wp_number*)node)->value = v; - } - else if (node->l->type == WP_NUMBER && - node->r->type == WP_SYMBOL) - { - node->lvp.v = ((struct wp_number*)(node->l))->value; - node->rip.p = ((struct wp_symbol*)(node->r))->ip.p; - node->type = WP_MUL_VP; - } - else if (node->l->type == WP_SYMBOL && - node->r->type == WP_NUMBER) - { - node->lvp.v = ((struct wp_number*)(node->r))->value; - node->rip.p = ((struct wp_symbol*)(node->l))->ip.p; - node->r = node->l; - node->type = WP_MUL_VP; - } - else if (node->l->type == WP_SYMBOL && - node->r->type == WP_SYMBOL) - { - node->lvp.ip.p = ((struct wp_symbol*)(node->l))->ip.p; - node->rip.p = ((struct wp_symbol*)(node->r))->ip.p; - node->type = WP_MUL_PP; - } - else if (node->l->type == WP_NUMBER && - node->r->type == WP_MUL_VP) - { - amrex_real v = ((struct wp_number*)(node->l))->value * WP_EVAL_R(node); - WP_MOVEUP_R(node, v); - node->type = WP_MUL_VP; - } - else if (node->l->type == WP_NUMBER && - node->r->type == WP_DIV_VP) - { - amrex_real v = ((struct wp_number*)(node->l))->value * WP_EVAL_R(node); - WP_MOVEUP_R(node, v); - node->type = WP_DIV_VP; - } - else if (node->l->type == WP_MUL_VP && - node->r->type == WP_NUMBER) - { - amrex_real v = WP_EVAL_L(node) * ((struct wp_number*)(node->r))->value; - WP_MOVEUP_L(node, v); - node->type = WP_MUL_VP; - } - else if (node->l->type == WP_DIV_VP && - node->r->type == WP_NUMBER) - { - amrex_real v = WP_EVAL_L(node) * ((struct wp_number*)(node->r))->value; - WP_MOVEUP_L(node, v); - node->type = WP_DIV_VP; - } - break; - case WP_DIV: - case WP_DIV_PP: - wp_ast_optimize(node->l); - wp_ast_optimize(node->r); - if (node->l->type == WP_NUMBER && - node->r->type == WP_NUMBER) - { - amrex_real v = ((struct wp_number*)(node->l))->value - / ((struct wp_number*)(node->r))->value; - ((struct wp_number*)node)->type = WP_NUMBER; - ((struct wp_number*)node)->value = v; - } - else if (node->l->type == WP_NUMBER && - node->r->type == WP_SYMBOL) - { - node->lvp.v = ((struct wp_number*)(node->l))->value; - node->rip.p = ((struct wp_symbol*)(node->r))->ip.p; - node->type = WP_DIV_VP; - } - else if (node->l->type == WP_SYMBOL && - node->r->type == WP_NUMBER) - { - node->lvp.v = 1./((struct wp_number*)(node->r))->value; - node->rip.p = ((struct wp_symbol*)(node->l))->ip.p; - node->r = node->l; - node->type = WP_MUL_VP; - } - else if (node->l->type == WP_SYMBOL && - node->r->type == WP_SYMBOL) - { - node->lvp.ip.p = ((struct wp_symbol*)(node->l))->ip.p; - node->rip.p = ((struct wp_symbol*)(node->r))->ip.p; - node->type = WP_DIV_PP; - } - else if (node->l->type == WP_NUMBER && - node->r->type == WP_MUL_VP) - { - amrex_real v = ((struct wp_number*)(node->l))->value / WP_EVAL_R(node); - WP_MOVEUP_R(node, v); - node->type = WP_DIV_VP; - } - else if (node->l->type == WP_NUMBER && - node->r->type == WP_DIV_VP) - { - amrex_real v = ((struct wp_number*)(node->l))->value / WP_EVAL_R(node); - WP_MOVEUP_R(node, v); - node->type = WP_MUL_VP; - } - else if (node->l->type == WP_MUL_VP && - node->r->type == WP_NUMBER) - { - amrex_real v = WP_EVAL_L(node) / ((struct wp_number*)(node->r))->value; - WP_MOVEUP_L(node, v); - node->type = WP_MUL_VP; - } - else if (node->l->type == WP_DIV_VP && - node->r->type == WP_NUMBER) - { - amrex_real v = WP_EVAL_L(node) / ((struct wp_number*)(node->r))->value; - WP_MOVEUP_L(node, v); - node->type = WP_DIV_VP; - } - break; - case WP_NEG: - wp_ast_optimize(node->l); - if (node->l->type == WP_NUMBER) - { - amrex_real v = -((struct wp_number*)(node->l))->value; - ((struct wp_number*)node)->type = WP_NUMBER; - ((struct wp_number*)node)->value = v; - } - else if (node->l->type == WP_SYMBOL) - { - node->lvp.ip.p = ((struct wp_symbol*)(node->l))->ip.p; - node->type = WP_NEG_P; - } - else if (node->l->type == WP_ADD_VP) - { - WP_NEG_MOVEUP(node); - node->type = WP_SUB_VP; - } - else if (node->l->type == WP_SUB_VP) - { - WP_NEG_MOVEUP(node); - node->type = WP_ADD_VP; - } - else if (node->l->type == WP_MUL_VP) - { - WP_NEG_MOVEUP(node); - node->type = WP_MUL_VP; - } - else if (node->l->type == WP_DIV_VP) - { - WP_NEG_MOVEUP(node); - node->type = WP_DIV_VP; - } - break; - case WP_F1: - wp_ast_optimize(node->l); - if (node->l->type == WP_NUMBER) - { - amrex_real v = wp_call_f1 - (((struct wp_f1*)node)->ftype, - ((struct wp_number*)(((struct wp_f1*)node)->l))->value); - ((struct wp_number*)node)->type = WP_NUMBER; - ((struct wp_number*)node)->value = v; - } - break; - case WP_F2: - wp_ast_optimize(node->l); - wp_ast_optimize(node->r); - if (node->l->type == WP_NUMBER && - node->r->type == WP_NUMBER) - { - amrex_real v = wp_call_f2 - (((struct wp_f2*)node)->ftype, - ((struct wp_number*)(((struct wp_f2*)node)->l))->value, - ((struct wp_number*)(((struct wp_f2*)node)->r))->value); - ((struct wp_number*)node)->type = WP_NUMBER; - ((struct wp_number*)node)->value = v; - } - else if (node->r->type == WP_NUMBER && ((struct wp_f2*)node)->ftype == WP_POW) - { - struct wp_node* n = node->l; - amrex_real v = ((struct wp_number*)(node->r))->value; - if (-3.0 == v) { - ((struct wp_f1*)node)->type = WP_F1; - ((struct wp_f1*)node)->l = n; - ((struct wp_f1*)node)->ftype = WP_POW_M3; - } else if (-2.0 == v) { - ((struct wp_f1*)node)->type = WP_F1; - ((struct wp_f1*)node)->l = n; - ((struct wp_f1*)node)->ftype = WP_POW_M2; - } else if (-1.0 == v) { - ((struct wp_f1*)node)->type = WP_F1; - ((struct wp_f1*)node)->l = n; - ((struct wp_f1*)node)->ftype = WP_POW_M1; - } else if (0.0 == v) { - ((struct wp_number*)node)->type = WP_NUMBER; - ((struct wp_number*)node)->value = 1.0; - } else if (1.0 == v) { - ((struct wp_f1*)node)->type = WP_F1; - ((struct wp_f1*)node)->l = n; - ((struct wp_f1*)node)->ftype = WP_POW_P1; - } else if (2.0 == v) { - ((struct wp_f1*)node)->type = WP_F1; - ((struct wp_f1*)node)->l = n; - ((struct wp_f1*)node)->ftype = WP_POW_P2; - } else if (3.0 == v) { - ((struct wp_f1*)node)->type = WP_F1; - ((struct wp_f1*)node)->l = n; - ((struct wp_f1*)node)->ftype = WP_POW_P3; - } - } - break; - case WP_F3: - wp_ast_optimize(((struct wp_f3*)node)->n1); - wp_ast_optimize(((struct wp_f3*)node)->n2); - wp_ast_optimize(((struct wp_f3*)node)->n3); - if (((struct wp_f3*)node)->n1->type == WP_NUMBER && - ((struct wp_f3*)node)->n2->type == WP_NUMBER && - ((struct wp_f3*)node)->n3->type == WP_NUMBER) - { - amrex_real v = wp_call_f3 - (((struct wp_f3*)node)->ftype, - ((struct wp_number*)(((struct wp_f3*)node)->n1))->value, - ((struct wp_number*)(((struct wp_f3*)node)->n2))->value, - ((struct wp_number*)(((struct wp_f3*)node)->n3))->value); - ((struct wp_number*)node)->type = WP_NUMBER; - ((struct wp_number*)node)->value = v; - } - break; - case WP_ADD_VP: - wp_ast_optimize(node->r); - if (node->r->type == WP_NUMBER) - { - amrex_real v = node->lvp.v + ((struct wp_number*)(node->r))->value; - ((struct wp_number*)node)->type = WP_NUMBER; - ((struct wp_number*)node)->value = v; - } - break; - case WP_SUB_VP: - wp_ast_optimize(node->r); - if (node->r->type == WP_NUMBER) - { - amrex_real v = node->lvp.v - ((struct wp_number*)(node->r))->value; - ((struct wp_number*)node)->type = WP_NUMBER; - ((struct wp_number*)node)->value = v; - } - break; - case WP_MUL_VP: - wp_ast_optimize(node->r); - if (node->r->type == WP_NUMBER) - { - amrex_real v = node->lvp.v * ((struct wp_number*)(node->r))->value; - ((struct wp_number*)node)->type = WP_NUMBER; - ((struct wp_number*)node)->value = v; - } - break; - case WP_DIV_VP: - wp_ast_optimize(node->r); - if (node->r->type == WP_NUMBER) - { - amrex_real v = node->lvp.v / ((struct wp_number*)(node->r))->value; - ((struct wp_number*)node)->type = WP_NUMBER; - ((struct wp_number*)node)->value = v; - } - break; - case WP_NEG_P: - wp_ast_optimize(node->l); - if (node->l->type == WP_NUMBER) - { - amrex_real v = -((struct wp_number*)(node->l))->value; - ((struct wp_number*)node)->type = WP_NUMBER; - ((struct wp_number*)node)->value = v; - } - break; - default: - amrex::AllPrint() << "wp_ast_optimize: unknown node type " << node->type << "\n"; - amrex::Abort(); - } -} - -static -void -wp_ast_print_f1 (struct wp_f1* f1) -{ - wp_ast_print(f1->l); - switch (f1->ftype) { - case WP_SQRT: std::printf("SQRT\n"); break; - case WP_EXP: std::printf("EXP\n"); break; - case WP_LOG: std::printf("LOG\n"); break; - case WP_LOG10: std::printf("LOG10\n"); break; - case WP_SIN: std::printf("SIN\n"); break; - case WP_COS: std::printf("COS\n"); break; - case WP_TAN: std::printf("TAN\n"); break; - case WP_ASIN: std::printf("ASIN\n"); break; - case WP_ACOS: std::printf("ACOS\n"); break; - case WP_ATAN: std::printf("ATAN\n"); break; - case WP_SINH: std::printf("SINH\n"); break; - case WP_COSH: std::printf("COSH\n"); break; - case WP_TANH: std::printf("TANH\n"); break; - case WP_ABS: std::printf("ABS\n"); break; - case WP_POW_M3: std::printf("POW(,-3)\n"); break; - case WP_POW_M2: std::printf("POW(,-2)\n"); break; - case WP_POW_M1: std::printf("POW(,-1)\n"); break; - case WP_POW_P1: std::printf("POW(,1)\n"); break; - case WP_POW_P2: std::printf("POW(,2)\n"); break; - case WP_POW_P3: std::printf("POW(,3)\n"); break; - default: - amrex::AllPrint() << "wp_ast+print_f1: Unknow function " << f1->ftype << "\n"; - } -} - -static -void -wp_ast_print_f2 (struct wp_f2* f2) -{ - wp_ast_print(f2->l); - wp_ast_print(f2->r); - switch (f2->ftype) { - case WP_POW: - std::printf("POW\n"); - break; - case WP_GT: - std::printf("GT\n"); - break; - case WP_LT: - std::printf("LT\n"); - break; - case WP_GEQ: - std::printf("GEQ\n"); - break; - case WP_LEQ: - std::printf("LEQ\n"); - break; - case WP_EQ: - std::printf("EQ\n"); - break; - case WP_NEQ: - std::printf("NEQ\n"); - break; - case WP_AND: - std::printf("AND\n"); - break; - case WP_OR: - std::printf("OR\n"); - break; - case WP_HEAVISIDE: - std::printf("HEAVISIDE\n"); - break; - case WP_JN: - std::printf("JN\n"); - break; - case WP_MIN: - std::printf("MIN\n"); - break; - case WP_MAX: - std::printf("MAX\n"); - break; - default: - amrex::AllPrint() << "wp_ast_print_f2: Unknown function " << f2->ftype << "\n"; - } -} - -static -void -wp_ast_print_f3 (struct wp_f3* f3) -{ - wp_ast_print(f3->n1); - wp_ast_print(f3->n2); - wp_ast_print(f3->n3); - switch (f3->ftype) { - case WP_IF: - std::printf("IF\n"); - break; - default: - amrex::AllPrint() << "wp_ast_print_f3: Unknow funciton " << f3->ftype << "\n"; - } -} - -void -wp_ast_print (struct wp_node* node) -{ - switch (node->type) - { - case WP_NUMBER: - std::printf("NUMBER: %.17g\n", ((struct wp_number*)node)->value); - break; - case WP_SYMBOL: - std::printf("VARIABLE: %s\n", ((struct wp_symbol*)node)->name); - break; - case WP_ADD: - wp_ast_print(node->l); - wp_ast_print(node->r); - std::printf("ADD\n"); - break; - case WP_SUB: - wp_ast_print(node->l); - wp_ast_print(node->r); - std::printf("SUB\n"); - break; - case WP_MUL: - wp_ast_print(node->l); - wp_ast_print(node->r); - std::printf("MUL\n"); - break; - case WP_DIV: - wp_ast_print(node->l); - wp_ast_print(node->r); - std::printf("DIV\n"); - break; - case WP_NEG: - wp_ast_print(node->l); - std::printf("NEG\n"); - break; - case WP_F1: - wp_ast_print_f1((struct wp_f1*)node); - break; - case WP_F2: - wp_ast_print_f2((struct wp_f2*)node); - break; - case WP_F3: - wp_ast_print_f3((struct wp_f3*)node); - break; - case WP_ADD_VP: - std::printf("ADD: %.17g %s\n", node->lvp.v, ((struct wp_symbol*)(node->r))->name); - break; - case WP_SUB_VP: - std::printf("SUM: %.17g %s\n", node->lvp.v, ((struct wp_symbol*)(node->r))->name); - break; - case WP_MUL_VP: - std::printf("MUL: %.17g %s\n", node->lvp.v, ((struct wp_symbol*)(node->r))->name); - break; - case WP_DIV_VP: - std::printf("DIV: %.17g %s\n", node->lvp.v, ((struct wp_symbol*)(node->r))->name); - break; - case WP_NEG_P: - std::printf("NEG: %s\n", ((struct wp_symbol*)(node->l))->name); - break; - case WP_ADD_PP: - std::printf("ADD: %s %s\n", ((struct wp_symbol*)(node->l))->name, - ((struct wp_symbol*)(node->r))->name); - break; - case WP_SUB_PP: - std::printf("SUB: %s %s\n", ((struct wp_symbol*)(node->l))->name, - ((struct wp_symbol*)(node->r))->name); - break; - case WP_MUL_PP: - std::printf("MUL: %s %s\n", ((struct wp_symbol*)(node->l))->name, - ((struct wp_symbol*)(node->r))->name); - break; - case WP_DIV_PP: - std::printf("DIV: %s %s\n", ((struct wp_symbol*)(node->l))->name, - ((struct wp_symbol*)(node->r))->name); - break; - default: - amrex::AllPrint() << "wp_ast_print: unknown node type " << node->type << "\n"; - amrex::Abort(); - } -} - -void -wp_ast_depth (struct wp_node* node, int* n) -{ - int nl = 0; - int nr = 0; - int n3 = 0; - switch (node->type) - { - case WP_NUMBER: - break; - case WP_SYMBOL: - break; - case WP_ADD: - wp_ast_depth(node->l, &nl); - wp_ast_depth(node->r, &nr); - break; - case WP_SUB: - wp_ast_depth(node->l, &nl); - wp_ast_depth(node->r, &nr); - break; - case WP_MUL: - wp_ast_depth(node->l, &nl); - wp_ast_depth(node->r, &nr); - break; - case WP_DIV: - wp_ast_depth(node->l, &nl); - wp_ast_depth(node->r, &nr); - break; - case WP_NEG: - wp_ast_depth(node->l, &nl); - break; - case WP_F1: - wp_ast_depth(((struct wp_f1*)node)->l, &nl); - break; - case WP_F2: - wp_ast_depth(((struct wp_f2*)node)->l, &nl); - wp_ast_depth(((struct wp_f2*)node)->r, &nr); - break; - case WP_F3: - wp_ast_depth(((struct wp_f3*)node)->n1, &nl); - wp_ast_depth(((struct wp_f3*)node)->n2, &nr); - wp_ast_depth(((struct wp_f3*)node)->n3, &n3); - break; - case WP_ADD_VP: - break; - case WP_SUB_VP: - break; - case WP_MUL_VP: - break; - case WP_DIV_VP: - break; - case WP_NEG_P: - break; - case WP_ADD_PP: - break; - case WP_SUB_PP: - break; - case WP_MUL_PP: - break; - case WP_DIV_PP: - break; - default: - wxparsererror("wp_ast_depth: unknown node type %d\n", node->type); - exit(1); - } - *n += std::max({nl,nr,n3}) + 1; -} - -void -wp_ast_regvar (struct wp_node* node, char const* name, amrex_real* p) -{ - switch (node->type) - { - case WP_NUMBER: - break; - case WP_SYMBOL: - if (strcmp(name, ((struct wp_symbol*)node)->name) == 0) { - ((struct wp_symbol*)node)->ip.p = p; - } - break; - case WP_ADD: - case WP_SUB: - case WP_MUL: - case WP_DIV: - wp_ast_regvar(node->l, name, p); - wp_ast_regvar(node->r, name, p); - break; - case WP_NEG: - wp_ast_regvar(node->l, name, p); - break; - case WP_F1: - wp_ast_regvar(node->l, name, p); - break; - case WP_F2: - wp_ast_regvar(node->l, name, p); - wp_ast_regvar(node->r, name, p); - break; - case WP_F3: - wp_ast_regvar(((struct wp_f3*)node)->n1, name, p); - wp_ast_regvar(((struct wp_f3*)node)->n2, name, p); - wp_ast_regvar(((struct wp_f3*)node)->n3, name, p); - break; - case WP_ADD_VP: - case WP_SUB_VP: - case WP_MUL_VP: - case WP_DIV_VP: - wp_ast_regvar(node->r, name, p); - node->rip.p = ((struct wp_symbol*)(node->r))->ip.p; - break; - case WP_NEG_P: - wp_ast_regvar(node->l, name, p); - node->lvp.ip.p = ((struct wp_symbol*)(node->l))->ip.p; - break; - case WP_ADD_PP: - case WP_SUB_PP: - case WP_MUL_PP: - case WP_DIV_PP: - wp_ast_regvar(node->l, name, p); - wp_ast_regvar(node->r, name, p); - node->lvp.ip.p = ((struct wp_symbol*)(node->l))->ip.p; - node->rip.p = ((struct wp_symbol*)(node->r))->ip.p; - break; - default: - amrex::AllPrint() << "wp_ast_regvar: unknown node type " << node->type << "\n"; - amrex::Abort(); - } -} - -void -wp_ast_regvar_gpu (struct wp_node* node, char const* name, int i) -{ - switch (node->type) - { - case WP_NUMBER: - break; - case WP_SYMBOL: - if (strcmp(name, ((struct wp_symbol*)node)->name) == 0) { - ((struct wp_symbol*)node)->ip.i = i; - } - break; - case WP_ADD: - case WP_SUB: - case WP_MUL: - case WP_DIV: - wp_ast_regvar_gpu(node->l, name, i); - wp_ast_regvar_gpu(node->r, name, i); - break; - case WP_NEG: - wp_ast_regvar_gpu(node->l, name, i); - break; - case WP_F1: - wp_ast_regvar_gpu(node->l, name, i); - break; - case WP_F2: - wp_ast_regvar_gpu(node->l, name, i); - wp_ast_regvar_gpu(node->r, name, i); - break; - case WP_F3: - wp_ast_regvar_gpu(((struct wp_f3*)node)->n1, name, i); - wp_ast_regvar_gpu(((struct wp_f3*)node)->n2, name, i); - wp_ast_regvar_gpu(((struct wp_f3*)node)->n3, name, i); - break; - case WP_ADD_VP: - case WP_SUB_VP: - case WP_MUL_VP: - case WP_DIV_VP: - wp_ast_regvar_gpu(node->r, name, i); - node->rip.i = ((struct wp_symbol*)(node->r))->ip.i; - break; - case WP_NEG_P: - wp_ast_regvar_gpu(node->l, name, i); - node->lvp.ip.i = ((struct wp_symbol*)(node->l))->ip.i; - break; - case WP_ADD_PP: - case WP_SUB_PP: - case WP_MUL_PP: - case WP_DIV_PP: - wp_ast_regvar_gpu(node->l, name, i); - wp_ast_regvar_gpu(node->r, name, i); - node->lvp.ip.i = ((struct wp_symbol*)(node->l))->ip.i; - node->rip.i = ((struct wp_symbol*)(node->r))->ip.i; - break; - default: - amrex::AllPrint() << "wp_ast_regvar_gpu: unknown node type " << node->type << "\n"; - amrex::Abort(); - } -} - -void wp_ast_setconst (struct wp_node* node, char const* name, amrex_real c) -{ - switch (node->type) - { - case WP_NUMBER: - break; - case WP_SYMBOL: - if (strcmp(name, ((struct wp_symbol*)node)->name) == 0) { - ((struct wp_number*)node)->type = WP_NUMBER; - ((struct wp_number*)node)->value = c; - } - break; - case WP_ADD: - case WP_SUB: - case WP_MUL: - case WP_DIV: - wp_ast_setconst(node->l, name, c); - wp_ast_setconst(node->r, name, c); - break; - case WP_NEG: - wp_ast_setconst(node->l, name, c); - break; - case WP_F1: - wp_ast_setconst(node->l, name, c); - break; - case WP_F2: - wp_ast_setconst(node->l, name, c); - wp_ast_setconst(node->r, name, c); - break; - case WP_F3: - wp_ast_setconst(((struct wp_f3*)node)->n1, name, c); - wp_ast_setconst(((struct wp_f3*)node)->n2, name, c); - wp_ast_setconst(((struct wp_f3*)node)->n3, name, c); - break; - case WP_ADD_VP: - case WP_SUB_VP: - case WP_MUL_VP: - case WP_DIV_VP: - wp_ast_setconst(node->r, name, c); - break; - case WP_NEG_P: - wp_ast_setconst(node->l, name, c); - break; - case WP_ADD_PP: - case WP_SUB_PP: - case WP_MUL_PP: - case WP_DIV_PP: - wp_ast_setconst(node->l, name, c); - wp_ast_setconst(node->r, name, c); - break; - default: - amrex::AllPrint() << "wp_ast_setconst: unknown node type " << node->type << "\n"; - amrex::Abort(); - } -} - -void -wp_parser_regvar (struct wp_parser* parser, char const* name, amrex_real* p) -{ - wp_ast_regvar(parser->ast, name, p); -} - -void -wp_parser_regvar_gpu (struct wp_parser* parser, char const* name, int i) -{ - wp_ast_regvar_gpu(parser->ast, name, i); -} - -void -wp_parser_setconst (struct wp_parser* parser, char const* name, amrex_real c) -{ - wp_ast_setconst(parser->ast, name, c); - wp_ast_optimize(parser->ast); -} diff --git a/Source/Parser/wp_parser_y.h b/Source/Parser/wp_parser_y.h deleted file mode 100644 index e91a5ba6cf0..00000000000 --- a/Source/Parser/wp_parser_y.h +++ /dev/null @@ -1,299 +0,0 @@ -#ifndef WP_PARSER_Y_H_ -#define WP_PARSER_Y_H_ - -#include -#include -#include -#include -#include - -#include -#include -#include -#include -#include -#include - -enum wp_f1_t { // Built-in functions with one argument - WP_SQRT = 1, - WP_EXP, - WP_LOG, - WP_LOG10, - WP_SIN, - WP_COS, - WP_TAN, - WP_ASIN, - WP_ACOS, - WP_ATAN, - WP_SINH, - WP_COSH, - WP_TANH, - WP_ABS, - WP_POW_M3, - WP_POW_M2, - WP_POW_M1, - WP_POW_P1, - WP_POW_P2, - WP_POW_P3 -}; - -enum wp_f2_t { // Built-in functions with two arguments - WP_POW = 1, - WP_GT, - WP_LT, - WP_GEQ, - WP_LEQ, - WP_EQ, - WP_NEQ, - WP_AND, - WP_OR, - WP_HEAVISIDE, - WP_JN, - WP_MIN, - WP_MAX -}; - -enum wp_f3_t { // functions with three arguments - WP_IF -}; - -enum wp_node_t { - WP_NUMBER = 1, - WP_SYMBOL, - WP_ADD, - WP_SUB, - WP_MUL, - WP_DIV, - WP_NEG, - WP_F1, - WP_F2, - WP_F3, - WP_ADD_VP, /* types below are generated by optimization */ - WP_ADD_PP, - WP_SUB_VP, - WP_SUB_PP, - WP_MUL_VP, - WP_MUL_PP, - WP_DIV_VP, - WP_DIV_PP, - WP_NEG_P -}; - -/* In C, the address of the first member of a struct is the same as - * the address of the struct itself. Because of this, all struct wp_* - * pointers can be passed around as struct wp_node pointer and enum - * wp_node_t type can be safely checked to determine their real type. - */ - -union wp_ip { - int i; - amrex_real* p; -}; - -union wp_nvp { - struct wp_node* n; - amrex_real v; - union wp_ip ip; -}; - -struct wp_node { - enum wp_node_t type; - struct wp_node* l; - struct wp_node* r; - union wp_nvp lvp; // After optimization, this may store left value/pointer. - union wp_ip rip; // this may store right pointer. -}; - -struct wp_number { - enum wp_node_t type; - amrex_real value; -}; - -struct wp_symbol { - enum wp_node_t type; - char* name; - union wp_ip ip; -}; - -struct wp_f1 { /* Builtin functions with one argument */ - enum wp_node_t type; - struct wp_node* l; - enum wp_f1_t ftype; -}; - -struct wp_f2 { /* Builtin functions with two arguments */ - enum wp_node_t type; - struct wp_node* l; - struct wp_node* r; - enum wp_f2_t ftype; -}; - -struct wp_f3 { /* Builtin funcitons with three arguments */ - enum wp_node_t type; - struct wp_node* n1; - struct wp_node* n2; - struct wp_node* n3; - enum wp_f3_t ftype; -}; - -/*******************************************************************/ - -/* These functions are used in bison rules to generate the original - * AST. */ -void wp_defexpr (struct wp_node* body); -struct wp_node* wp_newnumber (amrex_real d); -struct wp_symbol* wp_makesymbol (char* name); -struct wp_node* wp_newsymbol (struct wp_symbol* sym); -struct wp_node* wp_newnode (enum wp_node_t type, struct wp_node* l, - struct wp_node* r); -struct wp_node* wp_newf1 (enum wp_f1_t ftype, struct wp_node* l); -struct wp_node* wp_newf2 (enum wp_f2_t ftype, struct wp_node* l, - struct wp_node* r); -struct wp_node* wp_newf3 (enum wp_f3_t ftype, struct wp_node* n1, - struct wp_node* n2, struct wp_node* n3); - -void wxparsererror (char const *s, ...); - -/*******************************************************************/ - -/* This is our struct for storing AST in a more packed way. The whole - * tree is stored in a contiguous chunk of memory starting from void* - * p_root with a size of sz_mempool. - */ -struct wp_parser { - void* p_root; - void* p_free; - struct wp_node* ast; - size_t sz_mempool; -}; - -struct wp_parser* wp_parser_new (void); -void wp_parser_delete (struct wp_parser* parser); - -struct wp_parser* wp_parser_dup (struct wp_parser* source); -struct wp_node* wp_parser_ast_dup (struct wp_parser* parser, struct wp_node* src, int move); - -void wp_parser_regvar (struct wp_parser* parser, char const* name, amrex_real* p); -void wp_parser_regvar_gpu (struct wp_parser* parser, char const* name, int i); -void wp_parser_setconst (struct wp_parser* parser, char const* name, amrex_real c); - -/* We need to walk the tree in these functions */ -void wp_ast_optimize (struct wp_node* node); -size_t wp_ast_size (struct wp_node* node); -void wp_ast_print (struct wp_node* node); -void wp_ast_depth (struct wp_node* node, int* n); -void wp_ast_regvar (struct wp_node* node, char const* name, amrex_real* p); -void wp_ast_regvar_gpu (struct wp_node* node, char const* name, int i); -void wp_ast_setconst (struct wp_node* node, char const* name, amrex_real c); - -template ::value,int> = 0> -AMREX_GPU_HOST_DEVICE -#ifdef AMREX_USE_GPU -AMREX_NO_INLINE -#endif -T -wp_call_f1 (enum wp_f1_t type, T a) -{ - switch (type) { - case WP_SQRT: return std::sqrt(a); - case WP_EXP: return std::exp(a); - case WP_LOG: return std::log(a); - case WP_LOG10: return std::log10(a); - case WP_SIN: return std::sin(a); - case WP_COS: return std::cos(a); - case WP_TAN: return std::tan(a); - case WP_ASIN: return std::asin(a); - case WP_ACOS: return std::acos(a); - case WP_ATAN: return std::atan(a); - case WP_SINH: return std::sinh(a); - case WP_COSH: return std::cosh(a); - case WP_TANH: return std::tanh(a); - case WP_ABS: return amrex::Math::abs(a); - case WP_POW_M3: return amrex::Real(1.0)/(a*a*a); - case WP_POW_M2: return amrex::Real(1.0)/(a*a); - case WP_POW_M1: return amrex::Real(1.0)/a; - case WP_POW_P1: return a; - case WP_POW_P2: return a*a; - case WP_POW_P3: return a*a*a; - default: -#if AMREX_DEVICE_COMPILE - AMREX_DEVICE_PRINTF("wp_call_f1: Unknown function %d\n", type); -#else - amrex::AllPrint() << "wp_call_f1: Unknown function " << type << "\n"; -#endif - return 0.0; - } -} - - -template ::value,int> = 0> -AMREX_GPU_HOST_DEVICE -#ifdef AMREX_USE_GPU -AMREX_NO_INLINE -#endif -T -wp_call_f2 (enum wp_f2_t type, T a, T b) -{ - switch (type) { - case WP_POW: - return std::pow(a,b); - case WP_GT: - return (a > b) ? 1.0 : 0.0; - case WP_LT: - return (a < b) ? 1.0 : 0.0; - case WP_GEQ: - return (a >= b) ? 1.0 : 0.0; - case WP_LEQ: - return (a <= b) ? 1.0 : 0.0; - case WP_EQ: - return (a == b) ? 1.0 : 0.0; - case WP_NEQ: - return (a != b) ? 1.0 : 0.0; - case WP_AND: - return ((a != T(0)) && (b != T(0))) ? 1.0 : 0.0; - case WP_OR: - return ((a != T(0)) || (b != T(0))) ? 1.0 : 0.0; - case WP_HEAVISIDE: - return (a < 0.0) ? amrex::Real(0.0) : ((a > 0.0) ? amrex::Real(1.0) : b); - case WP_JN: -#ifdef AMREX_USE_DPCPP - // neither jn(f) nor std::cyl_bessel_j work yet - // https://github.com/oneapi-src/oneAPI-spec/issues/308 - AMREX_DEVICE_PRINTF("wp_call_f2: Parser does not implement jn (%d) for SYCL/DPC++ yet\n", type); - amrex::Abort(); - return 0.0; -#else -# if defined(AMREX_USE_FLOAT) && !defined(__APPLE__) - return jnf(int(a), b); -# else - return jn(int(a), b); -# endif -#endif - case WP_MIN: - return (a < b) ? a : b; - case WP_MAX: - return (a > b) ? a : b; - default: -#if AMREX_DEVICE_COMPILE - AMREX_DEVICE_PRINTF("wp_call_f2: Unknown function %d\n", type); -#else - amrex::AllPrint() << "wp_call_f2: Unknown function " << type << "\n"; -#endif - amrex::Abort(); - return 0.0; - } -} - -template ::value,int> = 0> -AMREX_GPU_HOST_DEVICE -#ifdef AMREX_USE_GPU -AMREX_NO_INLINE -#endif -T -wp_call_f3 (enum wp_f3_t /*type*/, T a, T b, T c) -{ - // There is only one type currently - return (a != T(0)) ? b : c; -} - -#endif diff --git a/Source/Particles/Filter/FilterFunctors.H b/Source/Particles/Filter/FilterFunctors.H index e713bcfe3f4..a5995336d76 100644 --- a/Source/Particles/Filter/FilterFunctors.H +++ b/Source/Particles/Filter/FilterFunctors.H @@ -13,6 +13,7 @@ #include "WarpX.H" #include +#include #include using SuperParticleType = typename WarpXParticleContainer::SuperParticleType; @@ -90,7 +91,8 @@ struct ParserFilter /** constructor * \param a_is_active whether the test is active */ - ParserFilter(bool a_is_active, HostDeviceParser<7> const& a_filter_parser, amrex::Real a_mass) + ParserFilter(bool a_is_active, amrex::ParserExecutor<7> const& a_filter_parser, + amrex::Real a_mass) : m_is_active(a_is_active), m_function_partparser(a_filter_parser), m_mass(a_mass) { m_t = WarpX::GetInstance().gett_new(0); @@ -126,7 +128,7 @@ private: const bool m_is_active; public: /** Parser function with 7 input variables, t,x,y,z,ux,uy,uz */ - HostDeviceParser<7> const m_function_partparser; + amrex::ParserExecutor<7> const m_function_partparser; /** Store physical time. */ amrex::Real m_t; /** Mass of particle species */ diff --git a/Source/Particles/Gather/GetExternalFields.H b/Source/Particles/Gather/GetExternalFields.H index 73fc3e941b6..254d335b9c2 100644 --- a/Source/Particles/Gather/GetExternalFields.H +++ b/Source/Particles/Gather/GetExternalFields.H @@ -1,7 +1,6 @@ #ifndef WARPX_PARTICLES_GATHER_GETEXTERNALFIELDS_H_ #define WARPX_PARTICLES_GATHER_GETEXTERNALFIELDS_H_ -#include "Parser/WarpXParserWrapper.H" #include "Particles/Pusher/GetAndSetPosition.H" #include "Particles/WarpXParticleContainer_fwd.H" @@ -10,6 +9,7 @@ #include #include #include +#include #include enum ExternalFieldInitType { Constant, Parser }; @@ -23,9 +23,9 @@ struct GetExternalField amrex::GpuArray m_field_value; - HostDeviceParser<4> m_xfield_partparser; - HostDeviceParser<4> m_yfield_partparser; - HostDeviceParser<4> m_zfield_partparser; + amrex::ParserExecutor<4> m_xfield_partparser; + amrex::ParserExecutor<4> m_yfield_partparser; + amrex::ParserExecutor<4> m_zfield_partparser; GetParticlePosition m_get_position; amrex::Real m_time; diff --git a/Source/Particles/Gather/GetExternalFields.cpp b/Source/Particles/Gather/GetExternalFields.cpp index f21c8fb5eb0..0808bd6c19d 100644 --- a/Source/Particles/Gather/GetExternalFields.cpp +++ b/Source/Particles/Gather/GetExternalFields.cpp @@ -25,9 +25,9 @@ GetExternalEField::GetExternalEField (const WarpXParIter& a_pti, int a_offset) n m_type = Parser; m_time = warpx.gett_new(a_pti.GetLevel()); m_get_position = GetParticlePosition(a_pti, a_offset); - m_xfield_partparser = getParser(mypc.m_Ex_particle_parser); - m_yfield_partparser = getParser(mypc.m_Ey_particle_parser); - m_zfield_partparser = getParser(mypc.m_Ez_particle_parser); + m_xfield_partparser = mypc.m_Ex_particle_parser->compile<4>(); + m_yfield_partparser = mypc.m_Ey_particle_parser->compile<4>(); + m_zfield_partparser = mypc.m_Ez_particle_parser->compile<4>(); } } @@ -47,8 +47,8 @@ GetExternalBField::GetExternalBField (const WarpXParIter& a_pti, int a_offset) n m_type = Parser; m_time = warpx.gett_new(a_pti.GetLevel()); m_get_position = GetParticlePosition(a_pti, a_offset); - m_xfield_partparser = getParser(mypc.m_Bx_particle_parser); - m_yfield_partparser = getParser(mypc.m_By_particle_parser); - m_zfield_partparser = getParser(mypc.m_Bz_particle_parser); + m_xfield_partparser = mypc.m_Bx_particle_parser->compile<4>(); + m_yfield_partparser = mypc.m_By_particle_parser->compile<4>(); + m_zfield_partparser = mypc.m_Bz_particle_parser->compile<4>(); } } diff --git a/Source/Particles/MultiParticleContainer.H b/Source/Particles/MultiParticleContainer.H index d244eaf476d..eafa6901279 100644 --- a/Source/Particles/MultiParticleContainer.H +++ b/Source/Particles/MultiParticleContainer.H @@ -14,7 +14,6 @@ #include "MultiParticleContainer_fwd.H" #include "Evolve/WarpXDtType.H" -#include "Parser/WarpXParserWrapper.H" #include "Particles/Collision/CollisionHandler.H" #ifdef WARPX_QED # include "Particles/ElementaryProcess/QEDInternals/BreitWheelerEngineWrapper_fwd.H" @@ -286,14 +285,14 @@ public: // External fields added to particle fields. amrex::Vector m_B_external_particle; amrex::Vector m_E_external_particle; - // ParserWrapper for B_external on the particle - std::unique_ptr > m_Bx_particle_parser; - std::unique_ptr > m_By_particle_parser; - std::unique_ptr > m_Bz_particle_parser; - // ParserWrapper for E_external on the particle - std::unique_ptr > m_Ex_particle_parser; - std::unique_ptr > m_Ey_particle_parser; - std::unique_ptr > m_Ez_particle_parser; + // Parser for B_external on the particle + std::unique_ptr m_Bx_particle_parser; + std::unique_ptr m_By_particle_parser; + std::unique_ptr m_Bz_particle_parser; + // Parser for E_external on the particle + std::unique_ptr m_Ex_particle_parser; + std::unique_ptr m_Ey_particle_parser; + std::unique_ptr m_Ez_particle_parser; #ifdef WARPX_QED /** diff --git a/Source/Particles/MultiParticleContainer.cpp b/Source/Particles/MultiParticleContainer.cpp index 213cdc78297..c1b462168cb 100644 --- a/Source/Particles/MultiParticleContainer.cpp +++ b/Source/Particles/MultiParticleContainer.cpp @@ -184,11 +184,11 @@ MultiParticleContainer::ReadParameters () str_Bz_ext_particle_function); // Parser for B_external on the particle - m_Bx_particle_parser = std::make_unique>( + m_Bx_particle_parser = std::make_unique( makeParser(str_Bx_ext_particle_function,{"x","y","z","t"})); - m_By_particle_parser = std::make_unique>( + m_By_particle_parser = std::make_unique( makeParser(str_By_ext_particle_function,{"x","y","z","t"})); - m_Bz_particle_parser = std::make_unique>( + m_Bz_particle_parser = std::make_unique( makeParser(str_Bz_ext_particle_function,{"x","y","z","t"})); } @@ -209,11 +209,11 @@ MultiParticleContainer::ReadParameters () Store_parserString(pp_particles, "Ez_external_particle_function(x,y,z,t)", str_Ez_ext_particle_function); // Parser for E_external on the particle - m_Ex_particle_parser = std::make_unique>( + m_Ex_particle_parser = std::make_unique( makeParser(str_Ex_ext_particle_function,{"x","y","z","t"})); - m_Ey_particle_parser = std::make_unique>( + m_Ey_particle_parser = std::make_unique( makeParser(str_Ey_ext_particle_function,{"x","y","z","t"})); - m_Ez_particle_parser = std::make_unique>( + m_Ez_particle_parser = std::make_unique( makeParser(str_Ez_ext_particle_function,{"x","y","z","t"})); } diff --git a/Source/Utils/WarpXMovingWindow.cpp b/Source/Utils/WarpXMovingWindow.cpp index e179ea870e2..9b270469c47 100644 --- a/Source/Utils/WarpXMovingWindow.cpp +++ b/Source/Utils/WarpXMovingWindow.cpp @@ -9,7 +9,6 @@ #include "WarpX.H" #include "BoundaryConditions/PML.H" -#include "Parser/WarpXParserWrapper.H" #include "Particles/MultiParticleContainer.H" #include "Utils/WarpXConst.H" #include "Utils/WarpXProfilerWrapper.H" @@ -32,6 +31,7 @@ #include #include #include +#include #include #include #include @@ -147,21 +147,21 @@ WarpX::MoveWindow (const int step, bool move_j) // Shift each component of vector fields (E, B, j) for (int dim = 0; dim < 3; ++dim) { // Fine grid - HostDeviceParser<3> Bfield_parser; - HostDeviceParser<3> Efield_parser; + ParserExecutor<3> Bfield_parser; + ParserExecutor<3> Efield_parser; bool use_Bparser = false; bool use_Eparser = false; if (B_ext_grid_s == "parse_b_ext_grid_function") { use_Bparser = true; - if (dim == 0) Bfield_parser = getParser(Bxfield_parser); - if (dim == 1) Bfield_parser = getParser(Byfield_parser); - if (dim == 2) Bfield_parser = getParser(Bzfield_parser); + if (dim == 0) Bfield_parser = Bxfield_parser->compile<3>(); + if (dim == 1) Bfield_parser = Byfield_parser->compile<3>(); + if (dim == 2) Bfield_parser = Bzfield_parser->compile<3>(); } if (E_ext_grid_s == "parse_e_ext_grid_function") { use_Eparser = true; - if (dim == 0) Efield_parser = getParser(Exfield_parser); - if (dim == 1) Efield_parser = getParser(Eyfield_parser); - if (dim == 2) Efield_parser = getParser(Ezfield_parser); + if (dim == 0) Efield_parser = Exfield_parser->compile<3>(); + if (dim == 1) Efield_parser = Eyfield_parser->compile<3>(); + if (dim == 2) Efield_parser = Ezfield_parser->compile<3>(); } shiftMF(*Bfield_fp[lev][dim], geom[lev], num_shift, dir, B_external_grid[dim], use_Bparser, Bfield_parser); shiftMF(*Efield_fp[lev][dim], geom[lev], num_shift, dir, E_external_grid[dim], use_Eparser, Efield_parser); @@ -277,7 +277,7 @@ WarpX::MoveWindow (const int step, bool move_j) void WarpX::shiftMF (MultiFab& mf, const Geometry& geom, int num_shift, int dir, amrex::Real external_field, bool useparser, - HostDeviceParser<3> const& field_parser) + ParserExecutor<3> const& field_parser) { WARPX_PROFILE("WarpX::shiftMF()"); const BoxArray& ba = mf.boxArray(); diff --git a/Source/Utils/WarpXUtil.H b/Source/Utils/WarpXUtil.H index 22216d3fba5..7096a73e615 100644 --- a/Source/Utils/WarpXUtil.H +++ b/Source/Utils/WarpXUtil.H @@ -8,8 +8,6 @@ #ifndef WARPX_UTILS_H_ #define WARPX_UTILS_H_ -#include "Parser/WarpXParser.H" - #include #include #include @@ -165,17 +163,17 @@ T trilinear_interp(T x0, T x1,T y0, T y1, T z0, T z1, } /** -* \brief Initialize a WarpXParser object from a string containing a math expression +* \brief Initialize an amrex::Parser object from a string containing a math expression * * \param parse_function String to read to initialize the parser. */ -WarpXParser makeParser (std::string const& parse_function, std::vector const& varnames); +amrex::Parser makeParser (std::string const& parse_function, amrex::Vector const& varnames); /** * \brief Similar to amrex::ParmParse::query, but also supports math expressions for the value. * * amrex::ParmParse::query reads a name and a value from the input file. This function does the - * same, and applies the WarpXParser to the value, so the user has the choice to specify a value or + * same, and applies the amrex::Parser to the value, so the user has the choice to specify a value or * a math expression (including user-defined constants). * Only works for amrex::Real numbers, one would need another version for integers etc. * @@ -191,7 +189,7 @@ int queryArrWithParser (const amrex::ParmParse& a_pp, char const * const str, st * \brief Similar to amrex::ParmParse::get, but also supports math expressions for the value. * * amrex::ParmParse::get reads a name and a value from the input file. This function does the - * same, and applies the WarpXParser to the value, so the user has the choice to specify a value or + * same, and applies the Parser to the value, so the user has the choice to specify a value or * a math expression (including user-defined constants). * Only works for amrex::Real numbers, one would need another version for integers etc. * diff --git a/Source/Utils/WarpXUtil.cpp b/Source/Utils/WarpXUtil.cpp index 4ea0f14c0b4..09d3a3ad285 100644 --- a/Source/Utils/WarpXUtil.cpp +++ b/Source/Utils/WarpXUtil.cpp @@ -25,6 +25,7 @@ #include #include #include +#include #include #include @@ -223,13 +224,13 @@ void Store_parserString(const amrex::ParmParse& pp, std::string query_string, f.clear(); } -WarpXParser makeParser (std::string const& parse_function, std::vector const& varnames) +Parser makeParser (std::string const& parse_function, amrex::Vector const& varnames) { // Since queryWithParser recursively calls this routine, keep track of symbols // in case an infinite recursion is found (a symbol's value depending on itself). static std::set recursive_symbols; - WarpXParser parser(parse_function); + Parser parser(parse_function); parser.registerVariables(varnames); ParmParse pp_my_constants("my_constants"); std::set symbols = parser.symbols(); @@ -292,7 +293,9 @@ queryWithParser (const amrex::ParmParse& a_pp, char const * const str, amrex::Re Store_parserString(a_pp, str, str_val); auto parser = makeParser(str_val, {}); - val = parser.eval(); + auto exe = parser.compileHost<0>(); + + val = exe(); } // return the same output as amrex::ParmParse::query return is_specified; @@ -306,7 +309,8 @@ getWithParser (const amrex::ParmParse& a_pp, char const * const str, amrex::Real Store_parserString(a_pp, str, str_val); auto parser = makeParser(str_val, {}); - val = parser.eval(); + auto exe = parser.compileHost<0>(); + val = exe(); } int @@ -323,7 +327,8 @@ queryArrWithParser (const amrex::ParmParse& a_pp, char const * const str, std::v val.resize(n); for (int i=0 ; i < n ; i++) { auto parser = makeParser(tmp_str_arr[i], {}); - val[i] = parser.eval(); + auto exe = parser.compileHost<0>(); + val[i] = exe(); } } // return the same output as amrex::ParmParse::query @@ -341,7 +346,8 @@ getArrWithParser (const amrex::ParmParse& a_pp, char const * const str, std::vec val.resize(n); for (int i=0 ; i < n ; i++) { auto parser = makeParser(tmp_str_arr[i], {}); - val[i] = parser.eval(); + auto exe = parser.compileHost<0>(); + val[i] = exe(); } } @@ -357,7 +363,8 @@ getArrWithParser (const amrex::ParmParse& a_pp, char const * const str, std::vec val.resize(n); for (int i=0 ; i < n ; i++) { auto parser = makeParser(tmp_str_arr[i], {}); - val[i] = parser.eval(); + auto exe = parser.compileHost<0>(); + val[i] = exe(); } } diff --git a/Source/WarpX.H b/Source/WarpX.H index 2cb5f4483d0..c50f023f81c 100644 --- a/Source/WarpX.H +++ b/Source/WarpX.H @@ -29,7 +29,6 @@ #include "Filter/BilinearFilter.H" #include "Filter/NCIGodfreyFilter_fwd.H" #include "Parallelization/GuardCellManager.H" -#include "Parser/WarpXParserWrapper.H" #include "Particles/MultiParticleContainer_fwd.H" #include "Particles/WarpXParticleContainer_fwd.H" #include "Utils/IntervalsParser.H" @@ -44,6 +43,7 @@ #endif #include #include +#include #include #include #include @@ -93,7 +93,7 @@ public: static void shiftMF (amrex::MultiFab& mf, const amrex::Geometry& geom, int num_shift, int dir, amrex::Real external_field=0.0, - bool useparser = false, HostDeviceParser<3> const& field_parser={}); + bool useparser = false, amrex::ParserExecutor<3> const& field_parser={}); static void GotoNextLine (std::istream& is); @@ -117,14 +117,14 @@ public: static std::string str_Ey_ext_grid_function; static std::string str_Ez_ext_grid_function; - // ParserWrapper for B_external on the grid - std::unique_ptr > Bxfield_parser; - std::unique_ptr > Byfield_parser; - std::unique_ptr > Bzfield_parser; - // ParserWrapper for E_external on the grid - std::unique_ptr > Exfield_parser; - std::unique_ptr > Eyfield_parser; - std::unique_ptr > Ezfield_parser; + // Parser for B_external on the grid + std::unique_ptr Bxfield_parser; + std::unique_ptr Byfield_parser; + std::unique_ptr Bzfield_parser; + // Parser for E_external on the grid + std::unique_ptr Exfield_parser; + std::unique_ptr Eyfield_parser; + std::unique_ptr Ezfield_parser; // Algorithms static long current_deposition_algo; @@ -661,8 +661,9 @@ public: */ void InitializeExternalFieldsOnGridUsingParser ( amrex::MultiFab *mfx, amrex::MultiFab *mfy, amrex::MultiFab *mfz, - HostDeviceParser<3> const& xfield_parser, HostDeviceParser<3> const& yfield_parser, - HostDeviceParser<3> const& zfield_parser, const int lev); + amrex::ParserExecutor<3> const& xfield_parser, + amrex::ParserExecutor<3> const& yfield_parser, + amrex::ParserExecutor<3> const& zfield_parser, const int lev); /** \brief adds particle and cell contributions in cells to compute heuristic * cost in each box on each level, and records in `costs` @@ -1127,9 +1128,6 @@ private: amrex::EBFArrayBoxFactory const& fieldEBFactory (int lev) const noexcept { return static_cast(*m_field_factory[lev]); } - - // EB implicit funciton - std::unique_ptr > m_eb_if_parser; #endif void InitEB (); diff --git a/Source/WarpX.cpp b/Source/WarpX.cpp index 0745b0941f9..f2231007814 100644 --- a/Source/WarpX.cpp +++ b/Source/WarpX.cpp @@ -27,7 +27,6 @@ #endif // use PSATD ifdef #include "FieldSolver/WarpX_FDTD.H" #include "Filter/NCIGodfreyFilter.H" -#include "Parser/WarpXParserWrapper.H" #include "Particles/MultiParticleContainer.H" #include "Python/WarpXWrappers.h" #include "Utils/WarpXAlgorithmSelection.H" diff --git a/cmake/WarpXFunctions.cmake b/cmake/WarpXFunctions.cmake index aecba07db7b..92e6668cd65 100644 --- a/cmake/WarpXFunctions.cmake +++ b/cmake/WarpXFunctions.cmake @@ -344,7 +344,6 @@ function(warpx_print_summary) if(MPI) message(" MPI (thread multiple): ${WarpX_MPI_THREAD_MULTIPLE}") endif() - message(" Parser depth: ${WarpX_PARSER_DEPTH}") message(" PSATD: ${WarpX_PSATD}") message(" PRECISION: ${WarpX_PRECISION}") message(" OPENPMD: ${WarpX_OPENPMD}")