Coverage Report

Created: 2018-02-28 10:36

/Users/buildslave/jenkins/workspace/clang-stage2-coverage-R/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/Common/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 isValidCIdentifier(StringRef S);
26
27
// This is a lazy version of StringRef. String size is computed lazily
28
// when it is needed. It is more efficient than StringRef to instantiate
29
// if you have a string whose size is unknown.
30
//
31
// ELF string tables contain a lot of null-terminated strings.
32
// Most of them are not necessary for the linker because they are names
33
// of local symbols and the linker doesn't use local symbol names for
34
// name resolution. So, we use this class to represents strings read
35
// from string tables.
36
class StringRefZ {
37
public:
38
0
  StringRefZ() : Start(nullptr), Size(0) {}
39
68
  StringRefZ(const char *S, size_t Size) : Start(S), Size(Size) {}
40
41
4.49k
  /*implicit*/ StringRefZ(const char *S) : Start(S), Size(-1) {}
42
43
  /*implicit*/ StringRefZ(llvm::StringRef S)
44
18.0k
      : Start(S.data()), Size(S.size()) {}
45
46
40.5k
  operator llvm::StringRef() const {
47
40.5k
    if (Size == (size_t)-1)
48
2.08k
      Size = strlen(Start);
49
40.5k
    return {Start, Size};
50
40.5k
  }
51
52
private:
53
  const char *Start;
54
  mutable size_t Size;
55
};
56
57
// This class represents multiple glob patterns.
58
class StringMatcher {
59
public:
60
651
  StringMatcher() = default;
61
  explicit StringMatcher(ArrayRef<StringRef> Pat);
62
63
  bool match(StringRef S) const;
64
65
private:
66
  std::vector<llvm::GlobPattern> Patterns;
67
};
68
69
5
inline ArrayRef<uint8_t> toArrayRef(StringRef S) {
70
5
  return {(const uint8_t *)S.data(), S.size()};
71
5
}
72
} // namespace elf
73
} // namespace lld
74
75
#endif