Coverage Report

Created: 2019-03-22 08:08

/Users/buildslave/jenkins/workspace/clang-stage2-coverage-R/llvm/tools/clang/include/clang/Basic/SourceManagerInternals.h
Line
Count
Source (jump to first uncovered line)
1
//===- SourceManagerInternals.h - SourceManager Internals -------*- C++ -*-===//
2
//
3
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4
// See https://llvm.org/LICENSE.txt for license information.
5
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6
//
7
//===----------------------------------------------------------------------===//
8
//
9
/// \file
10
/// Defines implementation details of the clang::SourceManager class.
11
//
12
//===----------------------------------------------------------------------===//
13
14
#ifndef LLVM_CLANG_BASIC_SOURCEMANAGERINTERNALS_H
15
#define LLVM_CLANG_BASIC_SOURCEMANAGERINTERNALS_H
16
17
#include "clang/Basic/SourceLocation.h"
18
#include "clang/Basic/SourceManager.h"
19
#include "llvm/ADT/StringMap.h"
20
#include "llvm/ADT/StringRef.h"
21
#include "llvm/Support/Allocator.h"
22
#include <cassert>
23
#include <map>
24
#include <vector>
25
26
namespace clang {
27
28
//===----------------------------------------------------------------------===//
29
// Line Table Implementation
30
//===----------------------------------------------------------------------===//
31
32
struct LineEntry {
33
  /// The offset in this file that the line entry occurs at.
34
  unsigned FileOffset;
35
36
  /// The presumed line number of this line entry: \#line 4.
37
  unsigned LineNo;
38
39
  /// The ID of the filename identified by this line entry:
40
  /// \#line 4 "foo.c".  This is -1 if not specified.
41
  int FilenameID;
42
43
  /// Set the 0 if no flags, 1 if a system header,
44
  SrcMgr::CharacteristicKind FileKind;
45
46
  /// The offset of the virtual include stack location,
47
  /// which is manipulated by GNU linemarker directives.
48
  ///
49
  /// If this is 0 then there is no virtual \#includer.
50
  unsigned IncludeOffset;
51
52
  static LineEntry get(unsigned Offs, unsigned Line, int Filename,
53
                       SrcMgr::CharacteristicKind FileKind,
54
164k
                       unsigned IncludeOffset) {
55
164k
    LineEntry E;
56
164k
    E.FileOffset = Offs;
57
164k
    E.LineNo = Line;
58
164k
    E.FilenameID = Filename;
59
164k
    E.FileKind = FileKind;
60
164k
    E.IncludeOffset = IncludeOffset;
61
164k
    return E;
62
164k
  }
63
};
64
65
// needed for FindNearestLineEntry (upper_bound of LineEntry)
66
0
inline bool operator<(const LineEntry &lhs, const LineEntry &rhs) {
67
0
  // FIXME: should check the other field?
68
0
  return lhs.FileOffset < rhs.FileOffset;
69
0
}
70
71
0
inline bool operator<(const LineEntry &E, unsigned Offset) {
72
0
  return E.FileOffset < Offset;
73
0
}
74
75
110k
inline bool operator<(unsigned Offset, const LineEntry &E) {
76
110k
  return Offset < E.FileOffset;
77
110k
}
78
79
/// Used to hold and unique data used to represent \#line information.
80
class LineTableInfo {
81
  /// Map used to assign unique IDs to filenames in \#line directives.
82
  ///
83
  /// This allows us to unique the filenames that
84
  /// frequently reoccur and reference them with indices.  FilenameIDs holds
85
  /// the mapping from string -> ID, and FilenamesByID holds the mapping of ID
86
  /// to string.
87
  llvm::StringMap<unsigned, llvm::BumpPtrAllocator> FilenameIDs;
88
  std::vector<llvm::StringMapEntry<unsigned>*> FilenamesByID;
89
90
  /// Map from FileIDs to a list of line entries (sorted by the offset
91
  /// at which they occur in the file).
92
  std::map<FileID, std::vector<LineEntry>> LineEntries;
93
94
public:
95
17
  void clear() {
96
17
    FilenameIDs.clear();
97
17
    FilenamesByID.clear();
98
17
    LineEntries.clear();
99
17
  }
100
101
  unsigned getLineTableFilenameID(StringRef Str);
102
103
2.34M
  StringRef getFilename(unsigned ID) const {
104
2.34M
    assert(ID < FilenamesByID.size() && "Invalid FilenameID");
105
2.34M
    return FilenamesByID[ID]->getKey();
106
2.34M
  }
107
108
0
  unsigned getNumFilenames() const { return FilenamesByID.size(); }
109
110
  void AddLineNote(FileID FID, unsigned Offset,
111
                   unsigned LineNo, int FilenameID,
112
                   unsigned EntryExit, SrcMgr::CharacteristicKind FileKind);
113
114
115
  /// Find the line entry nearest to FID that is before it.
116
  ///
117
  /// If there is no line entry before \p Offset in \p FID, returns null.
118
  const LineEntry *FindNearestLineEntry(FileID FID, unsigned Offset);
119
120
  // Low-level access
121
  using iterator = std::map<FileID, std::vector<LineEntry>>::iterator;
122
123
7.06k
  iterator begin() { return LineEntries.begin(); }
124
7.06k
  iterator end() { return LineEntries.end(); }
125
126
  /// Add a new line entry that has already been encoded into
127
  /// the internal representation of the line table.
128
  void AddEntry(FileID FID, const std::vector<LineEntry> &Entries);
129
};
130
131
} // namespace clang
132
133
#endif // LLVM_CLANG_BASIC_SOURCEMANAGERINTERNALS_H