Coverage Report

Created: 2019-07-24 05:18

/Users/buildslave/jenkins/workspace/clang-stage2-coverage-R/llvm/include/llvm/Support/SMLoc.h
Line
Count
Source
1
//===- SMLoc.h - Source location for use with diagnostics -------*- C++ -*-===//
2
//
3
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4
// See https://llvm.org/LICENSE.txt for license information.
5
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6
//
7
//===----------------------------------------------------------------------===//
8
//
9
// This file declares the SMLoc class.  This class encapsulates a location in
10
// source code for use in diagnostics.
11
//
12
//===----------------------------------------------------------------------===//
13
14
#ifndef LLVM_SUPPORT_SMLOC_H
15
#define LLVM_SUPPORT_SMLOC_H
16
17
#include "llvm/ADT/None.h"
18
#include <cassert>
19
20
namespace llvm {
21
22
/// Represents a location in source code.
23
class SMLoc {
24
  const char *Ptr = nullptr;
25
26
public:
27
162M
  SMLoc() = default;
28
29
286k
  bool isValid() const { return Ptr != nullptr; }
30
31
43.7k
  bool operator==(const SMLoc &RHS) const { return RHS.Ptr == Ptr; }
32
1.76M
  bool operator!=(const SMLoc &RHS) const { return RHS.Ptr != Ptr; }
33
34
3.20M
  const char *getPointer() const { return Ptr; }
35
36
80.0M
  static SMLoc getFromPointer(const char *Ptr) {
37
80.0M
    SMLoc L;
38
80.0M
    L.Ptr = Ptr;
39
80.0M
    return L;
40
80.0M
  }
41
};
42
43
/// Represents a range in source code.
44
///
45
/// SMRange is implemented using a half-open range, as is the convention in C++.
46
/// In the string "abc", the range [1,3) represents the substring "bc", and the
47
/// range [2,2) represents an empty range between the characters "b" and "c".
48
class SMRange {
49
public:
50
  SMLoc Start, End;
51
52
5.49M
  SMRange() = default;
53
161k
  SMRange(NoneType) {}
54
2.12M
  SMRange(SMLoc St, SMLoc En) : Start(St), End(En) {
55
2.12M
    assert(Start.isValid() == End.isValid() &&
56
2.12M
           "Start and End should either both be valid or both be invalid!");
57
2.12M
  }
58
59
87.1k
  bool isValid() const { return Start.isValid(); }
60
};
61
62
} // end namespace llvm
63
64
#endif // LLVM_SUPPORT_SMLOC_H