eval.hpp
Go to the documentation of this file.
A name bound by a comprehension, visible while the binding exists.
Definition eval.hpp:76
Binding(const Binding *&b, const std::string &n)
Bind n inside the bindings starting at b.
Definition eval.hpp:90
long long int iteration
The iteration of a repeat or instances statement, from 1, or 0.
Definition eval.hpp:117
Context(const std::string &t, long long int i=0, long long int n=-1)
Initialize for t in iteration i of n.
Definition eval.hpp:121
Value eval(const Expr &e)
Evaluate e, keeping why only if e explains it.
bool defined(const Expr &e) const
Test whether name e is defined.
bool test(const Expr &e)
Return whether e is true, avoiding a copy for names.
long long int count(const Expr &e, const char *what)
Return the value of e, a count described by what.
static std::string array_name(const Expr &a)
Describe array a of a comprehension, for messages.
Seq< int > record_path(int i) const
Return the indices of the record at of the check that select the records of its record name i.
RecordRef records_of(const Expr &e)
Evaluate e, a record or a list of records.
Value comprehension(const Expr &e)
all, any, count, and sum over the elements of an array
static std::string record_text(const Record &r, const Seq< int > &at)
Describe the records at of record name r, innermost first.
std::string located(const std::string &msg)
Return the error message msg with the location and context.
const Seq< int > * record_at
The records of the deepest of them, one index per repeat level.
Definition eval.hpp:389
void set(const std::string &n, Value &&v)
Define n as v in the innermost frame.
size_t record_place(const Record &r, const Seq< int > &at)
Return where the record at of record name r starts in the input, or npos if that is unknown.
Seq< Witness > why
Why the last condition evaluated is false, for messages: the elements of the all-comprehensions that ...
Definition eval.hpp:392
Value call(const Expr &e)
Call a function (names and arguments are checked by the parser).
const Value * lookup(const std::string &n) const
Return the value of n, or null if it is not defined.
bool holds(const Stmt &s, std::string &error)
Test whether check s holds, and otherwise store why it fails in error.
bool explained(const Expr &e)
Return whether e is true, with only its own explanation in why.
void fail(const std::string &msg)
Throw an error with message msg at the current position.
const long long int max_effort
Limit for effort, which grows with the input, so that repeated or nested expressions cannot take time...
Definition eval.hpp:397
size_t record_start(const RecordRef &l, int i)
Return where record i of list l starts in the input, or npos.
std::string failure(const Stmt &s, int deepest, const Seq< int > &at)
Return why check s fails for the records at of its record name deepest.
bool distinct(const Expr &e)
Test whether all integers in the arguments of call e differ.
bool compare(const Value &a, const Value &b, const Expr &e)
Compare single values a and b with the operator of e.
const Value & field(const Expr &e, Value &tmp)
Evaluate field e of a record or a list of records.
long long int integer(const Value &v, const std::string &op)
Return the integer of single value v, or fail for op.
const Value & starts(const Stmt *r, const std::string &n)
Return the record starts of repeat r, failing for n if the repeat has not run yet.
static bool explains(const Expr &e)
Test whether e passes on why it is false (see why).
void fail(const ShapeError &e, const std::string &n)
Throw an error for the shape error e of the value of n.
const Value & ref(const Expr &e, Value &tmp)
Evaluate e, avoiding a copy for names.
void visit(long long int k)
Account for visiting k values in expressions.
Seq< Context > context
Description of the statements being executed, for errors.
Definition eval.hpp:379
std::string located(const std::string &msg, const Place &at)
Return the error message msg at at with the context.
bool ranges(const Stmt &s, int i, int level) const
Test whether record name i of check s is defined and ranges over the repeat at level.
std::string scalar_hint(const Expr &e) const
Return a hint for indexing e, a single value.
bool check_records(const Stmt &s, int deepest, Seq< int > &at, std::string &error)
Evaluate check s for the records inside the records at of its record name deepest,...
static std::string indexed(const Expr &e)
Describe the array of index expression e, for messages.
void explain(const Expr &e, const RecordRef &r, int i)
Add why element i of the array of all-comprehension e, with records r, is false.
Seq< Seq< Entry > > frames
Values: the outermost frame and one per active repeat iteration.
Definition eval.hpp:377
int count_records(const RecordRef &l)
Return the number of records in list l.
Evaluator(const SpecImpl &s, const std::string &text, const std::string &origin)
Initialize for spec s and input text from origin.
Place place(size_t q) const
Return the place of position q in the input, or the current place if q is npos.
Value subscript(const Expr &e)
a[i]: element i, counted from 0, of the outermost list of a
RecordRef element_records(const Expr &e, const Expr &a)
Return the records that are the elements of array a of comprehension e, an array of values (see Expr:...
void add_split(const std::string &cs)
Make the characters cs tokens by themselves, unless they separate tokens.
Definition eval.hpp:164
size_t next_data(void)
Return where the next data starts (see skip), without moving there.
Definition eval.hpp:351
Place place(size_t q) const
Return the place of position q, which is not after the current one.
Definition eval.hpp:338
bool int_token(long long int &v)
Read the token at the position as an integer v, and return whether it is one.
Definition eval.hpp:278
bool skip_to_line_data(void)
Skip blanks and separators, and return whether data follows on the line.
Definition eval.hpp:251
bool line_start(void) const
Test whether only blanks precede the position on its line.
Definition eval.hpp:186
void skip(void)
Skip white space, comment lines, and everything after a stop line.
Definition eval.hpp:217
bool skip_to_data(void)
Skip to the next data (see skip), and return whether there is any.
Definition eval.hpp:246
std::string rest(void) const
Return the rest of the current line without trailing blanks.
Definition eval.hpp:318
void add_separators(const std::string &cs)
Make the characters cs separate tokens like white space.
Definition eval.hpp:170
std::string line_at(size_t s) const
Return the line starting at s without trailing blanks.
Definition eval.hpp:325
bool in_line(size_t q) const
Test whether position q is within the current line.
Definition eval.hpp:213
bool starts_with(const std::string &prefix) const
Test whether the text at the position starts with prefix.
Definition eval.hpp:193
Error about the shape or type of a value, located by the caller.
Definition impl.hpp:238
A part of the explanation of a failed check, such as "record 3 of'jobs'", with the position of the re...
Definition eval.hpp:67
Reading instance files described by reader specs.
bool add(long long int x, long long int y, long long int &r)
Store x + y in r unless it overflows.
bool sub(long long int x, long long int y, long long int &r)
Store x - y in r unless it overflows.
std::string quote(const std::string &s)
Return s in single quotes, with newlines and tabs escaped.
Gecode toplevel namespace
