summaryrefslogtreecommitdiff
path: root/src/smt/listeners.cpp
blob: e322531a7b46f45e7e6b30775a31df1118931206 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
/*********************                                                        */
/*! \file listeners.cpp
 ** \verbatim
 ** Top contributors (to current version):
 **   Andrew Reynolds, Abdalrhman Mohamed
 ** This file is part of the CVC4 project.
 ** Copyright (c) 2009-2021 by the authors listed in the file AUTHORS
 ** in the top-level source directory and their institutional affiliations.
 ** All rights reserved.  See the file COPYING in the top-level source
 ** directory for licensing information.\endverbatim
 **
 ** \brief Implements listener classes for SMT engine.
 **/

#include "smt/listeners.h"

#include "base/configuration.h"
#include "expr/attribute.h"
#include "expr/node_manager_attributes.h"
#include "options/smt_options.h"
#include "printer/printer.h"
#include "smt/dump.h"
#include "smt/dump_manager.h"
#include "smt/node_command.h"
#include "smt/smt_engine.h"
#include "smt/smt_engine_scope.h"

namespace cvc5 {
namespace smt {

ResourceOutListener::ResourceOutListener(SmtEngine& smt) : d_smt(smt) {}

void ResourceOutListener::notify()
{
  SmtScope scope(&d_smt);
  Assert(smt::smtEngineInScope());
  d_smt.interrupt();
}

SmtNodeManagerListener::SmtNodeManagerListener(DumpManager& dm,
                                               OutputManager& outMgr)
    : d_dm(dm), d_outMgr(outMgr)
{
}

void SmtNodeManagerListener::nmNotifyNewSort(TypeNode tn, uint32_t flags)
{
  DeclareTypeNodeCommand c(tn.getAttribute(expr::VarNameAttr()), 0, tn);
  if ((flags & NodeManager::SORT_FLAG_PLACEHOLDER) == 0)
  {
    d_dm.addToDump(c);
  }
}

void SmtNodeManagerListener::nmNotifyNewSortConstructor(TypeNode tn,
                                                        uint32_t flags)
{
  DeclareTypeNodeCommand c(tn.getAttribute(expr::VarNameAttr()),
                           tn.getAttribute(expr::SortArityAttr()),
                           tn);
  if ((flags & NodeManager::SORT_FLAG_PLACEHOLDER) == 0)
  {
    d_dm.addToDump(c);
  }
}

void SmtNodeManagerListener::nmNotifyNewDatatypes(
    const std::vector<TypeNode>& dtts, uint32_t flags)
{
  if ((flags & NodeManager::DATATYPE_FLAG_PLACEHOLDER) == 0)
  {
    if (Configuration::isAssertionBuild())
    {
      for (CVC4_UNUSED const TypeNode& dt : dtts)
      {
        Assert(dt.isDatatype());
      }
    }
    DeclareDatatypeNodeCommand c(dtts);
    d_dm.addToDump(c);
  }
}

void SmtNodeManagerListener::nmNotifyNewVar(TNode n)
{
  DeclareFunctionNodeCommand c(
      n.getAttribute(expr::VarNameAttr()), n, n.getType());
  d_dm.addToDump(c);
}

void SmtNodeManagerListener::nmNotifyNewSkolem(TNode n,
                                               const std::string& comment,
                                               uint32_t flags)
{
  std::string id = n.getAttribute(expr::VarNameAttr());
  DeclareFunctionNodeCommand c(id, n, n.getType());
  if (Dump.isOn("skolems") && comment != "")
  {
    d_outMgr.getPrinter().toStreamCmdComment(d_outMgr.getDumpOut(),
                                             id + " is " + comment);
  }
  d_dm.addToDump(c, "skolems");
}

}  // namespace smt
}  // namespace cvc5
generated by cgit on debian on lair
contact matthew@masot.net with questions or feedback