11 #include <hilti/base/util.h> 12 #include <hilti/compiler/detail/visitors.h> 18 Stream(std::ostream& s,
bool _compact) : _stream(s), _compact(_compact), _nl(_compact ?
' ' :
'\n') {}
22 _stream << std::string(static_cast<size_t>(_indent) * 4,
' ');
39 char newline()
const {
return _nl; }
41 bool isCompact() {
return _compact; }
42 bool setCompact(
bool new_compact) {
44 _compact = new_compact;
48 bool isExpandSubsequentType()
const {
return _expand_subsequent_type; }
49 void setExpandSubsequentType(
bool expand) { _expand_subsequent_type = expand; }
51 bool isFirstInBlock()
const {
return _first_in_block; }
52 bool isLastInBlock()
const {
return _last_in_block; }
53 void setPositionInBlock(
bool first,
bool last) {
54 _first_in_block = first;
55 _last_in_block = last;
58 auto indent()
const {
return _indent; }
59 void incrementIndent() { ++_indent; }
60 void decrementIndent() {
62 _first_in_block = _last_in_block =
false;
65 template<
typename T, IF_DERIVED_FROM(T, trait::isNode)>
66 Stream& operator<<(
const T& t) {
68 if constexpr ( std::is_base_of<trait::isType, T>::value ) {
69 if (
auto id =
Type(t).typeID() )
73 hilti::detail::printAST(t, *
this);
78 template<
typename T, IF_NOT_DERIVED_FROM(T, trait::isNode)>
79 Stream& operator<<(
const T& t) {
83 _expand_subsequent_type =
false;
89 Stream& operator<<(std::pair<T, const char*> p) {
91 for (
auto& i : p.first ) {
105 void _flush_pending() {
110 std::ostream& _stream;
113 std::string _pending;
115 bool _wrote_nl =
false;
116 bool _first_in_block =
false;
117 bool _last_in_block =
false;
118 bool _expand_subsequent_type =
false;
Definition: doc-string.h:10