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') {}
19 void beginLine() { _stream << std::string(_indent * 4,
' '); }
20 void endLine() { _stream << (_compact ?
' ' :
'\n'); }
25 _stream << (_compact ?
' ' :
'\n');
29 char newline()
const {
return _nl; }
31 const ID& currentScope()
const {
return _scopes.back(); }
32 void pushScope(
ID id) { _scopes.push_back(std::move(
id)); }
33 void popScope() { _scopes.pop_back(); }
35 bool isCompact() {
return _compact; }
36 bool setCompact(
bool new_compact) {
38 _compact = new_compact;
42 bool isExpandSubsequentType()
const {
return _expand_subsequent_type; }
43 void setExpandSubsequentType(
bool expand) { _expand_subsequent_type = expand; }
45 bool isFirstInBlock()
const {
return _first_in_block; }
46 bool isLastInBlock()
const {
return _last_in_block; }
47 void setPositionInBlock(
bool first,
bool last) {
48 _first_in_block = first;
49 _last_in_block = last;
52 auto indent()
const {
return _indent; }
53 void incrementIndent() { ++_indent; }
54 void decrementIndent() {
56 _first_in_block = _last_in_block =
false;
59 template<
typename T, IF_DERIVED_FROM(T, trait::isNode)>
60 Stream& operator<<(
const T& t) {
61 if constexpr ( std::is_base_of<trait::isType, T>::value ) {
62 if (
auto id = Type(t).typeID() )
66 hilti::detail::printAST(t, *
this);
71 template<
typename T, IF_NOT_DERIVED_FROM(T, trait::isNode)>
72 Stream& operator<<(
const T& t) {
75 _expand_subsequent_type =
false;
81 Stream& operator<<(std::pair<T, const char*> p) {
83 for (
auto& i : p.first ) {
95 std::ostream& _stream;
99 bool _wrote_nl =
false;
100 bool _first_in_block =
false;
101 bool _last_in_block =
false;
102 bool _expand_subsequent_type =
false;
103 std::vector<ID> _scopes = {
""};
Definition: visitors.h:23