GCC Code Coverage Report
Directory: . Exec Total Coverage
File: src/expr/sygus_datatype.h Lines: 3 3 100.0 %
Date: 2021-05-22 Branches: 3 10 30.0 %

Line Exec Source
1
/******************************************************************************
2
 * Top contributors (to current version):
3
 *   Andrew Reynolds, Haniel Barbosa
4
 *
5
 * This file is part of the cvc5 project.
6
 *
7
 * Copyright (c) 2009-2021 by the authors listed in the file AUTHORS
8
 * in the top-level source directory and their institutional affiliations.
9
 * All rights reserved.  See the file COPYING in the top-level source
10
 * directory for licensing information.
11
 * ****************************************************************************
12
 *
13
 * A class for constructing SyGuS datatypes.
14
 */
15
#include "cvc5_private.h"
16
17
#ifndef CVC5__EXPR__SYGUS_DATATYPE_H
18
#define CVC5__EXPR__SYGUS_DATATYPE_H
19
20
#include <string>
21
#include <vector>
22
23
#include "expr/attribute.h"
24
#include "expr/dtype.h"
25
#include "expr/node.h"
26
#include "expr/type_node.h"
27
28
namespace cvc5 {
29
30
/** Attribute true for variables that represent any constant */
31
struct SygusAnyConstAttributeId
32
{
33
};
34
typedef expr::Attribute<SygusAnyConstAttributeId, bool> SygusAnyConstAttribute;
35
36
/**
37
 * Information necessary to specify a sygus constructor. Further detail on these
38
 * fields can be found in SygusDatatype below.
39
 */
40
55345
class SygusDatatypeConstructor
41
{
42
 public:
43
  /** The operator that the constructor encodes. */
44
  Node d_op;
45
  /** Name of the constructor. */
46
  std::string d_name;
47
  /** List of argument types. */
48
  std::vector<TypeNode> d_argTypes;
49
  /** Weight of the constructor. */
50
  int d_weight;
51
};
52
53
/**
54
 * Keeps the necessary information for initializing a sygus datatype, which
55
 * includes the operators, names, print callbacks and list of argument types
56
 * for each constructor.
57
 *
58
 * It also maintains a datatype to represent the structure of the type node.
59
 *
60
 * Notice that this class is only responsible for setting SyGuS-related
61
 * information regarding the datatype. It is still required that the user
62
 * of this class construct the datatype type corresponding to the datatype
63
 * e.g. via a call to ExprManager::mkMutualDatatypeTypes().
64
 */
65
1745
class SygusDatatype
66
{
67
 public:
68
  /** constructor */
69
  SygusDatatype(const std::string& name);
70
2974
  ~SygusDatatype() {}
71
  /** get the name of this datatype */
72
  std::string getName() const;
73
  /**
74
   * Add constructor that encodes an application of builtin operator op.
75
   *
76
   * op: the builtin operator,
77
   * name: the name of the constructor,
78
   * argTypes: the argument types of the constructor (typically other sygus
79
   * datatype types).
80
   * spc: the print callback (for custom printing of this node),
81
   * weight: the weight of this constructor.
82
   *
83
   * It should be the case that argTypes are sygus datatype types (possibly
84
   * unresolved) that encode the arguments of the builtin operator. That is,
85
   * if op is the builtin PLUS operator, then argTypes could contain 2+
86
   * sygus datatype types that encode integer.
87
   */
88
  void addConstructor(Node op,
89
                      const std::string& name,
90
                      const std::vector<TypeNode>& argTypes,
91
                      int weight = -1);
92
  /**
93
   * Add constructor that encodes an application of builtin kind k. Like above,
94
   * the arguments argTypes should correspond to sygus datatypes that encode
95
   * the types of the arguments of the kind.
96
   */
97
  void addConstructor(Kind k,
98
                      const std::vector<TypeNode>& argTypes,
99
                      int weight = -1);
100
  /**
101
   * This adds a constructor that corresponds to the any constant constructor
102
   * for the given (builtin) type tn.
103
   */
104
  void addAnyConstantConstructor(TypeNode tn);
105
106
  /** Get the number of constructors added to this class so far */
107
  size_t getNumConstructors() const;
108
109
  /** Get constructor at index i */
110
  const SygusDatatypeConstructor& getConstructor(unsigned i) const;
111
112
  /** builds a datatype with the information in the type object
113
   *
114
   * sygusType: the builtin type that this datatype encodes,
115
   * sygusVars: the formal argument list of the function-to-synthesize,
116
   * allowConst: whether the grammar corresponding to this datatype allows
117
   * any constant,
118
   * allowAll: whether the grammar corresponding to this datatype allows
119
   * any term.
120
   */
121
  void initializeDatatype(TypeNode sygusType,
122
                          Node sygusVars,
123
                          bool allowConst,
124
                          bool allowAll);
125
  /** Get the sygus datatype initialized by this class */
126
  const DType& getDatatype() const;
127
128
  /** is initialized */
129
  bool isInitialized() const;
130
131
 private:
132
  /** Information for each constructor. */
133
  std::vector<SygusDatatypeConstructor> d_cons;
134
  /** Datatype to represent type's structure */
135
  DType d_dt;
136
};
137
138
}  // namespace cvc5
139
140
#endif