| 1 | //===--- Reflection.h - Kind of reflection operands ---*- 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 | // This file declares the kinds of reflection operands. |
| 10 | // |
| 11 | //===----------------------------------------------------------------------===// |
| 12 | |
| 13 | #ifndef LLVM_CLANG_AST_REFLECTION_H |
| 14 | #define LLVM_CLANG_AST_REFLECTION_H |
| 15 | |
| 16 | #include "clang/AST/TypeBase.h" |
| 17 | #include "llvm/Support/raw_ostream.h" |
| 18 | |
| 19 | namespace clang { |
| 20 | |
| 21 | // TODO(Reflection): Add support for Template, Namespace and DeclRefExpr. |
| 22 | enum class ReflectionKind { Null, Type }; |
| 23 | |
| 24 | inline llvm::raw_ostream &operator<<(llvm::raw_ostream &OS, |
| 25 | ReflectionKind Kind) { |
| 26 | switch (Kind) { |
| 27 | case ReflectionKind::Type: |
| 28 | OS << "type" ; |
| 29 | break; |
| 30 | case ReflectionKind::Null: |
| 31 | OS << "null" ; |
| 32 | break; |
| 33 | } |
| 34 | |
| 35 | return OS; |
| 36 | } |
| 37 | |
| 38 | /// [expr.reflect] p5, if a reflect-expression R matches the form |
| 39 | /// ^^reflection-name it is interpreted as such; the identifier is looked up |
| 40 | /// and the representation of R is determined as follows: |
| 41 | /// - if lookup finds a type alias A, R represents the type the underlying |
| 42 | /// entity of A if A was introduced by the declaration of a template |
| 43 | /// parameter; otherwise, R represents A. |
| 44 | |
| 45 | /// [expr.reflect] p6, Given reflect-expression R of the form ^^type-id, |
| 46 | /// if type-id is neither a placeholder type nor |
| 47 | /// in the form of nested-name-specifier_opt template_opt simple-template-id |
| 48 | /// then R represents the type denoted by the type-id |
| 49 | |
| 50 | // In particular, this means that e.g. '^^const Alias' is reflection of |
| 51 | // a type, not an alias. For example: |
| 52 | // |
| 53 | // using foo = const int; |
| 54 | // ^^int // Type |
| 55 | // ^^const int // Type |
| 56 | // ^^foo // Alias |
| 57 | // ^^const foo // Type |
| 58 | inline bool isTypeAliasAsReflectionName(QualType QT) { |
| 59 | return QT.getLocalQualifiers() == Qualifiers{}; |
| 60 | } |
| 61 | |
| 62 | } // namespace clang |
| 63 | |
| 64 | #endif |
| 65 | |