summaryrefslogtreecommitdiff
path: root/src/hir/pattern.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/hir/pattern.cpp')
-rw-r--r--src/hir/pattern.cpp118
1 files changed, 118 insertions, 0 deletions
diff --git a/src/hir/pattern.cpp b/src/hir/pattern.cpp
new file mode 100644
index 00000000..64b132a3
--- /dev/null
+++ b/src/hir/pattern.cpp
@@ -0,0 +1,118 @@
+
+#include "pattern.hpp"
+
+namespace HIR {
+ ::std::ostream& operator<<(::std::ostream& os, const Pattern::Value& x) {
+ TU_MATCH(Pattern::Value, (x), (e),
+ (Integer,
+ // TODO: Print with type
+ os << e.value;
+ ),
+ (String,
+ os << "\"" << e << "\"";
+ ),
+ (Named,
+ os << e;
+ )
+ )
+ return os;
+ }
+ ::std::ostream& operator<<(::std::ostream& os, const Pattern& x) {
+ if( x.m_binding.is_valid() ) {
+ if( x.m_binding.m_mutable )
+ os << "mut ";
+ switch(x.m_binding.m_type)
+ {
+ case PatternBinding::Type::Move: break;
+ case PatternBinding::Type::Ref: os << "ref "; break;
+ case PatternBinding::Type::MutRef: os << "ref mut "; break;
+ }
+ os << x.m_binding.m_name << " @ ";
+ }
+ TU_MATCH(Pattern::Data, (x.m_data), (e),
+ (Any,
+ os << "_";
+ ),
+ (Box,
+ os << "box " << *e.sub;
+ ),
+ (Ref,
+ switch(e.type)
+ {
+ case BorrowType::Shared: os << "&"; break;
+ case BorrowType::Unique: os << "&mut "; break;
+ case BorrowType::Owned: os << "&move "; break;
+ }
+ os << *e.sub;
+ ),
+ (Tuple,
+ os << "(";
+ for(const auto& s : e.sub_patterns)
+ os << s << ", ";
+ os << ")";
+ ),
+ (StructTuple,
+ os << e.path;
+ os << "(";
+ for(const auto& s : e.sub_patterns)
+ os << s << ", ";
+ os << ")";
+ ),
+ (StructTupleWildcard,
+ os << e.path;
+ ),
+ (Struct,
+ os << e.path;
+ os << "{ ";
+ for(const auto& ns : e.sub_patterns)
+ os << ns.first << ": " << ns.second << ", ";
+ os << "}";
+ ),
+
+ (Value,
+ os << e.val;
+ ),
+ (Range,
+ os << e.start << " ... " << e.end;
+ ),
+
+ (EnumTuple,
+ os << e.path;
+ os << "(";
+ for(const auto& s : e.sub_patterns)
+ os << s << ", ";
+ os << ")";
+ ),
+ (EnumTupleWildcard,
+ os << e.path;
+ ),
+ (EnumStruct,
+ os << e.path;
+ os << "{ ";
+ for(const auto& ns : e.sub_patterns)
+ os << ns.first << ": " << ns.second << ", ";
+ os << "}";
+ ),
+ (Slice,
+ os << "[";
+ for(const auto& s : e.sub_patterns)
+ os << s << ", ";
+ os << "]";
+ ),
+ (SplitSlice,
+ os << "[";
+ for(const auto& s : e.leading)
+ os << s << ", ";
+ if( e.extra_bind.is_valid() ) {
+ os << e.extra_bind.m_name << " @ ";
+ }
+ os << ".. ";
+ for(const auto& s : e.trailing)
+ os << s << ", ";
+ os << "]";
+ )
+ )
+ return os;
+ }
+}
+