Back to home page

EIC code displayed by LXR

 
 

    


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

0001 //===--- RefactoringOptions.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_REFACTORINGOPTIONS_H
0010 #define LLVM_CLANG_TOOLING_REFACTORING_REFACTORINGOPTIONS_H
0011 
0012 #include "clang/Basic/LLVM.h"
0013 #include "clang/Tooling/Refactoring/RefactoringActionRuleRequirements.h"
0014 #include "clang/Tooling/Refactoring/RefactoringOption.h"
0015 #include "clang/Tooling/Refactoring/RefactoringOptionVisitor.h"
0016 #include "llvm/Support/Error.h"
0017 #include <optional>
0018 #include <type_traits>
0019 
0020 namespace clang {
0021 namespace tooling {
0022 
0023 /// A refactoring option that stores a value of type \c T.
0024 template <typename T,
0025           typename = std::enable_if_t<traits::IsValidOptionType<T>::value>>
0026 class OptionalRefactoringOption : public RefactoringOption {
0027 public:
0028   void passToVisitor(RefactoringOptionVisitor &Visitor) final {
0029     Visitor.visit(*this, Value);
0030   }
0031 
0032   bool isRequired() const override { return false; }
0033 
0034   using ValueType = std::optional<T>;
0035 
0036   const ValueType &getValue() const { return Value; }
0037 
0038 protected:
0039   std::optional<T> Value;
0040 };
0041 
0042 /// A required refactoring option that stores a value of type \c T.
0043 template <typename T,
0044           typename = std::enable_if_t<traits::IsValidOptionType<T>::value>>
0045 class RequiredRefactoringOption : public OptionalRefactoringOption<T> {
0046 public:
0047   using ValueType = T;
0048 
0049   const ValueType &getValue() const {
0050     return *OptionalRefactoringOption<T>::Value;
0051   }
0052   bool isRequired() const final { return true; }
0053 };
0054 
0055 } // end namespace tooling
0056 } // end namespace clang
0057 
0058 #endif // LLVM_CLANG_TOOLING_REFACTORING_REFACTORINGOPTIONS_H