GCC Code Coverage Report
Directory: . Exec Total Coverage
File: src/parser/parser_builder.cpp Lines: 64 66 97.0 %
Date: 2021-09-06 Branches: 50 86 58.1 %

Line Exec Source
1
/******************************************************************************
2
 * Top contributors (to current version):
3
 *   Christopher L. Conway, Morgan Deters, Andrew Reynolds
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 builder for parsers.
14
 */
15
16
// This must be included first.
17
#include "parser/parser_builder.h"
18
19
#include <string>
20
21
#include "api/cpp/cvc5.h"
22
#include "base/check.h"
23
#include "cvc/cvc.h"
24
#include "parser/antlr_input.h"
25
#include "parser/input.h"
26
#include "parser/parser.h"
27
#include "smt2/smt2.h"
28
#include "tptp/tptp.h"
29
30
namespace cvc5 {
31
namespace parser {
32
33
6428
ParserBuilder::ParserBuilder(api::Solver* solver,
34
                             SymbolManager* sm,
35
6428
                             bool useOptions)
36
6428
    : d_solver(solver), d_symman(sm)
37
{
38
6428
  init(solver, sm);
39
6428
  if (useOptions)
40
  {
41
6392
    withOptions();
42
  }
43
6428
}
44
45
6428
void ParserBuilder::init(api::Solver* solver, SymbolManager* sm)
46
{
47
6428
  d_lang = "LANG_AUTO";
48
6428
  d_solver = solver;
49
6428
  d_symman = sm;
50
6428
  d_checksEnabled = true;
51
6428
  d_strictMode = false;
52
6428
  d_canIncludeFile = true;
53
6428
  d_parseOnly = false;
54
6428
  d_logicIsForced = false;
55
6428
  d_forcedLogic = "";
56
6428
}
57
58
6428
Parser* ParserBuilder::build()
59
{
60
6428
  Parser* parser = NULL;
61
6428
  if (d_lang == "LANG_SYGUS_V2" || d_lang == "LANG_SMTLIB_V2_6")
62
  {
63
5461
    parser = new Smt2(d_solver, d_symman, d_strictMode, d_parseOnly);
64
  }
65
967
  else if (d_lang == "LANG_TPTP")
66
  {
67
41
    parser = new Tptp(d_solver, d_symman, d_strictMode, d_parseOnly);
68
  }
69
  else
70
  {
71
926
    parser = new Cvc(d_solver, d_symman, d_strictMode, d_parseOnly);
72
  }
73
74
6428
  if( d_checksEnabled ) {
75
6428
    parser->enableChecks();
76
  } else {
77
    parser->disableChecks();
78
  }
79
80
6428
  if( d_canIncludeFile ) {
81
6428
    parser->allowIncludeFile();
82
  } else {
83
    parser->disallowIncludeFile();
84
  }
85
86
6428
  if( d_logicIsForced ) {
87
9
    parser->forceLogic(d_forcedLogic);
88
  }
89
90
6428
  return parser;
91
}
92
93
6392
ParserBuilder& ParserBuilder::withChecks(bool flag) {
94
6392
  d_checksEnabled = flag;
95
6392
  return *this;
96
}
97
98
6636
ParserBuilder& ParserBuilder::withInputLanguage(const std::string& lang)
99
{
100
6636
  d_lang = lang;
101
6636
  return *this;
102
}
103
104
6392
ParserBuilder& ParserBuilder::withParseOnly(bool flag) {
105
6392
  d_parseOnly = flag;
106
6392
  return *this;
107
}
108
109
6392
ParserBuilder& ParserBuilder::withOptions()
110
{
111
6392
  ParserBuilder& retval = *this;
112
19176
  retval = retval.withInputLanguage(d_solver->getOption("input-language"))
113
12784
               .withChecks(d_solver->getOptionInfo("semantic-checks").boolValue())
114
12784
               .withStrictMode(d_solver->getOptionInfo("strict-parsing").boolValue())
115
12784
               .withParseOnly(d_solver->getOptionInfo("parse-only").boolValue())
116
12784
               .withIncludeFile(d_solver->getOptionInfo("filesystem-access").boolValue());
117
12784
  auto info = d_solver->getOptionInfo("force-logic");
118
6392
  if (info.setByUser)
119
  {
120
18
    LogicInfo tmp(info.stringValue());
121
9
    retval = retval.withForcedLogic(tmp.getLogicString());
122
  }
123
12784
  return retval;
124
}
125
126
6494
ParserBuilder& ParserBuilder::withStrictMode(bool flag) {
127
6494
  d_strictMode = flag;
128
6494
  return *this;
129
}
130
131
6392
ParserBuilder& ParserBuilder::withIncludeFile(bool flag) {
132
6392
  d_canIncludeFile = flag;
133
6392
  return *this;
134
}
135
136
9
ParserBuilder& ParserBuilder::withForcedLogic(const std::string& logic)
137
{
138
9
  d_logicIsForced = true;
139
9
  d_forcedLogic = logic;
140
9
  return *this;
141
}
142
143
}  // namespace parser
144
29493
}  // namespace cvc5