GCC Code Coverage Report
Directory: . Exec Total Coverage
File: src/options/set_language.cpp Lines: 27 27 100.0 %
Date: 2021-09-18 Branches: 9 12 75.0 %

Line Exec Source
1
/******************************************************************************
2
 * Top contributors (to current version):
3
 *   Morgan Deters, Tim King, Kshitij Bansal
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
#include "options/set_language.h"
16
17
#include <iosfwd>
18
#include <iomanip>
19
20
#include "options/base_options.h"
21
#include "options/language.h"
22
#include "options/options.h"
23
24
namespace cvc5 {
25
namespace language {
26
27
9858
const int SetLanguage::s_iosIndex = std::ios_base::xalloc();
28
29
92
SetLanguage::Scope::Scope(std::ostream& out, Language language)
30
92
    : d_out(out), d_oldLanguage(SetLanguage::getLanguage(out))
31
{
32
92
  SetLanguage::setLanguage(out, language);
33
92
}
34
35
184
SetLanguage::Scope::~Scope(){
36
92
  SetLanguage::setLanguage(d_out, d_oldLanguage);
37
92
}
38
39
9117
SetLanguage::SetLanguage(Language l) : d_language(l) {}
40
41
8734
void SetLanguage::applyLanguage(std::ostream& out) {
42
  // (offset by one to detect whether default has been set yet)
43
8734
  out.iword(s_iosIndex) = int(d_language) + 1;
44
8734
}
45
46
372547
Language SetLanguage::getLanguage(std::ostream& out)
47
{
48
372547
  long& l = out.iword(s_iosIndex);
49
372547
  if(l == 0) {
50
    // set the default language on this ostream
51
    // (offset by one to detect whether default has been set yet)
52
36253
    if(not Options::isCurrentNull()) {
53
36243
      l = static_cast<long>(options::outputLanguage()) + 1;
54
    }
55
36253
    if (l <= 0 || l > static_cast<long>(Language::LANG_MAX))
56
    {
57
      // if called from outside the library, we may not have options
58
      // available to us at this point (or perhaps the output language
59
      // is not set in Options).  Default to something reasonable, but
60
      // don't set "l" since that would make it "sticky" for this
61
      // stream.
62
2109
      return s_defaultOutputLanguage;
63
    }
64
  }
65
370438
  return Language(l - 1);
66
}
67
68
184
void SetLanguage::setLanguage(std::ostream& out, Language l)
69
{
70
  // (offset by one to detect whether default has been set yet)
71
184
  out.iword(s_iosIndex) = int(l) + 1;
72
184
}
73
74
8734
std::ostream& operator<<(std::ostream& out, SetLanguage l) {
75
8734
  l.applyLanguage(out);
76
8734
  return out;
77
}
78
79
}  // namespace language
80
29574
}  // namespace cvc5