aboutsummaryrefslogtreecommitdiff
path: root/odb/diagnostics.cxx
blob: 0ebfba92eef2876e2da6ea1b251847b8ec64f2ee (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
// file      : odb/diagnostics.cxx
// copyright : Copyright (c) 2009-2012 Code Synthesis Tools CC
// license   : GNU GPL v3; see accompanying LICENSE file

#include <odb/gcc.hxx>

#include <sstream>

#include <odb/cxx-lexer.hxx>
#include <odb/diagnostics.hxx>

using namespace std;
using cutl::fs::path;

std::ostream&
error (path const& p, size_t line, size_t clmn)
{
  //@@ We only need to do this if we are still parsing (i.e.,
  //   pragma parsing). Is there a way to detect this?
  //
  errorcount++;

  cerr << p << ':' << line << ':' << clmn << ": error: ";
  return cerr;
}

std::ostream&
warn (path const& p, size_t line, size_t clmn)
{
  warningcount++;

  cerr << p << ':' << line << ':' << clmn << ": warning: ";
  return cerr;
}

std::ostream&
info (path const& p, size_t line, size_t clmn)
{
  cerr << p << ':' << line << ':' << clmn << ": info: ";
  return cerr;
}

std::ostream&
error (location_t loc)
{
  errorcount++;
  cerr << LOCATION_FILE (loc) << ':'
       << LOCATION_LINE (loc) << ':'
       << LOCATION_COLUMN (loc) << ':'
       << " error: ";
  return cerr;
}

std::ostream&
warn (location_t loc)
{
  warningcount++;
  cerr << LOCATION_FILE (loc) << ':'
       << LOCATION_LINE (loc) << ':'
       << LOCATION_COLUMN (loc) << ':'
       << " warning: ";
  return cerr;
}

std::ostream&
info (location_t loc)
{
  cerr << LOCATION_FILE (loc) << ':'
       << LOCATION_LINE (loc) << ':'
       << LOCATION_COLUMN (loc) << ':'
       << " info: ";
  return cerr;
}

std::ostream&
error (cxx_lexer& l)
{
  return error (l.location ());
}

std::ostream&
warn (cxx_lexer& l)
{
  return warn (l.location ());
}

std::ostream&
info (cxx_lexer& l)
{
  return info (l.location ());
}

std::string
location_string (path const& p, size_t line, size_t clmn, bool leaf)
{
  ostringstream ostr;

  if (leaf)
    ostr << p.leaf ();
  else
    ostr << p;

  ostr << ':' << line << ':' << clmn;
  return ostr.str ();
}

std::string
location_string (location_t loc, bool leaf)
{
  ostringstream ostr;

  if (leaf)
    ostr << path (LOCATION_FILE (loc)).leaf ();
  else
    ostr << LOCATION_FILE (loc);

  ostr << ':' << LOCATION_LINE (loc) << ':' << LOCATION_COLUMN (loc);
  return ostr.str ();
}

path
location_file (location_t loc)
{
  return path (LOCATION_FILE (loc));
}

size_t
location_line (location_t loc)
{
  return LOCATION_LINE (loc);
}

size_t
location_column (location_t loc)
{
  return LOCATION_COLUMN (loc);
}