Coverage Report

Created: 2022-01-25 06:29

/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
28.9k
  bool operator()(QualType T1, QualType T2) const {
30
28.9k
    return std::less<void*>()(T1.getAsOpaquePtr(), T2.getAsOpaquePtr());
31
28.9k
  }
32
};
33
34
}
35
36
namespace llvm {
37
38
  template<> struct DenseMapInfo<clang::QualType> {
39
227M
    static inline clang::QualType getEmptyKey() { return clang::QualType(); }
40
41
131M
    static inline clang::QualType getTombstoneKey() {
42
131M
      using clang::QualType;
43
131M
      return QualType::getFromOpaquePtr(reinterpret_cast<clang::Type *>(-1));
44
131M
    }
45
46
72.0M
    static unsigned getHashValue(clang::QualType Val) {
47
72.0M
      return (unsigned)((uintptr_t)Val.getAsOpaquePtr()) ^
48
72.0M
            ((unsigned)((uintptr_t)Val.getAsOpaquePtr() >> 9));
49
72.0M
    }
50
51
1.23G
    static bool isEqual(clang::QualType LHS, clang::QualType RHS) {
52
1.23G
      return LHS == RHS;
53
1.23G
    }
54
  };
55
56
  template<> struct DenseMapInfo<clang::CanQualType> {
57
1.14k
    static inline clang::CanQualType getEmptyKey() {
58
1.14k
      return clang::CanQualType();
59
1.14k
    }
60
61
670
    static inline clang::CanQualType getTombstoneKey() {
62
670
      using clang::CanQualType;
63
670
      return CanQualType::getFromOpaquePtr(reinterpret_cast<clang::Type *>(-1));
64
670
    }
65
66
555
    static unsigned getHashValue(clang::CanQualType Val) {
67
555
      return (unsigned)((uintptr_t)Val.getAsOpaquePtr()) ^
68
555
      ((unsigned)((uintptr_t)Val.getAsOpaquePtr() >> 9));
69
555
    }
70
71
10.0k
    static bool isEqual(clang::CanQualType LHS, clang::CanQualType RHS) {
72
10.0k
      return LHS == RHS;
73
10.0k
    }
74
  };
75
}
76
77
#endif