Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-05-10 08:37:11

0001 //===--- Extract.h - Clang refactoring library ----------------------------===//
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_TOOLING_REFACTORING_EXTRACT_EXTRACT_H
0010 #define LLVM_CLANG_TOOLING_REFACTORING_EXTRACT_EXTRACT_H
0011 
0012 #include "clang/Tooling/Refactoring/ASTSelection.h"
0013 #include "clang/Tooling/Refactoring/RefactoringActionRules.h"
0014 #include <optional>
0015 
0016 namespace clang {
0017 namespace tooling {
0018 
0019 /// An "Extract Function" refactoring moves code into a new function that's
0020 /// then called from the place where the original code was.
0021 class ExtractFunction final : public SourceChangeRefactoringRule {
0022 public:
0023   /// Initiates the extract function refactoring operation.
0024   ///
0025   /// \param Code     The selected set of statements.
0026   /// \param DeclName The name of the extract function. If None,
0027   ///                 "extracted" is used.
0028   static Expected<ExtractFunction>
0029   initiate(RefactoringRuleContext &Context, CodeRangeASTSelection Code,
0030            std::optional<std::string> DeclName);
0031 
0032   static const RefactoringDescriptor &describe();
0033 
0034 private:
0035   ExtractFunction(CodeRangeASTSelection Code,
0036                   std::optional<std::string> DeclName)
0037       : Code(std::move(Code)),
0038         DeclName(DeclName ? std::move(*DeclName) : "extracted") {}
0039 
0040   Expected<AtomicChanges>
0041   createSourceReplacements(RefactoringRuleContext &Context) override;
0042 
0043   CodeRangeASTSelection Code;
0044 
0045   // FIXME: Account for naming collisions:
0046   //  - error when name is specified by user.
0047   //  - rename to "extractedN" when name is implicit.
0048   std::string DeclName;
0049 };
0050 
0051 } // end namespace tooling
0052 } // end namespace clang
0053 
0054 #endif // LLVM_CLANG_TOOLING_REFACTORING_EXTRACT_EXTRACT_H