aboutsummaryrefslogtreecommitdiff
path: root/libcutl/compiler/sloc-counter.hxx
diff options
context:
space:
mode:
authorKaren Arutyunov <karen@codesynthesis.com>2020-12-16 20:29:05 +0300
committerKaren Arutyunov <karen@codesynthesis.com>2021-02-24 16:40:04 +0300
commit8e761289a2446367267c6c0d9a26e734f0f78306 (patch)
treefb495d8c18801f271d124ee48731f10df396ca89 /libcutl/compiler/sloc-counter.hxx
parent4c8104756b92b9fa16b3a725e8a6aa620dfd606e (diff)
Get rid of legacy build systems and rename cutl/ to libcutl/
Diffstat (limited to 'libcutl/compiler/sloc-counter.hxx')
-rw-r--r--libcutl/compiler/sloc-counter.hxx77
1 files changed, 77 insertions, 0 deletions
diff --git a/libcutl/compiler/sloc-counter.hxx b/libcutl/compiler/sloc-counter.hxx
new file mode 100644
index 0000000..581b6f3
--- /dev/null
+++ b/libcutl/compiler/sloc-counter.hxx
@@ -0,0 +1,77 @@
+// file : libcutl/compiler/sloc-counter.hxx
+// license : MIT; see accompanying LICENSE file
+
+#ifndef LIBCUTL_COMPILER_SLOC_COUNTER_HXX
+#define LIBCUTL_COMPILER_SLOC_COUNTER_HXX
+
+#include <cstddef> // std::size_t
+
+#include <libcutl/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);
+
+ virtual void
+ unbuffer ();
+
+ private:
+ void
+ code (C);
+
+ void
+ c_comment (C);
+
+ void
+ cxx_comment (C);
+
+ void
+ char_literal (C);
+
+ void
+ string_literal (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 <libcutl/compiler/sloc-counter.txx>
+
+#endif // LIBCUTL_COMPILER_SLOC_COUNTER_HXX