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