ROSE 0.11.145.192
Public Types | Public Member Functions | Static Public Member Functions | List of all members
Rosebud::SawyerGenerator Class Reference

Description

Generator that produces Sawyer::Tree class hierarchies.

Definition at line 8 of file SawyerGenerator.h.

#include <Rosebud/SawyerGenerator.h>

Inheritance diagram for Rosebud::SawyerGenerator:
Inheritance graph
[legend]
Collaboration diagram for Rosebud::SawyerGenerator:
Collaboration graph
[legend]

Public Types

using Ptr = std::shared_ptr< SawyerGenerator >
 
- Public Types inherited from Rosebud::Generator
using Ptr = GeneratorPtr
 

Public Member Functions

std::string name () const override
 Property: Every generator should have a unique name.
 
std::string purpose () const override
 Property: Single-line description for documentation.
 
void adjustParser (Sawyer::CommandLine::Parser &) override
 Add command-line switches and documentation to a parser.
 
void generate (const Ast::ProjectPtr &) override
 Generate code.
 
std::string valueType (const Ast::PropertyPtr &) override
 Type of value for initializing a property.
 
void genDefaultConstructor (std::ostream &, std::ostream &, const Ast::ClassPtr &, Access) override
 Emit code for the class default constructor.
 
bool genArgsConstructor (std::ostream &, std::ostream &, const Ast::ClassPtr &, const Hierarchy &, Access) override
 Emit code for the constructor with ctor_args property arguments.
 
void genConstructorBody (std::ostream &, const Ast::ClassPtr &) override
 Emit code for the constructor body.
 
std::string ctorInitializerExpression (const Ast::PropertyPtr &, const std::string &) override
 Expression for initializing a property in a constructor, or empty.
 
std::string propertyDataMemberName (const Ast::PropertyPtr &) const override
 Data member name for a property.
 
std::string propertyDataMemberType (const Ast::PropertyPtr &) override
 Type for the data member for a property.
 
std::string propertyMutatorArgumentType (const Ast::PropertyPtr &) override
 Type for the argument for a property mutator.
 
- Public Member Functions inherited from Rosebud::Generator
virtual std::vector< std::string > propertyAccessorNames (const Ast::PropertyPtr &) const
 Accessor names for a property.
 
virtual std::vector< std::string > propertyMutatorNames (const Ast::PropertyPtr &) const
 Mutator names for a property.
 
void commandLine (const std::vector< std::string > &)
 Property: Entire Rosebud command line.
 
const std::vector< std::string > & commandLine () const
 Property: Entire Rosebud command line.
 

Static Public Member Functions

static Ptr instance ()
 
- Static Public Member Functions inherited from Rosebud::Generator
static void registerGenerator (const Ptr &)
 Register a backend for use later.
 
static const std::vector< Ptr > & registeredGenerators ()
 Return all registered backends.
 
static Ptr lookup (const std::string &)
 Return the registered generator with the specified name.
 
static void addAllToParser (Sawyer::CommandLine::Parser &)
 Add all known generator switches to parser.
 

Additional Inherited Members

- Protected Member Functions inherited from Rosebud::CxxGenerator
virtual std::string machineGenerated (char commentType='/')
 Return a title comment that says the file is machine generated.
 
virtual std::string resetStatement (const Ast::PropertyPtr &)
 Statement to initialize a property.
 
virtual std::string propertyAccessorReturnType (const Ast::PropertyPtr &)
 Type for the return value for a property accessor.
 
virtual std::string initialValue (const Ast::PropertyPtr &)
 Initial value expression for the property.
 
virtual void genDestructor (std::ostream &header, std::ostream &impl, const Ast::ClassPtr &)
 Emit code for the class destructor.
 
virtual void genInitProperties (std::ostream &header, std::ostream &impl, const Ast::ClassPtr &)
 Emit code that initializes all local properties.
 
virtual std::string removePointer (const std::string &) const
 Given a type name, remove the outer pointer if present.
 
- Protected Member Functions inherited from Rosebud::Generator
std::string generatedByRosebud (const std::string &prefix)
 Return a multi-line comment that this file was generated by Rosebud.
 
- Protected Attributes inherited from Rosebud::CxxGenerator
size_t outputWidth = 130
 

Member Typedef Documentation

◆ Ptr

using Rosebud::SawyerGenerator::Ptr = std::shared_ptr<SawyerGenerator>

Definition at line 12 of file SawyerGenerator.h.

Constructor & Destructor Documentation

◆ SawyerGenerator()

Rosebud::SawyerGenerator::SawyerGenerator ( )
inlineprotected

Definition at line 19 of file SawyerGenerator.h.

