Coverage Report

Created: 2018-07-22 10:17

/Users/buildslave/jenkins/workspace/clang-stage2-coverage-R/llvm/tools/clang/include/clang/AST/TypeOrdering.h
Line
Count
Source
1
//===-------------- TypeOrdering.h - Total ordering for types -------------===//
2
//
3
//                     The LLVM Compiler Infrastructure
4
//
5
// This file is distributed under the University of Illinois Open Source
6
// License. See LICENSE.TXT for details.
7
//
8
//===----------------------------------------------------------------------===//
9
///
10
/// \file
11
/// Allows QualTypes to be sorted and hence used in maps and sets.
12
///
13
/// Defines clang::QualTypeOrdering, a total ordering on clang::QualType,
14
/// and hence enables QualType values to be sorted and to be used in
15
/// std::maps, std::sets, llvm::DenseMaps, and llvm::DenseSets.
16
///
17
//===----------------------------------------------------------------------===//
18
19
#ifndef LLVM_CLANG_AST_TYPEORDERING_H
20
#define LLVM_CLANG_AST_TYPEORDERING_H
21
22
#include "clang/AST/CanonicalType.h"
23
#include "clang/AST/Type.h"
24
#include <functional>
25
26
namespace clang {
27
28
/// Function object that provides a total ordering on QualType values.
29
struct QualTypeOrdering {
30
31.9k
  bool operator()(QualType T1, QualType T2) const {
31
31.9k
    return std::less<void*>()(T1.getAsOpaquePtr(), T2.getAsOpaquePtr());
32
31.9k
  }
33
};
34
35
}
36
37
namespace llvm {
38
  template<class> struct DenseMapInfo;
39
40
  template<> struct DenseMapInfo<clang::QualType> {
41
65.3M
    static inline clang::QualType getEmptyKey() { return clang::QualType(); }
42
43
34.3M
    static inline clang::QualType getTombstoneKey() {
44
34.3M
      using clang::QualType;
45
34.3M
      return QualType::getFromOpaquePtr(reinterpret_cast<clang::Type *>(-1));
46
34.3M
    }
47
48
10.6M
    static unsigned getHashValue(clang::QualType Val) {
49
10.6M
      return (unsigned)((uintptr_t)Val.getAsOpaquePtr()) ^
50
10.6M
            ((unsigned)((uintptr_t)Val.getAsOpaquePtr() >> 9));
51
10.6M
    }
52
53
310M
    static bool isEqual(clang::QualType LHS, clang::QualType RHS) {
54
310M
      return LHS == RHS;
55
310M
    }
56
  };
57
58
  template<> struct DenseMapInfo<clang::CanQualType> {
59
993
    static inline clang::CanQualType getEmptyKey() { 
60
993
      return clang::CanQualType(); 
61
993
    }
62
    
63
577
    static inline clang::CanQualType getTombstoneKey() {
64
577
      using clang::CanQualType;
65
577
      return CanQualType::getFromOpaquePtr(reinterpret_cast<clang::Type *>(-1));
66
577
    }
67
    
68
482
    static unsigned getHashValue(clang::CanQualType Val) {
69
482
      return (unsigned)((uintptr_t)Val.getAsOpaquePtr()) ^
70
482
      ((unsigned)((uintptr_t)Val.getAsOpaquePtr() >> 9));
71
482
    }
72
    
73
7.60k
    static bool isEqual(clang::CanQualType LHS, clang::CanQualType RHS) {
74
7.60k
      return LHS == RHS;
75
7.60k
    }
76
  };
77
}
78
79
#endif