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 |
9397 |
const int SetLanguage::s_iosIndex = std::ios_base::xalloc(); |
28 |
|
|
29 |
92 |
SetLanguage::Scope::Scope(std::ostream& out, OutputLanguage language) |
30 |
|
: d_out(out) |
31 |
92 |
, d_oldLanguage(SetLanguage::getLanguage(out)) |
32 |
|
{ |
33 |
92 |
SetLanguage::setLanguage(out, language); |
34 |
92 |
} |
35 |
|
|
36 |
184 |
SetLanguage::Scope::~Scope(){ |
37 |
92 |
SetLanguage::setLanguage(d_out, d_oldLanguage); |
38 |
92 |
} |
39 |
|
|
40 |
|
|
41 |
8770 |
SetLanguage::SetLanguage(OutputLanguage l) |
42 |
8770 |
: d_language(l) |
43 |
8770 |
{} |
44 |
|
|
45 |
8387 |
void SetLanguage::applyLanguage(std::ostream& out) { |
46 |
|
// (offset by one to detect whether default has been set yet) |
47 |
8387 |
out.iword(s_iosIndex) = int(d_language) + 1; |
48 |
8387 |
} |
49 |
|
|
50 |
371466 |
OutputLanguage SetLanguage::getLanguage(std::ostream& out) { |
51 |
371466 |
long& l = out.iword(s_iosIndex); |
52 |
371466 |
if(l == 0) { |
53 |
|
// set the default language on this ostream |
54 |
|
// (offset by one to detect whether default has been set yet) |
55 |
36711 |
if(not Options::isCurrentNull()) { |
56 |
36701 |
l = options::outputLanguage() + 1; |
57 |
|
} |
58 |
36711 |
if(l <= 0 || l > language::output::LANG_MAX) { |
59 |
|
// if called from outside the library, we may not have options |
60 |
|
// available to us at this point (or perhaps the output language |
61 |
|
// is not set in Options). Default to something reasonable, but |
62 |
|
// don't set "l" since that would make it "sticky" for this |
63 |
|
// stream. |
64 |
2062 |
return OutputLanguage(s_defaultOutputLanguage); |
65 |
|
} |
66 |
|
} |
67 |
369404 |
return OutputLanguage(l - 1); |
68 |
|
} |
69 |
|
|
70 |
184 |
void SetLanguage::setLanguage(std::ostream& out, OutputLanguage l) { |
71 |
|
// (offset by one to detect whether default has been set yet) |
72 |
184 |
out.iword(s_iosIndex) = int(l) + 1; |
73 |
184 |
} |
74 |
|
|
75 |
8387 |
std::ostream& operator<<(std::ostream& out, SetLanguage l) { |
76 |
8387 |
l.applyLanguage(out); |
77 |
8387 |
return out; |
78 |
|
} |
79 |
|
|
80 |
|
} // namespace language |
81 |
28191 |
} // namespace cvc5 |