GCC Code Coverage Report
Directory: . Exec Total Coverage
File: src/options/set_language.cpp Lines: 29 29 100.0 %
Date: 2021-03-22 Branches: 9 16 56.3 %

Line Exec Source
1
/*********************                                                        */
2
/*! \file set_language.cpp
3
 ** \verbatim
4
 ** Top contributors (to current version):
5
 **   Morgan Deters, Tim King, Kshitij Bansal
6
 ** This file is part of the CVC4 project.
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.\endverbatim
11
 **
12
 ** \brief Definition of input and output languages
13
 **
14
 ** Definition of input and output languages.
15
 **/
16
#include "options/set_language.h"
17
18
#include <iosfwd>
19
#include <iomanip>
20
21
#include "options/base_options.h"
22
#include "options/language.h"
23
#include "options/options.h"
24
25
namespace CVC4 {
26
namespace language {
27
28
8892
const int SetLanguage::s_iosIndex = std::ios_base::xalloc();
29
30
92
SetLanguage::Scope::Scope(std::ostream& out, OutputLanguage language)
31
  : d_out(out)
32
92
  , d_oldLanguage(SetLanguage::getLanguage(out))
33
{
34
92
  SetLanguage::setLanguage(out, language);
35
92
}
36
37
184
SetLanguage::Scope::~Scope(){
38
92
  SetLanguage::setLanguage(d_out, d_oldLanguage);
39
92
}
40
41
42
8674
SetLanguage::SetLanguage(OutputLanguage l)
43
8674
  : d_language(l)
44
8674
{}
45
46
8408
void SetLanguage::applyLanguage(std::ostream& out) {
47
  // (offset by one to detect whether default has been set yet)
48
8408
  out.iword(s_iosIndex) = int(d_language) + 1;
49
8408
}
50
51
362720
OutputLanguage SetLanguage::getLanguage(std::ostream& out) {
52
362720
  long& l = out.iword(s_iosIndex);
53
362720
  if(l == 0) {
54
    // set the default language on this ostream
55
    // (offset by one to detect whether default has been set yet)
56
42805
    if(not Options::isCurrentNull()) {
57
42795
      l = options::outputLanguage() + 1;
58
    }
59
42805
    if(l <= 0 || l > language::output::LANG_MAX) {
60
      // if called from outside the library, we may not have options
61
      // available to us at this point (or perhaps the output language
62
      // is not set in Options).  Default to something reasonable, but
63
      // don't set "l" since that would make it "sticky" for this
64
      // stream.
65
2016
      return OutputLanguage(s_defaultOutputLanguage);
66
    }
67
  }
68
360704
  return OutputLanguage(l - 1);
69
}
70
71
184
void SetLanguage::setLanguage(std::ostream& out, OutputLanguage l) {
72
  // (offset by one to detect whether default has been set yet)
73
184
  out.iword(s_iosIndex) = int(l) + 1;
74
184
}
75
76
8408
std::ostream& operator<<(std::ostream& out, SetLanguage l) {
77
8408
  l.applyLanguage(out);
78
8408
  return out;
79
}
80
81
}/* CVC4::language namespace */
82
26676
}/* CVC4 namespace */