Generated on for Gecode by doxygen 1.18.0

Evaluator of the expressions of a spec on an input. More...

#include <gecode/instance/eval.hpp>

Public Member Functions

 Evaluator (const SpecImpl &s, const std::string &text, const std::string &origin)
 Initialize for spec s and input text from origin.

Protected Member Functions

std::string located (const std::string &msg)
 Return the error message msg with the location and context.
std::string located (const std::string &msg, const Place &at)
 Return the error message msg at at with the context.
void fail (const std::string &msg)
 Throw an error with message msg at the current position.
void fail (const ShapeError &e, const std::string &n)
 Throw an error for the shape error e of the value of n.
void visit (long long int k)
 Account for visiting k values in expressions.
void set (const std::string &n, Value &&v)
 Define n as v in the innermost frame.
const Value * lookup (const std::string &n) const
 Return the value of n, or null if it is not defined.
const Value & ref (const Expr &e, Value &tmp)
 Evaluate e, avoiding a copy for names.
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.
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.
int count_records (const RecordRef &l)
 Return the number of records in list l.
size_t record_start (const RecordRef &l, int i)
 Return where record i of list l starts in the input, or npos.
RecordRef records_of (const Expr &e)
 Evaluate e, a record or a list of records.
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.
Value eval (const Expr &e)
 Evaluate e, keeping why only if e explains it.
Value evaluate (const Expr &e)
 Evaluate e.
bool test (const Expr &e)
 Return whether e is true, avoiding a copy for names.
bool explained (const Expr &e)
 Return whether e is true, with only its own explanation in why.
Value unary (const Expr &e)
 Evaluate unary expression e.
Value binary (const Expr &e)
 Evaluate binary expression e.
bool compare (const Value &a, const Value &b, const Expr &e)
 Compare single values a and b with the operator of e.
Value call (const Expr &e)
 Call a function (names and arguments are checked by the parser).
bool defined (const Expr &e) const
 Test whether name e is defined.
bool distinct (const Expr &e)
 Test whether all integers in the arguments of call e differ.
long long int index (const Expr &e)
 Return the value of index e.
std::string scalar_hint (const Expr &e) const
 Return a hint for indexing e, a single value.
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::elements).
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.
Value comprehension (const Expr &e)
 all, any, count, and sum over the elements of an array
long long int count (const Expr &e, const char *what)
 Return the value of e, a count described by what.
bool holds (const Stmt &s, std::string &error)
 Test whether check s holds, and otherwise store why it fails in error.
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.
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, and return whether it holds.
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.
Place place (size_t q) const
 Return the place of position q in the input, or the current place if q is 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.

Static Protected Member Functions

static bool truth (const Value &v)
 Test whether v is true.
static Value boolean (bool b)
 Return b as an integer.
static bool explains (const Expr &e)
 Test whether e passes on why it is false (see why).
static std::string indexed (const Expr &e)
 Describe the array of index expression e, for messages.
static std::string array_name (const Expr &a)
 Describe array a of a comprehension, for messages.
static std::string record_text (const Record &r, const Seq< int > &at)
 Describe the records at of record name r, innermost first.

Protected Attributes

const SpecImpl & spec
 The spec.
Input in
 The input.
Seq< Seq< Entry > > frames
 Values: the outermost frame and one per active repeat iteration.
Seq< Context > context
 Description of the statements being executed, for errors.
int spec_line
 Spec line of the current statement.
const Binding * bindings
 Names bound by the comprehensions being evaluated.
const Stmt * checked
 The check being evaluated, or null.
Seq< const Value * > records
 Values of its record names (see Record).
const Seq< int > * record_at
 The records of the deepest of them, one index per repeat level.
Seq< Witness > why
 Why the last condition evaluated is false, for messages: the elements of the all-comprehensions that failed, innermost first.
long long int effort
 Values visited by expressions.
const long long int max_effort
 Limit for effort, which grows with the input, so that repeated or nested expressions cannot take time far beyond the input's size.

Static Protected Attributes

static const long long int base_effort = 1LL << 20
 Base of the limit for effort.

Detailed Description

Evaluator of the expressions of a spec on an input.

Holds the values defined so far and evaluates expressions and checks with them. Errors point at the current position in the input.

Definition at line 367 of file eval.hpp.

Constructor & Destructor Documentation

◆ Evaluator()

Gecode::Instance::Evaluator::Evaluator ( const SpecImpl & s,
const std::string & text,
const std::string & origin )

Initialize for spec s and input text from origin.

Member Function Documentation

◆ located() [1/2]

std::string Gecode::Instance::Evaluator::located ( const std::string & msg)
protected

Return the error message msg with the location and context.

◆ located() [2/2]

std::string Gecode::Instance::Evaluator::located ( const std::string & msg,
const Place & at )
protected

