Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-05-10 08:36:46

0001 //===-------------- TypeOrdering.h - Total ordering for types ---*- C++ -*-===//
0002 //
0003 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
0004 // See https://llvm.org/LICENSE.txt for license information.
0005 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
0006 //
0007 //===----------------------------------------------------------------------===//
0008 ///
0009 /// \file
0010 /// Allows QualTypes to be sorted and hence used in maps and sets.
0011 ///
0012 /// Defines clang::QualTypeOrdering, a total ordering on clang::QualType,
0013 /// and hence enables QualType values to be sorted and to be used in
0014 /// std::maps, std::sets, llvm::DenseMaps, and llvm::DenseSets.
0015 ///
0016 //===----------------------------------------------------------------------===//
0017 
0018 #ifndef LLVM_CLANG_AST_TYPEORDERING_H
0019 #define LLVM_CLANG_AST_TYPEORDERING_H
0020 
0021 #include "clang/AST/CanonicalType.h"
0022 #include "clang/AST/Type.h"
0023 #include <functional>
0024 
0025 namespace clang {
0026 
0027 /// Function object that provides a total ordering on QualType values.
0028 struct QualTypeOrdering {
0029   bool operator()(QualType T1, QualType T2) const {
0030     return std::less<void*>()(T1.getAsOpaquePtr(), T2.getAsOpaquePtr());
0031   }
0032 };
0033 
0034 }
0035 
0036 namespace llvm {
0037 
0038   template<> struct DenseMapInfo<clang::QualType> {
0039     static inline clang::QualType getEmptyKey() { return clang::QualType(); }
0040 
0041     static inline clang::QualType getTombstoneKey() {
0042       using clang::QualType;
0043       return QualType::getFromOpaquePtr(reinterpret_cast<clang::Type *>(-1));
0044     }
0045 
0046     static unsigned getHashValue(clang::QualType Val) {
0047       return (unsigned)((uintptr_t)Val.getAsOpaquePtr()) ^
0048             ((unsigned)((uintptr_t)Val.getAsOpaquePtr() >> 9));
0049     }
0050 
0051     static bool isEqual(clang::QualType LHS, clang::QualType RHS) {
0052       return LHS == RHS;
0053     }
0054   };
0055 
0056   template<> struct DenseMapInfo<clang::CanQualType> {
0057     static inline clang::CanQualType getEmptyKey() {
0058       return clang::CanQualType();
0059     }
0060 
0061     static inline clang::CanQualType getTombstoneKey() {
0062       using clang::CanQualType;
0063       return CanQualType::getFromOpaquePtr(reinterpret_cast<clang::Type *>(-1));
0064     }
0065 
0066     static unsigned getHashValue(clang::CanQualType Val) {
0067       return (unsigned)((uintptr_t)Val.getAsOpaquePtr()) ^
0068       ((unsigned)((uintptr_t)Val.getAsOpaquePtr() >> 9));
0069     }
0070 
0071     static bool isEqual(clang::CanQualType LHS, clang::CanQualType RHS) {
0072       return LHS == RHS;
0073     }
0074   };
0075 }
0076 
0077 #endif