MLIR  20.0.0git
Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
mlir::tblgen::Class Class Reference

A class used to emit C++ classes from Tablegen. More...

#include "mlir/TableGen/Class.h"

Public Member Functions

virtual ~Class ()=default
 
 Class (const Class &)=delete
 Explicitly delete the copy constructor. More...
 
template<typename NameT , typename = std::enable_if_t<!std::is_same<NameT, Class>::value>>
 Class (NameT &&name, bool isStruct=false)
 Create a class with a name, and whether it should be declared as a class or struct. More...
 
template<Method::Properties Properties = Method::None, typename... Args>
ConstructoraddConstructor (Args &&...args)
 Add a new constructor to this class and prune and constructors made redundant by it. More...
 
template<Method::Properties Properties = Method::None, typename RetTypeT , typename NameT >
MethodaddMethod (RetTypeT &&retType, NameT &&name, Method::Properties properties, ArrayRef< MethodParameter > parameters)
 Add a new method to this class and prune any methods made redundant by it. More...
 
template<Method::Properties Properties = Method::None, typename RetTypeT , typename NameT >
MethodaddMethod (RetTypeT &&retType, NameT &&name, ArrayRef< MethodParameter > parameters)
 Add a method with statically-known properties. More...
 
template<Method::Properties Properties = Method::None, typename RetTypeT , typename NameT , typename... Args>
MethodaddMethod (RetTypeT &&retType, NameT &&name, Method::Properties properties, Args &&...args)
 
template<Method::Properties Properties = Method::None, typename RetTypeT , typename NameT , typename... Args>
MethodaddMethod (RetTypeT &&retType, NameT &&name, Args &&...args)
 Add a method with statically-known properties. More...
 
template<Method::Properties Properties = Method::None, typename RetTypeT , typename NameT , typename... Args>
MethodaddStaticMethod (RetTypeT &&retType, NameT &&name, Args &&...args)
 Add a static method. More...
 
template<Method::Properties Properties = Method::None, typename RetTypeT , typename NameT , typename... Args>
MethodaddStaticInlineMethod (RetTypeT &&retType, NameT &&name, Args &&...args)
 Add an inline static method. More...
 
template<Method::Properties Properties = Method::None, typename RetTypeT , typename NameT , typename... Args>
MethodaddInlineMethod (RetTypeT &&retType, NameT &&name, Args &&...args)
 Add an inline method. More...
 
template<Method::Properties Properties = Method::None, typename RetTypeT , typename NameT , typename... Args>
MethodaddConstMethod (RetTypeT &&retType, NameT &&name, Args &&...args)
 Add a const method. More...
 
template<Method::Properties Properties = Method::None, typename RetTypeT , typename NameT , typename... Args>
MethoddeclareMethod (RetTypeT &&retType, NameT &&name, Args &&...args)
 Add a declaration for a method. More...
 
template<Method::Properties Properties = Method::None, typename RetTypeT , typename NameT , typename... Args>
MethoddeclareStaticMethod (RetTypeT &&retType, NameT &&name, Args &&...args)
 Add a declaration for a static method. More...
 
template<typename TypeT , typename NameT >
void addField (TypeT &&type, NameT &&name)
 Add a new field to the class. More...
 
ParentClassaddParent (ParentClass parent)
 Add a parent class. More...
 
template<typename ParamT >
void addTemplateParam (ParamT param)
 Add a template parameter. More...
 
template<typename ContainerT >
void addTemplateParams (ContainerT &&container)
 Add a list of template parameters. More...
 
StringRef getClassName () const
 Return the C++ name of the class. More...
 
void writeDeclTo (raw_ostream &rawOs) const
 Write the declaration of this class, all declarations, and definitions of inline functions. More...
 
void writeDefTo (raw_ostream &rawOs) const
 Write the definitions of thiss class's out-of-line constructors and methods. More...
 
