Coverage Report

Created: 2017-10-03 07:32

/Users/buildslave/jenkins/sharedspace/clang-stage2-coverage-R@2/llvm/lib/Support/FormattedStream.cpp
Line
Count
Source (jump to first uncovered line)
1
//===-- llvm/Support/FormattedStream.cpp - Formatted streams ----*- C++ -*-===//
2
//
3
//                     The LLVM Compiler Infrastructure
4
//
5
// This file is distributed under the University of Illinois Open Source
6
// License. See LICENSE.TXT for details.
7
//
8
//===----------------------------------------------------------------------===//
9
//
10
// This file contains the implementation of formatted_raw_ostream.
11
//
12
//===----------------------------------------------------------------------===//
13
14
#include "llvm/Support/FormattedStream.h"
15
#include "llvm/Support/Debug.h"
16
#include "llvm/Support/raw_ostream.h"
17
#include <algorithm>
18
19
using namespace llvm;
20
21
/// UpdatePosition - Examine the given char sequence and figure out which
22
/// column we end up in after output, and how many line breaks are contained.
23
///
24
2.02M
static void UpdatePosition(std::pair<unsigned, unsigned> &Position, const char *Ptr, size_t Size) {
25
2.02M
  unsigned &Column = Position.first;
26
2.02M
  unsigned &Line = Position.second;
27
2.02M
28
2.02M
  // Keep track of the current column and line by scanning the string for
29
2.02M
  // special characters
30
260M
  for (const char *End = Ptr + Size; 
Ptr != End260M
;
++Ptr258M
) {
31
258M
    ++Column;
32
258M
    switch (*Ptr) {
33
6.98M
    case '\n':
34
6.98M
      Line += 1;
35
6.98M
      LLVM_FALLTHROUGH;
36
6.98M
    case '\r':
37
6.98M
      Column = 0;
38
6.98M
      break;
39
5.65M
    case '\t':
40
5.65M
      // Assumes tab stop = 8 characters.
41
5.65M
      Column += (8 - (Column & 0x7)) & 0x7;
42
5.65M
      break;
43
258M
    }
44
258M
  }
45
2.02M
}
46
47
/// ComputePosition - Examine the current output and update line and column
48
/// counts.
49
2.02M
void formatted_raw_ostream::ComputePosition(const char *Ptr, size_t Size) {
50
2.02M
  // If our previous scan pointer is inside the buffer, assume we already
51
2.02M
  // scanned those bytes. This depends on raw_ostream to not change our buffer
52
2.02M
  // in unexpected ways.
53
2.02M
  if (
Ptr <= Scanned && 2.02M
Scanned <= Ptr + Size1.27M
)
54
2.02M
    // Scan all characters added since our last scan to determine the new
55
2.02M
    // column.
56
1.27M
    UpdatePosition(Position, Scanned, Size - (Scanned - Ptr));
57
2.02M
  else
58
755k
    UpdatePosition(Position, Ptr, Size);
59
2.02M
60
2.02M
  // Update the scanning pointer.
61
2.02M
  Scanned = Ptr + Size;
62
2.02M
}
63
64
/// PadToColumn - Align the output to some column number.
65
///
66
/// \param NewCol - The column to move to.
67
///
68
1.27M
formatted_raw_ostream &formatted_raw_ostream::PadToColumn(unsigned NewCol) { 
69
1.27M
  // Figure out what's in the buffer and add it to the column count.
70
1.27M
  ComputePosition(getBufferStart(), GetNumBytesInBuffer());
71
1.27M
72
1.27M
  // Output spaces until we reach the desired column.
73
1.27M
  indent(std::max(int(NewCol - getColumn()), 1));
74
1.27M
  return *this;
75
1.27M
}
76
77
755k
void formatted_raw_ostream::write_impl(const char *Ptr, size_t Size) {
78
755k
  // Figure out what's in the buffer and add it to the column count.
79
755k
  ComputePosition(Ptr, Size);
80
755k
81
755k
  // Write the data to the underlying stream (which is unbuffered, so
82
755k
  // the data will be immediately written out).
83
755k
  TheStream->write(Ptr, Size);
84
755k
85
755k
  // Reset the scanning pointer.
86
755k
  Scanned = nullptr;
87
755k
}
88
89
/// fouts() - This returns a reference to a formatted_raw_ostream for
90
/// standard output.  Use it like: fouts() << "foo" << "bar";
91
0
formatted_raw_ostream &llvm::fouts() {
92
0
  static formatted_raw_ostream S(outs());
93
0
  return S;
94
0
}
95
96
/// ferrs() - This returns a reference to a formatted_raw_ostream for
97
/// standard error.  Use it like: ferrs() << "foo" << "bar";
98
0
formatted_raw_ostream &llvm::ferrs() {
99
0
  static formatted_raw_ostream S(errs());
100
0
  return S;
101
0
}
102
103
/// fdbgs() - This returns a reference to a formatted_raw_ostream for
104
/// the debug stream.  Use it like: fdbgs() << "foo" << "bar";
105
0
formatted_raw_ostream &llvm::fdbgs() {
106
0
  static formatted_raw_ostream S(dbgs());
107
0
  return S;
108
0
}