Replace RTTI generation script with macros. (#2703)

This keeps all of our C++ code written in C++ source files, and avoids the increasing size of the RTTI generation script we'd started to see in #2699.

Co-authored-by: Chandler Carruth <chandlerc@gmail.com>
This commit is contained in:
Richard Smith
2023-03-30 14:16:44 -07:00
committed by GitHub
co-authored by Chandler Carruth
parent 8990ccd05a
commit 807ef98758
13 changed files with 359 additions and 490 deletions
+20
View File
@@ -0,0 +1,20 @@
// 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(); \
}
CARBON_AST_FOR_EACH_ABSTRACT_CLASS(DEFINE_NAME_FUNCTION)
} // namespace Carbon