35#include "D4FunctionEvaluator.h"
36#include "D4FunctionScanner.h"
37#include "d4_function_parser.tab.hh"
65 std::istringstream iss(expr);
67 D4FunctionParser parser(scanner, *
this );
69 if (trace_parsing()) {
70 parser.set_debug_level(1);
71 parser.set_debug_stream(std::cerr);
74 return parser.parse() == 0;
106 throw InternalErr(__FILE__, __LINE__,
"Must parse() the function expression before calling eval()");
109 for (
auto result : *d_result) {
127 list<D4Dimension *> dim_set;
130 if ((*i)->is_vector_type()) {
131 auto a =
static_cast<Array *
>(*i);
132 for (
auto d = a->dim_begin(), de = a->dim_end(); d != de; ++d) {
136 bool found = (std::find(dim_set.begin(), dim_set.end(), d4_dim) != dim_set.end());
138 dim_set.push_back(a->dimension_D4dim(d));
147 for (
auto dim : dim_set) {
152 list<D4EnumDef *> enum_def_set;
154 if ((*i)->type() == dods_enum_c) {
155 enum_def_set.push_back(
static_cast<D4Enum *
>(*i)->enumeration());
159 for (
auto enum_def : enum_def_set) {
182D4RValue *D4FunctionEvaluator::build_rvalue(
const std::string &
id) {
186 if (top_basetype()) {
187 btp = top_basetype()->
var(
id);
193 return new D4RValue(btp);
197 char *end_ptr =
nullptr;
200 long long ll_val = strtoll(
id.c_str(), &end_ptr, 0);
201 if (*end_ptr ==
'\0' && errno == 0)
202 return new D4RValue(ll_val);
207 unsigned long long ull_val = strtoull(
id.c_str(), &end_ptr, 0);
208 if (*end_ptr ==
'\0' && errno == 0)
209 return new D4RValue(ull_val);
212 double d_val = strtod(
id.c_str(), &end_ptr);
213 if (*end_ptr ==
'\0' && errno == 0)
214 return new D4RValue(d_val);
218 return new D4RValue(
www2id(
id));
225template <
typename T> vector<T> *D4FunctionEvaluator::init_arg_list(T val) {
226 auto arg_list = make_unique<vector<T>>();
227 if (get_arg_length_hint() > 0)
228 arg_list->reserve(get_arg_length_hint());
230 arg_list->push_back(val);
232 return arg_list.release();
237template std::vector<dods_byte> *D4FunctionEvaluator::init_arg_list(dods_byte val);
238template std::vector<dods_int8> *D4FunctionEvaluator::init_arg_list(dods_int8 val);
239template std::vector<dods_uint16> *D4FunctionEvaluator::init_arg_list(dods_uint16 val);
240template std::vector<dods_int16> *D4FunctionEvaluator::init_arg_list(dods_int16 val);
241template std::vector<dods_uint32> *D4FunctionEvaluator::init_arg_list(dods_uint32 val);
242template std::vector<dods_int32> *D4FunctionEvaluator::init_arg_list(dods_int32 val);
243template std::vector<dods_uint64> *D4FunctionEvaluator::init_arg_list(dods_uint64 val);
244template std::vector<dods_int64> *D4FunctionEvaluator::init_arg_list(dods_int64 val);
245template std::vector<dods_float32> *D4FunctionEvaluator::init_arg_list(dods_float32 val);
246template std::vector<dods_float64> *D4FunctionEvaluator::init_arg_list(dods_float64 val);
251[[noreturn]]
void D4FunctionEvaluator::error(
const libdap::location &l,
const std::string &m) {
253 oss << l <<
": " << m << ends;
254 throw Error(malformed_expr, oss.str());
A multidimensional array of identical data types.
The basic data type for the DODS DAP types.
virtual BaseType * var(const string &name="", bool exact_match=true, btp_stack *s=nullptr)
Returns a pointer to a member of a constructor class.
void add_var(BaseType *bt, Part part=nil) override
void add_dim(D4Dimension *dim)
void add_enum(D4EnumDef *enum_def)
Holds a DAP4 enumeration.
bool parse(const std::string &expr)
D4RValueList * result() const
BaseType * find_var(const string &name)
D4Dimensions * dims()
Get the dimensions defined for this Group.
D4EnumDefs * enum_defs()
Get the enumerations defined for this Group.
A class for software fault reporting.
top level DAP object to house generic methods
string www2id(const string &in, const string &escape, const string &except)
bool is_quoted(const string &s)