GCC Code Coverage Report
Directory: . Exec Total Coverage
File: src/expr/dtype_cons.cpp Lines: 315 338 93.2 %
Date: 2021-08-01 Branches: 492 1306 37.7 %

Line Exec Source
1
/******************************************************************************
2
 * Top contributors (to current version):
3
 *   Andrew Reynolds, Morgan Deters, Tim King
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 representing a datatype definition.
14
 */
15
#include "expr/dtype_cons.h"
16
17
#include "expr/ascription_type.h"
18
#include "expr/dtype.h"
19
#include "expr/node_manager.h"
20
#include "expr/skolem_manager.h"
21
#include "expr/type_matcher.h"
22
#include "options/datatypes_options.h"
23
24
using namespace cvc5::kind;
25
using namespace cvc5::theory;
26
27
namespace cvc5 {
28
29
15324
DTypeConstructor::DTypeConstructor(std::string name,
30
15324
                                   unsigned weight)
31
    :  // We don't want to introduce a new data member, because eventually
32
       // we're going to be a constant stuffed inside a node.  So we stow
33
       // the tester name away inside the constructor name until
34
       // resolution.
35
      d_name(name),
36
      d_tester(),
37
      d_args(),
38
15324
      d_weight(weight)
39
{
40
15324
  Assert(name != "");
41
15324
}
42
43
15366
void DTypeConstructor::addArg(std::string selectorName, TypeNode selectorType)
44
{
45
  // We don't want to introduce a new data member, because eventually
46
  // we're going to be a constant stuffed inside a node.  So we stow
47
  // the selector type away inside a var until resolution (when we can
48
  // create the proper selector type)
49
15366
  Assert(!isResolved());
50
15366
  Assert(!selectorType.isNull());
51
15366
  SkolemManager* sm = NodeManager::currentNM()->getSkolemManager();
52
  Node sel = sm->mkDummySkolem(
53
30732
      "unresolved_" + selectorName,
54
      selectorType,
55
      "is an unresolved selector type placeholder",
56
61464
      NodeManager::SKOLEM_EXACT_NAME | NodeManager::SKOLEM_NO_NOTIFY);
57
  // can use null updater for now
58
30732
  Node nullNode;
59
15366
  Trace("datatypes") << "DTypeConstructor::addArg: " << sel << std::endl;
60
  std::shared_ptr<DTypeSelector> a =
61
30732
      std::make_shared<DTypeSelector>(selectorName, sel, nullNode);
62
15366
  addArg(a);
63
15366
}
64
65
15434
void DTypeConstructor::addArg(std::shared_ptr<DTypeSelector> a)
66
{
67
15434
  d_args.push_back(a);
68
15434
}
69
70
68
void DTypeConstructor::addArgSelf(std::string selectorName)
71
{
72
68
  Trace("datatypes") << "DTypeConstructor::addArgSelf" << std::endl;
73
136
  Node nullNode;
74
  std::shared_ptr<DTypeSelector> a =
75
136
      std::make_shared<DTypeSelector>(selectorName + '\0', nullNode, nullNode);
76
68
  addArg(a);
77
68
}
78
79
35414
const std::string& DTypeConstructor::getName() const { return d_name; }
80
81
526247
Node DTypeConstructor::getConstructor() const
82
{
83
526247
  Assert(isResolved());
84
526247
  return d_constructor;
85
}
86
87
239720
Node DTypeConstructor::getTester() const
88
{
89
239720
  Assert(isResolved());
90
239720
  return d_tester;
91
}
92
93
10178
void DTypeConstructor::setSygus(Node op)
94
{
95
10178
  Assert(!isResolved());
96
10178
  d_sygusOp = op;
97
10178
}
98
99
1801041
Node DTypeConstructor::getSygusOp() const
100
{
101
1801041
  Assert(isResolved());
102
1801041
  return d_sygusOp;
103
}
104
105
686
bool DTypeConstructor::isSygusIdFunc() const
106
{
107
686
  Assert(isResolved());
108
1655
  return (d_sygusOp.getKind() == LAMBDA && d_sygusOp[0].getNumChildren() == 1
109
2158
          && d_sygusOp[0][0] == d_sygusOp[1]);
110
}
111
112
302357
unsigned DTypeConstructor::getWeight() const
113
{
114
302357
  Assert(isResolved());
115
302357
  return d_weight;
116
}
117
118
7665997
size_t DTypeConstructor::getNumArgs() const { return d_args.size(); }
119
120
702
TypeNode DTypeConstructor::getSpecializedConstructorType(
121
    TypeNode returnType) const
122
{
123
702
  Assert(isResolved());
124
702
  Assert(returnType.isDatatype())
125
      << "DTypeConstructor::getSpecializedConstructorType: expected datatype, "
126
         "got "
127
      << returnType;
128
1404
  TypeNode ctn = d_constructor.getType();
129
702
  const DType& dt = DType::datatypeOf(d_constructor);
130
702
  if (!dt.isParametric())
131
  {
132
    // if the datatype is not parametric, then no specialization is needed
133
44
    return ctn;
134
  }
135
1316
  TypeNode dtt = dt.getTypeNode();
136
1316
  TypeMatcher m(dtt);
137
658
  m.doMatching(dtt, returnType);
138
1316
  std::vector<TypeNode> subst;
139
658
  m.getMatches(subst);
140
1316
  std::vector<TypeNode> params = dt.getParameters();
141
  return ctn.substitute(
142
658
      params.begin(), params.end(), subst.begin(), subst.end());
143
}
144
145
2212
const std::vector<std::shared_ptr<DTypeSelector> >& DTypeConstructor::getArgs()
146
    const
147
{
148
2212
  return d_args;
149
}
150
151
Cardinality DTypeConstructor::getCardinality(TypeNode t) const
152
{
153
  Assert(isResolved());
154
155
  Cardinality c = 1;
156
157
  for (size_t i = 0, nargs = d_args.size(); i < nargs; i++)
158
  {
159
    c *= getArgType(i).getCardinality();
160
  }
161
162
  return c;
163
}
164
165
113047
CardinalityClass DTypeConstructor::getCardinalityClass(TypeNode t) const
166
{
167
113047
  std::pair<CardinalityClass, bool> cinfo = computeCardinalityInfo(t);
168
113047
  return cinfo.first;
169
}
170
171
118154
bool DTypeConstructor::hasFiniteExternalArgType(TypeNode t) const
172
{
173
118154
  std::pair<CardinalityClass, bool> cinfo = computeCardinalityInfo(t);
174
118154
  return cinfo.second;
175
}
176
177
231201
std::pair<CardinalityClass, bool> DTypeConstructor::computeCardinalityInfo(
178
    TypeNode t) const
179
{
180
  std::map<TypeNode, std::pair<CardinalityClass, bool> >::iterator it =
181
231201
      d_cardInfo.find(t);
182
231201
  if (it != d_cardInfo.end())
183
  {
184
222984
    return it->second;
185
  }
186
8217
  std::pair<CardinalityClass, bool> ret(CardinalityClass::ONE, false);
187
16434
  std::vector<TypeNode> instTypes;
188
16434
  std::vector<TypeNode> paramTypes;
189
8217
  bool isParam = t.isParametricDatatype();
190
8217
  if (isParam)
191
  {
192
84
    paramTypes = t.getDType().getParameters();
193
84
    instTypes = t.getParamTypes();
194
  }
195
17833
  for (unsigned i = 0, nargs = getNumArgs(); i < nargs; i++)
196
  {
197
19232
    TypeNode tc = getArgType(i);
198
9616
    if (isParam)
199
    {
200
102
      tc = tc.substitute(paramTypes.begin(),
201
                         paramTypes.end(),
202
                         instTypes.begin(),
203
                         instTypes.end());
204
    }
205
    // get the current cardinality class
206
9616
    CardinalityClass cctc = tc.getCardinalityClass();
207
    // update ret.first to the max cardinality class
208
9616
    ret.first = maxCardinalityClass(ret.first, cctc);
209
9616
    if (cctc != CardinalityClass::INFINITE)
210
    {
211
      // if the argument is (interpreted) finite and external, set the flag
212
      // for indicating it has a finite external argument
213
1362
      ret.second = ret.second || !tc.isDatatype();
214
    }
215
  }
216
8217
  d_cardInfo[t] = ret;
217
8217
  return ret;
218
}
219
220
3641991
bool DTypeConstructor::isResolved() const { return !d_tester.isNull(); }
221
222
1476310
const DTypeSelector& DTypeConstructor::operator[](size_t index) const
223
{
224
1476310
  Assert(index < getNumArgs());
225
1476310
  return *d_args[index];
226
}
227
228
731382
TypeNode DTypeConstructor::getArgType(size_t index) const
229
{
230
731382
  Assert(index < getNumArgs());
231
731382
  return (*this)[index].getType().getSelectorRangeType();
232
}
233
234
411719
Node DTypeConstructor::getSelectorInternal(TypeNode domainType,
235
                                           size_t index) const
236
{
237
411719
  Assert(isResolved());
238
411719
  Assert(index < getNumArgs());
239
411719
  if (options::dtSharedSelectors())
240
  {
241
411719
    computeSharedSelectors(domainType);
242
411719
    Assert(d_sharedSelectors[domainType].size() == getNumArgs());
243
411719
    return d_sharedSelectors[domainType][index];
244
  }
245
  else
246
  {
247
    return d_args[index]->getSelector();
248
  }
249
}
250
251
266294
int DTypeConstructor::getSelectorIndexInternal(Node sel) const
252
{
253
266294
  Assert(isResolved());
254
266294
  if (options::dtSharedSelectors())
255
  {
256
266294
    Assert(sel.getType().isSelector());
257
382424
    TypeNode domainType = sel.getType().getSelectorDomainType();
258
266294
    computeSharedSelectors(domainType);
259
    std::map<Node, unsigned>::iterator its =
260
266294
        d_sharedSelectorIndex[domainType].find(sel);
261
266294
    if (its != d_sharedSelectorIndex[domainType].end())
262
    {
263
150164
      return (int)its->second;
264
    }
265
  }
266
  else
267
  {
268
    unsigned sindex = DType::indexOf(sel);
269
    if (getNumArgs() > sindex && d_args[sindex]->getSelector() == sel)
270
    {
271
      return static_cast<int>(sindex);
272
    }
273
  }
274
116130
  return -1;
275
}
276
277
14
int DTypeConstructor::getSelectorIndexForName(const std::string& name) const
278
{
279
18
  for (size_t i = 0, nargs = getNumArgs(); i < nargs; i++)
280
  {
281
14
    if (d_args[i]->getName() == name)
282
    {
283
10
      return i;
284
    }
285
  }
286
4
  return -1;
287
}
288
289
15322
bool DTypeConstructor::involvesExternalType() const
290
{
291
27963
  for (size_t i = 0, nargs = getNumArgs(); i < nargs; i++)
292
  {
293
14180
    if (!getArgType(i).isDatatype())
294
    {
295
1539
      return true;
296
    }
297
  }
298
13783
  return false;
299
}
300
301
15322
bool DTypeConstructor::involvesUninterpretedType() const
302
{
303
15885
  for (size_t i = 0, nargs = getNumArgs(); i < nargs; i++)
304
  {
305
8297
    if (!getArgType(i).isSort())
306
    {
307
7734
      return true;
308
    }
309
  }
310
7588
  return false;
311
}
312
313
13977
Cardinality DTypeConstructor::computeCardinality(
314
    TypeNode t, std::vector<TypeNode>& processing) const
315
{
316
13977
  Cardinality c = 1;
317
27954
  std::vector<TypeNode> instTypes;
318
27954
  std::vector<TypeNode> paramTypes;
319
13977
  bool isParam = t.isParametricDatatype();
320
13977
  if (isParam)
321
  {
322
    paramTypes = t.getDType().getParameters();
323
    instTypes = t.getParamTypes();
324
  }
325
19129
  for (size_t i = 0, nargs = d_args.size(); i < nargs; i++)
326
  {
327
10304
    TypeNode tc = getArgType(i);
328
5152
    if (isParam)
329
    {
330
      tc = tc.substitute(paramTypes.begin(),
331
                         paramTypes.end(),
332
                         instTypes.begin(),
333
                         instTypes.end());
334
    }
335
5152
    if (tc.isDatatype())
336
    {
337
4458
      const DType& dt = tc.getDType();
338
4458
      c *= dt.computeCardinality(t, processing);
339
    }
340
    else
341
    {
342
694
      c *= tc.getCardinality();
343
    }
344
  }
345
27954
  return c;
346
}
347
348
6391
bool DTypeConstructor::computeWellFounded(
349
    std::vector<TypeNode>& processing) const
350
{
351
11891
  for (size_t i = 0, nargs = getNumArgs(); i < nargs; i++)
352
  {
353
12106
    TypeNode t = getArgType(i);
354
6606
    if (t.isDatatype())
355
    {
356
3153
      const DType& dt = t.getDType();
357
3153
      if (!dt.computeWellFounded(processing))
358
      {
359
1106
        return false;
360
      }
361
    }
362
  }
363
5285
  return true;
364
}
365
366
1910
Node DTypeConstructor::computeGroundTerm(TypeNode t,
367
                                         std::vector<TypeNode>& processing,
368
                                         std::map<TypeNode, Node>& gt,
369
                                         bool isValue) const
370
{
371
1910
  NodeManager* nm = NodeManager::currentNM();
372
3820
  std::vector<Node> groundTerms;
373
1910
  groundTerms.push_back(getConstructor());
374
3820
  Trace("datatypes-init") << "cons " << d_constructor
375
1910
                          << " computeGroundTerm, isValue = " << isValue
376
1910
                          << std::endl;
377
378
  // for each selector, get a ground term
379
3820
  std::vector<TypeNode> instTypes;
380
3820
  std::vector<TypeNode> paramTypes;
381
1910
  bool isParam = t.isParametricDatatype();
382
1910
  if (isParam)
383
  {
384
29
    paramTypes = t.getDType().getParameters();
385
29
    instTypes = TypeNode(t).getParamTypes();
386
  }
387
2798
  for (size_t i = 0, nargs = getNumArgs(); i < nargs; i++)
388
  {
389
1868
    TypeNode selType = getArgType(i);
390
980
    if (isParam)
391
    {
392
20
      selType = selType.substitute(paramTypes.begin(),
393
                                   paramTypes.end(),
394
                                   instTypes.begin(),
395
                                   instTypes.end());
396
    }
397
1868
    Node arg;
398
980
    if (selType.isDatatype())
399
    {
400
629
      std::map<TypeNode, Node>::iterator itgt = gt.find(selType);
401
629
      if (itgt != gt.end())
402
      {
403
1
        arg = itgt->second;
404
      }
405
      else
406
      {
407
628
        const DType& dt = selType.getDType();
408
628
        arg = dt.computeGroundTerm(selType, processing, isValue);
409
      }
410
    }
411
    else
412
    {
413
      // call mkGroundValue or mkGroundTerm based on isValue
414
351
      arg = isValue ? selType.mkGroundValue() : selType.mkGroundTerm();
415
    }
416
980
    if (arg.isNull())
417
    {
418
184
      Trace("datatypes-init") << "...unable to construct arg of "
419
92
                              << d_args[i]->getName() << std::endl;
420
92
      return Node();
421
    }
422
    else
423
    {
424
1776
      Trace("datatypes-init")
425
1776
          << "...constructed arg " << arg << " of type " << arg.getType()
426
888
          << ", isConst = " << arg.isConst() << std::endl;
427
1776
      Assert(!isValue || arg.isConst())
428
888
          << "Expected non-constant constructor argument : " << arg
429
888
          << " of type " << arg.getType();
430
888
      groundTerms.push_back(arg);
431
    }
432
  }
433
434
3636
  Node groundTerm = nm->mkNode(APPLY_CONSTRUCTOR, groundTerms);
435
1818
  if (isParam)
436
  {
437
28
    Assert(DType::datatypeOf(d_constructor).isParametric());
438
    // type is parametric, must apply type ascription
439
56
    Trace("datatypes-init") << "ambiguous type for " << groundTerm
440
28
                            << ", ascribe to " << t << std::endl;
441
84
    groundTerms[0] = nm->mkNode(
442
        APPLY_TYPE_ASCRIPTION,
443
56
        nm->mkConst(AscriptionType(getSpecializedConstructorType(t))),
444
28
        groundTerms[0]);
445
28
    groundTerm = nm->mkNode(APPLY_CONSTRUCTOR, groundTerms);
446
  }
447
1818
  Trace("datatypes-init") << "...return " << groundTerm << std::endl;
448
1818
  Assert(!isValue || groundTerm.isConst()) << "Non-constant term " << groundTerm
449
                                           << " returned for computeGroundTerm";
450
1818
  return groundTerm;
451
}
452
453
678013
void DTypeConstructor::computeSharedSelectors(TypeNode domainType) const
454
{
455
678013
  if (d_sharedSelectors[domainType].size() < getNumArgs())
456
  {
457
3010
    TypeNode ctype;
458
1505
    if (domainType.isParametricDatatype())
459
    {
460
42
      ctype = getSpecializedConstructorType(domainType);
461
    }
462
    else
463
    {
464
1463
      ctype = d_constructor.getType();
465
    }
466
1505
    Assert(ctype.isConstructor());
467
1505
    Assert(ctype.getNumChildren() - 1 == getNumArgs());
468
    // compute the shared selectors
469
1505
    const DType& dt = DType::datatypeOf(d_constructor);
470
3010
    std::map<TypeNode, unsigned> counter;
471
4340
    for (size_t j = 0, jend = ctype.getNumChildren() - 1; j < jend; j++)
472
    {
473
5670
      TypeNode t = ctype[j];
474
5670
      Node ss = dt.getSharedSelector(domainType, t, counter[t]);
475
2835
      d_sharedSelectors[domainType].push_back(ss);
476
2835
      Assert(d_sharedSelectorIndex[domainType].find(ss)
477
             == d_sharedSelectorIndex[domainType].end());
478
2835
      d_sharedSelectorIndex[domainType][ss] = j;
479
2835
      counter[t]++;
480
    }
481
  }
482
678013
}
483
484
15322
bool DTypeConstructor::resolve(
485
    TypeNode self,
486
    const std::map<std::string, TypeNode>& resolutions,
487
    const std::vector<TypeNode>& placeholders,
488
    const std::vector<TypeNode>& replacements,
489
    const std::vector<TypeNode>& paramTypes,
490
    const std::vector<TypeNode>& paramReplacements,
491
    size_t cindex)
492
{
493
15322
  if (isResolved())
494
  {
495
    // already resolved, fail
496
    return false;
497
  }
498
30644
  Trace("datatypes") << "DTypeConstructor::resolve, self type is " << self
499
15322
                     << std::endl;
500
501
15322
  NodeManager* nm = NodeManager::currentNM();
502
15322
  SkolemManager* sm = nm->getSkolemManager();
503
15322
  size_t index = 0;
504
30644
  std::vector<TypeNode> argTypes;
505
15322
  Trace("datatypes-init") << "Initialize constructor " << d_name << std::endl;
506
30756
  for (std::shared_ptr<DTypeSelector> arg : d_args)
507
  {
508
30868
    std::string argName = arg->d_name;
509
30868
    TypeNode range;
510
15434
    if (arg->d_selector.isNull())
511
    {
512
      // the unresolved type wasn't created here; do name resolution
513
136
      std::string typeName = argName.substr(argName.find('\0') + 1);
514
136
      Trace("datatypes-init")
515
68
          << "  - selector, typeName is " << typeName << std::endl;
516
68
      argName.resize(argName.find('\0'));
517
68
      if (typeName == "")
518
      {
519
68
        Trace("datatypes-init") << "  ...self selector" << std::endl;
520
68
        range = self;
521
      }
522
      else
523
      {
524
        std::map<std::string, TypeNode>::const_iterator j =
525
            resolutions.find(typeName);
526
        if (j == resolutions.end())
527
        {
528
          Trace("datatypes-init")
529
              << "  ...failed to resolve selector" << std::endl;
530
          // failed to resolve selector
531
          return false;
532
        }
533
        else
534
        {
535
          Trace("datatypes-init") << "  ...resolved selector" << std::endl;
536
          range = (*j).second;
537
        }
538
      }
539
    }
540
    else
541
    {
542
      // the type for the selector already exists; may need
543
      // complex-type substitution
544
15366
      range = arg->d_selector.getType();
545
30732
      Trace("datatypes-init")
546
15366
          << "  - null selector, range = " << range << std::endl;
547
15366
      if (!placeholders.empty())
548
      {
549
13998
        range = range.substitute(placeholders.begin(),
550
                                 placeholders.end(),
551
                                 replacements.begin(),
552
                                 replacements.end());
553
      }
554
30732
      Trace("datatypes-init")
555
15366
          << "  ...range after placeholder replacement " << range << std::endl;
556
15366
      if (!paramTypes.empty())
557
      {
558
105
        range = doParametricSubstitution(range, paramTypes, paramReplacements);
559
      }
560
30732
      Trace("datatypes-init")
561
15366
          << "  ...range after parametric substitution " << range << std::endl;
562
    }
563
    // Internally, selectors (and updaters) are fresh internal skolems which
564
    // we constructor via mkDummySkolem.
565
61736
    arg->d_selector = sm->mkDummySkolem(
566
        argName,
567
30868
        nm->mkSelectorType(self, range),
568
        "is a selector",
569
15434
        NodeManager::SKOLEM_EXACT_NAME | NodeManager::SKOLEM_NO_NOTIFY);
570
30868
    std::string updateName("update_" + argName);
571
61736
    arg->d_updater = sm->mkDummySkolem(
572
        updateName,
573
30868
        nm->mkDatatypeUpdateType(self, range),
574
        "is a selector",
575
15434
        NodeManager::SKOLEM_EXACT_NAME | NodeManager::SKOLEM_NO_NOTIFY);
576
    // must set indices to ensure datatypes::utils::indexOf works
577
15434
    arg->d_selector.setAttribute(DTypeConsIndexAttr(), cindex);
578
15434
    arg->d_selector.setAttribute(DTypeIndexAttr(), index);
579
15434
    arg->d_updater.setAttribute(DTypeConsIndexAttr(), cindex);
580
15434
    arg->d_updater.setAttribute(DTypeIndexAttr(), index);
581
15434
    index = index + 1;
582
15434
    arg->d_resolved = true;
583
15434
    argTypes.push_back(range);
584
    // We use \0 as a distinguished marker for unresolved selectors for doing
585
    // name resolutions. We now can remove \0 from name if necessary.
586
15434
    const size_t nul = arg->d_name.find('\0');
587
15434
    if (nul != std::string::npos)
588
    {
589
68
      arg->d_name.resize(nul);
590
    }
591
  }
592
593
15322
  Assert(index == getNumArgs());
594
595
  // Set constructor/tester last, since DTypeConstructor::isResolved()
596
  // returns true when d_tester is not the null Node.  If something
597
  // fails above, we want Constuctor::isResolved() to remain "false".
598
  // Further, mkConstructorType() iterates over the selectors, so
599
  // should get the results of any resolutions we did above.
600
  // The name of the tester variable does not matter, it is only used
601
  // internally.
602
30644
  std::string testerName("is_" + d_name);
603
61288
  d_tester = sm->mkDummySkolem(
604
      testerName,
605
30644
      nm->mkTesterType(self),
606
      "is a tester",
607
15322
      NodeManager::SKOLEM_EXACT_NAME | NodeManager::SKOLEM_NO_NOTIFY);
608
61288
  d_constructor = sm->mkDummySkolem(
609
      getName(),
610
30644
      nm->mkConstructorType(argTypes, self),
611
      "is a constructor",
612
15322
      NodeManager::SKOLEM_EXACT_NAME | NodeManager::SKOLEM_NO_NOTIFY);
613
15322
  Assert(d_constructor.getType().isConstructor());
614
  // associate constructor with all selectors
615
30756
  for (std::shared_ptr<DTypeSelector> sel : d_args)
616
  {
617
15434
    sel->d_constructor = d_constructor;
618
  }
619
15322
  Assert(isResolved());
620
15322
  return true;
621
}
622
623
153
TypeNode DTypeConstructor::doParametricSubstitution(
624
    TypeNode range,
625
    const std::vector<TypeNode>& paramTypes,
626
    const std::vector<TypeNode>& paramReplacements)
627
{
628
153
  if (range.getNumChildren() == 0)
629
  {
630
109
    return range;
631
  }
632
88
  std::vector<TypeNode> origChildren;
633
88
  std::vector<TypeNode> children;
634
92
  for (TypeNode::const_iterator i = range.begin(), iend = range.end();
635
92
       i != iend;
636
       ++i)
637
  {
638
48
    origChildren.push_back((*i));
639
48
    children.push_back(
640
96
        doParametricSubstitution((*i), paramTypes, paramReplacements));
641
  }
642
54
  for (size_t i = 0, psize = paramTypes.size(); i < psize; ++i)
643
  {
644
52
    if (paramTypes[i].getSortConstructorArity() == origChildren.size())
645
    {
646
58
      TypeNode tn = paramTypes[i].instantiateSortConstructor(origChildren);
647
50
      if (range == tn)
648
      {
649
        TypeNode tret =
650
84
            paramReplacements[i].instantiateParametricDatatype(children);
651
42
        return tret;
652
      }
653
    }
654
  }
655
4
  NodeBuilder nb(range.getKind());
656
6
  for (size_t i = 0, csize = children.size(); i < csize; ++i)
657
  {
658
4
    nb << children[i];
659
  }
660
4
  TypeNode tn = nb.constructTypeNode();
661
2
  return tn;
662
}
663
664
38
void DTypeConstructor::toStream(std::ostream& out) const
665
{
666
38
  out << getName();
667
668
38
  unsigned nargs = getNumArgs();
669
38
  if (nargs == 0)
670
  {
671
18
    return;
672
  }
673
20
  out << "(";
674
54
  for (unsigned i = 0; i < nargs; i++)
675
  {
676
34
    out << *d_args[i];
677
34
    if (i + 1 < nargs)
678
    {
679
14
      out << ", ";
680
    }
681
  }
682
20
  out << ")";
683
}
684
685
38
std::ostream& operator<<(std::ostream& os, const DTypeConstructor& ctor)
686
{
687
  // can only output datatypes in the cvc5 native language
688
76
  language::SetLanguage::Scope ls(os, language::output::LANG_CVC);
689
38
  ctor.toStream(os);
690
76
  return os;
691
}
692
693
29280
}  // namespace cvc5