From 2119637a89ad7af0eb8a4d326b78f2ecaa89012d Mon Sep 17 00:00:00 2001 From: Andrew Reynolds Date: Sun, 10 Dec 2017 05:12:22 -0600 Subject: [PATCH] Fix issue 1433. (#1435) --- src/parser/smt2/Smt2.g | 62 ++++++++++++------- test/regress/regress0/datatypes/Makefile.am | 3 +- .../regress/regress0/datatypes/issue1433.smt2 | 7 +++ 3 files changed, 48 insertions(+), 24 deletions(-) create mode 100644 test/regress/regress0/datatypes/issue1433.smt2 diff --git a/src/parser/smt2/Smt2.g b/src/parser/smt2/Smt2.g index 1135d6dd4..81f62ccf4 100644 --- a/src/parser/smt2/Smt2.g +++ b/src/parser/smt2/Smt2.g @@ -1455,6 +1455,8 @@ datatypes_2_5_DefCommand[bool isCo, std::unique_ptr* cmd] std::vector dts; std::string name; std::vector sorts; + std::vector dnames; + std::vector arities; } : { PARSER_STATE->checkThatLogicIsSet(); /* open a scope to keep the UnresolvedTypes contained */ @@ -1474,15 +1476,16 @@ datatypeDefCommand[bool isCo, std::unique_ptr* cmd] @declarations { std::vector dts; std::string name; + std::vector dnames; + std::vector arities; } : { PARSER_STATE->checkThatLogicIsSet(); } - symbol[name,CHECK_UNDECLARED,SYM_SORT] LPAREN_TOK - { std::vector params; - dts.push_back(Datatype(name,params,isCo)); + symbol[name,CHECK_UNDECLARED,SYM_SORT] + { + dnames.push_back(name); + arities.push_back(-1); } - ( LPAREN_TOK constructorDef[dts.back()] RPAREN_TOK )+ - RPAREN_TOK - { cmd->reset(new DatatypeDeclarationCommand(PARSER_STATE->mkMutualDatatypeTypes(dts, true))); } + datatypesDef[isCo, dnames, arities, cmd] ; datatypesDefCommand[bool isCo, std::unique_ptr* cmd] @@ -1490,28 +1493,39 @@ datatypesDefCommand[bool isCo, std::unique_ptr* cmd] std::vector dts; std::string name; std::vector dnames; - std::vector arities; - std::vector params; + std::vector arities; } - : { PARSER_STATE->checkThatLogicIsSet(); PARSER_STATE->pushScope(true); } - LPAREN_TOK /* sorts */ + : { PARSER_STATE->checkThatLogicIsSet(); } + LPAREN_TOK /* datatype definition prelude */ ( LPAREN_TOK symbol[name,CHECK_UNDECLARED,SYM_SORT] n=INTEGER_LITERAL RPAREN_TOK { unsigned arity = AntlrInput::tokenToUnsigned(n); - //Type type; - //if(arity == 0) { - // type = PARSER_STATE->mkSort(name); - //} else { - // type = PARSER_STATE->mkSortConstructor(name, arity); - //} - //types.push_back(type); Debug("parser-dt") << "Datatype : " << name << ", arity = " << arity << std::endl; dnames.push_back(name); - arities.push_back( arity ); + arities.push_back( static_cast(arity) ); } )* RPAREN_TOK LPAREN_TOK - ( LPAREN_TOK { + datatypesDef[isCo, dnames, arities, cmd] + RPAREN_TOK + ; + +/** + * Read a list of datatype definitions for datatypes with names dnames and + * parametric arities arities. A negative value in arities indicates that the + * arity for the corresponding datatype has not been fixed. + */ +datatypesDef[bool isCo, + const std::vector& dnames, + const std::vector& arities, + std::unique_ptr* cmd] +@declarations { + std::vector dts; + std::string name; + std::vector params; +} + : { PARSER_STATE->pushScope(true); } + ( LPAREN_TOK { params.clear(); Debug("parser-dt") << "Processing datatype #" << dts.size() << std::endl; if( dts.size()>=dnames.size() ){ @@ -1523,7 +1537,8 @@ datatypesDefCommand[bool isCo, std::unique_ptr* cmd] { params.push_back( PARSER_STATE->mkSort(name) ); } )* RPAREN_TOK { - if( params.size()!=arities[dts.size()] ){ + // if the arity was fixed by prelude and is not equal to the number of parameters + if( arities[dts.size()]>=0 && static_cast(params.size())!=arities[dts.size()] ){ PARSER_STATE->parseError("Wrong number of parameters for datatype."); } Debug("parser-dt") << params.size() << " parameters for " << dnames[dts.size()] << std::endl; @@ -1532,7 +1547,8 @@ datatypesDefCommand[bool isCo, std::unique_ptr* cmd] LPAREN_TOK ( LPAREN_TOK constructorDef[dts.back()] RPAREN_TOK )+ RPAREN_TOK { PARSER_STATE->popScope(); } - | { if( 0!=arities[dts.size()] ){ + | { // if the arity was fixed by prelude and is not equal to 0 + if( arities[dts.size()]>0 ){ PARSER_STATE->parseError("No parameters given for datatype."); } Debug("parser-dt") << params.size() << " parameters for " << dnames[dts.size()] << std::endl; @@ -1542,8 +1558,8 @@ datatypesDefCommand[bool isCo, std::unique_ptr* cmd] ) RPAREN_TOK )+ - RPAREN_TOK - { PARSER_STATE->popScope(); + { + PARSER_STATE->popScope(); cmd->reset(new DatatypeDeclarationCommand(PARSER_STATE->mkMutualDatatypeTypes(dts, true))); } ; diff --git a/test/regress/regress0/datatypes/Makefile.am b/test/regress/regress0/datatypes/Makefile.am index adad0da32..d346c0056 100644 --- a/test/regress/regress0/datatypes/Makefile.am +++ b/test/regress/regress0/datatypes/Makefile.am @@ -83,7 +83,8 @@ TESTS = \ tuple-no-clash.cvc \ jsat-2.6.smt2 \ acyclicity-sr-ground096.smt2 \ - model-subterms-min.smt2 + model-subterms-min.smt2 \ + issue1433.smt2 # rec5 -- no longer support subrange types FAILING_TESTS = \ diff --git a/test/regress/regress0/datatypes/issue1433.smt2 b/test/regress/regress0/datatypes/issue1433.smt2 new file mode 100644 index 000000000..bac9b8af1 --- /dev/null +++ b/test/regress/regress0/datatypes/issue1433.smt2 @@ -0,0 +1,7 @@ +(set-logic QF_UFDTLIA) +(set-info :status sat) +(declare-datatype MyList (par (T) ((nelem) (cons (hd T) (tl (MyList T)))))) + +(declare-fun a () (MyList Int)) +(assert (> (hd a) 50)) +(check-sat) -- 2.30.2