r317137 - [ASTMatchers] Fix some Clang-tidy modernize and Include What You Use warnings; other minor fixes (NFC).
Eugene Zelenko via cfe-commits
cfe-commits at lists.llvm.org
Wed Nov 1 16:09:49 PDT 2017
Author: eugenezelenko
Date: Wed Nov 1 16:09:49 2017
New Revision: 317137
URL: http://llvm.org/viewvc/llvm-project?rev=317137&view=rev
Log:
[ASTMatchers] Fix some Clang-tidy modernize and Include What You Use warnings; other minor fixes (NFC).
Modified:
cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h
cfe/trunk/include/clang/ASTMatchers/ASTMatchersInternal.h
cfe/trunk/include/clang/ASTMatchers/Dynamic/Parser.h
cfe/trunk/include/clang/ASTMatchers/Dynamic/Registry.h
cfe/trunk/lib/ASTMatchers/ASTMatchersInternal.cpp
cfe/trunk/lib/ASTMatchers/Dynamic/Marshallers.h
cfe/trunk/lib/ASTMatchers/Dynamic/Parser.cpp
cfe/trunk/lib/ASTMatchers/Dynamic/Registry.cpp
Modified: cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h?rev=317137&r1=317136&r2=317137&view=diff
==============================================================================
--- cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h (original)
+++ cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h Wed Nov 1 16:09:49 2017
@@ -1,4 +1,4 @@
-//===--- ASTMatchers.h - Structural query framework -------------*- C++ -*-===//
+//===- ASTMatchers.h - Structural query framework ---------------*- C++ -*-===//
//
// The LLVM Compiler Infrastructure
//
@@ -46,13 +46,48 @@
#define LLVM_CLANG_ASTMATCHERS_ASTMATCHERS_H
#include "clang/AST/ASTContext.h"
+#include "clang/AST/ASTTypeTraits.h"
+#include "clang/AST/Attr.h"
+#include "clang/AST/Decl.h"
+#include "clang/AST/DeclCXX.h"
#include "clang/AST/DeclFriend.h"
#include "clang/AST/DeclObjC.h"
#include "clang/AST/DeclTemplate.h"
+#include "clang/AST/Expr.h"
+#include "clang/AST/ExprCXX.h"
+#include "clang/AST/ExprObjC.h"
+#include "clang/AST/NestedNameSpecifier.h"
+#include "clang/AST/OperationKinds.h"
+#include "clang/AST/Stmt.h"
+#include "clang/AST/StmtCXX.h"
+#include "clang/AST/StmtObjC.h"
+#include "clang/AST/TemplateBase.h"
+#include "clang/AST/TemplateName.h"
+#include "clang/AST/Type.h"
+#include "clang/AST/TypeLoc.h"
#include "clang/ASTMatchers/ASTMatchersInternal.h"
#include "clang/ASTMatchers/ASTMatchersMacros.h"
+#include "clang/Basic/AttrKinds.h"
+#include "clang/Basic/ExceptionSpecificationType.h"
+#include "clang/Basic/IdentifierTable.h"
+#include "clang/Basic/LLVM.h"
+#include "clang/Basic/SourceManager.h"
+#include "clang/Basic/Specifiers.h"
+#include "clang/Basic/TypeTraits.h"
+#include "llvm/ADT/ArrayRef.h"
+#include "llvm/ADT/SmallVector.h"
+#include "llvm/ADT/StringRef.h"
+#include "llvm/Support/Casting.h"
+#include "llvm/Support/Compiler.h"
+#include "llvm/Support/ErrorHandling.h"
#include "llvm/Support/Regex.h"
+#include <cassert>
+#include <cstddef>
#include <iterator>
+#include <limits>
+#include <string>
+#include <utility>
+#include <vector>
namespace clang {
namespace ast_matchers {
@@ -78,7 +113,7 @@ public:
/// \brief Type of mapping from binding identifiers to bound nodes. This type
/// is an associative container with a key type of \c std::string and a value
/// type of \c clang::ast_type_traits::DynTypedNode
- typedef internal::BoundNodesMap::IDToNodeMap IDToNodeMap;
+ using IDToNodeMap = internal::BoundNodesMap::IDToNodeMap;
/// \brief Retrieve mapping from binding identifiers to bound nodes.
const IDToNodeMap &getMap() const {
@@ -86,13 +121,13 @@ public:
}
private:
+ friend class internal::BoundNodesTreeBuilder;
+
/// \brief Create BoundNodes from a pre-filled map of bindings.
BoundNodes(internal::BoundNodesMap &MyBoundNodes)
: MyBoundNodes(MyBoundNodes) {}
internal::BoundNodesMap MyBoundNodes;
-
- friend class internal::BoundNodesTreeBuilder;
};
/// \brief If the provided matcher matches a node, binds the node to \c ID.
@@ -107,13 +142,13 @@ internal::Matcher<T> id(StringRef ID,
/// \brief Types of matchers for the top-level classes in the AST class
/// hierarchy.
/// @{
-typedef internal::Matcher<Decl> DeclarationMatcher;
-typedef internal::Matcher<Stmt> StatementMatcher;
-typedef internal::Matcher<QualType> TypeMatcher;
-typedef internal::Matcher<TypeLoc> TypeLocMatcher;
-typedef internal::Matcher<NestedNameSpecifier> NestedNameSpecifierMatcher;
-typedef internal::Matcher<NestedNameSpecifierLoc> NestedNameSpecifierLocMatcher;
-typedef internal::Matcher<CXXCtorInitializer> CXXCtorInitializerMatcher;
+using DeclarationMatcher = internal::Matcher<Decl>;
+using StatementMatcher = internal::Matcher<Stmt>;
+using TypeMatcher = internal::Matcher<QualType>;
+using TypeLocMatcher = internal::Matcher<TypeLoc>;
+using NestedNameSpecifierMatcher = internal::Matcher<NestedNameSpecifier>;
+using NestedNameSpecifierLocMatcher = internal::Matcher<NestedNameSpecifierLoc>;
+using CXXCtorInitializerMatcher = internal::Matcher<CXXCtorInitializer>;
/// @}
/// \brief Matches any node.
@@ -2186,23 +2221,23 @@ const internal::VariadicAllOfMatcher<Typ
/// \c b.
///
/// Usable as: Any Matcher
-const internal::VariadicOperatorMatcherFunc<2, UINT_MAX> eachOf = {
- internal::DynTypedMatcher::VO_EachOf
-};
+const internal::VariadicOperatorMatcherFunc<
+ 2, std::numeric_limits<unsigned>::max()>
+ eachOf = {internal::DynTypedMatcher::VO_EachOf};
/// \brief Matches if any of the given matchers matches.
///
/// Usable as: Any Matcher
-const internal::VariadicOperatorMatcherFunc<2, UINT_MAX> anyOf = {
- internal::DynTypedMatcher::VO_AnyOf
-};
+const internal::VariadicOperatorMatcherFunc<
+ 2, std::numeric_limits<unsigned>::max()>
+ anyOf = {internal::DynTypedMatcher::VO_AnyOf};
/// \brief Matches if all given matchers match.
///
/// Usable as: Any Matcher
-const internal::VariadicOperatorMatcherFunc<2, UINT_MAX> allOf = {
- internal::DynTypedMatcher::VO_AllOf
-};
+const internal::VariadicOperatorMatcherFunc<
+ 2, std::numeric_limits<unsigned>::max()>
+ allOf = {internal::DynTypedMatcher::VO_AllOf};
/// \brief Matches sizeof (C99), alignof (C++11) and vec_step (OpenCL)
///
@@ -4004,7 +4039,6 @@ AST_MATCHER_P(UnaryOperator, hasUnaryOpe
/// \code
/// int a = b ?: 1;
/// \endcode
-
AST_POLYMORPHIC_MATCHER_P(hasSourceExpression,
AST_POLYMORPHIC_SUPPORTED_TYPES(CastExpr,
OpaqueValueExpr),
@@ -5677,7 +5711,6 @@ AST_MATCHER_P(ReturnStmt, hasReturnValue
return false;
}
-
/// \brief Matches CUDA kernel call expression.
///
/// Example matches,
@@ -5688,7 +5721,6 @@ const internal::VariadicDynCastAllOfMatc
Stmt,
CUDAKernelCallExpr> cudaKernelCallExpr;
-
/// \brief Matches expressions that resolve to a null pointer constant, such as
/// GNU's __null, C++11's nullptr, or C's NULL macro.
///
@@ -5772,7 +5804,7 @@ AST_MATCHER(NamedDecl, hasExternalFormal
return Node.hasExternalFormalLinkage();
}
-} // end namespace ast_matchers
-} // end namespace clang
+} // namespace ast_matchers
+} // namespace clang
-#endif
+#endif // LLVM_CLANG_ASTMATCHERS_ASTMATCHERS_H
Modified: cfe/trunk/include/clang/ASTMatchers/ASTMatchersInternal.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/ASTMatchers/ASTMatchersInternal.h?rev=317137&r1=317136&r2=317137&view=diff
==============================================================================
--- cfe/trunk/include/clang/ASTMatchers/ASTMatchersInternal.h (original)
+++ cfe/trunk/include/clang/ASTMatchers/ASTMatchersInternal.h Wed Nov 1 16:09:49 2017
@@ -1,4 +1,4 @@
-//===--- ASTMatchersInternal.h - Structural query framework -----*- C++ -*-===//
+//===- ASTMatchersInternal.h - Structural query framework -------*- C++ -*-===//
//
// The LLVM Compiler Infrastructure
//
@@ -38,23 +38,42 @@
#include "clang/AST/ASTTypeTraits.h"
#include "clang/AST/Decl.h"
#include "clang/AST/DeclCXX.h"
-#include "clang/AST/DeclObjC.h"
#include "clang/AST/DeclTemplate.h"
+#include "clang/AST/Expr.h"
#include "clang/AST/ExprCXX.h"
-#include "clang/AST/ExprObjC.h"
+#include "clang/AST/NestedNameSpecifier.h"
#include "clang/AST/Stmt.h"
-#include "clang/AST/StmtCXX.h"
-#include "clang/AST/StmtObjC.h"
+#include "clang/AST/TemplateName.h"
#include "clang/AST/Type.h"
+#include "clang/AST/TypeLoc.h"
+#include "clang/Basic/LLVM.h"
+#include "clang/Basic/OperatorKinds.h"
+#include "llvm/ADT/APFloat.h"
#include "llvm/ADT/ArrayRef.h"
+#include "llvm/ADT/IntrusiveRefCntPtr.h"
+#include "llvm/ADT/None.h"
#include "llvm/ADT/Optional.h"
+#include "llvm/ADT/STLExtras.h"
#include "llvm/ADT/SmallVector.h"
+#include "llvm/ADT/StringRef.h"
+#include "llvm/ADT/iterator.h"
+#include "llvm/Support/Casting.h"
#include "llvm/Support/ManagedStatic.h"
+#include <algorithm>
+#include <cassert>
+#include <cstddef>
+#include <cstdint>
#include <map>
#include <string>
+#include <tuple>
+#include <type_traits>
+#include <utility>
#include <vector>
namespace clang {
+
+class ASTContext;
+
namespace ast_matchers {
class BoundNodes;
@@ -158,7 +177,7 @@ public:
/// Note that we're using std::map here, as for memoization:
/// - we need a comparison operator
/// - we need an assignment operator
- typedef std::map<std::string, ast_type_traits::DynTypedNode> IDToNodeMap;
+ using IDToNodeMap = std::map<std::string, ast_type_traits::DynTypedNode>;
const IDToNodeMap &getMap() const {
return NodeMap;
@@ -188,7 +207,7 @@ public:
/// BoundNodesTree.
class Visitor {
public:
- virtual ~Visitor() {}
+ virtual ~Visitor() = default;
/// \brief Called multiple times during a single call to VisitMatches(...).
///
@@ -248,7 +267,7 @@ class ASTMatchFinder;
class DynMatcherInterface
: public llvm::ThreadSafeRefCountedBase<DynMatcherInterface> {
public:
- virtual ~DynMatcherInterface() {}
+ virtual ~DynMatcherInterface() = default;
/// \brief Returns true if \p DynNode can be matched.
///
@@ -317,26 +336,29 @@ public:
/// \brief Takes ownership of the provided implementation pointer.
template <typename T>
DynTypedMatcher(MatcherInterface<T> *Implementation)
- : AllowBind(false),
- SupportedKind(ast_type_traits::ASTNodeKind::getFromNodeKind<T>()),
+ : SupportedKind(ast_type_traits::ASTNodeKind::getFromNodeKind<T>()),
RestrictKind(SupportedKind), Implementation(Implementation) {}
/// \brief Construct from a variadic function.
enum VariadicOperator {
/// \brief Matches nodes for which all provided matchers match.
VO_AllOf,
+
/// \brief Matches nodes for which at least one of the provided matchers
/// matches.
VO_AnyOf,
+
/// \brief Matches nodes for which at least one of the provided matchers
/// matches, but doesn't stop at the first match.
VO_EachOf,
+
/// \brief Matches nodes that do not match the provided matcher.
///
/// Uses the variadic matcher interface, but fails if
/// InnerMatchers.size() != 1.
VO_UnaryNot
};
+
static DynTypedMatcher
constructVariadic(VariadicOperator Op,
ast_type_traits::ASTNodeKind SupportedKind,
@@ -382,7 +404,7 @@ public:
/// include both in the ID to make it unique.
///
/// \c MatcherIDType supports operator< and provides strict weak ordering.
- typedef std::pair<ast_type_traits::ASTNodeKind, uint64_t> MatcherIDType;
+ using MatcherIDType = std::pair<ast_type_traits::ASTNodeKind, uint64_t>;
MatcherIDType getID() const {
/// FIXME: Document the requirements this imposes on matcher
/// implementations (no new() implementation_ during a Matches()).
@@ -428,13 +450,12 @@ private:
DynTypedMatcher(ast_type_traits::ASTNodeKind SupportedKind,
ast_type_traits::ASTNodeKind RestrictKind,
IntrusiveRefCntPtr<DynMatcherInterface> Implementation)
- : AllowBind(false),
- SupportedKind(SupportedKind),
- RestrictKind(RestrictKind),
+ : SupportedKind(SupportedKind), RestrictKind(RestrictKind),
Implementation(std::move(Implementation)) {}
- bool AllowBind;
+ bool AllowBind = false;
ast_type_traits::ASTNodeKind SupportedKind;
+
/// \brief A potentially stricter node kind.
///
/// It allows to perform implicit and dynamic cast of matchers without
@@ -545,6 +566,7 @@ public:
private:
// For Matcher<T> <=> Matcher<U> conversions.
template <typename U> friend class Matcher;
+
// For DynTypedMatcher::unconditionalConvertTo<T>.
friend class DynTypedMatcher;
@@ -618,8 +640,8 @@ bool matchesFirstInPointerRange(const Ma
// Metafunction to determine if type T has a member called getDecl.
template <typename Ty>
class has_getDecl {
- typedef char yes[1];
- typedef char no[2];
+ using yes = char[1];
+ using no = char[2];
template <typename Inner>
static yes& test(Inner *I, decltype(I->getDecl()) * = nullptr);
@@ -741,7 +763,6 @@ private:
/// matcher matches on it.
bool matchesSpecialized(const Type &Node, ASTMatchFinder *Finder,
BoundNodesTreeBuilder *Builder) const {
-
// DeducedType does not have declarations of its own, so
// match the deduced type instead.
const Type *EffectiveType = &Node;
@@ -917,6 +938,7 @@ public:
enum TraversalKind {
/// Will traverse any child nodes.
TK_AsIs,
+
/// Will not traverse implicit casts and parentheses.
TK_IgnoreImplicitCastsAndParentheses
};
@@ -925,6 +947,7 @@ public:
enum BindKind {
/// Stop at the first match and only bind the first match.
BK_First,
+
/// Create results for all combinations of bindings that match.
BK_All
};
@@ -933,11 +956,12 @@ public:
enum AncestorMatchMode {
/// All ancestors.
AMM_All,
+
/// Direct parent only.
AMM_ParentOnly
};
- virtual ~ASTMatchFinder() {}
+ virtual ~ASTMatchFinder() = default;
/// \brief Returns true if the given class is directly or indirectly derived
/// from a base type matching \c base.
@@ -960,7 +984,7 @@ public:
std::is_base_of<TypeLoc, T>::value ||
std::is_base_of<QualType, T>::value,
"unsupported type for recursive matching");
- return matchesChildOf(ast_type_traits::DynTypedNode::create(Node),
+ return matchesChildOf(ast_type_traits::DynTypedNode::create(Node),
Matcher, Builder, Traverse, Bind);
}
@@ -1023,17 +1047,17 @@ template <typename... Ts> struct TypeLis
template <typename T1, typename... Ts> struct TypeList<T1, Ts...> {
/// \brief The first type on the list.
- typedef T1 head;
+ using head = T1;
/// \brief A sublist with the tail. ie everything but the head.
///
/// This type is used to do recursion. TypeList<>/EmptyTypeList indicates the
/// end of the list.
- typedef TypeList<Ts...> tail;
+ using tail = TypeList<Ts...>;
};
/// \brief The empty type list.
-typedef TypeList<> EmptyTypeList;
+using EmptyTypeList = TypeList<>;
/// \brief Helper meta-function to determine if some type \c T is present or
/// a parent type in the list.
@@ -1051,8 +1075,9 @@ struct TypeListContainsSuperOf<EmptyType
/// \brief A "type list" that contains all types.
///
/// Useful for matchers like \c anything and \c unless.
-typedef TypeList<Decl, Stmt, NestedNameSpecifier, NestedNameSpecifierLoc,
- QualType, Type, TypeLoc, CXXCtorInitializer> AllNodeBaseTypes;
+using AllNodeBaseTypes =
+ TypeList<Decl, Stmt, NestedNameSpecifier, NestedNameSpecifierLoc, QualType,
+ Type, TypeLoc, CXXCtorInitializer>;
/// \brief Helper meta-function to extract the argument out of a function of
/// type void(Arg).
@@ -1060,21 +1085,22 @@ typedef TypeList<Decl, Stmt, NestedNameS
/// See AST_POLYMORPHIC_SUPPORTED_TYPES for details.
template <class T> struct ExtractFunctionArgMeta;
template <class T> struct ExtractFunctionArgMeta<void(T)> {
- typedef T type;
+ using type = T;
};
/// \brief Default type lists for ArgumentAdaptingMatcher matchers.
-typedef AllNodeBaseTypes AdaptativeDefaultFromTypes;
-typedef TypeList<Decl, Stmt, NestedNameSpecifier, NestedNameSpecifierLoc,
- TypeLoc, QualType> AdaptativeDefaultToTypes;
+using AdaptativeDefaultFromTypes = AllNodeBaseTypes;
+using AdaptativeDefaultToTypes =
+ TypeList<Decl, Stmt, NestedNameSpecifier, NestedNameSpecifierLoc, TypeLoc,
+ QualType>;
/// \brief All types that are supported by HasDeclarationMatcher above.
-typedef TypeList<CallExpr, CXXConstructExpr, CXXNewExpr, DeclRefExpr, EnumType,
- ElaboratedType, InjectedClassNameType, LabelStmt,
- AddrLabelExpr, MemberExpr, QualType, RecordType, TagType,
- TemplateSpecializationType, TemplateTypeParmType, TypedefType,
- UnresolvedUsingType>
- HasDeclarationSupportedTypes;
+using HasDeclarationSupportedTypes =
+ TypeList<CallExpr, CXXConstructExpr, CXXNewExpr, DeclRefExpr, EnumType,
+ ElaboratedType, InjectedClassNameType, LabelStmt, AddrLabelExpr,
+ MemberExpr, QualType, RecordType, TagType,
+ TemplateSpecializationType, TemplateTypeParmType, TypedefType,
+ UnresolvedUsingType>;
/// \brief Converts a \c Matcher<T> to a matcher of desired type \c To by
/// "adapting" a \c To into a \c T.
@@ -1098,7 +1124,7 @@ struct ArgumentAdaptingMatcherFunc {
explicit Adaptor(const Matcher<T> &InnerMatcher)
: InnerMatcher(InnerMatcher) {}
- typedef ToTypes ReturnTypes;
+ using ReturnTypes = ToTypes;
template <typename To> operator Matcher<To>() const {
return Matcher<To>(new ArgumentAdapterT<To, T>(InnerMatcher));
@@ -1135,7 +1161,8 @@ template <template <typename T> class Ma
typename ReturnTypesF = void(AllNodeBaseTypes)>
class PolymorphicMatcherWithParam0 {
public:
- typedef typename ExtractFunctionArgMeta<ReturnTypesF>::type ReturnTypes;
+ using ReturnTypes = typename ExtractFunctionArgMeta<ReturnTypesF>::type;
+
template <typename T>
operator Matcher<T>() const {
static_assert(TypeListContainsSuperOf<ReturnTypes, T>::value,
@@ -1152,7 +1179,7 @@ public:
explicit PolymorphicMatcherWithParam1(const P1 &Param1)
: Param1(Param1) {}
- typedef typename ExtractFunctionArgMeta<ReturnTypesF>::type ReturnTypes;
+ using ReturnTypes = typename ExtractFunctionArgMeta<ReturnTypesF>::type;
template <typename T>
operator Matcher<T>() const {
@@ -1173,7 +1200,7 @@ public:
PolymorphicMatcherWithParam2(const P1 &Param1, const P2 &Param2)
: Param1(Param1), Param2(Param2) {}
- typedef typename ExtractFunctionArgMeta<ReturnTypesF>::type ReturnTypes;
+ using ReturnTypes = typename ExtractFunctionArgMeta<ReturnTypesF>::type;
template <typename T>
operator Matcher<T>() const {
@@ -1192,8 +1219,8 @@ private:
/// This is useful when a matcher syntactically requires a child matcher,
/// but the context doesn't care. See for example: anything().
class TrueMatcher {
- public:
- typedef AllNodeBaseTypes ReturnTypes;
+public:
+ using ReturnTypes = AllNodeBaseTypes;
template <typename T>
operator Matcher<T>() const {
@@ -1239,7 +1266,6 @@ public:
/// ChildT must be an AST base type.
template <typename T, typename ChildT>
class HasMatcher : public WrapperMatcherInterface<T> {
-
public:
explicit HasMatcher(const Matcher<ChildT> &ChildMatcher)
: HasMatcher::WrapperMatcherInterface(ChildMatcher) {}
@@ -1333,7 +1359,7 @@ template<typename T>
BindableMatcher<T> makeAllOfComposite(
ArrayRef<const Matcher<T> *> InnerMatchers) {
// For the size() == 0 case, we return a "true" matcher.
- if (InnerMatchers.size() == 0) {
+ if (InnerMatchers.empty()) {
return BindableMatcher<T>(TrueMatcher());
}
// For the size() == 1 case, we simply return that one matcher.
@@ -1342,7 +1368,8 @@ BindableMatcher<T> makeAllOfComposite(
return BindableMatcher<T>(*InnerMatchers[0]);
}
- typedef llvm::pointee_iterator<const Matcher<T> *const *> PI;
+ using PI = llvm::pointee_iterator<const Matcher<T> *const *>;
+
std::vector<DynTypedMatcher> DynMatchers(PI(InnerMatchers.begin()),
PI(InnerMatchers.end()));
return BindableMatcher<T>(
@@ -1635,12 +1662,13 @@ template <typename InnerTBase,
typename ReturnTypesF>
class TypeTraversePolymorphicMatcher {
private:
- typedef TypeTraversePolymorphicMatcher<InnerTBase, Getter, MatcherImpl,
- ReturnTypesF> Self;
+ using Self = TypeTraversePolymorphicMatcher<InnerTBase, Getter, MatcherImpl,
+ ReturnTypesF>;
+
static Self create(ArrayRef<const Matcher<InnerTBase> *> InnerMatchers);
public:
- typedef typename ExtractFunctionArgMeta<ReturnTypesF>::type ReturnTypes;
+ using ReturnTypes = typename ExtractFunctionArgMeta<ReturnTypesF>::type;
explicit TypeTraversePolymorphicMatcher(
ArrayRef<const Matcher<InnerTBase> *> InnerMatchers)
@@ -1667,6 +1695,7 @@ private:
template <typename Matcher, Matcher (*Func)()> class MemoizedMatcher {
struct Wrapper {
Wrapper() : M(Func()) {}
+
Matcher M;
};
@@ -1712,6 +1741,7 @@ struct NotEqualsBoundNodePredicate {
bool operator()(const internal::BoundNodesMap &Nodes) const {
return Nodes.getNode(ID) != Node;
}
+
std::string ID;
ast_type_traits::DynTypedNode Node;
};
@@ -1767,9 +1797,10 @@ CompoundStmtMatcher<StmtExpr>::get(const
return Node.getSubStmt();
}
+} // namespace internal
+
+} // namespace ast_matchers
-} // end namespace internal
-} // end namespace ast_matchers
-} // end namespace clang
+} // namespace clang
#endif // LLVM_CLANG_ASTMATCHERS_ASTMATCHERSINTERNAL_H
Modified: cfe/trunk/include/clang/ASTMatchers/Dynamic/Parser.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/ASTMatchers/Dynamic/Parser.h?rev=317137&r1=317136&r2=317137&view=diff
==============================================================================
--- cfe/trunk/include/clang/ASTMatchers/Dynamic/Parser.h (original)
+++ cfe/trunk/include/clang/ASTMatchers/Dynamic/Parser.h Wed Nov 1 16:09:49 2017
@@ -1,4 +1,4 @@
-//===--- Parser.h - Matcher expression parser -----*- C++ -*-===//
+//===- Parser.h - Matcher expression parser ---------------------*- C++ -*-===//
//
// The LLVM Compiler Infrastructure
//
@@ -6,7 +6,7 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-///
+//
/// \file
/// \brief Simple matcher expression parser.
///
@@ -30,24 +30,28 @@
/// <Identifier> := [a-zA-Z]+
/// <ArgumentList> := <Expression> | <Expression>,<ArgumentList>
/// \endcode
-///
+//
//===----------------------------------------------------------------------===//
#ifndef LLVM_CLANG_ASTMATCHERS_DYNAMIC_PARSER_H
#define LLVM_CLANG_ASTMATCHERS_DYNAMIC_PARSER_H
-#include "clang/ASTMatchers/Dynamic/Diagnostics.h"
+#include "clang/ASTMatchers/ASTMatchersInternal.h"
#include "clang/ASTMatchers/Dynamic/Registry.h"
#include "clang/ASTMatchers/Dynamic/VariantValue.h"
-#include "clang/Basic/LLVM.h"
#include "llvm/ADT/ArrayRef.h"
#include "llvm/ADT/Optional.h"
+#include "llvm/ADT/StringMap.h"
#include "llvm/ADT/StringRef.h"
+#include <utility>
+#include <vector>
namespace clang {
namespace ast_matchers {
namespace dynamic {
+class Diagnostics;
+
/// \brief Matcher expression parser.
class Parser {
public:
@@ -124,8 +128,8 @@ public:
/// \brief Sema implementation that uses the matcher registry to process the
/// tokens.
class RegistrySema : public Parser::Sema {
- public:
- ~RegistrySema() override;
+ public:
+ ~RegistrySema() override;
llvm::Optional<MatcherCtor>
lookupMatcherCtor(StringRef MatcherName) override;
@@ -143,7 +147,7 @@ public:
getMatcherCompletions(llvm::ArrayRef<ArgKind> AcceptedTypes) override;
};
- typedef llvm::StringMap<VariantValue> NamedValueMap;
+ using NamedValueMap = llvm::StringMap<VariantValue>;
/// \brief Parse a matcher expression.
///
@@ -247,13 +251,14 @@ private:
const NamedValueMap *const NamedValues;
Diagnostics *const Error;
- typedef std::vector<std::pair<MatcherCtor, unsigned> > ContextStackTy;
+ using ContextStackTy = std::vector<std::pair<MatcherCtor, unsigned>>;
+
ContextStackTy ContextStack;
std::vector<MatcherCompletion> Completions;
};
-} // namespace dynamic
-} // namespace ast_matchers
-} // namespace clang
+} // namespace dynamic
+} // namespace ast_matchers
+} // namespace clang
-#endif // LLVM_CLANG_AST_MATCHERS_DYNAMIC_PARSER_H
+#endif // LLVM_CLANG_AST_MATCHERS_DYNAMIC_PARSER_H
Modified: cfe/trunk/include/clang/ASTMatchers/Dynamic/Registry.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/ASTMatchers/Dynamic/Registry.h?rev=317137&r1=317136&r2=317137&view=diff
==============================================================================
--- cfe/trunk/include/clang/ASTMatchers/Dynamic/Registry.h (original)
+++ cfe/trunk/include/clang/ASTMatchers/Dynamic/Registry.h Wed Nov 1 16:09:49 2017
@@ -1,4 +1,4 @@
-//===--- Registry.h - Matcher registry --------------------------*- C++ -*-===//
+//===- Registry.h - Matcher registry ----------------------------*- C++ -*-===//
//
// The LLVM Compiler Infrastructure
//
@@ -6,12 +6,12 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-///
+//
/// \file
/// \brief Registry of all known matchers.
///
/// The registry provides a generic interface to construct any matcher by name.
-///
+//
//===----------------------------------------------------------------------===//
#ifndef LLVM_CLANG_ASTMATCHERS_DYNAMIC_REGISTRY_H
@@ -34,9 +34,9 @@ namespace internal {
class MatcherDescriptor;
-} // end namespace internal
+} // namespace internal
-typedef const internal::MatcherDescriptor *MatcherCtor;
+using MatcherCtor = const internal::MatcherDescriptor *;
struct MatcherCompletion {
MatcherCompletion() = default;
@@ -129,8 +129,8 @@ public:
Diagnostics *Error);
};
-} // end namespace dynamic
-} // end namespace ast_matchers
-} // end namespace clang
+} // namespace dynamic
+} // namespace ast_matchers
+} // namespace clang
#endif // LLVM_CLANG_AST_MATCHERS_DYNAMIC_REGISTRY_H
Modified: cfe/trunk/lib/ASTMatchers/ASTMatchersInternal.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/ASTMatchers/ASTMatchersInternal.cpp?rev=317137&r1=317136&r2=317137&view=diff
==============================================================================
--- cfe/trunk/lib/ASTMatchers/ASTMatchersInternal.cpp (original)
+++ cfe/trunk/lib/ASTMatchers/ASTMatchersInternal.cpp Wed Nov 1 16:09:49 2017
@@ -1,4 +1,4 @@
-//===--- ASTMatchersInternal.cpp - Structural query framework -------------===//
+//===- ASTMatchersInternal.cpp - Structural query framework ---------------===//
//
// The LLVM Compiler Infrastructure
//
@@ -11,11 +11,30 @@
//
//===----------------------------------------------------------------------===//
-#include "clang/ASTMatchers/ASTMatchers.h"
#include "clang/ASTMatchers/ASTMatchersInternal.h"
+#include "clang/AST/ASTContext.h"
+#include "clang/AST/ASTTypeTraits.h"
+#include "clang/AST/Decl.h"
+#include "clang/AST/DeclTemplate.h"
+#include "clang/AST/PrettyPrinter.h"
+#include "clang/ASTMatchers/ASTMatchers.h"
+#include "clang/Basic/LLVM.h"
+#include "llvm/ADT/ArrayRef.h"
+#include "llvm/ADT/IntrusiveRefCntPtr.h"
+#include "llvm/ADT/None.h"
#include "llvm/ADT/SmallString.h"
#include "llvm/ADT/SmallVector.h"
+#include "llvm/ADT/StringRef.h"
+#include "llvm/Support/Casting.h"
+#include "llvm/Support/ErrorHandling.h"
#include "llvm/Support/ManagedStatic.h"
+#include "llvm/Support/raw_ostream.h"
+#include <algorithm>
+#include <cassert>
+#include <cstddef>
+#include <string>
+#include <utility>
+#include <vector>
namespace clang {
namespace ast_matchers {
@@ -40,7 +59,6 @@ bool AnyOfVariadicOperator(const ast_typ
BoundNodesTreeBuilder *Builder,
ArrayRef<DynTypedMatcher> InnerMatchers);
-
void BoundNodesTreeBuilder::visitMatches(Visitor *ResultVisitor) {
if (Bindings.empty())
Bindings.push_back(BoundNodesMap());
@@ -51,7 +69,7 @@ void BoundNodesTreeBuilder::visitMatches
namespace {
-typedef bool (*VariadicOperatorFunction)(
+using VariadicOperatorFunction = bool (*)(
const ast_type_traits::DynTypedNode &DynNode, ASTMatchFinder *Finder,
BoundNodesTreeBuilder *Builder, ArrayRef<DynTypedMatcher> InnerMatchers);
@@ -100,20 +118,22 @@ public:
TrueMatcherImpl() {
Retain(); // Reference count will never become zero.
}
+
bool dynMatches(const ast_type_traits::DynTypedNode &, ASTMatchFinder *,
BoundNodesTreeBuilder *) const override {
return true;
}
};
-static llvm::ManagedStatic<TrueMatcherImpl> TrueMatcherInstance;
-} // namespace
+} // namespace
+
+static llvm::ManagedStatic<TrueMatcherImpl> TrueMatcherInstance;
DynTypedMatcher DynTypedMatcher::constructVariadic(
DynTypedMatcher::VariadicOperator Op,
ast_type_traits::ASTNodeKind SupportedKind,
std::vector<DynTypedMatcher> InnerMatchers) {
- assert(InnerMatchers.size() > 0 && "Array must not be empty.");
+ assert(!InnerMatchers.empty() && "Array must not be empty.");
assert(std::all_of(InnerMatchers.begin(), InnerMatchers.end(),
[SupportedKind](const DynTypedMatcher &M) {
return M.canConvertTo(SupportedKind);
@@ -314,9 +334,7 @@ HasNameMatcher::HasNameMatcher(std::vect
#endif
}
-namespace {
-
-bool consumeNameSuffix(StringRef &FullName, StringRef Suffix) {
+static bool consumeNameSuffix(StringRef &FullName, StringRef Suffix) {
StringRef Name = FullName;
if (!Name.endswith(Suffix))
return false;
@@ -330,7 +348,8 @@ bool consumeNameSuffix(StringRef &FullNa
return true;
}
-StringRef getNodeName(const NamedDecl &Node, llvm::SmallString<128> &Scratch) {
+static StringRef getNodeName(const NamedDecl &Node,
+ llvm::SmallString<128> &Scratch) {
// Simple name.
if (Node.getIdentifier())
return Node.getName();
@@ -346,7 +365,8 @@ StringRef getNodeName(const NamedDecl &N
return "(anonymous)";
}
-StringRef getNodeName(const RecordDecl &Node, llvm::SmallString<128> &Scratch) {
+static StringRef getNodeName(const RecordDecl &Node,
+ llvm::SmallString<128> &Scratch) {
if (Node.getIdentifier()) {
return Node.getName();
}
@@ -354,11 +374,12 @@ StringRef getNodeName(const RecordDecl &
return ("(anonymous " + Node.getKindName() + ")").toStringRef(Scratch);
}
-StringRef getNodeName(const NamespaceDecl &Node,
- llvm::SmallString<128> &Scratch) {
+static StringRef getNodeName(const NamespaceDecl &Node,
+ llvm::SmallString<128> &Scratch) {
return Node.isAnonymousNamespace() ? "(anonymous namespace)" : Node.getName();
}
+namespace {
class PatternSet {
public:
@@ -397,10 +418,11 @@ private:
StringRef P;
bool IsFullyQualified;
};
+
llvm::SmallVector<Pattern, 8> Patterns;
};
-} // namespace
+} // namespace
bool HasNameMatcher::matchesNodeUnqualified(const NamedDecl &Node) const {
assert(UseUnqualifiedMatch);
Modified: cfe/trunk/lib/ASTMatchers/Dynamic/Marshallers.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/ASTMatchers/Dynamic/Marshallers.h?rev=317137&r1=317136&r2=317137&view=diff
==============================================================================
--- cfe/trunk/lib/ASTMatchers/Dynamic/Marshallers.h (original)
+++ cfe/trunk/lib/ASTMatchers/Dynamic/Marshallers.h Wed Nov 1 16:09:49 2017
@@ -1,4 +1,4 @@
-//===--- Marshallers.h - Generic matcher function marshallers ---*- C++ -*-===//
+//===- Marshallers.h - Generic matcher function marshallers -----*- C++ -*-===//
//
// The LLVM Compiler Infrastructure
//
@@ -6,7 +6,7 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-///
+//
/// \file
/// \brief Functions templates and classes to wrap matcher construct functions.
///
@@ -14,18 +14,33 @@
/// marshalling layer on top of matcher construct functions.
/// These are used by the registry to export all marshaller constructors with
/// the same generic interface.
-///
+//
//===----------------------------------------------------------------------===//
#ifndef LLVM_CLANG_LIB_ASTMATCHERS_DYNAMIC_MARSHALLERS_H
#define LLVM_CLANG_LIB_ASTMATCHERS_DYNAMIC_MARSHALLERS_H
-#include "clang/ASTMatchers/ASTMatchers.h"
+#include "clang/AST/ASTTypeTraits.h"
+#include "clang/AST/OperationKinds.h"
+#include "clang/ASTMatchers/ASTMatchersInternal.h"
#include "clang/ASTMatchers/Dynamic/Diagnostics.h"
#include "clang/ASTMatchers/Dynamic/VariantValue.h"
+#include "clang/Basic/AttrKinds.h"
#include "clang/Basic/LLVM.h"
+#include "llvm/ADT/ArrayRef.h"
+#include "llvm/ADT/None.h"
#include "llvm/ADT/STLExtras.h"
+#include "llvm/ADT/StringRef.h"
+#include "llvm/ADT/StringSwitch.h"
+#include "llvm/ADT/Twine.h"
+#include <cassert>
+#include <cstddef>
+#include <iterator>
+#include <limits>
+#include <memory>
#include <string>
+#include <utility>
+#include <vector>
namespace clang {
namespace ast_matchers {
@@ -41,9 +56,11 @@ template <class T> struct ArgTypeTraits<
template <> struct ArgTypeTraits<std::string> {
static bool is(const VariantValue &Value) { return Value.isString(); }
+
static const std::string &get(const VariantValue &Value) {
return Value.getString();
}
+
static ArgKind getKind() {
return ArgKind(ArgKind::AK_String);
}
@@ -53,13 +70,15 @@ template <>
struct ArgTypeTraits<StringRef> : public ArgTypeTraits<std::string> {
};
-template <class T> struct ArgTypeTraits<ast_matchers::internal::Matcher<T> > {
+template <class T> struct ArgTypeTraits<ast_matchers::internal::Matcher<T>> {
static bool is(const VariantValue &Value) {
return Value.isMatcher() && Value.getMatcher().hasTypedMatcher<T>();
}
+
static ast_matchers::internal::Matcher<T> get(const VariantValue &Value) {
return Value.getMatcher().getTypedMatcher<T>();
}
+
static ArgKind getKind() {
return ArgKind(ast_type_traits::ASTNodeKind::getFromNodeKind<T>());
}
@@ -67,9 +86,11 @@ template <class T> struct ArgTypeTraits<
template <> struct ArgTypeTraits<bool> {
static bool is(const VariantValue &Value) { return Value.isBoolean(); }
+
static bool get(const VariantValue &Value) {
return Value.getBoolean();
}
+
static ArgKind getKind() {
return ArgKind(ArgKind::AK_Boolean);
}
@@ -77,9 +98,11 @@ template <> struct ArgTypeTraits<bool> {
template <> struct ArgTypeTraits<double> {
static bool is(const VariantValue &Value) { return Value.isDouble(); }
+
static double get(const VariantValue &Value) {
return Value.getDouble();
}
+
static ArgKind getKind() {
return ArgKind(ArgKind::AK_Double);
}
@@ -87,9 +110,11 @@ template <> struct ArgTypeTraits<double>
template <> struct ArgTypeTraits<unsigned> {
static bool is(const VariantValue &Value) { return Value.isUnsigned(); }
+
static unsigned get(const VariantValue &Value) {
return Value.getUnsigned();
}
+
static ArgKind getKind() {
return ArgKind(ArgKind::AK_Unsigned);
}
@@ -103,23 +128,26 @@ private:
#include "clang/Basic/AttrList.inc"
.Default(attr::Kind(-1));
}
+
public:
static bool is(const VariantValue &Value) {
return Value.isString() &&
getAttrKind(Value.getString()) != attr::Kind(-1);
}
+
static attr::Kind get(const VariantValue &Value) {
return getAttrKind(Value.getString());
}
+
static ArgKind getKind() {
return ArgKind(ArgKind::AK_String);
}
};
-template <> struct ArgTypeTraits<clang::CastKind> {
+template <> struct ArgTypeTraits<CastKind> {
private:
- static clang::CastKind getCastKind(llvm::StringRef AttrKind) {
- return llvm::StringSwitch<clang::CastKind>(AttrKind)
+ static CastKind getCastKind(llvm::StringRef AttrKind) {
+ return llvm::StringSwitch<CastKind>(AttrKind)
#define CAST_OPERATION(Name) .Case( #Name, CK_##Name)
#include "clang/AST/OperationKinds.def"
.Default(CK_Invalid);
@@ -130,9 +158,11 @@ public:
return Value.isString() &&
getCastKind(Value.getString()) != CK_Invalid;
}
- static clang::CastKind get(const VariantValue &Value) {
+
+ static CastKind get(const VariantValue &Value) {
return getCastKind(Value.getString());
}
+
static ArgKind getKind() {
return ArgKind(ArgKind::AK_String);
}
@@ -144,7 +174,8 @@ public:
/// arguments, and various other methods for type introspection.
class MatcherDescriptor {
public:
- virtual ~MatcherDescriptor() {}
+ virtual ~MatcherDescriptor() = default;
+
virtual VariantMatcher create(SourceRange NameRange,
ArrayRef<ParserValue> Args,
Diagnostics *Error) const = 0;
@@ -201,11 +232,11 @@ inline bool isRetKindConvertibleTo(
/// their types, unpacking them and calling the underlying function.
class FixedArgCountMatcherDescriptor : public MatcherDescriptor {
public:
- typedef VariantMatcher (*MarshallerType)(void (*Func)(),
- StringRef MatcherName,
- SourceRange NameRange,
- ArrayRef<ParserValue> Args,
- Diagnostics *Error);
+ using MarshallerType = VariantMatcher (*)(void (*Func)(),
+ StringRef MatcherName,
+ SourceRange NameRange,
+ ArrayRef<ParserValue> Args,
+ Diagnostics *Error);
/// \param Marshaller Function to unpack the arguments and call \c Func
/// \param Func Matcher construct function. This is the function that
@@ -229,10 +260,12 @@ public:
bool isVariadic() const override { return false; }
unsigned getNumArgs() const override { return ArgKinds.size(); }
+
void getArgKinds(ast_type_traits::ASTNodeKind ThisKind, unsigned ArgNo,
std::vector<ArgKind> &Kinds) const override {
Kinds.push_back(ArgKinds[ArgNo]);
}
+
bool isConvertibleTo(
ast_type_traits::ASTNodeKind Kind, unsigned *Specificity,
ast_type_traits::ASTNodeKind *LeastDerivedKind) const override {
@@ -303,14 +336,14 @@ struct BuildReturnTypeVector {
};
template <typename T>
-struct BuildReturnTypeVector<ast_matchers::internal::Matcher<T> > {
+struct BuildReturnTypeVector<ast_matchers::internal::Matcher<T>> {
static void build(std::vector<ast_type_traits::ASTNodeKind> &RetTypes) {
RetTypes.push_back(ast_type_traits::ASTNodeKind::getFromNodeKind<T>());
}
};
template <typename T>
-struct BuildReturnTypeVector<ast_matchers::internal::BindableMatcher<T> > {
+struct BuildReturnTypeVector<ast_matchers::internal::BindableMatcher<T>> {
static void build(std::vector<ast_type_traits::ASTNodeKind> &RetTypes) {
RetTypes.push_back(ast_type_traits::ASTNodeKind::getFromNodeKind<T>());
}
@@ -326,7 +359,8 @@ variadicMatcherDescriptor(StringRef Matc
bool HasError = false;
for (size_t i = 0, e = Args.size(); i != e; ++i) {
- typedef ArgTypeTraits<ArgT> ArgTraits;
+ using ArgTraits = ArgTypeTraits<ArgT>;
+
const ParserValue &Arg = Args[i];
const VariantValue &Value = Arg.Value;
if (!ArgTraits::is(Value)) {
@@ -360,10 +394,10 @@ variadicMatcherDescriptor(StringRef Matc
/// object file.
class VariadicFuncMatcherDescriptor : public MatcherDescriptor {
public:
- typedef VariantMatcher (*RunFunc)(StringRef MatcherName,
- SourceRange NameRange,
- ArrayRef<ParserValue> Args,
- Diagnostics *Error);
+ using RunFunc = VariantMatcher (*)(StringRef MatcherName,
+ SourceRange NameRange,
+ ArrayRef<ParserValue> Args,
+ Diagnostics *Error);
template <typename ResultT, typename ArgT,
ResultT (*F)(ArrayRef<const ArgT *>)>
@@ -384,10 +418,12 @@ public:
bool isVariadic() const override { return true; }
unsigned getNumArgs() const override { return 0; }
+
void getArgKinds(ast_type_traits::ASTNodeKind ThisKind, unsigned ArgNo,
std::vector<ArgKind> &Kinds) const override {
Kinds.push_back(ArgsKind);
}
+
bool isConvertibleTo(
ast_type_traits::ASTNodeKind Kind, unsigned *Specificity,
ast_type_traits::ASTNodeKind *LeastDerivedKind) const override {
@@ -458,7 +494,7 @@ static VariantMatcher matcherMarshall0(v
SourceRange NameRange,
ArrayRef<ParserValue> Args,
Diagnostics *Error) {
- typedef ReturnType (*FuncType)();
+ using FuncType = ReturnType (*)();
CHECK_ARG_COUNT(0);
return outvalueToVariantMatcher(reinterpret_cast<FuncType>(Func)());
}
@@ -469,7 +505,7 @@ static VariantMatcher matcherMarshall1(v
SourceRange NameRange,
ArrayRef<ParserValue> Args,
Diagnostics *Error) {
- typedef ReturnType (*FuncType)(ArgType1);
+ using FuncType = ReturnType (*)(ArgType1);
CHECK_ARG_COUNT(1);
CHECK_ARG_TYPE(0, ArgType1);
return outvalueToVariantMatcher(reinterpret_cast<FuncType>(Func)(
@@ -482,7 +518,7 @@ static VariantMatcher matcherMarshall2(v
SourceRange NameRange,
ArrayRef<ParserValue> Args,
Diagnostics *Error) {
- typedef ReturnType (*FuncType)(ArgType1, ArgType2);
+ using FuncType = ReturnType (*)(ArgType1, ArgType2);
CHECK_ARG_COUNT(2);
CHECK_ARG_TYPE(0, ArgType1);
CHECK_ARG_TYPE(1, ArgType2);
@@ -507,8 +543,8 @@ public:
}
private:
- typedef ast_matchers::internal::ArgumentAdaptingMatcherFunc<
- ArgumentAdapterT, FromTypes, ToTypes> AdaptativeFunc;
+ using AdaptativeFunc = ast_matchers::internal::ArgumentAdaptingMatcherFunc<
+ ArgumentAdapterT, FromTypes, ToTypes>;
/// \brief End case for the recursion
static void collect(ast_matchers::internal::EmptyTypeList) {}
@@ -534,7 +570,7 @@ public:
: Overloads(std::make_move_iterator(Callbacks.begin()),
std::make_move_iterator(Callbacks.end())) {}
- ~OverloadedMatcherDescriptor() override {}
+ ~OverloadedMatcherDescriptor() override = default;
VariantMatcher create(SourceRange NameRange,
ArrayRef<ParserValue> Args,
@@ -604,7 +640,8 @@ private:
/// \brief Variadic operator marshaller function.
class VariadicOperatorMatcherDescriptor : public MatcherDescriptor {
public:
- typedef DynTypedMatcher::VariadicOperator VarOp;
+ using VarOp = DynTypedMatcher::VariadicOperator;
+
VariadicOperatorMatcherDescriptor(unsigned MinCount, unsigned MaxCount,
VarOp Op, StringRef MatcherName)
: MinCount(MinCount), MaxCount(MaxCount), Op(Op),
@@ -615,7 +652,9 @@ public:
Diagnostics *Error) const override {
if (Args.size() < MinCount || MaxCount < Args.size()) {
const std::string MaxStr =
- (MaxCount == UINT_MAX ? "" : Twine(MaxCount)).str();
+ (MaxCount == std::numeric_limits<unsigned>::max() ? ""
+ : Twine(MaxCount))
+ .str();
Error->addError(NameRange, Error->ET_RegistryWrongArgCount)
<< ("(" + Twine(MinCount) + ", " + MaxStr + ")") << Args.size();
return VariantMatcher();
@@ -637,10 +676,12 @@ public:
bool isVariadic() const override { return true; }
unsigned getNumArgs() const override { return 0; }
+
void getArgKinds(ast_type_traits::ASTNodeKind ThisKind, unsigned ArgNo,
std::vector<ArgKind> &Kinds) const override {
Kinds.push_back(ThisKind);
}
+
bool isConvertibleTo(ast_type_traits::ASTNodeKind Kind, unsigned *Specificity,
ast_type_traits::ASTNodeKind *LeastDerivedKind) const override {
if (Specificity)
@@ -649,6 +690,7 @@ public:
*LeastDerivedKind = Kind;
return true;
}
+
bool isPolymorphic() const override { return true; }
private:
Modified: cfe/trunk/lib/ASTMatchers/Dynamic/Parser.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/ASTMatchers/Dynamic/Parser.cpp?rev=317137&r1=317136&r2=317137&view=diff
==============================================================================
--- cfe/trunk/lib/ASTMatchers/Dynamic/Parser.cpp (original)
+++ cfe/trunk/lib/ASTMatchers/Dynamic/Parser.cpp Wed Nov 1 16:09:49 2017
@@ -1,4 +1,4 @@
-//===--- Parser.cpp - Matcher expression parser -----*- C++ -*-===//
+//===- Parser.cpp - Matcher expression parser -----------------------------===//
//
// The LLVM Compiler Infrastructure
//
@@ -13,11 +13,21 @@
//===----------------------------------------------------------------------===//
#include "clang/ASTMatchers/Dynamic/Parser.h"
+#include "clang/ASTMatchers/ASTMatchersInternal.h"
+#include "clang/ASTMatchers/Dynamic/Diagnostics.h"
#include "clang/ASTMatchers/Dynamic/Registry.h"
#include "clang/Basic/CharInfo.h"
#include "llvm/ADT/Optional.h"
+#include "llvm/ADT/StringRef.h"
+#include "llvm/Support/ErrorHandling.h"
#include "llvm/Support/ManagedStatic.h"
+#include <algorithm>
+#include <cassert>
+#include <cerrno>
+#include <cstddef>
+#include <cstdlib>
#include <string>
+#include <utility>
#include <vector>
namespace clang {
@@ -43,10 +53,10 @@ struct Parser::TokenInfo {
/// \brief Some known identifiers.
static const char* const ID_Bind;
- TokenInfo() : Text(), Kind(TK_Eof), Range(), Value() {}
+ TokenInfo() = default;
StringRef Text;
- TokenKind Kind;
+ TokenKind Kind = TK_Eof;
SourceRange Range;
VariantValue Value;
};
@@ -57,14 +67,13 @@ const char* const Parser::TokenInfo::ID_
class Parser::CodeTokenizer {
public:
explicit CodeTokenizer(StringRef MatcherCode, Diagnostics *Error)
- : Code(MatcherCode), StartOfLine(MatcherCode), Line(1), Error(Error),
- CodeCompletionLocation(nullptr) {
+ : Code(MatcherCode), StartOfLine(MatcherCode), Error(Error) {
NextToken = getNextToken();
}
CodeTokenizer(StringRef MatcherCode, Diagnostics *Error,
unsigned CodeCompletionOffset)
- : Code(MatcherCode), StartOfLine(MatcherCode), Line(1), Error(Error),
+ : Code(MatcherCode), StartOfLine(MatcherCode), Error(Error),
CodeCompletionLocation(MatcherCode.data() + CodeCompletionOffset) {
NextToken = getNextToken();
}
@@ -138,7 +147,7 @@ private:
if (isAlphanumeric(Code[0])) {
// Parse an identifier
size_t TokenLength = 1;
- while (1) {
+ while (true) {
// A code completion location in/immediately after an identifier will
// cause the portion of the identifier before the code completion
// location to become a code completion token.
@@ -283,22 +292,22 @@ private:
StringRef Code;
StringRef StartOfLine;
- unsigned Line;
+ unsigned Line = 1;
Diagnostics *Error;
TokenInfo NextToken;
- const char *CodeCompletionLocation;
+ const char *CodeCompletionLocation = nullptr;
};
-Parser::Sema::~Sema() {}
+Parser::Sema::~Sema() = default;
std::vector<ArgKind> Parser::Sema::getAcceptedCompletionTypes(
llvm::ArrayRef<std::pair<MatcherCtor, unsigned>> Context) {
- return std::vector<ArgKind>();
+ return {};
}
std::vector<MatcherCompletion>
Parser::Sema::getMatcherCompletions(llvm::ArrayRef<ArgKind> AcceptedTypes) {
- return std::vector<MatcherCompletion>();
+ return {};
}
struct Parser::ScopedContextEntry {
@@ -384,7 +393,7 @@ bool Parser::parseMatcherExpressionImpl(
EndToken = Tokenizer->consumeNextToken();
break;
}
- if (Args.size() > 0) {
+ if (!Args.empty()) {
// We must find a , token to continue.
const TokenInfo CommaToken = Tokenizer->consumeNextToken();
if (CommaToken.Kind != TokenInfo::TK_Comma) {
@@ -558,7 +567,7 @@ Parser::Parser(CodeTokenizer *Tokenizer,
: Tokenizer(Tokenizer), S(S ? S : &*DefaultRegistrySema),
NamedValues(NamedValues), Error(Error) {}
-Parser::RegistrySema::~RegistrySema() {}
+Parser::RegistrySema::~RegistrySema() = default;
llvm::Optional<MatcherCtor>
Parser::RegistrySema::lookupMatcherCtor(StringRef MatcherName) {
@@ -640,6 +649,6 @@ Parser::parseMatcherExpression(StringRef
return Result;
}
-} // namespace dynamic
-} // namespace ast_matchers
-} // namespace clang
+} // namespace dynamic
+} // namespace ast_matchers
+} // namespace clang
Modified: cfe/trunk/lib/ASTMatchers/Dynamic/Registry.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/ASTMatchers/Dynamic/Registry.cpp?rev=317137&r1=317136&r2=317137&view=diff
==============================================================================
--- cfe/trunk/lib/ASTMatchers/Dynamic/Registry.cpp (original)
+++ cfe/trunk/lib/ASTMatchers/Dynamic/Registry.cpp Wed Nov 1 16:09:49 2017
@@ -1,37 +1,49 @@
-//===--- Registry.cpp - Matcher registry -------------------------===//
+//===- Registry.cpp - Matcher registry ------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
-//===------------------------------------------------------------===//
-///
+//===----------------------------------------------------------------------===//
+//
/// \file
/// \brief Registry map populated at static initialization time.
-///
-//===------------------------------------------------------------===//
+//
+//===----------------------------------------------------------------------===//
#include "clang/ASTMatchers/Dynamic/Registry.h"
#include "Marshallers.h"
+#include "clang/AST/ASTTypeTraits.h"
#include "clang/ASTMatchers/ASTMatchers.h"
+#include "clang/ASTMatchers/Dynamic/Diagnostics.h"
+#include "clang/ASTMatchers/Dynamic/VariantValue.h"
+#include "llvm/ADT/Optional.h"
#include "llvm/ADT/STLExtras.h"
#include "llvm/ADT/StringMap.h"
#include "llvm/ADT/StringRef.h"
#include "llvm/Support/ManagedStatic.h"
+#include "llvm/Support/raw_ostream.h"
+#include <cassert>
+#include <iterator>
+#include <memory>
#include <set>
+#include <string>
#include <utility>
+#include <vector>
using namespace clang::ast_type_traits;
namespace clang {
namespace ast_matchers {
namespace dynamic {
+
namespace {
using internal::MatcherDescriptor;
-typedef llvm::StringMap<std::unique_ptr<const MatcherDescriptor>> ConstructorMap;
+using ConstructorMap = llvm::StringMap<std::unique_ptr<const MatcherDescriptor>>;
+
class RegistryMaps {
public:
RegistryMaps();
@@ -46,6 +58,8 @@ private:
ConstructorMap Constructors;
};
+} // namespace
+
void RegistryMaps::registerMatcher(
StringRef MatcherName, std::unique_ptr<MatcherDescriptor> Callback) {
assert(Constructors.find(MatcherName) == Constructors.end());
@@ -74,7 +88,7 @@ void RegistryMaps::registerMatcher(
MATCHER_OVERLOAD_ENTRY(name, 0), \
MATCHER_OVERLOAD_ENTRY(name, 1)}; \
REGISTER_MATCHER_OVERLOAD(name); \
- } while (0)
+ } while (false)
/// \brief Generate a registry map with all the known matchers.
RegistryMaps::RegistryMaps() {
@@ -454,12 +468,10 @@ RegistryMaps::RegistryMaps() {
REGISTER_MATCHER(withInitializer);
}
-RegistryMaps::~RegistryMaps() {}
+RegistryMaps::~RegistryMaps() = default;
static llvm::ManagedStatic<RegistryMaps> RegistryData;
-} // anonymous namespace
-
// static
llvm::Optional<MatcherCtor> Registry::lookupMatcherCtor(StringRef MatcherName) {
auto it = RegistryData->constructors().find(MatcherName);
@@ -468,10 +480,8 @@ llvm::Optional<MatcherCtor> Registry::lo
: it->second.get();
}
-namespace {
-
-llvm::raw_ostream &operator<<(llvm::raw_ostream &OS,
- const std::set<ASTNodeKind> &KS) {
+static llvm::raw_ostream &operator<<(llvm::raw_ostream &OS,
+ const std::set<ASTNodeKind> &KS) {
unsigned Count = 0;
for (std::set<ASTNodeKind>::const_iterator I = KS.begin(), E = KS.end();
I != E; ++I) {
@@ -486,8 +496,6 @@ llvm::raw_ostream &operator<<(llvm::raw_
return OS;
}
-} // namespace
-
std::vector<ArgKind> Registry::getAcceptedCompletionTypes(
ArrayRef<std::pair<MatcherCtor, unsigned>> Context) {
ASTNodeKind InitialTypes[] = {
@@ -597,7 +605,6 @@ Registry::getMatcherCompletions(ArrayRef
return Completions;
}
-// static
VariantMatcher Registry::constructMatcher(MatcherCtor Ctor,
SourceRange NameRange,
ArrayRef<ParserValue> Args,
@@ -605,7 +612,6 @@ VariantMatcher Registry::constructMatche
return Ctor->create(NameRange, Args, Error);
}
-// static
VariantMatcher Registry::constructBoundMatcher(MatcherCtor Ctor,
SourceRange NameRange,
StringRef BindID,
@@ -625,6 +631,6 @@ VariantMatcher Registry::constructBoundM
return VariantMatcher();
}
-} // namespace dynamic
-} // namespace ast_matchers
-} // namespace clang
+} // namespace dynamic
+} // namespace ast_matchers
+} // namespace clang
More information about the cfe-commits
mailing list