MLIR 22.0.0git
mlir::tblgen::UsingDeclaration Class Reference

This class describes a using-declaration for a class. More...

#include "mlir/TableGen/Class.h"

Inheritance diagram for mlir::tblgen::UsingDeclaration:

Public Attributes

bool isStruct
 Create a using declaration that either aliases name to value or inherits the parent methods `name.
std::vector< std::unique_ptr< ClassDeclaration > > declarations
 A list of declarations in the class, emitted in order.
SetVector< std::string, SmallVector< std::string >, StringSet<> > templateParams
 An optional list of class template parameters.

Additional Inherited Members

Public Types inherited from mlir::tblgen::ClassDeclarationBase< ClassDeclaration::UsingDeclaration >
using Base
Public Types inherited from mlir::tblgen::ClassDeclaration
enum  Kind {
  Method , UsingDeclaration , VisibilityDeclaration , Field ,
  ExtraClassDeclaration
}
 Kinds for LLVM-style RTTI. More...
Public Member Functions inherited from mlir::tblgen::ClassDeclarationBase< ClassDeclaration::UsingDeclaration >
 ClassDeclarationBase ()
Public Member Functions inherited from mlir::tblgen::ClassDeclaration
virtual ~ClassDeclaration ()=default
 ClassDeclaration (Kind kind)
 Create a class declaration with a given kind.
Kind getKind () const
 Get the class declaration kind.
virtual void writeDeclTo (raw_indented_ostream &os) const =0
 Write the declaration.
virtual void writeDefTo (raw_indented_ostream &os, StringRef namePrefix) const
 Write the definition, if any.
Static Public Member Functions inherited from mlir::tblgen::ClassDeclarationBase< ClassDeclaration::UsingDeclaration >
static bool classof (const ClassDeclaration *other)

Detailed Description

This class describes a using-declaration for a class.

E.g.

using Op::Op; using Adaptor = OpAdaptor;

Definition at line 556 of file Class.h.

Member Data Documentation

◆ declarations

std::vector<std::unique_ptr<ClassDeclaration> > mlir::tblgen::UsingDeclaration::declarations

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

Definition at line 894 of file Class.h.

◆ isStruct

bool mlir::tblgen::UsingDeclaration::isStruct

Create a using declaration that either aliases name to value or inherits the parent methods `name.

template <typename NameT, typename ValueT = std::string> UsingDeclaration(NameT &&name, ValueT &&value = "") : name(stringify(std::forward<NameT>(name))), value(stringify(std::forward<ValueT>(value))) {}

/ Write the using declaration. void writeDeclTo(raw_indented_ostream &os) const override;

/ Add a template parameter. template <typename ParamT> void addTemplateParam(ParamT param) { templateParams.insert(stringify(param)); }

/ Add a list of template parameters. template <typename ContainerT> void addTemplateParams(ContainerT &&container) { templateParams.insert(std::begin(container), std::end(container)); }

private: / The name of the declaration, or a resolved name to an inherited function. std::string name; / The type that is being aliased. Leave empty for inheriting functions. std::string value; / An optional list of class template parameters. / This is simply a ordered list of parameter names that are then added as / template type parameters when the using declaration is emitted. SetVector<std::string, SmallVector<std::string>, StringSet<>> templateParams; };

/ This class describes a class field. class Field : public ClassDeclarationBase<ClassDeclaration::Field> { public: / Create a class field with a type and variable name. template <typename TypeT, typename NameT> Field(TypeT &&type, NameT &&name) : type(stringify(std::forward<TypeT>(type))), name(stringify(std::forward<NameT>(name))) {}

/ Write the declaration of the field. void writeDeclTo(raw_indented_ostream &os) const override;

private: / The C++ type of the field. std::string type; / The variable name of the class whether. std::string name; };

/ A declaration for the visibility of subsequent declarations. class VisibilityDeclaration : public ClassDeclarationBase<ClassDeclaration::VisibilityDeclaration> { public: / Create a declaration for the given visibility. VisibilityDeclaration(Visibility visibility) : visibility(visibility) {}

/ Get the visibility. Visibility getVisibility() const { return visibility; }

/ Write the visibility declaration. void writeDeclTo(raw_indented_ostream &os) const override;

private: / The visibility of subsequent class declarations. Visibility visibility; };

