From: Andrew Reynolds Date: Sun, 18 Aug 2019 01:15:07 +0000 (-0500) Subject: Cleaning make bound var in smt2 parser (#3192) X-Git-Tag: cvc5-1.0.0~4006 X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=6f7c6f000e804a9b92166ce21206a006e3e92f06;p=cvc5.git Cleaning make bound var in smt2 parser (#3192) --- 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 Parser::mkBoundVars( + std::vector >& sortedVarNames) +{ + std::vector vars; + for (std::pair& 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 mkBoundVars( + std::vector >& 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* cmd] t = PARSER_STATE->mkFlatFunctionType(sorts, t, flattenVars); } PARSER_STATE->pushScope(true); - for(std::vector >::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* cmd] sygus_type = range; // create new scope for parsing the grammar, if any PARSER_STATE->pushScope(true); - for (const std::pair& 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* cmd] sygus_type = range; // create new scope for parsing the grammar, if any PARSER_STATE->pushScope(true); - for (const std::pair& 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* cmd] { /* add variables to parser state before parsing term */ Debug("parser") << "define fun: '" << name << "'" << std::endl; PARSER_STATE->pushScope(true); - for(std::vector >::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* cmd] { /* add variables to parser state before parsing term */ Debug("parser") << "define const: '" << name << "'" << std::endl; PARSER_STATE->pushScope(true); - for(std::vector >::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* cmd] { kind = CVC4::kind::RR_REWRITE; PARSER_STATE->pushScope(true); - for(std::vector >::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* cmd] LPAREN_TOK sortedVarList[sortedVarNames] RPAREN_TOK { PARSER_STATE->pushScope(true); - for(std::vector >::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 >::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& 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);