GCC Code Coverage Report
Directory: . Exec Total Coverage
File: src/parser/parser_builder.cpp Lines: 64 66 97.0 %
Date: 2021-09-07 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
6427
ParserBuilder::ParserBuilder(api::Solver* solver,
34
                             SymbolManager* sm,
35
6427
                             bool useOptions)
36
6427
    : d_solver(solver), d_symman(sm)
37
{
38
6427
  init(solver, sm);
39
6427
  if (useOptions)
40
  {
41
6391
    withOptions();
42
  }
43
6427
}
44
45
6427
void ParserBuilder::init(api::Solver* solver, SymbolManager* sm)
46
{
47
6427
  d_lang = "LANG_AUTO";
48
6427
  d_solver = solver;
49
6427
  d_symman = sm;
50
6427
  d_checksEnabled = true;
51
6427
  d_strictMode = false;
52
6427
  d_canIncludeFile = true;
53
6427
  d_parseOnly = false;
54
6427
  d_logicIsForced = false;
55
6427
  d_forcedLogic = "";
56
6427
}
57
58
6427
Parser* ParserBuilder::build()
59
{
60
6427
  Parser* parser = NULL;
61
6427
  if (d_lang == "LANG_SYGUS_V2" || d_lang == "LANG_SMTLIB_V2_6")
62
  {
63
5460
    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
6427
  if( d_checksEnabled ) {
75
6427
    parser->enableChecks();
76
  } else {
77
    parser->disableChecks();
78
  }
79
80
6427
  if( d_canIncludeFile ) {
81
6427
    parser->allowIncludeFile();
82
  } else {
83
    parser->disallowIncludeFile();
84
  }
85
86
6427
  if( d_logicIsForced ) {
87
9
    parser->forceLogic(d_forcedLogic);
88
  }
89
90
6427
  return parser;
91
}
92
93
6391
ParserBuilder& ParserBuilder::withChecks(bool flag) {
94
6391
  d_checksEnabled = flag;
95
6391
  return *this;
96
}
97
98
6635
ParserBuilder& ParserBuilder::withInputLanguage(const std::string& lang)
99
{
100
6635
  d_lang = lang;
101
6635
  return *this;
102
}
103
104
6391
ParserBuilder& ParserBuilder::withParseOnly(bool flag) {
105
6391
  d_parseOnly = flag;
106
6391
  return *this;
107
}
108
109
6391
ParserBuilder& ParserBuilder::withOptions()
110
{
111
6391
  ParserBuilder& retval = *this;
112
19173
  retval = retval.withInputLanguage(d_solver->getOption("input-language"))
113
12782
               .withChecks(d_solver->getOptionInfo("semantic-checks").boolValue())
114
12782
               .withStrictMode(d_solver->getOptionInfo("strict-parsing").boolValue())
115
12782
               .withParseOnly(d_solver->getOptionInfo("parse-only").boolValue())
116
12782
               .withIncludeFile(d_solver->getOptionInfo("filesystem-access").boolValue());
117
12782
  auto info = d_solver->getOptionInfo("force-logic");
118
6391
  if (info.setByUser)
119
  {
120
18
    LogicInfo tmp(info.stringValue());
121
9
    retval = retval.withForcedLogic(tmp.getLogicString());
122
  }
123
12782
  return retval;
124
}
125
126
6493
ParserBuilder& ParserBuilder::withStrictMode(bool flag) {
127
6493
  d_strictMode = flag;
128
6493
  return *this;
129
}
130
131
6391
ParserBuilder& ParserBuilder::withIncludeFile(bool flag) {
132
6391
  d_canIncludeFile = flag;
133
6391
  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
29487
}  // namespace cvc5