4 #include <core/assert.hh>
5 #include "generator.hh"
7 namespace ag
= ast::generator
;
10 ag::generateVisitorHeader(const char * working_directory
)
12 assert(working_directory
);
15 std::string
path(working_directory
);
17 path
.append("/visitor.hh");
18 out
.open(path
.c_str(), std::fstream::out
| std::fstream::trunc
);
19 assert(out
.is_open() && out
.good());
21 appendGeneratedWarning(out
);
22 out
<< "#ifndef AST_VISITOR_HH" << std::endl
23 << "# define AST_VISITOR_HH" << std::endl
25 << "#include <ast/ast.hh>" << std::endl
27 << "namespace ast" << std::endl
30 out
<< " class Visitor" << std::endl
32 << " public:" << std::endl
33 << " virtual ~Visitor() {};" << std::endl
37 for (node
= ag::nodes
; !node
->name
.empty() > 0; node
++)
38 out
<< " virtual void visit(" << node
->name
<< " & node) = 0;"
40 out
<< " };" << std::endl
<< std::endl
;
42 out
<< " class ConstVisitor" << std::endl
44 << " public:" << std::endl
45 << " virtual ~ConstVisitor() {};" << std::endl
48 for (node
= ag::nodes
; !node
->name
.empty() > 0; node
++)
49 out
<< " virtual void visit(const " << node
->name
<< " & node) = 0;"
51 out
<< " };" << std::endl
;
53 out
<< "} // namespace ast" << std::endl
54 << "#endif // !AST_VISITOR_HH" << std::endl
;