Generates llvm assembly code for additions :-)
[ozulis.git] / src / ast / generator-visitor.cc
blob8999f1592ed89a4c7877116b4611bed7925ae743
1 #include <iostream>
2 #include <fstream>
4 #include <core/assert.hh>
5 #include "generator.hh"
7 namespace ag = ast::generator;
9 static void
10 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 ag::appendGeneratedWarning(out);
22 out << "#ifndef AST_VISITOR_HH" NL
23 << "# define AST_VISITOR_HH" NL
25 << "#include <ast/ast.hh>" NL
27 << "namespace ast" NL
28 << "{" NL;
30 out << " /** @defgroup Visitors */" NL
31 << " /**" NL
32 << " * @brief The Visitor" NL
33 << " * @ingroup Visitors" NL
34 << " */" NL
35 << " class Visitor" NL
36 << " {" NL
37 << " public:" NL
38 << " virtual ~Visitor() {};" NL
39 NL;
41 const ag::Node *node;
42 for (node = ag::nodes; !node->name.empty() > 0; node++)
43 out << " /** The visit method, see the Visitor design pattern. */" NL
44 << " virtual void visit(" << node->name << " & node) = 0;"
45 NL NL;
46 out << " };" NL NL;
48 out << " /**" NL
49 << " * @brief The const Visitor" NL
50 << " * @ingroup Visitors" NL
51 << " */" NL
52 << " class ConstVisitor" NL
53 << " {" NL
54 << " public:" NL
55 << " virtual ~ConstVisitor() {};" NL
56 NL;
58 for (node = ag::nodes; !node->name.empty() > 0; node++)
59 out << " /** The visit method, see the Visitor design pattern. */" NL
60 << " virtual void visit(const " << node->name << " & node) = 0;"
61 NL NL;
62 out << " };" NL;
64 out << "} // namespace ast" NL
65 << "#endif // !AST_VISITOR_HH" NL;
66 out.close();
69 int main(int argc, char **argv)
71 assert(argc == 2);
72 generateVisitorHeader(argv[1]);
73 return 0;