dlinear  0.0.1
Delta-complete SMT solver for linear programming
Loading...
Searching...
No Matches
Driver.h
1
12#pragma once
13
14#include <istream>
15#include <string>
16#include <utility>
17#include <variant>
18#include <vector>
19
20#include "dlinear/parser/Driver.h"
21#include "dlinear/parser/smt2/FunctionDefinition.h"
22#include "dlinear/parser/smt2/Term.h"
23#include "dlinear/parser/smt2/scanner.h"
24#include "dlinear/solver/Context.h"
25#include "dlinear/util/ScopedUnorderedMap.hpp"
26
27namespace dlinear::smt2 {
28
38class Smt2Driver : public Driver {
39 public:
41 explicit Smt2Driver(Context &context); // NOLINT(runtime/references): Reference context filled during parsing.
42
47 static void error(const location &l, const std::string &m);
48
49 bool ParseStreamCore(std::istream &in) override;
50
60 static Formula EliminateBooleanVariables(const Variables &vars, const Formula &f);
61
71 void DefineFun(const std::string &name, const std::vector<Variable> &parameters, Sort return_type, const Term &body);
72
77 Variable RegisterVariable(const std::string &name, Sort sort);
78
80 Variable DeclareVariable(const std::string &name, Sort sort);
81
83 void DeclareVariable(const std::string &name, Sort sort, const Term &lb, const Term &ub);
84
86 Variable DeclareLocalVariable(const std::string &name, Sort sort);
87
89 void DefineLocalConstant(const std::string &name, const Expression &value);
90
97 void GetValue(const std::vector<Term> &term_list) const;
98
105 std::variant<const Expression *, const Variable *> LookupDefinedName(const std::string &name) const;
112 const Expression &LookupConstant(const std::string &name) const;
119 const Variable &LookupVariable(const std::string &name) const;
128 Term LookupFunction(const std::string &name, const std::vector<Term> &arguments) const;
129
130 void PushScope() { scope_variables_.push(); }
131
132 void PopScope() { scope_variables_.pop(); }
133
134 std::string MakeUniqueName(const std::string &name);
135
141
142 private:
144
148
149 int64_t nextUniqueId_{};
150};
151
152} // namespace dlinear::smt2
Context class that holds the set of constraints and provide Assert/Push/Pop/CheckSat functionalities.
Definition Context.h:31
The Driver is the base class for all the parsers.
Definition Driver.h:26
const Context & context() const
Get read-only access to the enabled of the Driver.
Definition Driver.h:143
Represents a symbolic form of an expression.
Represents a symbolic form of a first-order logic formula.
Represents a symbolic variable.
Represents a set of variables.
The Smt2Driver class brings together all components.
Definition Driver.h:38
Smt2Scanner * scanner_
The scanner producing the tokens for the parser.
Definition Driver.h:143
const Variable & LookupVariable(const std::string &name) const
Lookup a variable associated with a name name.
Definition Driver.cpp:132
void DefineLocalConstant(const std::string &name, const Expression &value)
Define a constant within the current scope.
Definition Driver.cpp:144
bool ParseStreamCore(std::istream &in) override
Parse the stream.
Definition Driver.cpp:21
Variable RegisterVariable(const std::string &name, Sort sort)
Register a variable with name name and sort s in the scope.
Definition Driver.cpp:51
ScopedUnorderedMap< std::string, Expression > scope_constants_
Scoped map from a name to a constant.
Definition Driver.h:145
Term LookupFunction(const std::string &name, const std::vector< Term > &arguments) const
Lookup a function with name name and run it with arguments, producing a new term.
Definition Driver.cpp:138
ScopedUnorderedMap< std::string, FunctionDefinition > scope_functions_
Scoped map from a name to a Function.
Definition Driver.h:147
Smt2Driver(Context &context)
construct a new parser driver context
Definition Driver.cpp:19
void DefineFun(const std::string &name, const std::vector< Variable > &parameters, Sort return_type, const Term &body)
Called by the define-fun command in the SMT-2 file.
Definition Driver.cpp:45
Variable DeclareVariable(const std::string &name, Sort sort)
Declare a variable with name name and sort sort.
Definition Driver.cpp:57
void GetValue(const std::vector< Term > &term_list) const
Get the value of all the terms in term_list.
Definition Driver.cpp:82
static Formula EliminateBooleanVariables(const Variables &vars, const Formula &f)
Eliminate Boolean variables vars from f.
Definition Driver.cpp:35
int64_t nextUniqueId_
Sequential value concatenated to names to make them unique.
Definition Driver.h:149
Variable DeclareLocalVariable(const std::string &name, Sort sort)
Declare a new variable with label name that is globally unique and cannot occur in an SMT-LIBv2 file.
Definition Driver.cpp:75
Smt2Scanner * scanner()
Pointer to the current scanner instance, this is used to connect the parser to the scanner.
Definition Driver.h:140
static void error(const location &l, const std::string &m)
Error handling with associated line number.
Definition Driver.cpp:33
ScopedUnorderedMap< std::string, Variable > scope_variables_
Scoped map from a name to a Variable.
Definition Driver.h:146
const Expression & LookupConstant(const std::string &name) const
Lookup a constant expression associated with a name name.
Definition Driver.cpp:126
std::variant< const Expression *, const Variable * > LookupDefinedName(const std::string &name) const
Lookup a variable or constant expression associated with a name name.
Definition Driver.cpp:118
Smt2Scanner is a derived class to add some extra function to the scanner class.
Definition scanner.h:41
Generic term that can be either an expression or a formula.
Definition Term.h:34
Namespace for the SMT2 parser of the dlinear library.
Definition Driver.cpp:17
Sort
Sort of a term.
Definition Sort.h:18