Adds some type nodes to the ast
[ozulis.git] / src / ast / generator.cc
blob4216ef642ea6621b0c28b76be8d7913ee760ecea
1 #include <iostream>
2 #include "generator.hh"
4 static ast::generator::Node nodes[] = {
5 {"Node", "", {""}},
7 /* Types */
8 {"Type", "Node", {
9 {"std::string", "name"},
10 {"unsigned", "size"},
11 {"bool", "const"},
12 {""}
16 {"Number", "Type", {
17 {""}
21 {"Integer", "Number", {
22 {""}
26 {"Float", "Number", {
27 {""}
31 {"Pointer", "Type", {
32 {"ast::Type*", "type"},
33 {""}
37 {"Enum", "Type", {
38 {"ast::Type*", "type"},
39 {"unsigned", "count"},
40 /* FIXME: elements */
41 {""}
45 {"Array", "Type", {
46 {"ast::Type*", "type"},
47 {""}
51 {"VarDec", "Node", {
52 {"std::string", "name"},
53 {"ast::Type*", "type"},
54 {""}
58 /* Expressions */
59 {"Exp", "Node", {
60 {""}
64 /* Functions */
65 {"Function", "Node", {
66 {"std::string", "name"},
67 {"ast::Type*", "returnType"},
68 {"std::vector<ast::Type*>", "params"},
69 {""}
73 {"", ""}
76 int main(void)
78 ast::generator::Node *node;
79 ast::generator::Attribute *attr;
81 std::cout << "#include <vector>" << std::endl << std::endl;
83 for (node = nodes; node->name.length() > 0; node++)
84 std::cout << "struct " << node->name << ";" << std::endl;
86 std::cout << std::endl;
88 for (node = nodes; !node->name.empty() > 0; node++)
90 std::cout << "struct " << node->name;
91 if (!node->parent.empty())
92 std::cout << " : public " << node->parent;
93 std::cout << std::endl << "{" << std::endl;
94 for (attr = node->attrs; !attr->type.empty() > 0; attr++)
95 std::cout << " " << attr->type << " " << attr->name << ";" << std::endl;
96 std::cout << "};" << std::endl << std::endl;
99 return 0;