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 |
9834 |
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 |
9109 |
SetLanguage::SetLanguage(Language l) : d_language(l) {} |
40 |
|
|
41 |
8726 |
void SetLanguage::applyLanguage(std::ostream& out) { |
42 |
|
// (offset by one to detect whether default has been set yet) |
43 |
8726 |
out.iword(s_iosIndex) = int(d_language) + 1; |
44 |
8726 |
} |
45 |
|
|
46 |
371524 |
Language SetLanguage::getLanguage(std::ostream& out) |
47 |
|
{ |
48 |
371524 |
long& l = out.iword(s_iosIndex); |
49 |
371524 |
if(l == 0) { |
50 |
|
// set the default language on this ostream |
51 |
|
// (offset by one to detect whether default has been set yet) |
52 |
35329 |
if(not Options::isCurrentNull()) { |
53 |
35319 |
l = static_cast<long>(options::outputLanguage()) + 1; |
54 |
|
} |
55 |
35329 |
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 |
2111 |
return s_defaultOutputLanguage; |
63 |
|
} |
64 |
|
} |
65 |
369413 |
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 |
8726 |
std::ostream& operator<<(std::ostream& out, SetLanguage l) { |
75 |
8726 |
l.applyLanguage(out); |
76 |
8726 |
return out; |
77 |
|
} |
78 |
|
|
79 |
|
} // namespace language |
80 |
29502 |
} // namespace cvc5 |