llvm/clang/utils/TableGen/ASTTableGen.h

//=== ASTTableGen.h - Common definitions for AST node tablegen --*- C++ -*-===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//

#ifndef CLANG_AST_TABLEGEN_H
#define CLANG_AST_TABLEGEN_H

#include "llvm/TableGen/Record.h"
#include "llvm/ADT/STLExtras.h"
#include <optional>

// These are spellings in the tblgen files.

#define HasPropertiesClassName

// ASTNodes and their common fields.  `Base` is actually defined
// in subclasses, but it's still common across the hierarchies.
#define ASTNodeClassName
#define BaseFieldName
#define AbstractFieldName

// Comment node hierarchy.
#define CommentNodeClassName

// Decl node hierarchy.
#define DeclNodeClassName
#define DeclContextNodeClassName

// Stmt node hierarchy.
#define StmtNodeClassName

// Type node hierarchy.
#define TypeNodeClassName
#define AlwaysDependentClassName
#define NeverCanonicalClassName
#define NeverCanonicalUnlessDependentClassName
#define LeafTypeClassName

// Cases of various non-ASTNode structured types like DeclarationName.
#define TypeKindClassName
#define KindTypeFieldName
#define KindPropertyNameFieldName
#define TypeCaseClassName

// Properties of AST nodes.
#define PropertyClassName
#define ClassFieldName
#define NameFieldName
#define TypeFieldName
#define ReadFieldName

// Types of properties.
#define PropertyTypeClassName
#define CXXTypeNameFieldName
#define PassByReferenceFieldName
#define ConstWhenWritingFieldName
#define ConditionalCodeFieldName
#define PackOptionalCodeFieldName
#define UnpackOptionalCodeFieldName
#define BufferElementTypesFieldName
#define ArrayTypeClassName
#define ArrayElementTypeFieldName
#define OptionalTypeClassName
#define OptionalElementTypeFieldName
#define SubclassPropertyTypeClassName
#define SubclassBaseTypeFieldName
#define SubclassClassNameFieldName
#define EnumPropertyTypeClassName

// Write helper rules.
#define ReadHelperRuleClassName
#define HelperCodeFieldName

// Creation rules.
#define CreationRuleClassName
#define CreateFieldName

// Override rules.
#define OverrideRuleClassName
#define IgnoredPropertiesFieldName

namespace clang {
namespace tblgen {

class WrappedRecord {};

/// Anything in the AST that has properties.
class HasProperties : public WrappedRecord {};

/// An (optional) reference to a TableGen node representing a class
/// in one of Clang's AST hierarchies.
class ASTNode : public HasProperties {};

class DeclNode : public ASTNode {};

class TypeNode : public ASTNode {};

class StmtNode : public ASTNode {};

/// The type of a property.
class PropertyType : public WrappedRecord {};

/// A rule for returning the kind of a type.
class TypeKindRule : public WrappedRecord {};

/// An implementation case of a property type.
class TypeCase : public HasProperties {};

/// A property of an AST node.
class Property : public WrappedRecord {};

/// A rule for running some helper code for reading properties from
/// a value (which is actually done when writing the value out).
class ReadHelperRule : public WrappedRecord {};

/// A rule for how to create an AST node from its properties.
class CreationRule : public WrappedRecord {};

/// A rule which overrides the standard rules for serializing an AST node.
class OverrideRule : public WrappedRecord {};

/// A visitor for an AST node hierarchy.  Note that `base` can be null for
/// the root class.
ASTNodeHierarchyVisitor;

void visitASTNodeHierarchyImpl(const llvm::RecordKeeper &records,
                               llvm::StringRef nodeClassName,
                               ASTNodeHierarchyVisitor<ASTNode> visit);

template <class NodeClass>
void visitASTNodeHierarchy(const llvm::RecordKeeper &records,
                           ASTNodeHierarchyVisitor<NodeClass> visit) {}

} // end namespace clang::tblgen
} // end namespace clang

#endif