GCC Code Coverage Report
Directory: . Exec Total Coverage
File: src/options/language.cpp Lines: 42 67 62.7 %
Date: 2021-05-22 Branches: 68 158 43.0 %

Line Exec Source
1
/******************************************************************************
2
 * Top contributors (to current version):
3
 *   Morgan Deters, Andrew Reynolds, Mathias Preiner
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
 * Definition of input and output languages.
14
 */
15
16
#include "options/language.h"
17
18
#include <sstream>
19
20
#include "base/exception.h"
21
#include "options/option_exception.h"
22
23
namespace cvc5 {
24
namespace language {
25
26
/** define the end points of smt2 languages */
27
namespace input {
28
Language LANG_SMTLIB_V2_START = LANG_SMTLIB_V2_6;
29
Language LANG_SMTLIB_V2_END = LANG_SMTLIB_V2_6;
30
}
31
namespace output {
32
Language LANG_SMTLIB_V2_START = LANG_SMTLIB_V2_6;
33
Language LANG_SMTLIB_V2_END = LANG_SMTLIB_V2_6;
34
}
35
36
10896
bool isInputLang_smt2(InputLanguage lang)
37
{
38
10896
  return lang >= input::LANG_SMTLIB_V2_START
39
10896
         && lang <= input::LANG_SMTLIB_V2_END;
40
}
41
42
10414
bool isOutputLang_smt2(OutputLanguage lang)
43
{
44
10414
  return lang >= output::LANG_SMTLIB_V2_START
45
10414
         && lang <= output::LANG_SMTLIB_V2_END;
46
}
47
48
531852
bool isInputLang_smt2_6(InputLanguage lang, bool exact)
49
{
50
1063704
  return exact ? lang == input::LANG_SMTLIB_V2_6
51
               : (lang >= input::LANG_SMTLIB_V2_6
52
1063704
                  && lang <= input::LANG_SMTLIB_V2_END);
53
}
54
55
bool isOutputLang_smt2_6(OutputLanguage lang, bool exact)
56
{
57
  return exact ? lang == output::LANG_SMTLIB_V2_6
58
               : (lang >= output::LANG_SMTLIB_V2_6
59
                  && lang <= output::LANG_SMTLIB_V2_END);
60
}
61
62
98750
bool isInputLangSygus(InputLanguage lang)
63
{
64
98750
  return lang == input::LANG_SYGUS_V2;
65
}
66
67
bool isOutputLangSygus(OutputLanguage lang)
68
{
69
  return lang == output::LANG_SYGUS_V2;
70
}
71
72
InputLanguage toInputLanguage(OutputLanguage language) {
73
  switch(language) {
74
  case output::LANG_SMTLIB_V2_6:
75
  case output::LANG_TPTP:
76
  case output::LANG_CVC:
77
  case output::LANG_SYGUS_V2:
78
    // these entries directly correspond (by design)
79
    return InputLanguage(int(language));
80
81
  default: {
82
    std::stringstream ss;
83
    ss << "Cannot map output language `" << language
84
       << "' to an input language.";
85
    throw cvc5::Exception(ss.str());
86
  }
87
  }/* switch(language) */
88
}/* toInputLanguage() */
89
90
6602
OutputLanguage toOutputLanguage(InputLanguage language) {
91
6602
  switch(language) {
92
6602
  case input::LANG_SMTLIB_V2_6:
93
  case input::LANG_TPTP:
94
  case input::LANG_CVC:
95
  case input::LANG_SYGUS_V2:
96
    // these entries directly correspond (by design)
97
6602
    return OutputLanguage(int(language));
98
99
  default:
100
    // Revert to the default (AST) language.
101
    //
102
    // We used to throw an exception here, but that's not quite right.
103
    // We often call this while constructing exceptions, for one, and
104
    // it's better to output SOMETHING related to the original
105
    // exception rather than mask it with another exception.  Also,
106
    // the input language isn't always defined---e.g. during the
107
    // initial phase of the main cvc5 driver while it determines which
108
    // language is appropriate, and during unit tests.  Also, when
109
    // users are writing their own code against the library.
110
    return output::LANG_AST;
111
  }/* switch(language) */
112
}/* toOutputLanguage() */
113
114
87
OutputLanguage toOutputLanguage(std::string language)
115
{
116
253
  if (language == "cvc" || language == "pl" || language == "presentation"
117
166
      || language == "native" || language == "LANG_CVC")
118
  {
119
8
    return output::LANG_CVC;
120
  }
121
237
  else if (language == "smtlib" || language == "smt" || language == "smtlib2"
122
79
           || language == "smt2" || language == "smtlib2.6"
123
63
           || language == "smt2.6" || language == "LANG_SMTLIB_V2_6"
124
142
           || language == "LANG_SMTLIB_V2")
125
  {
126
16
    return output::LANG_SMTLIB_V2_6;
127
  }
128
63
  else if (language == "tptp" || language == "LANG_TPTP")
129
  {
130
    return output::LANG_TPTP;
131
  }
132
189
  else if (language == "sygus" || language == "LANG_SYGUS"
133
126
           || language == "sygus2" || language == "LANG_SYGUS_V2")
134
  {
135
    return output::LANG_SYGUS_V2;
136
  }
137
63
  else if (language == "ast" || language == "LANG_AST")
138
  {
139
63
    return output::LANG_AST;
140
  }
141
  else if (language == "auto" || language == "LANG_AUTO")
142
  {
143
    return output::LANG_AUTO;
144
  }
145
146
  throw OptionException(
147
      std::string("unknown output language `" + language + "'"));
148
}
149
150
500
InputLanguage toInputLanguage(std::string language) {
151
1489
  if (language == "cvc" || language == "pl" || language == "presentation"
152
989
      || language == "native" || language == "LANG_CVC")
153
  {
154
11
    return input::LANG_CVC;
155
  }
156
1467
  else if (language == "smtlib" || language == "smt" || language == "smtlib2"
157
489
           || language == "smt2" || language == "smtlib2.6"
158
229
           || language == "smt2.6" || language == "LANG_SMTLIB_V2_6"
159
674
           || language == "LANG_SMTLIB_V2")
160
  {
161
304
    return input::LANG_SMTLIB_V2_6;
162
  }
163
185
  else if (language == "tptp" || language == "LANG_TPTP")
164
  {
165
    return input::LANG_TPTP;
166
  }
167
555
  else if (language == "sygus" || language == "sygus2"
168
185
           || language == "LANG_SYGUS" || language == "LANG_SYGUS_V2")
169
  {
170
185
    return input::LANG_SYGUS_V2;
171
  }
172
  else if (language == "auto" || language == "LANG_AUTO")
173
  {
174
    return input::LANG_AUTO;
175
  }
176
177
  throw OptionException(std::string("unknown input language `" + language + "'"));
178
}/* toInputLanguage() */
179
180
}  // namespace language
181
}  // namespace cvc5