2023-07-25 18:02:53 +01:00
|
|
|
/*
|
|
|
|
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
#include "Prune.h"
|
|
|
|
|
|
|
|
#include "TypeGraph.h"
|
|
|
|
#include "TypeIdentifier.h"
|
|
|
|
|
2023-07-26 15:31:53 +01:00
|
|
|
namespace oi::detail::type_graph {
|
2023-07-25 18:02:53 +01:00
|
|
|
|
|
|
|
Pass Prune::createPass() {
|
2023-08-15 15:27:20 +01:00
|
|
|
auto fn = [](TypeGraph& typeGraph, NodeTracker& tracker) {
|
|
|
|
Prune pass{tracker};
|
2023-07-25 18:02:53 +01:00
|
|
|
for (auto& type : typeGraph.rootTypes()) {
|
|
|
|
pass.accept(type);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
return Pass("Prune", fn);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Prune::accept(Type& type) {
|
|
|
|
if (tracker_.visit(type))
|
|
|
|
return;
|
|
|
|
|
|
|
|
type.accept(*this);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Prune::visit(Class& c) {
|
2023-12-14 16:15:43 +00:00
|
|
|
RecursiveVisitor::visit(c);
|
2023-07-25 18:02:53 +01:00
|
|
|
|
|
|
|
c.templateParams.clear();
|
|
|
|
c.parents.clear();
|
|
|
|
c.functions.clear();
|
|
|
|
|
|
|
|
// Should we bother with this shrinking? It saves memory but costs CPU
|
|
|
|
c.templateParams.shrink_to_fit();
|
|
|
|
c.parents.shrink_to_fit();
|
|
|
|
c.functions.shrink_to_fit();
|
|
|
|
}
|
|
|
|
|
2023-12-14 16:15:43 +00:00
|
|
|
void Prune::visit(Container& c) {
|
|
|
|
RecursiveVisitor::visit(c);
|
|
|
|
|
|
|
|
c.setUnderlying(nullptr);
|
|
|
|
}
|
|
|
|
|
2023-07-26 15:31:53 +01:00
|
|
|
} // namespace oi::detail::type_graph
|