ROSE 0.11.145.192
RosettaGenerator.h
1#ifndef Rosebud_RosettaGenerator_H
2#define Rosebud_RosettaGenerator_H
3#include <Rosebud/CxxGenerator.h>
4
5namespace Rosebud {
6
9public:
10 using Ptr = std::shared_ptr<RosettaGenerator>;
11
12private:
13 boost::filesystem::path rosettaFileName; // optional name of file into which ROSETTA source code is written
14 boost::filesystem::path implDirectoryName; // optional name of directory where node implementation files are created
15 boost::filesystem::path nodeListFileName; // optional name of file that contains list of all node types
16 std::string grammarFunctionName = "Grammar::no_name"; // name of ROSETTA function being generated
17 std::string cppProtection; // conditional compilation expression protecting all generated code
18 bool strictParents = false; // generate extra parent pointer checks and adjustments
19 bool smallHeaders = false; // pretend every class has `Rosebud::small_header`
20
21protected:
23
24public:
25 static Ptr instance();
26 virtual std::string name() const override;
27 virtual std::string purpose() const override;
29 virtual void generate(const Ast::ProjectPtr&) override;
30 virtual std::string propertyDataMemberName(const Ast::PropertyPtr&p) const override;
31 virtual std::vector<std::string> propertyAccessorNames(const Ast::PropertyPtr&) const override;
32 virtual std::vector<std::string> propertyMutatorNames(const Ast::PropertyPtr&) const override;
33
34private:
35 boost::filesystem::path fileWrtRose(const boost::filesystem::path&);
36 std::string shortName(const Ast::ClassPtr&);
37 std::string rosettaBaseClass(const Ast::ClassPtr&);
38 bool isBaseClass(const Ast::ClassPtr&, const Hierarchy&);
39 void genRosettaFileBegin(std::ostream &rosetta);
40 void genRosettaFileEnd(std::ostream &rosetta);
41 void genRosettaFunctionBegin(std::ostream &rosetta);
42 void genRosettaFunctionEnd(std::ostream &rosetta);
43 void genImplFileBegin(std::ostream &impl, const Ast::ClassPtr&);
44 void genImplFileEnd(std::ostream &impl, const Ast::ClassPtr&);
45 void genRosettaPragmas(std::ostream &rosetta, const std::vector<std::string>& pragmas, const Ast::ClassPtr&);
46 size_t genRosettaPragmas(std::ostream &rosetta, const Ast::ClassPtr&, const Ast::PropertyPtr&);
47 size_t genRosettaPragmas(std::ostream &rosetta, const Ast::ClassPtr&);
48 void genClassDefinition(std::ostream&, const Ast::ClassPtr&, const Hierarchy&);
49 void genNonterminalMacros(std::ostream &rosetta, const Ast::ClassPtr&, const Hierarchy&);
50 void genNewNonterminalMacro(std::ostream &rosetta, const Ast::ClassPtr&, const Hierarchy&);
51 void genLeafMacros(std::ostream &rosetta, const Ast::ClassPtr&);
52 void genClassBegin(std::ostream &rosetta, const Ast::ClassPtr&);
53 void genClassEnd(std::ostream &rosetta, const Ast::ClassPtr&);
54 void genClassDeclarations(std::ostream &rosetta, const Classes&);
55 void genPropertyDataMember(std::ostream &rosetta, std::ostream &header, const Ast::PropertyPtr&);
56 void genPropertyAccessors(std::ostream &header, std::ostream &impl, const Ast::PropertyPtr&);
57 void genPropertyMutators(std::ostream &header, std::ostream &impl, const Ast::PropertyPtr&);
58 void genProperty(std::ostream &rosetta, std::ostream &header, std::ostream &impl, const Ast::PropertyPtr&);
59 void genCppConditions(std::ostream &out, const Ast::FilePtr&, const std::string &text);
60 void genClassDestructor(std::ostream &header, std::ostream &impl, const Ast::ClassPtr&);
61 void genClassConstructors(std::ostream &header, std::ostream &impl, const Ast::ClassPtr&, const Hierarchy&);
62 void genOtherContent(std::ostream &rosetta, const Ast::ClassPtr&, const Hierarchy&, const std::string &content);
63 std::vector<std::string> implementationFileNames(const Classes&);
64 void adjustNodeList(const std::shared_ptr<Ast::Project>&);
65 void genTupFile(const std::vector<std::string> &implFileNames);
66 void genMakeFile(const std::vector<std::string> &implFileNames);
67 void genCmakeFile(const std::vector<std::string> &implFileNames);
68};
69
70} // namespace
71#endif
Base class for generators that produce C++ code.
Definition CxxGenerator.h:8
Generator that produces ROSETTA output.
virtual std::vector< std::string > propertyMutatorNames(const Ast::PropertyPtr &) const override
Mutator names for a property.
virtual void generate(const Ast::ProjectPtr &) override
Generate code.
virtual void adjustParser(Sawyer::CommandLine::Parser &) override
Add command-line switches and documentation to a parser.
virtual std::string name() const override
Property: Every generator should have a unique name.
virtual std::string propertyDataMemberName(const Ast::PropertyPtr &p) const override
Data member name for a property.
virtual std::vector< std::string > propertyAccessorNames(const Ast::PropertyPtr &) const override
Accessor names for a property.
virtual std::string purpose() const override
Property: Single-line description for documentation.
The parser for a program command line.
Graph containing user-defined vertices and edges.
Definition Graph.h:634
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.
std::shared_ptr< File > FilePtr
Shared-ownership pointer to a File.
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