File indexing completed on 2024-05-19 05:42:06

0001 // ct_lvtldr_freefunctionnode.cpp                                            -*-C++-*-
0002 
0003 /*
0004 // Copyright 2023 Codethink Ltd <codethink@codethink.co.uk>
0005 // SPDX-License-Identifier: Apache-2.0
0006 //
0007 // Licensed under the Apache License, Version 2.0 (the "License");
0008 // you may not use this file except in compliance with the License.
0009 // You may obtain a copy of the License at
0010 //
0011 //     http://www.apache.org/licenses/LICENSE-2.0
0012 //
0013 // Unless required by applicable law or agreed to in writing, software
0014 // distributed under the License is distributed on an "AS IS" BASIS,
0015 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
0016 // See the License for the specific language governing permissions and
0017 // limitations under the License.
0018 */
0019 
0020 #include <ct_lvtldr_freefunctionnode.h>
0021 #include <ct_lvtldr_nodestorage.h>
0022 
0023 namespace Codethink::lvtldr {
0024 
0025 using namespace lvtshr;
0026 
0027 // ==========================
0028 // class TypeNode
0029 // ==========================
0030 
0031 FreeFunctionNode::FreeFunctionNode(NodeStorage& store): LakosianNode(store, std::nullopt)
0032 {
0033     // Only to be used on tests
0034 }
0035 
0036 FreeFunctionNode::FreeFunctionNode(NodeStorage& store,
0037                                    std::optional<std::reference_wrapper<DatabaseHandler>> dbHandler,
0038                                    std::optional<FreeFunctionNodeFields> fields):
0039     LakosianNode(store, dbHandler), d_dbHandler(dbHandler), d_fields(*fields)
0040 {
0041     setName(d_fields.name);
0042     d_qualifiedNameParts = NamingUtils::buildQualifiedNamePrefixParts(d_fields.qualifiedName, "::");
0043 }
0044 
0045 FreeFunctionNode::~FreeFunctionNode() noexcept = default;
0046 
0047 lvtshr::DiagramType FreeFunctionNode::type() const
0048 {
0049     return lvtshr::DiagramType::FreeFunctionType;
0050 }
0051 
0052 void FreeFunctionNode::loadParent()
0053 {
0054     d->parentLoaded = true;
0055     d->parent = d->store.findById({DiagramType::ComponentType, *d_fields.componentId});
0056 }
0057 
0058 void FreeFunctionNode::loadProviders()
0059 {
0060     if (d->providersLoaded) {
0061         return;
0062     }
0063     d->providersLoaded = true;
0064 
0065     for (auto&& id : d_fields.calleeIds) {
0066         LakosianNode *node = d->store.findById({DiagramType::FreeFunctionType, id});
0067         d->providers.emplace_back(LakosianEdge{lvtshr::UsesInTheImplementation, node});
0068     }
0069 }
0070 
0071 void FreeFunctionNode::loadClients()
0072 {
0073     if (d->clientsLoaded) {
0074         return;
0075     }
0076     d->clientsLoaded = true;
0077 
0078     for (auto&& id : d_fields.callerIds) {
0079         LakosianNode *node = d->store.findById({DiagramType::FreeFunctionType, id});
0080         d->clients.emplace_back(LakosianEdge{lvtshr::UsesInTheImplementation, node});
0081     }
0082 }
0083 
0084 std::string FreeFunctionNode::qualifiedName() const
0085 {
0086     return NamingUtils::buildQualifiedName(d_qualifiedNameParts, name(), "::");
0087 }
0088 
0089 long long FreeFunctionNode::id() const
0090 {
0091     return d_fields.id;
0092 }
0093 
0094 lvtshr::UniqueId FreeFunctionNode::uid() const
0095 {
0096     return {lvtshr::DiagramType::FreeFunctionType, id()};
0097 }
0098 
0099 std::string FreeFunctionNode::parentName()
0100 {
0101     // TODO: Get parent name (minor)
0102     return "";
0103 }
0104 
0105 LakosianNode::IsLakosianResult FreeFunctionNode::isLakosian()
0106 {
0107     return LakosianNode::IsLakosianResult::IsLakosian;
0108 }
0109 
0110 } // namespace Codethink::lvtldr