fibonacci works again
[ozulis.git] / src / ast / generator-lib.cc
blobe61de31b5120901248fc05666a59e91520eb28c3
1 #include "generator.hh"
2 #include <core/assert.hh>
3 #include <iostream>
5 namespace ag = ast::generator;
7 bool ag::isNode(const std::string & type)
9 return
10 type == "Address *" ||
11 type == "Block *" ||
12 type == "ConditionalBranch *" ||
13 type == "Exp *" ||
14 type == "Label *" ||
15 type == "Node *" ||
16 type == "Symbol *" ||
17 type == "Type *" ||
18 false;
21 bool ag::isPrintable(const std::string & type)
23 return
24 type != "Scope *";
27 bool ag::isVectorOfNode(const std::string & type)
29 return
30 type == "std::vector<Node *> *" ||
31 type == "std::vector<Exp *> *" ||
32 type == "std::vector<Type *> *" ||
33 type == "std::vector<VarDecl *> *" ||
34 false;
37 const ag::Node *
38 ag::findNodeByName(const std::string & name)
40 for (const ag::Node * node = ag::nodes; !node->name.empty() > 0; node++)
41 if (node->name == name)
42 return node;
43 return 0;
46 std::vector<const ag::Attribute *>
47 ag::allAttributes(const ag::Node * node)
49 std::vector<const ag::Attribute *> attrs;
51 assert(node);
52 do {
53 for (const ag::Attribute * attr = node->attrs; !attr->type.empty(); ++attr)
54 attrs.push_back(attr);
55 } while ((node = findNodeByName(node->parent)));
56 return attrs;
59 void ag::appendGeneratedWarning(std::ostream & out)
61 out << "/* DO NOT MODIFY THIS FILE (GENERATED) */" << std::endl;
64 std::string
65 ag::deref(std::string type)
67 std::string::iterator it = type.end() - 1;
69 while (it != type.begin() && (*it == '*' || *it == ' '))
70 --it;
71 type.erase(it + 1, type.end());
72 return type;
75 template class std::vector<ag::Attribute *>;