diff options
author | Adam Lesinski <adamlesinski@google.com> | 2015-05-12 20:40:48 -0700 |
---|---|---|
committer | Adam Lesinski <adamlesinski@google.com> | 2015-05-12 20:45:20 -0700 |
commit | d13fb249865703901b77f48c5fed1864f06e1c63 (patch) | |
tree | 55c4b18e7c0e068a82c5c726cda0326348c5ca1f /tools/aapt2/Debug.cpp | |
parent | bdaa092a193d8ddccbd9ad8434be97878e6ded59 (diff) |
AAPT2: Debug: Dump only targetted style
Change-Id: Id7c5a4b5d0880520e1fea05e5a31d398946c5f05
Diffstat (limited to 'tools/aapt2/Debug.cpp')
-rw-r--r-- | tools/aapt2/Debug.cpp | 47 |
1 files changed, 29 insertions, 18 deletions
diff --git a/tools/aapt2/Debug.cpp b/tools/aapt2/Debug.cpp index a7b9bbaa28f3..cf222c68de55 100644 --- a/tools/aapt2/Debug.cpp +++ b/tools/aapt2/Debug.cpp @@ -23,6 +23,7 @@ #include <iostream> #include <map> #include <memory> +#include <queue> #include <set> #include <vector> @@ -135,43 +136,53 @@ static size_t getNodeIndex(const std::vector<ResourceName>& names, const Resourc return std::distance(names.begin(), iter); } -void Debug::printStyleGraph(const std::shared_ptr<ResourceTable>& table) { - std::vector<ResourceName> names; +void Debug::printStyleGraph(const std::shared_ptr<ResourceTable>& table, + const ResourceName& targetStyle) { std::map<ResourceName, std::set<ResourceName>> graph; - for (const auto& type : *table) { - for (const auto& entry : type->entries) { - ResourceName name = { table->getPackage(), type->type, entry->name }; + std::queue<ResourceName> stylesToVisit; + stylesToVisit.push(targetStyle); + for (; !stylesToVisit.empty(); stylesToVisit.pop()) { + const ResourceName& styleName = stylesToVisit.front(); + std::set<ResourceName>& parents = graph[styleName]; + if (!parents.empty()) { + // We've already visited this style. + continue; + } + + const ResourceTableType* type; + const ResourceEntry* entry; + std::tie(type, entry) = table->findResource(styleName); + if (entry) { for (const auto& value : entry->values) { visitFunc<Style>(*value.value, [&](const Style& style) { if (style.parent.name.isValid()) { - names.push_back(style.parent.name); - names.push_back(name); - graph[style.parent.name].insert(name); + parents.insert(style.parent.name); + stylesToVisit.push(style.parent.name); } }); } } } - std::sort(names.begin(), names.end()); - auto it1 = std::unique(names.begin(), names.end()); - names.resize(std::distance(names.begin(), it1)); + std::vector<ResourceName> names; + for (const auto& entry : graph) { + names.push_back(entry.first); + } std::cout << "digraph styles {\n"; - for (const auto& name : names) { std::cout << " node_" << getNodeIndex(names, name) - << " [label=\"" << name.entry << "\"];\n"; + << " [label=\"" << name << "\"];\n"; } for (const auto& entry : graph) { - const ResourceName& parent = entry.first; - size_t parentNodeIndex = getNodeIndex(names, parent); + const ResourceName& styleName = entry.first; + size_t styleNodeIndex = getNodeIndex(names, styleName); - for (const auto& childName : entry.second) { - std::cout << "node_" << getNodeIndex(names, childName) << " -> " - << "node_" << parentNodeIndex << ";\n"; + for (const auto& parentName : entry.second) { + std::cout << " node_" << styleNodeIndex << " -> " + << "node_" << getNodeIndex(names, parentName) << ";\n"; } } |