void writeDeclTo (raw_indented_ostream &os) const
 Write the declaration of this class, all declarations, and definitions of inline functions. More...
 
void writeDefTo (raw_indented_ostream &os) const
 Write the definitions of thiss class's out-of-line constructors and methods. More...
 
template<typename DeclT , typename... Args>
DeclT * declare (Args &&...args)
 Add a declaration. More...
 
virtual void finalize ()
 The declaration of a class needs to be "finalized". More...
 

Protected Member Functions

ConstructoraddConstructorAndPrune (Constructor &&newCtor)
 Add a new constructor if it is not made redundant by any existing constructors and prune and existing constructors made redundant. More...
 
MethodaddMethodAndPrune (Method &&newMethod)
 Add a new method if it is not made redundant by any existing methods and prune and existing methods made redundant. More...
 
Visibility getLastVisibilityDecl () const
 Get the last visibility declaration. More...
 

Protected Attributes

std::string className
 The C++ class name. More...
 
SmallVector< ParentClassparents
 The list of parent classes. More...
 
std::vector< std::unique_ptr< Method > > methods
 The pending list of methods and constructors. More...
 
SmallVector< Fieldfields
 The pending list of private class fields. More...
 
bool isStruct
 Whether this is a class or a struct. More...
 
std::vector< std::unique_ptr< ClassDeclaration > > declarations
 A list of declarations in the class, emitted in order. More...
 
SetVector< std::string, SmallVector< std::string >, StringSet<> > templateParams
 An optional list of class template parameters. More...
 

Detailed Description

A class used to emit C++ classes from Tablegen.

Contains a list of public methods and a list of private fields to be emitted.

Definition at line 646 of file Class.h.

Constructor & Destructor Documentation

◆ ~Class()

virtual mlir::tblgen::Class::~Class ( )
virtualdefault

◆ Class() [1/2]

mlir::tblgen::Class::Class ( const Class )
delete

Explicitly delete the copy constructor.

This is to work around a gcc-5 bug with std::is_trivially_move_constructible.

◆ Class() [2/2]

template<typename NameT , typename = std::enable_if_t<!std::is_same<NameT, Class>::value>>
mlir::tblgen::Class::Class ( NameT &&  name,
bool  isStruct = false 
)
inline

Create a class with a name, and whether it should be declared as a class or struct.

Also, prevent this from being mistaken as a move constructor candidate.

Definition at line 659 of file Class.h.

Member Function Documentation

◆ addConstMethod()

template<Method::Properties Properties = Method::None, typename RetTypeT , typename NameT , typename... Args>
Method* mlir::tblgen::Class::addConstMethod ( RetTypeT &&  retType,
NameT &&  name,
Args &&...  args 
)
inline

Add a const method.

Definition at line 749 of file Class.h.

◆ addConstructor()

template<Method::Properties Properties = Method::None, typename... Args>
Constructor* mlir::tblgen::Class::addConstructor ( Args &&...  args)
inline

Add a new constructor to this class and prune and constructors made redundant by it.

Returns null if the constructor was not added. Else, returns a pointer to the new constructor.

Definition at line 666 of file Class.h.

References addConstructorAndPrune(), mlir::tblgen::Method::Constructor, getClassName(), mlir::tblgen::Method::Inline, and templateParams.

◆ addConstructorAndPrune()

Constructor* mlir::tblgen::Class::addConstructorAndPrune ( Constructor &&  newCtor)
protected

Add a new constructor if it is not made redundant by any existing constructors and prune and existing constructors made redundant.

Referenced by addConstructor().

◆ addField()

template<typename TypeT , typename NameT >
void mlir::tblgen::Class::addField ( TypeT &&  type,
NameT &&  name 
)
inline

Add a new field to the class.

Class fields added this way are always private.

Definition at line 777 of file Class.h.

References fields.

◆ addInlineMethod()

