aboutsummaryrefslogtreecommitdiff
path: root/build/dump.cxx
blob: 98b0ff29c090fb3b7b6f71e29f9cde6c93fdec09 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
// file      : build/dump.cxx -*- C++ -*-
// copyright : Copyright (c) 2014-2015 Code Synthesis Tools CC
// license   : MIT; see accompanying LICENSE file

#include <build/dump>

#include <string>
#include <cassert>
#include <iostream>

#include <build/scope>
#include <build/target>
#include <build/variable>
#include <build/diagnostics>

using namespace std;

namespace build
{
  void
  dump ()
  {
    cout << endl;

    for (const auto& pt: targets)
    {
      target& t (*pt);

      cout << t << ':';

      for (const auto& p: t.prerequisites)
      {
        cout << ' ' << p;
      }

      cout << endl;
    }

    cout << endl;
  }

  static void
  dump_scope (scope& p, scope_map::iterator& i, string& ind)
  {
    string d (diag_relative_work (p.path ()));

    if (d.back () != path::traits::directory_separator)
      d += '/';

    cerr << ind << d << ":" << endl
         << ind << '{' << endl;

    ind += "  ";

    for (const auto& e: p.variables)
    {
      const variable& var (e.first);
      const value_ptr& val (e.second);

      cerr << ind << var.name << " = ";

      if (val == nullptr)
        cerr << "[undefined]";
      else
      {
        //@@ TODO: assuming it is a list.
        //
        cerr << dynamic_cast<list_value&> (*val).data;
      }

      cerr << endl;
    }

    // Print nested scopes of which we are a parent.
    //
    for (auto e (scopes.end ()); i != e && i->second.parent () == &p; )
    {
      scope& s (i->second);
      dump_scope (s, ++i, ind);
    }

    ind.resize (ind.size () - 2);
    cerr << ind << '}' << endl;
  }

  void
  dump_scopes ()
  {
    string ind;
    auto i (scopes.begin ());
    scope& r (i->second); // Root scope.
    assert (&r == root_scope);
    dump_scope (r, ++i, ind);
  }
}