summaryrefslogtreecommitdiff
path: root/src/parser/parser.cpp
diff options
context:
space:
mode:
authorMorgan Deters <mdeters@gmail.com>2011-04-18 08:59:09 +0000
committerMorgan Deters <mdeters@gmail.com>2011-04-18 08:59:09 +0000
commitb90081962840584bb9eeda368ea232a7d42a292b (patch)
treec0f568bc787744a5d53b79a818c0f1bd819596cf /src/parser/parser.cpp
parent7d281fba79b1c9f3ae646d3371a0e52e2efd3bba (diff)
Partial merge from datatypes-merge branch:
1. Defines a new type "DatatypeType", a type-constant that holds a Datatype, describing an inductive data type. 2. CVC language parser supports datatypes. 3. CVC language printer now functional. 4. Minor other cleanups. No performance impact is expected outside of datatypes. I'm verifying that that is the case with a cluster job this morning.
Diffstat (limited to 'src/parser/parser.cpp')
-rw-r--r--src/parser/parser.cpp70
1 files changed, 61 insertions, 9 deletions
diff --git a/src/parser/parser.cpp b/src/parser/parser.cpp
index 0ebccf720..c8a9876d5 100644
--- a/src/parser/parser.cpp
+++ b/src/parser/parser.cpp
@@ -72,8 +72,7 @@ Expr Parser::getFunction(const std::string& name) {
return getSymbol(name, SYM_VARIABLE);
}
-Type
-Parser::getType(const std::string& var_name,
+Type Parser::getType(const std::string& var_name,
SymbolType type) {
Assert( isDeclared(var_name, type) );
Type t = getSymbol(var_name, type).getType();
@@ -98,9 +97,15 @@ bool Parser::isBoolean(const std::string& name) {
return isDeclared(name, SYM_VARIABLE) && getType(name).isBoolean();
}
-/* Returns true if name is bound to a function. */
-bool Parser::isFunction(const std::string& name) {
- return isDeclared(name, SYM_VARIABLE) && getType(name).isFunction();
+/* Returns true if name is bound to a function-like thing (function,
+ * constructor, tester, or selector). */
+bool Parser::isFunctionLike(const std::string& name) {
+ if(!isDeclared(name, SYM_VARIABLE)) {
+ return false;
+ }
+ Type type = getType(name);
+ return type.isFunction() || type.isConstructor() ||
+ type.isTester() || type.isSelector();
}
/* Returns true if name is bound to a defined function. */
@@ -200,7 +205,7 @@ Parser::mkSortConstructor(const std::string& name, size_t arity) {
return type;
}
-const std::vector<Type>
+std::vector<Type>
Parser::mkSorts(const std::vector<std::string>& names) {
std::vector<Type> types;
for(unsigned i = 0; i < names.size(); ++i) {
@@ -209,6 +214,53 @@ Parser::mkSorts(const std::vector<std::string>& names) {
return types;
}
+std::vector<DatatypeType>
+Parser::mkMutualDatatypeTypes(const std::vector<Datatype>& datatypes) {
+ std::vector<DatatypeType> types =
+ d_exprManager->mkMutualDatatypeTypes(datatypes);
+ Assert(datatypes.size() == types.size());
+ for(unsigned i = 0; i < datatypes.size(); ++i) {
+ DatatypeType t = types[i];
+ const Datatype& dt = t.getDatatype();
+ Debug("parser-idt") << "define " << dt.getName() << " as " << t << std::endl;
+ defineType(dt.getName(), t);
+ for(Datatype::const_iterator j = dt.begin(),
+ j_end = dt.end();
+ j != j_end;
+ ++j) {
+ const Datatype::Constructor& ctor = *j;
+ Expr::printtypes::Scope pts(Debug("parser-idt"), true);
+ Expr constructor = ctor.getConstructor();
+ Debug("parser-idt") << "+ define " << constructor << std::endl;
+ string constructorName = constructor.toString();
+ if(isDeclared(constructorName, SYM_VARIABLE)) {
+ throw ParserException(constructorName + " already declared");
+ }
+ defineVar(constructorName, constructor);
+ Expr tester = ctor.getTester();
+ Debug("parser-idt") << "+ define " << tester << std::endl;
+ string testerName = tester.toString();
+ if(isDeclared(testerName, SYM_VARIABLE)) {
+ throw ParserException(testerName + " already declared");
+ }
+ defineVar(testerName, tester);
+ for(Datatype::Constructor::const_iterator k = ctor.begin(),
+ k_end = ctor.end();
+ k != k_end;
+ ++k) {
+ Expr selector = (*k).getSelector();
+ Debug("parser-idt") << "+++ define " << selector << std::endl;
+ string selectorName = selector.toString();
+ if(isDeclared(selectorName, SYM_VARIABLE)) {
+ throw ParserException(selectorName + " already declared");
+ }
+ defineVar(selectorName, selector);
+ }
+ }
+ }
+ return types;
+}
+
bool Parser::isDeclared(const std::string& name, SymbolType type) {
switch(type) {
case SYM_VARIABLE:
@@ -249,10 +301,10 @@ void Parser::checkDeclaration(const std::string& varName,
}
}
-void Parser::checkFunction(const std::string& name)
+void Parser::checkFunctionLike(const std::string& name)
throw (ParserException) {
- if( d_checksEnabled && !isFunction(name) ) {
- parseError("Expecting function symbol, found '" + name + "'");
+ if( d_checksEnabled && !isFunctionLike(name) ) {
+ parseError("Expecting function-like symbol, found '" + name + "'");
}
}
generated by cgit on debian on lair
contact matthew@masot.net with questions or feedback