return this->state_;
}
+Node::~Node()
+{
+ if (this->state_ != NULL)
+ {
+ if (this->expr() == NULL || this->expr()->var_expression() == NULL)
+ // Var expression Node is excluded since it shares state with the
+ // underlying var Node.
+ delete this->state_;
+ }
+}
+
int
Node::encoding()
{
std::map<Named_object*, Node*> Node::objects;
std::map<Expression*, Node*> Node::expressions;
std::map<Statement*, Node*> Node::statements;
+std::vector<Node*> Node::indirects;
// Make a object node or return a cached node for this object.
Node::make_indirect_node(Node* child)
{
Node* n = new Node(child);
+ Node::indirects.push_back(n);
return n;
}
Escape_analysis_tag eat(context);
eat.tag(fn);
}
+
+// Reclaim memory of escape analysis Nodes.
+
+void
+Gogo::reclaim_escape_nodes()
+{
+ Node::reclaim_nodes();
+}
+
+void
+Node::reclaim_nodes()
+{
+ for (std::map<Named_object*, Node*>::iterator p = Node::objects.begin();
+ p != Node::objects.end();
+ ++p)
+ delete p->second;
+ Node::objects.clear();
+
+ for (std::map<Expression*, Node*>::iterator p = Node::expressions.begin();
+ p != Node::expressions.end();
+ ++p)
+ delete p->second;
+ Node::expressions.clear();
+
+ for (std::map<Statement*, Node*>::iterator p = Node::statements.begin();
+ p != Node::statements.end();
+ ++p)
+ delete p->second;
+ Node::statements.clear();
+
+ for (std::vector<Node*>::iterator p = Node::indirects.begin();
+ p != Node::indirects.end();
+ ++p)
+ delete *p;
+ Node::indirects.clear();
+}
child_(n)
{}
+ ~Node();
+
// Return this node's type.
Type*
type() const;
static int
note_inout_flows(int e, int index, Level level);
+ // Reclaim nodes.
+ static void
+ reclaim_nodes();
+
private:
// The classification of this Node.
Node_classification classification_;
static std::map<Named_object*, Node*> objects;
static std::map<Expression*, Node*> expressions;
static std::map<Statement*, Node*> statements;
+
+ // Collection of all NODE_INDIRECT Nodes, used for reclaiming memory. This
+ // is not a cache -- each make_indirect_node will make a fresh Node.
+ static std::vector<Node*> indirects;
};
// The amount of bits used for the escapement encoding.
// Flatten the parse tree.
::gogo->flatten();
+ // Reclaim memory of escape analysis Nodes.
+ ::gogo->reclaim_escape_nodes();
+
// Dump ast, use filename[0] as the base name
::gogo->dump_ast(filenames[0]);
}