4 #include <core/assert.hh>
5 #include "generator.hh"
7 namespace ag
= ast::generator
;
10 generateDefaultVisitorHeader(const char * working_directory
)
12 assert(working_directory
);
15 std::string
path(working_directory
);
17 path
.append("/default-visitor.hh");
18 out
.open(path
.c_str(), std::fstream::out
| std::fstream::trunc
);
19 assert(out
.is_open() && out
.good());
23 ag::appendGeneratedWarning(out
);
24 out
<< "#ifndef AST_DEFAULT_VISITOR_HH" NL
25 << "# define AST_DEFAULT_VISITOR_HH" NL
27 << "#include <ast/visitor.hh>" NL
32 #define DEFAULT_VISITOR_HH(Prefix, Const) \
33 out << " /** @defgroup Visitors */" NL \
35 << " * @brief The default visitor" NL \
36 << " * @ingroup Visitors" NL \
38 << " class "Prefix"DefaultVisitor : public "Prefix"Visitor" NL \
41 << " virtual ~"Prefix"DefaultVisitor();" NL \
44 for (node = ag::nodes; !node->name.empty() > 0; node++) \
45 out << " virtual void visit("Const << node->name << " & node);" \
49 DEFAULT_VISITOR_HH("", "");
50 DEFAULT_VISITOR_HH("Const", "const ");
52 out
<< "} // namespace ast" NL
53 << "#endif // !AST_DEFAULT_VISITOR_HH" NL
;
58 generateDefaultVisitorSource(const char * working_directory
)
60 assert(working_directory
);
63 std::string
path(working_directory
);
65 path
.append("/default-visitor.cc");
66 out
.open(path
.c_str(), std::fstream::out
| std::fstream::trunc
);
67 assert(out
.is_open() && out
.good());
71 ag::appendGeneratedWarning(out
);
72 out
<< "#include <ast/default-visitor.hh>" NL NL
73 << "#define NL << std::endl" NL NL
77 #define DEFAULT_VISITOR_CC(Prefix, Const) \
78 out << " "Prefix"DefaultVisitor::~"Prefix"DefaultVisitor() {}" NL; \
80 for (node = ag::nodes; !node->name.empty() > 0; node++) \
81 out << " void "Prefix"DefaultVisitor::visit("Const << node->name \
84 DEFAULT_VISITOR_CC("", "");
85 DEFAULT_VISITOR_CC("Const", "const ");
87 out
<< "} // namespace ast" NL
;
91 int main(int argc
, char **argv
)
94 generateDefaultVisitorHeader(argv
[1]);
95 generateDefaultVisitorSource(argv
[1]);