Coverage Report

Created: 2018-07-20 23:04

/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 void AddFID(FIDMap &FIDs, SmallVectorImpl<FileID> &V,
29
7.36k
                   const SourceManager &SM, SourceLocation L) {
30
7.36k
  FileID FID = SM.getFileID(SM.getExpansionLoc(L));
31
7.36k
  FIDMap::iterator I = FIDs.find(FID);
32
7.36k
  if (I != FIDs.end())
33
7.31k
    return;
34
48
  FIDs[FID] = V.size();
35
48
  V.push_back(FID);
36
48
}
37
38
inline unsigned GetFID(const FIDMap &FIDs, const SourceManager &SM,
39
13.9k
                       SourceLocation L) {
40
13.9k
  FileID FID = SM.getFileID(SM.getExpansionLoc(L));
41
13.9k
  FIDMap::const_iterator I = FIDs.find(FID);
42
13.9k
  assert(I != FIDs.end());
43
13.9k
  return I->second;
44
13.9k
}
45
46
123k
inline raw_ostream &Indent(raw_ostream &o, const unsigned indent) {
47
1.04M
  for (unsigned i = 0; i < indent; 
++i917k
)
48
917k
    o << ' ';
49
123k
  return o;
50
123k
}
51
52
46
inline raw_ostream &EmitPlistHeader(raw_ostream &o) {
53
46
  static const char *PlistHeader =
54
46
      "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
55
46
      "<!DOCTYPE plist PUBLIC \"-//Apple Computer//DTD PLIST 1.0//EN\" "
56
46
      "\"http://www.apple.com/DTDs/PropertyList-1.0.dtd\">\n"
57
46
      "<plist version=\"1.0\">\n";
58
46
  return o << PlistHeader;
59
46
}
60
61
43.8k
inline raw_ostream &EmitInteger(raw_ostream &o, int64_t value) {
62
43.8k
  o << "<integer>";
63
43.8k
  o << value;
64
43.8k
  o << "</integer>";
65
43.8k
  return o;
66
43.8k
}
67
68
7.67k
inline raw_ostream &EmitString(raw_ostream &o, StringRef s) {
69
7.67k
  o << "<string>";
70
330k
  for (StringRef::const_iterator I = s.begin(), E = s.end(); I != E; 
++I322k
) {
71
322k
    char c = *I;
72
322k
    switch (c) {
73
322k
    default:
74
316k
      o << c;
75
316k
      break;
76
322k
    case '&':
77
0
      o << "&amp;";
78
0
      break;
79
322k
    case '<':
80
345
      o << "&lt;";
81
345
      break;
82
322k
    case '>':
83
345
      o << "&gt;";
84
345
      break;
85
322k
    case '\'':
86
6.14k
      o << "&apos;";
87
6.14k
      break;
88
322k
    case '\"':
89
6
      o << "&quot;";
90
6
      break;
91
322k
    }
92
322k
  }
93
7.67k
  o << "</string>";
94
7.67k
  return o;
95
7.67k
}
96
97
inline void EmitLocation(raw_ostream &o, const SourceManager &SM,
98
13.9k
                         SourceLocation L, const FIDMap &FM, unsigned indent) {
99
13.9k
  if (L.isInvalid()) 
return0
;
100
13.9k
101
13.9k
  FullSourceLoc Loc(SM.getExpansionLoc(L), const_cast<SourceManager &>(SM));
102
13.9k
103
13.9k
  Indent(o, indent) << "<dict>\n";
104
13.9k
  Indent(o, indent) << " <key>line</key>";
105
13.9k
  EmitInteger(o, Loc.getExpansionLineNumber()) << '\n';
106
13.9k
  Indent(o, indent) << " <key>col</key>";
107
13.9k
  EmitInteger(o, Loc.getExpansionColumnNumber()) << '\n';
108
13.9k
  Indent(o, indent) << " <key>file</key>";
109
13.9k
  EmitInteger(o, GetFID(FM, SM, Loc)) << '\n';
110
13.9k
  Indent(o, indent) << "</dict>\n";
111
13.9k
}
112
113
inline void EmitRange(raw_ostream &o, const SourceManager &SM,
114
5.80k
                      CharSourceRange R, const FIDMap &FM, unsigned indent) {
115
5.80k
  if (R.isInvalid()) 
return0
;
116
5.80k
117
5.80k
  assert(R.isCharRange() && "cannot handle a token range");
118
5.80k
  Indent(o, indent) << "<array>\n";
119
5.80k
  EmitLocation(o, SM, R.getBegin(), FM, indent + 1);
120
5.80k
  EmitLocation(o, SM, R.getEnd(), FM, indent + 1);
121
5.80k
  Indent(o, indent) << "</array>\n";
122
5.80k
}
123
124
} // namespace markup
125
} // namespace clang
126
127
#endif // LLVM_CLANG_BASIC_PLISTSUPPORT_H