aboutsummaryrefslogtreecommitdiff
path: root/cutl/compiler/sloc-counter.hxx
blob: 10dd3ccac59346564d58a974b5a65dd7e95ec700 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
// file      : cutl/compiler/sloc-counter.hxx
// copyright : Copyright (c) 2009-2017 Code Synthesis Tools CC
// license   : MIT; see accompanying LICENSE file

#ifndef CUTL_COMPILER_SLOC_COUNTER_HXX
#define CUTL_COMPILER_SLOC_COUNTER_HXX

#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);

      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 <cutl/compiler/sloc-counter.txx>

#endif // CUTL_COMPILER_SLOC_COUNTER_HXX