Coverage Report

Created: 2018-12-11 17:59

/Users/buildslave/jenkins/workspace/clang-stage2-coverage-R/llvm/tools/clang/include/clang/Basic/PlistSupport.h
Line
Count
Source (jump to first uncovered line)
1
//===- PlistSupport.h - Plist Output Utilities ------------------*- 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
#ifndef LLVM_CLANG_BASIC_PLISTSUPPORT_H
11
#define LLVM_CLANG_BASIC_PLISTSUPPORT_H
12
13
#include "clang/Basic/LLVM.h"
14
#include "clang/Basic/SourceLocation.h"
15
#include "clang/Basic/SourceManager.h"
16
#include "llvm/ADT/DenseMap.h"
17
#include "llvm/ADT/SmallVector.h"
18
#include "llvm/ADT/StringRef.h"
19
#include "llvm/Support/raw_ostream.h"
20
#include <cassert>
21
#include <cstdint>
22
23
namespace clang {
24
namespace markup {
25
26
using FIDMap = llvm::DenseMap<FileID, unsigned>;
27
28
inline unsigned AddFID(FIDMap &FIDs, SmallVectorImpl<FileID> &V,
29
8.05k
                   FileID FID) {
30
8.05k
  FIDMap::iterator I = FIDs.find(FID);
31
8.05k
  if (I != FIDs.end())
32
8.00k
    return I->second;
33
53
  unsigned NewValue = V.size();
34
53
  FIDs[FID] = NewValue;
35
53
  V.push_back(FID);
36
53
  return NewValue;
37
53
}
38
39
inline unsigned AddFID(FIDMap &FIDs, SmallVectorImpl<FileID> &V,
40
7.47k
                   const SourceManager &SM, SourceLocation L) {
41
7.47k
  FileID FID = SM.getFileID(SM.getExpansionLoc(L));
42
7.47k
  return AddFID(FIDs, V, FID);
43
7.47k
}
44
45
14.2k
inline unsigned GetFID(const FIDMap &FIDs, FileID FID) {
46
14.2k
  FIDMap::const_iterator I = FIDs.find(FID);
47
14.2k
  assert(I != FIDs.end());
48
14.2k
  return I->second;
49
14.2k
}
50
51
inline unsigned GetFID(const FIDMap &FIDs, const SourceManager &SM,
52
14.2k
                       SourceLocation L) {
53
14.2k
  FileID FID = SM.getFileID(SM.getExpansionLoc(L));
54
14.2k
  return GetFID(FIDs, FID);
55
14.2k
}
56
57
132k
inline raw_ostream &Indent(raw_ostream &o, const unsigned indent) {
58
1.09M
  for (unsigned i = 0; i < indent; 
++i959k
)
59
959k
    o << ' ';
60
132k
  return o;
61
132k
}
62
63
50
inline raw_ostream &EmitPlistHeader(raw_ostream &o) {
64
50
  static const char *PlistHeader =
65
50
      "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
66
50
      "<!DOCTYPE plist PUBLIC \"-//Apple Computer//DTD PLIST 1.0//EN\" "
67
50
      "\"http://www.apple.com/DTDs/PropertyList-1.0.dtd\">\n"
68
50
      "<plist version=\"1.0\">\n";
69
50
  return o << PlistHeader;
70
50
}
71
72
47.9k
inline raw_ostream &EmitInteger(raw_ostream &o, int64_t value) {
73
47.9k
  o << "<integer>";
74
47.9k
  o << value;
75
47.9k
  o << "</integer>";
76
47.9k
  return o;
77
47.9k
}
78
79
7.99k
inline raw_ostream &EmitString(raw_ostream &o, StringRef s) {
80
7.99k
  o << "<string>";
81
336k
  for (StringRef::const_iterator I = s.begin(), E = s.end(); I != E; 
++I328k
) {
82
328k
    char c = *I;
83
328k
    switch (c) {
84
328k
    default:
85
321k
      o << c;
86
321k
      break;
87
328k
    case '&':
88
10
      o << "&amp;";
89
10
      break;
90
328k
    case '<':
91
347
      o << "&lt;";
92
347
      break;
93
328k
    case '>':
94
345
      o << "&gt;";
95
345
      break;
96
328k
    case '\'':
97
6.49k
      o << "&apos;";
98
6.49k
      break;
99
328k
    case '\"':
100
26
      o << "&quot;";
101
26
      break;
102
328k
    }
103
328k
  }
104
7.99k
  o << "</string>";
105
7.99k
  return o;
106
7.99k
}
107
108
inline void EmitLocation(raw_ostream &o, const SourceManager &SM,
109
14.2k
                         SourceLocation L, const FIDMap &FM, unsigned indent) {
110
14.2k
  if (L.isInvalid()) 
return0
;
111
14.2k
112
14.2k
  FullSourceLoc Loc(SM.getExpansionLoc(L), const_cast<SourceManager &>(SM));
113
14.2k
114
14.2k
  Indent(o, indent) << "<dict>\n";
115
14.2k
  Indent(o, indent) << " <key>line</key>";
116
14.2k
  EmitInteger(o, Loc.getExpansionLineNumber()) << '\n';
117
14.2k
  Indent(o, indent) << " <key>col</key>";
118
14.2k
  EmitInteger(o, Loc.getExpansionColumnNumber()) << '\n';
119
14.2k
  Indent(o, indent) << " <key>file</key>";
120
14.2k
  EmitInteger(o, GetFID(FM, SM, Loc)) << '\n';
121
14.2k
  Indent(o, indent) << "</dict>\n";
122
14.2k
}
123
124
inline void EmitRange(raw_ostream &o, const SourceManager &SM,
125
5.90k
                      CharSourceRange R, const FIDMap &FM, unsigned indent) {
126
5.90k
  if (R.isInvalid()) 
return0
;
127
5.90k
128
5.90k
  assert(R.isCharRange() && "cannot handle a token range");
129
5.90k
  Indent(o, indent) << "<array>\n";
130
5.90k
  EmitLocation(o, SM, R.getBegin(), FM, indent + 1);
131
5.90k
  EmitLocation(o, SM, R.getEnd(), FM, indent + 1);
132
5.90k
  Indent(o, indent) << "</array>\n";
133
5.90k
}
134
135
} // namespace markup
136
} // namespace clang
137
138
#endif // LLVM_CLANG_BASIC_PLISTSUPPORT_H