31 #ifndef GOOGLE_PROTOBUF_COMPILER_SCC_H__
32 #define GOOGLE_PROTOBUF_COMPILER_SCC_H__
36 #include <google/protobuf/stubs/logging.h>
37 #include <google/protobuf/stubs/common.h>
38 #include <google/protobuf/descriptor.h>
40 #include <google/protobuf/port_def.inc>
62 template <
class DepsGenerator>
63 class PROTOC_EXPORT SCCAnalyzer {
79 std::map<const Descriptor*, NodeData> cache_;
80 std::vector<const Descriptor*>
stack_;
82 std::vector<std::unique_ptr<SCC>> garbage_bin_;
85 garbage_bin_.emplace_back(
new SCC());
86 return garbage_bin_.back().get();
103 if (cache_.count(
dep) == 0) {
105 NodeData child_data = DFS(
dep);
108 NodeData child_data = cache_[
dep];
109 if (child_data.scc ==
nullptr) {
117 SCC* scc = CreateSCC();
120 scc->descriptors.push_back(scc_desc);
123 cache_[scc_desc].scc = scc;
130 std::sort(scc->descriptors.begin(), scc->descriptors.end(),
132 return a->full_name() < b->full_name();
141 std::set<const SCC*>
seen;
143 for (
auto child_msg : DepsGenerator()(
descriptor)) {
145 const SCC*
child = GetSCC(child_msg);
146 if (
child == scc)
continue;
148 scc->children.push_back(
child);
162 #include <google/protobuf/port_undef.inc>
164 #endif // GOOGLE_PROTOBUF_COMPILER_SCC_H__