ROSE 0.11.145.147
SawyerGenerator.h
1#ifndef Rosebud_SawyerGenerator_H
2#define Rosebud_SawyerGenerator_H
3#include <Rosebud/CxxGenerator.h>
4
5namespace Rosebud {
6
9 using Base = CxxGenerator;
10
11public:
12 using Ptr = std::shared_ptr<SawyerGenerator>;
13
14private:
15 boost::filesystem::path generatedDir; // directory where generated files are written
16 boost::filesystem::path headerPrefix; // installation directory for the header files
17
18protected:
20
21public:
22 static Ptr instance();
23
24public:
25 std::string name() const override;
26 std::string purpose() const override;
28 void generate(const Ast::ProjectPtr&) override;
29 std::string valueType(const Ast::PropertyPtr&) override;
30 void genDefaultConstructor(std::ostream&, std::ostream&, const Ast::ClassPtr&, Access) override;
31 bool genArgsConstructor(std::ostream&, std::ostream&, const Ast::ClassPtr&, const Hierarchy&, Access) override;
32 void genConstructorBody(std::ostream&, const Ast::ClassPtr&) override;
33 std::string ctorInitializerExpression(const Ast::PropertyPtr&, const std::string&) override;
34 std::string propertyDataMemberName(const Ast::PropertyPtr&) const override;
35 std::string propertyDataMemberType(const Ast::PropertyPtr&) override;
36 std::string propertyMutatorArgumentType(const Ast::PropertyPtr&) override;
37
38private:
39 void genNodeDeclarations(const Ast::ProjectPtr&);
40 void genClass(const Ast::ClassPtr&, const Hierarchy&);
41 void genClassConstructors(std::ostream&, std::ostream&, const Ast::ClassPtr&, const Hierarchy&);
42 void genHeaderClose(std::ostream&, const Ast::ClassPtr&);
43 void genHeaderOpen(std::ostream&, const Ast::ClassPtr&);
44 void genImplClose(std::ostream&, const Ast::ClassPtr&);
45 void genImplOpen(std::ostream&, const Ast::ClassPtr&);
46 void genProperty(std::ostream&, std::ostream&, const Ast::PropertyPtr&);
47 void genPropertyAccessor(std::ostream&, std::ostream&, const Ast::PropertyPtr&, Access, const std::string &returnType,
48 const std::string &accessorName, const std::string &thisTypeQualifiers);
49 void genPropertyAccessors(std::ostream&, std::ostream&, const Ast::PropertyPtr&);
50 void genPropertyDataMember(std::ostream&, const Ast::PropertyPtr&);
51 void genPropertyMutator(std::ostream&, std::ostream&, const Ast::PropertyPtr&, Access, const std::string &mutatorName,
52 const std::string &argumentType);
53 void genPropertyMutators(std::ostream&, std::ostream&, const Ast::PropertyPtr&);
54 void genTupFile(const std::vector<std::string> &implNames, const std::vector<std::string> &hdrNames);
55 void genMakeFile(const std::vector<std::string> &implNames, const std::vector<std::string> &hdrNames);
56 void genCmakeFile(const std::vector<std::string> &implNames, const std::vector<std::string> &hdrNames);
57 void genNamespaceDeclarationOpen(std::ostream&, const std::string&);
58 void genNamespaceDeclarationClose(std::ostream&, const std::string&);
59
60 // A mutli-line title comment. The comment is indented according to the leading space in the argument.
61 static std::string title(const std::string&);
62
63 // Returns T if property's type is Edge<T> or EdgeVector<T>
64 Sawyer::Optional<std::string> treeScalarEdgeInnerType(const Ast::PropertyPtr&);
65 Sawyer::Optional<std::string> treeVectorEdgeInnerType(const Ast::PropertyPtr&);
66
67 // True if property's type is Edge<T> or EdgeVector<T>
68 bool isTreeScalarEdge(const Ast::PropertyPtr&);
69 bool isTreeVectorEdge(const Ast::PropertyPtr&);
70 bool isTreeEdge(const Ast::PropertyPtr&);
71
72 std::vector<std::string> implementationFileNames(const Classes&);
73 std::vector<std::string> headerFileNames(const Classes&);
74};
75
76} // namespace
77
78#endif
Base class for generators that produce C++ code.
Definition CxxGenerator.h:8
Generator that produces Sawyer::Tree class hierarchies.
std::string purpose() const override
Property: Single-line description for documentation.
std::string valueType(const Ast::PropertyPtr &) override
Type of value for initializing a property.
void genConstructorBody(std::ostream &, const Ast::ClassPtr &) override
Emit code for the constructor body.
void generate(const Ast::ProjectPtr &) override
Generate code.
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 ctorInitializerExpression(const Ast::PropertyPtr &, const std::string &) override
Expression for initializing a property in a constructor, or empty.
std::string propertyMutatorArgumentType(const Ast::PropertyPtr &) override
Type for the argument for a property mutator.
bool genArgsConstructor(std::ostream &, std::ostream &, const Ast::ClassPtr &, const Hierarchy &, Access) override
Emit code for the constructor with ctor_args property arguments.
std::string name() const override
Property: Every generator should have a unique name.
void adjustParser(Sawyer::CommandLine::Parser &) override
Add command-line switches and documentation to a parser.
void genDefaultConstructor(std::ostream &, std::ostream &, const Ast::ClassPtr &, Access) override
Emit code for the class default constructor.
The parser for a program command line.
Graph containing user-defined vertices and edges.
Definition Graph.h:634
Holds a value or nothing.
Definition Optional.h:56
std::shared_ptr< Class > ClassPtr
Shared-ownership pointer to a Class.
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::vector< Ast::ClassPtr > Classes
Ordered sequence of classes.
Definition ud/Utility.h:251
Access
Kinds of access.
Definition ud/Utility.h:20