forked from rose-compiler/rose
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
(Rosebud) Code generators are chosen using factories; added new
* Added code generators that generate no code. The main backend NoneGenerator can be used when all you want is to check that the input is valid. The NoneSerializer is used for nodes that don't yet support serialization because they have base classes that aren't Rosebud-generated and thus don't implement serialization. * The main backend code generators ("rosetta", "rose", "yaml", and now "none") are selected from the command-line by name with no hard-coded values. * The backend serialization generators ("boost" and now "none") are also selected by name with no hard-coded values. * This is similar to how some of the binary analysis class hierarchies work, except here we use "lookup" instead of "forge" since we're not forging any new objects. * These changes make it possible to later add user-defined code generators without needing to modify anything in Rosebud other than a call to register the generator. * The "rosetta" backend checks whether a class is serializable. RPM-357
- Loading branch information
Showing
22 changed files
with
478 additions
and
50 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
#include <Rosebud/NoneGenerator.h> | ||
|
||
namespace Rosebud { | ||
|
||
NoneGenerator::Ptr | ||
NoneGenerator::instance() { | ||
return Ptr(new NoneGenerator); | ||
} | ||
|
||
std::string | ||
NoneGenerator::name() const { | ||
return "none"; | ||
} | ||
|
||
std::string | ||
NoneGenerator::purpose() const { | ||
return "Do not generate code, but only check the input."; | ||
} | ||
|
||
void | ||
NoneGenerator::generate(const Ast::Project::Ptr&) {} | ||
|
||
} // namespace |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
#ifndef Rosebud_NoneGenerator_H | ||
#define Rosebud_NoneGenerator_H | ||
#include <Rosebud/Generator.h> | ||
|
||
#include <Sawyer/CommandLine.h> | ||
|
||
namespace Rosebud { | ||
|
||
/** Generator that produces a YAML description of the input. */ | ||
class NoneGenerator: public Generator { | ||
public: | ||
using Ptr = std::shared_ptr<NoneGenerator>; | ||
|
||
protected: | ||
NoneGenerator() {} | ||
|
||
public: | ||
static Ptr instance(); | ||
virtual std::string name() const override; | ||
virtual std::string purpose() const override; | ||
virtual void generate(const Ast::ProjectPtr&) override; | ||
}; | ||
|
||
} // namespace | ||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
#include <Rosebud/NoneSerializer.h> | ||
|
||
#include <Rosebud/Generator.h> | ||
|
||
#include <memory> | ||
#include <string> | ||
|
||
namespace Rosebud { | ||
|
||
NoneSerializer::Ptr | ||
NoneSerializer::instance() { | ||
return Ptr(new NoneSerializer); | ||
} | ||
|
||
std::string | ||
NoneSerializer::name() const { | ||
return "none"; | ||
} | ||
|
||
std::string | ||
NoneSerializer::purpose() const { | ||
return "Generates no serialization code."; | ||
} | ||
|
||
bool | ||
NoneSerializer::isSerializable(const Ast::ClassPtr&) const { | ||
return false; | ||
} | ||
|
||
void | ||
NoneSerializer::generate(std::ostream&, std::ostream&, const Ast::Class::Ptr&, const Generator&) const {} | ||
|
||
} // namespace |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
#ifndef Rosebud_NoneSerializer_H | ||
#define Rosebud_NoneSerializer_H | ||
#include <Rosebud/Serializer.h> | ||
|
||
namespace Rosebud { | ||
|
||
/** Class serializer using None Serialization. | ||
* | ||
* This serializer generates code for boost::serialization. */ | ||
class NoneSerializer: public Serializer { | ||
public: | ||
using Ptr = std::shared_ptr<NoneSerializer>; | ||
|
||
protected: | ||
NoneSerializer() {} | ||
|
||
public: | ||
static Ptr instance(); | ||
virtual std::string name() const override; | ||
virtual std::string purpose() const override; | ||
virtual bool isSerializable(const Ast::ClassPtr&) const override; | ||
virtual void generate(std::ostream &header, std::ostream &impl, const Ast::ClassPtr&, const Generator&) const override; | ||
}; | ||
|
||
} // namespace | ||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.