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