1//===--- Reflect.h - Reflection type for the constexpr VM -------*- 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#ifndef LLVM_CLANG_AST_INTERP_REFLECT_H
10#define LLVM_CLANG_AST_INTERP_REFLECT_H
11
12#include "clang/AST/APValue.h"
13#include "clang/AST/ComparisonCategories.h"
14#include "clang/AST/Reflection.h"
15#include "llvm/ADT/APSInt.h"
16#include "llvm/Support/MathExtras.h"
17#include "llvm/Support/raw_ostream.h"
18#include <cstddef>
19#include <cstdint>
20
21namespace clang {
22namespace interp {
23
24class Reflect final {
25private:
26 ReflectionKind Kind;
27 const void *Operand;
28
29public:
30 Reflect() : Kind(ReflectionKind::Null), Operand(nullptr) {}
31 Reflect(ReflectionKind Kind, const void *Operand)
32 : Kind(Kind), Operand(Operand) {}
33
34 ComparisonCategoryResult compare(const Reflect &RHS) const {
35 llvm::FoldingSetNodeID LID, RID;
36 APValue(Kind, Operand).Profile(ID&: LID);
37 APValue(RHS.Kind, RHS.Operand).Profile(ID&: RID);
38
39 if (LID == RID)
40 return ComparisonCategoryResult::Equal;
41 return ComparisonCategoryResult::Unordered;
42 }
43
44 void print(llvm::raw_ostream &OS) const {
45 OS << "Reflect(" << Kind << ", " << Operand << ")";
46 }
47 APValue toAPValue(const ASTContext &Ctx) const {
48 return APValue(Kind, Operand);
49 }
50};
51
52inline llvm::raw_ostream &operator<<(llvm::raw_ostream &OS, const Reflect &R) {
53 R.print(OS);
54 return OS;
55}
56
57} // namespace interp
58} // namespace clang
59
60#endif
61