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

0001 // ct_lvtclp_visitlog.h                                                -*-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 #ifndef INCLUDED_CT_LVTCLP_VISITLOG
0021 #define INCLUDED_CT_LVTCLP_VISITLOG
0022 
0023 //@PURPOSE: Remember which `clang::Decl`s we have already visited
0024 //
0025 //@CLASSES:
0026 //  lvtclp::VisitLog: Not for use outside lvtclp
0027 //
0028 //@SEE_ALSO: lvtclp::CodebaseDbVisitor
0029 //
0030 //@DESCRIPTION:
0031 //  CodebaseDbVistor consists of callbacks for different clang::Decl kinds.
0032 //  Each callback is for a particular clang::SourceLocation. We can skip any
0033 //  decls we have already seen (e.g. in a header file). The tuple
0034 //  <Decl::Kind, SourceLocation, templateKind> uniquely identifies the callback.
0035 //  We need the Decl::Kind because we can have multiple callbacks for the same
0036 //  source location e.g. VisitFunctionDecl and VisitMethodDecl.
0037 //  We need the templateKind because clang will give us callbacks for each
0038 //  specialization.
0039 
0040 #include <memory>
0041 
0042 #include <clang/AST/DeclBase.h>
0043 
0044 namespace Codethink::lvtclp {
0045 
0046 // ==============================
0047 // class VisitLog
0048 // ==============================
0049 
0050 class VisitLog {
0051     // Store which decl callbacks we have already processed
0052 
0053     // PRIVATE TYPES
0054     struct Private;
0055 
0056     // DATA
0057     std::unique_ptr<Private> d;
0058 
0059   public:
0060     // CREATORS
0061     VisitLog();
0062 
0063     ~VisitLog() noexcept;
0064 
0065     // MANIPULATORS
0066     bool alreadyVisited(const clang::Decl *decl, clang::Decl::Kind kind, int templateKind = -1);
0067     // Returns if we have already visited this decl.
0068     // If we haven't already visited this decl, it is now considered visited
0069 };
0070 
0071 } // end namespace Codethink::lvtclp
0072 
0073 #endif