Member Function Documentation

◆ name()

std::string Rosebud::SawyerGenerator::name ( ) const
overridevirtual

Property: Every generator should have a unique name.

Implements Rosebud::Generator.

◆ purpose()

std::string Rosebud::SawyerGenerator::purpose ( ) const
overridevirtual

Property: Single-line description for documentation.

Implements Rosebud::Generator.

◆ adjustParser()

void Rosebud::SawyerGenerator::adjustParser ( Sawyer::CommandLine::Parser )
overridevirtual

Add command-line switches and documentation to a parser.

Any command-line switches and documentation that is specific to the backend are added to the specified parser. In order to not conflict with other backends that might also be adding switch parsers, the backend should create a switch group and give it a unique prefix.

Reimplemented from Rosebud::Generator.

◆ generate()

void Rosebud::SawyerGenerator::generate ( const Ast::ProjectPtr )
overridevirtual

Generate code.

The specified project AST is used to generate code.

Implements Rosebud::Generator.

◆ valueType()

std::string Rosebud::SawyerGenerator::valueType ( const Ast::PropertyPtr )
overridevirtual

Type of value for initializing a property.

This is the type used by mutator arguments, but without the const reference part. The base implementation simply returns the type from the property definition after removing volatile and mutable, but sometimes we need something else. For instance, a property of type TreeEdge<T> is never initialized from another tree edge, but rather from a std::shared_ptr<T>, as follows:

// Class with property definition
class Node: public TreeNode {
[[Rosebud::property]]
TreeEdge<Foo> foo;
};
// Generated mutator member function declaration
void foo(std::shared_ptr<Foo> const&);

Reimplemented from Rosebud::CxxGenerator.

◆ genDefaultConstructor()

void Rosebud::SawyerGenerator::genDefaultConstructor ( std::ostream &  header,
std::ostream &  impl,
const Ast::ClassPtr ,
Access   
)
overridevirtual

Emit code for the class default constructor.

Reimplemented from Rosebud::CxxGenerator.

◆ genArgsConstructor()

bool Rosebud::SawyerGenerator::genArgsConstructor ( std::ostream &  header,
std::ostream &  impl,
const Ast::ClassPtr ,
const Hierarchy ,
Access   
)
overridevirtual

Emit code for the constructor with ctor_args property arguments.

Returns true if it generated a constructor.

Reimplemented from Rosebud::CxxGenerator.

◆ genConstructorBody()

void Rosebud::SawyerGenerator::genConstructorBody ( std::ostream &  ,
const Ast::ClassPtr  
)
overridevirtual

Emit code for the constructor body.

Reimplemented from Rosebud::CxxGenerator.

◆ ctorInitializerExpression()

std::string Rosebud::SawyerGenerator::ctorInitializerExpression ( const Ast::PropertyPtr ,
const std::string &  expr 
)
overridevirtual

Expression for initializing a property in a constructor, or empty.

For most properties, this is simply the initialization expression parsed from the input. However, some properties need extra arguments, etc. that can be returned by this funciton. For instance, a TreeEdge property is initialized in a special way:

// Class with property definition
class Node: public TreeNode {
[[Rosebud::property]]
TreeEdge<Foo> foo = Foo::instance();
[[Rosebud::property]]
int bar = 42;
};
// Generated default constructor
Node::Node()
: foo_(*this, Foo::instance()), bar_(42) {}

So the initializer expression for the "foo" property is overridden to add the "*this" argument, but for "bar" it is not overridden.

The expr argument is the default initializer expression such as the string from the right hand side of the "=" in the property definition, or some other expression.

Reimplemented from Rosebud::CxxGenerator.

◆ propertyDataMemberName()

std::string Rosebud::SawyerGenerator::propertyDataMemberName ( const Ast::PropertyPtr ) const
overridevirtual

Data member name for a property.

Returns the name of the class data member that stores the value of the property. The returned value must be a valid C++ name for the property data member. Each property has exactly one data member.

Reimplemented from Rosebud::Generator.

◆ propertyDataMemberType()

std::string Rosebud::SawyerGenerator::propertyDataMemberType ( const Ast::PropertyPtr )
overridevirtual

Type for the data member for a property.

The base implementation simply returns the property type from the input.

Reimplemented from Rosebud::CxxGenerator.

◆ propertyMutatorArgumentType()

std::string Rosebud::SawyerGenerator::propertyMutatorArgumentType ( const Ast::PropertyPtr )
overridevirtual

Type for the argument for a property mutator.

If the property data member type is T, then this is usually const T&.

Reimplemented from Rosebud::CxxGenerator.


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