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 ReflectionKind getKind() const { return Kind; }
35
36 ComparisonCategoryResult compare(const Reflect &RHS) const {
37 llvm::FoldingSetNodeID LID, RID;
38 APValue(Kind, Operand).Profile(ID&: LID);
39 APValue(RHS.Kind, RHS.Operand).Profile(ID&: RID);
40
41 if (LID == RID)
42 return ComparisonCategoryResult::Equal;
43 return ComparisonCategoryResult::Unordered;
44 }
45
46 void print(llvm::raw_ostream &OS) const {
47 OS << "Reflect(" << Kind << ", " << Operand << ")";
48 }
49 APValue toAPValue(const ASTContext &Ctx) const {
50 return APValue(Kind, Operand);
51 }
52};
53
54inline llvm::raw_ostream &operator<<(llvm::raw_ostream &OS, const Reflect &R) {
55 R.print(OS);
56 return OS;
57}
58
59} // namespace interp
60} // namespace clang
61
62#endif
63