ROSE 0.11.145.147
Generator.h
1#ifndef Rosebud_Generator_H
2#define Rosebud_Generator_H
3#include <Rosebud/Utility.h>
4
5#include <Sawyer/CommandLine.h>
6
7namespace Rosebud {
8
10class Generator {
12 // Nested types
14public:
15 using Ptr = GeneratorPtr;
16
18 // Data members
20private:
21 static std::vector<Ptr> registry_;
22 std::vector<std::string> commandLine_;
23
25 // Construction related stuff
27public:
28 virtual ~Generator() {}
29
30protected:
31 Generator() {}
32
33public:
35 static void registerGenerator(const Ptr&);
36
38 static const std::vector<Ptr>& registeredGenerators();
39
41 static Ptr lookup(const std::string&);
42
49
52
54 // Properties
56public:
58 virtual std::string name() const = 0;
59
61 virtual std::string purpose() const = 0;
62
66 void commandLine(const std::vector<std::string>&);
67 const std::vector<std::string>& commandLine() const;
71 // Code generation
73public:
77 virtual void generate(const Ast::ProjectPtr&) = 0;
78
83 virtual std::string propertyDataMemberName(const Ast::PropertyPtr&) const;
84
89 virtual std::vector<std::string> propertyAccessorNames(const Ast::PropertyPtr&) const;
90
95 virtual std::vector<std::string> propertyMutatorNames(const Ast::PropertyPtr&) const;
96
97protected:
99 std::string generatedByRosebud(const std::string &prefix);
100
101private:
102 static void initRegistry();
103};
104
105} // namespace
106#endif
Base class for backend code generators.
Definition Generator.h:10
virtual std::string propertyDataMemberName(const Ast::PropertyPtr &) const
Data member name for a property.
virtual std::string purpose() const =0
Property: Single-line description for documentation.
virtual std::string name() const =0
Property: Every generator should have a unique name.
virtual std::vector< std::string > propertyAccessorNames(const Ast::PropertyPtr &) const
Accessor names for a property.
static void addAllToParser(Sawyer::CommandLine::Parser &)
Add all known generator switches to parser.
const std::vector< std::string > & commandLine() const
Property: Entire Rosebud command line.
static Ptr lookup(const std::string &)
Return the registered generator with the specified name.
static void registerGenerator(const Ptr &)
Register a backend for use later.
virtual std::vector< std::string > propertyMutatorNames(const Ast::PropertyPtr &) const
Mutator names for a property.
std::string generatedByRosebud(const std::string &prefix)
Return a multi-line comment that this file was generated by Rosebud.
virtual void adjustParser(Sawyer::CommandLine::Parser &)
Add command-line switches and documentation to a parser.
Definition Generator.h:48
virtual void generate(const Ast::ProjectPtr &)=0
Generate code.
void commandLine(const std::vector< std::string > &)
Property: Entire Rosebud command line.
static const std::vector< Ptr > & registeredGenerators()
Return all registered backends.
The parser for a program command line.
std::shared_ptr< Property > PropertyPtr
Shared-ownership pointer to a Property.
std::shared_ptr< Project > ProjectPtr
Shared-ownership pointer to a Project.
Rosebud is a tool to generate abstract syntax trees.
Definition Ast.h:14
std::shared_ptr< Generator > GeneratorPtr
Shared-ownership pointer to a Generator.