forked from andreasfertig/cppinsights
-
Notifications
You must be signed in to change notification settings - Fork 0
/
InsightsMatchers.h
67 lines (52 loc) · 2.56 KB
/
InsightsMatchers.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
/******************************************************************************
*
* C++ Insights, copyright (C) by Andreas Fertig
* Distributed under an MIT license. See LICENSE for details
*
****************************************************************************/
#ifndef INSIGHTS_MATCHERS_H
#define INSIGHTS_MATCHERS_H
#include "clang/ASTMatchers/ASTMatchFinder.h"
#include "clang/ASTMatchers/ASTMatchers.h"
#include "ClangCompat.h"
#include "InsightsHelpers.h"
//-----------------------------------------------------------------------------
namespace clang {
namespace ast_matchers {
/* don't replace stuff in template definitions */
static const auto isTemplate = anyOf(hasAncestor(classTemplateDecl()),
hasAncestor(functionTemplateDecl()),
hasAncestor(classTemplateSpecializationDecl()));
//-----------------------------------------------------------------------------
static const auto isAutoAncestor =
hasAncestor(varDecl(anyOf(hasType(autoType().bind("autoType")),
hasType(qualType(hasDescendant(autoType().bind("autoType")))),
/* decltype and decltype(auto) */
hasType(decltypeType().bind("dt")),
hasType(qualType(hasDescendant(decltypeType().bind("dt")))))));
//-----------------------------------------------------------------------------
/// \brief Shut up a unused variable warnings
#define SILENCE \
(void)Finder; \
(void)Builder
extern const internal::VariadicDynCastAllOfMatcher<Decl, VarTemplateDecl> varTemplateDecl;
// \brief Matches AST nodes of type \c FunctionDecl which is a template instantiation.
AST_MATCHER(FunctionDecl, isTemplateInstantiationPlain)
{
SILENCE;
return Node.isTemplateInstantiation();
}
AST_POLYMORPHIC_MATCHER(isMacroOrInvalidLocation, AST_POLYMORPHIC_SUPPORTED_TYPES(Decl, Stmt))
{
SILENCE;
return (insights::IsMacroLocation(Node.getBeginLoc()) || insights::IsInvalidLocation(Node.getBeginLoc()));
}
AST_POLYMORPHIC_MATCHER(isInvalidLocation, AST_POLYMORPHIC_SUPPORTED_TYPES(Decl, Stmt))
{
SILENCE;
return insights::IsInvalidLocation(Node.getBeginLoc());
}
} // namespace ast_matchers
} // namespace clang
//-----------------------------------------------------------------------------
#endif /* INSIGHTS_MATCHERS_H */