Coverage Report

Created: 2018-09-25 23:22

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