Return the error message msg at at with the context.

◆ fail() [1/2]

void Gecode::Instance::Evaluator::fail ( const std::string & msg)
protected

Throw an error with message msg at the current position.

◆ fail() [2/2]

void Gecode::Instance::Evaluator::fail ( const ShapeError & e,
const std::string & n )
protected

Throw an error for the shape error e of the value of n.

◆ visit()

void Gecode::Instance::Evaluator::visit ( long long int k)
protected

Account for visiting k values in expressions.

◆ set()

void Gecode::Instance::Evaluator::set ( const std::string & n,
Value && v )
protected

Define n as v in the innermost frame.

◆ lookup()

const Value * Gecode::Instance::Evaluator::lookup ( const std::string & n) const
protected

Return the value of n, or null if it is not defined.

◆ truth()

bool Gecode::Instance::Evaluator::truth ( const Value & v)
staticprotected

Test whether v is true.

◆ boolean()

Value Gecode::Instance::Evaluator::boolean ( bool b)
staticprotected

Return b as an integer.

◆ ref()

const Value & Gecode::Instance::Evaluator::ref ( const Expr & e,
Value & tmp )
protected

Evaluate e, avoiding a copy for names.

The value is stored in tmp unless e is a name. Callers pass an integer scalar without a leaf as tmp, which needs no memory.

◆ record_path()

Seq< int > Gecode::Instance::Evaluator::record_path ( int i) const
protected

Return the indices of the record at of the check that select the records of its record name i.

◆ starts()

const Value & Gecode::Instance::Evaluator::starts ( const Stmt * r,
const std::string & n )
protected

Return the record starts of repeat r, failing for n if the repeat has not run yet.

◆ count_records()

int Gecode::Instance::Evaluator::count_records ( const RecordRef & l)
protected

Return the number of records in list l.

◆ record_start()

size_t Gecode::Instance::Evaluator::record_start ( const RecordRef & l,
int i )
protected

Return where record i of list l starts in the input, or npos.

◆ records_of()

RecordRef Gecode::Instance::Evaluator::records_of ( const Expr & e)
protected

Evaluate e, a record or a list of records.

◆ field()

const Value & Gecode::Instance::Evaluator::field ( const Expr & e,
Value & tmp )
protected

Evaluate field e of a record or a list of records.

The field of a list is the array of the field of each record. The value is stored in tmp unless it needs no copy.

◆ integer()

long long int Gecode::Instance::Evaluator::integer ( const Value & v,
const std::string & op )
protected

Return the integer of single value v, or fail for op.

◆ explains()

bool Gecode::Instance::Evaluator::explains ( const Expr & e)
staticprotected

Test whether e passes on why it is false (see why).

◆ eval()

Value Gecode::Instance::Evaluator::eval ( const Expr & e)
protected

Evaluate e, keeping why only if e explains it.

◆ evaluate()

Value Gecode::Instance::Evaluator::evaluate ( const Expr & e)
protected

Evaluate e.

◆ test()

bool Gecode::Instance::Evaluator::test ( const Expr & e)
protected

Return whether e is true, avoiding a copy for names.

◆ explained()

bool Gecode::Instance::Evaluator::explained ( const Expr & e)
protected

Return whether e is true, with only its own explanation in why.

◆ unary()

Value Gecode::Instance::Evaluator::unary ( const Expr & e)
protected

Evaluate unary expression e.

◆ binary()

Value Gecode::Instance::Evaluator::binary ( const Expr & e)
protected

Evaluate binary expression e.

◆ compare()

bool Gecode::Instance::Evaluator::compare ( const Value & a,
const Value & b,
const Expr & e )
protected

Compare single values a and b with the operator of e.

◆ call()

Value Gecode::Instance::Evaluator::call ( const Expr & e)
protected

Call a function (names and arguments are checked by the parser).

◆ defined()

bool Gecode::Instance::Evaluator::defined ( const Expr & e) const
protected

Test whether name e is defined.

◆ distinct()

bool Gecode::Instance::Evaluator::distinct ( const Expr & e)
protected

Test whether all integers in the arguments of call e differ.

◆ indexed()

std::string Gecode::Instance::Evaluator::indexed ( const Expr & e)
staticprotected

Describe the array of index expression e, for messages.

◆ index()

long long int Gecode::Instance::Evaluator::index ( const Expr & e)
protected

Return the value of index e.

◆ scalar_hint()

std::string Gecode::Instance::Evaluator::scalar_hint ( const Expr & e) const
protected

Return a hint for indexing e, a single value.

A record name in a check is one record, so that indexing the records needs their name.

◆ subscript()

Value Gecode::Instance::Evaluator::subscript ( const Expr & e)
protected

a[i]: element i, counted from 0, of the outermost list of a

◆ array_name()

