summaryrefslogtreecommitdiff
path: root/src/parser
diff options
context:
space:
mode:
authorAndrew Reynolds <andrew.j.reynolds@gmail.com>2019-08-17 20:15:07 -0500
committerGitHub <noreply@github.com>2019-08-17 20:15:07 -0500
commit6f7c6f000e804a9b92166ce21206a006e3e92f06 (patch)
tree47955bc9a8a3116c1c8d8b47b14717e469beb4bb /src/parser
parent246a0bc47aa23f3d4225a78e0600094d0e6ac639 (diff)
Cleaning make bound var in smt2 parser (#3192)
Diffstat (limited to 'src/parser')
-rw-r--r--src/parser/parser.cpp11
-rw-r--r--src/parser/parser.h12
-rw-r--r--src/parser/smt2/Smt2.g54
3 files changed, 31 insertions, 46 deletions
diff --git a/src/parser/parser.cpp b/src/parser/parser.cpp
index 8217e32c6..73e9239b8 100644
--- a/src/parser/parser.cpp
+++ b/src/parser/parser.cpp
@@ -220,6 +220,17 @@ Expr Parser::mkBoundVar(const std::string& name, const Type& type) {
return expr;
}
+std::vector<Expr> Parser::mkBoundVars(
+ std::vector<std::pair<std::string, Type> >& sortedVarNames)
+{
+ std::vector<Expr> vars;
+ for (std::pair<std::string, CVC4::Type>& i : sortedVarNames)
+ {
+ vars.push_back(mkBoundVar(i.first, i.second));
+ }
+ return vars;
+}
+
Expr Parser::mkAnonymousFunction(const std::string& prefix, const Type& type,
uint32_t flags) {
if (d_globalDeclarations) {
diff --git a/src/parser/parser.h b/src/parser/parser.h
index 9319181db..a1ee24bb6 100644
--- a/src/parser/parser.h
+++ b/src/parser/parser.h
@@ -482,8 +482,18 @@ public:
uint32_t flags = ExprManager::VAR_FLAG_NONE,
bool doOverload = false);
- /** Create a new CVC4 bound variable expression of the given type. */
+ /**
+ * Create a new CVC4 bound variable expression of the given type. This binds
+ * the symbol name to that variable in the current scope.
+ */
Expr mkBoundVar(const std::string& name, const Type& type);
+ /**
+ * Create a new CVC4 bound variable expressions of the given names and types.
+ * Like the method above, this binds these names to those variables in the
+ * current scope.
+ */
+ std::vector<Expr> mkBoundVars(
+ std::vector<std::pair<std::string, Type> >& sortedVarNames);
/**
* Create a set of new CVC4 bound variable expressions of the given type.
diff --git a/src/parser/smt2/Smt2.g b/src/parser/smt2/Smt2.g
index 9e7bc74ee..1d07969ff 100644
--- a/src/parser/smt2/Smt2.g
+++ b/src/parser/smt2/Smt2.g
@@ -346,12 +346,7 @@ command [std::unique_ptr<CVC4::Command>* cmd]
t = PARSER_STATE->mkFlatFunctionType(sorts, t, flattenVars);
}
PARSER_STATE->pushScope(true);
- for(std::vector<std::pair<std::string, CVC4::Type> >::const_iterator i =
- sortedVarNames.begin(), iend = sortedVarNames.end();
- i != iend;
- ++i) {
- terms.push_back(PARSER_STATE->mkBoundVar((*i).first, (*i).second));
- }
+ terms = PARSER_STATE->mkBoundVars(sortedVarNames);
}
term[expr, expr2]
{
@@ -624,10 +619,7 @@ sygusCommand [std::unique_ptr<CVC4::Command>* cmd]
sygus_type = range;
// create new scope for parsing the grammar, if any
PARSER_STATE->pushScope(true);
- for (const std::pair<std::string, CVC4::Type>& p : sortedVarNames)
- {
- sygus_vars.push_back(PARSER_STATE->mkBoundVar(p.first, p.second));
- }
+ sygus_vars = PARSER_STATE->mkBoundVars(sortedVarNames);
}
(
// optionally, read the sygus grammar
@@ -676,10 +668,7 @@ sygusCommand [std::unique_ptr<CVC4::Command>* cmd]
sygus_type = range;
// create new scope for parsing the grammar, if any
PARSER_STATE->pushScope(true);
- for (const std::pair<std::string, CVC4::Type>& p : sortedVarNames)
- {
- sygus_vars.push_back(PARSER_STATE->mkBoundVar(p.first, p.second));
- }
+ sygus_vars = PARSER_STATE->mkBoundVars(sortedVarNames);
}
(
// optionally, read the sygus grammar
@@ -1436,11 +1425,7 @@ extendedCommand[std::unique_ptr<CVC4::Command>* cmd]
{ /* add variables to parser state before parsing term */
Debug("parser") << "define fun: '" << name << "'" << std::endl;
PARSER_STATE->pushScope(true);
- for(std::vector<std::pair<std::string, CVC4::Type> >::const_iterator i =
- sortedVarNames.begin(), iend = sortedVarNames.end(); i != iend;
- ++i) {
- terms.push_back(PARSER_STATE->mkBoundVar((*i).first, (*i).second));
- }
+ terms = PARSER_STATE->mkBoundVars(sortedVarNames);
}
term[e,e2]
{ PARSER_STATE->popScope();
@@ -1470,11 +1455,7 @@ extendedCommand[std::unique_ptr<CVC4::Command>* cmd]
{ /* add variables to parser state before parsing term */
Debug("parser") << "define const: '" << name << "'" << std::endl;
PARSER_STATE->pushScope(true);
- for(std::vector<std::pair<std::string, CVC4::Type> >::const_iterator i =
- sortedVarNames.begin(), iend = sortedVarNames.end(); i != iend;
- ++i) {
- terms.push_back(PARSER_STATE->mkBoundVar((*i).first, (*i).second));
- }
+ terms = PARSER_STATE->mkBoundVars(sortedVarNames);
}
term[e, e2]
{ PARSER_STATE->popScope();
@@ -1654,12 +1635,7 @@ rewriterulesCommand[std::unique_ptr<CVC4::Command>* cmd]
{
kind = CVC4::kind::RR_REWRITE;
PARSER_STATE->pushScope(true);
- for(std::vector<std::pair<std::string, CVC4::Type> >::const_iterator i =
- sortedVarNames.begin(), iend = sortedVarNames.end();
- i != iend;
- ++i) {
- args.push_back(PARSER_STATE->mkBoundVar((*i).first, (*i).second));
- }
+ args = PARSER_STATE->mkBoundVars(sortedVarNames);
bvl = MK_EXPR(kind::BOUND_VAR_LIST, args);
}
LPAREN_TOK ( pattern[expr] { triggers.push_back( expr ); } )* RPAREN_TOK
@@ -1695,12 +1671,7 @@ rewriterulesCommand[std::unique_ptr<CVC4::Command>* cmd]
LPAREN_TOK sortedVarList[sortedVarNames] RPAREN_TOK
{
PARSER_STATE->pushScope(true);
- for(std::vector<std::pair<std::string, CVC4::Type> >::const_iterator i =
- sortedVarNames.begin(), iend = sortedVarNames.end();
- i != iend;
- ++i) {
- args.push_back(PARSER_STATE->mkBoundVar((*i).first, (*i).second));
- }
+ args = PARSER_STATE->mkBoundVars(sortedVarNames);
bvl = MK_EXPR(kind::BOUND_VAR_LIST, args);
}
LPAREN_TOK ( pattern[expr] { triggers.push_back( expr ); } )* RPAREN_TOK
@@ -1876,12 +1847,7 @@ termNonVariable[CVC4::Expr& expr, CVC4::Expr& expr2]
LPAREN_TOK sortedVarList[sortedVarNames] RPAREN_TOK
{
PARSER_STATE->pushScope(true);
- for(std::vector<std::pair<std::string, CVC4::Type> >::const_iterator i =
- sortedVarNames.begin(), iend = sortedVarNames.end();
- i != iend;
- ++i) {
- args.push_back(PARSER_STATE->mkBoundVar((*i).first, (*i).second));
- }
+ args = PARSER_STATE->mkBoundVars(sortedVarNames);
Expr bvl = MK_EXPR(kind::BOUND_VAR_LIST, args);
args.clear();
args.push_back(bvl);
@@ -2130,9 +2096,7 @@ termNonVariable[CVC4::Expr& expr, CVC4::Expr& expr2]
LPAREN_TOK sortedVarList[sortedVarNames] RPAREN_TOK
{
PARSER_STATE->pushScope(true);
- for(const std::pair<std::string, CVC4::Type>& svn : sortedVarNames){
- args.push_back(PARSER_STATE->mkBoundVar(svn.first, svn.second));
- }
+ args = PARSER_STATE->mkBoundVars(sortedVarNames);
Expr bvl = MK_EXPR(kind::BOUND_VAR_LIST, args);
args.clear();
args.push_back(bvl);
generated by cgit on debian on lair
contact matthew@masot.net with questions or feedback