/ Unstructured extra class declarations and definitions, from TableGen / definitions. The default visibility of extra class declarations is up to the / owning class. class ExtraClassDeclaration : public ClassDeclarationBase<ClassDeclaration::ExtraClassDeclaration> { public: / Create an extra class declaration. ExtraClassDeclaration(StringRef extraClassDeclaration, std::string extraClassDefinition = "") : ExtraClassDeclaration(extraClassDeclaration.str(), std::move(extraClassDefinition)) {}

ExtraClassDeclaration(std::string extraClassDeclaration, std::string extraClassDefinition = "") : extraClassDeclaration(extraClassDeclaration), extraClassDefinition(extraClassDefinition) {}

/ Write the extra class declarations. void writeDeclTo(raw_indented_ostream &os) const override;

/ Write the extra class definitions. void writeDefTo(raw_indented_ostream &os, StringRef namePrefix) const override;

private: / The string of the extra class declarations. It is re-indented before / printed. std::string extraClassDeclaration; / The string of the extra class definitions. It is re-indented before / printed. std::string extraClassDefinition; };

/ A class used to emit C++ classes from Tablegen. Contains a list of public / methods and a list of private fields to be emitted. class Class { public: virtual ~Class() = default;

/ Explicitly delete the copy constructor. This is to work around a gcc-5 bug / with std::is_trivially_move_constructible. Class(const Class &) = delete;

/ 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. template <typename NameT, typename = std::enable_if_t<!std::is_same<NameT, Class>::value>> Class(NameT &&name, bool isStruct = false) : className(stringify(std::forward<NameT>(name))), isStruct(isStruct) {}

/ 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. template <Method::Properties Properties = Method::None, typename... Args> Constructor *addConstructor(Args &&...args) { Method::Properties defaultProperties = Method::Constructor; If the class has template parameters, the constructor has to be defined inline. if (!templateParams.empty()) defaultProperties |= Method::Inline; return addConstructorAndPrune(Constructor(getClassName(), Properties | defaultProperties, std::forward<Args>(args)...)); }

/ 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. template <Method::Properties Properties = Method::None, typename RetTypeT, typename NameT> Method *addMethod(RetTypeT &&retType, NameT &&name, Method::Properties properties, ArrayRef<MethodParameter> parameters) { If the class has template parameters, then it has to be defined inline. if (!templateParams.empty()) properties |= Method::Inline; return addMethodAndPrune(Method(std::forward<RetTypeT>(retType), std::forward<NameT>(name), Properties | properties, parameters)); }

/ Add a method with statically-known properties. template <Method::Properties Properties = Method::None, typename RetTypeT, typename NameT> Method *addMethod(RetTypeT &&retType, NameT &&name, ArrayRef<MethodParameter> parameters) { return addMethod(std::forward<RetTypeT>(retType), std::forward<NameT>(name), Properties, parameters); }

template <Method::Properties Properties = Method::None, typename RetTypeT, typename NameT, typename... Args> Method *addMethod(RetTypeT &&retType, NameT &&name, Method::Properties properties, Args &&...args) { return addMethod(std::forward<RetTypeT>(retType), std::forward<NameT>(name), properties | Properties, {std::forward<Args>(args)...}); }

/ Add a method with statically-known properties. template <Method::Properties Properties = Method::None, typename RetTypeT, typename NameT, typename... Args> Method *addMethod(RetTypeT &&retType, NameT &&name, Args &&...args) { return addMethod(std::forward<RetTypeT>(retType), std::forward<NameT>(name), Properties, std::forward<Args>(args)...); }

/ Add a static method. template <Method::Properties Properties = Method::None, typename RetTypeT, typename NameT, typename... Args> Method *addStaticMethod(RetTypeT &&retType, NameT &&name, Args &&...args) { return addMethod<Properties | Method::Static>( std::forward<RetTypeT>(retType), std::forward<NameT>(name), std::forward<Args>(args)...); }

/ Add an inline static method. template <Method::Properties Properties = Method::None, typename RetTypeT, typename NameT, typename... Args> Method *addStaticInlineMethod(RetTypeT &&retType, NameT &&name, Args &&...args) { return addMethod<Properties | Method::StaticInline>( std::forward<RetTypeT>(retType), std::forward<NameT>(name), std::forward<Args>(args)...); }

/ Add an inline method. template <Method::Properties Properties = Method::None, typename RetTypeT, typename NameT, typename... Args> Method *addInlineMethod(RetTypeT &&retType, NameT &&name, Args &&...args) { return addMethod<Properties | Method::Inline>( std::forward<RetTypeT>(retType), std::forward<NameT>(name), std::forward<Args>(args)...); }

/ Add a const method. template <Method::Properties Properties = Method::None, typename RetTypeT, typename NameT, typename... Args> Method *addConstMethod(RetTypeT &&retType, NameT &&name, Args &&...args) { return addMethod<Properties | Method::Const>( std::forward<RetTypeT>(retType), std::forward<NameT>(name), std::forward<Args>(args)...); }

/ Add a declaration for a method. template <Method::Properties Properties = Method::None, typename RetTypeT, typename NameT, typename... Args> Method *declareMethod(RetTypeT &&retType, NameT &&name, Args &&...args) { return addMethod<Properties | Method::Declaration>( std::forward<RetTypeT>(retType), std::forward<NameT>(name), std::forward<Args>(args)...); }

/ Add a declaration for a static method. template <Method::Properties Properties = Method::None, typename RetTypeT, typename NameT, typename... Args> Method *declareStaticMethod(RetTypeT &&retType, NameT &&name, Args &&...args) { return addMethod<Properties | Method::StaticDeclaration>( std::forward<RetTypeT>(retType), std::forward<NameT>(name), std::forward<Args>(args)...); }

const std::vector<std::unique_ptr<Method>> &getMethods() const { return methods; }

/ Add a new field to the class. Class fields added this way are always / private. template <typename TypeT, typename NameT> void addField(TypeT &&type, NameT &&name) { fields.emplace_back(std::forward<TypeT>(type), std::forward<NameT>(name)); }

/ Add a parent class. ParentClass &addParent(ParentClass parent);

/ Add a template parameter. template <typename ParamT> void addTemplateParam(ParamT param) { templateParams.insert(stringify(param)); }

/ Add a list of template parameters. template <typename ContainerT> void addTemplateParams(ContainerT &&container) { templateParams.insert(std::begin(container), std::end(container)); }

/ Return the C++ name of the class. StringRef getClassName() const { return className; }

/ Write the declaration of this class, all declarations, and definitions of / inline functions. Wrap the output stream in an indented stream. void writeDeclTo(raw_ostream &rawOs) const { raw_indented_ostream os(rawOs); writeDeclTo(os); } / Write the definitions of thiss class's out-of-line constructors and / methods. Wrap the output stream in an indented stream. void writeDefTo(raw_ostream &rawOs) const { raw_indented_ostream os(rawOs); writeDefTo(os); }

/ Write the declaration of this class, all declarations, and definitions of / inline functions. void writeDeclTo(raw_indented_ostream &os) const; / Write the definitions of thiss class's out-of-line constructors and / methods. void writeDefTo(raw_indented_ostream &os) const;

/ Add a declaration. The declaration is appended directly to the list of / class declarations. template <typename DeclT, typename... Args> DeclT *declare(Args &&...args) { auto decl = std::make_unique<DeclT>(std::forward<Args>(args)...); auto *ret = decl.get(); declarations.push_back(std::move(decl)); return ret; }

/ 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. virtual void finalize();

protected: / Add a new constructor if it is not made redundant by any existing / constructors and prune and existing constructors made redundant. Constructor *addConstructorAndPrune(Constructor &&newCtor); / Add a new method if it is not made redundant by any existing methods and / prune and existing methods made redundant. Method *addMethodAndPrune(Method &&newMethod);

/ Get the last visibility declaration. Visibility getLastVisibilityDecl() const;

/ The C++ class name. std::string className; / The list of parent classes. SmallVector<ParentClass> parents; / The pending list of methods and constructors. std::vector<std::unique_ptr<Method>> methods; / The pending list of private class fields. SmallVector<Field> fields; / Whether this is a class or a struct.

Definition at line 891 of file Class.h.

◆ templateParams

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

An optional list of class template parameters.

Definition at line 897 of file Class.h.


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