template<Method::Properties Properties = Method::None, typename RetTypeT , typename NameT , typename... Args>
Method* mlir::tblgen::Class::addInlineMethod ( RetTypeT &&  retType,
NameT &&  name,
Args &&...  args 
)
inline

Add an inline method.

Definition at line 740 of file Class.h.

◆ addMethod() [1/4]

template<Method::Properties Properties = Method::None, typename RetTypeT , typename NameT , typename... Args>
Method* mlir::tblgen::Class::addMethod ( RetTypeT &&  retType,
NameT &&  name,
Args &&...  args 
)
inline

Add a method with statically-known properties.

Definition at line 713 of file Class.h.

References addMethod().

◆ addMethod() [2/4]

template<Method::Properties Properties = Method::None, typename RetTypeT , typename NameT >
Method* mlir::tblgen::Class::addMethod ( RetTypeT &&  retType,
NameT &&  name,
ArrayRef< MethodParameter parameters 
)
inline

Add a method with statically-known properties.

Definition at line 696 of file Class.h.

References addMethod().

◆ addMethod() [3/4]

template<Method::Properties Properties = Method::None, typename RetTypeT , typename NameT , typename... Args>
Method* mlir::tblgen::Class::addMethod ( RetTypeT &&  retType,
NameT &&  name,
Method::Properties  properties,
Args &&...  args 
)
inline

Definition at line 704 of file Class.h.

References addMethod().

◆ addMethod() [4/4]

template<Method::Properties Properties = Method::None, typename RetTypeT , typename NameT >
Method* mlir::tblgen::Class::addMethod ( RetTypeT &&  retType,
NameT &&  name,
Method::Properties  properties,
ArrayRef< MethodParameter parameters 
)
inline

Add a new method to this class and prune any methods made redundant by it.

Returns null if the method was not added (because an existing method would make it redundant). Else, returns a pointer to the new method.

Definition at line 682 of file Class.h.

References addMethodAndPrune(), mlir::tblgen::Method::Inline, and templateParams.

Referenced by addMethod().

◆ addMethodAndPrune()

Method* mlir::tblgen::Class::addMethodAndPrune ( Method &&  newMethod)
protected

Add a new method if it is not made redundant by any existing methods and prune and existing methods made redundant.

Referenced by addMethod().

◆ addParent()

ParentClass& mlir::tblgen::Class::addParent ( ParentClass  parent)

Add a parent class.

◆ addStaticInlineMethod()

template<Method::Properties Properties = Method::None, typename RetTypeT , typename NameT , typename... Args>
Method* mlir::tblgen::Class::addStaticInlineMethod ( RetTypeT &&  retType,
NameT &&  name,
Args &&...  args 
)
inline

Add an inline static method.

Definition at line 730 of file Class.h.

◆ addStaticMethod()

template<Method::Properties Properties = Method::None, typename RetTypeT , typename NameT , typename... Args>
Method* mlir::tblgen::Class::addStaticMethod ( RetTypeT &&  retType,
NameT &&  name,
Args &&...  args 
)
inline

Add a static method.

Definition at line 721 of file Class.h.

◆ addTemplateParam()

template<typename ParamT >
void mlir::tblgen::Class::addTemplateParam ( ParamT  param)
inline

Add a template parameter.

Definition at line 786 of file Class.h.

References mlir::tblgen::stringify(), and templateParams.

◆ addTemplateParams()

template<typename ContainerT >
void mlir::tblgen::Class::addTemplateParams ( ContainerT &&  container)
inline

Add a list of template parameters.

Definition at line 792 of file Class.h.

References templateParams.

◆ declare()

template<typename DeclT , typename... Args>
DeclT* mlir::tblgen::Class::declare ( Args &&...  args)
inline

Add a declaration.

The declaration is appended directly to the list of class declarations.

Definition at line 822 of file Class.h.

References declarations.

◆ declareMethod()

