//===--- VariantValue.h - Polymorphic value type ----------------*- C++ -*-===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// /// /// \file /// Polymorphic value type. /// /// Supports all the types required for dynamic Matcher construction. /// Used by the registry to construct matchers in a generic way. /// //===----------------------------------------------------------------------===// #ifndef LLVM_CLANG_ASTMATCHERS_DYNAMIC_VARIANTVALUE_H #define LLVM_CLANG_ASTMATCHERS_DYNAMIC_VARIANTVALUE_H #include "clang/ASTMatchers/ASTMatchers.h" #include "clang/ASTMatchers/ASTMatchersInternal.h" #include "llvm/ADT/IntrusiveRefCntPtr.h" #include <memory> #include <optional> #include <vector> namespace clang { namespace ast_matchers { namespace dynamic { /// Kind identifier. /// /// It supports all types that VariantValue can contain. class ArgKind { … }; DynTypedMatcher; /// A variant matcher object. /// /// The purpose of this object is to abstract simple and polymorphic matchers /// into a single object type. /// Polymorphic matchers might be implemented as a list of all the possible /// overloads of the matcher. \c VariantMatcher knows how to select the /// appropriate overload when needed. /// To get a real matcher object out of a \c VariantMatcher you can do: /// - getSingleMatcher() which returns a matcher, only if it is not ambiguous /// to decide which matcher to return. Eg. it contains only a single /// matcher, or a polymorphic one with only one overload. /// - hasTypedMatcher<T>()/getTypedMatcher<T>(): These calls will determine if /// the underlying matcher(s) can unambiguously return a Matcher<T>. class VariantMatcher { … }; /// Variant value class. /// /// Basically, a tagged union with value type semantics. /// It is used by the registry as the return value and argument type for the /// matcher factory methods. /// It can be constructed from any of the supported types. It supports /// copy/assignment. /// /// Supported types: /// - \c bool // - \c double /// - \c unsigned /// - \c llvm::StringRef /// - \c VariantMatcher (\c DynTypedMatcher / \c Matcher<T>) class VariantValue { … }; } // end namespace dynamic } // end namespace ast_matchers } // end namespace clang #endif // LLVM_CLANG_ASTMATCHERS_DYNAMIC_VARIANTVALUE_H