ROSE  0.11.145.0
Generator.h
1 #ifndef Rosebud_Generator_H
2 #define Rosebud_Generator_H
3 #include <Rosebud/Utility.h>
4 
5 #include <Sawyer/CommandLine.h>
6 
7 namespace Rosebud {
8 
10 class Generator {
12  // Nested types
14 public:
15  using Ptr = GeneratorPtr;
16 
18  // Data members
20 private:
21  static std::vector<Ptr> registry_;
22 
24  // Construction related stuff
26 public:
27  virtual ~Generator() {}
28 
29 protected:
30  Generator() {}
31 
32 public:
34  static void registerGenerator(const Ptr&);
35 
37  static const std::vector<Ptr>& registeredGenerators();
38 
40  static Ptr lookup(const std::string&);
41 
48 
51 
53  // Properties
55 public:
57  virtual std::string name() const = 0;
58 
60  virtual std::string purpose() const = 0;
61 
63  // Code generation
65 public:
69  virtual void generate(const Ast::ProjectPtr&) = 0;
70 
75  virtual std::string propertyDataMemberName(const Ast::PropertyPtr&) const;
76 
81  virtual std::vector<std::string> propertyAccessorNames(const Ast::PropertyPtr&) const;
82 
87  virtual std::vector<std::string> propertyMutatorNames(const Ast::PropertyPtr&) const;
88 
89 private:
90  static void initRegistry();
91 };
92 
93 } // namespace
94 #endif
static Ptr lookup(const std::string &)
Return the registered generator with the specified name.
virtual void adjustParser(Sawyer::CommandLine::Parser &)
Add command-line switches and documentation to a parser.
Definition: Generator.h:47
std::shared_ptr< Project > ProjectPtr
Shared-ownership pointer to a Project.
Definition: ud/BasicTypes.h:55
Rosebud is a tool to generate code for ROSE.
Definition: Ast.h:14
static const std::vector< Ptr > & registeredGenerators()
Return all registered backends.
Base class for backend code generators.
Definition: Generator.h:10
The parser for a program command line.
std::shared_ptr< Generator > GeneratorPtr
Shared-ownership pointer to a Generator.
Definition: ud/BasicTypes.h:30
virtual void generate(const Ast::ProjectPtr &)=0
Generate code.
virtual std::vector< std::string > propertyMutatorNames(const Ast::PropertyPtr &) const
Mutator names for a property.
static void addAllToParser(Sawyer::CommandLine::Parser &)
Add all known generator switches to parser.
virtual std::string name() const =0
Every generator should have a unique name.
virtual std::string purpose() const =0
Single-line description for documentation.
std::shared_ptr< Property > PropertyPtr
Shared-ownership pointer to a Property.
Definition: ud/BasicTypes.h:49
virtual std::string propertyDataMemberName(const Ast::PropertyPtr &) const
Data member name for a property.
static void registerGenerator(const Ptr &)
Register a backend for use later.
virtual std::vector< std::string > propertyAccessorNames(const Ast::PropertyPtr &) const
Accessor names for a property.