12 #include <hilti/ast/forward.h>
13 #include <hilti/ast/id.h>
14 #include <hilti/base/util.h>
32 void print(std::ostream& out, Node* root,
bool compact,
bool user_visible);
38 const Plugin* current_plugin =
nullptr;
40 std::vector<ID> scopes = {{
""}};
43 bool wrote_nl =
false;
44 bool first_in_block =
false;
45 bool last_in_block =
false;
46 bool expand_subsequent_type =
false;
48 bool user_visible =
true;
50 inline static std::unique_ptr<State> current;
51 inline static uint64_t depth = 0;
58 Stream(std::ostream& s) : _stream(s) {}
61 assert(detail::State::current);
62 return *detail::State::current;
67 _stream << std::string(static_cast<size_t>(state().indent) * 4,
' ');
70 void endLine() { _stream <<
'\n'; }
73 if ( state().wrote_nl )
77 state().wrote_nl =
true;
80 char newline()
const {
return '\n'; }
82 bool isExpandSubsequentType()
const {
return state().expand_subsequent_type; }
83 void setExpandSubsequentType(
bool expand) { state().expand_subsequent_type = expand; }
85 bool isCompact()
const {
return state().compact; }
86 void setCompact(
bool compact) { state().compact = compact; }
89 bool isFirstInBlock()
const {
return state().first_in_block; }
90 bool isLastInBlock()
const {
return state().last_in_block; }
91 void setPositionInBlock(
bool first,
bool last) {
92 state().first_in_block = first;
93 state().last_in_block = last;
96 auto indent()
const {
return state().indent; }
97 void incrementIndent() { ++state().indent; }
98 void decrementIndent() {
100 state().first_in_block = state().last_in_block =
false;
103 const ID& currentScope() {
return state().scopes.back(); }
104 void pushScope(
ID id) { state().scopes.push_back(std::move(
id)); }
105 void popScope() { state().scopes.pop_back(); }
107 template<
typename T, IF_DERIVED_FROM(T, Node)>
108 Stream& operator<<(T* t) {
116 template<
typename T, IF_NOT_DERIVED_FROM(T, Node)>
117 Stream& operator<<(
const T& t) {
118 state().wrote_nl =
false;
126 Stream& operator<<(
const std::pair<T, const char*>& p) {
128 for (
const auto& i : p.first ) {
142 Stream& operator<<(std::pair<T*, const char*> p) {
144 for (
auto& i : p.first ) {
158 friend void printer::print(std::ostream& out,
Node* root,
bool compact,
bool user_visible);
160 void _print(
Node* root);
162 void _flush_pending() {
163 _stream << state().pending;
164 state().pending.clear();
167 std::ostream& _stream;
void print(const T &t, const hilti::rt::TypeInfo *, bool newline=true)
Definition: hilti.h:23