From 0143e511f7a5f3595907787a832bee4e3cd03daf Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Sun, 13 Sep 2009 11:52:46 +0200 Subject: Add code stream interface and SLOC counter --- cutl/compiler/code-stream.hxx | 153 ++++++++++++++++++++++++++++ cutl/compiler/code-stream.txx | 96 ++++++++++++++++++ cutl/compiler/sloc-counter.hxx | 80 +++++++++++++++ cutl/compiler/sloc-counter.txx | 225 +++++++++++++++++++++++++++++++++++++++++ 4 files changed, 554 insertions(+) create mode 100644 cutl/compiler/code-stream.hxx create mode 100644 cutl/compiler/code-stream.txx create mode 100644 cutl/compiler/sloc-counter.hxx create mode 100644 cutl/compiler/sloc-counter.txx (limited to 'cutl') diff --git a/cutl/compiler/code-stream.hxx b/cutl/compiler/code-stream.hxx new file mode 100644 index 0000000..bb8305a --- /dev/null +++ b/cutl/compiler/code-stream.hxx @@ -0,0 +1,153 @@ +// file : cutl/compiler/code-stream.hxx +// author : Boris Kolpackov +// copyright : Copyright (c) 2009 Code Synthesis Tools CC +// license : MIT; see accompanying LICENSE file + +#ifndef CUTL_COMPILER_CODE_STREAM_HXX +#define CUTL_COMPILER_CODE_STREAM_HXX + +#include // std::auto_ptr +#include + +namespace cutl +{ + namespace compiler + { + // + // + template + class code_stream + { + public: + code_stream () {} + + virtual + ~code_stream (); + + public: + virtual void + put (C) = 0; + + // Unbuffer flushes internal formatting buffers (if any). + // Note that unbuffer is not exactly flushing since it can + // result in formatting errors and in general can not be + // called at arbitrary points. Natural use case would be + // to call unbuffer at the end of the stream when no more + // data is expected. + // + virtual void + unbuffer () = 0; + + private: + code_stream (code_stream const&); + + code_stream& + operator= (code_stream const&); + }; + + // + // + template + class from_streambuf_adapter: public code_stream + { + public: + typedef typename std::basic_streambuf::traits_type traits_type; + typedef typename std::basic_streambuf::int_type int_type; + + struct eof {}; + struct sync {}; + + public: + from_streambuf_adapter (std::basic_streambuf& stream) + : stream_ (stream) + { + } + + private: + from_streambuf_adapter (from_streambuf_adapter const&); + + from_streambuf_adapter& + operator= (from_streambuf_adapter const&); + + public: + virtual void + put (C c); + + virtual void + unbuffer (); + + private: + std::basic_streambuf& stream_; + }; + + // + // + template + class to_streambuf_adapter: public std::basic_streambuf + { + public: + typedef typename std::basic_streambuf::traits_type traits_type; + typedef typename std::basic_streambuf::int_type int_type; + + public: + to_streambuf_adapter (code_stream& stream) + : stream_ (stream) + { + } + + private: + to_streambuf_adapter (to_streambuf_adapter const&); + + to_streambuf_adapter& + operator= (to_streambuf_adapter const&); + + public: + virtual int_type + overflow (int_type i); + + // Does nothing since calling unbuffer here would be dangerous. + // See the note in code_stream. + // + virtual int + sync (); + + private: + code_stream& stream_; + }; + + // + // + template