@@ -44,10 +44,10 @@ namespace {
4444const StaticString s_invoke (" __invoke" );
4545
4646template <class Operation >
47- void with_file (fs::path dir, const php::Unit& u , Operation op) {
47+ void with_file (fs::path dir, const std::string& unitPath , Operation op) {
4848 // Paths for systemlib units start with /, which gets interpreted as
4949 // an absolute path, so strip it.
50- auto filename = u. filename -> data ();
50+ auto filename = unitPath. data ();
5151 if (filename[0 ] == ' /' ) ++filename;
5252
5353 auto const file = dir / fs::path (filename);
@@ -196,8 +196,6 @@ void dump_func_state(std::ostream& out,
196196std::string debug_dump_to () {
197197 if (!Trace::moduleEnabledRelease (Trace::hhbbc_dump, 1 )) return " " ;
198198
199- trace_time tracer (" debug dump" );
200-
201199 auto dir = [&]{
202200 if (auto const dumpDir = getenv (" HHBBC_DUMP_DIR" )) {
203201 return fs::path (dumpDir);
@@ -218,69 +216,79 @@ std::string debug_dump_to() {
218216 return dir.string ();
219217}
220218
221- void dump_representation (const std::string& dir,
222- const IIndex& index ,
223- const php::Unit& unit ) {
219+ void write_representation_dump (const std::string& dir,
220+ const std::string& unitPath ,
221+ const std::string& dump ) {
224222 auto const rep_dir = fs::path{dir} / " representation" ;
225- with_file (rep_dir, unit, [&] (std::ostream& out) {
226- out << show (unit, index);
227- });
223+ with_file (rep_dir, unitPath, [&] (std::ostream& out) { out << dump; });
224+ }
225+
226+ void write_index_dump (const std::string& dir,
227+ const std::string& unitPath,
228+ const std::string& dump) {
229+ auto const rep_dir = fs::path{dir} / " index" ;
230+ with_file (rep_dir, unitPath, [&] (std::ostream& out) { out << dump; });
231+ }
232+
233+ std::string dump_representation (const IIndex& index,
234+ const php::Unit& unit) {
235+ ContextPusher _{index, Context{ unit.filename , nullptr , nullptr }};
236+ return show (unit, index);
228237}
229238
230- void dump_index (const std::string& dir,
231- const IIndex& index,
232- const php::Unit& unit) {
239+ std::string dump_index (const IIndex& index, const php::Unit& unit) {
233240 if (!*unit.filename ->data ()) {
234241 // The native systemlibs: for now just skip.
235- return ;
242+ return " " ;
236243 }
237244
238- auto ind_dir = fs::path{dir} / " index " ;
245+ ContextPusher _{index, Context{ unit. filename , nullptr , nullptr }} ;
239246
240- with_file (ind_dir, unit, [&] (std::ostream& out) {
241- std::vector<const php::Class*> classes;
242- index.for_each_unit_class (
243- unit,
244- [&] (const php::Class& c) { classes.emplace_back (&c); }
245- );
246- std::sort (
247- begin (classes), end (classes),
248- [] (const php::Class* a, const php::Class* b) {
249- return string_data_lt_type{}(a->name , b->name );
250- }
251- );
252-
253- for (auto const c : classes) {
254- dump_class_state (out, index, c);
255-
256- std::vector<const php::Func*> funcs;
257- funcs.reserve (c->methods .size ());
258- for (auto const & m : c->methods ) {
259- if (!m) continue ;
260- funcs.emplace_back (m.get ());
261- }
262- std::sort (
263- begin (funcs), end (funcs),
264- [] (const php::Func* a, const php::Func* b) {
265- return string_data_lt{}(a->name , b->name );
266- }
267- );
268- for (auto const f : funcs) dump_func_state (out, index, *f);
247+ std::vector<const php::Class*> classes;
248+ index.for_each_unit_class (
249+ unit,
250+ [&] (const php::Class& c) { classes.emplace_back (&c); }
251+ );
252+ std::sort (
253+ begin (classes), end (classes),
254+ [] (const php::Class* a, const php::Class* b) {
255+ return string_data_lt_type{}(a->name , b->name );
269256 }
257+ );
258+
259+ std::ostringstream out;
260+ for (auto const c : classes) {
261+ dump_class_state (out, index, c);
270262
271263 std::vector<const php::Func*> funcs;
272- index.for_each_unit_func (
273- unit,
274- [&] (const php::Func& f) { funcs.emplace_back (&f); }
275- );
264+ funcs.reserve (c->methods .size ());
265+ for (auto const & m : c->methods ) {
266+ if (!m) continue ;
267+ funcs.emplace_back (m.get ());
268+ }
276269 std::sort (
277270 begin (funcs), end (funcs),
278271 [] (const php::Func* a, const php::Func* b) {
279272 return string_data_lt{}(a->name , b->name );
280273 }
281274 );
282275 for (auto const f : funcs) dump_func_state (out, index, *f);
283- });
276+ }
277+
278+ std::vector<const php::Func*> funcs;
279+ index.for_each_unit_func (
280+ unit,
281+ [&] (const php::Func& f) { funcs.emplace_back (&f); }
282+ );
283+ std::sort (
284+ begin (funcs), end (funcs),
285+ [] (const php::Func* a, const php::Func* b) {
286+ return string_data_lt{}(a->name , b->name );
287+ }
288+ );
289+ for (auto const f : funcs) dump_func_state (out, index, *f);
290+
291+ return out.str ();
284292}
285293
286294// ////////////////////////////////////////////////////////////////////
0 commit comments