Reland [OffloadBundler] Compress bundles over 4GB (#122307)
[llvm-project.git] / clang-tools-extra / clang-tidy / utils / UsingInserter.h
blob7ff1f0b9792e13b7bff74baa290192dc27897df7
1 //===---------- UsingInserter.h - clang-tidy ----------------------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
9 #ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_USINGINSERTER_H
10 #define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_USINGINSERTER_H
12 #include "clang/AST/Decl.h"
13 #include "clang/AST/Stmt.h"
14 #include "clang/Basic/Diagnostic.h"
15 #include "clang/Basic/SourceManager.h"
16 #include <optional>
17 #include <set>
19 namespace clang::tidy::utils {
21 // UsingInserter adds using declarations for |QualifiedName| to the surrounding
22 // function.
23 // This allows using a shorter name without clobbering other scopes.
24 class UsingInserter {
25 public:
26 UsingInserter(const SourceManager &SourceMgr);
28 // Creates a \p using declaration fixit. Returns ``std::nullopt`` on error
29 // or if the using declaration already exists.
30 std::optional<FixItHint>
31 createUsingDeclaration(ASTContext &Context, const Stmt &Statement,
32 llvm::StringRef QualifiedName);
34 // Returns the unqualified version of the name if there is an
35 // appropriate using declaration and the qualified name otherwise.
36 llvm::StringRef getShortName(ASTContext &Context, const Stmt &Statement,
37 llvm::StringRef QualifiedName);
39 private:
40 using NameInFunction = std::pair<const FunctionDecl *, std::string>;
41 const SourceManager &SourceMgr;
42 std::set<NameInFunction> AddedUsing;
45 } // namespace clang::tidy::utils
46 #endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_USINGINSERTER_H