Coverage Report

Created: 2017-10-03 07:32

/Users/buildslave/jenkins/sharedspace/clang-stage2-coverage-R@2/llvm/tools/lld/ELF/Strings.h
Line
Count
Source (jump to first uncovered line)
1
//===- Strings.h ------------------------------------------------*- C++ -*-===//
2
//
3
//                             The LLVM Linker
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 LLD_ELF_STRINGS_H
11
#define LLD_ELF_STRINGS_H
12
13
#include "lld/Core/LLVM.h"
14
#include "llvm/ADT/ArrayRef.h"
15
#include "llvm/ADT/BitVector.h"
16
#include "llvm/ADT/Optional.h"
17
#include "llvm/ADT/StringRef.h"
18
#include "llvm/Support/GlobPattern.h"
19
#include <vector>
20
21
namespace lld {
22
namespace elf {
23
24
std::vector<uint8_t> parseHex(StringRef S);
25
bool isAlnum(char C);
26
bool isValidCIdentifier(StringRef S);
27
28
// This is a lazy version of StringRef. String size is computed lazily
29
// when it is needed. It is more efficient than StringRef to instantiate
30
// if you have a string whose size is unknown.
31
//
32
// ELF string tables contain a lot of null-terminated strings.
33
// Most of them are not necessary for the linker because they are names
34
// of local symbols and the linker doesn't use local symbol names for
35
// name resolution. So, we use this class to represents strings read
36
// from string tables.
37
class StringRefZ {
38
public:
39
0
  StringRefZ() : Start(nullptr), Size(0) {}
40
56
  StringRefZ(const char *S, size_t Size) : Start(S), Size(Size) {}
41
42
3.44k
  /*implicit*/ StringRefZ(const char *S) : Start(S), Size(-1) {}
43
44
  /*implicit*/ StringRefZ(llvm::StringRef S)
45
5.92k
      : Start(S.data()), Size(S.size()) {}
46
47
14.0k
  operator llvm::StringRef() const {
48
14.0k
    if (Size == (size_t)-1)
49
1.38k
      Size = strlen(Start);
50
14.0k
    return {Start, Size};
51
14.0k
  }
52
53
private:
54
  const char *Start;
55
  mutable size_t Size;
56
};
57
58
// This class represents multiple glob patterns.
59
class StringMatcher {
60
public:
61
494
  StringMatcher() = default;
62
  explicit StringMatcher(ArrayRef<StringRef> Pat);
63
64
  bool match(StringRef S) const;
65
66
private:
67
  std::vector<llvm::GlobPattern> Patterns;
68
};
69
70
// Returns a demangled C++ symbol name. If Name is not a mangled
71
// name, it returns Optional::None.
72
llvm::Optional<std::string> demangle(StringRef Name);
73
74
5
inline ArrayRef<uint8_t> toArrayRef(StringRef S) {
75
5
  return {(const uint8_t *)S.data(), S.size()};
76
5
}
77
} // namespace elf
78
} // namespace lld
79
80
#endif