summaryrefslogtreecommitdiff
path: root/CIAO/CCF/CCF/CompilerElements/Diagnostic.hpp
blob: 34eb0006b695f90ada9777a8a09245d1e699e487 (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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
// file      : CCF/CompilerElements/Diagnostic.hpp
// author    : Boris Kolpackov <boris@dre.vanderbilt.edu>
// cvs-id    : $Id$

#ifndef CCF_DIAGNOSTIC_HPP
#define CCF_DIAGNOSTIC_HPP

#include <string>
#include <sstream>
#include <iostream>

#include "CCF/CompilerElements/ExH.hpp"

//@@ Should be inside CCF namespace

namespace Diagnostic
{
  //
  //
  //
  class Record : public std::ostringstream
  {
  public:

    struct Type
    {
      enum Value
      {
        INFO,
        WARNING,
        ERROR
      };
    };

    Record (Type::Value type,
            std::string file,
            unsigned long line,
            std::string description = "")
        : std::ostringstream (description),
          type_ (type),
          file_ (file),
          line_ (line)
    {
    }

  public:

    Type::Value
    type () const
    {
      return type_;
    }

    std::string
    file () const
    {
      return file_;
    }

    unsigned long line () const
    {
      return line_;
    }

    std::string
    description () const
    {
      return str ();
    }

  private:
    Type::Value type_;
    std::string file_;
    unsigned long line_;
  };


  //
  //
  //
  struct Info : public Record
  {
    Info (std::string file,
          unsigned long line,
          std::string description = "")
        : Record (Type::INFO, file, line, description)
    {
    }
  };


  //
  //
  //
  struct Warning : public Record
  {
    Warning (std::string file,
             unsigned long line,
             std::string description = "")
        : Record (Type::WARNING, file, line, description)
    {
    }
  };


  //
  //
  //
  struct Error : public Record
  {
    Error (std::string file,
           unsigned long line,
           std::string description = "")
        : Record (Type::ERROR, file, line, description)
    {
    }
  };


  //
  //
  //
  class Stream
  {
  public:

    Stream ()
        : info_count_ (0),
          warning_count_ (0),
          error_count_ (0)
    {
    }


    Stream&
    operator<< (Record const& msg)
    {
      std::cerr << msg.file () << ":" << msg.line () << ": "
                << msg.description () << std::endl;

      switch (msg.type ())
      {
      case Record::Type::INFO:
        {
          info_count_++;
          break;
        }
      case Record::Type::WARNING:
        {
          warning_count_++;
        }
      case Record::Type::ERROR:
        {
          error_count_++;
        }
      }

      return *this;
    }

  public:
    unsigned long
    info_count ()
    {
      return info_count_;
    }

    unsigned long
    warning_coun ()
    {
      return warning_count_;
    }

    unsigned long
    error_count ()
    {
      return error_count_;
    }

  private:
    unsigned long info_count_;
    unsigned long warning_count_;
    unsigned long error_count_;

  private:
    // Copy semanic is not supported.
    Stream (Stream const&) throw ();
    Stream& operator= (Stream const&) throw ();
  };
}

#endif  // CCF_DIAGNOSTIC_HPP