std::string Gecode::Instance::Evaluator::array_name ( const Expr & a)
staticprotected

Describe array a of a comprehension, for messages.

◆ element_records()

RecordRef Gecode::Instance::Evaluator::element_records ( const Expr & e,
const Expr & a )
protected

Return the records that are the elements of array a of comprehension e, an array of values (see Expr::elements).

◆ explain()

void Gecode::Instance::Evaluator::explain ( const Expr & e,
const RecordRef & r,
int i )
protected

Add why element i of the array of all-comprehension e, with records r, is false.

◆ comprehension()

Value Gecode::Instance::Evaluator::comprehension ( const Expr & e)
protected

all, any, count, and sum over the elements of an array

The name of the comprehension e is bound to each element of the outermost list of the array in turn, or to each record of a list of records. all and any stop at the first element that decides the result.

◆ count()

long long int Gecode::Instance::Evaluator::count ( const Expr & e,
const char * what )
protected

Return the value of e, a count described by what.

◆ holds()

bool Gecode::Instance::Evaluator::holds ( const Stmt & s,
std::string & error )
protected

Test whether check s holds, and otherwise store why it fails in error.

The check holds for every record of its record names (see Record) that are defined. The others are not defined when its expression uses them.

◆ ranges()

bool Gecode::Instance::Evaluator::ranges ( const Stmt & s,
int i,
int level ) const
protected

Test whether record name i of check s is defined and ranges over the repeat at level.

◆ check_records()

bool Gecode::Instance::Evaluator::check_records ( const Stmt & s,
int deepest,
Seq< int > & at,
std::string & error )
protected

Evaluate check s for the records inside the records at of its record name deepest, and return whether it holds.

at has a record number per repeat level, from the outermost. Each record name that ranges over a level is set to its record. If the check fails, error is why.

◆ record_place()

size_t Gecode::Instance::Evaluator::record_place ( const Record & r,
const Seq< int > & at )
protected

Return where the record at of record name r starts in the input, or npos if that is unknown.

◆ place()

Place Gecode::Instance::Evaluator::place ( size_t q) const
protected

Return the place of position q in the input, or the current place if q is npos.

◆ record_text()

std::string Gecode::Instance::Evaluator::record_text ( const Record & r,
const Seq< int > & at )
staticprotected

Describe the records at of record name r, innermost first.

◆ failure()

std::string Gecode::Instance::Evaluator::failure ( const Stmt & s,
int deepest,
const Seq< int > & at )
protected

Return why check s fails for the records at of its record name deepest.

Member Data Documentation

◆ spec

const SpecImpl& Gecode::Instance::Evaluator::spec
protected

The spec.

Definition at line 373 of file eval.hpp.

◆ in

Input Gecode::Instance::Evaluator::in
protected

The input.

Definition at line 375 of file eval.hpp.

◆ frames

Seq<Seq<Entry> > Gecode::Instance::Evaluator::frames
protected

Values: the outermost frame and one per active repeat iteration.

Definition at line 377 of file eval.hpp.

◆ context

Seq<Context> Gecode::Instance::Evaluator::context
protected

Description of the statements being executed, for errors.

Definition at line 379 of file eval.hpp.

◆ spec_line

int Gecode::Instance::Evaluator::spec_line
protected

Spec line of the current statement.

Definition at line 381 of file eval.hpp.

◆ bindings

const Binding* Gecode::Instance::Evaluator::bindings
protected

Names bound by the comprehensions being evaluated.

Definition at line 383 of file eval.hpp.

◆ checked

const Stmt* Gecode::Instance::Evaluator::checked
protected

The check being evaluated, or null.

Definition at line 385 of file eval.hpp.

◆ records

Seq<const Value*> Gecode::Instance::Evaluator::records
protected

Values of its record names (see Record).

Definition at line 387 of file eval.hpp.

◆ record_at

const Seq<int>* Gecode::Instance::Evaluator::record_at
protected

The records of the deepest of them, one index per repeat level.

Definition at line 389 of file eval.hpp.

◆ why

Seq<Witness> Gecode::Instance::Evaluator::why
protected

Why the last condition evaluated is false, for messages: the elements of the all-comprehensions that failed, innermost first.

Definition at line 392 of file eval.hpp.

◆ effort

long long int Gecode::Instance::Evaluator::effort
protected

Values visited by expressions.

Definition at line 394 of file eval.hpp.

◆ max_effort

const long long int Gecode::Instance::Evaluator::max_effort
protected

Limit for effort, which grows with the input, so that repeated or nested expressions cannot take time far beyond the input's size.

Definition at line 397 of file eval.hpp.

◆ base_effort

const long long int Gecode::Instance::Evaluator::base_effort = 1LL << 20
staticprotected

Base of the limit for effort.

Definition at line 399 of file eval.hpp.


The documentation for this class was generated from the following file: