From 6fbb7ffdbdfc3ea45eb913f9d6644fe5020f21d7 Mon Sep 17 00:00:00 2001 From: Patrick Walton Date: Tue, 9 Aug 2011 19:01:15 -0700 Subject: rt: Stub code for polymorphic log --- src/rt/rust_shape.cpp | 47 +++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 45 insertions(+), 2 deletions(-) (limited to 'src/rt/rust_shape.cpp') diff --git a/src/rt/rust_shape.cpp b/src/rt/rust_shape.cpp index 3e927b0f393..d7d5d500817 100644 --- a/src/rt/rust_shape.cpp +++ b/src/rt/rust_shape.cpp @@ -2,6 +2,7 @@ // actions, such as copying, freeing, comparing, and so on. #include +#include #include #include #include @@ -1085,11 +1086,11 @@ public: result(0) {} void walk_evec(bool align, bool is_pod, uint16_t sp_size) { - return walk_vec(align, is_pod, get_evec_data_range(dp)); + walk_vec(align, is_pod, get_evec_data_range(dp)); } void walk_ivec(bool align, bool is_pod, size_align &elem_sa) { - return walk_vec(align, is_pod, get_ivec_data_range(dp)); + walk_vec(align, is_pod, get_ivec_data_range(dp)); } void walk_fn(bool align) { return cmp_two_pointers(align); } @@ -1183,6 +1184,48 @@ cmp::walk_variant(bool align, tag_info &tinfo, uint32_t variant_id, } } + +// Polymorphic logging, for convenience + +class log : public data { + friend class data; + +private: + std::ostream &out; + bool in_string; + + void walk_evec(bool align, bool is_pod, uint16_t sp_size) { + walk_vec(align, is_pod, get_evec_data_range(dp)); + } + + void walk_ivec(bool align, bool is_pod, size_align &elem_sa) { + walk_vec(align, is_pod, get_ivec_data_range(dp)); + } + + void walk_vec(bool align, bool is_pod, + const std::pair &data); + + template + void walk_number() { out << get_dp(dp); } + +public: + log(rust_task *in_task, + const uint8_t *in_sp, + const type_param *in_params, + const rust_shape_tables *in_tables, + uint8_t *in_data, + std::ostream &in_out) + : data(in_task, in_sp, in_params, in_tables, in_data), + out(in_out) {} +}; + +void +log::walk_vec(bool align, bool is_pod, + const std::pair &data) { + // TODO: Check to see whether this is a string (contains u8). If so, + // write the vector ""-style; otherwise [ ... , ... ] style. +} + } // end namespace shape extern "C" void -- cgit 1.4.1-3-g733a5