GCC Code Coverage Report
Directory: . Exec Total Coverage
File: src/parser/parser_builder.cpp Lines: 63 65 96.9 %
Date: 2021-11-07 Branches: 47 96 49.0 %

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 "parser/antlr_input.h"
24
#include "parser/input.h"
25
#include "parser/parser.h"
26
#include "smt2/smt2.h"
27
#include "tptp/tptp.h"
28
29
namespace cvc5 {
30
namespace parser {
31
32
6738
ParserBuilder::ParserBuilder(api::Solver* solver,
33
                             SymbolManager* sm,
34
6738
                             bool useOptions)
35
6738
    : d_solver(solver), d_symman(sm)
36
{
37
6738
  init(solver, sm);
38
6738
  if (useOptions)
39
  {
40
6714
    withOptions();
41
  }
42
6738
}
43
44
6738
void ParserBuilder::init(api::Solver* solver, SymbolManager* sm)
45
{
46
6738
  d_lang = "LANG_AUTO";
47
6738
  d_solver = solver;
48
6738
  d_symman = sm;
49
6738
  d_checksEnabled = true;
50
6738
  d_strictMode = false;
51
6738
  d_canIncludeFile = true;
52
6738
  d_parseOnly = false;
53
6738
  d_logicIsForced = false;
54
6738
  d_forcedLogic = "";
55
6738
}
56
57
6738
Parser* ParserBuilder::build()
58
{
59
6738
  Parser* parser = NULL;
60
6738
  if (d_lang == "LANG_TPTP")
61
  {
62
42
    parser = new Tptp(d_solver, d_symman, d_strictMode, d_parseOnly);
63
  }
64
  else
65
  {
66
6696
    Assert(d_lang == "LANG_SYGUS_V2" || d_lang == "LANG_SMTLIB_V2_6");
67
6696
    parser = new Smt2(d_solver, d_symman, d_strictMode, d_parseOnly);
68
  }
69
70
6738
  if( d_checksEnabled ) {
71
6738
    parser->enableChecks();
72
  } else {
73
    parser->disableChecks();
74
  }
75
76
6738
  if( d_canIncludeFile ) {
77
6738
    parser->allowIncludeFile();
78
  } else {
79
    parser->disallowIncludeFile();
80
  }
81
82
6738
  if( d_logicIsForced ) {
83
9
    parser->forceLogic(d_forcedLogic);
84
  }
85
86
6738
  return parser;
87
}
88
89
6714
ParserBuilder& ParserBuilder::withChecks(bool flag) {
90
6714
  d_checksEnabled = flag;
91
6714
  return *this;
92
}
93
94
6846
ParserBuilder& ParserBuilder::withInputLanguage(const std::string& lang)
95
{
96
6846
  d_lang = lang;
97
6846
  return *this;
98
}
99
100
6714
ParserBuilder& ParserBuilder::withParseOnly(bool flag) {
101
6714
  d_parseOnly = flag;
102
6714
  return *this;
103
}
104
105
6714
ParserBuilder& ParserBuilder::withOptions()
106
{
107
6714
  ParserBuilder& retval = *this;
108
20142
  retval = retval.withInputLanguage(d_solver->getOption("input-language"))
109
13428
               .withChecks(d_solver->getOptionInfo("semantic-checks").boolValue())
110
13428
               .withStrictMode(d_solver->getOptionInfo("strict-parsing").boolValue())
111
13428
               .withParseOnly(d_solver->getOptionInfo("parse-only").boolValue())
112
13428
               .withIncludeFile(d_solver->getOptionInfo("filesystem-access").boolValue());
113
13428
  auto info = d_solver->getOptionInfo("force-logic");
114
6714
  if (info.setByUser)
115
  {
116
18
    LogicInfo tmp(info.stringValue());
117
9
    retval = retval.withForcedLogic(tmp.getLogicString());
118
  }
119
13428
  return retval;
120
}
121
122
6772
ParserBuilder& ParserBuilder::withStrictMode(bool flag) {
123
6772
  d_strictMode = flag;
124
6772
  return *this;
125
}
126
127
6714
ParserBuilder& ParserBuilder::withIncludeFile(bool flag) {
128
6714
  d_canIncludeFile = flag;
129
6714
  return *this;
130
}
131
132
9
ParserBuilder& ParserBuilder::withForcedLogic(const std::string& logic)
133
{
134
9
  d_logicIsForced = true;
135
9
  d_forcedLogic = logic;
136
9
  return *this;
137
}
138
139
}  // namespace parser
140
31116
}  // namespace cvc5