template<Method::Properties Properties = Method::None, typename RetTypeT , typename NameT , typename... Args>
Method* mlir::tblgen::Class::declareMethod ( RetTypeT &&  retType,
NameT &&  name,
Args &&...  args 
)
inline

Add a declaration for a method.

Definition at line 758 of file Class.h.

◆ declareStaticMethod()

template<Method::Properties Properties = Method::None, typename RetTypeT , typename NameT , typename... Args>
Method* mlir::tblgen::Class::declareStaticMethod ( RetTypeT &&  retType,
NameT &&  name,
Args &&...  args 
)
inline

Add a declaration for a static method.

Definition at line 767 of file Class.h.

◆ finalize()

virtual void mlir::tblgen::Class::finalize ( )
virtual

The declaration of a class needs to be "finalized".

Class constructors, methods, and fields can be added in any order, regardless of whether they are public or private. These are stored in lists separate from list of declarations declarations.

So that the generated C++ code is somewhat organised, public methods are declared together, and so are private methods and class fields. This function iterates through all the added methods and fields and organises them into the list of declarations, adding visibility declarations as needed, as follows:

  1. public methods and constructors
  2. private methods and constructors
  3. class fields – all are private

Class::finalize clears the lists of pending methods and fields, and can be called multiple times.

◆ getClassName()

StringRef mlir::tblgen::Class::getClassName ( ) const
inline

Return the C++ name of the class.

Definition at line 797 of file Class.h.

References className.

Referenced by addConstructor().

◆ getLastVisibilityDecl()

Visibility mlir::tblgen::Class::getLastVisibilityDecl ( ) const
protected

Get the last visibility declaration.

◆ writeDeclTo() [1/2]

void mlir::tblgen::Class::writeDeclTo ( raw_indented_ostream os) const

Write the declaration of this class, all declarations, and definitions of inline functions.

◆ writeDeclTo() [2/2]

void mlir::tblgen::Class::writeDeclTo ( raw_ostream &  rawOs) const
inline

Write the declaration of this class, all declarations, and definitions of inline functions.

Wrap the output stream in an indented stream.

Definition at line 801 of file Class.h.

◆ writeDefTo() [1/2]

void mlir::tblgen::Class::writeDefTo ( raw_indented_ostream os) const

Write the definitions of thiss class's out-of-line constructors and methods.

◆ writeDefTo() [2/2]

void mlir::tblgen::Class::writeDefTo ( raw_ostream &  rawOs) const
inline

Write the definitions of thiss class's out-of-line constructors and methods.

Wrap the output stream in an indented stream.

Definition at line 807 of file Class.h.

Member Data Documentation

◆ className

std::string mlir::tblgen::Class::className
protected

The C++ class name.

Definition at line 861 of file Class.h.

Referenced by getClassName().

◆ declarations

std::vector<std::unique_ptr<ClassDeclaration> > mlir::tblgen::Class::declarations
protected

A list of declarations in the class, emitted in order.

Definition at line 872 of file Class.h.

Referenced by declare().

◆ fields

SmallVector<Field> mlir::tblgen::Class::fields
protected

The pending list of private class fields.

Definition at line 867 of file Class.h.

Referenced by addField().

◆ isStruct

bool mlir::tblgen::Class::isStruct
protected

Whether this is a class or a struct.

Definition at line 869 of file Class.h.

◆ methods

std::vector<std::unique_ptr<Method> > mlir::tblgen::Class::methods
protected

The pending list of methods and constructors.

Definition at line 865 of file Class.h.

◆ parents

SmallVector<ParentClass> mlir::tblgen::Class::parents
protected

The list of parent classes.

Definition at line 863 of file Class.h.

◆ templateParams

SetVector<std::string, SmallVector<std::string>, StringSet<> > mlir::tblgen::Class::templateParams
protected

An optional list of class template parameters.

Definition at line 875 of file Class.h.

Referenced by addConstructor(), addMethod(), addTemplateParam(), and addTemplateParams().


The documentation for this class was generated from the following file: