mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-09-25 10:00:11 +01:00
The different approach to Names avoids the issues with trying to define a static member (or also member function) of the templated instance of Carbon::Internal::EnumBase from a non-enclosing namespace such as Carbon::SemIR. Note, I'm trying to do this from the cpp file. An alternative might be to do `inline constexpr llvm::StringLiteral Names[]` in the .h file, but I think concerns had been raised about that needing deduplication.
20 lines
724 B
C++
20 lines
724 B
C++
// Part of the Carbon Language project, under the Apache License v2.0 with LLVM
|
|
// Exceptions. See /LICENSE for license information.
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
|
|
|
#include "explorer/ast/ast_rtti.h"
|
|
|
|
namespace Carbon {
|
|
|
|
// Define kind names for the base enumeration type.
|
|
CARBON_DEFINE_ENUM_CLASS_NAMES(AstRttiNodeKind) = {
|
|
CARBON_AST_FOR_EACH_FINAL_CLASS(CARBON_ENUM_CLASS_NAME_STRING)};
|
|
|
|
// For other kind enumerations, reuse the same table.
|
|
#define DEFINE_NAME_FUNCTION(C) \
|
|
CARBON_ENUM_NAME_FUNCTION(C##Kind) { \
|
|
return AstRttiNodeKind(static_cast<const C##Kind&>(*this)).name(); \
|
|
}
|
|
|
|
} // namespace Carbon
|