12 #include <hilti/ast/forward.h>
13 #include <hilti/ast/id.h>
14 #include <hilti/ast/node.h>
15 #include <hilti/base/util.h>
33 void print(std::ostream& out, Node* root,
bool compact,
bool user_visible);
39 const Plugin* current_plugin =
nullptr;
41 std::vector<ID> scopes = {{
""}};
44 bool wrote_nl =
false;
45 bool first_in_block =
false;
46 bool last_in_block =
false;
47 bool expand_subsequent_type =
false;
49 bool user_visible =
true;
51 inline static std::unique_ptr<State> current;
52 inline static uint64_t depth = 0;
59 Stream(std::ostream& s) : _stream(s) {}
62 assert(detail::State::current);
63 return *detail::State::current;
68 _stream << std::string(static_cast<size_t>(state().indent) * 4,
' ');
71 void endLine() { _stream <<
'\n'; }
74 if ( state().wrote_nl )
78 state().wrote_nl =
true;
81 char newline()
const {
return '\n'; }
83 bool isExpandSubsequentType()
const {
return state().expand_subsequent_type; }
84 void setExpandSubsequentType(
bool expand) { state().expand_subsequent_type = expand; }
86 bool isCompact()
const {
return state().compact; }
87 void setCompact(
bool compact) { state().compact = compact; }
90 bool isFirstInBlock()
const {
return state().first_in_block; }
91 bool isLastInBlock()
const {
return state().last_in_block; }
92 void setPositionInBlock(
bool first,
bool last) {
93 state().first_in_block = first;
94 state().last_in_block = last;
97 auto indent()
const {
return state().indent; }
98 void incrementIndent() { ++state().indent; }
99 void decrementIndent() {
101 state().first_in_block = state().last_in_block =
false;
104 const ID& currentScope() {
return state().scopes.back(); }
105 void pushScope(
ID id) { state().scopes.push_back(std::move(
id)); }
106 void popScope() { state().scopes.pop_back(); }
110 requires std::is_base_of_v<Node, T>
120 Stream& operator<<(
const T& t)
121 requires(! std::is_base_of_v<Node, T>)
123 state().wrote_nl =
false;
131 Stream& operator<<(
const std::pair<T, const char*>& p) {
133 for (
const auto& i : p.first ) {
147 Stream& operator<<(std::pair<T*, const char*> p) {
149 for (
auto& i : p.first ) {
163 friend void printer::print(std::ostream& out,
Node* root,
bool compact,
bool user_visible);
165 void _print(
Node* root);
167 void _flush_pending() {
168 _stream << state().pending;
169 state().pending.clear();
172 std::ostream& _stream;
void print(const T &t, const hilti::rt::TypeInfo *, bool newline=true)
Definition: hilti.h:23