10 #include <hilti/base/util.h> 11 #include <hilti/compiler/detail/visitors.h> 17 Stream(std::ostream& s,
bool _compact) : _stream(s), _compact(_compact), _nl(_compact ?
' ' :
'\n') {}
21 _stream << std::string(_indent * 4,
' ');
38 char newline()
const {
return _nl; }
40 const ID& currentScope()
const {
return _scopes.back(); }
41 void pushScope(
ID id) { _scopes.push_back(std::move(
id)); }
42 void popScope() { _scopes.pop_back(); }
44 bool isCompact() {
return _compact; }
45 bool setCompact(
bool new_compact) {
47 _compact = new_compact;
51 bool isExpandSubsequentType()
const {
return _expand_subsequent_type; }
52 void setExpandSubsequentType(
bool expand) { _expand_subsequent_type = expand; }
54 bool isFirstInBlock()
const {
return _first_in_block; }
55 bool isLastInBlock()
const {
return _last_in_block; }
56 void setPositionInBlock(
bool first,
bool last) {
57 _first_in_block = first;
58 _last_in_block = last;
61 auto indent()
const {
return _indent; }
62 void incrementIndent() { ++_indent; }
63 void decrementIndent() {
65 _first_in_block = _last_in_block =
false;
68 template<
typename T, IF_DERIVED_FROM(T, trait::isNode)>
69 Stream& operator<<(
const T& t) {
71 if constexpr ( std::is_base_of<trait::isType, T>::value ) {
72 if (
auto id =
Type(t).typeID() )
76 hilti::detail::printAST(t, *
this);
81 template<
typename T, IF_NOT_DERIVED_FROM(T, trait::isNode)>
82 Stream& operator<<(
const T& t) {
86 _expand_subsequent_type =
false;
92 Stream& operator<<(std::pair<T, const char*> p) {
94 for (
auto& i : p.first ) {
108 void _flush_pending() {
113 std::ostream& _stream;
116 std::string _pending;
118 bool _wrote_nl =
false;
119 bool _first_in_block =
false;
120 bool _last_in_block =
false;
121 bool _expand_subsequent_type =
false;
122 std::vector<ID> _scopes = {
""};
Definition: visitors.h:24