Coverage Report

Created: 2020-02-15 09:57

/Users/buildslave/jenkins/workspace/coverage/llvm-project/clang/include/clang/AST/TypeOrdering.h
Line
Count
Source
1
//===-------------- TypeOrdering.h - Total ordering for types ---*- 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
/// \file
10
/// Allows QualTypes to be sorted and hence used in maps and sets.
11
///
12
/// Defines clang::QualTypeOrdering, a total ordering on clang::QualType,
13
/// and hence enables QualType values to be sorted and to be used in
14
/// std::maps, std::sets, llvm::DenseMaps, and llvm::DenseSets.
15
///
16
//===----------------------------------------------------------------------===//
17
18
#ifndef LLVM_CLANG_AST_TYPEORDERING_H
19
#define LLVM_CLANG_AST_TYPEORDERING_H
20
21
#include "clang/AST/CanonicalType.h"
22
#include "clang/AST/Type.h"
23
#include <functional>
24
25
namespace clang {
26
27
/// Function object that provides a total ordering on QualType values.
28
struct QualTypeOrdering {
29
29.3k
  bool operator()(QualType T1, QualType T2) const {
30
29.3k
    return std::less<void*>()(T1.getAsOpaquePtr(), T2.getAsOpaquePtr());
31
29.3k
  }
32
};
33
34
}
35
36
namespace llvm {
37
  template<class> struct DenseMapInfo;
38
39
  template<> struct DenseMapInfo<clang::QualType> {
40
60.0M
    static inline clang::QualType getEmptyKey() { return clang::QualType(); }
41
42
33.3M
    static inline clang::QualType getTombstoneKey() {
43
33.3M
      using clang::QualType;
44
33.3M
      return QualType::getFromOpaquePtr(reinterpret_cast<clang::Type *>(-1));
45
33.3M
    }
46
47
14.3M
    static unsigned getHashValue(clang::QualType Val) {
48
14.3M
      return (unsigned)((uintptr_t)Val.getAsOpaquePtr()) ^
49
14.3M
            ((unsigned)((uintptr_t)Val.getAsOpaquePtr() >> 9));
50
14.3M
    }
51
52
329M
    static bool isEqual(clang::QualType LHS, clang::QualType RHS) {
53
329M
      return LHS == RHS;
54
329M
    }
55
  };
56
57
  template<> struct DenseMapInfo<clang::CanQualType> {
58
1.08k
    static inline clang::CanQualType getEmptyKey() {
59
1.08k
      return clang::CanQualType();
60
1.08k
    }
61
62
637
    static inline clang::CanQualType getTombstoneKey() {
63
637
      using clang::CanQualType;
64
637
      return CanQualType::getFromOpaquePtr(reinterpret_cast<clang::Type *>(-1));
65
637
    }
66
67
529
    static unsigned getHashValue(clang::CanQualType Val) {
68
529
      return (unsigned)((uintptr_t)Val.getAsOpaquePtr()) ^
69
529
      ((unsigned)((uintptr_t)Val.getAsOpaquePtr() >> 9));
70
529
    }
71
72
9.45k
    static bool isEqual(clang::CanQualType LHS, clang::CanQualType RHS) {
73
9.45k
      return LHS == RHS;
74
9.45k
    }
75
  };
76
}
77
78
#endif