{
public:
Escape_analysis_discover(Gogo* gogo)
- : Traverse(traverse_functions),
+ : Traverse(traverse_functions | traverse_func_declarations),
gogo_(gogo), component_ids_()
{ }
int
function(Named_object*);
+ int
+ function_declaration(Named_object*);
+
int
visit(Named_object*);
return TRAVERSE_CONTINUE;
}
+int
+Escape_analysis_discover::function_declaration(Named_object* fn)
+{
+ this->visit(fn);
+ return TRAVERSE_CONTINUE;
+}
+
// Visit a function FN, adding it to the current stack of functions
// in this connected component. If this is the root of the component,
// create a set of functions to be analyzed later.
}
}
+ // Traverse function declarations when needed.
+ if ((traverse_mask & Traverse::traverse_func_declarations) != 0)
+ {
+ for (Bindings::const_declarations_iterator p = this->begin_declarations();
+ p != this->end_declarations();
+ ++p)
+ {
+ if (p->second->is_function_declaration())
+ {
+ if (traverse->function_declaration(p->second) == TRAVERSE_EXIT)
+ return TRAVERSE_EXIT;
+ }
+ }
+ }
+
return TRAVERSE_CONTINUE;
}
go_unreachable();
}
+int
+Traverse::function_declaration(Named_object*)
+{
+ go_unreachable();
+}
+
// Class Statement_inserter.
void
{
public:
// These bitmasks say what to traverse.
- static const unsigned int traverse_variables = 0x1;
- static const unsigned int traverse_constants = 0x2;
- static const unsigned int traverse_functions = 0x4;
- static const unsigned int traverse_blocks = 0x8;
- static const unsigned int traverse_statements = 0x10;
- static const unsigned int traverse_expressions = 0x20;
- static const unsigned int traverse_types = 0x40;
+ static const unsigned int traverse_variables = 0x1;
+ static const unsigned int traverse_constants = 0x2;
+ static const unsigned int traverse_functions = 0x4;
+ static const unsigned int traverse_blocks = 0x8;
+ static const unsigned int traverse_statements = 0x10;
+ static const unsigned int traverse_expressions = 0x20;
+ static const unsigned int traverse_types = 0x40;
+ static const unsigned int traverse_func_declarations = 0x80;
Traverse(unsigned int traverse_mask)
: traverse_mask_(traverse_mask), types_seen_(NULL), expressions_seen_(NULL)
virtual int
type(Type*);
+ // If traverse_func_declarations is set in the mask, this is called
+ // for every function declarations in the tree.
+ virtual int
+ function_declaration(Named_object*);
+
private:
// A hash table for types we have seen during this traversal. Note
// that this uses the default hash functions for pointers rather