1 #ifndef Rosebud_RosettaGenerator_H
2 #define Rosebud_RosettaGenerator_H
3 #include <Rosebud/CxxGenerator.h>
5 namespace Rosebud {
9 public:
10  using Ptr = std::shared_ptr<RosettaGenerator>;
12 private:
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
20 protected:
21  RosettaGenerator() {}
23 public:
24  static Ptr instance();
25  virtual std::string name() const override;
26  virtual std::string purpose() const override;
27  virtual void adjustParser(Sawyer::CommandLine::Parser&) override;
28  virtual void generate(const Ast::ProjectPtr&) override;
29  virtual std::string propertyDataMemberName(const Ast::PropertyPtr&p) const override;
30  virtual std::vector<std::string> propertyAccessorNames(const Ast::PropertyPtr&) const override;
31  virtual std::vector<std::string> propertyMutatorNames(const Ast::PropertyPtr&) const override;
33 private:
34  boost::filesystem::path fileWrtRose(const boost::filesystem::path&);
35  std::string shortName(const Ast::ClassPtr&);
36  std::string rosettaBaseClass(const Ast::ClassPtr&);
37  bool isBaseClass(const Ast::ClassPtr&, const Hierarchy&);
38  void genRosettaFileBegin(std::ostream &rosetta);
39  void genRosettaFileEnd(std::ostream &rosetta);
40  void genRosettaFunctionBegin(std::ostream &rosetta);
41  void genRosettaFunctionEnd(std::ostream &rosetta);
42  void genImplFileBegin(std::ostream &impl, const Ast::ClassPtr&);
43  void genImplFileEnd(std::ostream &impl, const Ast::ClassPtr&);
44  void genRosettaPragmas(std::ostream &rosetta, const std::vector<std::string>& pragmas, const Ast::ClassPtr&);
45  size_t genRosettaPragmas(std::ostream &rosetta, const Ast::ClassPtr&, const Ast::PropertyPtr&);
46  size_t genRosettaPragmas(std::ostream &rosetta, const Ast::ClassPtr&);
47  void genClassDefinition(std::ostream&, const Ast::ClassPtr&, const Hierarchy&);
48  void genNonterminalMacros(std::ostream &rosetta, const Ast::ClassPtr&, const Hierarchy&);
49  void genNewNonterminalMacro(std::ostream &rosetta, const Ast::ClassPtr&, const Hierarchy&);
50  void genLeafMacros(std::ostream &rosetta, const Ast::ClassPtr&);
51  void genClassBegin(std::ostream &rosetta, const Ast::ClassPtr&);
52  void genClassEnd(std::ostream &rosetta, const Ast::ClassPtr&);
53  void genClassDeclarations(std::ostream &rosetta, const Classes&);
54  void genPropertyDataMember(std::ostream &rosetta, std::ostream &header, const Ast::PropertyPtr&);
55  void genPropertyAccessors(std::ostream &header, std::ostream &impl, const Ast::PropertyPtr&);
56  void genPropertyMutators(std::ostream &header, std::ostream &impl, const Ast::PropertyPtr&);
57  void genProperty(std::ostream &rosetta, std::ostream &header, std::ostream &impl, const Ast::PropertyPtr&);
58  void genCppConditions(std::ostream &out, const Ast::FilePtr&, const std::string &text);
59  void genClassDestructor(std::ostream &header, std::ostream &impl, const Ast::ClassPtr&);
60  void genClassConstructors(std::ostream &header, std::ostream &impl, const Ast::ClassPtr&, const Hierarchy&);
61  void genOtherContent(std::ostream &rosetta, const Ast::ClassPtr&, const std::string &content);
62  std::vector<std::string> implementationFileNames(const Classes&);
63  void adjustNodeList(const std::shared_ptr<Ast::Project>&);
64  void genTupFile(const std::vector<std::string> &implFileNames);
65  void genMakeFile(const std::vector<std::string> &implFileNames);
66  void genCmakeFile(const std::vector<std::string> &implFileNames);
67 };
69 } // namespace
70 #endif
Base class for generators that produce C++ code.
Definition: CxxGenerator.h:8
virtual std::string name() const override
Every generator should have a unique name.
virtual void adjustParser(Sawyer::CommandLine::Parser &) override
Add command-line switches and documentation to a parser.
virtual std::vector< std::string > propertyMutatorNames(const Ast::PropertyPtr &) const override
Mutator names for a property.
Graph containing user-defined vertices and edges.
Definition: Graph.h:625
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.
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
std::vector< Ast::ClassPtr > Classes
Ordered sequence of classes.
Definition: ud/Utility.h:216
The parser for a program command line.
virtual std::string purpose() const override
Single-line description for documentation.
std::shared_ptr< Property > PropertyPtr
Shared-ownership pointer to a Property.
Definition: ud/BasicTypes.h:49
std::shared_ptr< File > FilePtr
Shared-ownership pointer to a File.
Definition: ud/BasicTypes.h:53
std::shared_ptr< Class > ClassPtr
Shared-ownership pointer to a Class.
Definition: ud/BasicTypes.h:51
virtual void generate(const Ast::ProjectPtr &) override
Generate code.
Generator that produces ROSETTA output.