diff options
author | Boris Kolpackov <boris@codesynthesis.com> | 2009-09-13 11:52:46 +0200 |
---|---|---|
committer | Boris Kolpackov <boris@codesynthesis.com> | 2009-09-13 11:52:46 +0200 |
commit | 0143e511f7a5f3595907787a832bee4e3cd03daf (patch) | |
tree | 141d76fb8c18a8258eaa7d20035e22875f1bf0a3 /cutl/compiler/sloc-counter.hxx | |
parent | cb9ea47e7825b5073d4d645afb94f6326cb7cf4d (diff) |
Add code stream interface and SLOC counter
Diffstat (limited to 'cutl/compiler/sloc-counter.hxx')
-rw-r--r-- | cutl/compiler/sloc-counter.hxx | 80 |
1 files changed, 80 insertions, 0 deletions
diff --git a/cutl/compiler/sloc-counter.hxx b/cutl/compiler/sloc-counter.hxx new file mode 100644 index 0000000..eb9e259 --- /dev/null +++ b/cutl/compiler/sloc-counter.hxx @@ -0,0 +1,80 @@ +// file : cutl/compiler/sloc-counter.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2009 Code Synthesis Tools CC +// license : MIT; see accompanying LICENSE file + +#ifndef CUTL_COMPILER_SLOC_COUNTER_HXX +#define CUTL_COMPILER_SLOC_COUNTER_HXX + +#include <cctype> // std::isspace +#include <cstddef> // std::size_t + +#include <cutl/compiler/code-stream.hxx> + +namespace cutl +{ + namespace compiler + { + template <typename C> + class sloc_counter: public code_stream<C> + { + public: + sloc_counter (code_stream<C>& out); + + std::size_t + count () const + { + return count_; + } + + private: + sloc_counter (sloc_counter const&); + + sloc_counter& + operator= (sloc_counter const&); + + public: + virtual void + put (C c); + + virtual void + unbuffer (); + + private: + void + code (C c); + + void + c_comment (C c); + + void + cxx_comment (C c); + + void + char_literal (C c); + + void + string_literal (C c); + + private: + code_stream<C>& out_; + std::size_t count_; + + C prev_; // Previous character or '\0'. + bool code_counted_; // This code line has already been counted. + + enum construct + { + con_code, + con_c_com, + con_cxx_com, + con_char_lit, + con_string_lit + } construct_; + }; + } +} + +#include <cutl/compiler/sloc-counter.txx> + +#endif // CUTL_COMPILER_SLOC_COUNTER_HXX |