splitted generator
[ozulis.git] / src / ast / generator-visitor.cc
blob54f916ebb62222a308d23cdb08d011e57948927a
1 #include <iostream>
2 #include <fstream>
4 #include <core/assert.hh>
5 #include "generator.hh"
7 namespace ag = ast::generator;
9 void
10 ag::generateVisitorHeader(const char * working_directory)
12 assert(working_directory);
14 std::fstream out;
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
24 << std::endl
25 << "#include <ast/ast.hh>" << std::endl
26 << std::endl
27 << "namespace ast" << std::endl
28 << "{" << std::endl;
30 out << " class Visitor" << std::endl
31 << " {" << std::endl
32 << " public:" << std::endl
33 << " virtual ~Visitor() {};" << std::endl
34 << std::endl;
36 const ag::Node *node;
37 for (node = ag::nodes; !node->name.empty() > 0; node++)
38 out << " virtual void visit(" << node->name << " & node) = 0;"
39 << std::endl;
40 out << " };" << std::endl << std::endl;
42 out << " class ConstVisitor" << std::endl
43 << " {" << std::endl
44 << " public:" << std::endl
45 << " virtual ~ConstVisitor() {};" << std::endl
46 << std::endl;
48 for (node = ag::nodes; !node->name.empty() > 0; node++)
49 out << " virtual void visit(const " << node->name << " & node) = 0;"
50 << std::endl;
51 out << " };" << std::endl;
53 out << "} // namespace ast" << std::endl
54 << "#endif // !AST_VISITOR_HH" << std::endl;
55 out.close();