Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-05-10 08:36:22

0001 //===---------- UsingInserter.h - clang-tidy ----------------------------===//
0002 //
0003 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
0004 // See https://llvm.org/LICENSE.txt for license information.
0005 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
0006 //
0007 //===----------------------------------------------------------------------===//
0008 
0009 #ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_USINGINSERTER_H
0010 #define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_USINGINSERTER_H
0011 
0012 #include "clang/AST/Decl.h"
0013 #include "clang/AST/Stmt.h"
0014 #include "clang/Basic/Diagnostic.h"
0015 #include "clang/Basic/SourceManager.h"
0016 #include <optional>
0017 #include <set>
0018 
0019 namespace clang::tidy::utils {
0020 
0021 // UsingInserter adds using declarations for |QualifiedName| to the surrounding
0022 // function.
0023 // This allows using a shorter name without clobbering other scopes.
0024 class UsingInserter {
0025 public:
0026   UsingInserter(const SourceManager &SourceMgr);
0027 
0028   // Creates a \p using declaration fixit. Returns ``std::nullopt`` on error
0029   // or if the using declaration already exists.
0030   std::optional<FixItHint>
0031   createUsingDeclaration(ASTContext &Context, const Stmt &Statement,
0032                          llvm::StringRef QualifiedName);
0033 
0034   // Returns the unqualified version of the name if there is an
0035   // appropriate using declaration and the qualified name otherwise.
0036   llvm::StringRef getShortName(ASTContext &Context, const Stmt &Statement,
0037                                llvm::StringRef QualifiedName);
0038 
0039 private:
0040   using NameInFunction = std::pair<const FunctionDecl *, std::string>;
0041   const SourceManager &SourceMgr;
0042   std::set<NameInFunction> AddedUsing;
0043 };
0044 
0045 } // namespace clang::tidy::utils
0046 #endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_USINGINSERTER_H