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 const ID& currentScope()
const {
return _scopes.back(); }
42 void pushScope(
ID id) { _scopes.push_back(std::move(
id)); }
43 void popScope() { _scopes.pop_back(); }
45 bool isCompact() {
return _compact; }
46 bool setCompact(
bool new_compact) {
48 _compact = new_compact;
52 bool isExpandSubsequentType()
const {
return _expand_subsequent_type; }
53 void setExpandSubsequentType(
bool expand) { _expand_subsequent_type = expand; }
55 bool isFirstInBlock()
const {
return _first_in_block; }
56 bool isLastInBlock()
const {
return _last_in_block; }
57 void setPositionInBlock(
bool first,
bool last) {
58 _first_in_block = first;
59 _last_in_block = last;
62 auto indent()
const {
return _indent; }
63 void incrementIndent() { ++_indent; }
64 void decrementIndent() {
66 _first_in_block = _last_in_block =
false;
69 template<
typename T, IF_DERIVED_FROM(T, trait::isNode)>
70 Stream& operator<<(
const T& t) {
72 if constexpr ( std::is_base_of<trait::isType, T>::value ) {
73 if (
auto id =
Type(t).typeID() )
77 hilti::detail::printAST(t, *
this);
82 template<
typename T, IF_NOT_DERIVED_FROM(T, trait::isNode)>
83 Stream& operator<<(
const T& t) {
87 _expand_subsequent_type =
false;
93 Stream& operator<<(std::pair<T, const char*> p) {
95 for (
auto& i : p.first ) {
109 void _flush_pending() {
114 std::ostream& _stream;
117 std::string _pending;
119 bool _wrote_nl =
false;
120 bool _first_in_block =
false;
121 bool _last_in_block =
false;
122 bool _expand_subsequent_type =
false;
123 std::vector<ID> _scopes = {
""};
Definition: visitors.h:24